]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9-3.3.1-201204062021.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9-3.3.1-201204062021.patch
CommitLineData
3977694d
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index 0c083c5..9c2512a 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@@ -69,6 +73,7 @@ Image
34 Module.markers
35 Module.symvers
36 PENDING
37+PERF*
38 SCCS
39 System.map*
40 TAGS
41@@ -92,19 +97,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@@ -115,9 +125,11 @@ devlist.h*
67 dnotify_test
68 docproc
69 dslm
70+dtc-lexer.lex.c
71 elf2ecoff
72 elfconfig.h*
73 evergreen_reg_safe.h
74+exception_policy.conf
75 fixdep
76 flask.h
77 fore200e_mkfirm
78@@ -125,12 +137,15 @@ fore200e_pca_fw.c*
79 gconf
80 gconf.glade.h
81 gen-devlist
82+gen-kdb_cmds.c
83 gen_crc32table
84 gen_init_cpio
85 generated
86 genheaders
87 genksyms
88 *_gray256.c
89+hash
90+hid-example
91 hpet_example
92 hugepage-mmap
93 hugepage-shm
94@@ -145,7 +160,7 @@ int32.c
95 int4.c
96 int8.c
97 kallsyms
98-kconfig
99+kern_constants.h
100 keywords.c
101 ksym.c*
102 ksym.h*
103@@ -153,7 +168,7 @@ kxgettext
104 lkc_defs.h
105 lex.c
106 lex.*.c
107-linux
108+lib1funcs.S
109 logo_*.c
110 logo_*_clut224.c
111 logo_*_mono.c
112@@ -165,14 +180,15 @@ machtypes.h
113 map
114 map_hugetlb
115 maui_boot.h
116-media
117 mconf
118+mdp
119 miboot*
120 mk_elfconfig
121 mkboot
122 mkbugboot
123 mkcpustr
124 mkdep
125+mkpiggy
126 mkprep
127 mkregtable
128 mktables
129@@ -208,6 +224,7 @@ r300_reg_safe.h
130 r420_reg_safe.h
131 r600_reg_safe.h
132 recordmcount
133+regdb.c
134 relocs
135 rlim_names.h
136 rn50_reg_safe.h
137@@ -218,6 +235,7 @@ setup
138 setup.bin
139 setup.elf
140 sImage
141+slabinfo
142 sm_tbl*
143 split-include
144 syscalltab.h
145@@ -228,6 +246,7 @@ tftpboot.img
146 timeconst.h
147 times.h*
148 trix_boot.h
149+user_constants.h
150 utsrelease.h*
151 vdso-syms.lds
152 vdso.lds
153@@ -245,7 +264,9 @@ vmlinux
154 vmlinux-*
155 vmlinux.aout
156 vmlinux.bin.all
157+vmlinux.bin.bz2
158 vmlinux.lds
159+vmlinux.relocs
160 vmlinuz
161 voffset.h
162 vsyscall.lds
163@@ -253,9 +274,11 @@ vsyscall_32.lds
164 wanxlfw.inc
165 uImage
166 unifdef
167+utsrelease.h
168 wakeup.bin
169 wakeup.elf
170 wakeup.lds
171 zImage*
172 zconf.hash.c
173+zconf.lex.c
174 zoffset.h
175diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
176index d99fd9c..8689fef 100644
177--- a/Documentation/kernel-parameters.txt
178+++ b/Documentation/kernel-parameters.txt
179@@ -1977,6 +1977,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
180 the specified number of seconds. This is to be used if
181 your oopses keep scrolling off the screen.
182
183+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
184+ virtualization environments that don't cope well with the
185+ expand down segment used by UDEREF on X86-32 or the frequent
186+ page table updates on X86-64.
187+
188+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
189+
190 pcbit= [HW,ISDN]
191
192 pcd. [PARIDE]
193diff --git a/Makefile b/Makefile
194index 026a227..22ef9bc 100644
195--- a/Makefile
196+++ b/Makefile
197@@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
198
199 HOSTCC = gcc
200 HOSTCXX = g++
201-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
202-HOSTCXXFLAGS = -O2
203+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
204+HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
205+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
206
207 # Decide whether to build built-in, modular, or both.
208 # Normally, just do built-in.
209@@ -407,8 +408,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exc
210 # Rules shared between *config targets and build targets
211
212 # Basic helpers built in scripts/
213-PHONY += scripts_basic
214-scripts_basic:
215+PHONY += scripts_basic gcc-plugins
216+scripts_basic: gcc-plugins
217 $(Q)$(MAKE) $(build)=scripts/basic
218 $(Q)rm -f .tmp_quiet_recordmcount
219
220@@ -564,6 +565,50 @@ else
221 KBUILD_CFLAGS += -O2
222 endif
223
224+ifndef DISABLE_PAX_PLUGINS
225+ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(CC)"), y)
226+ifndef DISABLE_PAX_CONSTIFY_PLUGIN
227+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
228+endif
229+ifdef CONFIG_PAX_MEMORY_STACKLEAK
230+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
231+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
232+endif
233+ifdef CONFIG_KALLOCSTAT_PLUGIN
234+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
235+endif
236+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
237+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
238+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
239+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
240+endif
241+ifdef CONFIG_CHECKER_PLUGIN
242+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
243+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
244+endif
245+endif
246+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
247+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
248+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
249+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
250+export CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN
251+ifeq ($(KBUILD_EXTMOD),)
252+gcc-plugins:
253+ $(Q)$(MAKE) $(build)=tools/gcc
254+else
255+gcc-plugins: ;
256+endif
257+else
258+gcc-plugins:
259+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
260+ $(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.))
261+else
262+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
263+endif
264+ $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
265+endif
266+endif
267+
268 include $(srctree)/arch/$(SRCARCH)/Makefile
269
270 ifneq ($(CONFIG_FRAME_WARN),0)
271@@ -708,7 +753,7 @@ export mod_strip_cmd
272
273
274 ifeq ($(KBUILD_EXTMOD),)
275-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
276+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
277
278 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
279 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
280@@ -932,6 +977,8 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
281
282 # The actual objects are generated when descending,
283 # make sure no implicit rule kicks in
284+$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
285+$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
286 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
287
288 # Handle descending into subdirectories listed in $(vmlinux-dirs)
289@@ -941,7 +988,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
290 # Error messages still appears in the original language
291
292 PHONY += $(vmlinux-dirs)
293-$(vmlinux-dirs): prepare scripts
294+$(vmlinux-dirs): gcc-plugins prepare scripts
295 $(Q)$(MAKE) $(build)=$@
296
297 # Store (new) KERNELRELASE string in include/config/kernel.release
298@@ -985,6 +1032,7 @@ prepare0: archprepare FORCE
299 $(Q)$(MAKE) $(build)=.
300
301 # All the preparing..
302+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
303 prepare: prepare0
304
305 # Generate some files
306@@ -1089,6 +1137,8 @@ all: modules
307 # using awk while concatenating to the final file.
308
309 PHONY += modules
310+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
311+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
312 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
313 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
314 @$(kecho) ' Building modules, stage 2.';
315@@ -1104,7 +1154,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
316
317 # Target to prepare building external modules
318 PHONY += modules_prepare
319-modules_prepare: prepare scripts
320+modules_prepare: gcc-plugins prepare scripts
321
322 # Target to install modules
323 PHONY += modules_install
324@@ -1201,6 +1251,7 @@ distclean: mrproper
325 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
326 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
327 -o -name '.*.rej' \
328+ -o -name '.*.rej' -o -name '*.so' \
329 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
330 -type f -print | xargs rm -f
331
332@@ -1361,6 +1412,8 @@ PHONY += $(module-dirs) modules
333 $(module-dirs): crmodverdir $(objtree)/Module.symvers
334 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
335
336+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
337+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
338 modules: $(module-dirs)
339 @$(kecho) ' Building modules, stage 2.';
340 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
341@@ -1487,17 +1540,21 @@ else
342 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
343 endif
344
345-%.s: %.c prepare scripts FORCE
346+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
347+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
348+%.s: %.c gcc-plugins prepare scripts FORCE
349 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
350 %.i: %.c prepare scripts FORCE
351 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
352-%.o: %.c prepare scripts FORCE
353+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
354+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
355+%.o: %.c gcc-plugins prepare scripts FORCE
356 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
357 %.lst: %.c prepare scripts FORCE
358 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
359-%.s: %.S prepare scripts FORCE
360+%.s: %.S gcc-plugins prepare scripts FORCE
361 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
362-%.o: %.S prepare scripts FORCE
363+%.o: %.S gcc-plugins prepare scripts FORCE
364 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
365 %.symtypes: %.c prepare scripts FORCE
366 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
367@@ -1507,11 +1564,15 @@ endif
368 $(cmd_crmodverdir)
369 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
370 $(build)=$(build-dir)
371-%/: prepare scripts FORCE
372+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
373+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
374+%/: gcc-plugins prepare scripts FORCE
375 $(cmd_crmodverdir)
376 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
377 $(build)=$(build-dir)
378-%.ko: prepare scripts FORCE
379+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
380+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
381+%.ko: gcc-plugins prepare scripts FORCE
382 $(cmd_crmodverdir)
383 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
384 $(build)=$(build-dir) $(@:.ko=.o)
385diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
386index 640f909..48b6597 100644
387--- a/arch/alpha/include/asm/atomic.h
388+++ b/arch/alpha/include/asm/atomic.h
389@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
390 #define atomic_dec(v) atomic_sub(1,(v))
391 #define atomic64_dec(v) atomic64_sub(1,(v))
392
393+#define atomic64_read_unchecked(v) atomic64_read(v)
394+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
395+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
396+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
397+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
398+#define atomic64_inc_unchecked(v) atomic64_inc(v)
399+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
400+#define atomic64_dec_unchecked(v) atomic64_dec(v)
401+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
402+
403 #define smp_mb__before_atomic_dec() smp_mb()
404 #define smp_mb__after_atomic_dec() smp_mb()
405 #define smp_mb__before_atomic_inc() smp_mb()
406diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
407index ad368a9..fbe0f25 100644
408--- a/arch/alpha/include/asm/cache.h
409+++ b/arch/alpha/include/asm/cache.h
410@@ -4,19 +4,19 @@
411 #ifndef __ARCH_ALPHA_CACHE_H
412 #define __ARCH_ALPHA_CACHE_H
413
414+#include <linux/const.h>
415
416 /* Bytes per L1 (data) cache line. */
417 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
418-# define L1_CACHE_BYTES 64
419 # define L1_CACHE_SHIFT 6
420 #else
421 /* Both EV4 and EV5 are write-through, read-allocate,
422 direct-mapped, physical.
423 */
424-# define L1_CACHE_BYTES 32
425 # define L1_CACHE_SHIFT 5
426 #endif
427
428+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
429 #define SMP_CACHE_BYTES L1_CACHE_BYTES
430
431 #endif
432diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
433index da5449e..7418343 100644
434--- a/arch/alpha/include/asm/elf.h
435+++ b/arch/alpha/include/asm/elf.h
436@@ -90,6 +90,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
437
438 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
439
440+#ifdef CONFIG_PAX_ASLR
441+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
442+
443+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
444+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
445+#endif
446+
447 /* $0 is set by ld.so to a pointer to a function which might be
448 registered using atexit. This provides a mean for the dynamic
449 linker to call DT_FINI functions for shared libraries that have
450diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
451index de98a73..bd4f1f8 100644
452--- a/arch/alpha/include/asm/pgtable.h
453+++ b/arch/alpha/include/asm/pgtable.h
454@@ -101,6 +101,17 @@ struct vm_area_struct;
455 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
456 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
457 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
458+
459+#ifdef CONFIG_PAX_PAGEEXEC
460+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
461+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
462+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
463+#else
464+# define PAGE_SHARED_NOEXEC PAGE_SHARED
465+# define PAGE_COPY_NOEXEC PAGE_COPY
466+# define PAGE_READONLY_NOEXEC PAGE_READONLY
467+#endif
468+
469 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
470
471 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
472diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
473index 2fd00b7..cfd5069 100644
474--- a/arch/alpha/kernel/module.c
475+++ b/arch/alpha/kernel/module.c
476@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
477
478 /* The small sections were sorted to the end of the segment.
479 The following should definitely cover them. */
480- gp = (u64)me->module_core + me->core_size - 0x8000;
481+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
482 got = sechdrs[me->arch.gotsecindex].sh_addr;
483
484 for (i = 0; i < n; i++) {
485diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
486index 01e8715..be0e80f 100644
487--- a/arch/alpha/kernel/osf_sys.c
488+++ b/arch/alpha/kernel/osf_sys.c
489@@ -1147,7 +1147,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
490 /* At this point: (!vma || addr < vma->vm_end). */
491 if (limit - len < addr)
492 return -ENOMEM;
493- if (!vma || addr + len <= vma->vm_start)
494+ if (check_heap_stack_gap(vma, addr, len))
495 return addr;
496 addr = vma->vm_end;
497 vma = vma->vm_next;
498@@ -1183,6 +1183,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
499 merely specific addresses, but regions of memory -- perhaps
500 this feature should be incorporated into all ports? */
501
502+#ifdef CONFIG_PAX_RANDMMAP
503+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
504+#endif
505+
506 if (addr) {
507 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
508 if (addr != (unsigned long) -ENOMEM)
509@@ -1190,8 +1194,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
510 }
511
512 /* Next, try allocating at TASK_UNMAPPED_BASE. */
513- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
514- len, limit);
515+ addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
516+
517 if (addr != (unsigned long) -ENOMEM)
518 return addr;
519
520diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
521index fadd5f8..904e73a 100644
522--- a/arch/alpha/mm/fault.c
523+++ b/arch/alpha/mm/fault.c
524@@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
525 __reload_thread(pcb);
526 }
527
528+#ifdef CONFIG_PAX_PAGEEXEC
529+/*
530+ * PaX: decide what to do with offenders (regs->pc = fault address)
531+ *
532+ * returns 1 when task should be killed
533+ * 2 when patched PLT trampoline was detected
534+ * 3 when unpatched PLT trampoline was detected
535+ */
536+static int pax_handle_fetch_fault(struct pt_regs *regs)
537+{
538+
539+#ifdef CONFIG_PAX_EMUPLT
540+ int err;
541+
542+ do { /* PaX: patched PLT emulation #1 */
543+ unsigned int ldah, ldq, jmp;
544+
545+ err = get_user(ldah, (unsigned int *)regs->pc);
546+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
547+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
548+
549+ if (err)
550+ break;
551+
552+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
553+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
554+ jmp == 0x6BFB0000U)
555+ {
556+ unsigned long r27, addr;
557+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
558+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
559+
560+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
561+ err = get_user(r27, (unsigned long *)addr);
562+ if (err)
563+ break;
564+
565+ regs->r27 = r27;
566+ regs->pc = r27;
567+ return 2;
568+ }
569+ } while (0);
570+
571+ do { /* PaX: patched PLT emulation #2 */
572+ unsigned int ldah, lda, br;
573+
574+ err = get_user(ldah, (unsigned int *)regs->pc);
575+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
576+ err |= get_user(br, (unsigned int *)(regs->pc+8));
577+
578+ if (err)
579+ break;
580+
581+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
582+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
583+ (br & 0xFFE00000U) == 0xC3E00000U)
584+ {
585+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
586+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
587+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
588+
589+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
590+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
591+ return 2;
592+ }
593+ } while (0);
594+
595+ do { /* PaX: unpatched PLT emulation */
596+ unsigned int br;
597+
598+ err = get_user(br, (unsigned int *)regs->pc);
599+
600+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
601+ unsigned int br2, ldq, nop, jmp;
602+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
603+
604+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
605+ err = get_user(br2, (unsigned int *)addr);
606+ err |= get_user(ldq, (unsigned int *)(addr+4));
607+ err |= get_user(nop, (unsigned int *)(addr+8));
608+ err |= get_user(jmp, (unsigned int *)(addr+12));
609+ err |= get_user(resolver, (unsigned long *)(addr+16));
610+
611+ if (err)
612+ break;
613+
614+ if (br2 == 0xC3600000U &&
615+ ldq == 0xA77B000CU &&
616+ nop == 0x47FF041FU &&
617+ jmp == 0x6B7B0000U)
618+ {
619+ regs->r28 = regs->pc+4;
620+ regs->r27 = addr+16;
621+ regs->pc = resolver;
622+ return 3;
623+ }
624+ }
625+ } while (0);
626+#endif
627+
628+ return 1;
629+}
630+
631+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
632+{
633+ unsigned long i;
634+
635+ printk(KERN_ERR "PAX: bytes at PC: ");
636+ for (i = 0; i < 5; i++) {
637+ unsigned int c;
638+ if (get_user(c, (unsigned int *)pc+i))
639+ printk(KERN_CONT "???????? ");
640+ else
641+ printk(KERN_CONT "%08x ", c);
642+ }
643+ printk("\n");
644+}
645+#endif
646
647 /*
648 * This routine handles page faults. It determines the address,
649@@ -131,8 +249,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
650 good_area:
651 si_code = SEGV_ACCERR;
652 if (cause < 0) {
653- if (!(vma->vm_flags & VM_EXEC))
654+ if (!(vma->vm_flags & VM_EXEC)) {
655+
656+#ifdef CONFIG_PAX_PAGEEXEC
657+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
658+ goto bad_area;
659+
660+ up_read(&mm->mmap_sem);
661+ switch (pax_handle_fetch_fault(regs)) {
662+
663+#ifdef CONFIG_PAX_EMUPLT
664+ case 2:
665+ case 3:
666+ return;
667+#endif
668+
669+ }
670+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
671+ do_group_exit(SIGKILL);
672+#else
673 goto bad_area;
674+#endif
675+
676+ }
677 } else if (!cause) {
678 /* Allow reads even for write-only mappings */
679 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
680diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
681index 86976d0..8e07f84 100644
682--- a/arch/arm/include/asm/atomic.h
683+++ b/arch/arm/include/asm/atomic.h
684@@ -15,6 +15,10 @@
685 #include <linux/types.h>
686 #include <asm/system.h>
687
688+#ifdef CONFIG_GENERIC_ATOMIC64
689+#include <asm-generic/atomic64.h>
690+#endif
691+
692 #define ATOMIC_INIT(i) { (i) }
693
694 #ifdef __KERNEL__
695@@ -25,7 +29,15 @@
696 * atomic_set() is the clrex or dummy strex done on every exception return.
697 */
698 #define atomic_read(v) (*(volatile int *)&(v)->counter)
699+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
700+{
701+ return v->counter;
702+}
703 #define atomic_set(v,i) (((v)->counter) = (i))
704+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
705+{
706+ v->counter = i;
707+}
708
709 #if __LINUX_ARM_ARCH__ >= 6
710
711@@ -40,6 +52,35 @@ static inline void atomic_add(int i, atomic_t *v)
712 int result;
713
714 __asm__ __volatile__("@ atomic_add\n"
715+"1: ldrex %1, [%3]\n"
716+" adds %0, %1, %4\n"
717+
718+#ifdef CONFIG_PAX_REFCOUNT
719+" bvc 3f\n"
720+"2: bkpt 0xf103\n"
721+"3:\n"
722+#endif
723+
724+" strex %1, %0, [%3]\n"
725+" teq %1, #0\n"
726+" bne 1b"
727+
728+#ifdef CONFIG_PAX_REFCOUNT
729+"\n4:\n"
730+ _ASM_EXTABLE(2b, 4b)
731+#endif
732+
733+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
734+ : "r" (&v->counter), "Ir" (i)
735+ : "cc");
736+}
737+
738+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
739+{
740+ unsigned long tmp;
741+ int result;
742+
743+ __asm__ __volatile__("@ atomic_add_unchecked\n"
744 "1: ldrex %0, [%3]\n"
745 " add %0, %0, %4\n"
746 " strex %1, %0, [%3]\n"
747@@ -58,6 +99,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
748 smp_mb();
749
750 __asm__ __volatile__("@ atomic_add_return\n"
751+"1: ldrex %1, [%3]\n"
752+" adds %0, %1, %4\n"
753+
754+#ifdef CONFIG_PAX_REFCOUNT
755+" bvc 3f\n"
756+" mov %0, %1\n"
757+"2: bkpt 0xf103\n"
758+"3:\n"
759+#endif
760+
761+" strex %1, %0, [%3]\n"
762+" teq %1, #0\n"
763+" bne 1b"
764+
765+#ifdef CONFIG_PAX_REFCOUNT
766+"\n4:\n"
767+ _ASM_EXTABLE(2b, 4b)
768+#endif
769+
770+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
771+ : "r" (&v->counter), "Ir" (i)
772+ : "cc");
773+
774+ smp_mb();
775+
776+ return result;
777+}
778+
779+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
780+{
781+ unsigned long tmp;
782+ int result;
783+
784+ smp_mb();
785+
786+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
787 "1: ldrex %0, [%3]\n"
788 " add %0, %0, %4\n"
789 " strex %1, %0, [%3]\n"
790@@ -78,6 +155,35 @@ static inline void atomic_sub(int i, atomic_t *v)
791 int result;
792
793 __asm__ __volatile__("@ atomic_sub\n"
794+"1: ldrex %1, [%3]\n"
795+" subs %0, %1, %4\n"
796+
797+#ifdef CONFIG_PAX_REFCOUNT
798+" bvc 3f\n"
799+"2: bkpt 0xf103\n"
800+"3:\n"
801+#endif
802+
803+" strex %1, %0, [%3]\n"
804+" teq %1, #0\n"
805+" bne 1b"
806+
807+#ifdef CONFIG_PAX_REFCOUNT
808+"\n4:\n"
809+ _ASM_EXTABLE(2b, 4b)
810+#endif
811+
812+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
813+ : "r" (&v->counter), "Ir" (i)
814+ : "cc");
815+}
816+
817+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
818+{
819+ unsigned long tmp;
820+ int result;
821+
822+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
823 "1: ldrex %0, [%3]\n"
824 " sub %0, %0, %4\n"
825 " strex %1, %0, [%3]\n"
826@@ -96,11 +202,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
827 smp_mb();
828
829 __asm__ __volatile__("@ atomic_sub_return\n"
830-"1: ldrex %0, [%3]\n"
831-" sub %0, %0, %4\n"
832+"1: ldrex %1, [%3]\n"
833+" sub %0, %1, %4\n"
834+
835+#ifdef CONFIG_PAX_REFCOUNT
836+" bvc 3f\n"
837+" mov %0, %1\n"
838+"2: bkpt 0xf103\n"
839+"3:\n"
840+#endif
841+
842 " strex %1, %0, [%3]\n"
843 " teq %1, #0\n"
844 " bne 1b"
845+
846+#ifdef CONFIG_PAX_REFCOUNT
847+"\n4:\n"
848+ _ASM_EXTABLE(2b, 4b)
849+#endif
850+
851 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
852 : "r" (&v->counter), "Ir" (i)
853 : "cc");
854@@ -132,6 +252,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
855 return oldval;
856 }
857
858+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
859+{
860+ unsigned long oldval, res;
861+
862+ smp_mb();
863+
864+ do {
865+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
866+ "ldrex %1, [%3]\n"
867+ "mov %0, #0\n"
868+ "teq %1, %4\n"
869+ "strexeq %0, %5, [%3]\n"
870+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
871+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
872+ : "cc");
873+ } while (res);
874+
875+ smp_mb();
876+
877+ return oldval;
878+}
879+
880 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
881 {
882 unsigned long tmp, tmp2;
883@@ -165,7 +307,9 @@ static inline int atomic_add_return(int i, atomic_t *v)
884
885 return val;
886 }
887+#define atomic_add_return_unchecked(i, v) atomic_add_return(i, v)
888 #define atomic_add(i, v) (void) atomic_add_return(i, v)
889+#define atomic_add_unchecked(i, v) (void) atomic_add_return_unchecked(i, v)
890
891 static inline int atomic_sub_return(int i, atomic_t *v)
892 {
893@@ -179,7 +323,9 @@ static inline int atomic_sub_return(int i, atomic_t *v)
894
895 return val;
896 }
897+#define atomic_sub_return_unchecked(i, v) atomic_sub_return(i, v)
898 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
899+#define atomic_sub_unchecked(i, v) (void) atomic_sub_return_unchecked(i, v)
900
901 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
902 {
903@@ -194,6 +340,7 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
904
905 return ret;
906 }
907+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg(v, o, n)
908
909 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
910 {
911@@ -207,6 +354,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
912 #endif /* __LINUX_ARM_ARCH__ */
913
914 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
915+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
916+{
917+ return xchg(&v->counter, new);
918+}
919
920 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
921 {
922@@ -219,11 +370,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
923 }
924
925 #define atomic_inc(v) atomic_add(1, v)
926+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
927+{
928+ atomic_add_unchecked(1, v);
929+}
930 #define atomic_dec(v) atomic_sub(1, v)
931+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
932+{
933+ atomic_sub_unchecked(1, v);
934+}
935
936 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
937+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
938+{
939+ return atomic_add_return_unchecked(1, v) == 0;
940+}
941 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
942 #define atomic_inc_return(v) (atomic_add_return(1, v))
943+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
944+{
945+ return atomic_add_return_unchecked(1, v);
946+}
947 #define atomic_dec_return(v) (atomic_sub_return(1, v))
948 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
949
950@@ -239,6 +406,14 @@ typedef struct {
951 u64 __aligned(8) counter;
952 } atomic64_t;
953
954+#ifdef CONFIG_PAX_REFCOUNT
955+typedef struct {
956+ u64 __aligned(8) counter;
957+} atomic64_unchecked_t;
958+#else
959+typedef atomic64_t atomic64_unchecked_t;
960+#endif
961+
962 #define ATOMIC64_INIT(i) { (i) }
963
964 static inline u64 atomic64_read(atomic64_t *v)
965@@ -254,6 +429,19 @@ static inline u64 atomic64_read(atomic64_t *v)
966 return result;
967 }
968
969+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
970+{
971+ u64 result;
972+
973+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
974+" ldrexd %0, %H0, [%1]"
975+ : "=&r" (result)
976+ : "r" (&v->counter), "Qo" (v->counter)
977+ );
978+
979+ return result;
980+}
981+
982 static inline void atomic64_set(atomic64_t *v, u64 i)
983 {
984 u64 tmp;
985@@ -268,6 +456,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
986 : "cc");
987 }
988
989+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
990+{
991+ u64 tmp;
992+
993+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
994+"1: ldrexd %0, %H0, [%2]\n"
995+" strexd %0, %3, %H3, [%2]\n"
996+" teq %0, #0\n"
997+" bne 1b"
998+ : "=&r" (tmp), "=Qo" (v->counter)
999+ : "r" (&v->counter), "r" (i)
1000+ : "cc");
1001+}
1002+
1003 static inline void atomic64_add(u64 i, atomic64_t *v)
1004 {
1005 u64 result;
1006@@ -276,6 +478,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1007 __asm__ __volatile__("@ atomic64_add\n"
1008 "1: ldrexd %0, %H0, [%3]\n"
1009 " adds %0, %0, %4\n"
1010+" adcs %H0, %H0, %H4\n"
1011+
1012+#ifdef CONFIG_PAX_REFCOUNT
1013+" bvc 3f\n"
1014+"2: bkpt 0xf103\n"
1015+"3:\n"
1016+#endif
1017+
1018+" strexd %1, %0, %H0, [%3]\n"
1019+" teq %1, #0\n"
1020+" bne 1b"
1021+
1022+#ifdef CONFIG_PAX_REFCOUNT
1023+"\n4:\n"
1024+ _ASM_EXTABLE(2b, 4b)
1025+#endif
1026+
1027+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1028+ : "r" (&v->counter), "r" (i)
1029+ : "cc");
1030+}
1031+
1032+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1033+{
1034+ u64 result;
1035+ unsigned long tmp;
1036+
1037+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1038+"1: ldrexd %0, %H0, [%3]\n"
1039+" adds %0, %0, %4\n"
1040 " adc %H0, %H0, %H4\n"
1041 " strexd %1, %0, %H0, [%3]\n"
1042 " teq %1, #0\n"
1043@@ -287,12 +519,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1044
1045 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1046 {
1047- u64 result;
1048- unsigned long tmp;
1049+ u64 result, tmp;
1050
1051 smp_mb();
1052
1053 __asm__ __volatile__("@ atomic64_add_return\n"
1054+"1: ldrexd %1, %H1, [%3]\n"
1055+" adds %0, %1, %4\n"
1056+" adcs %H0, %H1, %H4\n"
1057+
1058+#ifdef CONFIG_PAX_REFCOUNT
1059+" bvc 3f\n"
1060+" mov %0, %1\n"
1061+" mov %H0, %H1\n"
1062+"2: bkpt 0xf103\n"
1063+"3:\n"
1064+#endif
1065+
1066+" strexd %1, %0, %H0, [%3]\n"
1067+" teq %1, #0\n"
1068+" bne 1b"
1069+
1070+#ifdef CONFIG_PAX_REFCOUNT
1071+"\n4:\n"
1072+ _ASM_EXTABLE(2b, 4b)
1073+#endif
1074+
1075+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1076+ : "r" (&v->counter), "r" (i)
1077+ : "cc");
1078+
1079+ smp_mb();
1080+
1081+ return result;
1082+}
1083+
1084+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1085+{
1086+ u64 result;
1087+ unsigned long tmp;
1088+
1089+ smp_mb();
1090+
1091+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1092 "1: ldrexd %0, %H0, [%3]\n"
1093 " adds %0, %0, %4\n"
1094 " adc %H0, %H0, %H4\n"
1095@@ -316,6 +585,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1096 __asm__ __volatile__("@ atomic64_sub\n"
1097 "1: ldrexd %0, %H0, [%3]\n"
1098 " subs %0, %0, %4\n"
1099+" sbcs %H0, %H0, %H4\n"
1100+
1101+#ifdef CONFIG_PAX_REFCOUNT
1102+" bvc 3f\n"
1103+"2: bkpt 0xf103\n"
1104+"3:\n"
1105+#endif
1106+
1107+" strexd %1, %0, %H0, [%3]\n"
1108+" teq %1, #0\n"
1109+" bne 1b"
1110+
1111+#ifdef CONFIG_PAX_REFCOUNT
1112+"\n4:\n"
1113+ _ASM_EXTABLE(2b, 4b)
1114+#endif
1115+
1116+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1117+ : "r" (&v->counter), "r" (i)
1118+ : "cc");
1119+}
1120+
1121+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1122+{
1123+ u64 result;
1124+ unsigned long tmp;
1125+
1126+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1127+"1: ldrexd %0, %H0, [%3]\n"
1128+" subs %0, %0, %4\n"
1129 " sbc %H0, %H0, %H4\n"
1130 " strexd %1, %0, %H0, [%3]\n"
1131 " teq %1, #0\n"
1132@@ -327,18 +626,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1133
1134 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1135 {
1136- u64 result;
1137- unsigned long tmp;
1138+ u64 result, tmp;
1139
1140 smp_mb();
1141
1142 __asm__ __volatile__("@ atomic64_sub_return\n"
1143-"1: ldrexd %0, %H0, [%3]\n"
1144-" subs %0, %0, %4\n"
1145-" sbc %H0, %H0, %H4\n"
1146+"1: ldrexd %1, %H1, [%3]\n"
1147+" subs %0, %1, %4\n"
1148+" sbc %H0, %H1, %H4\n"
1149+
1150+#ifdef CONFIG_PAX_REFCOUNT
1151+" bvc 3f\n"
1152+" mov %0, %1\n"
1153+" mov %H0, %H1\n"
1154+"2: bkpt 0xf103\n"
1155+"3:\n"
1156+#endif
1157+
1158 " strexd %1, %0, %H0, [%3]\n"
1159 " teq %1, #0\n"
1160 " bne 1b"
1161+
1162+#ifdef CONFIG_PAX_REFCOUNT
1163+"\n4:\n"
1164+ _ASM_EXTABLE(2b, 4b)
1165+#endif
1166+
1167 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1168 : "r" (&v->counter), "r" (i)
1169 : "cc");
1170@@ -372,6 +685,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1171 return oldval;
1172 }
1173
1174+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1175+{
1176+ u64 oldval;
1177+ unsigned long res;
1178+
1179+ smp_mb();
1180+
1181+ do {
1182+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1183+ "ldrexd %1, %H1, [%3]\n"
1184+ "mov %0, #0\n"
1185+ "teq %1, %4\n"
1186+ "teqeq %H1, %H4\n"
1187+ "strexdeq %0, %5, %H5, [%3]"
1188+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1189+ : "r" (&ptr->counter), "r" (old), "r" (new)
1190+ : "cc");
1191+ } while (res);
1192+
1193+ smp_mb();
1194+
1195+ return oldval;
1196+}
1197+
1198 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1199 {
1200 u64 result;
1201@@ -395,21 +732,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1202
1203 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1204 {
1205- u64 result;
1206- unsigned long tmp;
1207+ u64 result, tmp;
1208
1209 smp_mb();
1210
1211 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1212-"1: ldrexd %0, %H0, [%3]\n"
1213-" subs %0, %0, #1\n"
1214-" sbc %H0, %H0, #0\n"
1215+"1: ldrexd %1, %H1, [%3]\n"
1216+" subs %0, %1, #1\n"
1217+" sbc %H0, %H1, #0\n"
1218+
1219+#ifdef CONFIG_PAX_REFCOUNT
1220+" bvc 3f\n"
1221+" mov %0, %1\n"
1222+" mov %H0, %H1\n"
1223+"2: bkpt 0xf103\n"
1224+"3:\n"
1225+#endif
1226+
1227 " teq %H0, #0\n"
1228-" bmi 2f\n"
1229+" bmi 4f\n"
1230 " strexd %1, %0, %H0, [%3]\n"
1231 " teq %1, #0\n"
1232 " bne 1b\n"
1233-"2:"
1234+"4:\n"
1235+
1236+#ifdef CONFIG_PAX_REFCOUNT
1237+ _ASM_EXTABLE(2b, 4b)
1238+#endif
1239+
1240 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1241 : "r" (&v->counter)
1242 : "cc");
1243@@ -432,13 +782,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1244 " teq %0, %5\n"
1245 " teqeq %H0, %H5\n"
1246 " moveq %1, #0\n"
1247-" beq 2f\n"
1248+" beq 4f\n"
1249 " adds %0, %0, %6\n"
1250 " adc %H0, %H0, %H6\n"
1251+
1252+#ifdef CONFIG_PAX_REFCOUNT
1253+" bvc 3f\n"
1254+"2: bkpt 0xf103\n"
1255+"3:\n"
1256+#endif
1257+
1258 " strexd %2, %0, %H0, [%4]\n"
1259 " teq %2, #0\n"
1260 " bne 1b\n"
1261-"2:"
1262+"4:\n"
1263+
1264+#ifdef CONFIG_PAX_REFCOUNT
1265+ _ASM_EXTABLE(2b, 4b)
1266+#endif
1267+
1268 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1269 : "r" (&v->counter), "r" (u), "r" (a)
1270 : "cc");
1271@@ -451,10 +813,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1272
1273 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1274 #define atomic64_inc(v) atomic64_add(1LL, (v))
1275+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1276 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1277+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1278 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1279 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1280 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1281+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1282 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1283 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1284 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1285diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1286index 75fe66b..2255c86 100644
1287--- a/arch/arm/include/asm/cache.h
1288+++ b/arch/arm/include/asm/cache.h
1289@@ -4,8 +4,10 @@
1290 #ifndef __ASMARM_CACHE_H
1291 #define __ASMARM_CACHE_H
1292
1293+#include <linux/const.h>
1294+
1295 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1296-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1297+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1298
1299 /*
1300 * Memory returned by kmalloc() may be used for DMA, so we must make
1301diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1302index d5d8d5c..ad92c96 100644
1303--- a/arch/arm/include/asm/cacheflush.h
1304+++ b/arch/arm/include/asm/cacheflush.h
1305@@ -108,7 +108,7 @@ struct cpu_cache_fns {
1306 void (*dma_unmap_area)(const void *, size_t, int);
1307
1308 void (*dma_flush_range)(const void *, const void *);
1309-};
1310+} __no_const;
1311
1312 /*
1313 * Select the calling method
1314diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1315index 0e9ce8d..6ef1e03 100644
1316--- a/arch/arm/include/asm/elf.h
1317+++ b/arch/arm/include/asm/elf.h
1318@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1319 the loader. We need to make sure that it is out of the way of the program
1320 that it will "exec", and that there is sufficient room for the brk. */
1321
1322-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1323+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1324+
1325+#ifdef CONFIG_PAX_ASLR
1326+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1327+
1328+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1329+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1330+#endif
1331
1332 /* When the program starts, a1 contains a pointer to a function to be
1333 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1334@@ -126,10 +133,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1335 extern void elf_set_personality(const struct elf32_hdr *);
1336 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1337
1338-struct mm_struct;
1339-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1340-#define arch_randomize_brk arch_randomize_brk
1341-
1342 extern int vectors_user_mapping(void);
1343 #define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
1344 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
1345diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1346index e51b1e8..32a3113 100644
1347--- a/arch/arm/include/asm/kmap_types.h
1348+++ b/arch/arm/include/asm/kmap_types.h
1349@@ -21,6 +21,7 @@ enum km_type {
1350 KM_L1_CACHE,
1351 KM_L2_CACHE,
1352 KM_KDB,
1353+ KM_CLEARPAGE,
1354 KM_TYPE_NR
1355 };
1356
1357diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1358index 53426c6..c7baff3 100644
1359--- a/arch/arm/include/asm/outercache.h
1360+++ b/arch/arm/include/asm/outercache.h
1361@@ -35,7 +35,7 @@ struct outer_cache_fns {
1362 #endif
1363 void (*set_debug)(unsigned long);
1364 void (*resume)(void);
1365-};
1366+} __no_const;
1367
1368 #ifdef CONFIG_OUTER_CACHE
1369
1370diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1371index 97b440c..b7ff179 100644
1372--- a/arch/arm/include/asm/page.h
1373+++ b/arch/arm/include/asm/page.h
1374@@ -123,7 +123,7 @@ struct cpu_user_fns {
1375 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1376 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1377 unsigned long vaddr, struct vm_area_struct *vma);
1378-};
1379+} __no_const;
1380
1381 #ifdef MULTI_USER
1382 extern struct cpu_user_fns cpu_user;
1383diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h
1384index e4c96cc..1145653 100644
1385--- a/arch/arm/include/asm/system.h
1386+++ b/arch/arm/include/asm/system.h
1387@@ -98,6 +98,8 @@ void hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int,
1388
1389 #define xchg(ptr,x) \
1390 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1391+#define xchg_unchecked(ptr,x) \
1392+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1393
1394 extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
1395
1396@@ -534,6 +536,13 @@ static inline unsigned long long __cmpxchg64_mb(volatile void *ptr,
1397
1398 #endif /* __LINUX_ARM_ARCH__ >= 6 */
1399
1400+#define _ASM_EXTABLE(from, to) \
1401+" .pushsection __ex_table,\"a\"\n"\
1402+" .align 3\n" \
1403+" .long " #from ", " #to"\n" \
1404+" .popsection"
1405+
1406+
1407 #endif /* __ASSEMBLY__ */
1408
1409 #define arch_align_stack(x) (x)
1410diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1411index 2958976..12ccac4 100644
1412--- a/arch/arm/include/asm/uaccess.h
1413+++ b/arch/arm/include/asm/uaccess.h
1414@@ -22,6 +22,8 @@
1415 #define VERIFY_READ 0
1416 #define VERIFY_WRITE 1
1417
1418+extern void check_object_size(const void *ptr, unsigned long n, bool to);
1419+
1420 /*
1421 * The exception table consists of pairs of addresses: the first is the
1422 * address of an instruction that is allowed to fault, and the second is
1423@@ -387,8 +389,23 @@ do { \
1424
1425
1426 #ifdef CONFIG_MMU
1427-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1428-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1429+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1430+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1431+
1432+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1433+{
1434+ if (!__builtin_constant_p(n))
1435+ check_object_size(to, n, false);
1436+ return ___copy_from_user(to, from, n);
1437+}
1438+
1439+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1440+{
1441+ if (!__builtin_constant_p(n))
1442+ check_object_size(from, n, true);
1443+ return ___copy_to_user(to, from, n);
1444+}
1445+
1446 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1447 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1448 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1449@@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1450
1451 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1452 {
1453+ if ((long)n < 0)
1454+ return n;
1455+
1456 if (access_ok(VERIFY_READ, from, n))
1457 n = __copy_from_user(to, from, n);
1458 else /* security hole - plug it */
1459@@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1460
1461 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1462 {
1463+ if ((long)n < 0)
1464+ return n;
1465+
1466 if (access_ok(VERIFY_WRITE, to, n))
1467 n = __copy_to_user(to, from, n);
1468 return n;
1469diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1470index 5b0bce6..becd81c 100644
1471--- a/arch/arm/kernel/armksyms.c
1472+++ b/arch/arm/kernel/armksyms.c
1473@@ -95,8 +95,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1474 #ifdef CONFIG_MMU
1475 EXPORT_SYMBOL(copy_page);
1476
1477-EXPORT_SYMBOL(__copy_from_user);
1478-EXPORT_SYMBOL(__copy_to_user);
1479+EXPORT_SYMBOL(___copy_from_user);
1480+EXPORT_SYMBOL(___copy_to_user);
1481 EXPORT_SYMBOL(__clear_user);
1482
1483 EXPORT_SYMBOL(__get_user_1);
1484diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1485index 971d65c..cc936fb 100644
1486--- a/arch/arm/kernel/process.c
1487+++ b/arch/arm/kernel/process.c
1488@@ -28,7 +28,6 @@
1489 #include <linux/tick.h>
1490 #include <linux/utsname.h>
1491 #include <linux/uaccess.h>
1492-#include <linux/random.h>
1493 #include <linux/hw_breakpoint.h>
1494 #include <linux/cpuidle.h>
1495
1496@@ -273,9 +272,10 @@ void machine_power_off(void)
1497 machine_shutdown();
1498 if (pm_power_off)
1499 pm_power_off();
1500+ BUG();
1501 }
1502
1503-void machine_restart(char *cmd)
1504+__noreturn void machine_restart(char *cmd)
1505 {
1506 machine_shutdown();
1507
1508@@ -517,12 +517,6 @@ unsigned long get_wchan(struct task_struct *p)
1509 return 0;
1510 }
1511
1512-unsigned long arch_randomize_brk(struct mm_struct *mm)
1513-{
1514- unsigned long range_end = mm->brk + 0x02000000;
1515- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1516-}
1517-
1518 #ifdef CONFIG_MMU
1519 /*
1520 * The vectors page is always readable from user space for the
1521diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1522index a255c39..4a19b25 100644
1523--- a/arch/arm/kernel/setup.c
1524+++ b/arch/arm/kernel/setup.c
1525@@ -109,13 +109,13 @@ struct processor processor __read_mostly;
1526 struct cpu_tlb_fns cpu_tlb __read_mostly;
1527 #endif
1528 #ifdef MULTI_USER
1529-struct cpu_user_fns cpu_user __read_mostly;
1530+struct cpu_user_fns cpu_user __read_only;
1531 #endif
1532 #ifdef MULTI_CACHE
1533-struct cpu_cache_fns cpu_cache __read_mostly;
1534+struct cpu_cache_fns cpu_cache __read_only;
1535 #endif
1536 #ifdef CONFIG_OUTER_CACHE
1537-struct outer_cache_fns outer_cache __read_mostly;
1538+struct outer_cache_fns outer_cache __read_only;
1539 EXPORT_SYMBOL(outer_cache);
1540 #endif
1541
1542diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1543index f84dfe6..13e94f7 100644
1544--- a/arch/arm/kernel/traps.c
1545+++ b/arch/arm/kernel/traps.c
1546@@ -259,6 +259,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1547
1548 static DEFINE_RAW_SPINLOCK(die_lock);
1549
1550+extern void gr_handle_kernel_exploit(void);
1551+
1552 /*
1553 * This function is protected against re-entrancy.
1554 */
1555@@ -291,6 +293,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1556 panic("Fatal exception in interrupt");
1557 if (panic_on_oops)
1558 panic("Fatal exception");
1559+
1560+ gr_handle_kernel_exploit();
1561+
1562 if (ret != NOTIFY_STOP)
1563 do_exit(SIGSEGV);
1564 }
1565diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1566index 66a477a..bee61d3 100644
1567--- a/arch/arm/lib/copy_from_user.S
1568+++ b/arch/arm/lib/copy_from_user.S
1569@@ -16,7 +16,7 @@
1570 /*
1571 * Prototype:
1572 *
1573- * size_t __copy_from_user(void *to, const void *from, size_t n)
1574+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
1575 *
1576 * Purpose:
1577 *
1578@@ -84,11 +84,11 @@
1579
1580 .text
1581
1582-ENTRY(__copy_from_user)
1583+ENTRY(___copy_from_user)
1584
1585 #include "copy_template.S"
1586
1587-ENDPROC(__copy_from_user)
1588+ENDPROC(___copy_from_user)
1589
1590 .pushsection .fixup,"ax"
1591 .align 0
1592diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1593index 6ee2f67..d1cce76 100644
1594--- a/arch/arm/lib/copy_page.S
1595+++ b/arch/arm/lib/copy_page.S
1596@@ -10,6 +10,7 @@
1597 * ASM optimised string functions
1598 */
1599 #include <linux/linkage.h>
1600+#include <linux/const.h>
1601 #include <asm/assembler.h>
1602 #include <asm/asm-offsets.h>
1603 #include <asm/cache.h>
1604diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1605index d066df6..df28194 100644
1606--- a/arch/arm/lib/copy_to_user.S
1607+++ b/arch/arm/lib/copy_to_user.S
1608@@ -16,7 +16,7 @@
1609 /*
1610 * Prototype:
1611 *
1612- * size_t __copy_to_user(void *to, const void *from, size_t n)
1613+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
1614 *
1615 * Purpose:
1616 *
1617@@ -88,11 +88,11 @@
1618 .text
1619
1620 ENTRY(__copy_to_user_std)
1621-WEAK(__copy_to_user)
1622+WEAK(___copy_to_user)
1623
1624 #include "copy_template.S"
1625
1626-ENDPROC(__copy_to_user)
1627+ENDPROC(___copy_to_user)
1628 ENDPROC(__copy_to_user_std)
1629
1630 .pushsection .fixup,"ax"
1631diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
1632index 5c908b1..e712687 100644
1633--- a/arch/arm/lib/uaccess.S
1634+++ b/arch/arm/lib/uaccess.S
1635@@ -20,7 +20,7 @@
1636
1637 #define PAGE_SHIFT 12
1638
1639-/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
1640+/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
1641 * Purpose : copy a block to user memory from kernel memory
1642 * Params : to - user memory
1643 * : from - kernel memory
1644@@ -40,7 +40,7 @@ USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1645 sub r2, r2, ip
1646 b .Lc2u_dest_aligned
1647
1648-ENTRY(__copy_to_user)
1649+ENTRY(___copy_to_user)
1650 stmfd sp!, {r2, r4 - r7, lr}
1651 cmp r2, #4
1652 blt .Lc2u_not_enough
1653@@ -278,14 +278,14 @@ USER( TUSER( strgeb) r3, [r0], #1) @ May fault
1654 ldrgtb r3, [r1], #0
1655 USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1656 b .Lc2u_finished
1657-ENDPROC(__copy_to_user)
1658+ENDPROC(___copy_to_user)
1659
1660 .pushsection .fixup,"ax"
1661 .align 0
1662 9001: ldmfd sp!, {r0, r4 - r7, pc}
1663 .popsection
1664
1665-/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
1666+/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
1667 * Purpose : copy a block from user memory to kernel memory
1668 * Params : to - kernel memory
1669 * : from - user memory
1670@@ -304,7 +304,7 @@ USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1671 sub r2, r2, ip
1672 b .Lcfu_dest_aligned
1673
1674-ENTRY(__copy_from_user)
1675+ENTRY(___copy_from_user)
1676 stmfd sp!, {r0, r2, r4 - r7, lr}
1677 cmp r2, #4
1678 blt .Lcfu_not_enough
1679@@ -544,7 +544,7 @@ USER( TUSER( ldrgeb) r3, [r1], #1) @ May fault
1680 USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1681 strgtb r3, [r0], #1
1682 b .Lcfu_finished
1683-ENDPROC(__copy_from_user)
1684+ENDPROC(___copy_from_user)
1685
1686 .pushsection .fixup,"ax"
1687 .align 0
1688diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1689index 025f742..8432b08 100644
1690--- a/arch/arm/lib/uaccess_with_memcpy.c
1691+++ b/arch/arm/lib/uaccess_with_memcpy.c
1692@@ -104,7 +104,7 @@ out:
1693 }
1694
1695 unsigned long
1696-__copy_to_user(void __user *to, const void *from, unsigned long n)
1697+___copy_to_user(void __user *to, const void *from, unsigned long n)
1698 {
1699 /*
1700 * This test is stubbed out of the main function above to keep
1701diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1702index 6722627..8f97548c 100644
1703--- a/arch/arm/mach-omap2/board-n8x0.c
1704+++ b/arch/arm/mach-omap2/board-n8x0.c
1705@@ -597,7 +597,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1706 }
1707 #endif
1708
1709-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1710+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1711 .late_init = n8x0_menelaus_late_init,
1712 };
1713
1714diff --git a/arch/arm/mach-ux500/mbox-db5500.c b/arch/arm/mach-ux500/mbox-db5500.c
1715index 2b2d51c..0127490 100644
1716--- a/arch/arm/mach-ux500/mbox-db5500.c
1717+++ b/arch/arm/mach-ux500/mbox-db5500.c
1718@@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct device *dev,
1719 return sprintf(buf, "0x%X\n", mbox_value);
1720 }
1721
1722-static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1723+static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1724
1725 static int mbox_show(struct seq_file *s, void *data)
1726 {
1727diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1728index bb7eac3..3bade16 100644
1729--- a/arch/arm/mm/fault.c
1730+++ b/arch/arm/mm/fault.c
1731@@ -172,6 +172,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1732 }
1733 #endif
1734
1735+#ifdef CONFIG_PAX_PAGEEXEC
1736+ if (fsr & FSR_LNX_PF) {
1737+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1738+ do_group_exit(SIGKILL);
1739+ }
1740+#endif
1741+
1742 tsk->thread.address = addr;
1743 tsk->thread.error_code = fsr;
1744 tsk->thread.trap_no = 14;
1745@@ -393,6 +400,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1746 }
1747 #endif /* CONFIG_MMU */
1748
1749+#ifdef CONFIG_PAX_PAGEEXEC
1750+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1751+{
1752+ long i;
1753+
1754+ printk(KERN_ERR "PAX: bytes at PC: ");
1755+ for (i = 0; i < 20; i++) {
1756+ unsigned char c;
1757+ if (get_user(c, (__force unsigned char __user *)pc+i))
1758+ printk(KERN_CONT "?? ");
1759+ else
1760+ printk(KERN_CONT "%02x ", c);
1761+ }
1762+ printk("\n");
1763+
1764+ printk(KERN_ERR "PAX: bytes at SP-4: ");
1765+ for (i = -1; i < 20; i++) {
1766+ unsigned long c;
1767+ if (get_user(c, (__force unsigned long __user *)sp+i))
1768+ printk(KERN_CONT "???????? ");
1769+ else
1770+ printk(KERN_CONT "%08lx ", c);
1771+ }
1772+ printk("\n");
1773+}
1774+#endif
1775+
1776 /*
1777 * First Level Translation Fault Handler
1778 *
1779@@ -573,6 +607,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1780 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1781 struct siginfo info;
1782
1783+#ifdef CONFIG_PAX_REFCOUNT
1784+ if (fsr_fs(ifsr) == 2) {
1785+ unsigned int bkpt;
1786+
1787+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1788+ current->thread.error_code = ifsr;
1789+ current->thread.trap_no = 0;
1790+ pax_report_refcount_overflow(regs);
1791+ fixup_exception(regs);
1792+ return;
1793+ }
1794+ }
1795+#endif
1796+
1797 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1798 return;
1799
1800diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1801index ce8cb19..3ec539d 100644
1802--- a/arch/arm/mm/mmap.c
1803+++ b/arch/arm/mm/mmap.c
1804@@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1805 if (len > TASK_SIZE)
1806 return -ENOMEM;
1807
1808+#ifdef CONFIG_PAX_RANDMMAP
1809+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1810+#endif
1811+
1812 if (addr) {
1813 if (do_align)
1814 addr = COLOUR_ALIGN(addr, pgoff);
1815@@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1816 addr = PAGE_ALIGN(addr);
1817
1818 vma = find_vma(mm, addr);
1819- if (TASK_SIZE - len >= addr &&
1820- (!vma || addr + len <= vma->vm_start))
1821+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1822 return addr;
1823 }
1824 if (len > mm->cached_hole_size) {
1825- start_addr = addr = mm->free_area_cache;
1826+ start_addr = addr = mm->free_area_cache;
1827 } else {
1828- start_addr = addr = mm->mmap_base;
1829- mm->cached_hole_size = 0;
1830+ start_addr = addr = mm->mmap_base;
1831+ mm->cached_hole_size = 0;
1832 }
1833
1834 full_search:
1835@@ -124,14 +127,14 @@ full_search:
1836 * Start a new search - just in case we missed
1837 * some holes.
1838 */
1839- if (start_addr != TASK_UNMAPPED_BASE) {
1840- start_addr = addr = TASK_UNMAPPED_BASE;
1841+ if (start_addr != mm->mmap_base) {
1842+ start_addr = addr = mm->mmap_base;
1843 mm->cached_hole_size = 0;
1844 goto full_search;
1845 }
1846 return -ENOMEM;
1847 }
1848- if (!vma || addr + len <= vma->vm_start) {
1849+ if (check_heap_stack_gap(vma, addr, len)) {
1850 /*
1851 * Remember the place where we stopped the search:
1852 */
1853@@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1854
1855 if (mmap_is_legacy()) {
1856 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1857+
1858+#ifdef CONFIG_PAX_RANDMMAP
1859+ if (mm->pax_flags & MF_PAX_RANDMMAP)
1860+ mm->mmap_base += mm->delta_mmap;
1861+#endif
1862+
1863 mm->get_unmapped_area = arch_get_unmapped_area;
1864 mm->unmap_area = arch_unmap_area;
1865 } else {
1866 mm->mmap_base = mmap_base(random_factor);
1867+
1868+#ifdef CONFIG_PAX_RANDMMAP
1869+ if (mm->pax_flags & MF_PAX_RANDMMAP)
1870+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
1871+#endif
1872+
1873 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
1874 mm->unmap_area = arch_unmap_area_topdown;
1875 }
1876diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
1877index 71a6827..e7fbc23 100644
1878--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
1879+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
1880@@ -43,7 +43,7 @@ struct samsung_dma_ops {
1881 int (*started)(unsigned ch);
1882 int (*flush)(unsigned ch);
1883 int (*stop)(unsigned ch);
1884-};
1885+} __no_const;
1886
1887 extern void *samsung_dmadev_get_ops(void);
1888 extern void *s3c_dma_get_ops(void);
1889diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
1890index 5f28cae..3d23723 100644
1891--- a/arch/arm/plat-samsung/include/plat/ehci.h
1892+++ b/arch/arm/plat-samsung/include/plat/ehci.h
1893@@ -14,7 +14,7 @@
1894 struct s5p_ehci_platdata {
1895 int (*phy_init)(struct platform_device *pdev, int type);
1896 int (*phy_exit)(struct platform_device *pdev, int type);
1897-};
1898+} __no_const;
1899
1900 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
1901
1902diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
1903index c3a58a1..78fbf54 100644
1904--- a/arch/avr32/include/asm/cache.h
1905+++ b/arch/avr32/include/asm/cache.h
1906@@ -1,8 +1,10 @@
1907 #ifndef __ASM_AVR32_CACHE_H
1908 #define __ASM_AVR32_CACHE_H
1909
1910+#include <linux/const.h>
1911+
1912 #define L1_CACHE_SHIFT 5
1913-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1914+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1915
1916 /*
1917 * Memory returned by kmalloc() may be used for DMA, so we must make
1918diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
1919index 3b3159b..425ea94 100644
1920--- a/arch/avr32/include/asm/elf.h
1921+++ b/arch/avr32/include/asm/elf.h
1922@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
1923 the loader. We need to make sure that it is out of the way of the program
1924 that it will "exec", and that there is sufficient room for the brk. */
1925
1926-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1927+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1928
1929+#ifdef CONFIG_PAX_ASLR
1930+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
1931+
1932+#define PAX_DELTA_MMAP_LEN 15
1933+#define PAX_DELTA_STACK_LEN 15
1934+#endif
1935
1936 /* This yields a mask that user programs can use to figure out what
1937 instruction set this CPU supports. This could be done in user space,
1938diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
1939index b7f5c68..556135c 100644
1940--- a/arch/avr32/include/asm/kmap_types.h
1941+++ b/arch/avr32/include/asm/kmap_types.h
1942@@ -22,7 +22,8 @@ D(10) KM_IRQ0,
1943 D(11) KM_IRQ1,
1944 D(12) KM_SOFTIRQ0,
1945 D(13) KM_SOFTIRQ1,
1946-D(14) KM_TYPE_NR
1947+D(14) KM_CLEARPAGE,
1948+D(15) KM_TYPE_NR
1949 };
1950
1951 #undef D
1952diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
1953index f7040a1..db9f300 100644
1954--- a/arch/avr32/mm/fault.c
1955+++ b/arch/avr32/mm/fault.c
1956@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
1957
1958 int exception_trace = 1;
1959
1960+#ifdef CONFIG_PAX_PAGEEXEC
1961+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1962+{
1963+ unsigned long i;
1964+
1965+ printk(KERN_ERR "PAX: bytes at PC: ");
1966+ for (i = 0; i < 20; i++) {
1967+ unsigned char c;
1968+ if (get_user(c, (unsigned char *)pc+i))
1969+ printk(KERN_CONT "???????? ");
1970+ else
1971+ printk(KERN_CONT "%02x ", c);
1972+ }
1973+ printk("\n");
1974+}
1975+#endif
1976+
1977 /*
1978 * This routine handles page faults. It determines the address and the
1979 * problem, and then passes it off to one of the appropriate routines.
1980@@ -156,6 +173,16 @@ bad_area:
1981 up_read(&mm->mmap_sem);
1982
1983 if (user_mode(regs)) {
1984+
1985+#ifdef CONFIG_PAX_PAGEEXEC
1986+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
1987+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
1988+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
1989+ do_group_exit(SIGKILL);
1990+ }
1991+ }
1992+#endif
1993+
1994 if (exception_trace && printk_ratelimit())
1995 printk("%s%s[%d]: segfault at %08lx pc %08lx "
1996 "sp %08lx ecr %lu\n",
1997diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
1998index 568885a..f8008df 100644
1999--- a/arch/blackfin/include/asm/cache.h
2000+++ b/arch/blackfin/include/asm/cache.h
2001@@ -7,6 +7,7 @@
2002 #ifndef __ARCH_BLACKFIN_CACHE_H
2003 #define __ARCH_BLACKFIN_CACHE_H
2004
2005+#include <linux/const.h>
2006 #include <linux/linkage.h> /* for asmlinkage */
2007
2008 /*
2009@@ -14,7 +15,7 @@
2010 * Blackfin loads 32 bytes for cache
2011 */
2012 #define L1_CACHE_SHIFT 5
2013-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2014+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2015 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2016
2017 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2018diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2019index aea2718..3639a60 100644
2020--- a/arch/cris/include/arch-v10/arch/cache.h
2021+++ b/arch/cris/include/arch-v10/arch/cache.h
2022@@ -1,8 +1,9 @@
2023 #ifndef _ASM_ARCH_CACHE_H
2024 #define _ASM_ARCH_CACHE_H
2025
2026+#include <linux/const.h>
2027 /* Etrax 100LX have 32-byte cache-lines. */
2028-#define L1_CACHE_BYTES 32
2029 #define L1_CACHE_SHIFT 5
2030+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2031
2032 #endif /* _ASM_ARCH_CACHE_H */
2033diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2034index 1de779f..336fad3 100644
2035--- a/arch/cris/include/arch-v32/arch/cache.h
2036+++ b/arch/cris/include/arch-v32/arch/cache.h
2037@@ -1,11 +1,12 @@
2038 #ifndef _ASM_CRIS_ARCH_CACHE_H
2039 #define _ASM_CRIS_ARCH_CACHE_H
2040
2041+#include <linux/const.h>
2042 #include <arch/hwregs/dma.h>
2043
2044 /* A cache-line is 32 bytes. */
2045-#define L1_CACHE_BYTES 32
2046 #define L1_CACHE_SHIFT 5
2047+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2048
2049 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
2050
2051diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2052index 0d8a7d6..d0c9ff5 100644
2053--- a/arch/frv/include/asm/atomic.h
2054+++ b/arch/frv/include/asm/atomic.h
2055@@ -241,6 +241,16 @@ extern uint32_t __xchg_32(uint32_t i, volatile void *v);
2056 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2057 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2058
2059+#define atomic64_read_unchecked(v) atomic64_read(v)
2060+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2061+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2062+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2063+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2064+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2065+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2066+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2067+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2068+
2069 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2070 {
2071 int c, old;
2072diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2073index 2797163..c2a401d 100644
2074--- a/arch/frv/include/asm/cache.h
2075+++ b/arch/frv/include/asm/cache.h
2076@@ -12,10 +12,11 @@
2077 #ifndef __ASM_CACHE_H
2078 #define __ASM_CACHE_H
2079
2080+#include <linux/const.h>
2081
2082 /* bytes per L1 cache line */
2083 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2084-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2085+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2086
2087 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2088 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2089diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2090index f8e16b2..c73ff79 100644
2091--- a/arch/frv/include/asm/kmap_types.h
2092+++ b/arch/frv/include/asm/kmap_types.h
2093@@ -23,6 +23,7 @@ enum km_type {
2094 KM_IRQ1,
2095 KM_SOFTIRQ0,
2096 KM_SOFTIRQ1,
2097+ KM_CLEARPAGE,
2098 KM_TYPE_NR
2099 };
2100
2101diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2102index 385fd30..6c3d97e 100644
2103--- a/arch/frv/mm/elf-fdpic.c
2104+++ b/arch/frv/mm/elf-fdpic.c
2105@@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2106 if (addr) {
2107 addr = PAGE_ALIGN(addr);
2108 vma = find_vma(current->mm, addr);
2109- if (TASK_SIZE - len >= addr &&
2110- (!vma || addr + len <= vma->vm_start))
2111+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2112 goto success;
2113 }
2114
2115@@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2116 for (; vma; vma = vma->vm_next) {
2117 if (addr > limit)
2118 break;
2119- if (addr + len <= vma->vm_start)
2120+ if (check_heap_stack_gap(vma, addr, len))
2121 goto success;
2122 addr = vma->vm_end;
2123 }
2124@@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2125 for (; vma; vma = vma->vm_next) {
2126 if (addr > limit)
2127 break;
2128- if (addr + len <= vma->vm_start)
2129+ if (check_heap_stack_gap(vma, addr, len))
2130 goto success;
2131 addr = vma->vm_end;
2132 }
2133diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2134index c635028..6d9445a 100644
2135--- a/arch/h8300/include/asm/cache.h
2136+++ b/arch/h8300/include/asm/cache.h
2137@@ -1,8 +1,10 @@
2138 #ifndef __ARCH_H8300_CACHE_H
2139 #define __ARCH_H8300_CACHE_H
2140
2141+#include <linux/const.h>
2142+
2143 /* bytes per L1 cache line */
2144-#define L1_CACHE_BYTES 4
2145+#define L1_CACHE_BYTES _AC(4,UL)
2146
2147 /* m68k-elf-gcc 2.95.2 doesn't like these */
2148
2149diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2150index 0f01de2..d37d309 100644
2151--- a/arch/hexagon/include/asm/cache.h
2152+++ b/arch/hexagon/include/asm/cache.h
2153@@ -21,9 +21,11 @@
2154 #ifndef __ASM_CACHE_H
2155 #define __ASM_CACHE_H
2156
2157+#include <linux/const.h>
2158+
2159 /* Bytes per L1 cache line */
2160-#define L1_CACHE_SHIFT (5)
2161-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2162+#define L1_CACHE_SHIFT 5
2163+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2164
2165 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2166 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2167diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2168index 3fad89e..3047da5 100644
2169--- a/arch/ia64/include/asm/atomic.h
2170+++ b/arch/ia64/include/asm/atomic.h
2171@@ -209,6 +209,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2172 #define atomic64_inc(v) atomic64_add(1, (v))
2173 #define atomic64_dec(v) atomic64_sub(1, (v))
2174
2175+#define atomic64_read_unchecked(v) atomic64_read(v)
2176+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2177+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2178+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2179+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2180+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2181+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2182+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2183+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2184+
2185 /* Atomic operations are already serializing */
2186 #define smp_mb__before_atomic_dec() barrier()
2187 #define smp_mb__after_atomic_dec() barrier()
2188diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2189index 988254a..e1ee885 100644
2190--- a/arch/ia64/include/asm/cache.h
2191+++ b/arch/ia64/include/asm/cache.h
2192@@ -1,6 +1,7 @@
2193 #ifndef _ASM_IA64_CACHE_H
2194 #define _ASM_IA64_CACHE_H
2195
2196+#include <linux/const.h>
2197
2198 /*
2199 * Copyright (C) 1998-2000 Hewlett-Packard Co
2200@@ -9,7 +10,7 @@
2201
2202 /* Bytes per L1 (data) cache line. */
2203 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2204-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2205+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2206
2207 #ifdef CONFIG_SMP
2208 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2209diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2210index b5298eb..67c6e62 100644
2211--- a/arch/ia64/include/asm/elf.h
2212+++ b/arch/ia64/include/asm/elf.h
2213@@ -42,6 +42,13 @@
2214 */
2215 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2216
2217+#ifdef CONFIG_PAX_ASLR
2218+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2219+
2220+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2221+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2222+#endif
2223+
2224 #define PT_IA_64_UNWIND 0x70000001
2225
2226 /* IA-64 relocations: */
2227diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2228index 1a97af3..7529d31 100644
2229--- a/arch/ia64/include/asm/pgtable.h
2230+++ b/arch/ia64/include/asm/pgtable.h
2231@@ -12,7 +12,7 @@
2232 * David Mosberger-Tang <davidm@hpl.hp.com>
2233 */
2234
2235-
2236+#include <linux/const.h>
2237 #include <asm/mman.h>
2238 #include <asm/page.h>
2239 #include <asm/processor.h>
2240@@ -143,6 +143,17 @@
2241 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2242 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2243 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2244+
2245+#ifdef CONFIG_PAX_PAGEEXEC
2246+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2247+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2248+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2249+#else
2250+# define PAGE_SHARED_NOEXEC PAGE_SHARED
2251+# define PAGE_READONLY_NOEXEC PAGE_READONLY
2252+# define PAGE_COPY_NOEXEC PAGE_COPY
2253+#endif
2254+
2255 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2256 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2257 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2258diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2259index b77768d..e0795eb 100644
2260--- a/arch/ia64/include/asm/spinlock.h
2261+++ b/arch/ia64/include/asm/spinlock.h
2262@@ -72,7 +72,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2263 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2264
2265 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2266- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2267+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2268 }
2269
2270 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2271diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2272index 449c8c0..432a3d2 100644
2273--- a/arch/ia64/include/asm/uaccess.h
2274+++ b/arch/ia64/include/asm/uaccess.h
2275@@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2276 const void *__cu_from = (from); \
2277 long __cu_len = (n); \
2278 \
2279- if (__access_ok(__cu_to, __cu_len, get_fs())) \
2280+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2281 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2282 __cu_len; \
2283 })
2284@@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2285 long __cu_len = (n); \
2286 \
2287 __chk_user_ptr(__cu_from); \
2288- if (__access_ok(__cu_from, __cu_len, get_fs())) \
2289+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2290 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2291 __cu_len; \
2292 })
2293diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2294index 24603be..948052d 100644
2295--- a/arch/ia64/kernel/module.c
2296+++ b/arch/ia64/kernel/module.c
2297@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2298 void
2299 module_free (struct module *mod, void *module_region)
2300 {
2301- if (mod && mod->arch.init_unw_table &&
2302- module_region == mod->module_init) {
2303+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2304 unw_remove_unwind_table(mod->arch.init_unw_table);
2305 mod->arch.init_unw_table = NULL;
2306 }
2307@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2308 }
2309
2310 static inline int
2311+in_init_rx (const struct module *mod, uint64_t addr)
2312+{
2313+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2314+}
2315+
2316+static inline int
2317+in_init_rw (const struct module *mod, uint64_t addr)
2318+{
2319+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2320+}
2321+
2322+static inline int
2323 in_init (const struct module *mod, uint64_t addr)
2324 {
2325- return addr - (uint64_t) mod->module_init < mod->init_size;
2326+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2327+}
2328+
2329+static inline int
2330+in_core_rx (const struct module *mod, uint64_t addr)
2331+{
2332+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2333+}
2334+
2335+static inline int
2336+in_core_rw (const struct module *mod, uint64_t addr)
2337+{
2338+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2339 }
2340
2341 static inline int
2342 in_core (const struct module *mod, uint64_t addr)
2343 {
2344- return addr - (uint64_t) mod->module_core < mod->core_size;
2345+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2346 }
2347
2348 static inline int
2349@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2350 break;
2351
2352 case RV_BDREL:
2353- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2354+ if (in_init_rx(mod, val))
2355+ val -= (uint64_t) mod->module_init_rx;
2356+ else if (in_init_rw(mod, val))
2357+ val -= (uint64_t) mod->module_init_rw;
2358+ else if (in_core_rx(mod, val))
2359+ val -= (uint64_t) mod->module_core_rx;
2360+ else if (in_core_rw(mod, val))
2361+ val -= (uint64_t) mod->module_core_rw;
2362 break;
2363
2364 case RV_LTV:
2365@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2366 * addresses have been selected...
2367 */
2368 uint64_t gp;
2369- if (mod->core_size > MAX_LTOFF)
2370+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2371 /*
2372 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2373 * at the end of the module.
2374 */
2375- gp = mod->core_size - MAX_LTOFF / 2;
2376+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2377 else
2378- gp = mod->core_size / 2;
2379- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2380+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2381+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2382 mod->arch.gp = gp;
2383 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2384 }
2385diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2386index 609d500..7dde2a8 100644
2387--- a/arch/ia64/kernel/sys_ia64.c
2388+++ b/arch/ia64/kernel/sys_ia64.c
2389@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2390 if (REGION_NUMBER(addr) == RGN_HPAGE)
2391 addr = 0;
2392 #endif
2393+
2394+#ifdef CONFIG_PAX_RANDMMAP
2395+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2396+ addr = mm->free_area_cache;
2397+ else
2398+#endif
2399+
2400 if (!addr)
2401 addr = mm->free_area_cache;
2402
2403@@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2404 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2405 /* At this point: (!vma || addr < vma->vm_end). */
2406 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2407- if (start_addr != TASK_UNMAPPED_BASE) {
2408+ if (start_addr != mm->mmap_base) {
2409 /* Start a new search --- just in case we missed some holes. */
2410- addr = TASK_UNMAPPED_BASE;
2411+ addr = mm->mmap_base;
2412 goto full_search;
2413 }
2414 return -ENOMEM;
2415 }
2416- if (!vma || addr + len <= vma->vm_start) {
2417+ if (check_heap_stack_gap(vma, addr, len)) {
2418 /* Remember the address where we stopped this search: */
2419 mm->free_area_cache = addr + len;
2420 return addr;
2421diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2422index 53c0ba0..2accdde 100644
2423--- a/arch/ia64/kernel/vmlinux.lds.S
2424+++ b/arch/ia64/kernel/vmlinux.lds.S
2425@@ -199,7 +199,7 @@ SECTIONS {
2426 /* Per-cpu data: */
2427 . = ALIGN(PERCPU_PAGE_SIZE);
2428 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2429- __phys_per_cpu_start = __per_cpu_load;
2430+ __phys_per_cpu_start = per_cpu_load;
2431 /*
2432 * ensure percpu data fits
2433 * into percpu page size
2434diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2435index 20b3593..1ce77f0 100644
2436--- a/arch/ia64/mm/fault.c
2437+++ b/arch/ia64/mm/fault.c
2438@@ -73,6 +73,23 @@ mapped_kernel_page_is_present (unsigned long address)
2439 return pte_present(pte);
2440 }
2441
2442+#ifdef CONFIG_PAX_PAGEEXEC
2443+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2444+{
2445+ unsigned long i;
2446+
2447+ printk(KERN_ERR "PAX: bytes at PC: ");
2448+ for (i = 0; i < 8; i++) {
2449+ unsigned int c;
2450+ if (get_user(c, (unsigned int *)pc+i))
2451+ printk(KERN_CONT "???????? ");
2452+ else
2453+ printk(KERN_CONT "%08x ", c);
2454+ }
2455+ printk("\n");
2456+}
2457+#endif
2458+
2459 void __kprobes
2460 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2461 {
2462@@ -146,9 +163,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2463 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2464 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2465
2466- if ((vma->vm_flags & mask) != mask)
2467+ if ((vma->vm_flags & mask) != mask) {
2468+
2469+#ifdef CONFIG_PAX_PAGEEXEC
2470+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2471+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2472+ goto bad_area;
2473+
2474+ up_read(&mm->mmap_sem);
2475+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2476+ do_group_exit(SIGKILL);
2477+ }
2478+#endif
2479+
2480 goto bad_area;
2481
2482+ }
2483+
2484 /*
2485 * If for any reason at all we couldn't handle the fault, make
2486 * sure we exit gracefully rather than endlessly redo the
2487diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2488index 5ca674b..e0e1b70 100644
2489--- a/arch/ia64/mm/hugetlbpage.c
2490+++ b/arch/ia64/mm/hugetlbpage.c
2491@@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2492 /* At this point: (!vmm || addr < vmm->vm_end). */
2493 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2494 return -ENOMEM;
2495- if (!vmm || (addr + len) <= vmm->vm_start)
2496+ if (check_heap_stack_gap(vmm, addr, len))
2497 return addr;
2498 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2499 }
2500diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2501index 13df239d..cb52116 100644
2502--- a/arch/ia64/mm/init.c
2503+++ b/arch/ia64/mm/init.c
2504@@ -121,6 +121,19 @@ ia64_init_addr_space (void)
2505 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2506 vma->vm_end = vma->vm_start + PAGE_SIZE;
2507 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2508+
2509+#ifdef CONFIG_PAX_PAGEEXEC
2510+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2511+ vma->vm_flags &= ~VM_EXEC;
2512+
2513+#ifdef CONFIG_PAX_MPROTECT
2514+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
2515+ vma->vm_flags &= ~VM_MAYEXEC;
2516+#endif
2517+
2518+ }
2519+#endif
2520+
2521 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2522 down_write(&current->mm->mmap_sem);
2523 if (insert_vm_struct(current->mm, vma)) {
2524diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2525index 40b3ee9..8c2c112 100644
2526--- a/arch/m32r/include/asm/cache.h
2527+++ b/arch/m32r/include/asm/cache.h
2528@@ -1,8 +1,10 @@
2529 #ifndef _ASM_M32R_CACHE_H
2530 #define _ASM_M32R_CACHE_H
2531
2532+#include <linux/const.h>
2533+
2534 /* L1 cache line size */
2535 #define L1_CACHE_SHIFT 4
2536-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2537+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2538
2539 #endif /* _ASM_M32R_CACHE_H */
2540diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2541index 82abd15..d95ae5d 100644
2542--- a/arch/m32r/lib/usercopy.c
2543+++ b/arch/m32r/lib/usercopy.c
2544@@ -14,6 +14,9 @@
2545 unsigned long
2546 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2547 {
2548+ if ((long)n < 0)
2549+ return n;
2550+
2551 prefetch(from);
2552 if (access_ok(VERIFY_WRITE, to, n))
2553 __copy_user(to,from,n);
2554@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2555 unsigned long
2556 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2557 {
2558+ if ((long)n < 0)
2559+ return n;
2560+
2561 prefetchw(to);
2562 if (access_ok(VERIFY_READ, from, n))
2563 __copy_user_zeroing(to,from,n);
2564diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2565index 0395c51..5f26031 100644
2566--- a/arch/m68k/include/asm/cache.h
2567+++ b/arch/m68k/include/asm/cache.h
2568@@ -4,9 +4,11 @@
2569 #ifndef __ARCH_M68K_CACHE_H
2570 #define __ARCH_M68K_CACHE_H
2571
2572+#include <linux/const.h>
2573+
2574 /* bytes per L1 cache line */
2575 #define L1_CACHE_SHIFT 4
2576-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2577+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2578
2579 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2580
2581diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2582index 4efe96a..60e8699 100644
2583--- a/arch/microblaze/include/asm/cache.h
2584+++ b/arch/microblaze/include/asm/cache.h
2585@@ -13,11 +13,12 @@
2586 #ifndef _ASM_MICROBLAZE_CACHE_H
2587 #define _ASM_MICROBLAZE_CACHE_H
2588
2589+#include <linux/const.h>
2590 #include <asm/registers.h>
2591
2592 #define L1_CACHE_SHIFT 5
2593 /* word-granular cache in microblaze */
2594-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2595+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2596
2597 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2598
2599diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2600index 1d93f81..67794d0 100644
2601--- a/arch/mips/include/asm/atomic.h
2602+++ b/arch/mips/include/asm/atomic.h
2603@@ -21,6 +21,10 @@
2604 #include <asm/war.h>
2605 #include <asm/system.h>
2606
2607+#ifdef CONFIG_GENERIC_ATOMIC64
2608+#include <asm-generic/atomic64.h>
2609+#endif
2610+
2611 #define ATOMIC_INIT(i) { (i) }
2612
2613 /*
2614@@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2615 */
2616 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2617
2618+#define atomic64_read_unchecked(v) atomic64_read(v)
2619+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2620+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2621+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2622+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2623+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2624+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2625+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2626+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2627+
2628 #endif /* CONFIG_64BIT */
2629
2630 /*
2631diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2632index b4db69f..8f3b093 100644
2633--- a/arch/mips/include/asm/cache.h
2634+++ b/arch/mips/include/asm/cache.h
2635@@ -9,10 +9,11 @@
2636 #ifndef _ASM_CACHE_H
2637 #define _ASM_CACHE_H
2638
2639+#include <linux/const.h>
2640 #include <kmalloc.h>
2641
2642 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2643-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2644+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2645
2646 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2647 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2648diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2649index 455c0ac..ad65fbe 100644
2650--- a/arch/mips/include/asm/elf.h
2651+++ b/arch/mips/include/asm/elf.h
2652@@ -372,13 +372,16 @@ extern const char *__elf_platform;
2653 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2654 #endif
2655
2656+#ifdef CONFIG_PAX_ASLR
2657+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2658+
2659+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2660+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2661+#endif
2662+
2663 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2664 struct linux_binprm;
2665 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2666 int uses_interp);
2667
2668-struct mm_struct;
2669-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2670-#define arch_randomize_brk arch_randomize_brk
2671-
2672 #endif /* _ASM_ELF_H */
2673diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2674index da9bd7d..91aa7ab 100644
2675--- a/arch/mips/include/asm/page.h
2676+++ b/arch/mips/include/asm/page.h
2677@@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2678 #ifdef CONFIG_CPU_MIPS32
2679 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2680 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2681- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2682+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2683 #else
2684 typedef struct { unsigned long long pte; } pte_t;
2685 #define pte_val(x) ((x).pte)
2686diff --git a/arch/mips/include/asm/system.h b/arch/mips/include/asm/system.h
2687index 6018c80..7c37203 100644
2688--- a/arch/mips/include/asm/system.h
2689+++ b/arch/mips/include/asm/system.h
2690@@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
2691 */
2692 #define __ARCH_WANT_UNLOCKED_CTXSW
2693
2694-extern unsigned long arch_align_stack(unsigned long sp);
2695+#define arch_align_stack(x) ((x) & ~0xfUL)
2696
2697 #endif /* _ASM_SYSTEM_H */
2698diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2699index 9fdd8bc..4bd7f1a 100644
2700--- a/arch/mips/kernel/binfmt_elfn32.c
2701+++ b/arch/mips/kernel/binfmt_elfn32.c
2702@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2703 #undef ELF_ET_DYN_BASE
2704 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2705
2706+#ifdef CONFIG_PAX_ASLR
2707+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2708+
2709+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2710+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2711+#endif
2712+
2713 #include <asm/processor.h>
2714 #include <linux/module.h>
2715 #include <linux/elfcore.h>
2716diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2717index ff44823..97f8906 100644
2718--- a/arch/mips/kernel/binfmt_elfo32.c
2719+++ b/arch/mips/kernel/binfmt_elfo32.c
2720@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2721 #undef ELF_ET_DYN_BASE
2722 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2723
2724+#ifdef CONFIG_PAX_ASLR
2725+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2726+
2727+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2728+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2729+#endif
2730+
2731 #include <asm/processor.h>
2732
2733 /*
2734diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2735index 7955409..ceaea7c 100644
2736--- a/arch/mips/kernel/process.c
2737+++ b/arch/mips/kernel/process.c
2738@@ -483,15 +483,3 @@ unsigned long get_wchan(struct task_struct *task)
2739 out:
2740 return pc;
2741 }
2742-
2743-/*
2744- * Don't forget that the stack pointer must be aligned on a 8 bytes
2745- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2746- */
2747-unsigned long arch_align_stack(unsigned long sp)
2748-{
2749- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2750- sp -= get_random_int() & ~PAGE_MASK;
2751-
2752- return sp & ALMASK;
2753-}
2754diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
2755index 69ebd58..e4bff83 100644
2756--- a/arch/mips/mm/fault.c
2757+++ b/arch/mips/mm/fault.c
2758@@ -28,6 +28,23 @@
2759 #include <asm/highmem.h> /* For VMALLOC_END */
2760 #include <linux/kdebug.h>
2761
2762+#ifdef CONFIG_PAX_PAGEEXEC
2763+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2764+{
2765+ unsigned long i;
2766+
2767+ printk(KERN_ERR "PAX: bytes at PC: ");
2768+ for (i = 0; i < 5; i++) {
2769+ unsigned int c;
2770+ if (get_user(c, (unsigned int *)pc+i))
2771+ printk(KERN_CONT "???????? ");
2772+ else
2773+ printk(KERN_CONT "%08x ", c);
2774+ }
2775+ printk("\n");
2776+}
2777+#endif
2778+
2779 /*
2780 * This routine handles page faults. It determines the address,
2781 * and the problem, and then passes it off to one of the appropriate
2782diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
2783index 302d779..7d35bf8 100644
2784--- a/arch/mips/mm/mmap.c
2785+++ b/arch/mips/mm/mmap.c
2786@@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2787 do_color_align = 1;
2788
2789 /* requesting a specific address */
2790+
2791+#ifdef CONFIG_PAX_RANDMMAP
2792+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2793+#endif
2794+
2795 if (addr) {
2796 if (do_color_align)
2797 addr = COLOUR_ALIGN(addr, pgoff);
2798@@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2799 addr = PAGE_ALIGN(addr);
2800
2801 vma = find_vma(mm, addr);
2802- if (TASK_SIZE - len >= addr &&
2803- (!vma || addr + len <= vma->vm_start))
2804+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
2805 return addr;
2806 }
2807
2808@@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2809 /* At this point: (!vma || addr < vma->vm_end). */
2810 if (TASK_SIZE - len < addr)
2811 return -ENOMEM;
2812- if (!vma || addr + len <= vma->vm_start)
2813+ if (check_heap_stack_gap(vmm, addr, len))
2814 return addr;
2815 addr = vma->vm_end;
2816 if (do_color_align)
2817@@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2818 /* make sure it can fit in the remaining address space */
2819 if (likely(addr > len)) {
2820 vma = find_vma(mm, addr - len);
2821- if (!vma || addr <= vma->vm_start) {
2822+ if (check_heap_stack_gap(vmm, addr - len, len))
2823 /* cache the address as a hint for next time */
2824 return mm->free_area_cache = addr - len;
2825 }
2826@@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
2827 * return with success:
2828 */
2829 vma = find_vma(mm, addr);
2830- if (likely(!vma || addr + len <= vma->vm_start)) {
2831+ if (check_heap_stack_gap(vmm, addr, len)) {
2832 /* cache the address as a hint for next time */
2833 return mm->free_area_cache = addr;
2834 }
2835@@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2836 mm->unmap_area = arch_unmap_area_topdown;
2837 }
2838 }
2839-
2840-static inline unsigned long brk_rnd(void)
2841-{
2842- unsigned long rnd = get_random_int();
2843-
2844- rnd = rnd << PAGE_SHIFT;
2845- /* 8MB for 32bit, 256MB for 64bit */
2846- if (TASK_IS_32BIT_ADDR)
2847- rnd = rnd & 0x7ffffful;
2848- else
2849- rnd = rnd & 0xffffffful;
2850-
2851- return rnd;
2852-}
2853-
2854-unsigned long arch_randomize_brk(struct mm_struct *mm)
2855-{
2856- unsigned long base = mm->brk;
2857- unsigned long ret;
2858-
2859- ret = PAGE_ALIGN(base + brk_rnd());
2860-
2861- if (ret < mm->brk)
2862- return mm->brk;
2863-
2864- return ret;
2865-}
2866diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
2867index 967d144..db12197 100644
2868--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
2869+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
2870@@ -11,12 +11,14 @@
2871 #ifndef _ASM_PROC_CACHE_H
2872 #define _ASM_PROC_CACHE_H
2873
2874+#include <linux/const.h>
2875+
2876 /* L1 cache */
2877
2878 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
2879 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
2880-#define L1_CACHE_BYTES 16 /* bytes per entry */
2881 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
2882+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
2883 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
2884
2885 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
2886diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2887index bcb5df2..84fabd2 100644
2888--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2889+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
2890@@ -16,13 +16,15 @@
2891 #ifndef _ASM_PROC_CACHE_H
2892 #define _ASM_PROC_CACHE_H
2893
2894+#include <linux/const.h>
2895+
2896 /*
2897 * L1 cache
2898 */
2899 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
2900 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
2901-#define L1_CACHE_BYTES 32 /* bytes per entry */
2902 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
2903+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
2904 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
2905
2906 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
2907diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
2908index 4ce7a01..449202a 100644
2909--- a/arch/openrisc/include/asm/cache.h
2910+++ b/arch/openrisc/include/asm/cache.h
2911@@ -19,11 +19,13 @@
2912 #ifndef __ASM_OPENRISC_CACHE_H
2913 #define __ASM_OPENRISC_CACHE_H
2914
2915+#include <linux/const.h>
2916+
2917 /* FIXME: How can we replace these with values from the CPU...
2918 * they shouldn't be hard-coded!
2919 */
2920
2921-#define L1_CACHE_BYTES 16
2922 #define L1_CACHE_SHIFT 4
2923+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2924
2925 #endif /* __ASM_OPENRISC_CACHE_H */
2926diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
2927index 4054b31..a10c105 100644
2928--- a/arch/parisc/include/asm/atomic.h
2929+++ b/arch/parisc/include/asm/atomic.h
2930@@ -335,6 +335,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2931
2932 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
2933
2934+#define atomic64_read_unchecked(v) atomic64_read(v)
2935+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2936+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2937+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2938+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2939+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2940+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2941+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2942+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2943+
2944 #endif /* !CONFIG_64BIT */
2945
2946
2947diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
2948index 47f11c7..3420df2 100644
2949--- a/arch/parisc/include/asm/cache.h
2950+++ b/arch/parisc/include/asm/cache.h
2951@@ -5,6 +5,7 @@
2952 #ifndef __ARCH_PARISC_CACHE_H
2953 #define __ARCH_PARISC_CACHE_H
2954
2955+#include <linux/const.h>
2956
2957 /*
2958 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
2959@@ -15,13 +16,13 @@
2960 * just ruin performance.
2961 */
2962 #ifdef CONFIG_PA20
2963-#define L1_CACHE_BYTES 64
2964 #define L1_CACHE_SHIFT 6
2965 #else
2966-#define L1_CACHE_BYTES 32
2967 #define L1_CACHE_SHIFT 5
2968 #endif
2969
2970+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2971+
2972 #ifndef __ASSEMBLY__
2973
2974 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2975diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
2976index 19f6cb1..6c78cf2 100644
2977--- a/arch/parisc/include/asm/elf.h
2978+++ b/arch/parisc/include/asm/elf.h
2979@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
2980
2981 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
2982
2983+#ifdef CONFIG_PAX_ASLR
2984+#define PAX_ELF_ET_DYN_BASE 0x10000UL
2985+
2986+#define PAX_DELTA_MMAP_LEN 16
2987+#define PAX_DELTA_STACK_LEN 16
2988+#endif
2989+
2990 /* This yields a mask that user programs can use to figure out what
2991 instruction set this CPU supports. This could be done in user space,
2992 but it's not easy, and we've already done it here. */
2993diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
2994index 22dadeb..f6c2be4 100644
2995--- a/arch/parisc/include/asm/pgtable.h
2996+++ b/arch/parisc/include/asm/pgtable.h
2997@@ -210,6 +210,17 @@ struct vm_area_struct;
2998 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
2999 #define PAGE_COPY PAGE_EXECREAD
3000 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3001+
3002+#ifdef CONFIG_PAX_PAGEEXEC
3003+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3004+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3005+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3006+#else
3007+# define PAGE_SHARED_NOEXEC PAGE_SHARED
3008+# define PAGE_COPY_NOEXEC PAGE_COPY
3009+# define PAGE_READONLY_NOEXEC PAGE_READONLY
3010+#endif
3011+
3012 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3013 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3014 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3015diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3016index 5e34ccf..672bc9c 100644
3017--- a/arch/parisc/kernel/module.c
3018+++ b/arch/parisc/kernel/module.c
3019@@ -98,16 +98,38 @@
3020
3021 /* three functions to determine where in the module core
3022 * or init pieces the location is */
3023+static inline int in_init_rx(struct module *me, void *loc)
3024+{
3025+ return (loc >= me->module_init_rx &&
3026+ loc < (me->module_init_rx + me->init_size_rx));
3027+}
3028+
3029+static inline int in_init_rw(struct module *me, void *loc)
3030+{
3031+ return (loc >= me->module_init_rw &&
3032+ loc < (me->module_init_rw + me->init_size_rw));
3033+}
3034+
3035 static inline int in_init(struct module *me, void *loc)
3036 {
3037- return (loc >= me->module_init &&
3038- loc <= (me->module_init + me->init_size));
3039+ return in_init_rx(me, loc) || in_init_rw(me, loc);
3040+}
3041+
3042+static inline int in_core_rx(struct module *me, void *loc)
3043+{
3044+ return (loc >= me->module_core_rx &&
3045+ loc < (me->module_core_rx + me->core_size_rx));
3046+}
3047+
3048+static inline int in_core_rw(struct module *me, void *loc)
3049+{
3050+ return (loc >= me->module_core_rw &&
3051+ loc < (me->module_core_rw + me->core_size_rw));
3052 }
3053
3054 static inline int in_core(struct module *me, void *loc)
3055 {
3056- return (loc >= me->module_core &&
3057- loc <= (me->module_core + me->core_size));
3058+ return in_core_rx(me, loc) || in_core_rw(me, loc);
3059 }
3060
3061 static inline int in_local(struct module *me, void *loc)
3062@@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3063 }
3064
3065 /* align things a bit */
3066- me->core_size = ALIGN(me->core_size, 16);
3067- me->arch.got_offset = me->core_size;
3068- me->core_size += gots * sizeof(struct got_entry);
3069+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3070+ me->arch.got_offset = me->core_size_rw;
3071+ me->core_size_rw += gots * sizeof(struct got_entry);
3072
3073- me->core_size = ALIGN(me->core_size, 16);
3074- me->arch.fdesc_offset = me->core_size;
3075- me->core_size += fdescs * sizeof(Elf_Fdesc);
3076+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3077+ me->arch.fdesc_offset = me->core_size_rw;
3078+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3079
3080 me->arch.got_max = gots;
3081 me->arch.fdesc_max = fdescs;
3082@@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3083
3084 BUG_ON(value == 0);
3085
3086- got = me->module_core + me->arch.got_offset;
3087+ got = me->module_core_rw + me->arch.got_offset;
3088 for (i = 0; got[i].addr; i++)
3089 if (got[i].addr == value)
3090 goto out;
3091@@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3092 #ifdef CONFIG_64BIT
3093 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3094 {
3095- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3096+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3097
3098 if (!value) {
3099 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3100@@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3101
3102 /* Create new one */
3103 fdesc->addr = value;
3104- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3105+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3106 return (Elf_Addr)fdesc;
3107 }
3108 #endif /* CONFIG_64BIT */
3109@@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3110
3111 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3112 end = table + sechdrs[me->arch.unwind_section].sh_size;
3113- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3114+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3115
3116 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3117 me->arch.unwind_section, table, end, gp);
3118diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3119index c9b9322..02d8940 100644
3120--- a/arch/parisc/kernel/sys_parisc.c
3121+++ b/arch/parisc/kernel/sys_parisc.c
3122@@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3123 /* At this point: (!vma || addr < vma->vm_end). */
3124 if (TASK_SIZE - len < addr)
3125 return -ENOMEM;
3126- if (!vma || addr + len <= vma->vm_start)
3127+ if (check_heap_stack_gap(vma, addr, len))
3128 return addr;
3129 addr = vma->vm_end;
3130 }
3131@@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3132 /* At this point: (!vma || addr < vma->vm_end). */
3133 if (TASK_SIZE - len < addr)
3134 return -ENOMEM;
3135- if (!vma || addr + len <= vma->vm_start)
3136+ if (check_heap_stack_gap(vma, addr, len))
3137 return addr;
3138 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3139 if (addr < vma->vm_end) /* handle wraparound */
3140@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3141 if (flags & MAP_FIXED)
3142 return addr;
3143 if (!addr)
3144- addr = TASK_UNMAPPED_BASE;
3145+ addr = current->mm->mmap_base;
3146
3147 if (filp) {
3148 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3149diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3150index f19e660..414fe24 100644
3151--- a/arch/parisc/kernel/traps.c
3152+++ b/arch/parisc/kernel/traps.c
3153@@ -733,9 +733,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3154
3155 down_read(&current->mm->mmap_sem);
3156 vma = find_vma(current->mm,regs->iaoq[0]);
3157- if (vma && (regs->iaoq[0] >= vma->vm_start)
3158- && (vma->vm_flags & VM_EXEC)) {
3159-
3160+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3161 fault_address = regs->iaoq[0];
3162 fault_space = regs->iasq[0];
3163
3164diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3165index 18162ce..94de376 100644
3166--- a/arch/parisc/mm/fault.c
3167+++ b/arch/parisc/mm/fault.c
3168@@ -15,6 +15,7 @@
3169 #include <linux/sched.h>
3170 #include <linux/interrupt.h>
3171 #include <linux/module.h>
3172+#include <linux/unistd.h>
3173
3174 #include <asm/uaccess.h>
3175 #include <asm/traps.h>
3176@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3177 static unsigned long
3178 parisc_acctyp(unsigned long code, unsigned int inst)
3179 {
3180- if (code == 6 || code == 16)
3181+ if (code == 6 || code == 7 || code == 16)
3182 return VM_EXEC;
3183
3184 switch (inst & 0xf0000000) {
3185@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3186 }
3187 #endif
3188
3189+#ifdef CONFIG_PAX_PAGEEXEC
3190+/*
3191+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3192+ *
3193+ * returns 1 when task should be killed
3194+ * 2 when rt_sigreturn trampoline was detected
3195+ * 3 when unpatched PLT trampoline was detected
3196+ */
3197+static int pax_handle_fetch_fault(struct pt_regs *regs)
3198+{
3199+
3200+#ifdef CONFIG_PAX_EMUPLT
3201+ int err;
3202+
3203+ do { /* PaX: unpatched PLT emulation */
3204+ unsigned int bl, depwi;
3205+
3206+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3207+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3208+
3209+ if (err)
3210+ break;
3211+
3212+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3213+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3214+
3215+ err = get_user(ldw, (unsigned int *)addr);
3216+ err |= get_user(bv, (unsigned int *)(addr+4));
3217+ err |= get_user(ldw2, (unsigned int *)(addr+8));
3218+
3219+ if (err)
3220+ break;
3221+
3222+ if (ldw == 0x0E801096U &&
3223+ bv == 0xEAC0C000U &&
3224+ ldw2 == 0x0E881095U)
3225+ {
3226+ unsigned int resolver, map;
3227+
3228+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3229+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3230+ if (err)
3231+ break;
3232+
3233+ regs->gr[20] = instruction_pointer(regs)+8;
3234+ regs->gr[21] = map;
3235+ regs->gr[22] = resolver;
3236+ regs->iaoq[0] = resolver | 3UL;
3237+ regs->iaoq[1] = regs->iaoq[0] + 4;
3238+ return 3;
3239+ }
3240+ }
3241+ } while (0);
3242+#endif
3243+
3244+#ifdef CONFIG_PAX_EMUTRAMP
3245+
3246+#ifndef CONFIG_PAX_EMUSIGRT
3247+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3248+ return 1;
3249+#endif
3250+
3251+ do { /* PaX: rt_sigreturn emulation */
3252+ unsigned int ldi1, ldi2, bel, nop;
3253+
3254+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3255+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3256+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3257+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3258+
3259+ if (err)
3260+ break;
3261+
3262+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3263+ ldi2 == 0x3414015AU &&
3264+ bel == 0xE4008200U &&
3265+ nop == 0x08000240U)
3266+ {
3267+ regs->gr[25] = (ldi1 & 2) >> 1;
3268+ regs->gr[20] = __NR_rt_sigreturn;
3269+ regs->gr[31] = regs->iaoq[1] + 16;
3270+ regs->sr[0] = regs->iasq[1];
3271+ regs->iaoq[0] = 0x100UL;
3272+ regs->iaoq[1] = regs->iaoq[0] + 4;
3273+ regs->iasq[0] = regs->sr[2];
3274+ regs->iasq[1] = regs->sr[2];
3275+ return 2;
3276+ }
3277+ } while (0);
3278+#endif
3279+
3280+ return 1;
3281+}
3282+
3283+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3284+{
3285+ unsigned long i;
3286+
3287+ printk(KERN_ERR "PAX: bytes at PC: ");
3288+ for (i = 0; i < 5; i++) {
3289+ unsigned int c;
3290+ if (get_user(c, (unsigned int *)pc+i))
3291+ printk(KERN_CONT "???????? ");
3292+ else
3293+ printk(KERN_CONT "%08x ", c);
3294+ }
3295+ printk("\n");
3296+}
3297+#endif
3298+
3299 int fixup_exception(struct pt_regs *regs)
3300 {
3301 const struct exception_table_entry *fix;
3302@@ -192,8 +303,33 @@ good_area:
3303
3304 acc_type = parisc_acctyp(code,regs->iir);
3305
3306- if ((vma->vm_flags & acc_type) != acc_type)
3307+ if ((vma->vm_flags & acc_type) != acc_type) {
3308+
3309+#ifdef CONFIG_PAX_PAGEEXEC
3310+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3311+ (address & ~3UL) == instruction_pointer(regs))
3312+ {
3313+ up_read(&mm->mmap_sem);
3314+ switch (pax_handle_fetch_fault(regs)) {
3315+
3316+#ifdef CONFIG_PAX_EMUPLT
3317+ case 3:
3318+ return;
3319+#endif
3320+
3321+#ifdef CONFIG_PAX_EMUTRAMP
3322+ case 2:
3323+ return;
3324+#endif
3325+
3326+ }
3327+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3328+ do_group_exit(SIGKILL);
3329+ }
3330+#endif
3331+
3332 goto bad_area;
3333+ }
3334
3335 /*
3336 * If for any reason at all we couldn't handle the fault, make
3337diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3338index 02e41b5..ec6e26c 100644
3339--- a/arch/powerpc/include/asm/atomic.h
3340+++ b/arch/powerpc/include/asm/atomic.h
3341@@ -469,6 +469,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3342
3343 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3344
3345+#define atomic64_read_unchecked(v) atomic64_read(v)
3346+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3347+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3348+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3349+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3350+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3351+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3352+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3353+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3354+
3355 #endif /* __powerpc64__ */
3356
3357 #endif /* __KERNEL__ */
3358diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3359index 4b50941..5605819 100644
3360--- a/arch/powerpc/include/asm/cache.h
3361+++ b/arch/powerpc/include/asm/cache.h
3362@@ -3,6 +3,7 @@
3363
3364 #ifdef __KERNEL__
3365
3366+#include <linux/const.h>
3367
3368 /* bytes per L1 cache line */
3369 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3370@@ -22,7 +23,7 @@
3371 #define L1_CACHE_SHIFT 7
3372 #endif
3373
3374-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3375+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3376
3377 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3378
3379diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3380index 3bf9cca..e7457d0 100644
3381--- a/arch/powerpc/include/asm/elf.h
3382+++ b/arch/powerpc/include/asm/elf.h
3383@@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3384 the loader. We need to make sure that it is out of the way of the program
3385 that it will "exec", and that there is sufficient room for the brk. */
3386
3387-extern unsigned long randomize_et_dyn(unsigned long base);
3388-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3389+#define ELF_ET_DYN_BASE (0x20000000)
3390+
3391+#ifdef CONFIG_PAX_ASLR
3392+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3393+
3394+#ifdef __powerpc64__
3395+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3396+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3397+#else
3398+#define PAX_DELTA_MMAP_LEN 15
3399+#define PAX_DELTA_STACK_LEN 15
3400+#endif
3401+#endif
3402
3403 /*
3404 * Our registers are always unsigned longs, whether we're a 32 bit
3405@@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3406 (0x7ff >> (PAGE_SHIFT - 12)) : \
3407 (0x3ffff >> (PAGE_SHIFT - 12)))
3408
3409-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3410-#define arch_randomize_brk arch_randomize_brk
3411-
3412 #endif /* __KERNEL__ */
3413
3414 /*
3415diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3416index bca8fdc..61e9580 100644
3417--- a/arch/powerpc/include/asm/kmap_types.h
3418+++ b/arch/powerpc/include/asm/kmap_types.h
3419@@ -27,6 +27,7 @@ enum km_type {
3420 KM_PPC_SYNC_PAGE,
3421 KM_PPC_SYNC_ICACHE,
3422 KM_KDB,
3423+ KM_CLEARPAGE,
3424 KM_TYPE_NR
3425 };
3426
3427diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3428index d4a7f64..451de1c 100644
3429--- a/arch/powerpc/include/asm/mman.h
3430+++ b/arch/powerpc/include/asm/mman.h
3431@@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3432 }
3433 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3434
3435-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3436+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3437 {
3438 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3439 }
3440diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3441index f072e97..b436dee 100644
3442--- a/arch/powerpc/include/asm/page.h
3443+++ b/arch/powerpc/include/asm/page.h
3444@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3445 * and needs to be executable. This means the whole heap ends
3446 * up being executable.
3447 */
3448-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3449- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3450+#define VM_DATA_DEFAULT_FLAGS32 \
3451+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3452+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3453
3454 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3455 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3456@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3457 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3458 #endif
3459
3460+#define ktla_ktva(addr) (addr)
3461+#define ktva_ktla(addr) (addr)
3462+
3463 /*
3464 * Use the top bit of the higher-level page table entries to indicate whether
3465 * the entries we point to contain hugepages. This works because we know that
3466diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3467index fed85e6..da5c71b 100644
3468--- a/arch/powerpc/include/asm/page_64.h
3469+++ b/arch/powerpc/include/asm/page_64.h
3470@@ -146,15 +146,18 @@ do { \
3471 * stack by default, so in the absence of a PT_GNU_STACK program header
3472 * we turn execute permission off.
3473 */
3474-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3475- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3476+#define VM_STACK_DEFAULT_FLAGS32 \
3477+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3478+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3479
3480 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3481 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3482
3483+#ifndef CONFIG_PAX_PAGEEXEC
3484 #define VM_STACK_DEFAULT_FLAGS \
3485 (is_32bit_task() ? \
3486 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3487+#endif
3488
3489 #include <asm-generic/getorder.h>
3490
3491diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3492index 2e0e411..7899c68 100644
3493--- a/arch/powerpc/include/asm/pgtable.h
3494+++ b/arch/powerpc/include/asm/pgtable.h
3495@@ -2,6 +2,7 @@
3496 #define _ASM_POWERPC_PGTABLE_H
3497 #ifdef __KERNEL__
3498
3499+#include <linux/const.h>
3500 #ifndef __ASSEMBLY__
3501 #include <asm/processor.h> /* For TASK_SIZE */
3502 #include <asm/mmu.h>
3503diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3504index 4aad413..85d86bf 100644
3505--- a/arch/powerpc/include/asm/pte-hash32.h
3506+++ b/arch/powerpc/include/asm/pte-hash32.h
3507@@ -21,6 +21,7 @@
3508 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3509 #define _PAGE_USER 0x004 /* usermode access allowed */
3510 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3511+#define _PAGE_EXEC _PAGE_GUARDED
3512 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3513 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3514 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3515diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3516index 7fdc2c0..e47a9b02d3 100644
3517--- a/arch/powerpc/include/asm/reg.h
3518+++ b/arch/powerpc/include/asm/reg.h
3519@@ -212,6 +212,7 @@
3520 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3521 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3522 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3523+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3524 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3525 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3526 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3527diff --git a/arch/powerpc/include/asm/system.h b/arch/powerpc/include/asm/system.h
3528index c377457..3c69fbc 100644
3529--- a/arch/powerpc/include/asm/system.h
3530+++ b/arch/powerpc/include/asm/system.h
3531@@ -539,7 +539,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
3532 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
3533 #endif
3534
3535-extern unsigned long arch_align_stack(unsigned long sp);
3536+#define arch_align_stack(x) ((x) & ~0xfUL)
3537
3538 /* Used in very early kernel initialization. */
3539 extern unsigned long reloc_offset(void);
3540diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3541index bd0fb84..a42a14b 100644
3542--- a/arch/powerpc/include/asm/uaccess.h
3543+++ b/arch/powerpc/include/asm/uaccess.h
3544@@ -13,6 +13,8 @@
3545 #define VERIFY_READ 0
3546 #define VERIFY_WRITE 1
3547
3548+extern void check_object_size(const void *ptr, unsigned long n, bool to);
3549+
3550 /*
3551 * The fs value determines whether argument validity checking should be
3552 * performed or not. If get_fs() == USER_DS, checking is performed, with
3553@@ -327,52 +329,6 @@ do { \
3554 extern unsigned long __copy_tofrom_user(void __user *to,
3555 const void __user *from, unsigned long size);
3556
3557-#ifndef __powerpc64__
3558-
3559-static inline unsigned long copy_from_user(void *to,
3560- const void __user *from, unsigned long n)
3561-{
3562- unsigned long over;
3563-
3564- if (access_ok(VERIFY_READ, from, n))
3565- return __copy_tofrom_user((__force void __user *)to, from, n);
3566- if ((unsigned long)from < TASK_SIZE) {
3567- over = (unsigned long)from + n - TASK_SIZE;
3568- return __copy_tofrom_user((__force void __user *)to, from,
3569- n - over) + over;
3570- }
3571- return n;
3572-}
3573-
3574-static inline unsigned long copy_to_user(void __user *to,
3575- const void *from, unsigned long n)
3576-{
3577- unsigned long over;
3578-
3579- if (access_ok(VERIFY_WRITE, to, n))
3580- return __copy_tofrom_user(to, (__force void __user *)from, n);
3581- if ((unsigned long)to < TASK_SIZE) {
3582- over = (unsigned long)to + n - TASK_SIZE;
3583- return __copy_tofrom_user(to, (__force void __user *)from,
3584- n - over) + over;
3585- }
3586- return n;
3587-}
3588-
3589-#else /* __powerpc64__ */
3590-
3591-#define __copy_in_user(to, from, size) \
3592- __copy_tofrom_user((to), (from), (size))
3593-
3594-extern unsigned long copy_from_user(void *to, const void __user *from,
3595- unsigned long n);
3596-extern unsigned long copy_to_user(void __user *to, const void *from,
3597- unsigned long n);
3598-extern unsigned long copy_in_user(void __user *to, const void __user *from,
3599- unsigned long n);
3600-
3601-#endif /* __powerpc64__ */
3602-
3603 static inline unsigned long __copy_from_user_inatomic(void *to,
3604 const void __user *from, unsigned long n)
3605 {
3606@@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
3607 if (ret == 0)
3608 return 0;
3609 }
3610+
3611+ if (!__builtin_constant_p(n))
3612+ check_object_size(to, n, false);
3613+
3614 return __copy_tofrom_user((__force void __user *)to, from, n);
3615 }
3616
3617@@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
3618 if (ret == 0)
3619 return 0;
3620 }
3621+
3622+ if (!__builtin_constant_p(n))
3623+ check_object_size(from, n, true);
3624+
3625 return __copy_tofrom_user(to, (__force const void __user *)from, n);
3626 }
3627
3628@@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
3629 return __copy_to_user_inatomic(to, from, size);
3630 }
3631
3632+#ifndef __powerpc64__
3633+
3634+static inline unsigned long __must_check copy_from_user(void *to,
3635+ const void __user *from, unsigned long n)
3636+{
3637+ unsigned long over;
3638+
3639+ if ((long)n < 0)
3640+ return n;
3641+
3642+ if (access_ok(VERIFY_READ, from, n)) {
3643+ if (!__builtin_constant_p(n))
3644+ check_object_size(to, n, false);
3645+ return __copy_tofrom_user((__force void __user *)to, from, n);
3646+ }
3647+ if ((unsigned long)from < TASK_SIZE) {
3648+ over = (unsigned long)from + n - TASK_SIZE;
3649+ if (!__builtin_constant_p(n - over))
3650+ check_object_size(to, n - over, false);
3651+ return __copy_tofrom_user((__force void __user *)to, from,
3652+ n - over) + over;
3653+ }
3654+ return n;
3655+}
3656+
3657+static inline unsigned long __must_check copy_to_user(void __user *to,
3658+ const void *from, unsigned long n)
3659+{
3660+ unsigned long over;
3661+
3662+ if ((long)n < 0)
3663+ return n;
3664+
3665+ if (access_ok(VERIFY_WRITE, to, n)) {
3666+ if (!__builtin_constant_p(n))
3667+ check_object_size(from, n, true);
3668+ return __copy_tofrom_user(to, (__force void __user *)from, n);
3669+ }
3670+ if ((unsigned long)to < TASK_SIZE) {
3671+ over = (unsigned long)to + n - TASK_SIZE;
3672+ if (!__builtin_constant_p(n))
3673+ check_object_size(from, n - over, true);
3674+ return __copy_tofrom_user(to, (__force void __user *)from,
3675+ n - over) + over;
3676+ }
3677+ return n;
3678+}
3679+
3680+#else /* __powerpc64__ */
3681+
3682+#define __copy_in_user(to, from, size) \
3683+ __copy_tofrom_user((to), (from), (size))
3684+
3685+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
3686+{
3687+ if ((long)n < 0 || n > INT_MAX)
3688+ return n;
3689+
3690+ if (!__builtin_constant_p(n))
3691+ check_object_size(to, n, false);
3692+
3693+ if (likely(access_ok(VERIFY_READ, from, n)))
3694+ n = __copy_from_user(to, from, n);
3695+ else
3696+ memset(to, 0, n);
3697+ return n;
3698+}
3699+
3700+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
3701+{
3702+ if ((long)n < 0 || n > INT_MAX)
3703+ return n;
3704+
3705+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
3706+ if (!__builtin_constant_p(n))
3707+ check_object_size(from, n, true);
3708+ n = __copy_to_user(to, from, n);
3709+ }
3710+ return n;
3711+}
3712+
3713+extern unsigned long copy_in_user(void __user *to, const void __user *from,
3714+ unsigned long n);
3715+
3716+#endif /* __powerpc64__ */
3717+
3718 extern unsigned long __clear_user(void __user *addr, unsigned long size);
3719
3720 static inline unsigned long clear_user(void __user *addr, unsigned long size)
3721diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
3722index 429983c..7af363b 100644
3723--- a/arch/powerpc/kernel/exceptions-64e.S
3724+++ b/arch/powerpc/kernel/exceptions-64e.S
3725@@ -587,6 +587,7 @@ storage_fault_common:
3726 std r14,_DAR(r1)
3727 std r15,_DSISR(r1)
3728 addi r3,r1,STACK_FRAME_OVERHEAD
3729+ bl .save_nvgprs
3730 mr r4,r14
3731 mr r5,r15
3732 ld r14,PACA_EXGEN+EX_R14(r13)
3733@@ -596,8 +597,7 @@ storage_fault_common:
3734 cmpdi r3,0
3735 bne- 1f
3736 b .ret_from_except_lite
3737-1: bl .save_nvgprs
3738- mr r5,r3
3739+1: mr r5,r3
3740 addi r3,r1,STACK_FRAME_OVERHEAD
3741 ld r4,_DAR(r1)
3742 bl .bad_page_fault
3743diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
3744index 15c5a4f..22a4000 100644
3745--- a/arch/powerpc/kernel/exceptions-64s.S
3746+++ b/arch/powerpc/kernel/exceptions-64s.S
3747@@ -1004,10 +1004,10 @@ handle_page_fault:
3748 11: ld r4,_DAR(r1)
3749 ld r5,_DSISR(r1)
3750 addi r3,r1,STACK_FRAME_OVERHEAD
3751+ bl .save_nvgprs
3752 bl .do_page_fault
3753 cmpdi r3,0
3754 beq+ 13f
3755- bl .save_nvgprs
3756 mr r5,r3
3757 addi r3,r1,STACK_FRAME_OVERHEAD
3758 lwz r4,_DAR(r1)
3759diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
3760index 01e2877..a1ba360 100644
3761--- a/arch/powerpc/kernel/irq.c
3762+++ b/arch/powerpc/kernel/irq.c
3763@@ -560,9 +560,6 @@ struct irq_host *irq_alloc_host(struct device_node *of_node,
3764 host->ops = ops;
3765 host->of_node = of_node_get(of_node);
3766
3767- if (host->ops->match == NULL)
3768- host->ops->match = default_irq_host_match;
3769-
3770 raw_spin_lock_irqsave(&irq_big_lock, flags);
3771
3772 /* If it's a legacy controller, check for duplicates and
3773@@ -635,7 +632,12 @@ struct irq_host *irq_find_host(struct device_node *node)
3774 */
3775 raw_spin_lock_irqsave(&irq_big_lock, flags);
3776 list_for_each_entry(h, &irq_hosts, link)
3777- if (h->ops->match(h, node)) {
3778+ if (h->ops->match) {
3779+ if (h->ops->match(h, node)) {
3780+ found = h;
3781+ break;
3782+ }
3783+ } else if (default_irq_host_match(h, node)) {
3784 found = h;
3785 break;
3786 }
3787diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
3788index 0b6d796..d760ddb 100644
3789--- a/arch/powerpc/kernel/module_32.c
3790+++ b/arch/powerpc/kernel/module_32.c
3791@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
3792 me->arch.core_plt_section = i;
3793 }
3794 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
3795- printk("Module doesn't contain .plt or .init.plt sections.\n");
3796+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
3797 return -ENOEXEC;
3798 }
3799
3800@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
3801
3802 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
3803 /* Init, or core PLT? */
3804- if (location >= mod->module_core
3805- && location < mod->module_core + mod->core_size)
3806+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
3807+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
3808 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
3809- else
3810+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
3811+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
3812 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
3813+ else {
3814+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
3815+ return ~0UL;
3816+ }
3817
3818 /* Find this entry, or if that fails, the next avail. entry */
3819 while (entry->jump[0]) {
3820diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
3821index d817ab0..b23b18e 100644
3822--- a/arch/powerpc/kernel/process.c
3823+++ b/arch/powerpc/kernel/process.c
3824@@ -676,8 +676,8 @@ void show_regs(struct pt_regs * regs)
3825 * Lookup NIP late so we have the best change of getting the
3826 * above info out without failing
3827 */
3828- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
3829- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
3830+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
3831+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
3832 #endif
3833 show_stack(current, (unsigned long *) regs->gpr[1]);
3834 if (!user_mode(regs))
3835@@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
3836 newsp = stack[0];
3837 ip = stack[STACK_FRAME_LR_SAVE];
3838 if (!firstframe || ip != lr) {
3839- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
3840+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
3841 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3842 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
3843- printk(" (%pS)",
3844+ printk(" (%pA)",
3845 (void *)current->ret_stack[curr_frame].ret);
3846 curr_frame--;
3847 }
3848@@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
3849 struct pt_regs *regs = (struct pt_regs *)
3850 (sp + STACK_FRAME_OVERHEAD);
3851 lr = regs->link;
3852- printk("--- Exception: %lx at %pS\n LR = %pS\n",
3853+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
3854 regs->trap, (void *)regs->nip, (void *)lr);
3855 firstframe = 1;
3856 }
3857@@ -1279,58 +1279,3 @@ void thread_info_cache_init(void)
3858 }
3859
3860 #endif /* THREAD_SHIFT < PAGE_SHIFT */
3861-
3862-unsigned long arch_align_stack(unsigned long sp)
3863-{
3864- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3865- sp -= get_random_int() & ~PAGE_MASK;
3866- return sp & ~0xf;
3867-}
3868-
3869-static inline unsigned long brk_rnd(void)
3870-{
3871- unsigned long rnd = 0;
3872-
3873- /* 8MB for 32bit, 1GB for 64bit */
3874- if (is_32bit_task())
3875- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
3876- else
3877- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
3878-
3879- return rnd << PAGE_SHIFT;
3880-}
3881-
3882-unsigned long arch_randomize_brk(struct mm_struct *mm)
3883-{
3884- unsigned long base = mm->brk;
3885- unsigned long ret;
3886-
3887-#ifdef CONFIG_PPC_STD_MMU_64
3888- /*
3889- * If we are using 1TB segments and we are allowed to randomise
3890- * the heap, we can put it above 1TB so it is backed by a 1TB
3891- * segment. Otherwise the heap will be in the bottom 1TB
3892- * which always uses 256MB segments and this may result in a
3893- * performance penalty.
3894- */
3895- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
3896- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
3897-#endif
3898-
3899- ret = PAGE_ALIGN(base + brk_rnd());
3900-
3901- if (ret < mm->brk)
3902- return mm->brk;
3903-
3904- return ret;
3905-}
3906-
3907-unsigned long randomize_et_dyn(unsigned long base)
3908-{
3909- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
3910-
3911- if (ret < base)
3912- return base;
3913-
3914- return ret;
3915-}
3916diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
3917index 836a5a1..27289a3 100644
3918--- a/arch/powerpc/kernel/signal_32.c
3919+++ b/arch/powerpc/kernel/signal_32.c
3920@@ -859,7 +859,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
3921 /* Save user registers on the stack */
3922 frame = &rt_sf->uc.uc_mcontext;
3923 addr = frame;
3924- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
3925+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3926 if (save_user_regs(regs, frame, 0, 1))
3927 goto badframe;
3928 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
3929diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
3930index a50b5ec..547078a 100644
3931--- a/arch/powerpc/kernel/signal_64.c
3932+++ b/arch/powerpc/kernel/signal_64.c
3933@@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
3934 current->thread.fpscr.val = 0;
3935
3936 /* Set up to return from userspace. */
3937- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
3938+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3939 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
3940 } else {
3941 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
3942diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
3943index c091527..5592625 100644
3944--- a/arch/powerpc/kernel/traps.c
3945+++ b/arch/powerpc/kernel/traps.c
3946@@ -131,6 +131,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
3947 return flags;
3948 }
3949
3950+extern void gr_handle_kernel_exploit(void);
3951+
3952 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
3953 int signr)
3954 {
3955@@ -178,6 +180,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
3956 panic("Fatal exception in interrupt");
3957 if (panic_on_oops)
3958 panic("Fatal exception");
3959+
3960+ gr_handle_kernel_exploit();
3961+
3962 do_exit(signr);
3963 }
3964
3965diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
3966index 7d14bb6..1305601 100644
3967--- a/arch/powerpc/kernel/vdso.c
3968+++ b/arch/powerpc/kernel/vdso.c
3969@@ -35,6 +35,7 @@
3970 #include <asm/firmware.h>
3971 #include <asm/vdso.h>
3972 #include <asm/vdso_datapage.h>
3973+#include <asm/mman.h>
3974
3975 #include "setup.h"
3976
3977@@ -219,7 +220,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3978 vdso_base = VDSO32_MBASE;
3979 #endif
3980
3981- current->mm->context.vdso_base = 0;
3982+ current->mm->context.vdso_base = ~0UL;
3983
3984 /* vDSO has a problem and was disabled, just don't "enable" it for the
3985 * process
3986@@ -239,7 +240,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3987 vdso_base = get_unmapped_area(NULL, vdso_base,
3988 (vdso_pages << PAGE_SHIFT) +
3989 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
3990- 0, 0);
3991+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
3992 if (IS_ERR_VALUE(vdso_base)) {
3993 rc = vdso_base;
3994 goto fail_mmapsem;
3995diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
3996index 5eea6f3..5d10396 100644
3997--- a/arch/powerpc/lib/usercopy_64.c
3998+++ b/arch/powerpc/lib/usercopy_64.c
3999@@ -9,22 +9,6 @@
4000 #include <linux/module.h>
4001 #include <asm/uaccess.h>
4002
4003-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4004-{
4005- if (likely(access_ok(VERIFY_READ, from, n)))
4006- n = __copy_from_user(to, from, n);
4007- else
4008- memset(to, 0, n);
4009- return n;
4010-}
4011-
4012-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4013-{
4014- if (likely(access_ok(VERIFY_WRITE, to, n)))
4015- n = __copy_to_user(to, from, n);
4016- return n;
4017-}
4018-
4019 unsigned long copy_in_user(void __user *to, const void __user *from,
4020 unsigned long n)
4021 {
4022@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4023 return n;
4024 }
4025
4026-EXPORT_SYMBOL(copy_from_user);
4027-EXPORT_SYMBOL(copy_to_user);
4028 EXPORT_SYMBOL(copy_in_user);
4029
4030diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4031index 2f0d1b0..36fb5cc 100644
4032--- a/arch/powerpc/mm/fault.c
4033+++ b/arch/powerpc/mm/fault.c
4034@@ -32,6 +32,10 @@
4035 #include <linux/perf_event.h>
4036 #include <linux/magic.h>
4037 #include <linux/ratelimit.h>
4038+#include <linux/slab.h>
4039+#include <linux/pagemap.h>
4040+#include <linux/compiler.h>
4041+#include <linux/unistd.h>
4042
4043 #include <asm/firmware.h>
4044 #include <asm/page.h>
4045@@ -43,6 +47,7 @@
4046 #include <asm/tlbflush.h>
4047 #include <asm/siginfo.h>
4048 #include <mm/mmu_decl.h>
4049+#include <asm/ptrace.h>
4050
4051 #include "icswx.h"
4052
4053@@ -68,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4054 }
4055 #endif
4056
4057+#ifdef CONFIG_PAX_PAGEEXEC
4058+/*
4059+ * PaX: decide what to do with offenders (regs->nip = fault address)
4060+ *
4061+ * returns 1 when task should be killed
4062+ */
4063+static int pax_handle_fetch_fault(struct pt_regs *regs)
4064+{
4065+ return 1;
4066+}
4067+
4068+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4069+{
4070+ unsigned long i;
4071+
4072+ printk(KERN_ERR "PAX: bytes at PC: ");
4073+ for (i = 0; i < 5; i++) {
4074+ unsigned int c;
4075+ if (get_user(c, (unsigned int __user *)pc+i))
4076+ printk(KERN_CONT "???????? ");
4077+ else
4078+ printk(KERN_CONT "%08x ", c);
4079+ }
4080+ printk("\n");
4081+}
4082+#endif
4083+
4084 /*
4085 * Check whether the instruction at regs->nip is a store using
4086 * an update addressing form which will update r1.
4087@@ -138,7 +170,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4088 * indicate errors in DSISR but can validly be set in SRR1.
4089 */
4090 if (trap == 0x400)
4091- error_code &= 0x48200000;
4092+ error_code &= 0x58200000;
4093 else
4094 is_write = error_code & DSISR_ISSTORE;
4095 #else
4096@@ -276,7 +308,7 @@ good_area:
4097 * "undefined". Of those that can be set, this is the only
4098 * one which seems bad.
4099 */
4100- if (error_code & 0x10000000)
4101+ if (error_code & DSISR_GUARDED)
4102 /* Guarded storage error. */
4103 goto bad_area;
4104 #endif /* CONFIG_8xx */
4105@@ -291,7 +323,7 @@ good_area:
4106 * processors use the same I/D cache coherency mechanism
4107 * as embedded.
4108 */
4109- if (error_code & DSISR_PROTFAULT)
4110+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4111 goto bad_area;
4112 #endif /* CONFIG_PPC_STD_MMU */
4113
4114@@ -360,6 +392,23 @@ bad_area:
4115 bad_area_nosemaphore:
4116 /* User mode accesses cause a SIGSEGV */
4117 if (user_mode(regs)) {
4118+
4119+#ifdef CONFIG_PAX_PAGEEXEC
4120+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4121+#ifdef CONFIG_PPC_STD_MMU
4122+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4123+#else
4124+ if (is_exec && regs->nip == address) {
4125+#endif
4126+ switch (pax_handle_fetch_fault(regs)) {
4127+ }
4128+
4129+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4130+ do_group_exit(SIGKILL);
4131+ }
4132+ }
4133+#endif
4134+
4135 _exception(SIGSEGV, regs, code, address);
4136 return 0;
4137 }
4138diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4139index 67a42ed..1c7210c 100644
4140--- a/arch/powerpc/mm/mmap_64.c
4141+++ b/arch/powerpc/mm/mmap_64.c
4142@@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4143 */
4144 if (mmap_is_legacy()) {
4145 mm->mmap_base = TASK_UNMAPPED_BASE;
4146+
4147+#ifdef CONFIG_PAX_RANDMMAP
4148+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4149+ mm->mmap_base += mm->delta_mmap;
4150+#endif
4151+
4152 mm->get_unmapped_area = arch_get_unmapped_area;
4153 mm->unmap_area = arch_unmap_area;
4154 } else {
4155 mm->mmap_base = mmap_base();
4156+
4157+#ifdef CONFIG_PAX_RANDMMAP
4158+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4159+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4160+#endif
4161+
4162 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4163 mm->unmap_area = arch_unmap_area_topdown;
4164 }
4165diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4166index 73709f7..6b90313 100644
4167--- a/arch/powerpc/mm/slice.c
4168+++ b/arch/powerpc/mm/slice.c
4169@@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4170 if ((mm->task_size - len) < addr)
4171 return 0;
4172 vma = find_vma(mm, addr);
4173- return (!vma || (addr + len) <= vma->vm_start);
4174+ return check_heap_stack_gap(vma, addr, len);
4175 }
4176
4177 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4178@@ -256,7 +256,7 @@ full_search:
4179 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4180 continue;
4181 }
4182- if (!vma || addr + len <= vma->vm_start) {
4183+ if (check_heap_stack_gap(vma, addr, len)) {
4184 /*
4185 * Remember the place where we stopped the search:
4186 */
4187@@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4188 }
4189 }
4190
4191- addr = mm->mmap_base;
4192- while (addr > len) {
4193+ if (mm->mmap_base < len)
4194+ addr = -ENOMEM;
4195+ else
4196+ addr = mm->mmap_base - len;
4197+
4198+ while (!IS_ERR_VALUE(addr)) {
4199 /* Go down by chunk size */
4200- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4201+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
4202
4203 /* Check for hit with different page size */
4204 mask = slice_range_to_mask(addr, len);
4205@@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4206 * return with success:
4207 */
4208 vma = find_vma(mm, addr);
4209- if (!vma || (addr + len) <= vma->vm_start) {
4210+ if (check_heap_stack_gap(vma, addr, len)) {
4211 /* remember the address as a hint for next time */
4212 if (use_cache)
4213 mm->free_area_cache = addr;
4214@@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4215 mm->cached_hole_size = vma->vm_start - addr;
4216
4217 /* try just below the current vma->vm_start */
4218- addr = vma->vm_start;
4219+ addr = skip_heap_stack_gap(vma, len);
4220 }
4221
4222 /*
4223@@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4224 if (fixed && addr > (mm->task_size - len))
4225 return -EINVAL;
4226
4227+#ifdef CONFIG_PAX_RANDMMAP
4228+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4229+ addr = 0;
4230+#endif
4231+
4232 /* If hint, make sure it matches our alignment restrictions */
4233 if (!fixed && addr) {
4234 addr = _ALIGN_UP(addr, 1ul << pshift);
4235diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4236index 8517d2a..d2738d4 100644
4237--- a/arch/s390/include/asm/atomic.h
4238+++ b/arch/s390/include/asm/atomic.h
4239@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4240 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4241 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4242
4243+#define atomic64_read_unchecked(v) atomic64_read(v)
4244+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4245+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4246+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4247+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4248+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4249+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4250+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4251+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4252+
4253 #define smp_mb__before_atomic_dec() smp_mb()
4254 #define smp_mb__after_atomic_dec() smp_mb()
4255 #define smp_mb__before_atomic_inc() smp_mb()
4256diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4257index 2a30d5a..5e5586f 100644
4258--- a/arch/s390/include/asm/cache.h
4259+++ b/arch/s390/include/asm/cache.h
4260@@ -11,8 +11,10 @@
4261 #ifndef __ARCH_S390_CACHE_H
4262 #define __ARCH_S390_CACHE_H
4263
4264-#define L1_CACHE_BYTES 256
4265+#include <linux/const.h>
4266+
4267 #define L1_CACHE_SHIFT 8
4268+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4269 #define NET_SKB_PAD 32
4270
4271 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4272diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4273index 547f1a6..0b22b53 100644
4274--- a/arch/s390/include/asm/elf.h
4275+++ b/arch/s390/include/asm/elf.h
4276@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
4277 the loader. We need to make sure that it is out of the way of the program
4278 that it will "exec", and that there is sufficient room for the brk. */
4279
4280-extern unsigned long randomize_et_dyn(unsigned long base);
4281-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4282+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4283+
4284+#ifdef CONFIG_PAX_ASLR
4285+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4286+
4287+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4288+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4289+#endif
4290
4291 /* This yields a mask that user programs can use to figure out what
4292 instruction set this CPU supports. */
4293@@ -211,7 +217,4 @@ struct linux_binprm;
4294 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4295 int arch_setup_additional_pages(struct linux_binprm *, int);
4296
4297-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4298-#define arch_randomize_brk arch_randomize_brk
4299-
4300 #endif
4301diff --git a/arch/s390/include/asm/system.h b/arch/s390/include/asm/system.h
4302index d73cc6b..1a296ad 100644
4303--- a/arch/s390/include/asm/system.h
4304+++ b/arch/s390/include/asm/system.h
4305@@ -260,7 +260,7 @@ extern void (*_machine_restart)(char *command);
4306 extern void (*_machine_halt)(void);
4307 extern void (*_machine_power_off)(void);
4308
4309-extern unsigned long arch_align_stack(unsigned long sp);
4310+#define arch_align_stack(x) ((x) & ~0xfUL)
4311
4312 static inline int tprot(unsigned long addr)
4313 {
4314diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4315index 2b23885..e136e31 100644
4316--- a/arch/s390/include/asm/uaccess.h
4317+++ b/arch/s390/include/asm/uaccess.h
4318@@ -235,6 +235,10 @@ static inline unsigned long __must_check
4319 copy_to_user(void __user *to, const void *from, unsigned long n)
4320 {
4321 might_fault();
4322+
4323+ if ((long)n < 0)
4324+ return n;
4325+
4326 if (access_ok(VERIFY_WRITE, to, n))
4327 n = __copy_to_user(to, from, n);
4328 return n;
4329@@ -260,6 +264,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4330 static inline unsigned long __must_check
4331 __copy_from_user(void *to, const void __user *from, unsigned long n)
4332 {
4333+ if ((long)n < 0)
4334+ return n;
4335+
4336 if (__builtin_constant_p(n) && (n <= 256))
4337 return uaccess.copy_from_user_small(n, from, to);
4338 else
4339@@ -294,6 +301,10 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
4340 unsigned int sz = __compiletime_object_size(to);
4341
4342 might_fault();
4343+
4344+ if ((long)n < 0)
4345+ return n;
4346+
4347 if (unlikely(sz != -1 && sz < n)) {
4348 copy_from_user_overflow();
4349 return n;
4350diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4351index dfcb343..eda788a 100644
4352--- a/arch/s390/kernel/module.c
4353+++ b/arch/s390/kernel/module.c
4354@@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4355
4356 /* Increase core size by size of got & plt and set start
4357 offsets for got and plt. */
4358- me->core_size = ALIGN(me->core_size, 4);
4359- me->arch.got_offset = me->core_size;
4360- me->core_size += me->arch.got_size;
4361- me->arch.plt_offset = me->core_size;
4362- me->core_size += me->arch.plt_size;
4363+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
4364+ me->arch.got_offset = me->core_size_rw;
4365+ me->core_size_rw += me->arch.got_size;
4366+ me->arch.plt_offset = me->core_size_rx;
4367+ me->core_size_rx += me->arch.plt_size;
4368 return 0;
4369 }
4370
4371@@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4372 if (info->got_initialized == 0) {
4373 Elf_Addr *gotent;
4374
4375- gotent = me->module_core + me->arch.got_offset +
4376+ gotent = me->module_core_rw + me->arch.got_offset +
4377 info->got_offset;
4378 *gotent = val;
4379 info->got_initialized = 1;
4380@@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4381 else if (r_type == R_390_GOTENT ||
4382 r_type == R_390_GOTPLTENT)
4383 *(unsigned int *) loc =
4384- (val + (Elf_Addr) me->module_core - loc) >> 1;
4385+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4386 else if (r_type == R_390_GOT64 ||
4387 r_type == R_390_GOTPLT64)
4388 *(unsigned long *) loc = val;
4389@@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4390 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4391 if (info->plt_initialized == 0) {
4392 unsigned int *ip;
4393- ip = me->module_core + me->arch.plt_offset +
4394+ ip = me->module_core_rx + me->arch.plt_offset +
4395 info->plt_offset;
4396 #ifndef CONFIG_64BIT
4397 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4398@@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4399 val - loc + 0xffffUL < 0x1ffffeUL) ||
4400 (r_type == R_390_PLT32DBL &&
4401 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4402- val = (Elf_Addr) me->module_core +
4403+ val = (Elf_Addr) me->module_core_rx +
4404 me->arch.plt_offset +
4405 info->plt_offset;
4406 val += rela->r_addend - loc;
4407@@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4408 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4409 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4410 val = val + rela->r_addend -
4411- ((Elf_Addr) me->module_core + me->arch.got_offset);
4412+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4413 if (r_type == R_390_GOTOFF16)
4414 *(unsigned short *) loc = val;
4415 else if (r_type == R_390_GOTOFF32)
4416@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4417 break;
4418 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4419 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4420- val = (Elf_Addr) me->module_core + me->arch.got_offset +
4421+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4422 rela->r_addend - loc;
4423 if (r_type == R_390_GOTPC)
4424 *(unsigned int *) loc = val;
4425diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4426index e795933..b32563c 100644
4427--- a/arch/s390/kernel/process.c
4428+++ b/arch/s390/kernel/process.c
4429@@ -323,39 +323,3 @@ unsigned long get_wchan(struct task_struct *p)
4430 }
4431 return 0;
4432 }
4433-
4434-unsigned long arch_align_stack(unsigned long sp)
4435-{
4436- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4437- sp -= get_random_int() & ~PAGE_MASK;
4438- return sp & ~0xf;
4439-}
4440-
4441-static inline unsigned long brk_rnd(void)
4442-{
4443- /* 8MB for 32bit, 1GB for 64bit */
4444- if (is_32bit_task())
4445- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4446- else
4447- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4448-}
4449-
4450-unsigned long arch_randomize_brk(struct mm_struct *mm)
4451-{
4452- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4453-
4454- if (ret < mm->brk)
4455- return mm->brk;
4456- return ret;
4457-}
4458-
4459-unsigned long randomize_et_dyn(unsigned long base)
4460-{
4461- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4462-
4463- if (!(current->flags & PF_RANDOMIZE))
4464- return base;
4465- if (ret < base)
4466- return base;
4467- return ret;
4468-}
4469diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4470index a0155c0..34cc491 100644
4471--- a/arch/s390/mm/mmap.c
4472+++ b/arch/s390/mm/mmap.c
4473@@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4474 */
4475 if (mmap_is_legacy()) {
4476 mm->mmap_base = TASK_UNMAPPED_BASE;
4477+
4478+#ifdef CONFIG_PAX_RANDMMAP
4479+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4480+ mm->mmap_base += mm->delta_mmap;
4481+#endif
4482+
4483 mm->get_unmapped_area = arch_get_unmapped_area;
4484 mm->unmap_area = arch_unmap_area;
4485 } else {
4486 mm->mmap_base = mmap_base();
4487+
4488+#ifdef CONFIG_PAX_RANDMMAP
4489+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4490+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4491+#endif
4492+
4493 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4494 mm->unmap_area = arch_unmap_area_topdown;
4495 }
4496@@ -167,10 +179,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4497 */
4498 if (mmap_is_legacy()) {
4499 mm->mmap_base = TASK_UNMAPPED_BASE;
4500+
4501+#ifdef CONFIG_PAX_RANDMMAP
4502+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4503+ mm->mmap_base += mm->delta_mmap;
4504+#endif
4505+
4506 mm->get_unmapped_area = s390_get_unmapped_area;
4507 mm->unmap_area = arch_unmap_area;
4508 } else {
4509 mm->mmap_base = mmap_base();
4510+
4511+#ifdef CONFIG_PAX_RANDMMAP
4512+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4513+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4514+#endif
4515+
4516 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4517 mm->unmap_area = arch_unmap_area_topdown;
4518 }
4519diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4520index ae3d59f..f65f075 100644
4521--- a/arch/score/include/asm/cache.h
4522+++ b/arch/score/include/asm/cache.h
4523@@ -1,7 +1,9 @@
4524 #ifndef _ASM_SCORE_CACHE_H
4525 #define _ASM_SCORE_CACHE_H
4526
4527+#include <linux/const.h>
4528+
4529 #define L1_CACHE_SHIFT 4
4530-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4531+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4532
4533 #endif /* _ASM_SCORE_CACHE_H */
4534diff --git a/arch/score/include/asm/system.h b/arch/score/include/asm/system.h
4535index 589d5c7..669e274 100644
4536--- a/arch/score/include/asm/system.h
4537+++ b/arch/score/include/asm/system.h
4538@@ -17,7 +17,7 @@ do { \
4539 #define finish_arch_switch(prev) do {} while (0)
4540
4541 typedef void (*vi_handler_t)(void);
4542-extern unsigned long arch_align_stack(unsigned long sp);
4543+#define arch_align_stack(x) (x)
4544
4545 #define mb() barrier()
4546 #define rmb() barrier()
4547diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4548index 25d0803..d6c8e36 100644
4549--- a/arch/score/kernel/process.c
4550+++ b/arch/score/kernel/process.c
4551@@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4552
4553 return task_pt_regs(task)->cp0_epc;
4554 }
4555-
4556-unsigned long arch_align_stack(unsigned long sp)
4557-{
4558- return sp;
4559-}
4560diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4561index ef9e555..331bd29 100644
4562--- a/arch/sh/include/asm/cache.h
4563+++ b/arch/sh/include/asm/cache.h
4564@@ -9,10 +9,11 @@
4565 #define __ASM_SH_CACHE_H
4566 #ifdef __KERNEL__
4567
4568+#include <linux/const.h>
4569 #include <linux/init.h>
4570 #include <cpu/cache.h>
4571
4572-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4573+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4574
4575 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4576
4577diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4578index afeb710..d1d1289 100644
4579--- a/arch/sh/mm/mmap.c
4580+++ b/arch/sh/mm/mmap.c
4581@@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4582 addr = PAGE_ALIGN(addr);
4583
4584 vma = find_vma(mm, addr);
4585- if (TASK_SIZE - len >= addr &&
4586- (!vma || addr + len <= vma->vm_start))
4587+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4588 return addr;
4589 }
4590
4591@@ -106,7 +105,7 @@ full_search:
4592 }
4593 return -ENOMEM;
4594 }
4595- if (likely(!vma || addr + len <= vma->vm_start)) {
4596+ if (likely(check_heap_stack_gap(vma, addr, len))) {
4597 /*
4598 * Remember the place where we stopped the search:
4599 */
4600@@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4601 addr = PAGE_ALIGN(addr);
4602
4603 vma = find_vma(mm, addr);
4604- if (TASK_SIZE - len >= addr &&
4605- (!vma || addr + len <= vma->vm_start))
4606+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4607 return addr;
4608 }
4609
4610@@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4611 /* make sure it can fit in the remaining address space */
4612 if (likely(addr > len)) {
4613 vma = find_vma(mm, addr-len);
4614- if (!vma || addr <= vma->vm_start) {
4615+ if (check_heap_stack_gap(vma, addr - len, len)) {
4616 /* remember the address as a hint for next time */
4617 return (mm->free_area_cache = addr-len);
4618 }
4619@@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4620 if (unlikely(mm->mmap_base < len))
4621 goto bottomup;
4622
4623- addr = mm->mmap_base-len;
4624- if (do_colour_align)
4625- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4626+ addr = mm->mmap_base - len;
4627
4628 do {
4629+ if (do_colour_align)
4630+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4631 /*
4632 * Lookup failure means no vma is above this address,
4633 * else if new region fits below vma->vm_start,
4634 * return with success:
4635 */
4636 vma = find_vma(mm, addr);
4637- if (likely(!vma || addr+len <= vma->vm_start)) {
4638+ if (likely(check_heap_stack_gap(vma, addr, len))) {
4639 /* remember the address as a hint for next time */
4640 return (mm->free_area_cache = addr);
4641 }
4642@@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4643 mm->cached_hole_size = vma->vm_start - addr;
4644
4645 /* try just below the current vma->vm_start */
4646- addr = vma->vm_start-len;
4647- if (do_colour_align)
4648- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4649- } while (likely(len < vma->vm_start));
4650+ addr = skip_heap_stack_gap(vma, len);
4651+ } while (!IS_ERR_VALUE(addr));
4652
4653 bottomup:
4654 /*
4655diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
4656index eddcfb3..b117d90 100644
4657--- a/arch/sparc/Makefile
4658+++ b/arch/sparc/Makefile
4659@@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
4660 # Export what is needed by arch/sparc/boot/Makefile
4661 export VMLINUX_INIT VMLINUX_MAIN
4662 VMLINUX_INIT := $(head-y) $(init-y)
4663-VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
4664+VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
4665 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
4666 VMLINUX_MAIN += $(drivers-y) $(net-y)
4667
4668diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
4669index 9f421df..b81fc12 100644
4670--- a/arch/sparc/include/asm/atomic_64.h
4671+++ b/arch/sparc/include/asm/atomic_64.h
4672@@ -14,18 +14,40 @@
4673 #define ATOMIC64_INIT(i) { (i) }
4674
4675 #define atomic_read(v) (*(volatile int *)&(v)->counter)
4676+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
4677+{
4678+ return v->counter;
4679+}
4680 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
4681+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
4682+{
4683+ return v->counter;
4684+}
4685
4686 #define atomic_set(v, i) (((v)->counter) = i)
4687+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
4688+{
4689+ v->counter = i;
4690+}
4691 #define atomic64_set(v, i) (((v)->counter) = i)
4692+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
4693+{
4694+ v->counter = i;
4695+}
4696
4697 extern void atomic_add(int, atomic_t *);
4698+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
4699 extern void atomic64_add(long, atomic64_t *);
4700+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
4701 extern void atomic_sub(int, atomic_t *);
4702+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
4703 extern void atomic64_sub(long, atomic64_t *);
4704+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
4705
4706 extern int atomic_add_ret(int, atomic_t *);
4707+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
4708 extern long atomic64_add_ret(long, atomic64_t *);
4709+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
4710 extern int atomic_sub_ret(int, atomic_t *);
4711 extern long atomic64_sub_ret(long, atomic64_t *);
4712
4713@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4714 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
4715
4716 #define atomic_inc_return(v) atomic_add_ret(1, v)
4717+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
4718+{
4719+ return atomic_add_ret_unchecked(1, v);
4720+}
4721 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
4722+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
4723+{
4724+ return atomic64_add_ret_unchecked(1, v);
4725+}
4726
4727 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
4728 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
4729
4730 #define atomic_add_return(i, v) atomic_add_ret(i, v)
4731+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
4732+{
4733+ return atomic_add_ret_unchecked(i, v);
4734+}
4735 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
4736+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
4737+{
4738+ return atomic64_add_ret_unchecked(i, v);
4739+}
4740
4741 /*
4742 * atomic_inc_and_test - increment and test
4743@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4744 * other cases.
4745 */
4746 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
4747+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
4748+{
4749+ return atomic_inc_return_unchecked(v) == 0;
4750+}
4751 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
4752
4753 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
4754@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4755 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
4756
4757 #define atomic_inc(v) atomic_add(1, v)
4758+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
4759+{
4760+ atomic_add_unchecked(1, v);
4761+}
4762 #define atomic64_inc(v) atomic64_add(1, v)
4763+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
4764+{
4765+ atomic64_add_unchecked(1, v);
4766+}
4767
4768 #define atomic_dec(v) atomic_sub(1, v)
4769+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
4770+{
4771+ atomic_sub_unchecked(1, v);
4772+}
4773 #define atomic64_dec(v) atomic64_sub(1, v)
4774+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
4775+{
4776+ atomic64_sub_unchecked(1, v);
4777+}
4778
4779 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
4780 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
4781
4782 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
4783+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
4784+{
4785+ return cmpxchg(&v->counter, old, new);
4786+}
4787 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
4788+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
4789+{
4790+ return xchg(&v->counter, new);
4791+}
4792
4793 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
4794 {
4795- int c, old;
4796+ int c, old, new;
4797 c = atomic_read(v);
4798 for (;;) {
4799- if (unlikely(c == (u)))
4800+ if (unlikely(c == u))
4801 break;
4802- old = atomic_cmpxchg((v), c, c + (a));
4803+
4804+ asm volatile("addcc %2, %0, %0\n"
4805+
4806+#ifdef CONFIG_PAX_REFCOUNT
4807+ "tvs %%icc, 6\n"
4808+#endif
4809+
4810+ : "=r" (new)
4811+ : "0" (c), "ir" (a)
4812+ : "cc");
4813+
4814+ old = atomic_cmpxchg(v, c, new);
4815 if (likely(old == c))
4816 break;
4817 c = old;
4818@@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
4819 #define atomic64_cmpxchg(v, o, n) \
4820 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
4821 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
4822+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
4823+{
4824+ return xchg(&v->counter, new);
4825+}
4826
4827 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
4828 {
4829- long c, old;
4830+ long c, old, new;
4831 c = atomic64_read(v);
4832 for (;;) {
4833- if (unlikely(c == (u)))
4834+ if (unlikely(c == u))
4835 break;
4836- old = atomic64_cmpxchg((v), c, c + (a));
4837+
4838+ asm volatile("addcc %2, %0, %0\n"
4839+
4840+#ifdef CONFIG_PAX_REFCOUNT
4841+ "tvs %%xcc, 6\n"
4842+#endif
4843+
4844+ : "=r" (new)
4845+ : "0" (c), "ir" (a)
4846+ : "cc");
4847+
4848+ old = atomic64_cmpxchg(v, c, new);
4849 if (likely(old == c))
4850 break;
4851 c = old;
4852 }
4853- return c != (u);
4854+ return c != u;
4855 }
4856
4857 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4858diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
4859index 69358b5..9d0d492 100644
4860--- a/arch/sparc/include/asm/cache.h
4861+++ b/arch/sparc/include/asm/cache.h
4862@@ -7,10 +7,12 @@
4863 #ifndef _SPARC_CACHE_H
4864 #define _SPARC_CACHE_H
4865
4866+#include <linux/const.h>
4867+
4868 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
4869
4870 #define L1_CACHE_SHIFT 5
4871-#define L1_CACHE_BYTES 32
4872+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4873
4874 #ifdef CONFIG_SPARC32
4875 #define SMP_CACHE_BYTES_SHIFT 5
4876diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
4877index 4269ca6..e3da77f 100644
4878--- a/arch/sparc/include/asm/elf_32.h
4879+++ b/arch/sparc/include/asm/elf_32.h
4880@@ -114,6 +114,13 @@ typedef struct {
4881
4882 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
4883
4884+#ifdef CONFIG_PAX_ASLR
4885+#define PAX_ELF_ET_DYN_BASE 0x10000UL
4886+
4887+#define PAX_DELTA_MMAP_LEN 16
4888+#define PAX_DELTA_STACK_LEN 16
4889+#endif
4890+
4891 /* This yields a mask that user programs can use to figure out what
4892 instruction set this cpu supports. This can NOT be done in userspace
4893 on Sparc. */
4894diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
4895index 7df8b7f..4946269 100644
4896--- a/arch/sparc/include/asm/elf_64.h
4897+++ b/arch/sparc/include/asm/elf_64.h
4898@@ -180,6 +180,13 @@ typedef struct {
4899 #define ELF_ET_DYN_BASE 0x0000010000000000UL
4900 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
4901
4902+#ifdef CONFIG_PAX_ASLR
4903+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
4904+
4905+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
4906+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
4907+#endif
4908+
4909 extern unsigned long sparc64_elf_hwcap;
4910 #define ELF_HWCAP sparc64_elf_hwcap
4911
4912diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
4913index a790cc6..091ed94 100644
4914--- a/arch/sparc/include/asm/pgtable_32.h
4915+++ b/arch/sparc/include/asm/pgtable_32.h
4916@@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
4917 BTFIXUPDEF_INT(page_none)
4918 BTFIXUPDEF_INT(page_copy)
4919 BTFIXUPDEF_INT(page_readonly)
4920+
4921+#ifdef CONFIG_PAX_PAGEEXEC
4922+BTFIXUPDEF_INT(page_shared_noexec)
4923+BTFIXUPDEF_INT(page_copy_noexec)
4924+BTFIXUPDEF_INT(page_readonly_noexec)
4925+#endif
4926+
4927 BTFIXUPDEF_INT(page_kernel)
4928
4929 #define PMD_SHIFT SUN4C_PMD_SHIFT
4930@@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
4931 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
4932 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
4933
4934+#ifdef CONFIG_PAX_PAGEEXEC
4935+extern pgprot_t PAGE_SHARED_NOEXEC;
4936+# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
4937+# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
4938+#else
4939+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4940+# define PAGE_COPY_NOEXEC PAGE_COPY
4941+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4942+#endif
4943+
4944 extern unsigned long page_kernel;
4945
4946 #ifdef MODULE
4947diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
4948index f6ae2b2..b03ffc7 100644
4949--- a/arch/sparc/include/asm/pgtsrmmu.h
4950+++ b/arch/sparc/include/asm/pgtsrmmu.h
4951@@ -115,6 +115,13 @@
4952 SRMMU_EXEC | SRMMU_REF)
4953 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
4954 SRMMU_EXEC | SRMMU_REF)
4955+
4956+#ifdef CONFIG_PAX_PAGEEXEC
4957+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
4958+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4959+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4960+#endif
4961+
4962 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
4963 SRMMU_DIRTY | SRMMU_REF)
4964
4965diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
4966index 9689176..63c18ea 100644
4967--- a/arch/sparc/include/asm/spinlock_64.h
4968+++ b/arch/sparc/include/asm/spinlock_64.h
4969@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
4970
4971 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
4972
4973-static void inline arch_read_lock(arch_rwlock_t *lock)
4974+static inline void arch_read_lock(arch_rwlock_t *lock)
4975 {
4976 unsigned long tmp1, tmp2;
4977
4978 __asm__ __volatile__ (
4979 "1: ldsw [%2], %0\n"
4980 " brlz,pn %0, 2f\n"
4981-"4: add %0, 1, %1\n"
4982+"4: addcc %0, 1, %1\n"
4983+
4984+#ifdef CONFIG_PAX_REFCOUNT
4985+" tvs %%icc, 6\n"
4986+#endif
4987+
4988 " cas [%2], %0, %1\n"
4989 " cmp %0, %1\n"
4990 " bne,pn %%icc, 1b\n"
4991@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
4992 " .previous"
4993 : "=&r" (tmp1), "=&r" (tmp2)
4994 : "r" (lock)
4995- : "memory");
4996+ : "memory", "cc");
4997 }
4998
4999-static int inline arch_read_trylock(arch_rwlock_t *lock)
5000+static inline int arch_read_trylock(arch_rwlock_t *lock)
5001 {
5002 int tmp1, tmp2;
5003
5004@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5005 "1: ldsw [%2], %0\n"
5006 " brlz,a,pn %0, 2f\n"
5007 " mov 0, %0\n"
5008-" add %0, 1, %1\n"
5009+" addcc %0, 1, %1\n"
5010+
5011+#ifdef CONFIG_PAX_REFCOUNT
5012+" tvs %%icc, 6\n"
5013+#endif
5014+
5015 " cas [%2], %0, %1\n"
5016 " cmp %0, %1\n"
5017 " bne,pn %%icc, 1b\n"
5018@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5019 return tmp1;
5020 }
5021
5022-static void inline arch_read_unlock(arch_rwlock_t *lock)
5023+static inline void arch_read_unlock(arch_rwlock_t *lock)
5024 {
5025 unsigned long tmp1, tmp2;
5026
5027 __asm__ __volatile__(
5028 "1: lduw [%2], %0\n"
5029-" sub %0, 1, %1\n"
5030+" subcc %0, 1, %1\n"
5031+
5032+#ifdef CONFIG_PAX_REFCOUNT
5033+" tvs %%icc, 6\n"
5034+#endif
5035+
5036 " cas [%2], %0, %1\n"
5037 " cmp %0, %1\n"
5038 " bne,pn %%xcc, 1b\n"
5039@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5040 : "memory");
5041 }
5042
5043-static void inline arch_write_lock(arch_rwlock_t *lock)
5044+static inline void arch_write_lock(arch_rwlock_t *lock)
5045 {
5046 unsigned long mask, tmp1, tmp2;
5047
5048@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5049 : "memory");
5050 }
5051
5052-static void inline arch_write_unlock(arch_rwlock_t *lock)
5053+static inline void arch_write_unlock(arch_rwlock_t *lock)
5054 {
5055 __asm__ __volatile__(
5056 " stw %%g0, [%0]"
5057@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5058 : "memory");
5059 }
5060
5061-static int inline arch_write_trylock(arch_rwlock_t *lock)
5062+static inline int arch_write_trylock(arch_rwlock_t *lock)
5063 {
5064 unsigned long mask, tmp1, tmp2, result;
5065
5066diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5067index c2a1080..21ed218 100644
5068--- a/arch/sparc/include/asm/thread_info_32.h
5069+++ b/arch/sparc/include/asm/thread_info_32.h
5070@@ -50,6 +50,8 @@ struct thread_info {
5071 unsigned long w_saved;
5072
5073 struct restart_block restart_block;
5074+
5075+ unsigned long lowest_stack;
5076 };
5077
5078 /*
5079diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5080index 01d057f..0a02f7e 100644
5081--- a/arch/sparc/include/asm/thread_info_64.h
5082+++ b/arch/sparc/include/asm/thread_info_64.h
5083@@ -63,6 +63,8 @@ struct thread_info {
5084 struct pt_regs *kern_una_regs;
5085 unsigned int kern_una_insn;
5086
5087+ unsigned long lowest_stack;
5088+
5089 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5090 };
5091
5092diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5093index e88fbe5..96b0ce5 100644
5094--- a/arch/sparc/include/asm/uaccess.h
5095+++ b/arch/sparc/include/asm/uaccess.h
5096@@ -1,5 +1,13 @@
5097 #ifndef ___ASM_SPARC_UACCESS_H
5098 #define ___ASM_SPARC_UACCESS_H
5099+
5100+#ifdef __KERNEL__
5101+#ifndef __ASSEMBLY__
5102+#include <linux/types.h>
5103+extern void check_object_size(const void *ptr, unsigned long n, bool to);
5104+#endif
5105+#endif
5106+
5107 #if defined(__sparc__) && defined(__arch64__)
5108 #include <asm/uaccess_64.h>
5109 #else
5110diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5111index 8303ac4..07f333d 100644
5112--- a/arch/sparc/include/asm/uaccess_32.h
5113+++ b/arch/sparc/include/asm/uaccess_32.h
5114@@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5115
5116 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5117 {
5118- if (n && __access_ok((unsigned long) to, n))
5119+ if ((long)n < 0)
5120+ return n;
5121+
5122+ if (n && __access_ok((unsigned long) to, n)) {
5123+ if (!__builtin_constant_p(n))
5124+ check_object_size(from, n, true);
5125 return __copy_user(to, (__force void __user *) from, n);
5126- else
5127+ } else
5128 return n;
5129 }
5130
5131 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5132 {
5133+ if ((long)n < 0)
5134+ return n;
5135+
5136+ if (!__builtin_constant_p(n))
5137+ check_object_size(from, n, true);
5138+
5139 return __copy_user(to, (__force void __user *) from, n);
5140 }
5141
5142 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5143 {
5144- if (n && __access_ok((unsigned long) from, n))
5145+ if ((long)n < 0)
5146+ return n;
5147+
5148+ if (n && __access_ok((unsigned long) from, n)) {
5149+ if (!__builtin_constant_p(n))
5150+ check_object_size(to, n, false);
5151 return __copy_user((__force void __user *) to, from, n);
5152- else
5153+ } else
5154 return n;
5155 }
5156
5157 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5158 {
5159+ if ((long)n < 0)
5160+ return n;
5161+
5162 return __copy_user((__force void __user *) to, from, n);
5163 }
5164
5165diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5166index 3e1449f..5293a0e 100644
5167--- a/arch/sparc/include/asm/uaccess_64.h
5168+++ b/arch/sparc/include/asm/uaccess_64.h
5169@@ -10,6 +10,7 @@
5170 #include <linux/compiler.h>
5171 #include <linux/string.h>
5172 #include <linux/thread_info.h>
5173+#include <linux/kernel.h>
5174 #include <asm/asi.h>
5175 #include <asm/system.h>
5176 #include <asm/spitfire.h>
5177@@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5178 static inline unsigned long __must_check
5179 copy_from_user(void *to, const void __user *from, unsigned long size)
5180 {
5181- unsigned long ret = ___copy_from_user(to, from, size);
5182+ unsigned long ret;
5183
5184+ if ((long)size < 0 || size > INT_MAX)
5185+ return size;
5186+
5187+ if (!__builtin_constant_p(size))
5188+ check_object_size(to, size, false);
5189+
5190+ ret = ___copy_from_user(to, from, size);
5191 if (unlikely(ret))
5192 ret = copy_from_user_fixup(to, from, size);
5193
5194@@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5195 static inline unsigned long __must_check
5196 copy_to_user(void __user *to, const void *from, unsigned long size)
5197 {
5198- unsigned long ret = ___copy_to_user(to, from, size);
5199+ unsigned long ret;
5200
5201+ if ((long)size < 0 || size > INT_MAX)
5202+ return size;
5203+
5204+ if (!__builtin_constant_p(size))
5205+ check_object_size(from, size, true);
5206+
5207+ ret = ___copy_to_user(to, from, size);
5208 if (unlikely(ret))
5209 ret = copy_to_user_fixup(to, from, size);
5210 return ret;
5211diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5212index cb85458..e063f17 100644
5213--- a/arch/sparc/kernel/Makefile
5214+++ b/arch/sparc/kernel/Makefile
5215@@ -3,7 +3,7 @@
5216 #
5217
5218 asflags-y := -ansi
5219-ccflags-y := -Werror
5220+#ccflags-y := -Werror
5221
5222 extra-y := head_$(BITS).o
5223 extra-y += init_task.o
5224diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5225index f793742..4d880af 100644
5226--- a/arch/sparc/kernel/process_32.c
5227+++ b/arch/sparc/kernel/process_32.c
5228@@ -204,7 +204,7 @@ void __show_backtrace(unsigned long fp)
5229 rw->ins[4], rw->ins[5],
5230 rw->ins[6],
5231 rw->ins[7]);
5232- printk("%pS\n", (void *) rw->ins[7]);
5233+ printk("%pA\n", (void *) rw->ins[7]);
5234 rw = (struct reg_window32 *) rw->ins[6];
5235 }
5236 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
5237@@ -271,14 +271,14 @@ void show_regs(struct pt_regs *r)
5238
5239 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5240 r->psr, r->pc, r->npc, r->y, print_tainted());
5241- printk("PC: <%pS>\n", (void *) r->pc);
5242+ printk("PC: <%pA>\n", (void *) r->pc);
5243 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5244 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5245 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5246 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5247 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5248 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5249- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5250+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5251
5252 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5253 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5254@@ -313,7 +313,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5255 rw = (struct reg_window32 *) fp;
5256 pc = rw->ins[7];
5257 printk("[%08lx : ", pc);
5258- printk("%pS ] ", (void *) pc);
5259+ printk("%pA ] ", (void *) pc);
5260 fp = rw->ins[6];
5261 } while (++count < 16);
5262 printk("\n");
5263diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5264index 39d8b05..d1a7d90 100644
5265--- a/arch/sparc/kernel/process_64.c
5266+++ b/arch/sparc/kernel/process_64.c
5267@@ -182,14 +182,14 @@ static void show_regwindow(struct pt_regs *regs)
5268 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5269 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5270 if (regs->tstate & TSTATE_PRIV)
5271- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5272+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5273 }
5274
5275 void show_regs(struct pt_regs *regs)
5276 {
5277 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5278 regs->tpc, regs->tnpc, regs->y, print_tainted());
5279- printk("TPC: <%pS>\n", (void *) regs->tpc);
5280+ printk("TPC: <%pA>\n", (void *) regs->tpc);
5281 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5282 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5283 regs->u_regs[3]);
5284@@ -202,7 +202,7 @@ void show_regs(struct pt_regs *regs)
5285 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5286 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5287 regs->u_regs[15]);
5288- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5289+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5290 show_regwindow(regs);
5291 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5292 }
5293@@ -287,7 +287,7 @@ void arch_trigger_all_cpu_backtrace(void)
5294 ((tp && tp->task) ? tp->task->pid : -1));
5295
5296 if (gp->tstate & TSTATE_PRIV) {
5297- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5298+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5299 (void *) gp->tpc,
5300 (void *) gp->o7,
5301 (void *) gp->i7,
5302diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5303index 42b282f..28ce9f2 100644
5304--- a/arch/sparc/kernel/sys_sparc_32.c
5305+++ b/arch/sparc/kernel/sys_sparc_32.c
5306@@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5307 if (ARCH_SUN4C && len > 0x20000000)
5308 return -ENOMEM;
5309 if (!addr)
5310- addr = TASK_UNMAPPED_BASE;
5311+ addr = current->mm->mmap_base;
5312
5313 if (flags & MAP_SHARED)
5314 addr = COLOUR_ALIGN(addr);
5315@@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5316 }
5317 if (TASK_SIZE - PAGE_SIZE - len < addr)
5318 return -ENOMEM;
5319- if (!vmm || addr + len <= vmm->vm_start)
5320+ if (check_heap_stack_gap(vmm, addr, len))
5321 return addr;
5322 addr = vmm->vm_end;
5323 if (flags & MAP_SHARED)
5324diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5325index 232df99..cee1f9c 100644
5326--- a/arch/sparc/kernel/sys_sparc_64.c
5327+++ b/arch/sparc/kernel/sys_sparc_64.c
5328@@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5329 /* We do not accept a shared mapping if it would violate
5330 * cache aliasing constraints.
5331 */
5332- if ((flags & MAP_SHARED) &&
5333+ if ((filp || (flags & MAP_SHARED)) &&
5334 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5335 return -EINVAL;
5336 return addr;
5337@@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5338 if (filp || (flags & MAP_SHARED))
5339 do_color_align = 1;
5340
5341+#ifdef CONFIG_PAX_RANDMMAP
5342+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5343+#endif
5344+
5345 if (addr) {
5346 if (do_color_align)
5347 addr = COLOUR_ALIGN(addr, pgoff);
5348@@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5349 addr = PAGE_ALIGN(addr);
5350
5351 vma = find_vma(mm, addr);
5352- if (task_size - len >= addr &&
5353- (!vma || addr + len <= vma->vm_start))
5354+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5355 return addr;
5356 }
5357
5358 if (len > mm->cached_hole_size) {
5359- start_addr = addr = mm->free_area_cache;
5360+ start_addr = addr = mm->free_area_cache;
5361 } else {
5362- start_addr = addr = TASK_UNMAPPED_BASE;
5363+ start_addr = addr = mm->mmap_base;
5364 mm->cached_hole_size = 0;
5365 }
5366
5367@@ -174,14 +177,14 @@ full_search:
5368 vma = find_vma(mm, VA_EXCLUDE_END);
5369 }
5370 if (unlikely(task_size < addr)) {
5371- if (start_addr != TASK_UNMAPPED_BASE) {
5372- start_addr = addr = TASK_UNMAPPED_BASE;
5373+ if (start_addr != mm->mmap_base) {
5374+ start_addr = addr = mm->mmap_base;
5375 mm->cached_hole_size = 0;
5376 goto full_search;
5377 }
5378 return -ENOMEM;
5379 }
5380- if (likely(!vma || addr + len <= vma->vm_start)) {
5381+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5382 /*
5383 * Remember the place where we stopped the search:
5384 */
5385@@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5386 /* We do not accept a shared mapping if it would violate
5387 * cache aliasing constraints.
5388 */
5389- if ((flags & MAP_SHARED) &&
5390+ if ((filp || (flags & MAP_SHARED)) &&
5391 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5392 return -EINVAL;
5393 return addr;
5394@@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5395 addr = PAGE_ALIGN(addr);
5396
5397 vma = find_vma(mm, addr);
5398- if (task_size - len >= addr &&
5399- (!vma || addr + len <= vma->vm_start))
5400+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5401 return addr;
5402 }
5403
5404@@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5405 /* make sure it can fit in the remaining address space */
5406 if (likely(addr > len)) {
5407 vma = find_vma(mm, addr-len);
5408- if (!vma || addr <= vma->vm_start) {
5409+ if (check_heap_stack_gap(vma, addr - len, len)) {
5410 /* remember the address as a hint for next time */
5411 return (mm->free_area_cache = addr-len);
5412 }
5413@@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5414 if (unlikely(mm->mmap_base < len))
5415 goto bottomup;
5416
5417- addr = mm->mmap_base-len;
5418- if (do_color_align)
5419- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5420+ addr = mm->mmap_base - len;
5421
5422 do {
5423+ if (do_color_align)
5424+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5425 /*
5426 * Lookup failure means no vma is above this address,
5427 * else if new region fits below vma->vm_start,
5428 * return with success:
5429 */
5430 vma = find_vma(mm, addr);
5431- if (likely(!vma || addr+len <= vma->vm_start)) {
5432+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5433 /* remember the address as a hint for next time */
5434 return (mm->free_area_cache = addr);
5435 }
5436@@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5437 mm->cached_hole_size = vma->vm_start - addr;
5438
5439 /* try just below the current vma->vm_start */
5440- addr = vma->vm_start-len;
5441- if (do_color_align)
5442- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5443- } while (likely(len < vma->vm_start));
5444+ addr = skip_heap_stack_gap(vma, len);
5445+ } while (!IS_ERR_VALUE(addr));
5446
5447 bottomup:
5448 /*
5449@@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5450 gap == RLIM_INFINITY ||
5451 sysctl_legacy_va_layout) {
5452 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5453+
5454+#ifdef CONFIG_PAX_RANDMMAP
5455+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5456+ mm->mmap_base += mm->delta_mmap;
5457+#endif
5458+
5459 mm->get_unmapped_area = arch_get_unmapped_area;
5460 mm->unmap_area = arch_unmap_area;
5461 } else {
5462@@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5463 gap = (task_size / 6 * 5);
5464
5465 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5466+
5467+#ifdef CONFIG_PAX_RANDMMAP
5468+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5469+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5470+#endif
5471+
5472 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5473 mm->unmap_area = arch_unmap_area_topdown;
5474 }
5475diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
5476index 591f20c..0f1b925 100644
5477--- a/arch/sparc/kernel/traps_32.c
5478+++ b/arch/sparc/kernel/traps_32.c
5479@@ -45,6 +45,8 @@ static void instruction_dump(unsigned long *pc)
5480 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
5481 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
5482
5483+extern void gr_handle_kernel_exploit(void);
5484+
5485 void die_if_kernel(char *str, struct pt_regs *regs)
5486 {
5487 static int die_counter;
5488@@ -77,15 +79,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5489 count++ < 30 &&
5490 (((unsigned long) rw) >= PAGE_OFFSET) &&
5491 !(((unsigned long) rw) & 0x7)) {
5492- printk("Caller[%08lx]: %pS\n", rw->ins[7],
5493+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
5494 (void *) rw->ins[7]);
5495 rw = (struct reg_window32 *)rw->ins[6];
5496 }
5497 }
5498 printk("Instruction DUMP:");
5499 instruction_dump ((unsigned long *) regs->pc);
5500- if(regs->psr & PSR_PS)
5501+ if(regs->psr & PSR_PS) {
5502+ gr_handle_kernel_exploit();
5503 do_exit(SIGKILL);
5504+ }
5505 do_exit(SIGSEGV);
5506 }
5507
5508diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
5509index 0cbdaa4..438e4c9 100644
5510--- a/arch/sparc/kernel/traps_64.c
5511+++ b/arch/sparc/kernel/traps_64.c
5512@@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
5513 i + 1,
5514 p->trapstack[i].tstate, p->trapstack[i].tpc,
5515 p->trapstack[i].tnpc, p->trapstack[i].tt);
5516- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
5517+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
5518 }
5519 }
5520
5521@@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
5522
5523 lvl -= 0x100;
5524 if (regs->tstate & TSTATE_PRIV) {
5525+
5526+#ifdef CONFIG_PAX_REFCOUNT
5527+ if (lvl == 6)
5528+ pax_report_refcount_overflow(regs);
5529+#endif
5530+
5531 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
5532 die_if_kernel(buffer, regs);
5533 }
5534@@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
5535 void bad_trap_tl1(struct pt_regs *regs, long lvl)
5536 {
5537 char buffer[32];
5538-
5539+
5540 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
5541 0, lvl, SIGTRAP) == NOTIFY_STOP)
5542 return;
5543
5544+#ifdef CONFIG_PAX_REFCOUNT
5545+ if (lvl == 6)
5546+ pax_report_refcount_overflow(regs);
5547+#endif
5548+
5549 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
5550
5551 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
5552@@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
5553 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
5554 printk("%s" "ERROR(%d): ",
5555 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
5556- printk("TPC<%pS>\n", (void *) regs->tpc);
5557+ printk("TPC<%pA>\n", (void *) regs->tpc);
5558 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
5559 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
5560 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
5561@@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
5562 smp_processor_id(),
5563 (type & 0x1) ? 'I' : 'D',
5564 regs->tpc);
5565- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
5566+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
5567 panic("Irrecoverable Cheetah+ parity error.");
5568 }
5569
5570@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
5571 smp_processor_id(),
5572 (type & 0x1) ? 'I' : 'D',
5573 regs->tpc);
5574- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
5575+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
5576 }
5577
5578 struct sun4v_error_entry {
5579@@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
5580
5581 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
5582 regs->tpc, tl);
5583- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
5584+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
5585 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5586- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
5587+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
5588 (void *) regs->u_regs[UREG_I7]);
5589 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
5590 "pte[%lx] error[%lx]\n",
5591@@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
5592
5593 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
5594 regs->tpc, tl);
5595- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
5596+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
5597 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5598- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
5599+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
5600 (void *) regs->u_regs[UREG_I7]);
5601 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
5602 "pte[%lx] error[%lx]\n",
5603@@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5604 fp = (unsigned long)sf->fp + STACK_BIAS;
5605 }
5606
5607- printk(" [%016lx] %pS\n", pc, (void *) pc);
5608+ printk(" [%016lx] %pA\n", pc, (void *) pc);
5609 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
5610 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
5611 int index = tsk->curr_ret_stack;
5612 if (tsk->ret_stack && index >= graph) {
5613 pc = tsk->ret_stack[index - graph].ret;
5614- printk(" [%016lx] %pS\n", pc, (void *) pc);
5615+ printk(" [%016lx] %pA\n", pc, (void *) pc);
5616 graph++;
5617 }
5618 }
5619@@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
5620 return (struct reg_window *) (fp + STACK_BIAS);
5621 }
5622
5623+extern void gr_handle_kernel_exploit(void);
5624+
5625 void die_if_kernel(char *str, struct pt_regs *regs)
5626 {
5627 static int die_counter;
5628@@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5629 while (rw &&
5630 count++ < 30 &&
5631 kstack_valid(tp, (unsigned long) rw)) {
5632- printk("Caller[%016lx]: %pS\n", rw->ins[7],
5633+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
5634 (void *) rw->ins[7]);
5635
5636 rw = kernel_stack_up(rw);
5637@@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5638 }
5639 user_instruction_dump ((unsigned int __user *) regs->tpc);
5640 }
5641- if (regs->tstate & TSTATE_PRIV)
5642+ if (regs->tstate & TSTATE_PRIV) {
5643+ gr_handle_kernel_exploit();
5644 do_exit(SIGKILL);
5645+ }
5646 do_exit(SIGSEGV);
5647 }
5648 EXPORT_SYMBOL(die_if_kernel);
5649diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
5650index 76e4ac1..78f8bb1 100644
5651--- a/arch/sparc/kernel/unaligned_64.c
5652+++ b/arch/sparc/kernel/unaligned_64.c
5653@@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs *regs)
5654 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
5655
5656 if (__ratelimit(&ratelimit)) {
5657- printk("Kernel unaligned access at TPC[%lx] %pS\n",
5658+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
5659 regs->tpc, (void *) regs->tpc);
5660 }
5661 }
5662diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
5663index a3fc437..fea9957 100644
5664--- a/arch/sparc/lib/Makefile
5665+++ b/arch/sparc/lib/Makefile
5666@@ -2,7 +2,7 @@
5667 #
5668
5669 asflags-y := -ansi -DST_DIV0=0x02
5670-ccflags-y := -Werror
5671+#ccflags-y := -Werror
5672
5673 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
5674 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
5675diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
5676index 59186e0..f747d7a 100644
5677--- a/arch/sparc/lib/atomic_64.S
5678+++ b/arch/sparc/lib/atomic_64.S
5679@@ -18,7 +18,12 @@
5680 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
5681 BACKOFF_SETUP(%o2)
5682 1: lduw [%o1], %g1
5683- add %g1, %o0, %g7
5684+ addcc %g1, %o0, %g7
5685+
5686+#ifdef CONFIG_PAX_REFCOUNT
5687+ tvs %icc, 6
5688+#endif
5689+
5690 cas [%o1], %g1, %g7
5691 cmp %g1, %g7
5692 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5693@@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
5694 2: BACKOFF_SPIN(%o2, %o3, 1b)
5695 .size atomic_add, .-atomic_add
5696
5697+ .globl atomic_add_unchecked
5698+ .type atomic_add_unchecked,#function
5699+atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5700+ BACKOFF_SETUP(%o2)
5701+1: lduw [%o1], %g1
5702+ add %g1, %o0, %g7
5703+ cas [%o1], %g1, %g7
5704+ cmp %g1, %g7
5705+ bne,pn %icc, 2f
5706+ nop
5707+ retl
5708+ nop
5709+2: BACKOFF_SPIN(%o2, %o3, 1b)
5710+ .size atomic_add_unchecked, .-atomic_add_unchecked
5711+
5712 .globl atomic_sub
5713 .type atomic_sub,#function
5714 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5715 BACKOFF_SETUP(%o2)
5716 1: lduw [%o1], %g1
5717- sub %g1, %o0, %g7
5718+ subcc %g1, %o0, %g7
5719+
5720+#ifdef CONFIG_PAX_REFCOUNT
5721+ tvs %icc, 6
5722+#endif
5723+
5724 cas [%o1], %g1, %g7
5725 cmp %g1, %g7
5726 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5727@@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5728 2: BACKOFF_SPIN(%o2, %o3, 1b)
5729 .size atomic_sub, .-atomic_sub
5730
5731+ .globl atomic_sub_unchecked
5732+ .type atomic_sub_unchecked,#function
5733+atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
5734+ BACKOFF_SETUP(%o2)
5735+1: lduw [%o1], %g1
5736+ sub %g1, %o0, %g7
5737+ cas [%o1], %g1, %g7
5738+ cmp %g1, %g7
5739+ bne,pn %icc, 2f
5740+ nop
5741+ retl
5742+ nop
5743+2: BACKOFF_SPIN(%o2, %o3, 1b)
5744+ .size atomic_sub_unchecked, .-atomic_sub_unchecked
5745+
5746 .globl atomic_add_ret
5747 .type atomic_add_ret,#function
5748 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5749 BACKOFF_SETUP(%o2)
5750 1: lduw [%o1], %g1
5751- add %g1, %o0, %g7
5752+ addcc %g1, %o0, %g7
5753+
5754+#ifdef CONFIG_PAX_REFCOUNT
5755+ tvs %icc, 6
5756+#endif
5757+
5758 cas [%o1], %g1, %g7
5759 cmp %g1, %g7
5760 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5761@@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5762 2: BACKOFF_SPIN(%o2, %o3, 1b)
5763 .size atomic_add_ret, .-atomic_add_ret
5764
5765+ .globl atomic_add_ret_unchecked
5766+ .type atomic_add_ret_unchecked,#function
5767+atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5768+ BACKOFF_SETUP(%o2)
5769+1: lduw [%o1], %g1
5770+ addcc %g1, %o0, %g7
5771+ cas [%o1], %g1, %g7
5772+ cmp %g1, %g7
5773+ bne,pn %icc, 2f
5774+ add %g7, %o0, %g7
5775+ sra %g7, 0, %o0
5776+ retl
5777+ nop
5778+2: BACKOFF_SPIN(%o2, %o3, 1b)
5779+ .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
5780+
5781 .globl atomic_sub_ret
5782 .type atomic_sub_ret,#function
5783 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5784 BACKOFF_SETUP(%o2)
5785 1: lduw [%o1], %g1
5786- sub %g1, %o0, %g7
5787+ subcc %g1, %o0, %g7
5788+
5789+#ifdef CONFIG_PAX_REFCOUNT
5790+ tvs %icc, 6
5791+#endif
5792+
5793 cas [%o1], %g1, %g7
5794 cmp %g1, %g7
5795 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
5796@@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5797 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
5798 BACKOFF_SETUP(%o2)
5799 1: ldx [%o1], %g1
5800- add %g1, %o0, %g7
5801+ addcc %g1, %o0, %g7
5802+
5803+#ifdef CONFIG_PAX_REFCOUNT
5804+ tvs %xcc, 6
5805+#endif
5806+
5807 casx [%o1], %g1, %g7
5808 cmp %g1, %g7
5809 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5810@@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
5811 2: BACKOFF_SPIN(%o2, %o3, 1b)
5812 .size atomic64_add, .-atomic64_add
5813
5814+ .globl atomic64_add_unchecked
5815+ .type atomic64_add_unchecked,#function
5816+atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5817+ BACKOFF_SETUP(%o2)
5818+1: ldx [%o1], %g1
5819+ addcc %g1, %o0, %g7
5820+ casx [%o1], %g1, %g7
5821+ cmp %g1, %g7
5822+ bne,pn %xcc, 2f
5823+ nop
5824+ retl
5825+ nop
5826+2: BACKOFF_SPIN(%o2, %o3, 1b)
5827+ .size atomic64_add_unchecked, .-atomic64_add_unchecked
5828+
5829 .globl atomic64_sub
5830 .type atomic64_sub,#function
5831 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5832 BACKOFF_SETUP(%o2)
5833 1: ldx [%o1], %g1
5834- sub %g1, %o0, %g7
5835+ subcc %g1, %o0, %g7
5836+
5837+#ifdef CONFIG_PAX_REFCOUNT
5838+ tvs %xcc, 6
5839+#endif
5840+
5841 casx [%o1], %g1, %g7
5842 cmp %g1, %g7
5843 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5844@@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5845 2: BACKOFF_SPIN(%o2, %o3, 1b)
5846 .size atomic64_sub, .-atomic64_sub
5847
5848+ .globl atomic64_sub_unchecked
5849+ .type atomic64_sub_unchecked,#function
5850+atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
5851+ BACKOFF_SETUP(%o2)
5852+1: ldx [%o1], %g1
5853+ subcc %g1, %o0, %g7
5854+ casx [%o1], %g1, %g7
5855+ cmp %g1, %g7
5856+ bne,pn %xcc, 2f
5857+ nop
5858+ retl
5859+ nop
5860+2: BACKOFF_SPIN(%o2, %o3, 1b)
5861+ .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
5862+
5863 .globl atomic64_add_ret
5864 .type atomic64_add_ret,#function
5865 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5866 BACKOFF_SETUP(%o2)
5867 1: ldx [%o1], %g1
5868- add %g1, %o0, %g7
5869+ addcc %g1, %o0, %g7
5870+
5871+#ifdef CONFIG_PAX_REFCOUNT
5872+ tvs %xcc, 6
5873+#endif
5874+
5875 casx [%o1], %g1, %g7
5876 cmp %g1, %g7
5877 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5878@@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5879 2: BACKOFF_SPIN(%o2, %o3, 1b)
5880 .size atomic64_add_ret, .-atomic64_add_ret
5881
5882+ .globl atomic64_add_ret_unchecked
5883+ .type atomic64_add_ret_unchecked,#function
5884+atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5885+ BACKOFF_SETUP(%o2)
5886+1: ldx [%o1], %g1
5887+ addcc %g1, %o0, %g7
5888+ casx [%o1], %g1, %g7
5889+ cmp %g1, %g7
5890+ bne,pn %xcc, 2f
5891+ add %g7, %o0, %g7
5892+ mov %g7, %o0
5893+ retl
5894+ nop
5895+2: BACKOFF_SPIN(%o2, %o3, 1b)
5896+ .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
5897+
5898 .globl atomic64_sub_ret
5899 .type atomic64_sub_ret,#function
5900 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5901 BACKOFF_SETUP(%o2)
5902 1: ldx [%o1], %g1
5903- sub %g1, %o0, %g7
5904+ subcc %g1, %o0, %g7
5905+
5906+#ifdef CONFIG_PAX_REFCOUNT
5907+ tvs %xcc, 6
5908+#endif
5909+
5910 casx [%o1], %g1, %g7
5911 cmp %g1, %g7
5912 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
5913diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
5914index f73c224..662af10 100644
5915--- a/arch/sparc/lib/ksyms.c
5916+++ b/arch/sparc/lib/ksyms.c
5917@@ -136,12 +136,18 @@ EXPORT_SYMBOL(__downgrade_write);
5918
5919 /* Atomic counter implementation. */
5920 EXPORT_SYMBOL(atomic_add);
5921+EXPORT_SYMBOL(atomic_add_unchecked);
5922 EXPORT_SYMBOL(atomic_add_ret);
5923+EXPORT_SYMBOL(atomic_add_ret_unchecked);
5924 EXPORT_SYMBOL(atomic_sub);
5925+EXPORT_SYMBOL(atomic_sub_unchecked);
5926 EXPORT_SYMBOL(atomic_sub_ret);
5927 EXPORT_SYMBOL(atomic64_add);
5928+EXPORT_SYMBOL(atomic64_add_unchecked);
5929 EXPORT_SYMBOL(atomic64_add_ret);
5930+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
5931 EXPORT_SYMBOL(atomic64_sub);
5932+EXPORT_SYMBOL(atomic64_sub_unchecked);
5933 EXPORT_SYMBOL(atomic64_sub_ret);
5934
5935 /* Atomic bit operations. */
5936diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
5937index 301421c..e2535d1 100644
5938--- a/arch/sparc/mm/Makefile
5939+++ b/arch/sparc/mm/Makefile
5940@@ -2,7 +2,7 @@
5941 #
5942
5943 asflags-y := -ansi
5944-ccflags-y := -Werror
5945+#ccflags-y := -Werror
5946
5947 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
5948 obj-y += fault_$(BITS).o
5949diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
5950index 8023fd7..c8e89e9 100644
5951--- a/arch/sparc/mm/fault_32.c
5952+++ b/arch/sparc/mm/fault_32.c
5953@@ -21,6 +21,9 @@
5954 #include <linux/perf_event.h>
5955 #include <linux/interrupt.h>
5956 #include <linux/kdebug.h>
5957+#include <linux/slab.h>
5958+#include <linux/pagemap.h>
5959+#include <linux/compiler.h>
5960
5961 #include <asm/system.h>
5962 #include <asm/page.h>
5963@@ -208,6 +211,268 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
5964 return safe_compute_effective_address(regs, insn);
5965 }
5966
5967+#ifdef CONFIG_PAX_PAGEEXEC
5968+#ifdef CONFIG_PAX_DLRESOLVE
5969+static void pax_emuplt_close(struct vm_area_struct *vma)
5970+{
5971+ vma->vm_mm->call_dl_resolve = 0UL;
5972+}
5973+
5974+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
5975+{
5976+ unsigned int *kaddr;
5977+
5978+ vmf->page = alloc_page(GFP_HIGHUSER);
5979+ if (!vmf->page)
5980+ return VM_FAULT_OOM;
5981+
5982+ kaddr = kmap(vmf->page);
5983+ memset(kaddr, 0, PAGE_SIZE);
5984+ kaddr[0] = 0x9DE3BFA8U; /* save */
5985+ flush_dcache_page(vmf->page);
5986+ kunmap(vmf->page);
5987+ return VM_FAULT_MAJOR;
5988+}
5989+
5990+static const struct vm_operations_struct pax_vm_ops = {
5991+ .close = pax_emuplt_close,
5992+ .fault = pax_emuplt_fault
5993+};
5994+
5995+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
5996+{
5997+ int ret;
5998+
5999+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6000+ vma->vm_mm = current->mm;
6001+ vma->vm_start = addr;
6002+ vma->vm_end = addr + PAGE_SIZE;
6003+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6004+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6005+ vma->vm_ops = &pax_vm_ops;
6006+
6007+ ret = insert_vm_struct(current->mm, vma);
6008+ if (ret)
6009+ return ret;
6010+
6011+ ++current->mm->total_vm;
6012+ return 0;
6013+}
6014+#endif
6015+
6016+/*
6017+ * PaX: decide what to do with offenders (regs->pc = fault address)
6018+ *
6019+ * returns 1 when task should be killed
6020+ * 2 when patched PLT trampoline was detected
6021+ * 3 when unpatched PLT trampoline was detected
6022+ */
6023+static int pax_handle_fetch_fault(struct pt_regs *regs)
6024+{
6025+
6026+#ifdef CONFIG_PAX_EMUPLT
6027+ int err;
6028+
6029+ do { /* PaX: patched PLT emulation #1 */
6030+ unsigned int sethi1, sethi2, jmpl;
6031+
6032+ err = get_user(sethi1, (unsigned int *)regs->pc);
6033+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6034+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6035+
6036+ if (err)
6037+ break;
6038+
6039+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6040+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6041+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6042+ {
6043+ unsigned int addr;
6044+
6045+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6046+ addr = regs->u_regs[UREG_G1];
6047+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6048+ regs->pc = addr;
6049+ regs->npc = addr+4;
6050+ return 2;
6051+ }
6052+ } while (0);
6053+
6054+ { /* PaX: patched PLT emulation #2 */
6055+ unsigned int ba;
6056+
6057+ err = get_user(ba, (unsigned int *)regs->pc);
6058+
6059+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6060+ unsigned int addr;
6061+
6062+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6063+ regs->pc = addr;
6064+ regs->npc = addr+4;
6065+ return 2;
6066+ }
6067+ }
6068+
6069+ do { /* PaX: patched PLT emulation #3 */
6070+ unsigned int sethi, jmpl, nop;
6071+
6072+ err = get_user(sethi, (unsigned int *)regs->pc);
6073+ err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
6074+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6075+
6076+ if (err)
6077+ break;
6078+
6079+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6080+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6081+ nop == 0x01000000U)
6082+ {
6083+ unsigned int addr;
6084+
6085+ addr = (sethi & 0x003FFFFFU) << 10;
6086+ regs->u_regs[UREG_G1] = addr;
6087+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6088+ regs->pc = addr;
6089+ regs->npc = addr+4;
6090+ return 2;
6091+ }
6092+ } while (0);
6093+
6094+ do { /* PaX: unpatched PLT emulation step 1 */
6095+ unsigned int sethi, ba, nop;
6096+
6097+ err = get_user(sethi, (unsigned int *)regs->pc);
6098+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
6099+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6100+
6101+ if (err)
6102+ break;
6103+
6104+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6105+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6106+ nop == 0x01000000U)
6107+ {
6108+ unsigned int addr, save, call;
6109+
6110+ if ((ba & 0xFFC00000U) == 0x30800000U)
6111+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6112+ else
6113+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6114+
6115+ err = get_user(save, (unsigned int *)addr);
6116+ err |= get_user(call, (unsigned int *)(addr+4));
6117+ err |= get_user(nop, (unsigned int *)(addr+8));
6118+ if (err)
6119+ break;
6120+
6121+#ifdef CONFIG_PAX_DLRESOLVE
6122+ if (save == 0x9DE3BFA8U &&
6123+ (call & 0xC0000000U) == 0x40000000U &&
6124+ nop == 0x01000000U)
6125+ {
6126+ struct vm_area_struct *vma;
6127+ unsigned long call_dl_resolve;
6128+
6129+ down_read(&current->mm->mmap_sem);
6130+ call_dl_resolve = current->mm->call_dl_resolve;
6131+ up_read(&current->mm->mmap_sem);
6132+ if (likely(call_dl_resolve))
6133+ goto emulate;
6134+
6135+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6136+
6137+ down_write(&current->mm->mmap_sem);
6138+ if (current->mm->call_dl_resolve) {
6139+ call_dl_resolve = current->mm->call_dl_resolve;
6140+ up_write(&current->mm->mmap_sem);
6141+ if (vma)
6142+ kmem_cache_free(vm_area_cachep, vma);
6143+ goto emulate;
6144+ }
6145+
6146+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6147+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6148+ up_write(&current->mm->mmap_sem);
6149+ if (vma)
6150+ kmem_cache_free(vm_area_cachep, vma);
6151+ return 1;
6152+ }
6153+
6154+ if (pax_insert_vma(vma, call_dl_resolve)) {
6155+ up_write(&current->mm->mmap_sem);
6156+ kmem_cache_free(vm_area_cachep, vma);
6157+ return 1;
6158+ }
6159+
6160+ current->mm->call_dl_resolve = call_dl_resolve;
6161+ up_write(&current->mm->mmap_sem);
6162+
6163+emulate:
6164+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6165+ regs->pc = call_dl_resolve;
6166+ regs->npc = addr+4;
6167+ return 3;
6168+ }
6169+#endif
6170+
6171+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6172+ if ((save & 0xFFC00000U) == 0x05000000U &&
6173+ (call & 0xFFFFE000U) == 0x85C0A000U &&
6174+ nop == 0x01000000U)
6175+ {
6176+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6177+ regs->u_regs[UREG_G2] = addr + 4;
6178+ addr = (save & 0x003FFFFFU) << 10;
6179+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6180+ regs->pc = addr;
6181+ regs->npc = addr+4;
6182+ return 3;
6183+ }
6184+ }
6185+ } while (0);
6186+
6187+ do { /* PaX: unpatched PLT emulation step 2 */
6188+ unsigned int save, call, nop;
6189+
6190+ err = get_user(save, (unsigned int *)(regs->pc-4));
6191+ err |= get_user(call, (unsigned int *)regs->pc);
6192+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
6193+ if (err)
6194+ break;
6195+
6196+ if (save == 0x9DE3BFA8U &&
6197+ (call & 0xC0000000U) == 0x40000000U &&
6198+ nop == 0x01000000U)
6199+ {
6200+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6201+
6202+ regs->u_regs[UREG_RETPC] = regs->pc;
6203+ regs->pc = dl_resolve;
6204+ regs->npc = dl_resolve+4;
6205+ return 3;
6206+ }
6207+ } while (0);
6208+#endif
6209+
6210+ return 1;
6211+}
6212+
6213+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6214+{
6215+ unsigned long i;
6216+
6217+ printk(KERN_ERR "PAX: bytes at PC: ");
6218+ for (i = 0; i < 8; i++) {
6219+ unsigned int c;
6220+ if (get_user(c, (unsigned int *)pc+i))
6221+ printk(KERN_CONT "???????? ");
6222+ else
6223+ printk(KERN_CONT "%08x ", c);
6224+ }
6225+ printk("\n");
6226+}
6227+#endif
6228+
6229 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6230 int text_fault)
6231 {
6232@@ -280,6 +545,24 @@ good_area:
6233 if(!(vma->vm_flags & VM_WRITE))
6234 goto bad_area;
6235 } else {
6236+
6237+#ifdef CONFIG_PAX_PAGEEXEC
6238+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6239+ up_read(&mm->mmap_sem);
6240+ switch (pax_handle_fetch_fault(regs)) {
6241+
6242+#ifdef CONFIG_PAX_EMUPLT
6243+ case 2:
6244+ case 3:
6245+ return;
6246+#endif
6247+
6248+ }
6249+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6250+ do_group_exit(SIGKILL);
6251+ }
6252+#endif
6253+
6254 /* Allow reads even for write-only mappings */
6255 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6256 goto bad_area;
6257diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6258index 504c062..6fcb9c6 100644
6259--- a/arch/sparc/mm/fault_64.c
6260+++ b/arch/sparc/mm/fault_64.c
6261@@ -21,6 +21,9 @@
6262 #include <linux/kprobes.h>
6263 #include <linux/kdebug.h>
6264 #include <linux/percpu.h>
6265+#include <linux/slab.h>
6266+#include <linux/pagemap.h>
6267+#include <linux/compiler.h>
6268
6269 #include <asm/page.h>
6270 #include <asm/pgtable.h>
6271@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6272 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6273 regs->tpc);
6274 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6275- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6276+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6277 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6278 dump_stack();
6279 unhandled_fault(regs->tpc, current, regs);
6280@@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6281 show_regs(regs);
6282 }
6283
6284+#ifdef CONFIG_PAX_PAGEEXEC
6285+#ifdef CONFIG_PAX_DLRESOLVE
6286+static void pax_emuplt_close(struct vm_area_struct *vma)
6287+{
6288+ vma->vm_mm->call_dl_resolve = 0UL;
6289+}
6290+
6291+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6292+{
6293+ unsigned int *kaddr;
6294+
6295+ vmf->page = alloc_page(GFP_HIGHUSER);
6296+ if (!vmf->page)
6297+ return VM_FAULT_OOM;
6298+
6299+ kaddr = kmap(vmf->page);
6300+ memset(kaddr, 0, PAGE_SIZE);
6301+ kaddr[0] = 0x9DE3BFA8U; /* save */
6302+ flush_dcache_page(vmf->page);
6303+ kunmap(vmf->page);
6304+ return VM_FAULT_MAJOR;
6305+}
6306+
6307+static const struct vm_operations_struct pax_vm_ops = {
6308+ .close = pax_emuplt_close,
6309+ .fault = pax_emuplt_fault
6310+};
6311+
6312+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6313+{
6314+ int ret;
6315+
6316+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6317+ vma->vm_mm = current->mm;
6318+ vma->vm_start = addr;
6319+ vma->vm_end = addr + PAGE_SIZE;
6320+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6321+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6322+ vma->vm_ops = &pax_vm_ops;
6323+
6324+ ret = insert_vm_struct(current->mm, vma);
6325+ if (ret)
6326+ return ret;
6327+
6328+ ++current->mm->total_vm;
6329+ return 0;
6330+}
6331+#endif
6332+
6333+/*
6334+ * PaX: decide what to do with offenders (regs->tpc = fault address)
6335+ *
6336+ * returns 1 when task should be killed
6337+ * 2 when patched PLT trampoline was detected
6338+ * 3 when unpatched PLT trampoline was detected
6339+ */
6340+static int pax_handle_fetch_fault(struct pt_regs *regs)
6341+{
6342+
6343+#ifdef CONFIG_PAX_EMUPLT
6344+ int err;
6345+
6346+ do { /* PaX: patched PLT emulation #1 */
6347+ unsigned int sethi1, sethi2, jmpl;
6348+
6349+ err = get_user(sethi1, (unsigned int *)regs->tpc);
6350+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6351+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6352+
6353+ if (err)
6354+ break;
6355+
6356+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6357+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6358+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6359+ {
6360+ unsigned long addr;
6361+
6362+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6363+ addr = regs->u_regs[UREG_G1];
6364+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6365+
6366+ if (test_thread_flag(TIF_32BIT))
6367+ addr &= 0xFFFFFFFFUL;
6368+
6369+ regs->tpc = addr;
6370+ regs->tnpc = addr+4;
6371+ return 2;
6372+ }
6373+ } while (0);
6374+
6375+ { /* PaX: patched PLT emulation #2 */
6376+ unsigned int ba;
6377+
6378+ err = get_user(ba, (unsigned int *)regs->tpc);
6379+
6380+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6381+ unsigned long addr;
6382+
6383+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6384+
6385+ if (test_thread_flag(TIF_32BIT))
6386+ addr &= 0xFFFFFFFFUL;
6387+
6388+ regs->tpc = addr;
6389+ regs->tnpc = addr+4;
6390+ return 2;
6391+ }
6392+ }
6393+
6394+ do { /* PaX: patched PLT emulation #3 */
6395+ unsigned int sethi, jmpl, nop;
6396+
6397+ err = get_user(sethi, (unsigned int *)regs->tpc);
6398+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
6399+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6400+
6401+ if (err)
6402+ break;
6403+
6404+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6405+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6406+ nop == 0x01000000U)
6407+ {
6408+ unsigned long addr;
6409+
6410+ addr = (sethi & 0x003FFFFFU) << 10;
6411+ regs->u_regs[UREG_G1] = addr;
6412+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6413+
6414+ if (test_thread_flag(TIF_32BIT))
6415+ addr &= 0xFFFFFFFFUL;
6416+
6417+ regs->tpc = addr;
6418+ regs->tnpc = addr+4;
6419+ return 2;
6420+ }
6421+ } while (0);
6422+
6423+ do { /* PaX: patched PLT emulation #4 */
6424+ unsigned int sethi, mov1, call, mov2;
6425+
6426+ err = get_user(sethi, (unsigned int *)regs->tpc);
6427+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6428+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
6429+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6430+
6431+ if (err)
6432+ break;
6433+
6434+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6435+ mov1 == 0x8210000FU &&
6436+ (call & 0xC0000000U) == 0x40000000U &&
6437+ mov2 == 0x9E100001U)
6438+ {
6439+ unsigned long addr;
6440+
6441+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6442+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6443+
6444+ if (test_thread_flag(TIF_32BIT))
6445+ addr &= 0xFFFFFFFFUL;
6446+
6447+ regs->tpc = addr;
6448+ regs->tnpc = addr+4;
6449+ return 2;
6450+ }
6451+ } while (0);
6452+
6453+ do { /* PaX: patched PLT emulation #5 */
6454+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6455+
6456+ err = get_user(sethi, (unsigned int *)regs->tpc);
6457+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6458+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6459+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6460+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6461+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6462+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6463+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6464+
6465+ if (err)
6466+ break;
6467+
6468+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6469+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
6470+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6471+ (or1 & 0xFFFFE000U) == 0x82106000U &&
6472+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
6473+ sllx == 0x83287020U &&
6474+ jmpl == 0x81C04005U &&
6475+ nop == 0x01000000U)
6476+ {
6477+ unsigned long addr;
6478+
6479+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6480+ regs->u_regs[UREG_G1] <<= 32;
6481+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6482+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6483+ regs->tpc = addr;
6484+ regs->tnpc = addr+4;
6485+ return 2;
6486+ }
6487+ } while (0);
6488+
6489+ do { /* PaX: patched PLT emulation #6 */
6490+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
6491+
6492+ err = get_user(sethi, (unsigned int *)regs->tpc);
6493+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6494+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6495+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
6496+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
6497+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
6498+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
6499+
6500+ if (err)
6501+ break;
6502+
6503+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6504+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
6505+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6506+ sllx == 0x83287020U &&
6507+ (or & 0xFFFFE000U) == 0x8A116000U &&
6508+ jmpl == 0x81C04005U &&
6509+ nop == 0x01000000U)
6510+ {
6511+ unsigned long addr;
6512+
6513+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
6514+ regs->u_regs[UREG_G1] <<= 32;
6515+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
6516+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6517+ regs->tpc = addr;
6518+ regs->tnpc = addr+4;
6519+ return 2;
6520+ }
6521+ } while (0);
6522+
6523+ do { /* PaX: unpatched PLT emulation step 1 */
6524+ unsigned int sethi, ba, nop;
6525+
6526+ err = get_user(sethi, (unsigned int *)regs->tpc);
6527+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6528+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6529+
6530+ if (err)
6531+ break;
6532+
6533+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6534+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6535+ nop == 0x01000000U)
6536+ {
6537+ unsigned long addr;
6538+ unsigned int save, call;
6539+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
6540+
6541+ if ((ba & 0xFFC00000U) == 0x30800000U)
6542+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6543+ else
6544+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6545+
6546+ if (test_thread_flag(TIF_32BIT))
6547+ addr &= 0xFFFFFFFFUL;
6548+
6549+ err = get_user(save, (unsigned int *)addr);
6550+ err |= get_user(call, (unsigned int *)(addr+4));
6551+ err |= get_user(nop, (unsigned int *)(addr+8));
6552+ if (err)
6553+ break;
6554+
6555+#ifdef CONFIG_PAX_DLRESOLVE
6556+ if (save == 0x9DE3BFA8U &&
6557+ (call & 0xC0000000U) == 0x40000000U &&
6558+ nop == 0x01000000U)
6559+ {
6560+ struct vm_area_struct *vma;
6561+ unsigned long call_dl_resolve;
6562+
6563+ down_read(&current->mm->mmap_sem);
6564+ call_dl_resolve = current->mm->call_dl_resolve;
6565+ up_read(&current->mm->mmap_sem);
6566+ if (likely(call_dl_resolve))
6567+ goto emulate;
6568+
6569+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6570+
6571+ down_write(&current->mm->mmap_sem);
6572+ if (current->mm->call_dl_resolve) {
6573+ call_dl_resolve = current->mm->call_dl_resolve;
6574+ up_write(&current->mm->mmap_sem);
6575+ if (vma)
6576+ kmem_cache_free(vm_area_cachep, vma);
6577+ goto emulate;
6578+ }
6579+
6580+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6581+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6582+ up_write(&current->mm->mmap_sem);
6583+ if (vma)
6584+ kmem_cache_free(vm_area_cachep, vma);
6585+ return 1;
6586+ }
6587+
6588+ if (pax_insert_vma(vma, call_dl_resolve)) {
6589+ up_write(&current->mm->mmap_sem);
6590+ kmem_cache_free(vm_area_cachep, vma);
6591+ return 1;
6592+ }
6593+
6594+ current->mm->call_dl_resolve = call_dl_resolve;
6595+ up_write(&current->mm->mmap_sem);
6596+
6597+emulate:
6598+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6599+ regs->tpc = call_dl_resolve;
6600+ regs->tnpc = addr+4;
6601+ return 3;
6602+ }
6603+#endif
6604+
6605+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6606+ if ((save & 0xFFC00000U) == 0x05000000U &&
6607+ (call & 0xFFFFE000U) == 0x85C0A000U &&
6608+ nop == 0x01000000U)
6609+ {
6610+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6611+ regs->u_regs[UREG_G2] = addr + 4;
6612+ addr = (save & 0x003FFFFFU) << 10;
6613+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6614+
6615+ if (test_thread_flag(TIF_32BIT))
6616+ addr &= 0xFFFFFFFFUL;
6617+
6618+ regs->tpc = addr;
6619+ regs->tnpc = addr+4;
6620+ return 3;
6621+ }
6622+
6623+ /* PaX: 64-bit PLT stub */
6624+ err = get_user(sethi1, (unsigned int *)addr);
6625+ err |= get_user(sethi2, (unsigned int *)(addr+4));
6626+ err |= get_user(or1, (unsigned int *)(addr+8));
6627+ err |= get_user(or2, (unsigned int *)(addr+12));
6628+ err |= get_user(sllx, (unsigned int *)(addr+16));
6629+ err |= get_user(add, (unsigned int *)(addr+20));
6630+ err |= get_user(jmpl, (unsigned int *)(addr+24));
6631+ err |= get_user(nop, (unsigned int *)(addr+28));
6632+ if (err)
6633+ break;
6634+
6635+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
6636+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6637+ (or1 & 0xFFFFE000U) == 0x88112000U &&
6638+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
6639+ sllx == 0x89293020U &&
6640+ add == 0x8A010005U &&
6641+ jmpl == 0x89C14000U &&
6642+ nop == 0x01000000U)
6643+ {
6644+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6645+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6646+ regs->u_regs[UREG_G4] <<= 32;
6647+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6648+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
6649+ regs->u_regs[UREG_G4] = addr + 24;
6650+ addr = regs->u_regs[UREG_G5];
6651+ regs->tpc = addr;
6652+ regs->tnpc = addr+4;
6653+ return 3;
6654+ }
6655+ }
6656+ } while (0);
6657+
6658+#ifdef CONFIG_PAX_DLRESOLVE
6659+ do { /* PaX: unpatched PLT emulation step 2 */
6660+ unsigned int save, call, nop;
6661+
6662+ err = get_user(save, (unsigned int *)(regs->tpc-4));
6663+ err |= get_user(call, (unsigned int *)regs->tpc);
6664+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
6665+ if (err)
6666+ break;
6667+
6668+ if (save == 0x9DE3BFA8U &&
6669+ (call & 0xC0000000U) == 0x40000000U &&
6670+ nop == 0x01000000U)
6671+ {
6672+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6673+
6674+ if (test_thread_flag(TIF_32BIT))
6675+ dl_resolve &= 0xFFFFFFFFUL;
6676+
6677+ regs->u_regs[UREG_RETPC] = regs->tpc;
6678+ regs->tpc = dl_resolve;
6679+ regs->tnpc = dl_resolve+4;
6680+ return 3;
6681+ }
6682+ } while (0);
6683+#endif
6684+
6685+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
6686+ unsigned int sethi, ba, nop;
6687+
6688+ err = get_user(sethi, (unsigned int *)regs->tpc);
6689+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6690+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6691+
6692+ if (err)
6693+ break;
6694+
6695+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6696+ (ba & 0xFFF00000U) == 0x30600000U &&
6697+ nop == 0x01000000U)
6698+ {
6699+ unsigned long addr;
6700+
6701+ addr = (sethi & 0x003FFFFFU) << 10;
6702+ regs->u_regs[UREG_G1] = addr;
6703+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6704+
6705+ if (test_thread_flag(TIF_32BIT))
6706+ addr &= 0xFFFFFFFFUL;
6707+
6708+ regs->tpc = addr;
6709+ regs->tnpc = addr+4;
6710+ return 2;
6711+ }
6712+ } while (0);
6713+
6714+#endif
6715+
6716+ return 1;
6717+}
6718+
6719+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6720+{
6721+ unsigned long i;
6722+
6723+ printk(KERN_ERR "PAX: bytes at PC: ");
6724+ for (i = 0; i < 8; i++) {
6725+ unsigned int c;
6726+ if (get_user(c, (unsigned int *)pc+i))
6727+ printk(KERN_CONT "???????? ");
6728+ else
6729+ printk(KERN_CONT "%08x ", c);
6730+ }
6731+ printk("\n");
6732+}
6733+#endif
6734+
6735 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
6736 {
6737 struct mm_struct *mm = current->mm;
6738@@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
6739 if (!vma)
6740 goto bad_area;
6741
6742+#ifdef CONFIG_PAX_PAGEEXEC
6743+ /* PaX: detect ITLB misses on non-exec pages */
6744+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
6745+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
6746+ {
6747+ if (address != regs->tpc)
6748+ goto good_area;
6749+
6750+ up_read(&mm->mmap_sem);
6751+ switch (pax_handle_fetch_fault(regs)) {
6752+
6753+#ifdef CONFIG_PAX_EMUPLT
6754+ case 2:
6755+ case 3:
6756+ return;
6757+#endif
6758+
6759+ }
6760+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
6761+ do_group_exit(SIGKILL);
6762+ }
6763+#endif
6764+
6765 /* Pure DTLB misses do not tell us whether the fault causing
6766 * load/store/atomic was a write or not, it only says that there
6767 * was no match. So in such a case we (carefully) read the
6768diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
6769index 07e1453..0a7d9e9 100644
6770--- a/arch/sparc/mm/hugetlbpage.c
6771+++ b/arch/sparc/mm/hugetlbpage.c
6772@@ -67,7 +67,7 @@ full_search:
6773 }
6774 return -ENOMEM;
6775 }
6776- if (likely(!vma || addr + len <= vma->vm_start)) {
6777+ if (likely(check_heap_stack_gap(vma, addr, len))) {
6778 /*
6779 * Remember the place where we stopped the search:
6780 */
6781@@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6782 /* make sure it can fit in the remaining address space */
6783 if (likely(addr > len)) {
6784 vma = find_vma(mm, addr-len);
6785- if (!vma || addr <= vma->vm_start) {
6786+ if (check_heap_stack_gap(vma, addr - len, len)) {
6787 /* remember the address as a hint for next time */
6788 return (mm->free_area_cache = addr-len);
6789 }
6790@@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6791 if (unlikely(mm->mmap_base < len))
6792 goto bottomup;
6793
6794- addr = (mm->mmap_base-len) & HPAGE_MASK;
6795+ addr = mm->mmap_base - len;
6796
6797 do {
6798+ addr &= HPAGE_MASK;
6799 /*
6800 * Lookup failure means no vma is above this address,
6801 * else if new region fits below vma->vm_start,
6802 * return with success:
6803 */
6804 vma = find_vma(mm, addr);
6805- if (likely(!vma || addr+len <= vma->vm_start)) {
6806+ if (likely(check_heap_stack_gap(vma, addr, len))) {
6807 /* remember the address as a hint for next time */
6808 return (mm->free_area_cache = addr);
6809 }
6810@@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6811 mm->cached_hole_size = vma->vm_start - addr;
6812
6813 /* try just below the current vma->vm_start */
6814- addr = (vma->vm_start-len) & HPAGE_MASK;
6815- } while (likely(len < vma->vm_start));
6816+ addr = skip_heap_stack_gap(vma, len);
6817+ } while (!IS_ERR_VALUE(addr));
6818
6819 bottomup:
6820 /*
6821@@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
6822 if (addr) {
6823 addr = ALIGN(addr, HPAGE_SIZE);
6824 vma = find_vma(mm, addr);
6825- if (task_size - len >= addr &&
6826- (!vma || addr + len <= vma->vm_start))
6827+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
6828 return addr;
6829 }
6830 if (mm->get_unmapped_area == arch_get_unmapped_area)
6831diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
6832index 7b00de6..78239f4 100644
6833--- a/arch/sparc/mm/init_32.c
6834+++ b/arch/sparc/mm/init_32.c
6835@@ -316,6 +316,9 @@ extern void device_scan(void);
6836 pgprot_t PAGE_SHARED __read_mostly;
6837 EXPORT_SYMBOL(PAGE_SHARED);
6838
6839+pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
6840+EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
6841+
6842 void __init paging_init(void)
6843 {
6844 switch(sparc_cpu_model) {
6845@@ -344,17 +347,17 @@ void __init paging_init(void)
6846
6847 /* Initialize the protection map with non-constant, MMU dependent values. */
6848 protection_map[0] = PAGE_NONE;
6849- protection_map[1] = PAGE_READONLY;
6850- protection_map[2] = PAGE_COPY;
6851- protection_map[3] = PAGE_COPY;
6852+ protection_map[1] = PAGE_READONLY_NOEXEC;
6853+ protection_map[2] = PAGE_COPY_NOEXEC;
6854+ protection_map[3] = PAGE_COPY_NOEXEC;
6855 protection_map[4] = PAGE_READONLY;
6856 protection_map[5] = PAGE_READONLY;
6857 protection_map[6] = PAGE_COPY;
6858 protection_map[7] = PAGE_COPY;
6859 protection_map[8] = PAGE_NONE;
6860- protection_map[9] = PAGE_READONLY;
6861- protection_map[10] = PAGE_SHARED;
6862- protection_map[11] = PAGE_SHARED;
6863+ protection_map[9] = PAGE_READONLY_NOEXEC;
6864+ protection_map[10] = PAGE_SHARED_NOEXEC;
6865+ protection_map[11] = PAGE_SHARED_NOEXEC;
6866 protection_map[12] = PAGE_READONLY;
6867 protection_map[13] = PAGE_READONLY;
6868 protection_map[14] = PAGE_SHARED;
6869diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
6870index cbef74e..c38fead 100644
6871--- a/arch/sparc/mm/srmmu.c
6872+++ b/arch/sparc/mm/srmmu.c
6873@@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
6874 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
6875 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
6876 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
6877+
6878+#ifdef CONFIG_PAX_PAGEEXEC
6879+ PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
6880+ BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
6881+ BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
6882+#endif
6883+
6884 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
6885 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
6886
6887diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
6888index 27fe667..36d474c 100644
6889--- a/arch/tile/include/asm/atomic_64.h
6890+++ b/arch/tile/include/asm/atomic_64.h
6891@@ -142,6 +142,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
6892
6893 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6894
6895+#define atomic64_read_unchecked(v) atomic64_read(v)
6896+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6897+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6898+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6899+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6900+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6901+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6902+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6903+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6904+
6905 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
6906 #define smp_mb__before_atomic_dec() smp_mb()
6907 #define smp_mb__after_atomic_dec() smp_mb()
6908diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
6909index 392e533..536b092 100644
6910--- a/arch/tile/include/asm/cache.h
6911+++ b/arch/tile/include/asm/cache.h
6912@@ -15,11 +15,12 @@
6913 #ifndef _ASM_TILE_CACHE_H
6914 #define _ASM_TILE_CACHE_H
6915
6916+#include <linux/const.h>
6917 #include <arch/chip.h>
6918
6919 /* bytes per L1 data cache line */
6920 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
6921-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6922+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6923
6924 /* bytes per L2 cache line */
6925 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
6926diff --git a/arch/um/Makefile b/arch/um/Makefile
6927index 28688e6..4c0aa1c 100644
6928--- a/arch/um/Makefile
6929+++ b/arch/um/Makefile
6930@@ -61,6 +61,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
6931 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
6932 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
6933
6934+ifdef CONSTIFY_PLUGIN
6935+USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
6936+endif
6937+
6938 #This will adjust *FLAGS accordingly to the platform.
6939 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
6940
6941diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
6942index 19e1bdd..3665b77 100644
6943--- a/arch/um/include/asm/cache.h
6944+++ b/arch/um/include/asm/cache.h
6945@@ -1,6 +1,7 @@
6946 #ifndef __UM_CACHE_H
6947 #define __UM_CACHE_H
6948
6949+#include <linux/const.h>
6950
6951 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
6952 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
6953@@ -12,6 +13,6 @@
6954 # define L1_CACHE_SHIFT 5
6955 #endif
6956
6957-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6958+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6959
6960 #endif
6961diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
6962index 6c03acd..a5e0215 100644
6963--- a/arch/um/include/asm/kmap_types.h
6964+++ b/arch/um/include/asm/kmap_types.h
6965@@ -23,6 +23,7 @@ enum km_type {
6966 KM_IRQ1,
6967 KM_SOFTIRQ0,
6968 KM_SOFTIRQ1,
6969+ KM_CLEARPAGE,
6970 KM_TYPE_NR
6971 };
6972
6973diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
6974index 7cfc3ce..cbd1a58 100644
6975--- a/arch/um/include/asm/page.h
6976+++ b/arch/um/include/asm/page.h
6977@@ -14,6 +14,9 @@
6978 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
6979 #define PAGE_MASK (~(PAGE_SIZE-1))
6980
6981+#define ktla_ktva(addr) (addr)
6982+#define ktva_ktla(addr) (addr)
6983+
6984 #ifndef __ASSEMBLY__
6985
6986 struct page;
6987diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
6988index 69f2490..2634831 100644
6989--- a/arch/um/kernel/process.c
6990+++ b/arch/um/kernel/process.c
6991@@ -408,22 +408,6 @@ int singlestepping(void * t)
6992 return 2;
6993 }
6994
6995-/*
6996- * Only x86 and x86_64 have an arch_align_stack().
6997- * All other arches have "#define arch_align_stack(x) (x)"
6998- * in their asm/system.h
6999- * As this is included in UML from asm-um/system-generic.h,
7000- * we can use it to behave as the subarch does.
7001- */
7002-#ifndef arch_align_stack
7003-unsigned long arch_align_stack(unsigned long sp)
7004-{
7005- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7006- sp -= get_random_int() % 8192;
7007- return sp & ~0xf;
7008-}
7009-#endif
7010-
7011 unsigned long get_wchan(struct task_struct *p)
7012 {
7013 unsigned long stack_page, sp, ip;
7014diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7015index ad8f795..2c7eec6 100644
7016--- a/arch/unicore32/include/asm/cache.h
7017+++ b/arch/unicore32/include/asm/cache.h
7018@@ -12,8 +12,10 @@
7019 #ifndef __UNICORE_CACHE_H__
7020 #define __UNICORE_CACHE_H__
7021
7022-#define L1_CACHE_SHIFT (5)
7023-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7024+#include <linux/const.h>
7025+
7026+#define L1_CACHE_SHIFT 5
7027+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7028
7029 /*
7030 * Memory returned by kmalloc() may be used for DMA, so we must make
7031diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7032index 5bed94e..fbcf200 100644
7033--- a/arch/x86/Kconfig
7034+++ b/arch/x86/Kconfig
7035@@ -226,7 +226,7 @@ config X86_HT
7036
7037 config X86_32_LAZY_GS
7038 def_bool y
7039- depends on X86_32 && !CC_STACKPROTECTOR
7040+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7041
7042 config ARCH_HWEIGHT_CFLAGS
7043 string
7044@@ -1058,7 +1058,7 @@ choice
7045
7046 config NOHIGHMEM
7047 bool "off"
7048- depends on !X86_NUMAQ
7049+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7050 ---help---
7051 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7052 However, the address space of 32-bit x86 processors is only 4
7053@@ -1095,7 +1095,7 @@ config NOHIGHMEM
7054
7055 config HIGHMEM4G
7056 bool "4GB"
7057- depends on !X86_NUMAQ
7058+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7059 ---help---
7060 Select this if you have a 32-bit processor and between 1 and 4
7061 gigabytes of physical RAM.
7062@@ -1149,7 +1149,7 @@ config PAGE_OFFSET
7063 hex
7064 default 0xB0000000 if VMSPLIT_3G_OPT
7065 default 0x80000000 if VMSPLIT_2G
7066- default 0x78000000 if VMSPLIT_2G_OPT
7067+ default 0x70000000 if VMSPLIT_2G_OPT
7068 default 0x40000000 if VMSPLIT_1G
7069 default 0xC0000000
7070 depends on X86_32
7071@@ -1539,6 +1539,7 @@ config SECCOMP
7072
7073 config CC_STACKPROTECTOR
7074 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7075+ depends on X86_64 || !PAX_MEMORY_UDEREF
7076 ---help---
7077 This option turns on the -fstack-protector GCC feature. This
7078 feature puts, at the beginning of functions, a canary value on
7079@@ -1596,6 +1597,7 @@ config KEXEC_JUMP
7080 config PHYSICAL_START
7081 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7082 default "0x1000000"
7083+ range 0x400000 0x40000000
7084 ---help---
7085 This gives the physical address where the kernel is loaded.
7086
7087@@ -1659,6 +1661,7 @@ config X86_NEED_RELOCS
7088 config PHYSICAL_ALIGN
7089 hex "Alignment value to which kernel should be aligned" if X86_32
7090 default "0x1000000"
7091+ range 0x400000 0x1000000 if PAX_KERNEXEC
7092 range 0x2000 0x1000000
7093 ---help---
7094 This value puts the alignment restrictions on physical address
7095@@ -1690,9 +1693,10 @@ config HOTPLUG_CPU
7096 Say N if you want to disable CPU hotplug.
7097
7098 config COMPAT_VDSO
7099- def_bool y
7100+ def_bool n
7101 prompt "Compat VDSO support"
7102 depends on X86_32 || IA32_EMULATION
7103+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7104 ---help---
7105 Map the 32-bit VDSO to the predictable old-style address too.
7106
7107diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7108index 3c57033..22d44aa 100644
7109--- a/arch/x86/Kconfig.cpu
7110+++ b/arch/x86/Kconfig.cpu
7111@@ -335,7 +335,7 @@ config X86_PPRO_FENCE
7112
7113 config X86_F00F_BUG
7114 def_bool y
7115- depends on M586MMX || M586TSC || M586 || M486 || M386
7116+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7117
7118 config X86_INVD_BUG
7119 def_bool y
7120@@ -359,7 +359,7 @@ config X86_POPAD_OK
7121
7122 config X86_ALIGNMENT_16
7123 def_bool y
7124- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7125+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7126
7127 config X86_INTEL_USERCOPY
7128 def_bool y
7129@@ -405,7 +405,7 @@ config X86_CMPXCHG64
7130 # generates cmov.
7131 config X86_CMOV
7132 def_bool y
7133- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7134+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7135
7136 config X86_MINIMUM_CPU_FAMILY
7137 int
7138diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7139index e46c214..7c72b55 100644
7140--- a/arch/x86/Kconfig.debug
7141+++ b/arch/x86/Kconfig.debug
7142@@ -84,7 +84,7 @@ config X86_PTDUMP
7143 config DEBUG_RODATA
7144 bool "Write protect kernel read-only data structures"
7145 default y
7146- depends on DEBUG_KERNEL
7147+ depends on DEBUG_KERNEL && BROKEN
7148 ---help---
7149 Mark the kernel read-only data as write-protected in the pagetables,
7150 in order to catch accidental (and incorrect) writes to such const
7151@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7152
7153 config DEBUG_SET_MODULE_RONX
7154 bool "Set loadable kernel module data as NX and text as RO"
7155- depends on MODULES
7156+ depends on MODULES && BROKEN
7157 ---help---
7158 This option helps catch unintended modifications to loadable
7159 kernel module's text and read-only data. It also prevents execution
7160diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7161index 209ba12..15140db 100644
7162--- a/arch/x86/Makefile
7163+++ b/arch/x86/Makefile
7164@@ -46,6 +46,7 @@ else
7165 UTS_MACHINE := x86_64
7166 CHECKFLAGS += -D__x86_64__ -m64
7167
7168+ biarch := $(call cc-option,-m64)
7169 KBUILD_AFLAGS += -m64
7170 KBUILD_CFLAGS += -m64
7171
7172@@ -201,3 +202,12 @@ define archhelp
7173 echo ' FDARGS="..." arguments for the booted kernel'
7174 echo ' FDINITRD=file initrd for the booted kernel'
7175 endef
7176+
7177+define OLD_LD
7178+
7179+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7180+*** Please upgrade your binutils to 2.18 or newer
7181+endef
7182+
7183+archprepare:
7184+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7185diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7186index 95365a8..52f857b 100644
7187--- a/arch/x86/boot/Makefile
7188+++ b/arch/x86/boot/Makefile
7189@@ -63,6 +63,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7190 $(call cc-option, -fno-stack-protector) \
7191 $(call cc-option, -mpreferred-stack-boundary=2)
7192 KBUILD_CFLAGS += $(call cc-option, -m32)
7193+ifdef CONSTIFY_PLUGIN
7194+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7195+endif
7196 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7197 GCOV_PROFILE := n
7198
7199diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7200index 878e4b9..20537ab 100644
7201--- a/arch/x86/boot/bitops.h
7202+++ b/arch/x86/boot/bitops.h
7203@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7204 u8 v;
7205 const u32 *p = (const u32 *)addr;
7206
7207- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7208+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7209 return v;
7210 }
7211
7212@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7213
7214 static inline void set_bit(int nr, void *addr)
7215 {
7216- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7217+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7218 }
7219
7220 #endif /* BOOT_BITOPS_H */
7221diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7222index c7093bd..d4247ffe0 100644
7223--- a/arch/x86/boot/boot.h
7224+++ b/arch/x86/boot/boot.h
7225@@ -85,7 +85,7 @@ static inline void io_delay(void)
7226 static inline u16 ds(void)
7227 {
7228 u16 seg;
7229- asm("movw %%ds,%0" : "=rm" (seg));
7230+ asm volatile("movw %%ds,%0" : "=rm" (seg));
7231 return seg;
7232 }
7233
7234@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7235 static inline int memcmp(const void *s1, const void *s2, size_t len)
7236 {
7237 u8 diff;
7238- asm("repe; cmpsb; setnz %0"
7239+ asm volatile("repe; cmpsb; setnz %0"
7240 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7241 return diff;
7242 }
7243diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7244index b123b9a..2cf2f23 100644
7245--- a/arch/x86/boot/compressed/Makefile
7246+++ b/arch/x86/boot/compressed/Makefile
7247@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7248 KBUILD_CFLAGS += $(cflags-y)
7249 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7250 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7251+ifdef CONSTIFY_PLUGIN
7252+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7253+endif
7254
7255 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7256 GCOV_PROFILE := n
7257diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7258index a055993..47e126c 100644
7259--- a/arch/x86/boot/compressed/head_32.S
7260+++ b/arch/x86/boot/compressed/head_32.S
7261@@ -98,7 +98,7 @@ preferred_addr:
7262 notl %eax
7263 andl %eax, %ebx
7264 #else
7265- movl $LOAD_PHYSICAL_ADDR, %ebx
7266+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7267 #endif
7268
7269 /* Target address to relocate to for decompression */
7270@@ -184,7 +184,7 @@ relocated:
7271 * and where it was actually loaded.
7272 */
7273 movl %ebp, %ebx
7274- subl $LOAD_PHYSICAL_ADDR, %ebx
7275+ subl $____LOAD_PHYSICAL_ADDR, %ebx
7276 jz 2f /* Nothing to be done if loaded at compiled addr. */
7277 /*
7278 * Process relocations.
7279@@ -192,8 +192,7 @@ relocated:
7280
7281 1: subl $4, %edi
7282 movl (%edi), %ecx
7283- testl %ecx, %ecx
7284- jz 2f
7285+ jecxz 2f
7286 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7287 jmp 1b
7288 2:
7289diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7290index 558d76c..606aa24 100644
7291--- a/arch/x86/boot/compressed/head_64.S
7292+++ b/arch/x86/boot/compressed/head_64.S
7293@@ -91,7 +91,7 @@ ENTRY(startup_32)
7294 notl %eax
7295 andl %eax, %ebx
7296 #else
7297- movl $LOAD_PHYSICAL_ADDR, %ebx
7298+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7299 #endif
7300
7301 /* Target address to relocate to for decompression */
7302@@ -253,7 +253,7 @@ preferred_addr:
7303 notq %rax
7304 andq %rax, %rbp
7305 #else
7306- movq $LOAD_PHYSICAL_ADDR, %rbp
7307+ movq $____LOAD_PHYSICAL_ADDR, %rbp
7308 #endif
7309
7310 /* Target address to relocate to for decompression */
7311diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7312index 7116dcb..d9ae1d7 100644
7313--- a/arch/x86/boot/compressed/misc.c
7314+++ b/arch/x86/boot/compressed/misc.c
7315@@ -310,7 +310,7 @@ static void parse_elf(void *output)
7316 case PT_LOAD:
7317 #ifdef CONFIG_RELOCATABLE
7318 dest = output;
7319- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7320+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7321 #else
7322 dest = (void *)(phdr->p_paddr);
7323 #endif
7324@@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7325 error("Destination address too large");
7326 #endif
7327 #ifndef CONFIG_RELOCATABLE
7328- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7329+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7330 error("Wrong destination address");
7331 #endif
7332
7333diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
7334index 89bbf4e..869908e 100644
7335--- a/arch/x86/boot/compressed/relocs.c
7336+++ b/arch/x86/boot/compressed/relocs.c
7337@@ -13,8 +13,11 @@
7338
7339 static void die(char *fmt, ...);
7340
7341+#include "../../../../include/generated/autoconf.h"
7342+
7343 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
7344 static Elf32_Ehdr ehdr;
7345+static Elf32_Phdr *phdr;
7346 static unsigned long reloc_count, reloc_idx;
7347 static unsigned long *relocs;
7348
7349@@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
7350 }
7351 }
7352
7353+static void read_phdrs(FILE *fp)
7354+{
7355+ unsigned int i;
7356+
7357+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
7358+ if (!phdr) {
7359+ die("Unable to allocate %d program headers\n",
7360+ ehdr.e_phnum);
7361+ }
7362+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
7363+ die("Seek to %d failed: %s\n",
7364+ ehdr.e_phoff, strerror(errno));
7365+ }
7366+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
7367+ die("Cannot read ELF program headers: %s\n",
7368+ strerror(errno));
7369+ }
7370+ for(i = 0; i < ehdr.e_phnum; i++) {
7371+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
7372+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
7373+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
7374+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
7375+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
7376+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
7377+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
7378+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
7379+ }
7380+
7381+}
7382+
7383 static void read_shdrs(FILE *fp)
7384 {
7385- int i;
7386+ unsigned int i;
7387 Elf32_Shdr shdr;
7388
7389 secs = calloc(ehdr.e_shnum, sizeof(struct section));
7390@@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
7391
7392 static void read_strtabs(FILE *fp)
7393 {
7394- int i;
7395+ unsigned int i;
7396 for (i = 0; i < ehdr.e_shnum; i++) {
7397 struct section *sec = &secs[i];
7398 if (sec->shdr.sh_type != SHT_STRTAB) {
7399@@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
7400
7401 static void read_symtabs(FILE *fp)
7402 {
7403- int i,j;
7404+ unsigned int i,j;
7405 for (i = 0; i < ehdr.e_shnum; i++) {
7406 struct section *sec = &secs[i];
7407 if (sec->shdr.sh_type != SHT_SYMTAB) {
7408@@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
7409
7410 static void read_relocs(FILE *fp)
7411 {
7412- int i,j;
7413+ unsigned int i,j;
7414+ uint32_t base;
7415+
7416 for (i = 0; i < ehdr.e_shnum; i++) {
7417 struct section *sec = &secs[i];
7418 if (sec->shdr.sh_type != SHT_REL) {
7419@@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
7420 die("Cannot read symbol table: %s\n",
7421 strerror(errno));
7422 }
7423+ base = 0;
7424+ for (j = 0; j < ehdr.e_phnum; j++) {
7425+ if (phdr[j].p_type != PT_LOAD )
7426+ continue;
7427+ 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)
7428+ continue;
7429+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
7430+ break;
7431+ }
7432 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
7433 Elf32_Rel *rel = &sec->reltab[j];
7434- rel->r_offset = elf32_to_cpu(rel->r_offset);
7435+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
7436 rel->r_info = elf32_to_cpu(rel->r_info);
7437 }
7438 }
7439@@ -396,14 +440,14 @@ static void read_relocs(FILE *fp)
7440
7441 static void print_absolute_symbols(void)
7442 {
7443- int i;
7444+ unsigned int i;
7445 printf("Absolute symbols\n");
7446 printf(" Num: Value Size Type Bind Visibility Name\n");
7447 for (i = 0; i < ehdr.e_shnum; i++) {
7448 struct section *sec = &secs[i];
7449 char *sym_strtab;
7450 Elf32_Sym *sh_symtab;
7451- int j;
7452+ unsigned int j;
7453
7454 if (sec->shdr.sh_type != SHT_SYMTAB) {
7455 continue;
7456@@ -431,14 +475,14 @@ static void print_absolute_symbols(void)
7457
7458 static void print_absolute_relocs(void)
7459 {
7460- int i, printed = 0;
7461+ unsigned int i, printed = 0;
7462
7463 for (i = 0; i < ehdr.e_shnum; i++) {
7464 struct section *sec = &secs[i];
7465 struct section *sec_applies, *sec_symtab;
7466 char *sym_strtab;
7467 Elf32_Sym *sh_symtab;
7468- int j;
7469+ unsigned int j;
7470 if (sec->shdr.sh_type != SHT_REL) {
7471 continue;
7472 }
7473@@ -499,13 +543,13 @@ static void print_absolute_relocs(void)
7474
7475 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7476 {
7477- int i;
7478+ unsigned int i;
7479 /* Walk through the relocations */
7480 for (i = 0; i < ehdr.e_shnum; i++) {
7481 char *sym_strtab;
7482 Elf32_Sym *sh_symtab;
7483 struct section *sec_applies, *sec_symtab;
7484- int j;
7485+ unsigned int j;
7486 struct section *sec = &secs[i];
7487
7488 if (sec->shdr.sh_type != SHT_REL) {
7489@@ -530,6 +574,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7490 !is_rel_reloc(sym_name(sym_strtab, sym))) {
7491 continue;
7492 }
7493+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
7494+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
7495+ continue;
7496+
7497+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
7498+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
7499+ if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
7500+ continue;
7501+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
7502+ continue;
7503+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
7504+ continue;
7505+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
7506+ continue;
7507+#endif
7508+
7509 switch (r_type) {
7510 case R_386_NONE:
7511 case R_386_PC32:
7512@@ -571,7 +631,7 @@ static int cmp_relocs(const void *va, const void *vb)
7513
7514 static void emit_relocs(int as_text)
7515 {
7516- int i;
7517+ unsigned int i;
7518 /* Count how many relocations I have and allocate space for them. */
7519 reloc_count = 0;
7520 walk_relocs(count_reloc);
7521@@ -665,6 +725,7 @@ int main(int argc, char **argv)
7522 fname, strerror(errno));
7523 }
7524 read_ehdr(fp);
7525+ read_phdrs(fp);
7526 read_shdrs(fp);
7527 read_strtabs(fp);
7528 read_symtabs(fp);
7529diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7530index 4d3ff03..e4972ff 100644
7531--- a/arch/x86/boot/cpucheck.c
7532+++ b/arch/x86/boot/cpucheck.c
7533@@ -74,7 +74,7 @@ static int has_fpu(void)
7534 u16 fcw = -1, fsw = -1;
7535 u32 cr0;
7536
7537- asm("movl %%cr0,%0" : "=r" (cr0));
7538+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
7539 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7540 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7541 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7542@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7543 {
7544 u32 f0, f1;
7545
7546- asm("pushfl ; "
7547+ asm volatile("pushfl ; "
7548 "pushfl ; "
7549 "popl %0 ; "
7550 "movl %0,%1 ; "
7551@@ -115,7 +115,7 @@ static void get_flags(void)
7552 set_bit(X86_FEATURE_FPU, cpu.flags);
7553
7554 if (has_eflag(X86_EFLAGS_ID)) {
7555- asm("cpuid"
7556+ asm volatile("cpuid"
7557 : "=a" (max_intel_level),
7558 "=b" (cpu_vendor[0]),
7559 "=d" (cpu_vendor[1]),
7560@@ -124,7 +124,7 @@ static void get_flags(void)
7561
7562 if (max_intel_level >= 0x00000001 &&
7563 max_intel_level <= 0x0000ffff) {
7564- asm("cpuid"
7565+ asm volatile("cpuid"
7566 : "=a" (tfms),
7567 "=c" (cpu.flags[4]),
7568 "=d" (cpu.flags[0])
7569@@ -136,7 +136,7 @@ static void get_flags(void)
7570 cpu.model += ((tfms >> 16) & 0xf) << 4;
7571 }
7572
7573- asm("cpuid"
7574+ asm volatile("cpuid"
7575 : "=a" (max_amd_level)
7576 : "a" (0x80000000)
7577 : "ebx", "ecx", "edx");
7578@@ -144,7 +144,7 @@ static void get_flags(void)
7579 if (max_amd_level >= 0x80000001 &&
7580 max_amd_level <= 0x8000ffff) {
7581 u32 eax = 0x80000001;
7582- asm("cpuid"
7583+ asm volatile("cpuid"
7584 : "+a" (eax),
7585 "=c" (cpu.flags[6]),
7586 "=d" (cpu.flags[1])
7587@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7588 u32 ecx = MSR_K7_HWCR;
7589 u32 eax, edx;
7590
7591- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7592+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7593 eax &= ~(1 << 15);
7594- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7595+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7596
7597 get_flags(); /* Make sure it really did something */
7598 err = check_flags();
7599@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7600 u32 ecx = MSR_VIA_FCR;
7601 u32 eax, edx;
7602
7603- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7604+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7605 eax |= (1<<1)|(1<<7);
7606- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7607+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7608
7609 set_bit(X86_FEATURE_CX8, cpu.flags);
7610 err = check_flags();
7611@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7612 u32 eax, edx;
7613 u32 level = 1;
7614
7615- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7616- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7617- asm("cpuid"
7618+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7619+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7620+ asm volatile("cpuid"
7621 : "+a" (level), "=d" (cpu.flags[0])
7622 : : "ecx", "ebx");
7623- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7624+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7625
7626 err = check_flags();
7627 }
7628diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7629index f1bbeeb..aff09cb 100644
7630--- a/arch/x86/boot/header.S
7631+++ b/arch/x86/boot/header.S
7632@@ -372,7 +372,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
7633 # single linked list of
7634 # struct setup_data
7635
7636-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7637+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7638
7639 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7640 #define VO_INIT_SIZE (VO__end - VO__text)
7641diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7642index db75d07..8e6d0af 100644
7643--- a/arch/x86/boot/memory.c
7644+++ b/arch/x86/boot/memory.c
7645@@ -19,7 +19,7 @@
7646
7647 static int detect_memory_e820(void)
7648 {
7649- int count = 0;
7650+ unsigned int count = 0;
7651 struct biosregs ireg, oreg;
7652 struct e820entry *desc = boot_params.e820_map;
7653 static struct e820entry buf; /* static so it is zeroed */
7654diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
7655index 11e8c6e..fdbb1ed 100644
7656--- a/arch/x86/boot/video-vesa.c
7657+++ b/arch/x86/boot/video-vesa.c
7658@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7659
7660 boot_params.screen_info.vesapm_seg = oreg.es;
7661 boot_params.screen_info.vesapm_off = oreg.di;
7662+ boot_params.screen_info.vesapm_size = oreg.cx;
7663 }
7664
7665 /*
7666diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
7667index 43eda28..5ab5fdb 100644
7668--- a/arch/x86/boot/video.c
7669+++ b/arch/x86/boot/video.c
7670@@ -96,7 +96,7 @@ static void store_mode_params(void)
7671 static unsigned int get_entry(void)
7672 {
7673 char entry_buf[4];
7674- int i, len = 0;
7675+ unsigned int i, len = 0;
7676 int key;
7677 unsigned int v;
7678
7679diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
7680index 5b577d5..3c1fed4 100644
7681--- a/arch/x86/crypto/aes-x86_64-asm_64.S
7682+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
7683@@ -8,6 +8,8 @@
7684 * including this sentence is retained in full.
7685 */
7686
7687+#include <asm/alternative-asm.h>
7688+
7689 .extern crypto_ft_tab
7690 .extern crypto_it_tab
7691 .extern crypto_fl_tab
7692@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
7693 je B192; \
7694 leaq 32(r9),r9;
7695
7696+#define ret pax_force_retaddr 0, 1; ret
7697+
7698 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
7699 movq r1,r2; \
7700 movq r3,r4; \
7701diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
7702index be6d9e3..21fbbca 100644
7703--- a/arch/x86/crypto/aesni-intel_asm.S
7704+++ b/arch/x86/crypto/aesni-intel_asm.S
7705@@ -31,6 +31,7 @@
7706
7707 #include <linux/linkage.h>
7708 #include <asm/inst.h>
7709+#include <asm/alternative-asm.h>
7710
7711 #ifdef __x86_64__
7712 .data
7713@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
7714 pop %r14
7715 pop %r13
7716 pop %r12
7717+ pax_force_retaddr 0, 1
7718 ret
7719+ENDPROC(aesni_gcm_dec)
7720
7721
7722 /*****************************************************************************
7723@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
7724 pop %r14
7725 pop %r13
7726 pop %r12
7727+ pax_force_retaddr 0, 1
7728 ret
7729+ENDPROC(aesni_gcm_enc)
7730
7731 #endif
7732
7733@@ -1714,6 +1719,7 @@ _key_expansion_256a:
7734 pxor %xmm1, %xmm0
7735 movaps %xmm0, (TKEYP)
7736 add $0x10, TKEYP
7737+ pax_force_retaddr_bts
7738 ret
7739
7740 .align 4
7741@@ -1738,6 +1744,7 @@ _key_expansion_192a:
7742 shufps $0b01001110, %xmm2, %xmm1
7743 movaps %xmm1, 0x10(TKEYP)
7744 add $0x20, TKEYP
7745+ pax_force_retaddr_bts
7746 ret
7747
7748 .align 4
7749@@ -1757,6 +1764,7 @@ _key_expansion_192b:
7750
7751 movaps %xmm0, (TKEYP)
7752 add $0x10, TKEYP
7753+ pax_force_retaddr_bts
7754 ret
7755
7756 .align 4
7757@@ -1769,6 +1777,7 @@ _key_expansion_256b:
7758 pxor %xmm1, %xmm2
7759 movaps %xmm2, (TKEYP)
7760 add $0x10, TKEYP
7761+ pax_force_retaddr_bts
7762 ret
7763
7764 /*
7765@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
7766 #ifndef __x86_64__
7767 popl KEYP
7768 #endif
7769+ pax_force_retaddr 0, 1
7770 ret
7771+ENDPROC(aesni_set_key)
7772
7773 /*
7774 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
7775@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
7776 popl KLEN
7777 popl KEYP
7778 #endif
7779+ pax_force_retaddr 0, 1
7780 ret
7781+ENDPROC(aesni_enc)
7782
7783 /*
7784 * _aesni_enc1: internal ABI
7785@@ -1959,6 +1972,7 @@ _aesni_enc1:
7786 AESENC KEY STATE
7787 movaps 0x70(TKEYP), KEY
7788 AESENCLAST KEY STATE
7789+ pax_force_retaddr_bts
7790 ret
7791
7792 /*
7793@@ -2067,6 +2081,7 @@ _aesni_enc4:
7794 AESENCLAST KEY STATE2
7795 AESENCLAST KEY STATE3
7796 AESENCLAST KEY STATE4
7797+ pax_force_retaddr_bts
7798 ret
7799
7800 /*
7801@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
7802 popl KLEN
7803 popl KEYP
7804 #endif
7805+ pax_force_retaddr 0, 1
7806 ret
7807+ENDPROC(aesni_dec)
7808
7809 /*
7810 * _aesni_dec1: internal ABI
7811@@ -2146,6 +2163,7 @@ _aesni_dec1:
7812 AESDEC KEY STATE
7813 movaps 0x70(TKEYP), KEY
7814 AESDECLAST KEY STATE
7815+ pax_force_retaddr_bts
7816 ret
7817
7818 /*
7819@@ -2254,6 +2272,7 @@ _aesni_dec4:
7820 AESDECLAST KEY STATE2
7821 AESDECLAST KEY STATE3
7822 AESDECLAST KEY STATE4
7823+ pax_force_retaddr_bts
7824 ret
7825
7826 /*
7827@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
7828 popl KEYP
7829 popl LEN
7830 #endif
7831+ pax_force_retaddr 0, 1
7832 ret
7833+ENDPROC(aesni_ecb_enc)
7834
7835 /*
7836 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7837@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
7838 popl KEYP
7839 popl LEN
7840 #endif
7841+ pax_force_retaddr 0, 1
7842 ret
7843+ENDPROC(aesni_ecb_dec)
7844
7845 /*
7846 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7847@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
7848 popl LEN
7849 popl IVP
7850 #endif
7851+ pax_force_retaddr 0, 1
7852 ret
7853+ENDPROC(aesni_cbc_enc)
7854
7855 /*
7856 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7857@@ -2498,7 +2523,9 @@ ENTRY(aesni_cbc_dec)
7858 popl LEN
7859 popl IVP
7860 #endif
7861+ pax_force_retaddr 0, 1
7862 ret
7863+ENDPROC(aesni_cbc_dec)
7864
7865 #ifdef __x86_64__
7866 .align 16
7867@@ -2524,6 +2551,7 @@ _aesni_inc_init:
7868 mov $1, TCTR_LOW
7869 MOVQ_R64_XMM TCTR_LOW INC
7870 MOVQ_R64_XMM CTR TCTR_LOW
7871+ pax_force_retaddr_bts
7872 ret
7873
7874 /*
7875@@ -2552,6 +2580,7 @@ _aesni_inc:
7876 .Linc_low:
7877 movaps CTR, IV
7878 PSHUFB_XMM BSWAP_MASK IV
7879+ pax_force_retaddr_bts
7880 ret
7881
7882 /*
7883@@ -2612,5 +2641,7 @@ ENTRY(aesni_ctr_enc)
7884 .Lctr_enc_ret:
7885 movups IV, (IVP)
7886 .Lctr_enc_just_ret:
7887+ pax_force_retaddr 0, 1
7888 ret
7889+ENDPROC(aesni_ctr_enc)
7890 #endif
7891diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
7892index 391d245..67f35c2 100644
7893--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
7894+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
7895@@ -20,6 +20,8 @@
7896 *
7897 */
7898
7899+#include <asm/alternative-asm.h>
7900+
7901 .file "blowfish-x86_64-asm.S"
7902 .text
7903
7904@@ -151,9 +153,11 @@ __blowfish_enc_blk:
7905 jnz __enc_xor;
7906
7907 write_block();
7908+ pax_force_retaddr 0, 1
7909 ret;
7910 __enc_xor:
7911 xor_block();
7912+ pax_force_retaddr 0, 1
7913 ret;
7914
7915 .align 8
7916@@ -188,6 +192,7 @@ blowfish_dec_blk:
7917
7918 movq %r11, %rbp;
7919
7920+ pax_force_retaddr 0, 1
7921 ret;
7922
7923 /**********************************************************************
7924@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
7925
7926 popq %rbx;
7927 popq %rbp;
7928+ pax_force_retaddr 0, 1
7929 ret;
7930
7931 __enc_xor4:
7932@@ -349,6 +355,7 @@ __enc_xor4:
7933
7934 popq %rbx;
7935 popq %rbp;
7936+ pax_force_retaddr 0, 1
7937 ret;
7938
7939 .align 8
7940@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
7941 popq %rbx;
7942 popq %rbp;
7943
7944+ pax_force_retaddr 0, 1
7945 ret;
7946
7947diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
7948index 6214a9b..1f4fc9a 100644
7949--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
7950+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
7951@@ -1,3 +1,5 @@
7952+#include <asm/alternative-asm.h>
7953+
7954 # enter ECRYPT_encrypt_bytes
7955 .text
7956 .p2align 5
7957@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
7958 add %r11,%rsp
7959 mov %rdi,%rax
7960 mov %rsi,%rdx
7961+ pax_force_retaddr 0, 1
7962 ret
7963 # bytesatleast65:
7964 ._bytesatleast65:
7965@@ -891,6 +894,7 @@ ECRYPT_keysetup:
7966 add %r11,%rsp
7967 mov %rdi,%rax
7968 mov %rsi,%rdx
7969+ pax_force_retaddr
7970 ret
7971 # enter ECRYPT_ivsetup
7972 .text
7973@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
7974 add %r11,%rsp
7975 mov %rdi,%rax
7976 mov %rsi,%rdx
7977+ pax_force_retaddr
7978 ret
7979diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
7980index 7f24a15..9cd3ffe 100644
7981--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
7982+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
7983@@ -24,6 +24,8 @@
7984 *
7985 */
7986
7987+#include <asm/alternative-asm.h>
7988+
7989 .file "serpent-sse2-x86_64-asm_64.S"
7990 .text
7991
7992@@ -695,12 +697,14 @@ __serpent_enc_blk_8way:
7993 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
7994 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
7995
7996+ pax_force_retaddr
7997 ret;
7998
7999 __enc_xor8:
8000 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8001 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8002
8003+ pax_force_retaddr
8004 ret;
8005
8006 .align 8
8007@@ -758,4 +762,5 @@ serpent_dec_blk_8way:
8008 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8009 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8010
8011+ pax_force_retaddr
8012 ret;
8013diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8014index b2c2f57..8470cab 100644
8015--- a/arch/x86/crypto/sha1_ssse3_asm.S
8016+++ b/arch/x86/crypto/sha1_ssse3_asm.S
8017@@ -28,6 +28,8 @@
8018 * (at your option) any later version.
8019 */
8020
8021+#include <asm/alternative-asm.h>
8022+
8023 #define CTX %rdi // arg1
8024 #define BUF %rsi // arg2
8025 #define CNT %rdx // arg3
8026@@ -104,6 +106,7 @@
8027 pop %r12
8028 pop %rbp
8029 pop %rbx
8030+ pax_force_retaddr 0, 1
8031 ret
8032
8033 .size \name, .-\name
8034diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8035index 5b012a2..36d5364 100644
8036--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8037+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8038@@ -20,6 +20,8 @@
8039 *
8040 */
8041
8042+#include <asm/alternative-asm.h>
8043+
8044 .file "twofish-x86_64-asm-3way.S"
8045 .text
8046
8047@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8048 popq %r13;
8049 popq %r14;
8050 popq %r15;
8051+ pax_force_retaddr 0, 1
8052 ret;
8053
8054 __enc_xor3:
8055@@ -271,6 +274,7 @@ __enc_xor3:
8056 popq %r13;
8057 popq %r14;
8058 popq %r15;
8059+ pax_force_retaddr 0, 1
8060 ret;
8061
8062 .global twofish_dec_blk_3way
8063@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8064 popq %r13;
8065 popq %r14;
8066 popq %r15;
8067+ pax_force_retaddr 0, 1
8068 ret;
8069
8070diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8071index 7bcf3fc..f53832f 100644
8072--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8073+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8074@@ -21,6 +21,7 @@
8075 .text
8076
8077 #include <asm/asm-offsets.h>
8078+#include <asm/alternative-asm.h>
8079
8080 #define a_offset 0
8081 #define b_offset 4
8082@@ -268,6 +269,7 @@ twofish_enc_blk:
8083
8084 popq R1
8085 movq $1,%rax
8086+ pax_force_retaddr 0, 1
8087 ret
8088
8089 twofish_dec_blk:
8090@@ -319,4 +321,5 @@ twofish_dec_blk:
8091
8092 popq R1
8093 movq $1,%rax
8094+ pax_force_retaddr 0, 1
8095 ret
8096diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8097index 39e4909..887aa7e 100644
8098--- a/arch/x86/ia32/ia32_aout.c
8099+++ b/arch/x86/ia32/ia32_aout.c
8100@@ -162,6 +162,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8101 unsigned long dump_start, dump_size;
8102 struct user32 dump;
8103
8104+ memset(&dump, 0, sizeof(dump));
8105+
8106 fs = get_fs();
8107 set_fs(KERNEL_DS);
8108 has_dumped = 1;
8109diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8110index 6557769..ef6ae89 100644
8111--- a/arch/x86/ia32/ia32_signal.c
8112+++ b/arch/x86/ia32/ia32_signal.c
8113@@ -169,7 +169,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8114 }
8115 seg = get_fs();
8116 set_fs(KERNEL_DS);
8117- ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8118+ ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8119 set_fs(seg);
8120 if (ret >= 0 && uoss_ptr) {
8121 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8122@@ -370,7 +370,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8123 */
8124 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8125 size_t frame_size,
8126- void **fpstate)
8127+ void __user **fpstate)
8128 {
8129 unsigned long sp;
8130
8131@@ -391,7 +391,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8132
8133 if (used_math()) {
8134 sp = sp - sig_xstate_ia32_size;
8135- *fpstate = (struct _fpstate_ia32 *) sp;
8136+ *fpstate = (struct _fpstate_ia32 __user *) sp;
8137 if (save_i387_xstate_ia32(*fpstate) < 0)
8138 return (void __user *) -1L;
8139 }
8140@@ -399,7 +399,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8141 sp -= frame_size;
8142 /* Align the stack pointer according to the i386 ABI,
8143 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8144- sp = ((sp + 4) & -16ul) - 4;
8145+ sp = ((sp - 12) & -16ul) - 4;
8146 return (void __user *) sp;
8147 }
8148
8149@@ -457,7 +457,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8150 * These are actually not used anymore, but left because some
8151 * gdb versions depend on them as a marker.
8152 */
8153- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8154+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8155 } put_user_catch(err);
8156
8157 if (err)
8158@@ -499,7 +499,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8159 0xb8,
8160 __NR_ia32_rt_sigreturn,
8161 0x80cd,
8162- 0,
8163+ 0
8164 };
8165
8166 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8167@@ -529,16 +529,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8168
8169 if (ka->sa.sa_flags & SA_RESTORER)
8170 restorer = ka->sa.sa_restorer;
8171+ else if (current->mm->context.vdso)
8172+ /* Return stub is in 32bit vsyscall page */
8173+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8174 else
8175- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8176- rt_sigreturn);
8177+ restorer = &frame->retcode;
8178 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8179
8180 /*
8181 * Not actually used anymore, but left because some gdb
8182 * versions need it.
8183 */
8184- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8185+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8186 } put_user_catch(err);
8187
8188 if (err)
8189diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8190index e3e7340..05ed805 100644
8191--- a/arch/x86/ia32/ia32entry.S
8192+++ b/arch/x86/ia32/ia32entry.S
8193@@ -13,8 +13,10 @@
8194 #include <asm/thread_info.h>
8195 #include <asm/segment.h>
8196 #include <asm/irqflags.h>
8197+#include <asm/pgtable.h>
8198 #include <linux/linkage.h>
8199 #include <linux/err.h>
8200+#include <asm/alternative-asm.h>
8201
8202 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8203 #include <linux/elf-em.h>
8204@@ -94,6 +96,32 @@ ENTRY(native_irq_enable_sysexit)
8205 ENDPROC(native_irq_enable_sysexit)
8206 #endif
8207
8208+ .macro pax_enter_kernel_user
8209+ pax_set_fptr_mask
8210+#ifdef CONFIG_PAX_MEMORY_UDEREF
8211+ call pax_enter_kernel_user
8212+#endif
8213+ .endm
8214+
8215+ .macro pax_exit_kernel_user
8216+#ifdef CONFIG_PAX_MEMORY_UDEREF
8217+ call pax_exit_kernel_user
8218+#endif
8219+#ifdef CONFIG_PAX_RANDKSTACK
8220+ pushq %rax
8221+ pushq %r11
8222+ call pax_randomize_kstack
8223+ popq %r11
8224+ popq %rax
8225+#endif
8226+ .endm
8227+
8228+.macro pax_erase_kstack
8229+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8230+ call pax_erase_kstack
8231+#endif
8232+.endm
8233+
8234 /*
8235 * 32bit SYSENTER instruction entry.
8236 *
8237@@ -120,12 +148,6 @@ ENTRY(ia32_sysenter_target)
8238 CFI_REGISTER rsp,rbp
8239 SWAPGS_UNSAFE_STACK
8240 movq PER_CPU_VAR(kernel_stack), %rsp
8241- addq $(KERNEL_STACK_OFFSET),%rsp
8242- /*
8243- * No need to follow this irqs on/off section: the syscall
8244- * disabled irqs, here we enable it straight after entry:
8245- */
8246- ENABLE_INTERRUPTS(CLBR_NONE)
8247 movl %ebp,%ebp /* zero extension */
8248 pushq_cfi $__USER32_DS
8249 /*CFI_REL_OFFSET ss,0*/
8250@@ -133,24 +155,39 @@ ENTRY(ia32_sysenter_target)
8251 CFI_REL_OFFSET rsp,0
8252 pushfq_cfi
8253 /*CFI_REL_OFFSET rflags,0*/
8254- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8255- CFI_REGISTER rip,r10
8256+ orl $X86_EFLAGS_IF,(%rsp)
8257+ GET_THREAD_INFO(%r11)
8258+ movl TI_sysenter_return(%r11), %r11d
8259+ CFI_REGISTER rip,r11
8260 pushq_cfi $__USER32_CS
8261 /*CFI_REL_OFFSET cs,0*/
8262 movl %eax, %eax
8263- pushq_cfi %r10
8264+ pushq_cfi %r11
8265 CFI_REL_OFFSET rip,0
8266 pushq_cfi %rax
8267 cld
8268 SAVE_ARGS 0,1,0
8269+ pax_enter_kernel_user
8270+ /*
8271+ * No need to follow this irqs on/off section: the syscall
8272+ * disabled irqs, here we enable it straight after entry:
8273+ */
8274+ ENABLE_INTERRUPTS(CLBR_NONE)
8275 /* no need to do an access_ok check here because rbp has been
8276 32bit zero extended */
8277+
8278+#ifdef CONFIG_PAX_MEMORY_UDEREF
8279+ mov $PAX_USER_SHADOW_BASE,%r11
8280+ add %r11,%rbp
8281+#endif
8282+
8283 1: movl (%rbp),%ebp
8284 .section __ex_table,"a"
8285 .quad 1b,ia32_badarg
8286 .previous
8287- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8288- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8289+ GET_THREAD_INFO(%r11)
8290+ orl $TS_COMPAT,TI_status(%r11)
8291+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8292 CFI_REMEMBER_STATE
8293 jnz sysenter_tracesys
8294 cmpq $(IA32_NR_syscalls-1),%rax
8295@@ -160,12 +197,15 @@ sysenter_do_call:
8296 sysenter_dispatch:
8297 call *ia32_sys_call_table(,%rax,8)
8298 movq %rax,RAX-ARGOFFSET(%rsp)
8299+ GET_THREAD_INFO(%r11)
8300 DISABLE_INTERRUPTS(CLBR_NONE)
8301 TRACE_IRQS_OFF
8302- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8303+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8304 jnz sysexit_audit
8305 sysexit_from_sys_call:
8306- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8307+ pax_exit_kernel_user
8308+ pax_erase_kstack
8309+ andl $~TS_COMPAT,TI_status(%r11)
8310 /* clear IF, that popfq doesn't enable interrupts early */
8311 andl $~0x200,EFLAGS-R11(%rsp)
8312 movl RIP-R11(%rsp),%edx /* User %eip */
8313@@ -191,6 +231,9 @@ sysexit_from_sys_call:
8314 movl %eax,%esi /* 2nd arg: syscall number */
8315 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8316 call __audit_syscall_entry
8317+
8318+ pax_erase_kstack
8319+
8320 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8321 cmpq $(IA32_NR_syscalls-1),%rax
8322 ja ia32_badsys
8323@@ -202,7 +245,7 @@ sysexit_from_sys_call:
8324 .endm
8325
8326 .macro auditsys_exit exit
8327- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8328+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8329 jnz ia32_ret_from_sys_call
8330 TRACE_IRQS_ON
8331 sti
8332@@ -213,11 +256,12 @@ sysexit_from_sys_call:
8333 1: setbe %al /* 1 if error, 0 if not */
8334 movzbl %al,%edi /* zero-extend that into %edi */
8335 call __audit_syscall_exit
8336+ GET_THREAD_INFO(%r11)
8337 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8338 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8339 cli
8340 TRACE_IRQS_OFF
8341- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8342+ testl %edi,TI_flags(%r11)
8343 jz \exit
8344 CLEAR_RREGS -ARGOFFSET
8345 jmp int_with_check
8346@@ -235,7 +279,7 @@ sysexit_audit:
8347
8348 sysenter_tracesys:
8349 #ifdef CONFIG_AUDITSYSCALL
8350- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8351+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8352 jz sysenter_auditsys
8353 #endif
8354 SAVE_REST
8355@@ -243,6 +287,9 @@ sysenter_tracesys:
8356 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8357 movq %rsp,%rdi /* &pt_regs -> arg1 */
8358 call syscall_trace_enter
8359+
8360+ pax_erase_kstack
8361+
8362 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8363 RESTORE_REST
8364 cmpq $(IA32_NR_syscalls-1),%rax
8365@@ -274,19 +321,20 @@ ENDPROC(ia32_sysenter_target)
8366 ENTRY(ia32_cstar_target)
8367 CFI_STARTPROC32 simple
8368 CFI_SIGNAL_FRAME
8369- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8370+ CFI_DEF_CFA rsp,0
8371 CFI_REGISTER rip,rcx
8372 /*CFI_REGISTER rflags,r11*/
8373 SWAPGS_UNSAFE_STACK
8374 movl %esp,%r8d
8375 CFI_REGISTER rsp,r8
8376 movq PER_CPU_VAR(kernel_stack),%rsp
8377+ SAVE_ARGS 8*6,0,0
8378+ pax_enter_kernel_user
8379 /*
8380 * No need to follow this irqs on/off section: the syscall
8381 * disabled irqs and here we enable it straight after entry:
8382 */
8383 ENABLE_INTERRUPTS(CLBR_NONE)
8384- SAVE_ARGS 8,0,0
8385 movl %eax,%eax /* zero extension */
8386 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8387 movq %rcx,RIP-ARGOFFSET(%rsp)
8388@@ -302,12 +350,19 @@ ENTRY(ia32_cstar_target)
8389 /* no need to do an access_ok check here because r8 has been
8390 32bit zero extended */
8391 /* hardware stack frame is complete now */
8392+
8393+#ifdef CONFIG_PAX_MEMORY_UDEREF
8394+ mov $PAX_USER_SHADOW_BASE,%r11
8395+ add %r11,%r8
8396+#endif
8397+
8398 1: movl (%r8),%r9d
8399 .section __ex_table,"a"
8400 .quad 1b,ia32_badarg
8401 .previous
8402- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8403- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8404+ GET_THREAD_INFO(%r11)
8405+ orl $TS_COMPAT,TI_status(%r11)
8406+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8407 CFI_REMEMBER_STATE
8408 jnz cstar_tracesys
8409 cmpq $IA32_NR_syscalls-1,%rax
8410@@ -317,12 +372,15 @@ cstar_do_call:
8411 cstar_dispatch:
8412 call *ia32_sys_call_table(,%rax,8)
8413 movq %rax,RAX-ARGOFFSET(%rsp)
8414+ GET_THREAD_INFO(%r11)
8415 DISABLE_INTERRUPTS(CLBR_NONE)
8416 TRACE_IRQS_OFF
8417- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8418+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8419 jnz sysretl_audit
8420 sysretl_from_sys_call:
8421- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8422+ pax_exit_kernel_user
8423+ pax_erase_kstack
8424+ andl $~TS_COMPAT,TI_status(%r11)
8425 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8426 movl RIP-ARGOFFSET(%rsp),%ecx
8427 CFI_REGISTER rip,rcx
8428@@ -350,7 +408,7 @@ sysretl_audit:
8429
8430 cstar_tracesys:
8431 #ifdef CONFIG_AUDITSYSCALL
8432- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8433+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8434 jz cstar_auditsys
8435 #endif
8436 xchgl %r9d,%ebp
8437@@ -359,6 +417,9 @@ cstar_tracesys:
8438 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8439 movq %rsp,%rdi /* &pt_regs -> arg1 */
8440 call syscall_trace_enter
8441+
8442+ pax_erase_kstack
8443+
8444 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8445 RESTORE_REST
8446 xchgl %ebp,%r9d
8447@@ -404,19 +465,21 @@ ENTRY(ia32_syscall)
8448 CFI_REL_OFFSET rip,RIP-RIP
8449 PARAVIRT_ADJUST_EXCEPTION_FRAME
8450 SWAPGS
8451- /*
8452- * No need to follow this irqs on/off section: the syscall
8453- * disabled irqs and here we enable it straight after entry:
8454- */
8455- ENABLE_INTERRUPTS(CLBR_NONE)
8456 movl %eax,%eax
8457 pushq_cfi %rax
8458 cld
8459 /* note the registers are not zero extended to the sf.
8460 this could be a problem. */
8461 SAVE_ARGS 0,1,0
8462- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8463- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8464+ pax_enter_kernel_user
8465+ /*
8466+ * No need to follow this irqs on/off section: the syscall
8467+ * disabled irqs and here we enable it straight after entry:
8468+ */
8469+ ENABLE_INTERRUPTS(CLBR_NONE)
8470+ GET_THREAD_INFO(%r11)
8471+ orl $TS_COMPAT,TI_status(%r11)
8472+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8473 jnz ia32_tracesys
8474 cmpq $(IA32_NR_syscalls-1),%rax
8475 ja ia32_badsys
8476@@ -435,6 +498,9 @@ ia32_tracesys:
8477 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8478 movq %rsp,%rdi /* &pt_regs -> arg1 */
8479 call syscall_trace_enter
8480+
8481+ pax_erase_kstack
8482+
8483 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8484 RESTORE_REST
8485 cmpq $(IA32_NR_syscalls-1),%rax
8486diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8487index f6f5c53..b358b28 100644
8488--- a/arch/x86/ia32/sys_ia32.c
8489+++ b/arch/x86/ia32/sys_ia32.c
8490@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8491 */
8492 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8493 {
8494- typeof(ubuf->st_uid) uid = 0;
8495- typeof(ubuf->st_gid) gid = 0;
8496+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
8497+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
8498 SET_UID(uid, stat->uid);
8499 SET_GID(gid, stat->gid);
8500 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8501@@ -308,8 +308,8 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
8502 }
8503 set_fs(KERNEL_DS);
8504 ret = sys_rt_sigprocmask(how,
8505- set ? (sigset_t __user *)&s : NULL,
8506- oset ? (sigset_t __user *)&s : NULL,
8507+ set ? (sigset_t __force_user *)&s : NULL,
8508+ oset ? (sigset_t __force_user *)&s : NULL,
8509 sigsetsize);
8510 set_fs(old_fs);
8511 if (ret)
8512@@ -332,7 +332,7 @@ asmlinkage long sys32_alarm(unsigned int seconds)
8513 return alarm_setitimer(seconds);
8514 }
8515
8516-asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8517+asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8518 int options)
8519 {
8520 return compat_sys_wait4(pid, stat_addr, options, NULL);
8521@@ -353,7 +353,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8522 mm_segment_t old_fs = get_fs();
8523
8524 set_fs(KERNEL_DS);
8525- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8526+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8527 set_fs(old_fs);
8528 if (put_compat_timespec(&t, interval))
8529 return -EFAULT;
8530@@ -369,7 +369,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8531 mm_segment_t old_fs = get_fs();
8532
8533 set_fs(KERNEL_DS);
8534- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8535+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8536 set_fs(old_fs);
8537 if (!ret) {
8538 switch (_NSIG_WORDS) {
8539@@ -394,7 +394,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8540 if (copy_siginfo_from_user32(&info, uinfo))
8541 return -EFAULT;
8542 set_fs(KERNEL_DS);
8543- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
8544+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
8545 set_fs(old_fs);
8546 return ret;
8547 }
8548@@ -439,7 +439,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
8549 return -EFAULT;
8550
8551 set_fs(KERNEL_DS);
8552- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
8553+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
8554 count);
8555 set_fs(old_fs);
8556
8557diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
8558index 952bd01..7692c6f 100644
8559--- a/arch/x86/include/asm/alternative-asm.h
8560+++ b/arch/x86/include/asm/alternative-asm.h
8561@@ -15,6 +15,45 @@
8562 .endm
8563 #endif
8564
8565+#ifdef KERNEXEC_PLUGIN
8566+ .macro pax_force_retaddr_bts rip=0
8567+ btsq $63,\rip(%rsp)
8568+ .endm
8569+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
8570+ .macro pax_force_retaddr rip=0, reload=0
8571+ btsq $63,\rip(%rsp)
8572+ .endm
8573+ .macro pax_force_fptr ptr
8574+ btsq $63,\ptr
8575+ .endm
8576+ .macro pax_set_fptr_mask
8577+ .endm
8578+#endif
8579+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
8580+ .macro pax_force_retaddr rip=0, reload=0
8581+ .if \reload
8582+ pax_set_fptr_mask
8583+ .endif
8584+ orq %r10,\rip(%rsp)
8585+ .endm
8586+ .macro pax_force_fptr ptr
8587+ orq %r10,\ptr
8588+ .endm
8589+ .macro pax_set_fptr_mask
8590+ movabs $0x8000000000000000,%r10
8591+ .endm
8592+#endif
8593+#else
8594+ .macro pax_force_retaddr rip=0, reload=0
8595+ .endm
8596+ .macro pax_force_fptr ptr
8597+ .endm
8598+ .macro pax_force_retaddr_bts rip=0
8599+ .endm
8600+ .macro pax_set_fptr_mask
8601+ .endm
8602+#endif
8603+
8604 .macro altinstruction_entry orig alt feature orig_len alt_len
8605 .long \orig - .
8606 .long \alt - .
8607diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
8608index 37ad100..7d47faa 100644
8609--- a/arch/x86/include/asm/alternative.h
8610+++ b/arch/x86/include/asm/alternative.h
8611@@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
8612 ".section .discard,\"aw\",@progbits\n" \
8613 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
8614 ".previous\n" \
8615- ".section .altinstr_replacement, \"ax\"\n" \
8616+ ".section .altinstr_replacement, \"a\"\n" \
8617 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
8618 ".previous"
8619
8620diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
8621index 3ab9bdd..238033e 100644
8622--- a/arch/x86/include/asm/apic.h
8623+++ b/arch/x86/include/asm/apic.h
8624@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
8625
8626 #ifdef CONFIG_X86_LOCAL_APIC
8627
8628-extern unsigned int apic_verbosity;
8629+extern int apic_verbosity;
8630 extern int local_apic_timer_c2_ok;
8631
8632 extern int disable_apic;
8633diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
8634index 20370c6..a2eb9b0 100644
8635--- a/arch/x86/include/asm/apm.h
8636+++ b/arch/x86/include/asm/apm.h
8637@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
8638 __asm__ __volatile__(APM_DO_ZERO_SEGS
8639 "pushl %%edi\n\t"
8640 "pushl %%ebp\n\t"
8641- "lcall *%%cs:apm_bios_entry\n\t"
8642+ "lcall *%%ss:apm_bios_entry\n\t"
8643 "setc %%al\n\t"
8644 "popl %%ebp\n\t"
8645 "popl %%edi\n\t"
8646@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
8647 __asm__ __volatile__(APM_DO_ZERO_SEGS
8648 "pushl %%edi\n\t"
8649 "pushl %%ebp\n\t"
8650- "lcall *%%cs:apm_bios_entry\n\t"
8651+ "lcall *%%ss:apm_bios_entry\n\t"
8652 "setc %%bl\n\t"
8653 "popl %%ebp\n\t"
8654 "popl %%edi\n\t"
8655diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
8656index 58cb6d4..ca9010d 100644
8657--- a/arch/x86/include/asm/atomic.h
8658+++ b/arch/x86/include/asm/atomic.h
8659@@ -22,7 +22,18 @@
8660 */
8661 static inline int atomic_read(const atomic_t *v)
8662 {
8663- return (*(volatile int *)&(v)->counter);
8664+ return (*(volatile const int *)&(v)->counter);
8665+}
8666+
8667+/**
8668+ * atomic_read_unchecked - read atomic variable
8669+ * @v: pointer of type atomic_unchecked_t
8670+ *
8671+ * Atomically reads the value of @v.
8672+ */
8673+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8674+{
8675+ return (*(volatile const int *)&(v)->counter);
8676 }
8677
8678 /**
8679@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
8680 }
8681
8682 /**
8683+ * atomic_set_unchecked - set atomic variable
8684+ * @v: pointer of type atomic_unchecked_t
8685+ * @i: required value
8686+ *
8687+ * Atomically sets the value of @v to @i.
8688+ */
8689+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8690+{
8691+ v->counter = i;
8692+}
8693+
8694+/**
8695 * atomic_add - add integer to atomic variable
8696 * @i: integer value to add
8697 * @v: pointer of type atomic_t
8698@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
8699 */
8700 static inline void atomic_add(int i, atomic_t *v)
8701 {
8702- asm volatile(LOCK_PREFIX "addl %1,%0"
8703+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
8704+
8705+#ifdef CONFIG_PAX_REFCOUNT
8706+ "jno 0f\n"
8707+ LOCK_PREFIX "subl %1,%0\n"
8708+ "int $4\n0:\n"
8709+ _ASM_EXTABLE(0b, 0b)
8710+#endif
8711+
8712+ : "+m" (v->counter)
8713+ : "ir" (i));
8714+}
8715+
8716+/**
8717+ * atomic_add_unchecked - add integer to atomic variable
8718+ * @i: integer value to add
8719+ * @v: pointer of type atomic_unchecked_t
8720+ *
8721+ * Atomically adds @i to @v.
8722+ */
8723+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
8724+{
8725+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
8726 : "+m" (v->counter)
8727 : "ir" (i));
8728 }
8729@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
8730 */
8731 static inline void atomic_sub(int i, atomic_t *v)
8732 {
8733- asm volatile(LOCK_PREFIX "subl %1,%0"
8734+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
8735+
8736+#ifdef CONFIG_PAX_REFCOUNT
8737+ "jno 0f\n"
8738+ LOCK_PREFIX "addl %1,%0\n"
8739+ "int $4\n0:\n"
8740+ _ASM_EXTABLE(0b, 0b)
8741+#endif
8742+
8743+ : "+m" (v->counter)
8744+ : "ir" (i));
8745+}
8746+
8747+/**
8748+ * atomic_sub_unchecked - subtract integer from atomic variable
8749+ * @i: integer value to subtract
8750+ * @v: pointer of type atomic_unchecked_t
8751+ *
8752+ * Atomically subtracts @i from @v.
8753+ */
8754+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
8755+{
8756+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
8757 : "+m" (v->counter)
8758 : "ir" (i));
8759 }
8760@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8761 {
8762 unsigned char c;
8763
8764- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
8765+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
8766+
8767+#ifdef CONFIG_PAX_REFCOUNT
8768+ "jno 0f\n"
8769+ LOCK_PREFIX "addl %2,%0\n"
8770+ "int $4\n0:\n"
8771+ _ASM_EXTABLE(0b, 0b)
8772+#endif
8773+
8774+ "sete %1\n"
8775 : "+m" (v->counter), "=qm" (c)
8776 : "ir" (i) : "memory");
8777 return c;
8778@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8779 */
8780 static inline void atomic_inc(atomic_t *v)
8781 {
8782- asm volatile(LOCK_PREFIX "incl %0"
8783+ asm volatile(LOCK_PREFIX "incl %0\n"
8784+
8785+#ifdef CONFIG_PAX_REFCOUNT
8786+ "jno 0f\n"
8787+ LOCK_PREFIX "decl %0\n"
8788+ "int $4\n0:\n"
8789+ _ASM_EXTABLE(0b, 0b)
8790+#endif
8791+
8792+ : "+m" (v->counter));
8793+}
8794+
8795+/**
8796+ * atomic_inc_unchecked - increment atomic variable
8797+ * @v: pointer of type atomic_unchecked_t
8798+ *
8799+ * Atomically increments @v by 1.
8800+ */
8801+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8802+{
8803+ asm volatile(LOCK_PREFIX "incl %0\n"
8804 : "+m" (v->counter));
8805 }
8806
8807@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
8808 */
8809 static inline void atomic_dec(atomic_t *v)
8810 {
8811- asm volatile(LOCK_PREFIX "decl %0"
8812+ asm volatile(LOCK_PREFIX "decl %0\n"
8813+
8814+#ifdef CONFIG_PAX_REFCOUNT
8815+ "jno 0f\n"
8816+ LOCK_PREFIX "incl %0\n"
8817+ "int $4\n0:\n"
8818+ _ASM_EXTABLE(0b, 0b)
8819+#endif
8820+
8821+ : "+m" (v->counter));
8822+}
8823+
8824+/**
8825+ * atomic_dec_unchecked - decrement atomic variable
8826+ * @v: pointer of type atomic_unchecked_t
8827+ *
8828+ * Atomically decrements @v by 1.
8829+ */
8830+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8831+{
8832+ asm volatile(LOCK_PREFIX "decl %0\n"
8833 : "+m" (v->counter));
8834 }
8835
8836@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
8837 {
8838 unsigned char c;
8839
8840- asm volatile(LOCK_PREFIX "decl %0; sete %1"
8841+ asm volatile(LOCK_PREFIX "decl %0\n"
8842+
8843+#ifdef CONFIG_PAX_REFCOUNT
8844+ "jno 0f\n"
8845+ LOCK_PREFIX "incl %0\n"
8846+ "int $4\n0:\n"
8847+ _ASM_EXTABLE(0b, 0b)
8848+#endif
8849+
8850+ "sete %1\n"
8851 : "+m" (v->counter), "=qm" (c)
8852 : : "memory");
8853 return c != 0;
8854@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
8855 {
8856 unsigned char c;
8857
8858- asm volatile(LOCK_PREFIX "incl %0; sete %1"
8859+ asm volatile(LOCK_PREFIX "incl %0\n"
8860+
8861+#ifdef CONFIG_PAX_REFCOUNT
8862+ "jno 0f\n"
8863+ LOCK_PREFIX "decl %0\n"
8864+ "int $4\n0:\n"
8865+ _ASM_EXTABLE(0b, 0b)
8866+#endif
8867+
8868+ "sete %1\n"
8869+ : "+m" (v->counter), "=qm" (c)
8870+ : : "memory");
8871+ return c != 0;
8872+}
8873+
8874+/**
8875+ * atomic_inc_and_test_unchecked - increment and test
8876+ * @v: pointer of type atomic_unchecked_t
8877+ *
8878+ * Atomically increments @v by 1
8879+ * and returns true if the result is zero, or false for all
8880+ * other cases.
8881+ */
8882+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8883+{
8884+ unsigned char c;
8885+
8886+ asm volatile(LOCK_PREFIX "incl %0\n"
8887+ "sete %1\n"
8888 : "+m" (v->counter), "=qm" (c)
8889 : : "memory");
8890 return c != 0;
8891@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
8892 {
8893 unsigned char c;
8894
8895- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
8896+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
8897+
8898+#ifdef CONFIG_PAX_REFCOUNT
8899+ "jno 0f\n"
8900+ LOCK_PREFIX "subl %2,%0\n"
8901+ "int $4\n0:\n"
8902+ _ASM_EXTABLE(0b, 0b)
8903+#endif
8904+
8905+ "sets %1\n"
8906 : "+m" (v->counter), "=qm" (c)
8907 : "ir" (i) : "memory");
8908 return c;
8909@@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
8910 goto no_xadd;
8911 #endif
8912 /* Modern 486+ processor */
8913- return i + xadd(&v->counter, i);
8914+ return i + xadd_check_overflow(&v->counter, i);
8915
8916 #ifdef CONFIG_M386
8917 no_xadd: /* Legacy 386 processor */
8918@@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
8919 }
8920
8921 /**
8922+ * atomic_add_return_unchecked - add integer and return
8923+ * @i: integer value to add
8924+ * @v: pointer of type atomic_unchecked_t
8925+ *
8926+ * Atomically adds @i to @v and returns @i + @v
8927+ */
8928+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8929+{
8930+#ifdef CONFIG_M386
8931+ int __i;
8932+ unsigned long flags;
8933+ if (unlikely(boot_cpu_data.x86 <= 3))
8934+ goto no_xadd;
8935+#endif
8936+ /* Modern 486+ processor */
8937+ return i + xadd(&v->counter, i);
8938+
8939+#ifdef CONFIG_M386
8940+no_xadd: /* Legacy 386 processor */
8941+ raw_local_irq_save(flags);
8942+ __i = atomic_read_unchecked(v);
8943+ atomic_set_unchecked(v, i + __i);
8944+ raw_local_irq_restore(flags);
8945+ return i + __i;
8946+#endif
8947+}
8948+
8949+/**
8950 * atomic_sub_return - subtract integer and return
8951 * @v: pointer of type atomic_t
8952 * @i: integer value to subtract
8953@@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
8954 }
8955
8956 #define atomic_inc_return(v) (atomic_add_return(1, v))
8957+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8958+{
8959+ return atomic_add_return_unchecked(1, v);
8960+}
8961 #define atomic_dec_return(v) (atomic_sub_return(1, v))
8962
8963 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
8964@@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
8965 return cmpxchg(&v->counter, old, new);
8966 }
8967
8968+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8969+{
8970+ return cmpxchg(&v->counter, old, new);
8971+}
8972+
8973 static inline int atomic_xchg(atomic_t *v, int new)
8974 {
8975 return xchg(&v->counter, new);
8976 }
8977
8978+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8979+{
8980+ return xchg(&v->counter, new);
8981+}
8982+
8983 /**
8984 * __atomic_add_unless - add unless the number is already a given value
8985 * @v: pointer of type atomic_t
8986@@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
8987 */
8988 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8989 {
8990- int c, old;
8991+ int c, old, new;
8992 c = atomic_read(v);
8993 for (;;) {
8994- if (unlikely(c == (u)))
8995+ if (unlikely(c == u))
8996 break;
8997- old = atomic_cmpxchg((v), c, c + (a));
8998+
8999+ asm volatile("addl %2,%0\n"
9000+
9001+#ifdef CONFIG_PAX_REFCOUNT
9002+ "jno 0f\n"
9003+ "subl %2,%0\n"
9004+ "int $4\n0:\n"
9005+ _ASM_EXTABLE(0b, 0b)
9006+#endif
9007+
9008+ : "=r" (new)
9009+ : "0" (c), "ir" (a));
9010+
9011+ old = atomic_cmpxchg(v, c, new);
9012 if (likely(old == c))
9013 break;
9014 c = old;
9015@@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9016 return c;
9017 }
9018
9019+/**
9020+ * atomic_inc_not_zero_hint - increment if not null
9021+ * @v: pointer of type atomic_t
9022+ * @hint: probable value of the atomic before the increment
9023+ *
9024+ * This version of atomic_inc_not_zero() gives a hint of probable
9025+ * value of the atomic. This helps processor to not read the memory
9026+ * before doing the atomic read/modify/write cycle, lowering
9027+ * number of bus transactions on some arches.
9028+ *
9029+ * Returns: 0 if increment was not done, 1 otherwise.
9030+ */
9031+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9032+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9033+{
9034+ int val, c = hint, new;
9035+
9036+ /* sanity test, should be removed by compiler if hint is a constant */
9037+ if (!hint)
9038+ return __atomic_add_unless(v, 1, 0);
9039+
9040+ do {
9041+ asm volatile("incl %0\n"
9042+
9043+#ifdef CONFIG_PAX_REFCOUNT
9044+ "jno 0f\n"
9045+ "decl %0\n"
9046+ "int $4\n0:\n"
9047+ _ASM_EXTABLE(0b, 0b)
9048+#endif
9049+
9050+ : "=r" (new)
9051+ : "0" (c));
9052+
9053+ val = atomic_cmpxchg(v, c, new);
9054+ if (val == c)
9055+ return 1;
9056+ c = val;
9057+ } while (c);
9058+
9059+ return 0;
9060+}
9061
9062 /*
9063 * atomic_dec_if_positive - decrement by 1 if old value positive
9064diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9065index fa13f0e..27c2e08 100644
9066--- a/arch/x86/include/asm/atomic64_32.h
9067+++ b/arch/x86/include/asm/atomic64_32.h
9068@@ -12,6 +12,14 @@ typedef struct {
9069 u64 __aligned(8) counter;
9070 } atomic64_t;
9071
9072+#ifdef CONFIG_PAX_REFCOUNT
9073+typedef struct {
9074+ u64 __aligned(8) counter;
9075+} atomic64_unchecked_t;
9076+#else
9077+typedef atomic64_t atomic64_unchecked_t;
9078+#endif
9079+
9080 #define ATOMIC64_INIT(val) { (val) }
9081
9082 #ifdef CONFIG_X86_CMPXCHG64
9083@@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9084 }
9085
9086 /**
9087+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9088+ * @p: pointer to type atomic64_unchecked_t
9089+ * @o: expected value
9090+ * @n: new value
9091+ *
9092+ * Atomically sets @v to @n if it was equal to @o and returns
9093+ * the old value.
9094+ */
9095+
9096+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9097+{
9098+ return cmpxchg64(&v->counter, o, n);
9099+}
9100+
9101+/**
9102 * atomic64_xchg - xchg atomic64 variable
9103 * @v: pointer to type atomic64_t
9104 * @n: value to assign
9105@@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9106 }
9107
9108 /**
9109+ * atomic64_set_unchecked - set atomic64 variable
9110+ * @v: pointer to type atomic64_unchecked_t
9111+ * @n: value to assign
9112+ *
9113+ * Atomically sets the value of @v to @n.
9114+ */
9115+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9116+{
9117+ unsigned high = (unsigned)(i >> 32);
9118+ unsigned low = (unsigned)i;
9119+ asm volatile(ATOMIC64_ALTERNATIVE(set)
9120+ : "+b" (low), "+c" (high)
9121+ : "S" (v)
9122+ : "eax", "edx", "memory"
9123+ );
9124+}
9125+
9126+/**
9127 * atomic64_read - read atomic64 variable
9128 * @v: pointer to type atomic64_t
9129 *
9130@@ -93,6 +134,22 @@ static inline long long atomic64_read(const atomic64_t *v)
9131 }
9132
9133 /**
9134+ * atomic64_read_unchecked - read atomic64 variable
9135+ * @v: pointer to type atomic64_unchecked_t
9136+ *
9137+ * Atomically reads the value of @v and returns it.
9138+ */
9139+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9140+{
9141+ long long r;
9142+ asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
9143+ : "=A" (r), "+c" (v)
9144+ : : "memory"
9145+ );
9146+ return r;
9147+ }
9148+
9149+/**
9150 * atomic64_add_return - add and return
9151 * @i: integer value to add
9152 * @v: pointer to type atomic64_t
9153@@ -108,6 +165,22 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9154 return i;
9155 }
9156
9157+/**
9158+ * atomic64_add_return_unchecked - add and return
9159+ * @i: integer value to add
9160+ * @v: pointer to type atomic64_unchecked_t
9161+ *
9162+ * Atomically adds @i to @v and returns @i + *@v
9163+ */
9164+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9165+{
9166+ asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
9167+ : "+A" (i), "+c" (v)
9168+ : : "memory"
9169+ );
9170+ return i;
9171+}
9172+
9173 /*
9174 * Other variants with different arithmetic operators:
9175 */
9176@@ -131,6 +204,17 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9177 return a;
9178 }
9179
9180+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9181+{
9182+ long long a;
9183+ asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
9184+ : "=A" (a)
9185+ : "S" (v)
9186+ : "memory", "ecx"
9187+ );
9188+ return a;
9189+}
9190+
9191 static inline long long atomic64_dec_return(atomic64_t *v)
9192 {
9193 long long a;
9194@@ -159,6 +243,22 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9195 }
9196
9197 /**
9198+ * atomic64_add_unchecked - add integer to atomic64 variable
9199+ * @i: integer value to add
9200+ * @v: pointer to type atomic64_unchecked_t
9201+ *
9202+ * Atomically adds @i to @v.
9203+ */
9204+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9205+{
9206+ asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
9207+ : "+A" (i), "+c" (v)
9208+ : : "memory"
9209+ );
9210+ return i;
9211+}
9212+
9213+/**
9214 * atomic64_sub - subtract the atomic64 variable
9215 * @i: integer value to subtract
9216 * @v: pointer to type atomic64_t
9217diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9218index 0e1cbfc..5623683 100644
9219--- a/arch/x86/include/asm/atomic64_64.h
9220+++ b/arch/x86/include/asm/atomic64_64.h
9221@@ -18,7 +18,19 @@
9222 */
9223 static inline long atomic64_read(const atomic64_t *v)
9224 {
9225- return (*(volatile long *)&(v)->counter);
9226+ return (*(volatile const long *)&(v)->counter);
9227+}
9228+
9229+/**
9230+ * atomic64_read_unchecked - read atomic64 variable
9231+ * @v: pointer of type atomic64_unchecked_t
9232+ *
9233+ * Atomically reads the value of @v.
9234+ * Doesn't imply a read memory barrier.
9235+ */
9236+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9237+{
9238+ return (*(volatile const long *)&(v)->counter);
9239 }
9240
9241 /**
9242@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9243 }
9244
9245 /**
9246+ * atomic64_set_unchecked - set atomic64 variable
9247+ * @v: pointer to type atomic64_unchecked_t
9248+ * @i: required value
9249+ *
9250+ * Atomically sets the value of @v to @i.
9251+ */
9252+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9253+{
9254+ v->counter = i;
9255+}
9256+
9257+/**
9258 * atomic64_add - add integer to atomic64 variable
9259 * @i: integer value to add
9260 * @v: pointer to type atomic64_t
9261@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9262 */
9263 static inline void atomic64_add(long i, atomic64_t *v)
9264 {
9265+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
9266+
9267+#ifdef CONFIG_PAX_REFCOUNT
9268+ "jno 0f\n"
9269+ LOCK_PREFIX "subq %1,%0\n"
9270+ "int $4\n0:\n"
9271+ _ASM_EXTABLE(0b, 0b)
9272+#endif
9273+
9274+ : "=m" (v->counter)
9275+ : "er" (i), "m" (v->counter));
9276+}
9277+
9278+/**
9279+ * atomic64_add_unchecked - add integer to atomic64 variable
9280+ * @i: integer value to add
9281+ * @v: pointer to type atomic64_unchecked_t
9282+ *
9283+ * Atomically adds @i to @v.
9284+ */
9285+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9286+{
9287 asm volatile(LOCK_PREFIX "addq %1,%0"
9288 : "=m" (v->counter)
9289 : "er" (i), "m" (v->counter));
9290@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9291 */
9292 static inline void atomic64_sub(long i, atomic64_t *v)
9293 {
9294- asm volatile(LOCK_PREFIX "subq %1,%0"
9295+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9296+
9297+#ifdef CONFIG_PAX_REFCOUNT
9298+ "jno 0f\n"
9299+ LOCK_PREFIX "addq %1,%0\n"
9300+ "int $4\n0:\n"
9301+ _ASM_EXTABLE(0b, 0b)
9302+#endif
9303+
9304+ : "=m" (v->counter)
9305+ : "er" (i), "m" (v->counter));
9306+}
9307+
9308+/**
9309+ * atomic64_sub_unchecked - subtract the atomic64 variable
9310+ * @i: integer value to subtract
9311+ * @v: pointer to type atomic64_unchecked_t
9312+ *
9313+ * Atomically subtracts @i from @v.
9314+ */
9315+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9316+{
9317+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9318 : "=m" (v->counter)
9319 : "er" (i), "m" (v->counter));
9320 }
9321@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9322 {
9323 unsigned char c;
9324
9325- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9326+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
9327+
9328+#ifdef CONFIG_PAX_REFCOUNT
9329+ "jno 0f\n"
9330+ LOCK_PREFIX "addq %2,%0\n"
9331+ "int $4\n0:\n"
9332+ _ASM_EXTABLE(0b, 0b)
9333+#endif
9334+
9335+ "sete %1\n"
9336 : "=m" (v->counter), "=qm" (c)
9337 : "er" (i), "m" (v->counter) : "memory");
9338 return c;
9339@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9340 */
9341 static inline void atomic64_inc(atomic64_t *v)
9342 {
9343+ asm volatile(LOCK_PREFIX "incq %0\n"
9344+
9345+#ifdef CONFIG_PAX_REFCOUNT
9346+ "jno 0f\n"
9347+ LOCK_PREFIX "decq %0\n"
9348+ "int $4\n0:\n"
9349+ _ASM_EXTABLE(0b, 0b)
9350+#endif
9351+
9352+ : "=m" (v->counter)
9353+ : "m" (v->counter));
9354+}
9355+
9356+/**
9357+ * atomic64_inc_unchecked - increment atomic64 variable
9358+ * @v: pointer to type atomic64_unchecked_t
9359+ *
9360+ * Atomically increments @v by 1.
9361+ */
9362+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9363+{
9364 asm volatile(LOCK_PREFIX "incq %0"
9365 : "=m" (v->counter)
9366 : "m" (v->counter));
9367@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9368 */
9369 static inline void atomic64_dec(atomic64_t *v)
9370 {
9371- asm volatile(LOCK_PREFIX "decq %0"
9372+ asm volatile(LOCK_PREFIX "decq %0\n"
9373+
9374+#ifdef CONFIG_PAX_REFCOUNT
9375+ "jno 0f\n"
9376+ LOCK_PREFIX "incq %0\n"
9377+ "int $4\n0:\n"
9378+ _ASM_EXTABLE(0b, 0b)
9379+#endif
9380+
9381+ : "=m" (v->counter)
9382+ : "m" (v->counter));
9383+}
9384+
9385+/**
9386+ * atomic64_dec_unchecked - decrement atomic64 variable
9387+ * @v: pointer to type atomic64_t
9388+ *
9389+ * Atomically decrements @v by 1.
9390+ */
9391+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9392+{
9393+ asm volatile(LOCK_PREFIX "decq %0\n"
9394 : "=m" (v->counter)
9395 : "m" (v->counter));
9396 }
9397@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9398 {
9399 unsigned char c;
9400
9401- asm volatile(LOCK_PREFIX "decq %0; sete %1"
9402+ asm volatile(LOCK_PREFIX "decq %0\n"
9403+
9404+#ifdef CONFIG_PAX_REFCOUNT
9405+ "jno 0f\n"
9406+ LOCK_PREFIX "incq %0\n"
9407+ "int $4\n0:\n"
9408+ _ASM_EXTABLE(0b, 0b)
9409+#endif
9410+
9411+ "sete %1\n"
9412 : "=m" (v->counter), "=qm" (c)
9413 : "m" (v->counter) : "memory");
9414 return c != 0;
9415@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9416 {
9417 unsigned char c;
9418
9419- asm volatile(LOCK_PREFIX "incq %0; sete %1"
9420+ asm volatile(LOCK_PREFIX "incq %0\n"
9421+
9422+#ifdef CONFIG_PAX_REFCOUNT
9423+ "jno 0f\n"
9424+ LOCK_PREFIX "decq %0\n"
9425+ "int $4\n0:\n"
9426+ _ASM_EXTABLE(0b, 0b)
9427+#endif
9428+
9429+ "sete %1\n"
9430 : "=m" (v->counter), "=qm" (c)
9431 : "m" (v->counter) : "memory");
9432 return c != 0;
9433@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9434 {
9435 unsigned char c;
9436
9437- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9438+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
9439+
9440+#ifdef CONFIG_PAX_REFCOUNT
9441+ "jno 0f\n"
9442+ LOCK_PREFIX "subq %2,%0\n"
9443+ "int $4\n0:\n"
9444+ _ASM_EXTABLE(0b, 0b)
9445+#endif
9446+
9447+ "sets %1\n"
9448 : "=m" (v->counter), "=qm" (c)
9449 : "er" (i), "m" (v->counter) : "memory");
9450 return c;
9451@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9452 */
9453 static inline long atomic64_add_return(long i, atomic64_t *v)
9454 {
9455+ return i + xadd_check_overflow(&v->counter, i);
9456+}
9457+
9458+/**
9459+ * atomic64_add_return_unchecked - add and return
9460+ * @i: integer value to add
9461+ * @v: pointer to type atomic64_unchecked_t
9462+ *
9463+ * Atomically adds @i to @v and returns @i + @v
9464+ */
9465+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9466+{
9467 return i + xadd(&v->counter, i);
9468 }
9469
9470@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9471 }
9472
9473 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9474+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9475+{
9476+ return atomic64_add_return_unchecked(1, v);
9477+}
9478 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9479
9480 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9481@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9482 return cmpxchg(&v->counter, old, new);
9483 }
9484
9485+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9486+{
9487+ return cmpxchg(&v->counter, old, new);
9488+}
9489+
9490 static inline long atomic64_xchg(atomic64_t *v, long new)
9491 {
9492 return xchg(&v->counter, new);
9493@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
9494 */
9495 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9496 {
9497- long c, old;
9498+ long c, old, new;
9499 c = atomic64_read(v);
9500 for (;;) {
9501- if (unlikely(c == (u)))
9502+ if (unlikely(c == u))
9503 break;
9504- old = atomic64_cmpxchg((v), c, c + (a));
9505+
9506+ asm volatile("add %2,%0\n"
9507+
9508+#ifdef CONFIG_PAX_REFCOUNT
9509+ "jno 0f\n"
9510+ "sub %2,%0\n"
9511+ "int $4\n0:\n"
9512+ _ASM_EXTABLE(0b, 0b)
9513+#endif
9514+
9515+ : "=r" (new)
9516+ : "0" (c), "ir" (a));
9517+
9518+ old = atomic64_cmpxchg(v, c, new);
9519 if (likely(old == c))
9520 break;
9521 c = old;
9522 }
9523- return c != (u);
9524+ return c != u;
9525 }
9526
9527 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9528diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
9529index b97596e..9bd48b06 100644
9530--- a/arch/x86/include/asm/bitops.h
9531+++ b/arch/x86/include/asm/bitops.h
9532@@ -38,7 +38,7 @@
9533 * a mask operation on a byte.
9534 */
9535 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
9536-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
9537+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
9538 #define CONST_MASK(nr) (1 << ((nr) & 7))
9539
9540 /**
9541diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
9542index 5e1a2ee..c9f9533 100644
9543--- a/arch/x86/include/asm/boot.h
9544+++ b/arch/x86/include/asm/boot.h
9545@@ -11,10 +11,15 @@
9546 #include <asm/pgtable_types.h>
9547
9548 /* Physical address where kernel should be loaded. */
9549-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9550+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9551 + (CONFIG_PHYSICAL_ALIGN - 1)) \
9552 & ~(CONFIG_PHYSICAL_ALIGN - 1))
9553
9554+#ifndef __ASSEMBLY__
9555+extern unsigned char __LOAD_PHYSICAL_ADDR[];
9556+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
9557+#endif
9558+
9559 /* Minimum kernel alignment, as a power of two */
9560 #ifdef CONFIG_X86_64
9561 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
9562diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
9563index 48f99f1..d78ebf9 100644
9564--- a/arch/x86/include/asm/cache.h
9565+++ b/arch/x86/include/asm/cache.h
9566@@ -5,12 +5,13 @@
9567
9568 /* L1 cache line size */
9569 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9570-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9571+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9572
9573 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9574+#define __read_only __attribute__((__section__(".data..read_only")))
9575
9576 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
9577-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
9578+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
9579
9580 #ifdef CONFIG_X86_VSMP
9581 #ifdef CONFIG_SMP
9582diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
9583index 4e12668..501d239 100644
9584--- a/arch/x86/include/asm/cacheflush.h
9585+++ b/arch/x86/include/asm/cacheflush.h
9586@@ -26,7 +26,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
9587 unsigned long pg_flags = pg->flags & _PGMT_MASK;
9588
9589 if (pg_flags == _PGMT_DEFAULT)
9590- return -1;
9591+ return ~0UL;
9592 else if (pg_flags == _PGMT_WC)
9593 return _PAGE_CACHE_WC;
9594 else if (pg_flags == _PGMT_UC_MINUS)
9595diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
9596index 46fc474..b02b0f9 100644
9597--- a/arch/x86/include/asm/checksum_32.h
9598+++ b/arch/x86/include/asm/checksum_32.h
9599@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
9600 int len, __wsum sum,
9601 int *src_err_ptr, int *dst_err_ptr);
9602
9603+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
9604+ int len, __wsum sum,
9605+ int *src_err_ptr, int *dst_err_ptr);
9606+
9607+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
9608+ int len, __wsum sum,
9609+ int *src_err_ptr, int *dst_err_ptr);
9610+
9611 /*
9612 * Note: when you get a NULL pointer exception here this means someone
9613 * passed in an incorrect kernel address to one of these functions.
9614@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
9615 int *err_ptr)
9616 {
9617 might_sleep();
9618- return csum_partial_copy_generic((__force void *)src, dst,
9619+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
9620 len, sum, err_ptr, NULL);
9621 }
9622
9623@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
9624 {
9625 might_sleep();
9626 if (access_ok(VERIFY_WRITE, dst, len))
9627- return csum_partial_copy_generic(src, (__force void *)dst,
9628+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
9629 len, sum, NULL, err_ptr);
9630
9631 if (len)
9632diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
9633index b3b7332..3935f40 100644
9634--- a/arch/x86/include/asm/cmpxchg.h
9635+++ b/arch/x86/include/asm/cmpxchg.h
9636@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
9637 __compiletime_error("Bad argument size for cmpxchg");
9638 extern void __xadd_wrong_size(void)
9639 __compiletime_error("Bad argument size for xadd");
9640+extern void __xadd_check_overflow_wrong_size(void)
9641+ __compiletime_error("Bad argument size for xadd_check_overflow");
9642 extern void __add_wrong_size(void)
9643 __compiletime_error("Bad argument size for add");
9644+extern void __add_check_overflow_wrong_size(void)
9645+ __compiletime_error("Bad argument size for add_check_overflow");
9646
9647 /*
9648 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
9649@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
9650 __ret; \
9651 })
9652
9653+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
9654+ ({ \
9655+ __typeof__ (*(ptr)) __ret = (arg); \
9656+ switch (sizeof(*(ptr))) { \
9657+ case __X86_CASE_L: \
9658+ asm volatile (lock #op "l %0, %1\n" \
9659+ "jno 0f\n" \
9660+ "mov %0,%1\n" \
9661+ "int $4\n0:\n" \
9662+ _ASM_EXTABLE(0b, 0b) \
9663+ : "+r" (__ret), "+m" (*(ptr)) \
9664+ : : "memory", "cc"); \
9665+ break; \
9666+ case __X86_CASE_Q: \
9667+ asm volatile (lock #op "q %q0, %1\n" \
9668+ "jno 0f\n" \
9669+ "mov %0,%1\n" \
9670+ "int $4\n0:\n" \
9671+ _ASM_EXTABLE(0b, 0b) \
9672+ : "+r" (__ret), "+m" (*(ptr)) \
9673+ : : "memory", "cc"); \
9674+ break; \
9675+ default: \
9676+ __ ## op ## _check_overflow_wrong_size(); \
9677+ } \
9678+ __ret; \
9679+ })
9680+
9681 /*
9682 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
9683 * Since this is generally used to protect other memory information, we
9684@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
9685 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
9686 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
9687
9688+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
9689+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
9690+
9691 #define __add(ptr, inc, lock) \
9692 ({ \
9693 __typeof__ (*(ptr)) __ret = (inc); \
9694diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
9695index 8d67d42..183d0eb 100644
9696--- a/arch/x86/include/asm/cpufeature.h
9697+++ b/arch/x86/include/asm/cpufeature.h
9698@@ -367,7 +367,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
9699 ".section .discard,\"aw\",@progbits\n"
9700 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
9701 ".previous\n"
9702- ".section .altinstr_replacement,\"ax\"\n"
9703+ ".section .altinstr_replacement,\"a\"\n"
9704 "3: movb $1,%0\n"
9705 "4:\n"
9706 ".previous\n"
9707diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
9708index e95822d..a90010e 100644
9709--- a/arch/x86/include/asm/desc.h
9710+++ b/arch/x86/include/asm/desc.h
9711@@ -4,6 +4,7 @@
9712 #include <asm/desc_defs.h>
9713 #include <asm/ldt.h>
9714 #include <asm/mmu.h>
9715+#include <asm/pgtable.h>
9716
9717 #include <linux/smp.h>
9718
9719@@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
9720
9721 desc->type = (info->read_exec_only ^ 1) << 1;
9722 desc->type |= info->contents << 2;
9723+ desc->type |= info->seg_not_present ^ 1;
9724
9725 desc->s = 1;
9726 desc->dpl = 0x3;
9727@@ -34,19 +36,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
9728 }
9729
9730 extern struct desc_ptr idt_descr;
9731-extern gate_desc idt_table[];
9732 extern struct desc_ptr nmi_idt_descr;
9733-extern gate_desc nmi_idt_table[];
9734-
9735-struct gdt_page {
9736- struct desc_struct gdt[GDT_ENTRIES];
9737-} __attribute__((aligned(PAGE_SIZE)));
9738-
9739-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
9740+extern gate_desc idt_table[256];
9741+extern gate_desc nmi_idt_table[256];
9742
9743+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
9744 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
9745 {
9746- return per_cpu(gdt_page, cpu).gdt;
9747+ return cpu_gdt_table[cpu];
9748 }
9749
9750 #ifdef CONFIG_X86_64
9751@@ -71,8 +68,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
9752 unsigned long base, unsigned dpl, unsigned flags,
9753 unsigned short seg)
9754 {
9755- gate->a = (seg << 16) | (base & 0xffff);
9756- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
9757+ gate->gate.offset_low = base;
9758+ gate->gate.seg = seg;
9759+ gate->gate.reserved = 0;
9760+ gate->gate.type = type;
9761+ gate->gate.s = 0;
9762+ gate->gate.dpl = dpl;
9763+ gate->gate.p = 1;
9764+ gate->gate.offset_high = base >> 16;
9765 }
9766
9767 #endif
9768@@ -117,12 +120,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
9769
9770 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
9771 {
9772+ pax_open_kernel();
9773 memcpy(&idt[entry], gate, sizeof(*gate));
9774+ pax_close_kernel();
9775 }
9776
9777 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
9778 {
9779+ pax_open_kernel();
9780 memcpy(&ldt[entry], desc, 8);
9781+ pax_close_kernel();
9782 }
9783
9784 static inline void
9785@@ -136,7 +143,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
9786 default: size = sizeof(*gdt); break;
9787 }
9788
9789+ pax_open_kernel();
9790 memcpy(&gdt[entry], desc, size);
9791+ pax_close_kernel();
9792 }
9793
9794 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
9795@@ -209,7 +218,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
9796
9797 static inline void native_load_tr_desc(void)
9798 {
9799+ pax_open_kernel();
9800 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
9801+ pax_close_kernel();
9802 }
9803
9804 static inline void native_load_gdt(const struct desc_ptr *dtr)
9805@@ -246,8 +257,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
9806 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
9807 unsigned int i;
9808
9809+ pax_open_kernel();
9810 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
9811 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
9812+ pax_close_kernel();
9813 }
9814
9815 #define _LDT_empty(info) \
9816@@ -310,7 +323,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
9817 }
9818
9819 #ifdef CONFIG_X86_64
9820-static inline void set_nmi_gate(int gate, void *addr)
9821+static inline void set_nmi_gate(int gate, const void *addr)
9822 {
9823 gate_desc s;
9824
9825@@ -319,7 +332,7 @@ static inline void set_nmi_gate(int gate, void *addr)
9826 }
9827 #endif
9828
9829-static inline void _set_gate(int gate, unsigned type, void *addr,
9830+static inline void _set_gate(int gate, unsigned type, const void *addr,
9831 unsigned dpl, unsigned ist, unsigned seg)
9832 {
9833 gate_desc s;
9834@@ -338,7 +351,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
9835 * Pentium F0 0F bugfix can have resulted in the mapped
9836 * IDT being write-protected.
9837 */
9838-static inline void set_intr_gate(unsigned int n, void *addr)
9839+static inline void set_intr_gate(unsigned int n, const void *addr)
9840 {
9841 BUG_ON((unsigned)n > 0xFF);
9842 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
9843@@ -368,19 +381,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
9844 /*
9845 * This routine sets up an interrupt gate at directory privilege level 3.
9846 */
9847-static inline void set_system_intr_gate(unsigned int n, void *addr)
9848+static inline void set_system_intr_gate(unsigned int n, const void *addr)
9849 {
9850 BUG_ON((unsigned)n > 0xFF);
9851 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
9852 }
9853
9854-static inline void set_system_trap_gate(unsigned int n, void *addr)
9855+static inline void set_system_trap_gate(unsigned int n, const void *addr)
9856 {
9857 BUG_ON((unsigned)n > 0xFF);
9858 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
9859 }
9860
9861-static inline void set_trap_gate(unsigned int n, void *addr)
9862+static inline void set_trap_gate(unsigned int n, const void *addr)
9863 {
9864 BUG_ON((unsigned)n > 0xFF);
9865 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
9866@@ -389,19 +402,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
9867 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
9868 {
9869 BUG_ON((unsigned)n > 0xFF);
9870- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
9871+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
9872 }
9873
9874-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
9875+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
9876 {
9877 BUG_ON((unsigned)n > 0xFF);
9878 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
9879 }
9880
9881-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
9882+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
9883 {
9884 BUG_ON((unsigned)n > 0xFF);
9885 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
9886 }
9887
9888+#ifdef CONFIG_X86_32
9889+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
9890+{
9891+ struct desc_struct d;
9892+
9893+ if (likely(limit))
9894+ limit = (limit - 1UL) >> PAGE_SHIFT;
9895+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
9896+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
9897+}
9898+#endif
9899+
9900 #endif /* _ASM_X86_DESC_H */
9901diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
9902index 278441f..b95a174 100644
9903--- a/arch/x86/include/asm/desc_defs.h
9904+++ b/arch/x86/include/asm/desc_defs.h
9905@@ -31,6 +31,12 @@ struct desc_struct {
9906 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
9907 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
9908 };
9909+ struct {
9910+ u16 offset_low;
9911+ u16 seg;
9912+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
9913+ unsigned offset_high: 16;
9914+ } gate;
9915 };
9916 } __attribute__((packed));
9917
9918diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
9919index 3778256..c5d4fce 100644
9920--- a/arch/x86/include/asm/e820.h
9921+++ b/arch/x86/include/asm/e820.h
9922@@ -69,7 +69,7 @@ struct e820map {
9923 #define ISA_START_ADDRESS 0xa0000
9924 #define ISA_END_ADDRESS 0x100000
9925
9926-#define BIOS_BEGIN 0x000a0000
9927+#define BIOS_BEGIN 0x000c0000
9928 #define BIOS_END 0x00100000
9929
9930 #define BIOS_ROM_BASE 0xffe00000
9931diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
9932index 5f962df..7289f09 100644
9933--- a/arch/x86/include/asm/elf.h
9934+++ b/arch/x86/include/asm/elf.h
9935@@ -238,7 +238,25 @@ extern int force_personality32;
9936 the loader. We need to make sure that it is out of the way of the program
9937 that it will "exec", and that there is sufficient room for the brk. */
9938
9939+#ifdef CONFIG_PAX_SEGMEXEC
9940+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
9941+#else
9942 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
9943+#endif
9944+
9945+#ifdef CONFIG_PAX_ASLR
9946+#ifdef CONFIG_X86_32
9947+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
9948+
9949+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9950+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9951+#else
9952+#define PAX_ELF_ET_DYN_BASE 0x400000UL
9953+
9954+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9955+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9956+#endif
9957+#endif
9958
9959 /* This yields a mask that user programs can use to figure out what
9960 instruction set this CPU supports. This could be done in user space,
9961@@ -291,9 +309,7 @@ do { \
9962
9963 #define ARCH_DLINFO \
9964 do { \
9965- if (vdso_enabled) \
9966- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
9967- (unsigned long)current->mm->context.vdso); \
9968+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
9969 } while (0)
9970
9971 #define AT_SYSINFO 32
9972@@ -304,7 +320,7 @@ do { \
9973
9974 #endif /* !CONFIG_X86_32 */
9975
9976-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
9977+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
9978
9979 #define VDSO_ENTRY \
9980 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
9981@@ -318,9 +334,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
9982 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
9983 #define compat_arch_setup_additional_pages syscall32_setup_pages
9984
9985-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9986-#define arch_randomize_brk arch_randomize_brk
9987-
9988 /*
9989 * True on X86_32 or when emulating IA32 on X86_64
9990 */
9991diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
9992index cc70c1c..d96d011 100644
9993--- a/arch/x86/include/asm/emergency-restart.h
9994+++ b/arch/x86/include/asm/emergency-restart.h
9995@@ -15,6 +15,6 @@ enum reboot_type {
9996
9997 extern enum reboot_type reboot_type;
9998
9999-extern void machine_emergency_restart(void);
10000+extern void machine_emergency_restart(void) __noreturn;
10001
10002 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10003diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10004index d09bb03..4ea4194 100644
10005--- a/arch/x86/include/asm/futex.h
10006+++ b/arch/x86/include/asm/futex.h
10007@@ -12,16 +12,18 @@
10008 #include <asm/system.h>
10009
10010 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10011+ typecheck(u32 __user *, uaddr); \
10012 asm volatile("1:\t" insn "\n" \
10013 "2:\t.section .fixup,\"ax\"\n" \
10014 "3:\tmov\t%3, %1\n" \
10015 "\tjmp\t2b\n" \
10016 "\t.previous\n" \
10017 _ASM_EXTABLE(1b, 3b) \
10018- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10019+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10020 : "i" (-EFAULT), "0" (oparg), "1" (0))
10021
10022 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10023+ typecheck(u32 __user *, uaddr); \
10024 asm volatile("1:\tmovl %2, %0\n" \
10025 "\tmovl\t%0, %3\n" \
10026 "\t" insn "\n" \
10027@@ -34,7 +36,7 @@
10028 _ASM_EXTABLE(1b, 4b) \
10029 _ASM_EXTABLE(2b, 4b) \
10030 : "=&a" (oldval), "=&r" (ret), \
10031- "+m" (*uaddr), "=&r" (tem) \
10032+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10033 : "r" (oparg), "i" (-EFAULT), "1" (0))
10034
10035 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10036@@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10037
10038 switch (op) {
10039 case FUTEX_OP_SET:
10040- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10041+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10042 break;
10043 case FUTEX_OP_ADD:
10044- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10045+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10046 uaddr, oparg);
10047 break;
10048 case FUTEX_OP_OR:
10049@@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10050 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10051 return -EFAULT;
10052
10053- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10054+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10055 "2:\t.section .fixup, \"ax\"\n"
10056 "3:\tmov %3, %0\n"
10057 "\tjmp 2b\n"
10058 "\t.previous\n"
10059 _ASM_EXTABLE(1b, 3b)
10060- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10061+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10062 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10063 : "memory"
10064 );
10065diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10066index eb92a6e..b98b2f4 100644
10067--- a/arch/x86/include/asm/hw_irq.h
10068+++ b/arch/x86/include/asm/hw_irq.h
10069@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10070 extern void enable_IO_APIC(void);
10071
10072 /* Statistics */
10073-extern atomic_t irq_err_count;
10074-extern atomic_t irq_mis_count;
10075+extern atomic_unchecked_t irq_err_count;
10076+extern atomic_unchecked_t irq_mis_count;
10077
10078 /* EISA */
10079 extern void eisa_set_level_irq(unsigned int irq);
10080diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
10081index 2479049..3fb9795 100644
10082--- a/arch/x86/include/asm/i387.h
10083+++ b/arch/x86/include/asm/i387.h
10084@@ -93,6 +93,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10085 {
10086 int err;
10087
10088+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10089+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10090+ fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10091+#endif
10092+
10093 /* See comment in fxsave() below. */
10094 #ifdef CONFIG_AS_FXSAVEQ
10095 asm volatile("1: fxrstorq %[fx]\n\t"
10096@@ -122,6 +127,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10097 {
10098 int err;
10099
10100+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10101+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10102+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10103+#endif
10104+
10105 /*
10106 * Clear the bytes not touched by the fxsave and reserved
10107 * for the SW usage.
10108@@ -278,7 +288,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10109 "emms\n\t" /* clear stack tags */
10110 "fildl %P[addr]", /* set F?P to defined value */
10111 X86_FEATURE_FXSAVE_LEAK,
10112- [addr] "m" (tsk->thread.fpu.has_fpu));
10113+ [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10114
10115 return fpu_restore_checking(&tsk->thread.fpu);
10116 }
10117@@ -445,7 +455,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
10118 static inline bool interrupted_user_mode(void)
10119 {
10120 struct pt_regs *regs = get_irq_regs();
10121- return regs && user_mode_vm(regs);
10122+ return regs && user_mode(regs);
10123 }
10124
10125 /*
10126diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10127index d8e8eef..99f81ae 100644
10128--- a/arch/x86/include/asm/io.h
10129+++ b/arch/x86/include/asm/io.h
10130@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10131
10132 #include <linux/vmalloc.h>
10133
10134+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10135+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10136+{
10137+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10138+}
10139+
10140+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10141+{
10142+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10143+}
10144+
10145 /*
10146 * Convert a virtual cached pointer to an uncached pointer
10147 */
10148diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10149index bba3cf8..06bc8da 100644
10150--- a/arch/x86/include/asm/irqflags.h
10151+++ b/arch/x86/include/asm/irqflags.h
10152@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10153 sti; \
10154 sysexit
10155
10156+#define GET_CR0_INTO_RDI mov %cr0, %rdi
10157+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10158+#define GET_CR3_INTO_RDI mov %cr3, %rdi
10159+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10160+
10161 #else
10162 #define INTERRUPT_RETURN iret
10163 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10164diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10165index 5478825..839e88c 100644
10166--- a/arch/x86/include/asm/kprobes.h
10167+++ b/arch/x86/include/asm/kprobes.h
10168@@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10169 #define RELATIVEJUMP_SIZE 5
10170 #define RELATIVECALL_OPCODE 0xe8
10171 #define RELATIVE_ADDR_SIZE 4
10172-#define MAX_STACK_SIZE 64
10173-#define MIN_STACK_SIZE(ADDR) \
10174- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10175- THREAD_SIZE - (unsigned long)(ADDR))) \
10176- ? (MAX_STACK_SIZE) \
10177- : (((unsigned long)current_thread_info()) + \
10178- THREAD_SIZE - (unsigned long)(ADDR)))
10179+#define MAX_STACK_SIZE 64UL
10180+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10181
10182 #define flush_insn_slot(p) do { } while (0)
10183
10184diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10185index 52d6640..a013b87 100644
10186--- a/arch/x86/include/asm/kvm_host.h
10187+++ b/arch/x86/include/asm/kvm_host.h
10188@@ -663,7 +663,7 @@ struct kvm_x86_ops {
10189 int (*check_intercept)(struct kvm_vcpu *vcpu,
10190 struct x86_instruction_info *info,
10191 enum x86_intercept_stage stage);
10192-};
10193+} __do_const;
10194
10195 struct kvm_arch_async_pf {
10196 u32 token;
10197diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10198index 9cdae5d..300d20f 100644
10199--- a/arch/x86/include/asm/local.h
10200+++ b/arch/x86/include/asm/local.h
10201@@ -18,26 +18,58 @@ typedef struct {
10202
10203 static inline void local_inc(local_t *l)
10204 {
10205- asm volatile(_ASM_INC "%0"
10206+ asm volatile(_ASM_INC "%0\n"
10207+
10208+#ifdef CONFIG_PAX_REFCOUNT
10209+ "jno 0f\n"
10210+ _ASM_DEC "%0\n"
10211+ "int $4\n0:\n"
10212+ _ASM_EXTABLE(0b, 0b)
10213+#endif
10214+
10215 : "+m" (l->a.counter));
10216 }
10217
10218 static inline void local_dec(local_t *l)
10219 {
10220- asm volatile(_ASM_DEC "%0"
10221+ asm volatile(_ASM_DEC "%0\n"
10222+
10223+#ifdef CONFIG_PAX_REFCOUNT
10224+ "jno 0f\n"
10225+ _ASM_INC "%0\n"
10226+ "int $4\n0:\n"
10227+ _ASM_EXTABLE(0b, 0b)
10228+#endif
10229+
10230 : "+m" (l->a.counter));
10231 }
10232
10233 static inline void local_add(long i, local_t *l)
10234 {
10235- asm volatile(_ASM_ADD "%1,%0"
10236+ asm volatile(_ASM_ADD "%1,%0\n"
10237+
10238+#ifdef CONFIG_PAX_REFCOUNT
10239+ "jno 0f\n"
10240+ _ASM_SUB "%1,%0\n"
10241+ "int $4\n0:\n"
10242+ _ASM_EXTABLE(0b, 0b)
10243+#endif
10244+
10245 : "+m" (l->a.counter)
10246 : "ir" (i));
10247 }
10248
10249 static inline void local_sub(long i, local_t *l)
10250 {
10251- asm volatile(_ASM_SUB "%1,%0"
10252+ asm volatile(_ASM_SUB "%1,%0\n"
10253+
10254+#ifdef CONFIG_PAX_REFCOUNT
10255+ "jno 0f\n"
10256+ _ASM_ADD "%1,%0\n"
10257+ "int $4\n0:\n"
10258+ _ASM_EXTABLE(0b, 0b)
10259+#endif
10260+
10261 : "+m" (l->a.counter)
10262 : "ir" (i));
10263 }
10264@@ -55,7 +87,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10265 {
10266 unsigned char c;
10267
10268- asm volatile(_ASM_SUB "%2,%0; sete %1"
10269+ asm volatile(_ASM_SUB "%2,%0\n"
10270+
10271+#ifdef CONFIG_PAX_REFCOUNT
10272+ "jno 0f\n"
10273+ _ASM_ADD "%2,%0\n"
10274+ "int $4\n0:\n"
10275+ _ASM_EXTABLE(0b, 0b)
10276+#endif
10277+
10278+ "sete %1\n"
10279 : "+m" (l->a.counter), "=qm" (c)
10280 : "ir" (i) : "memory");
10281 return c;
10282@@ -73,7 +114,16 @@ static inline int local_dec_and_test(local_t *l)
10283 {
10284 unsigned char c;
10285
10286- asm volatile(_ASM_DEC "%0; sete %1"
10287+ asm volatile(_ASM_DEC "%0\n"
10288+
10289+#ifdef CONFIG_PAX_REFCOUNT
10290+ "jno 0f\n"
10291+ _ASM_INC "%0\n"
10292+ "int $4\n0:\n"
10293+ _ASM_EXTABLE(0b, 0b)
10294+#endif
10295+
10296+ "sete %1\n"
10297 : "+m" (l->a.counter), "=qm" (c)
10298 : : "memory");
10299 return c != 0;
10300@@ -91,7 +141,16 @@ static inline int local_inc_and_test(local_t *l)
10301 {
10302 unsigned char c;
10303
10304- asm volatile(_ASM_INC "%0; sete %1"
10305+ asm volatile(_ASM_INC "%0\n"
10306+
10307+#ifdef CONFIG_PAX_REFCOUNT
10308+ "jno 0f\n"
10309+ _ASM_DEC "%0\n"
10310+ "int $4\n0:\n"
10311+ _ASM_EXTABLE(0b, 0b)
10312+#endif
10313+
10314+ "sete %1\n"
10315 : "+m" (l->a.counter), "=qm" (c)
10316 : : "memory");
10317 return c != 0;
10318@@ -110,7 +169,16 @@ static inline int local_add_negative(long i, local_t *l)
10319 {
10320 unsigned char c;
10321
10322- asm volatile(_ASM_ADD "%2,%0; sets %1"
10323+ asm volatile(_ASM_ADD "%2,%0\n"
10324+
10325+#ifdef CONFIG_PAX_REFCOUNT
10326+ "jno 0f\n"
10327+ _ASM_SUB "%2,%0\n"
10328+ "int $4\n0:\n"
10329+ _ASM_EXTABLE(0b, 0b)
10330+#endif
10331+
10332+ "sets %1\n"
10333 : "+m" (l->a.counter), "=qm" (c)
10334 : "ir" (i) : "memory");
10335 return c;
10336@@ -133,7 +201,15 @@ static inline long local_add_return(long i, local_t *l)
10337 #endif
10338 /* Modern 486+ processor */
10339 __i = i;
10340- asm volatile(_ASM_XADD "%0, %1;"
10341+ asm volatile(_ASM_XADD "%0, %1\n"
10342+
10343+#ifdef CONFIG_PAX_REFCOUNT
10344+ "jno 0f\n"
10345+ _ASM_MOV "%0,%1\n"
10346+ "int $4\n0:\n"
10347+ _ASM_EXTABLE(0b, 0b)
10348+#endif
10349+
10350 : "+r" (i), "+m" (l->a.counter)
10351 : : "memory");
10352 return i + __i;
10353diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10354index 593e51d..fa69c9a 100644
10355--- a/arch/x86/include/asm/mman.h
10356+++ b/arch/x86/include/asm/mman.h
10357@@ -5,4 +5,14 @@
10358
10359 #include <asm-generic/mman.h>
10360
10361+#ifdef __KERNEL__
10362+#ifndef __ASSEMBLY__
10363+#ifdef CONFIG_X86_32
10364+#define arch_mmap_check i386_mmap_check
10365+int i386_mmap_check(unsigned long addr, unsigned long len,
10366+ unsigned long flags);
10367+#endif
10368+#endif
10369+#endif
10370+
10371 #endif /* _ASM_X86_MMAN_H */
10372diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10373index 5f55e69..e20bfb1 100644
10374--- a/arch/x86/include/asm/mmu.h
10375+++ b/arch/x86/include/asm/mmu.h
10376@@ -9,7 +9,7 @@
10377 * we put the segment information here.
10378 */
10379 typedef struct {
10380- void *ldt;
10381+ struct desc_struct *ldt;
10382 int size;
10383
10384 #ifdef CONFIG_X86_64
10385@@ -18,7 +18,19 @@ typedef struct {
10386 #endif
10387
10388 struct mutex lock;
10389- void *vdso;
10390+ unsigned long vdso;
10391+
10392+#ifdef CONFIG_X86_32
10393+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10394+ unsigned long user_cs_base;
10395+ unsigned long user_cs_limit;
10396+
10397+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10398+ cpumask_t cpu_user_cs_mask;
10399+#endif
10400+
10401+#endif
10402+#endif
10403 } mm_context_t;
10404
10405 #ifdef CONFIG_SMP
10406diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10407index 6902152..399f3a2 100644
10408--- a/arch/x86/include/asm/mmu_context.h
10409+++ b/arch/x86/include/asm/mmu_context.h
10410@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10411
10412 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10413 {
10414+
10415+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10416+ unsigned int i;
10417+ pgd_t *pgd;
10418+
10419+ pax_open_kernel();
10420+ pgd = get_cpu_pgd(smp_processor_id());
10421+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10422+ set_pgd_batched(pgd+i, native_make_pgd(0));
10423+ pax_close_kernel();
10424+#endif
10425+
10426 #ifdef CONFIG_SMP
10427 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10428 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10429@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10430 struct task_struct *tsk)
10431 {
10432 unsigned cpu = smp_processor_id();
10433+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10434+ int tlbstate = TLBSTATE_OK;
10435+#endif
10436
10437 if (likely(prev != next)) {
10438 #ifdef CONFIG_SMP
10439+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10440+ tlbstate = percpu_read(cpu_tlbstate.state);
10441+#endif
10442 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10443 percpu_write(cpu_tlbstate.active_mm, next);
10444 #endif
10445 cpumask_set_cpu(cpu, mm_cpumask(next));
10446
10447 /* Re-load page tables */
10448+#ifdef CONFIG_PAX_PER_CPU_PGD
10449+ pax_open_kernel();
10450+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10451+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10452+ pax_close_kernel();
10453+ load_cr3(get_cpu_pgd(cpu));
10454+#else
10455 load_cr3(next->pgd);
10456+#endif
10457
10458 /* stop flush ipis for the previous mm */
10459 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10460@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10461 */
10462 if (unlikely(prev->context.ldt != next->context.ldt))
10463 load_LDT_nolock(&next->context);
10464- }
10465+
10466+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10467+ if (!(__supported_pte_mask & _PAGE_NX)) {
10468+ smp_mb__before_clear_bit();
10469+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10470+ smp_mb__after_clear_bit();
10471+ cpu_set(cpu, next->context.cpu_user_cs_mask);
10472+ }
10473+#endif
10474+
10475+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10476+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10477+ prev->context.user_cs_limit != next->context.user_cs_limit))
10478+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10479 #ifdef CONFIG_SMP
10480+ else if (unlikely(tlbstate != TLBSTATE_OK))
10481+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10482+#endif
10483+#endif
10484+
10485+ }
10486 else {
10487+
10488+#ifdef CONFIG_PAX_PER_CPU_PGD
10489+ pax_open_kernel();
10490+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10491+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10492+ pax_close_kernel();
10493+ load_cr3(get_cpu_pgd(cpu));
10494+#endif
10495+
10496+#ifdef CONFIG_SMP
10497 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10498 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10499
10500@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10501 * tlb flush IPI delivery. We must reload CR3
10502 * to make sure to use no freed page tables.
10503 */
10504+
10505+#ifndef CONFIG_PAX_PER_CPU_PGD
10506 load_cr3(next->pgd);
10507+#endif
10508+
10509 load_LDT_nolock(&next->context);
10510+
10511+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10512+ if (!(__supported_pte_mask & _PAGE_NX))
10513+ cpu_set(cpu, next->context.cpu_user_cs_mask);
10514+#endif
10515+
10516+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10517+#ifdef CONFIG_PAX_PAGEEXEC
10518+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10519+#endif
10520+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10521+#endif
10522+
10523 }
10524+#endif
10525 }
10526-#endif
10527 }
10528
10529 #define activate_mm(prev, next) \
10530diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
10531index 9eae775..c914fea 100644
10532--- a/arch/x86/include/asm/module.h
10533+++ b/arch/x86/include/asm/module.h
10534@@ -5,6 +5,7 @@
10535
10536 #ifdef CONFIG_X86_64
10537 /* X86_64 does not define MODULE_PROC_FAMILY */
10538+#define MODULE_PROC_FAMILY ""
10539 #elif defined CONFIG_M386
10540 #define MODULE_PROC_FAMILY "386 "
10541 #elif defined CONFIG_M486
10542@@ -59,8 +60,20 @@
10543 #error unknown processor family
10544 #endif
10545
10546-#ifdef CONFIG_X86_32
10547-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
10548+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10549+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
10550+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
10551+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
10552+#else
10553+#define MODULE_PAX_KERNEXEC ""
10554 #endif
10555
10556+#ifdef CONFIG_PAX_MEMORY_UDEREF
10557+#define MODULE_PAX_UDEREF "UDEREF "
10558+#else
10559+#define MODULE_PAX_UDEREF ""
10560+#endif
10561+
10562+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
10563+
10564 #endif /* _ASM_X86_MODULE_H */
10565diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
10566index 7639dbf..e08a58c 100644
10567--- a/arch/x86/include/asm/page_64_types.h
10568+++ b/arch/x86/include/asm/page_64_types.h
10569@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
10570
10571 /* duplicated to the one in bootmem.h */
10572 extern unsigned long max_pfn;
10573-extern unsigned long phys_base;
10574+extern const unsigned long phys_base;
10575
10576 extern unsigned long __phys_addr(unsigned long);
10577 #define __phys_reloc_hide(x) (x)
10578diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
10579index a7d2db9..edb023e 100644
10580--- a/arch/x86/include/asm/paravirt.h
10581+++ b/arch/x86/include/asm/paravirt.h
10582@@ -667,6 +667,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
10583 val);
10584 }
10585
10586+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
10587+{
10588+ pgdval_t val = native_pgd_val(pgd);
10589+
10590+ if (sizeof(pgdval_t) > sizeof(long))
10591+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
10592+ val, (u64)val >> 32);
10593+ else
10594+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
10595+ val);
10596+}
10597+
10598 static inline void pgd_clear(pgd_t *pgdp)
10599 {
10600 set_pgd(pgdp, __pgd(0));
10601@@ -748,6 +760,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
10602 pv_mmu_ops.set_fixmap(idx, phys, flags);
10603 }
10604
10605+#ifdef CONFIG_PAX_KERNEXEC
10606+static inline unsigned long pax_open_kernel(void)
10607+{
10608+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
10609+}
10610+
10611+static inline unsigned long pax_close_kernel(void)
10612+{
10613+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
10614+}
10615+#else
10616+static inline unsigned long pax_open_kernel(void) { return 0; }
10617+static inline unsigned long pax_close_kernel(void) { return 0; }
10618+#endif
10619+
10620 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
10621
10622 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
10623@@ -964,7 +991,7 @@ extern void default_banner(void);
10624
10625 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
10626 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
10627-#define PARA_INDIRECT(addr) *%cs:addr
10628+#define PARA_INDIRECT(addr) *%ss:addr
10629 #endif
10630
10631 #define INTERRUPT_RETURN \
10632@@ -1041,6 +1068,21 @@ extern void default_banner(void);
10633 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
10634 CLBR_NONE, \
10635 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
10636+
10637+#define GET_CR0_INTO_RDI \
10638+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
10639+ mov %rax,%rdi
10640+
10641+#define SET_RDI_INTO_CR0 \
10642+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
10643+
10644+#define GET_CR3_INTO_RDI \
10645+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
10646+ mov %rax,%rdi
10647+
10648+#define SET_RDI_INTO_CR3 \
10649+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
10650+
10651 #endif /* CONFIG_X86_32 */
10652
10653 #endif /* __ASSEMBLY__ */
10654diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
10655index 8e8b9a4..f07d725 100644
10656--- a/arch/x86/include/asm/paravirt_types.h
10657+++ b/arch/x86/include/asm/paravirt_types.h
10658@@ -84,20 +84,20 @@ struct pv_init_ops {
10659 */
10660 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
10661 unsigned long addr, unsigned len);
10662-};
10663+} __no_const;
10664
10665
10666 struct pv_lazy_ops {
10667 /* Set deferred update mode, used for batching operations. */
10668 void (*enter)(void);
10669 void (*leave)(void);
10670-};
10671+} __no_const;
10672
10673 struct pv_time_ops {
10674 unsigned long long (*sched_clock)(void);
10675 unsigned long long (*steal_clock)(int cpu);
10676 unsigned long (*get_tsc_khz)(void);
10677-};
10678+} __no_const;
10679
10680 struct pv_cpu_ops {
10681 /* hooks for various privileged instructions */
10682@@ -193,7 +193,7 @@ struct pv_cpu_ops {
10683
10684 void (*start_context_switch)(struct task_struct *prev);
10685 void (*end_context_switch)(struct task_struct *next);
10686-};
10687+} __no_const;
10688
10689 struct pv_irq_ops {
10690 /*
10691@@ -224,7 +224,7 @@ struct pv_apic_ops {
10692 unsigned long start_eip,
10693 unsigned long start_esp);
10694 #endif
10695-};
10696+} __no_const;
10697
10698 struct pv_mmu_ops {
10699 unsigned long (*read_cr2)(void);
10700@@ -313,6 +313,7 @@ struct pv_mmu_ops {
10701 struct paravirt_callee_save make_pud;
10702
10703 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
10704+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
10705 #endif /* PAGETABLE_LEVELS == 4 */
10706 #endif /* PAGETABLE_LEVELS >= 3 */
10707
10708@@ -324,6 +325,12 @@ struct pv_mmu_ops {
10709 an mfn. We can tell which is which from the index. */
10710 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
10711 phys_addr_t phys, pgprot_t flags);
10712+
10713+#ifdef CONFIG_PAX_KERNEXEC
10714+ unsigned long (*pax_open_kernel)(void);
10715+ unsigned long (*pax_close_kernel)(void);
10716+#endif
10717+
10718 };
10719
10720 struct arch_spinlock;
10721@@ -334,7 +341,7 @@ struct pv_lock_ops {
10722 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
10723 int (*spin_trylock)(struct arch_spinlock *lock);
10724 void (*spin_unlock)(struct arch_spinlock *lock);
10725-};
10726+} __no_const;
10727
10728 /* This contains all the paravirt structures: we get a convenient
10729 * number for each function using the offset which we use to indicate
10730diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
10731index b4389a4..b7ff22c 100644
10732--- a/arch/x86/include/asm/pgalloc.h
10733+++ b/arch/x86/include/asm/pgalloc.h
10734@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
10735 pmd_t *pmd, pte_t *pte)
10736 {
10737 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10738+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
10739+}
10740+
10741+static inline void pmd_populate_user(struct mm_struct *mm,
10742+ pmd_t *pmd, pte_t *pte)
10743+{
10744+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10745 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
10746 }
10747
10748diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
10749index 98391db..8f6984e 100644
10750--- a/arch/x86/include/asm/pgtable-2level.h
10751+++ b/arch/x86/include/asm/pgtable-2level.h
10752@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
10753
10754 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10755 {
10756+ pax_open_kernel();
10757 *pmdp = pmd;
10758+ pax_close_kernel();
10759 }
10760
10761 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10762diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
10763index effff47..f9e4035 100644
10764--- a/arch/x86/include/asm/pgtable-3level.h
10765+++ b/arch/x86/include/asm/pgtable-3level.h
10766@@ -38,12 +38,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10767
10768 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10769 {
10770+ pax_open_kernel();
10771 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
10772+ pax_close_kernel();
10773 }
10774
10775 static inline void native_set_pud(pud_t *pudp, pud_t pud)
10776 {
10777+ pax_open_kernel();
10778 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
10779+ pax_close_kernel();
10780 }
10781
10782 /*
10783diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
10784index 49afb3f..ed14d07 100644
10785--- a/arch/x86/include/asm/pgtable.h
10786+++ b/arch/x86/include/asm/pgtable.h
10787@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
10788
10789 #ifndef __PAGETABLE_PUD_FOLDED
10790 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
10791+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
10792 #define pgd_clear(pgd) native_pgd_clear(pgd)
10793 #endif
10794
10795@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
10796
10797 #define arch_end_context_switch(prev) do {} while(0)
10798
10799+#define pax_open_kernel() native_pax_open_kernel()
10800+#define pax_close_kernel() native_pax_close_kernel()
10801 #endif /* CONFIG_PARAVIRT */
10802
10803+#define __HAVE_ARCH_PAX_OPEN_KERNEL
10804+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
10805+
10806+#ifdef CONFIG_PAX_KERNEXEC
10807+static inline unsigned long native_pax_open_kernel(void)
10808+{
10809+ unsigned long cr0;
10810+
10811+ preempt_disable();
10812+ barrier();
10813+ cr0 = read_cr0() ^ X86_CR0_WP;
10814+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
10815+ write_cr0(cr0);
10816+ return cr0 ^ X86_CR0_WP;
10817+}
10818+
10819+static inline unsigned long native_pax_close_kernel(void)
10820+{
10821+ unsigned long cr0;
10822+
10823+ cr0 = read_cr0() ^ X86_CR0_WP;
10824+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
10825+ write_cr0(cr0);
10826+ barrier();
10827+ preempt_enable_no_resched();
10828+ return cr0 ^ X86_CR0_WP;
10829+}
10830+#else
10831+static inline unsigned long native_pax_open_kernel(void) { return 0; }
10832+static inline unsigned long native_pax_close_kernel(void) { return 0; }
10833+#endif
10834+
10835 /*
10836 * The following only work if pte_present() is true.
10837 * Undefined behaviour if not..
10838 */
10839+static inline int pte_user(pte_t pte)
10840+{
10841+ return pte_val(pte) & _PAGE_USER;
10842+}
10843+
10844 static inline int pte_dirty(pte_t pte)
10845 {
10846 return pte_flags(pte) & _PAGE_DIRTY;
10847@@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
10848 return pte_clear_flags(pte, _PAGE_RW);
10849 }
10850
10851+static inline pte_t pte_mkread(pte_t pte)
10852+{
10853+ return __pte(pte_val(pte) | _PAGE_USER);
10854+}
10855+
10856 static inline pte_t pte_mkexec(pte_t pte)
10857 {
10858- return pte_clear_flags(pte, _PAGE_NX);
10859+#ifdef CONFIG_X86_PAE
10860+ if (__supported_pte_mask & _PAGE_NX)
10861+ return pte_clear_flags(pte, _PAGE_NX);
10862+ else
10863+#endif
10864+ return pte_set_flags(pte, _PAGE_USER);
10865+}
10866+
10867+static inline pte_t pte_exprotect(pte_t pte)
10868+{
10869+#ifdef CONFIG_X86_PAE
10870+ if (__supported_pte_mask & _PAGE_NX)
10871+ return pte_set_flags(pte, _PAGE_NX);
10872+ else
10873+#endif
10874+ return pte_clear_flags(pte, _PAGE_USER);
10875 }
10876
10877 static inline pte_t pte_mkdirty(pte_t pte)
10878@@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
10879 #endif
10880
10881 #ifndef __ASSEMBLY__
10882+
10883+#ifdef CONFIG_PAX_PER_CPU_PGD
10884+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
10885+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
10886+{
10887+ return cpu_pgd[cpu];
10888+}
10889+#endif
10890+
10891 #include <linux/mm_types.h>
10892
10893 static inline int pte_none(pte_t pte)
10894@@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
10895
10896 static inline int pgd_bad(pgd_t pgd)
10897 {
10898- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
10899+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
10900 }
10901
10902 static inline int pgd_none(pgd_t pgd)
10903@@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
10904 * pgd_offset() returns a (pgd_t *)
10905 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
10906 */
10907-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
10908+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
10909+
10910+#ifdef CONFIG_PAX_PER_CPU_PGD
10911+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
10912+#endif
10913+
10914 /*
10915 * a shortcut which implies the use of the kernel's pgd, instead
10916 * of a process's
10917@@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
10918 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
10919 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
10920
10921+#ifdef CONFIG_X86_32
10922+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
10923+#else
10924+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
10925+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
10926+
10927+#ifdef CONFIG_PAX_MEMORY_UDEREF
10928+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
10929+#else
10930+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
10931+#endif
10932+
10933+#endif
10934+
10935 #ifndef __ASSEMBLY__
10936
10937 extern int direct_gbpages;
10938@@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
10939 * dst and src can be on the same page, but the range must not overlap,
10940 * and must not cross a page boundary.
10941 */
10942-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
10943+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
10944 {
10945- memcpy(dst, src, count * sizeof(pgd_t));
10946+ pax_open_kernel();
10947+ while (count--)
10948+ *dst++ = *src++;
10949+ pax_close_kernel();
10950 }
10951
10952+#ifdef CONFIG_PAX_PER_CPU_PGD
10953+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
10954+#endif
10955+
10956+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10957+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
10958+#else
10959+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
10960+#endif
10961
10962 #include <asm-generic/pgtable.h>
10963 #endif /* __ASSEMBLY__ */
10964diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
10965index 0c92113..34a77c6 100644
10966--- a/arch/x86/include/asm/pgtable_32.h
10967+++ b/arch/x86/include/asm/pgtable_32.h
10968@@ -25,9 +25,6 @@
10969 struct mm_struct;
10970 struct vm_area_struct;
10971
10972-extern pgd_t swapper_pg_dir[1024];
10973-extern pgd_t initial_page_table[1024];
10974-
10975 static inline void pgtable_cache_init(void) { }
10976 static inline void check_pgt_cache(void) { }
10977 void paging_init(void);
10978@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
10979 # include <asm/pgtable-2level.h>
10980 #endif
10981
10982+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
10983+extern pgd_t initial_page_table[PTRS_PER_PGD];
10984+#ifdef CONFIG_X86_PAE
10985+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
10986+#endif
10987+
10988 #if defined(CONFIG_HIGHPTE)
10989 #define pte_offset_map(dir, address) \
10990 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
10991@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
10992 /* Clear a kernel PTE and flush it from the TLB */
10993 #define kpte_clear_flush(ptep, vaddr) \
10994 do { \
10995+ pax_open_kernel(); \
10996 pte_clear(&init_mm, (vaddr), (ptep)); \
10997+ pax_close_kernel(); \
10998 __flush_tlb_one((vaddr)); \
10999 } while (0)
11000
11001@@ -74,6 +79,9 @@ do { \
11002
11003 #endif /* !__ASSEMBLY__ */
11004
11005+#define HAVE_ARCH_UNMAPPED_AREA
11006+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11007+
11008 /*
11009 * kern_addr_valid() is (1) for FLATMEM and (0) for
11010 * SPARSEMEM and DISCONTIGMEM
11011diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11012index ed5903b..c7fe163 100644
11013--- a/arch/x86/include/asm/pgtable_32_types.h
11014+++ b/arch/x86/include/asm/pgtable_32_types.h
11015@@ -8,7 +8,7 @@
11016 */
11017 #ifdef CONFIG_X86_PAE
11018 # include <asm/pgtable-3level_types.h>
11019-# define PMD_SIZE (1UL << PMD_SHIFT)
11020+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11021 # define PMD_MASK (~(PMD_SIZE - 1))
11022 #else
11023 # include <asm/pgtable-2level_types.h>
11024@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11025 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11026 #endif
11027
11028+#ifdef CONFIG_PAX_KERNEXEC
11029+#ifndef __ASSEMBLY__
11030+extern unsigned char MODULES_EXEC_VADDR[];
11031+extern unsigned char MODULES_EXEC_END[];
11032+#endif
11033+#include <asm/boot.h>
11034+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11035+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11036+#else
11037+#define ktla_ktva(addr) (addr)
11038+#define ktva_ktla(addr) (addr)
11039+#endif
11040+
11041 #define MODULES_VADDR VMALLOC_START
11042 #define MODULES_END VMALLOC_END
11043 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11044diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11045index 975f709..107976d 100644
11046--- a/arch/x86/include/asm/pgtable_64.h
11047+++ b/arch/x86/include/asm/pgtable_64.h
11048@@ -16,10 +16,14 @@
11049
11050 extern pud_t level3_kernel_pgt[512];
11051 extern pud_t level3_ident_pgt[512];
11052+extern pud_t level3_vmalloc_start_pgt[512];
11053+extern pud_t level3_vmalloc_end_pgt[512];
11054+extern pud_t level3_vmemmap_pgt[512];
11055+extern pud_t level2_vmemmap_pgt[512];
11056 extern pmd_t level2_kernel_pgt[512];
11057 extern pmd_t level2_fixmap_pgt[512];
11058-extern pmd_t level2_ident_pgt[512];
11059-extern pgd_t init_level4_pgt[];
11060+extern pmd_t level2_ident_pgt[512*2];
11061+extern pgd_t init_level4_pgt[512];
11062
11063 #define swapper_pg_dir init_level4_pgt
11064
11065@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11066
11067 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11068 {
11069+ pax_open_kernel();
11070 *pmdp = pmd;
11071+ pax_close_kernel();
11072 }
11073
11074 static inline void native_pmd_clear(pmd_t *pmd)
11075@@ -107,6 +113,13 @@ static inline void native_pud_clear(pud_t *pud)
11076
11077 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11078 {
11079+ pax_open_kernel();
11080+ *pgdp = pgd;
11081+ pax_close_kernel();
11082+}
11083+
11084+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11085+{
11086 *pgdp = pgd;
11087 }
11088
11089diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11090index 766ea16..5b96cb3 100644
11091--- a/arch/x86/include/asm/pgtable_64_types.h
11092+++ b/arch/x86/include/asm/pgtable_64_types.h
11093@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11094 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11095 #define MODULES_END _AC(0xffffffffff000000, UL)
11096 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11097+#define MODULES_EXEC_VADDR MODULES_VADDR
11098+#define MODULES_EXEC_END MODULES_END
11099+
11100+#define ktla_ktva(addr) (addr)
11101+#define ktva_ktla(addr) (addr)
11102
11103 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11104diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11105index 013286a..8b42f4f 100644
11106--- a/arch/x86/include/asm/pgtable_types.h
11107+++ b/arch/x86/include/asm/pgtable_types.h
11108@@ -16,13 +16,12 @@
11109 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11110 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11111 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11112-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11113+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11114 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11115 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11116 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11117-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11118-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11119-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11120+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11121+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11122 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11123
11124 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11125@@ -40,7 +39,6 @@
11126 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11127 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11128 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11129-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11130 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11131 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11132 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11133@@ -57,8 +55,10 @@
11134
11135 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11136 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11137-#else
11138+#elif defined(CONFIG_KMEMCHECK)
11139 #define _PAGE_NX (_AT(pteval_t, 0))
11140+#else
11141+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11142 #endif
11143
11144 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11145@@ -96,6 +96,9 @@
11146 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11147 _PAGE_ACCESSED)
11148
11149+#define PAGE_READONLY_NOEXEC PAGE_READONLY
11150+#define PAGE_SHARED_NOEXEC PAGE_SHARED
11151+
11152 #define __PAGE_KERNEL_EXEC \
11153 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11154 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11155@@ -106,7 +109,7 @@
11156 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11157 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11158 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11159-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11160+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11161 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11162 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11163 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11164@@ -168,8 +171,8 @@
11165 * bits are combined, this will alow user to access the high address mapped
11166 * VDSO in the presence of CONFIG_COMPAT_VDSO
11167 */
11168-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11169-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11170+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11171+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11172 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11173 #endif
11174
11175@@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11176 {
11177 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11178 }
11179+#endif
11180
11181+#if PAGETABLE_LEVELS == 3
11182+#include <asm-generic/pgtable-nopud.h>
11183+#endif
11184+
11185+#if PAGETABLE_LEVELS == 2
11186+#include <asm-generic/pgtable-nopmd.h>
11187+#endif
11188+
11189+#ifndef __ASSEMBLY__
11190 #if PAGETABLE_LEVELS > 3
11191 typedef struct { pudval_t pud; } pud_t;
11192
11193@@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11194 return pud.pud;
11195 }
11196 #else
11197-#include <asm-generic/pgtable-nopud.h>
11198-
11199 static inline pudval_t native_pud_val(pud_t pud)
11200 {
11201 return native_pgd_val(pud.pgd);
11202@@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11203 return pmd.pmd;
11204 }
11205 #else
11206-#include <asm-generic/pgtable-nopmd.h>
11207-
11208 static inline pmdval_t native_pmd_val(pmd_t pmd)
11209 {
11210 return native_pgd_val(pmd.pud.pgd);
11211@@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11212
11213 extern pteval_t __supported_pte_mask;
11214 extern void set_nx(void);
11215-extern int nx_enabled;
11216
11217 #define pgprot_writecombine pgprot_writecombine
11218 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11219diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11220index 58545c9..fe6fc38e 100644
11221--- a/arch/x86/include/asm/processor.h
11222+++ b/arch/x86/include/asm/processor.h
11223@@ -266,7 +266,7 @@ struct tss_struct {
11224
11225 } ____cacheline_aligned;
11226
11227-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11228+extern struct tss_struct init_tss[NR_CPUS];
11229
11230 /*
11231 * Save the original ist values for checking stack pointers during debugging
11232@@ -860,11 +860,18 @@ static inline void spin_lock_prefetch(const void *x)
11233 */
11234 #define TASK_SIZE PAGE_OFFSET
11235 #define TASK_SIZE_MAX TASK_SIZE
11236+
11237+#ifdef CONFIG_PAX_SEGMEXEC
11238+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11239+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11240+#else
11241 #define STACK_TOP TASK_SIZE
11242-#define STACK_TOP_MAX STACK_TOP
11243+#endif
11244+
11245+#define STACK_TOP_MAX TASK_SIZE
11246
11247 #define INIT_THREAD { \
11248- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11249+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11250 .vm86_info = NULL, \
11251 .sysenter_cs = __KERNEL_CS, \
11252 .io_bitmap_ptr = NULL, \
11253@@ -878,7 +885,7 @@ static inline void spin_lock_prefetch(const void *x)
11254 */
11255 #define INIT_TSS { \
11256 .x86_tss = { \
11257- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11258+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11259 .ss0 = __KERNEL_DS, \
11260 .ss1 = __KERNEL_CS, \
11261 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11262@@ -889,11 +896,7 @@ static inline void spin_lock_prefetch(const void *x)
11263 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11264
11265 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11266-#define KSTK_TOP(info) \
11267-({ \
11268- unsigned long *__ptr = (unsigned long *)(info); \
11269- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11270-})
11271+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11272
11273 /*
11274 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11275@@ -908,7 +911,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11276 #define task_pt_regs(task) \
11277 ({ \
11278 struct pt_regs *__regs__; \
11279- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11280+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11281 __regs__ - 1; \
11282 })
11283
11284@@ -918,13 +921,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11285 /*
11286 * User space process size. 47bits minus one guard page.
11287 */
11288-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11289+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11290
11291 /* This decides where the kernel will search for a free chunk of vm
11292 * space during mmap's.
11293 */
11294 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11295- 0xc0000000 : 0xFFFFe000)
11296+ 0xc0000000 : 0xFFFFf000)
11297
11298 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
11299 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11300@@ -935,11 +938,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11301 #define STACK_TOP_MAX TASK_SIZE_MAX
11302
11303 #define INIT_THREAD { \
11304- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11305+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11306 }
11307
11308 #define INIT_TSS { \
11309- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11310+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11311 }
11312
11313 /*
11314@@ -961,6 +964,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11315 */
11316 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11317
11318+#ifdef CONFIG_PAX_SEGMEXEC
11319+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11320+#endif
11321+
11322 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11323
11324 /* Get/set a process' ability to use the timestamp counter instruction */
11325diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11326index 3566454..4bdfb8c 100644
11327--- a/arch/x86/include/asm/ptrace.h
11328+++ b/arch/x86/include/asm/ptrace.h
11329@@ -156,28 +156,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11330 }
11331
11332 /*
11333- * user_mode_vm(regs) determines whether a register set came from user mode.
11334+ * user_mode(regs) determines whether a register set came from user mode.
11335 * This is true if V8086 mode was enabled OR if the register set was from
11336 * protected mode with RPL-3 CS value. This tricky test checks that with
11337 * one comparison. Many places in the kernel can bypass this full check
11338- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11339+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11340+ * be used.
11341 */
11342-static inline int user_mode(struct pt_regs *regs)
11343+static inline int user_mode_novm(struct pt_regs *regs)
11344 {
11345 #ifdef CONFIG_X86_32
11346 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11347 #else
11348- return !!(regs->cs & 3);
11349+ return !!(regs->cs & SEGMENT_RPL_MASK);
11350 #endif
11351 }
11352
11353-static inline int user_mode_vm(struct pt_regs *regs)
11354+static inline int user_mode(struct pt_regs *regs)
11355 {
11356 #ifdef CONFIG_X86_32
11357 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11358 USER_RPL;
11359 #else
11360- return user_mode(regs);
11361+ return user_mode_novm(regs);
11362 #endif
11363 }
11364
11365@@ -193,15 +194,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11366 #ifdef CONFIG_X86_64
11367 static inline bool user_64bit_mode(struct pt_regs *regs)
11368 {
11369+ unsigned long cs = regs->cs & 0xffff;
11370 #ifndef CONFIG_PARAVIRT
11371 /*
11372 * On non-paravirt systems, this is the only long mode CPL 3
11373 * selector. We do not allow long mode selectors in the LDT.
11374 */
11375- return regs->cs == __USER_CS;
11376+ return cs == __USER_CS;
11377 #else
11378 /* Headers are too twisted for this to go in paravirt.h. */
11379- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11380+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11381 #endif
11382 }
11383 #endif
11384diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11385index 92f29706..a79cbbb 100644
11386--- a/arch/x86/include/asm/reboot.h
11387+++ b/arch/x86/include/asm/reboot.h
11388@@ -6,19 +6,19 @@
11389 struct pt_regs;
11390
11391 struct machine_ops {
11392- void (*restart)(char *cmd);
11393- void (*halt)(void);
11394- void (*power_off)(void);
11395+ void (* __noreturn restart)(char *cmd);
11396+ void (* __noreturn halt)(void);
11397+ void (* __noreturn power_off)(void);
11398 void (*shutdown)(void);
11399 void (*crash_shutdown)(struct pt_regs *);
11400- void (*emergency_restart)(void);
11401-};
11402+ void (* __noreturn emergency_restart)(void);
11403+} __no_const;
11404
11405 extern struct machine_ops machine_ops;
11406
11407 void native_machine_crash_shutdown(struct pt_regs *regs);
11408 void native_machine_shutdown(void);
11409-void machine_real_restart(unsigned int type);
11410+void machine_real_restart(unsigned int type) __noreturn;
11411 /* These must match dispatch_table in reboot_32.S */
11412 #define MRR_BIOS 0
11413 #define MRR_APM 1
11414diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11415index 2dbe4a7..ce1db00 100644
11416--- a/arch/x86/include/asm/rwsem.h
11417+++ b/arch/x86/include/asm/rwsem.h
11418@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11419 {
11420 asm volatile("# beginning down_read\n\t"
11421 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11422+
11423+#ifdef CONFIG_PAX_REFCOUNT
11424+ "jno 0f\n"
11425+ LOCK_PREFIX _ASM_DEC "(%1)\n"
11426+ "int $4\n0:\n"
11427+ _ASM_EXTABLE(0b, 0b)
11428+#endif
11429+
11430 /* adds 0x00000001 */
11431 " jns 1f\n"
11432 " call call_rwsem_down_read_failed\n"
11433@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11434 "1:\n\t"
11435 " mov %1,%2\n\t"
11436 " add %3,%2\n\t"
11437+
11438+#ifdef CONFIG_PAX_REFCOUNT
11439+ "jno 0f\n"
11440+ "sub %3,%2\n"
11441+ "int $4\n0:\n"
11442+ _ASM_EXTABLE(0b, 0b)
11443+#endif
11444+
11445 " jle 2f\n\t"
11446 LOCK_PREFIX " cmpxchg %2,%0\n\t"
11447 " jnz 1b\n\t"
11448@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
11449 long tmp;
11450 asm volatile("# beginning down_write\n\t"
11451 LOCK_PREFIX " xadd %1,(%2)\n\t"
11452+
11453+#ifdef CONFIG_PAX_REFCOUNT
11454+ "jno 0f\n"
11455+ "mov %1,(%2)\n"
11456+ "int $4\n0:\n"
11457+ _ASM_EXTABLE(0b, 0b)
11458+#endif
11459+
11460 /* adds 0xffff0001, returns the old value */
11461 " test %1,%1\n\t"
11462 /* was the count 0 before? */
11463@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
11464 long tmp;
11465 asm volatile("# beginning __up_read\n\t"
11466 LOCK_PREFIX " xadd %1,(%2)\n\t"
11467+
11468+#ifdef CONFIG_PAX_REFCOUNT
11469+ "jno 0f\n"
11470+ "mov %1,(%2)\n"
11471+ "int $4\n0:\n"
11472+ _ASM_EXTABLE(0b, 0b)
11473+#endif
11474+
11475 /* subtracts 1, returns the old value */
11476 " jns 1f\n\t"
11477 " call call_rwsem_wake\n" /* expects old value in %edx */
11478@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
11479 long tmp;
11480 asm volatile("# beginning __up_write\n\t"
11481 LOCK_PREFIX " xadd %1,(%2)\n\t"
11482+
11483+#ifdef CONFIG_PAX_REFCOUNT
11484+ "jno 0f\n"
11485+ "mov %1,(%2)\n"
11486+ "int $4\n0:\n"
11487+ _ASM_EXTABLE(0b, 0b)
11488+#endif
11489+
11490 /* subtracts 0xffff0001, returns the old value */
11491 " jns 1f\n\t"
11492 " call call_rwsem_wake\n" /* expects old value in %edx */
11493@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11494 {
11495 asm volatile("# beginning __downgrade_write\n\t"
11496 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
11497+
11498+#ifdef CONFIG_PAX_REFCOUNT
11499+ "jno 0f\n"
11500+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
11501+ "int $4\n0:\n"
11502+ _ASM_EXTABLE(0b, 0b)
11503+#endif
11504+
11505 /*
11506 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
11507 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
11508@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11509 */
11510 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11511 {
11512- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
11513+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
11514+
11515+#ifdef CONFIG_PAX_REFCOUNT
11516+ "jno 0f\n"
11517+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
11518+ "int $4\n0:\n"
11519+ _ASM_EXTABLE(0b, 0b)
11520+#endif
11521+
11522 : "+m" (sem->count)
11523 : "er" (delta));
11524 }
11525@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11526 */
11527 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
11528 {
11529- return delta + xadd(&sem->count, delta);
11530+ return delta + xadd_check_overflow(&sem->count, delta);
11531 }
11532
11533 #endif /* __KERNEL__ */
11534diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
11535index 5e64171..f58957e 100644
11536--- a/arch/x86/include/asm/segment.h
11537+++ b/arch/x86/include/asm/segment.h
11538@@ -64,10 +64,15 @@
11539 * 26 - ESPFIX small SS
11540 * 27 - per-cpu [ offset to per-cpu data area ]
11541 * 28 - stack_canary-20 [ for stack protector ]
11542- * 29 - unused
11543- * 30 - unused
11544+ * 29 - PCI BIOS CS
11545+ * 30 - PCI BIOS DS
11546 * 31 - TSS for double fault handler
11547 */
11548+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
11549+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
11550+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
11551+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
11552+
11553 #define GDT_ENTRY_TLS_MIN 6
11554 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
11555
11556@@ -79,6 +84,8 @@
11557
11558 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
11559
11560+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
11561+
11562 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
11563
11564 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
11565@@ -104,6 +111,12 @@
11566 #define __KERNEL_STACK_CANARY 0
11567 #endif
11568
11569+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
11570+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
11571+
11572+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
11573+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
11574+
11575 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
11576
11577 /*
11578@@ -141,7 +154,7 @@
11579 */
11580
11581 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
11582-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
11583+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
11584
11585
11586 #else
11587@@ -165,6 +178,8 @@
11588 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
11589 #define __USER32_DS __USER_DS
11590
11591+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
11592+
11593 #define GDT_ENTRY_TSS 8 /* needs two entries */
11594 #define GDT_ENTRY_LDT 10 /* needs two entries */
11595 #define GDT_ENTRY_TLS_MIN 12
11596@@ -185,6 +200,7 @@
11597 #endif
11598
11599 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
11600+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
11601 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
11602 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
11603 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
11604diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
11605index 0434c40..1714bf0 100644
11606--- a/arch/x86/include/asm/smp.h
11607+++ b/arch/x86/include/asm/smp.h
11608@@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
11609 /* cpus sharing the last level cache: */
11610 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
11611 DECLARE_PER_CPU(u16, cpu_llc_id);
11612-DECLARE_PER_CPU(int, cpu_number);
11613+DECLARE_PER_CPU(unsigned int, cpu_number);
11614
11615 static inline struct cpumask *cpu_sibling_mask(int cpu)
11616 {
11617@@ -77,7 +77,7 @@ struct smp_ops {
11618
11619 void (*send_call_func_ipi)(const struct cpumask *mask);
11620 void (*send_call_func_single_ipi)(int cpu);
11621-};
11622+} __no_const;
11623
11624 /* Globals due to paravirt */
11625 extern void set_cpu_sibling_map(int cpu);
11626@@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
11627 extern int safe_smp_processor_id(void);
11628
11629 #elif defined(CONFIG_X86_64_SMP)
11630-#define raw_smp_processor_id() (percpu_read(cpu_number))
11631-
11632-#define stack_smp_processor_id() \
11633-({ \
11634- struct thread_info *ti; \
11635- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
11636- ti->cpu; \
11637-})
11638+#define raw_smp_processor_id() (percpu_read(cpu_number))
11639+#define stack_smp_processor_id() raw_smp_processor_id()
11640 #define safe_smp_processor_id() smp_processor_id()
11641
11642 #endif
11643diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
11644index a82c2bf..2198f61 100644
11645--- a/arch/x86/include/asm/spinlock.h
11646+++ b/arch/x86/include/asm/spinlock.h
11647@@ -175,6 +175,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
11648 static inline void arch_read_lock(arch_rwlock_t *rw)
11649 {
11650 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
11651+
11652+#ifdef CONFIG_PAX_REFCOUNT
11653+ "jno 0f\n"
11654+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
11655+ "int $4\n0:\n"
11656+ _ASM_EXTABLE(0b, 0b)
11657+#endif
11658+
11659 "jns 1f\n"
11660 "call __read_lock_failed\n\t"
11661 "1:\n"
11662@@ -184,6 +192,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
11663 static inline void arch_write_lock(arch_rwlock_t *rw)
11664 {
11665 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
11666+
11667+#ifdef CONFIG_PAX_REFCOUNT
11668+ "jno 0f\n"
11669+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
11670+ "int $4\n0:\n"
11671+ _ASM_EXTABLE(0b, 0b)
11672+#endif
11673+
11674 "jz 1f\n"
11675 "call __write_lock_failed\n\t"
11676 "1:\n"
11677@@ -213,13 +229,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
11678
11679 static inline void arch_read_unlock(arch_rwlock_t *rw)
11680 {
11681- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
11682+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
11683+
11684+#ifdef CONFIG_PAX_REFCOUNT
11685+ "jno 0f\n"
11686+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
11687+ "int $4\n0:\n"
11688+ _ASM_EXTABLE(0b, 0b)
11689+#endif
11690+
11691 :"+m" (rw->lock) : : "memory");
11692 }
11693
11694 static inline void arch_write_unlock(arch_rwlock_t *rw)
11695 {
11696- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
11697+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
11698+
11699+#ifdef CONFIG_PAX_REFCOUNT
11700+ "jno 0f\n"
11701+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
11702+ "int $4\n0:\n"
11703+ _ASM_EXTABLE(0b, 0b)
11704+#endif
11705+
11706 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
11707 }
11708
11709diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
11710index 1575177..cb23f52 100644
11711--- a/arch/x86/include/asm/stackprotector.h
11712+++ b/arch/x86/include/asm/stackprotector.h
11713@@ -48,7 +48,7 @@
11714 * head_32 for boot CPU and setup_per_cpu_areas() for others.
11715 */
11716 #define GDT_STACK_CANARY_INIT \
11717- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
11718+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
11719
11720 /*
11721 * Initialize the stackprotector canary value.
11722@@ -113,7 +113,7 @@ static inline void setup_stack_canary_segment(int cpu)
11723
11724 static inline void load_stack_canary_segment(void)
11725 {
11726-#ifdef CONFIG_X86_32
11727+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
11728 asm volatile ("mov %0, %%gs" : : "r" (0));
11729 #endif
11730 }
11731diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
11732index 70bbe39..4ae2bd4 100644
11733--- a/arch/x86/include/asm/stacktrace.h
11734+++ b/arch/x86/include/asm/stacktrace.h
11735@@ -11,28 +11,20 @@
11736
11737 extern int kstack_depth_to_print;
11738
11739-struct thread_info;
11740+struct task_struct;
11741 struct stacktrace_ops;
11742
11743-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
11744- unsigned long *stack,
11745- unsigned long bp,
11746- const struct stacktrace_ops *ops,
11747- void *data,
11748- unsigned long *end,
11749- int *graph);
11750+typedef unsigned long walk_stack_t(struct task_struct *task,
11751+ void *stack_start,
11752+ unsigned long *stack,
11753+ unsigned long bp,
11754+ const struct stacktrace_ops *ops,
11755+ void *data,
11756+ unsigned long *end,
11757+ int *graph);
11758
11759-extern unsigned long
11760-print_context_stack(struct thread_info *tinfo,
11761- unsigned long *stack, unsigned long bp,
11762- const struct stacktrace_ops *ops, void *data,
11763- unsigned long *end, int *graph);
11764-
11765-extern unsigned long
11766-print_context_stack_bp(struct thread_info *tinfo,
11767- unsigned long *stack, unsigned long bp,
11768- const struct stacktrace_ops *ops, void *data,
11769- unsigned long *end, int *graph);
11770+extern walk_stack_t print_context_stack;
11771+extern walk_stack_t print_context_stack_bp;
11772
11773 /* Generic stack tracer with callbacks */
11774
11775@@ -40,7 +32,7 @@ struct stacktrace_ops {
11776 void (*address)(void *data, unsigned long address, int reliable);
11777 /* On negative return stop dumping */
11778 int (*stack)(void *data, char *name);
11779- walk_stack_t walk_stack;
11780+ walk_stack_t *walk_stack;
11781 };
11782
11783 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
11784diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
11785index cb23852..2dde194 100644
11786--- a/arch/x86/include/asm/sys_ia32.h
11787+++ b/arch/x86/include/asm/sys_ia32.h
11788@@ -40,7 +40,7 @@ asmlinkage long sys32_rt_sigprocmask(int, compat_sigset_t __user *,
11789 compat_sigset_t __user *, unsigned int);
11790 asmlinkage long sys32_alarm(unsigned int);
11791
11792-asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
11793+asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
11794 asmlinkage long sys32_sysfs(int, u32, u32);
11795
11796 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
11797diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
11798index 2d2f01c..f985723 100644
11799--- a/arch/x86/include/asm/system.h
11800+++ b/arch/x86/include/asm/system.h
11801@@ -129,7 +129,7 @@ do { \
11802 "call __switch_to\n\t" \
11803 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
11804 __switch_canary \
11805- "movq %P[thread_info](%%rsi),%%r8\n\t" \
11806+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
11807 "movq %%rax,%%rdi\n\t" \
11808 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
11809 "jnz ret_from_fork\n\t" \
11810@@ -140,7 +140,7 @@ do { \
11811 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
11812 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
11813 [_tif_fork] "i" (_TIF_FORK), \
11814- [thread_info] "i" (offsetof(struct task_struct, stack)), \
11815+ [thread_info] "m" (current_tinfo), \
11816 [current_task] "m" (current_task) \
11817 __switch_canary_iparam \
11818 : "memory", "cc" __EXTRA_CLOBBER)
11819@@ -200,7 +200,7 @@ static inline unsigned long get_limit(unsigned long segment)
11820 {
11821 unsigned long __limit;
11822 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
11823- return __limit + 1;
11824+ return __limit;
11825 }
11826
11827 static inline void native_clts(void)
11828@@ -397,13 +397,13 @@ void enable_hlt(void);
11829
11830 void cpu_idle_wait(void);
11831
11832-extern unsigned long arch_align_stack(unsigned long sp);
11833+#define arch_align_stack(x) ((x) & ~0xfUL)
11834 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11835
11836 void default_idle(void);
11837 bool set_pm_idle_to_default(void);
11838
11839-void stop_this_cpu(void *dummy);
11840+void stop_this_cpu(void *dummy) __noreturn;
11841
11842 /*
11843 * Force strict CPU ordering.
11844diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
11845index cfd8144..1b1127d 100644
11846--- a/arch/x86/include/asm/thread_info.h
11847+++ b/arch/x86/include/asm/thread_info.h
11848@@ -10,6 +10,7 @@
11849 #include <linux/compiler.h>
11850 #include <asm/page.h>
11851 #include <asm/types.h>
11852+#include <asm/percpu.h>
11853
11854 /*
11855 * low level task data that entry.S needs immediate access to
11856@@ -24,7 +25,6 @@ struct exec_domain;
11857 #include <linux/atomic.h>
11858
11859 struct thread_info {
11860- struct task_struct *task; /* main task structure */
11861 struct exec_domain *exec_domain; /* execution domain */
11862 __u32 flags; /* low level flags */
11863 __u32 status; /* thread synchronous flags */
11864@@ -34,19 +34,13 @@ struct thread_info {
11865 mm_segment_t addr_limit;
11866 struct restart_block restart_block;
11867 void __user *sysenter_return;
11868-#ifdef CONFIG_X86_32
11869- unsigned long previous_esp; /* ESP of the previous stack in
11870- case of nested (IRQ) stacks
11871- */
11872- __u8 supervisor_stack[0];
11873-#endif
11874+ unsigned long lowest_stack;
11875 unsigned int sig_on_uaccess_error:1;
11876 unsigned int uaccess_err:1; /* uaccess failed */
11877 };
11878
11879-#define INIT_THREAD_INFO(tsk) \
11880+#define INIT_THREAD_INFO \
11881 { \
11882- .task = &tsk, \
11883 .exec_domain = &default_exec_domain, \
11884 .flags = 0, \
11885 .cpu = 0, \
11886@@ -57,7 +51,7 @@ struct thread_info {
11887 }, \
11888 }
11889
11890-#define init_thread_info (init_thread_union.thread_info)
11891+#define init_thread_info (init_thread_union.stack)
11892 #define init_stack (init_thread_union.stack)
11893
11894 #else /* !__ASSEMBLY__ */
11895@@ -169,45 +163,40 @@ struct thread_info {
11896 ret; \
11897 })
11898
11899-#ifdef CONFIG_X86_32
11900-
11901-#define STACK_WARN (THREAD_SIZE/8)
11902-/*
11903- * macros/functions for gaining access to the thread information structure
11904- *
11905- * preempt_count needs to be 1 initially, until the scheduler is functional.
11906- */
11907-#ifndef __ASSEMBLY__
11908-
11909-
11910-/* how to get the current stack pointer from C */
11911-register unsigned long current_stack_pointer asm("esp") __used;
11912-
11913-/* how to get the thread information struct from C */
11914-static inline struct thread_info *current_thread_info(void)
11915-{
11916- return (struct thread_info *)
11917- (current_stack_pointer & ~(THREAD_SIZE - 1));
11918-}
11919-
11920-#else /* !__ASSEMBLY__ */
11921-
11922+#ifdef __ASSEMBLY__
11923 /* how to get the thread information struct from ASM */
11924 #define GET_THREAD_INFO(reg) \
11925- movl $-THREAD_SIZE, reg; \
11926- andl %esp, reg
11927+ mov PER_CPU_VAR(current_tinfo), reg
11928
11929 /* use this one if reg already contains %esp */
11930-#define GET_THREAD_INFO_WITH_ESP(reg) \
11931- andl $-THREAD_SIZE, reg
11932+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
11933+#else
11934+/* how to get the thread information struct from C */
11935+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
11936+
11937+static __always_inline struct thread_info *current_thread_info(void)
11938+{
11939+ return percpu_read_stable(current_tinfo);
11940+}
11941+#endif
11942+
11943+#ifdef CONFIG_X86_32
11944+
11945+#define STACK_WARN (THREAD_SIZE/8)
11946+/*
11947+ * macros/functions for gaining access to the thread information structure
11948+ *
11949+ * preempt_count needs to be 1 initially, until the scheduler is functional.
11950+ */
11951+#ifndef __ASSEMBLY__
11952+
11953+/* how to get the current stack pointer from C */
11954+register unsigned long current_stack_pointer asm("esp") __used;
11955
11956 #endif
11957
11958 #else /* X86_32 */
11959
11960-#include <asm/percpu.h>
11961-#define KERNEL_STACK_OFFSET (5*8)
11962-
11963 /*
11964 * macros/functions for gaining access to the thread information structure
11965 * preempt_count needs to be 1 initially, until the scheduler is functional.
11966@@ -215,27 +204,8 @@ static inline struct thread_info *current_thread_info(void)
11967 #ifndef __ASSEMBLY__
11968 DECLARE_PER_CPU(unsigned long, kernel_stack);
11969
11970-static inline struct thread_info *current_thread_info(void)
11971-{
11972- struct thread_info *ti;
11973- ti = (void *)(percpu_read_stable(kernel_stack) +
11974- KERNEL_STACK_OFFSET - THREAD_SIZE);
11975- return ti;
11976-}
11977-
11978-#else /* !__ASSEMBLY__ */
11979-
11980-/* how to get the thread information struct from ASM */
11981-#define GET_THREAD_INFO(reg) \
11982- movq PER_CPU_VAR(kernel_stack),reg ; \
11983- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
11984-
11985-/*
11986- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
11987- * a certain register (to be used in assembler memory operands).
11988- */
11989-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
11990-
11991+/* how to get the current stack pointer from C */
11992+register unsigned long current_stack_pointer asm("rsp") __used;
11993 #endif
11994
11995 #endif /* !X86_32 */
11996@@ -269,5 +239,16 @@ extern void arch_task_cache_init(void);
11997 extern void free_thread_info(struct thread_info *ti);
11998 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
11999 #define arch_task_cache_init arch_task_cache_init
12000+
12001+#define __HAVE_THREAD_FUNCTIONS
12002+#define task_thread_info(task) (&(task)->tinfo)
12003+#define task_stack_page(task) ((task)->stack)
12004+#define setup_thread_stack(p, org) do {} while (0)
12005+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12006+
12007+#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12008+extern struct task_struct *alloc_task_struct_node(int node);
12009+extern void free_task_struct(struct task_struct *);
12010+
12011 #endif
12012 #endif /* _ASM_X86_THREAD_INFO_H */
12013diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12014index 8be5f54..7ae826d 100644
12015--- a/arch/x86/include/asm/uaccess.h
12016+++ b/arch/x86/include/asm/uaccess.h
12017@@ -7,12 +7,15 @@
12018 #include <linux/compiler.h>
12019 #include <linux/thread_info.h>
12020 #include <linux/string.h>
12021+#include <linux/sched.h>
12022 #include <asm/asm.h>
12023 #include <asm/page.h>
12024
12025 #define VERIFY_READ 0
12026 #define VERIFY_WRITE 1
12027
12028+extern void check_object_size(const void *ptr, unsigned long n, bool to);
12029+
12030 /*
12031 * The fs value determines whether argument validity checking should be
12032 * performed or not. If get_fs() == USER_DS, checking is performed, with
12033@@ -28,7 +31,12 @@
12034
12035 #define get_ds() (KERNEL_DS)
12036 #define get_fs() (current_thread_info()->addr_limit)
12037+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12038+void __set_fs(mm_segment_t x);
12039+void set_fs(mm_segment_t x);
12040+#else
12041 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12042+#endif
12043
12044 #define segment_eq(a, b) ((a).seg == (b).seg)
12045
12046@@ -76,7 +84,33 @@
12047 * checks that the pointer is in the user space range - after calling
12048 * this function, memory access functions may still return -EFAULT.
12049 */
12050-#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12051+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12052+#define access_ok(type, addr, size) \
12053+({ \
12054+ long __size = size; \
12055+ unsigned long __addr = (unsigned long)addr; \
12056+ unsigned long __addr_ao = __addr & PAGE_MASK; \
12057+ unsigned long __end_ao = __addr + __size - 1; \
12058+ bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12059+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12060+ while(__addr_ao <= __end_ao) { \
12061+ char __c_ao; \
12062+ __addr_ao += PAGE_SIZE; \
12063+ if (__size > PAGE_SIZE) \
12064+ cond_resched(); \
12065+ if (__get_user(__c_ao, (char __user *)__addr)) \
12066+ break; \
12067+ if (type != VERIFY_WRITE) { \
12068+ __addr = __addr_ao; \
12069+ continue; \
12070+ } \
12071+ if (__put_user(__c_ao, (char __user *)__addr)) \
12072+ break; \
12073+ __addr = __addr_ao; \
12074+ } \
12075+ } \
12076+ __ret_ao; \
12077+})
12078
12079 /*
12080 * The exception table consists of pairs of addresses: the first is the
12081@@ -182,12 +216,20 @@ extern int __get_user_bad(void);
12082 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12083 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12084
12085-
12086+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12087+#define __copyuser_seg "gs;"
12088+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12089+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12090+#else
12091+#define __copyuser_seg
12092+#define __COPYUSER_SET_ES
12093+#define __COPYUSER_RESTORE_ES
12094+#endif
12095
12096 #ifdef CONFIG_X86_32
12097 #define __put_user_asm_u64(x, addr, err, errret) \
12098- asm volatile("1: movl %%eax,0(%2)\n" \
12099- "2: movl %%edx,4(%2)\n" \
12100+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12101+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12102 "3:\n" \
12103 ".section .fixup,\"ax\"\n" \
12104 "4: movl %3,%0\n" \
12105@@ -199,8 +241,8 @@ extern int __get_user_bad(void);
12106 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12107
12108 #define __put_user_asm_ex_u64(x, addr) \
12109- asm volatile("1: movl %%eax,0(%1)\n" \
12110- "2: movl %%edx,4(%1)\n" \
12111+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12112+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12113 "3:\n" \
12114 _ASM_EXTABLE(1b, 2b - 1b) \
12115 _ASM_EXTABLE(2b, 3b - 2b) \
12116@@ -252,7 +294,7 @@ extern void __put_user_8(void);
12117 __typeof__(*(ptr)) __pu_val; \
12118 __chk_user_ptr(ptr); \
12119 might_fault(); \
12120- __pu_val = x; \
12121+ __pu_val = (x); \
12122 switch (sizeof(*(ptr))) { \
12123 case 1: \
12124 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12125@@ -373,7 +415,7 @@ do { \
12126 } while (0)
12127
12128 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12129- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12130+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12131 "2:\n" \
12132 ".section .fixup,\"ax\"\n" \
12133 "3: mov %3,%0\n" \
12134@@ -381,7 +423,7 @@ do { \
12135 " jmp 2b\n" \
12136 ".previous\n" \
12137 _ASM_EXTABLE(1b, 3b) \
12138- : "=r" (err), ltype(x) \
12139+ : "=r" (err), ltype (x) \
12140 : "m" (__m(addr)), "i" (errret), "0" (err))
12141
12142 #define __get_user_size_ex(x, ptr, size) \
12143@@ -406,7 +448,7 @@ do { \
12144 } while (0)
12145
12146 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12147- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12148+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12149 "2:\n" \
12150 _ASM_EXTABLE(1b, 2b - 1b) \
12151 : ltype(x) : "m" (__m(addr)))
12152@@ -423,13 +465,24 @@ do { \
12153 int __gu_err; \
12154 unsigned long __gu_val; \
12155 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12156- (x) = (__force __typeof__(*(ptr)))__gu_val; \
12157+ (x) = (__typeof__(*(ptr)))__gu_val; \
12158 __gu_err; \
12159 })
12160
12161 /* FIXME: this hack is definitely wrong -AK */
12162 struct __large_struct { unsigned long buf[100]; };
12163-#define __m(x) (*(struct __large_struct __user *)(x))
12164+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12165+#define ____m(x) \
12166+({ \
12167+ unsigned long ____x = (unsigned long)(x); \
12168+ if (____x < PAX_USER_SHADOW_BASE) \
12169+ ____x += PAX_USER_SHADOW_BASE; \
12170+ (void __user *)____x; \
12171+})
12172+#else
12173+#define ____m(x) (x)
12174+#endif
12175+#define __m(x) (*(struct __large_struct __user *)____m(x))
12176
12177 /*
12178 * Tell gcc we read from memory instead of writing: this is because
12179@@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
12180 * aliasing issues.
12181 */
12182 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12183- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12184+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12185 "2:\n" \
12186 ".section .fixup,\"ax\"\n" \
12187 "3: mov %3,%0\n" \
12188@@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
12189 ".previous\n" \
12190 _ASM_EXTABLE(1b, 3b) \
12191 : "=r"(err) \
12192- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12193+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12194
12195 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12196- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12197+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12198 "2:\n" \
12199 _ASM_EXTABLE(1b, 2b - 1b) \
12200 : : ltype(x), "m" (__m(addr)))
12201@@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
12202 * On error, the variable @x is set to zero.
12203 */
12204
12205+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12206+#define __get_user(x, ptr) get_user((x), (ptr))
12207+#else
12208 #define __get_user(x, ptr) \
12209 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12210+#endif
12211
12212 /**
12213 * __put_user: - Write a simple value into user space, with less checking.
12214@@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
12215 * Returns zero on success, or -EFAULT on error.
12216 */
12217
12218+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12219+#define __put_user(x, ptr) put_user((x), (ptr))
12220+#else
12221 #define __put_user(x, ptr) \
12222 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12223+#endif
12224
12225 #define __get_user_unaligned __get_user
12226 #define __put_user_unaligned __put_user
12227@@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
12228 #define get_user_ex(x, ptr) do { \
12229 unsigned long __gue_val; \
12230 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12231- (x) = (__force __typeof__(*(ptr)))__gue_val; \
12232+ (x) = (__typeof__(*(ptr)))__gue_val; \
12233 } while (0)
12234
12235 #ifdef CONFIG_X86_WP_WORKS_OK
12236diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12237index 566e803..b9521e9 100644
12238--- a/arch/x86/include/asm/uaccess_32.h
12239+++ b/arch/x86/include/asm/uaccess_32.h
12240@@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12241 static __always_inline unsigned long __must_check
12242 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12243 {
12244+ if ((long)n < 0)
12245+ return n;
12246+
12247 if (__builtin_constant_p(n)) {
12248 unsigned long ret;
12249
12250@@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12251 return ret;
12252 }
12253 }
12254+ if (!__builtin_constant_p(n))
12255+ check_object_size(from, n, true);
12256 return __copy_to_user_ll(to, from, n);
12257 }
12258
12259@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12260 __copy_to_user(void __user *to, const void *from, unsigned long n)
12261 {
12262 might_fault();
12263+
12264 return __copy_to_user_inatomic(to, from, n);
12265 }
12266
12267 static __always_inline unsigned long
12268 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12269 {
12270+ if ((long)n < 0)
12271+ return n;
12272+
12273 /* Avoid zeroing the tail if the copy fails..
12274 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12275 * but as the zeroing behaviour is only significant when n is not
12276@@ -137,6 +146,10 @@ static __always_inline unsigned long
12277 __copy_from_user(void *to, const void __user *from, unsigned long n)
12278 {
12279 might_fault();
12280+
12281+ if ((long)n < 0)
12282+ return n;
12283+
12284 if (__builtin_constant_p(n)) {
12285 unsigned long ret;
12286
12287@@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12288 return ret;
12289 }
12290 }
12291+ if (!__builtin_constant_p(n))
12292+ check_object_size(to, n, false);
12293 return __copy_from_user_ll(to, from, n);
12294 }
12295
12296@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12297 const void __user *from, unsigned long n)
12298 {
12299 might_fault();
12300+
12301+ if ((long)n < 0)
12302+ return n;
12303+
12304 if (__builtin_constant_p(n)) {
12305 unsigned long ret;
12306
12307@@ -181,15 +200,19 @@ static __always_inline unsigned long
12308 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12309 unsigned long n)
12310 {
12311- return __copy_from_user_ll_nocache_nozero(to, from, n);
12312+ if ((long)n < 0)
12313+ return n;
12314+
12315+ return __copy_from_user_ll_nocache_nozero(to, from, n);
12316 }
12317
12318-unsigned long __must_check copy_to_user(void __user *to,
12319- const void *from, unsigned long n);
12320-unsigned long __must_check _copy_from_user(void *to,
12321- const void __user *from,
12322- unsigned long n);
12323-
12324+extern void copy_to_user_overflow(void)
12325+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12326+ __compiletime_error("copy_to_user() buffer size is not provably correct")
12327+#else
12328+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
12329+#endif
12330+;
12331
12332 extern void copy_from_user_overflow(void)
12333 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12334@@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
12335 #endif
12336 ;
12337
12338-static inline unsigned long __must_check copy_from_user(void *to,
12339- const void __user *from,
12340- unsigned long n)
12341+/**
12342+ * copy_to_user: - Copy a block of data into user space.
12343+ * @to: Destination address, in user space.
12344+ * @from: Source address, in kernel space.
12345+ * @n: Number of bytes to copy.
12346+ *
12347+ * Context: User context only. This function may sleep.
12348+ *
12349+ * Copy data from kernel space to user space.
12350+ *
12351+ * Returns number of bytes that could not be copied.
12352+ * On success, this will be zero.
12353+ */
12354+static inline unsigned long __must_check
12355+copy_to_user(void __user *to, const void *from, unsigned long n)
12356+{
12357+ int sz = __compiletime_object_size(from);
12358+
12359+ if (unlikely(sz != -1 && sz < n))
12360+ copy_to_user_overflow();
12361+ else if (access_ok(VERIFY_WRITE, to, n))
12362+ n = __copy_to_user(to, from, n);
12363+ return n;
12364+}
12365+
12366+/**
12367+ * copy_from_user: - Copy a block of data from user space.
12368+ * @to: Destination address, in kernel space.
12369+ * @from: Source address, in user space.
12370+ * @n: Number of bytes to copy.
12371+ *
12372+ * Context: User context only. This function may sleep.
12373+ *
12374+ * Copy data from user space to kernel space.
12375+ *
12376+ * Returns number of bytes that could not be copied.
12377+ * On success, this will be zero.
12378+ *
12379+ * If some data could not be copied, this function will pad the copied
12380+ * data to the requested size using zero bytes.
12381+ */
12382+static inline unsigned long __must_check
12383+copy_from_user(void *to, const void __user *from, unsigned long n)
12384 {
12385 int sz = __compiletime_object_size(to);
12386
12387- if (likely(sz == -1 || sz >= n))
12388- n = _copy_from_user(to, from, n);
12389- else
12390+ if (unlikely(sz != -1 && sz < n))
12391 copy_from_user_overflow();
12392-
12393+ else if (access_ok(VERIFY_READ, from, n))
12394+ n = __copy_from_user(to, from, n);
12395+ else if ((long)n > 0) {
12396+ if (!__builtin_constant_p(n))
12397+ check_object_size(to, n, false);
12398+ memset(to, 0, n);
12399+ }
12400 return n;
12401 }
12402
12403diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
12404index 1c66d30..e66922c 100644
12405--- a/arch/x86/include/asm/uaccess_64.h
12406+++ b/arch/x86/include/asm/uaccess_64.h
12407@@ -10,6 +10,9 @@
12408 #include <asm/alternative.h>
12409 #include <asm/cpufeature.h>
12410 #include <asm/page.h>
12411+#include <asm/pgtable.h>
12412+
12413+#define set_fs(x) (current_thread_info()->addr_limit = (x))
12414
12415 /*
12416 * Copy To/From Userspace
12417@@ -17,12 +20,12 @@
12418
12419 /* Handles exceptions in both to and from, but doesn't do access_ok */
12420 __must_check unsigned long
12421-copy_user_generic_string(void *to, const void *from, unsigned len);
12422+copy_user_generic_string(void *to, const void *from, unsigned long len);
12423 __must_check unsigned long
12424-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
12425+copy_user_generic_unrolled(void *to, const void *from, unsigned long len);
12426
12427 static __always_inline __must_check unsigned long
12428-copy_user_generic(void *to, const void *from, unsigned len)
12429+copy_user_generic(void *to, const void *from, unsigned long len)
12430 {
12431 unsigned ret;
12432
12433@@ -32,142 +35,226 @@ copy_user_generic(void *to, const void *from, unsigned len)
12434 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
12435 "=d" (len)),
12436 "1" (to), "2" (from), "3" (len)
12437- : "memory", "rcx", "r8", "r9", "r10", "r11");
12438+ : "memory", "rcx", "r8", "r9", "r11");
12439 return ret;
12440 }
12441
12442+static __always_inline __must_check unsigned long
12443+__copy_to_user(void __user *to, const void *from, unsigned long len);
12444+static __always_inline __must_check unsigned long
12445+__copy_from_user(void *to, const void __user *from, unsigned long len);
12446 __must_check unsigned long
12447-_copy_to_user(void __user *to, const void *from, unsigned len);
12448-__must_check unsigned long
12449-_copy_from_user(void *to, const void __user *from, unsigned len);
12450-__must_check unsigned long
12451-copy_in_user(void __user *to, const void __user *from, unsigned len);
12452+copy_in_user(void __user *to, const void __user *from, unsigned long len);
12453
12454 static inline unsigned long __must_check copy_from_user(void *to,
12455 const void __user *from,
12456 unsigned long n)
12457 {
12458- int sz = __compiletime_object_size(to);
12459-
12460 might_fault();
12461- if (likely(sz == -1 || sz >= n))
12462- n = _copy_from_user(to, from, n);
12463-#ifdef CONFIG_DEBUG_VM
12464- else
12465- WARN(1, "Buffer overflow detected!\n");
12466-#endif
12467+
12468+ if (access_ok(VERIFY_READ, from, n))
12469+ n = __copy_from_user(to, from, n);
12470+ else if (n < INT_MAX) {
12471+ if (!__builtin_constant_p(n))
12472+ check_object_size(to, n, false);
12473+ memset(to, 0, n);
12474+ }
12475 return n;
12476 }
12477
12478 static __always_inline __must_check
12479-int copy_to_user(void __user *dst, const void *src, unsigned size)
12480+int copy_to_user(void __user *dst, const void *src, unsigned long size)
12481 {
12482 might_fault();
12483
12484- return _copy_to_user(dst, src, size);
12485+ if (access_ok(VERIFY_WRITE, dst, size))
12486+ size = __copy_to_user(dst, src, size);
12487+ return size;
12488 }
12489
12490 static __always_inline __must_check
12491-int __copy_from_user(void *dst, const void __user *src, unsigned size)
12492+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
12493 {
12494- int ret = 0;
12495+ int sz = __compiletime_object_size(dst);
12496+ unsigned ret = 0;
12497
12498 might_fault();
12499- if (!__builtin_constant_p(size))
12500- return copy_user_generic(dst, (__force void *)src, size);
12501+
12502+ if (size > INT_MAX)
12503+ return size;
12504+
12505+#ifdef CONFIG_PAX_MEMORY_UDEREF
12506+ if (!__access_ok(VERIFY_READ, src, size))
12507+ return size;
12508+#endif
12509+
12510+ if (unlikely(sz != -1 && sz < size)) {
12511+#ifdef CONFIG_DEBUG_VM
12512+ WARN(1, "Buffer overflow detected!\n");
12513+#endif
12514+ return size;
12515+ }
12516+
12517+ if (!__builtin_constant_p(size)) {
12518+ check_object_size(dst, size, false);
12519+
12520+#ifdef CONFIG_PAX_MEMORY_UDEREF
12521+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12522+ src += PAX_USER_SHADOW_BASE;
12523+#endif
12524+
12525+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
12526+ }
12527 switch (size) {
12528- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
12529+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
12530 ret, "b", "b", "=q", 1);
12531 return ret;
12532- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
12533+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
12534 ret, "w", "w", "=r", 2);
12535 return ret;
12536- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
12537+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
12538 ret, "l", "k", "=r", 4);
12539 return ret;
12540- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
12541+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12542 ret, "q", "", "=r", 8);
12543 return ret;
12544 case 10:
12545- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12546+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12547 ret, "q", "", "=r", 10);
12548 if (unlikely(ret))
12549 return ret;
12550 __get_user_asm(*(u16 *)(8 + (char *)dst),
12551- (u16 __user *)(8 + (char __user *)src),
12552+ (const u16 __user *)(8 + (const char __user *)src),
12553 ret, "w", "w", "=r", 2);
12554 return ret;
12555 case 16:
12556- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12557+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12558 ret, "q", "", "=r", 16);
12559 if (unlikely(ret))
12560 return ret;
12561 __get_user_asm(*(u64 *)(8 + (char *)dst),
12562- (u64 __user *)(8 + (char __user *)src),
12563+ (const u64 __user *)(8 + (const char __user *)src),
12564 ret, "q", "", "=r", 8);
12565 return ret;
12566 default:
12567- return copy_user_generic(dst, (__force void *)src, size);
12568+
12569+#ifdef CONFIG_PAX_MEMORY_UDEREF
12570+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12571+ src += PAX_USER_SHADOW_BASE;
12572+#endif
12573+
12574+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
12575 }
12576 }
12577
12578 static __always_inline __must_check
12579-int __copy_to_user(void __user *dst, const void *src, unsigned size)
12580+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
12581 {
12582- int ret = 0;
12583+ int sz = __compiletime_object_size(src);
12584+ unsigned ret = 0;
12585
12586 might_fault();
12587- if (!__builtin_constant_p(size))
12588- return copy_user_generic((__force void *)dst, src, size);
12589+
12590+ if (size > INT_MAX)
12591+ return size;
12592+
12593+#ifdef CONFIG_PAX_MEMORY_UDEREF
12594+ if (!__access_ok(VERIFY_WRITE, dst, size))
12595+ return size;
12596+#endif
12597+
12598+ if (unlikely(sz != -1 && sz < size)) {
12599+#ifdef CONFIG_DEBUG_VM
12600+ WARN(1, "Buffer overflow detected!\n");
12601+#endif
12602+ return size;
12603+ }
12604+
12605+ if (!__builtin_constant_p(size)) {
12606+ check_object_size(src, size, true);
12607+
12608+#ifdef CONFIG_PAX_MEMORY_UDEREF
12609+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12610+ dst += PAX_USER_SHADOW_BASE;
12611+#endif
12612+
12613+ return copy_user_generic((__force_kernel void *)dst, src, size);
12614+ }
12615 switch (size) {
12616- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
12617+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
12618 ret, "b", "b", "iq", 1);
12619 return ret;
12620- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
12621+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
12622 ret, "w", "w", "ir", 2);
12623 return ret;
12624- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
12625+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
12626 ret, "l", "k", "ir", 4);
12627 return ret;
12628- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
12629+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12630 ret, "q", "", "er", 8);
12631 return ret;
12632 case 10:
12633- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12634+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12635 ret, "q", "", "er", 10);
12636 if (unlikely(ret))
12637 return ret;
12638 asm("":::"memory");
12639- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
12640+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
12641 ret, "w", "w", "ir", 2);
12642 return ret;
12643 case 16:
12644- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12645+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12646 ret, "q", "", "er", 16);
12647 if (unlikely(ret))
12648 return ret;
12649 asm("":::"memory");
12650- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
12651+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
12652 ret, "q", "", "er", 8);
12653 return ret;
12654 default:
12655- return copy_user_generic((__force void *)dst, src, size);
12656+
12657+#ifdef CONFIG_PAX_MEMORY_UDEREF
12658+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12659+ dst += PAX_USER_SHADOW_BASE;
12660+#endif
12661+
12662+ return copy_user_generic((__force_kernel void *)dst, src, size);
12663 }
12664 }
12665
12666 static __always_inline __must_check
12667-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12668+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
12669 {
12670- int ret = 0;
12671+ unsigned ret = 0;
12672
12673 might_fault();
12674- if (!__builtin_constant_p(size))
12675- return copy_user_generic((__force void *)dst,
12676- (__force void *)src, size);
12677+
12678+ if (size > INT_MAX)
12679+ return size;
12680+
12681+#ifdef CONFIG_PAX_MEMORY_UDEREF
12682+ if (!__access_ok(VERIFY_READ, src, size))
12683+ return size;
12684+ if (!__access_ok(VERIFY_WRITE, dst, size))
12685+ return size;
12686+#endif
12687+
12688+ if (!__builtin_constant_p(size)) {
12689+
12690+#ifdef CONFIG_PAX_MEMORY_UDEREF
12691+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12692+ src += PAX_USER_SHADOW_BASE;
12693+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12694+ dst += PAX_USER_SHADOW_BASE;
12695+#endif
12696+
12697+ return copy_user_generic((__force_kernel void *)dst,
12698+ (__force_kernel const void *)src, size);
12699+ }
12700 switch (size) {
12701 case 1: {
12702 u8 tmp;
12703- __get_user_asm(tmp, (u8 __user *)src,
12704+ __get_user_asm(tmp, (const u8 __user *)src,
12705 ret, "b", "b", "=q", 1);
12706 if (likely(!ret))
12707 __put_user_asm(tmp, (u8 __user *)dst,
12708@@ -176,7 +263,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12709 }
12710 case 2: {
12711 u16 tmp;
12712- __get_user_asm(tmp, (u16 __user *)src,
12713+ __get_user_asm(tmp, (const u16 __user *)src,
12714 ret, "w", "w", "=r", 2);
12715 if (likely(!ret))
12716 __put_user_asm(tmp, (u16 __user *)dst,
12717@@ -186,7 +273,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12718
12719 case 4: {
12720 u32 tmp;
12721- __get_user_asm(tmp, (u32 __user *)src,
12722+ __get_user_asm(tmp, (const u32 __user *)src,
12723 ret, "l", "k", "=r", 4);
12724 if (likely(!ret))
12725 __put_user_asm(tmp, (u32 __user *)dst,
12726@@ -195,7 +282,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12727 }
12728 case 8: {
12729 u64 tmp;
12730- __get_user_asm(tmp, (u64 __user *)src,
12731+ __get_user_asm(tmp, (const u64 __user *)src,
12732 ret, "q", "", "=r", 8);
12733 if (likely(!ret))
12734 __put_user_asm(tmp, (u64 __user *)dst,
12735@@ -203,8 +290,16 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12736 return ret;
12737 }
12738 default:
12739- return copy_user_generic((__force void *)dst,
12740- (__force void *)src, size);
12741+
12742+#ifdef CONFIG_PAX_MEMORY_UDEREF
12743+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12744+ src += PAX_USER_SHADOW_BASE;
12745+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12746+ dst += PAX_USER_SHADOW_BASE;
12747+#endif
12748+
12749+ return copy_user_generic((__force_kernel void *)dst,
12750+ (__force_kernel const void *)src, size);
12751 }
12752 }
12753
12754@@ -219,35 +314,72 @@ __must_check unsigned long clear_user(void __user *mem, unsigned long len);
12755 __must_check unsigned long __clear_user(void __user *mem, unsigned long len);
12756
12757 static __must_check __always_inline int
12758-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
12759+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
12760 {
12761- return copy_user_generic(dst, (__force const void *)src, size);
12762+ if (size > INT_MAX)
12763+ return size;
12764+
12765+#ifdef CONFIG_PAX_MEMORY_UDEREF
12766+ if (!__access_ok(VERIFY_READ, src, size))
12767+ return size;
12768+
12769+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12770+ src += PAX_USER_SHADOW_BASE;
12771+#endif
12772+
12773+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
12774 }
12775
12776-static __must_check __always_inline int
12777-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
12778+static __must_check __always_inline unsigned long
12779+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
12780 {
12781- return copy_user_generic((__force void *)dst, src, size);
12782+ if (size > INT_MAX)
12783+ return size;
12784+
12785+#ifdef CONFIG_PAX_MEMORY_UDEREF
12786+ if (!__access_ok(VERIFY_WRITE, dst, size))
12787+ return size;
12788+
12789+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12790+ dst += PAX_USER_SHADOW_BASE;
12791+#endif
12792+
12793+ return copy_user_generic((__force_kernel void *)dst, src, size);
12794 }
12795
12796-extern long __copy_user_nocache(void *dst, const void __user *src,
12797- unsigned size, int zerorest);
12798+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
12799+ unsigned long size, int zerorest);
12800
12801-static inline int
12802-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12803+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
12804 {
12805 might_sleep();
12806+
12807+ if (size > INT_MAX)
12808+ return size;
12809+
12810+#ifdef CONFIG_PAX_MEMORY_UDEREF
12811+ if (!__access_ok(VERIFY_READ, src, size))
12812+ return size;
12813+#endif
12814+
12815 return __copy_user_nocache(dst, src, size, 1);
12816 }
12817
12818-static inline int
12819-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12820- unsigned size)
12821+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12822+ unsigned long size)
12823 {
12824+ if (size > INT_MAX)
12825+ return size;
12826+
12827+#ifdef CONFIG_PAX_MEMORY_UDEREF
12828+ if (!__access_ok(VERIFY_READ, src, size))
12829+ return size;
12830+#endif
12831+
12832 return __copy_user_nocache(dst, src, size, 0);
12833 }
12834
12835-unsigned long
12836-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
12837+extern unsigned long
12838+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest);
12839
12840 #endif /* _ASM_X86_UACCESS_64_H */
12841diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
12842index bb05228..d763d5b 100644
12843--- a/arch/x86/include/asm/vdso.h
12844+++ b/arch/x86/include/asm/vdso.h
12845@@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
12846 #define VDSO32_SYMBOL(base, name) \
12847 ({ \
12848 extern const char VDSO32_##name[]; \
12849- (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
12850+ (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
12851 })
12852 #endif
12853
12854diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
12855index 517d476..a1cb4d9 100644
12856--- a/arch/x86/include/asm/x86_init.h
12857+++ b/arch/x86/include/asm/x86_init.h
12858@@ -29,7 +29,7 @@ struct x86_init_mpparse {
12859 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
12860 void (*find_smp_config)(void);
12861 void (*get_smp_config)(unsigned int early);
12862-};
12863+} __no_const;
12864
12865 /**
12866 * struct x86_init_resources - platform specific resource related ops
12867@@ -43,7 +43,7 @@ struct x86_init_resources {
12868 void (*probe_roms)(void);
12869 void (*reserve_resources)(void);
12870 char *(*memory_setup)(void);
12871-};
12872+} __no_const;
12873
12874 /**
12875 * struct x86_init_irqs - platform specific interrupt setup
12876@@ -56,7 +56,7 @@ struct x86_init_irqs {
12877 void (*pre_vector_init)(void);
12878 void (*intr_init)(void);
12879 void (*trap_init)(void);
12880-};
12881+} __no_const;
12882
12883 /**
12884 * struct x86_init_oem - oem platform specific customizing functions
12885@@ -66,7 +66,7 @@ struct x86_init_irqs {
12886 struct x86_init_oem {
12887 void (*arch_setup)(void);
12888 void (*banner)(void);
12889-};
12890+} __no_const;
12891
12892 /**
12893 * struct x86_init_mapping - platform specific initial kernel pagetable setup
12894@@ -77,7 +77,7 @@ struct x86_init_oem {
12895 */
12896 struct x86_init_mapping {
12897 void (*pagetable_reserve)(u64 start, u64 end);
12898-};
12899+} __no_const;
12900
12901 /**
12902 * struct x86_init_paging - platform specific paging functions
12903@@ -87,7 +87,7 @@ struct x86_init_mapping {
12904 struct x86_init_paging {
12905 void (*pagetable_setup_start)(pgd_t *base);
12906 void (*pagetable_setup_done)(pgd_t *base);
12907-};
12908+} __no_const;
12909
12910 /**
12911 * struct x86_init_timers - platform specific timer setup
12912@@ -102,7 +102,7 @@ struct x86_init_timers {
12913 void (*tsc_pre_init)(void);
12914 void (*timer_init)(void);
12915 void (*wallclock_init)(void);
12916-};
12917+} __no_const;
12918
12919 /**
12920 * struct x86_init_iommu - platform specific iommu setup
12921@@ -110,7 +110,7 @@ struct x86_init_timers {
12922 */
12923 struct x86_init_iommu {
12924 int (*iommu_init)(void);
12925-};
12926+} __no_const;
12927
12928 /**
12929 * struct x86_init_pci - platform specific pci init functions
12930@@ -124,7 +124,7 @@ struct x86_init_pci {
12931 int (*init)(void);
12932 void (*init_irq)(void);
12933 void (*fixup_irqs)(void);
12934-};
12935+} __no_const;
12936
12937 /**
12938 * struct x86_init_ops - functions for platform specific setup
12939@@ -140,7 +140,7 @@ struct x86_init_ops {
12940 struct x86_init_timers timers;
12941 struct x86_init_iommu iommu;
12942 struct x86_init_pci pci;
12943-};
12944+} __no_const;
12945
12946 /**
12947 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
12948@@ -149,7 +149,7 @@ struct x86_init_ops {
12949 struct x86_cpuinit_ops {
12950 void (*setup_percpu_clockev)(void);
12951 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
12952-};
12953+} __no_const;
12954
12955 /**
12956 * struct x86_platform_ops - platform specific runtime functions
12957@@ -171,7 +171,7 @@ struct x86_platform_ops {
12958 void (*nmi_init)(void);
12959 unsigned char (*get_nmi_reason)(void);
12960 int (*i8042_detect)(void);
12961-};
12962+} __no_const;
12963
12964 struct pci_dev;
12965
12966@@ -180,7 +180,7 @@ struct x86_msi_ops {
12967 void (*teardown_msi_irq)(unsigned int irq);
12968 void (*teardown_msi_irqs)(struct pci_dev *dev);
12969 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
12970-};
12971+} __no_const;
12972
12973 extern struct x86_init_ops x86_init;
12974 extern struct x86_cpuinit_ops x86_cpuinit;
12975diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
12976index c6ce245..ffbdab7 100644
12977--- a/arch/x86/include/asm/xsave.h
12978+++ b/arch/x86/include/asm/xsave.h
12979@@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
12980 {
12981 int err;
12982
12983+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12984+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
12985+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
12986+#endif
12987+
12988 /*
12989 * Clear the xsave header first, so that reserved fields are
12990 * initialized to zero.
12991@@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
12992 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
12993 {
12994 int err;
12995- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
12996+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
12997 u32 lmask = mask;
12998 u32 hmask = mask >> 32;
12999
13000+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13001+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13002+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13003+#endif
13004+
13005 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13006 "2:\n"
13007 ".section .fixup,\"ax\"\n"
13008diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13009index 6a564ac..9b1340c 100644
13010--- a/arch/x86/kernel/acpi/realmode/Makefile
13011+++ b/arch/x86/kernel/acpi/realmode/Makefile
13012@@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13013 $(call cc-option, -fno-stack-protector) \
13014 $(call cc-option, -mpreferred-stack-boundary=2)
13015 KBUILD_CFLAGS += $(call cc-option, -m32)
13016+ifdef CONSTIFY_PLUGIN
13017+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13018+endif
13019 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13020 GCOV_PROFILE := n
13021
13022diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13023index b4fd836..4358fe3 100644
13024--- a/arch/x86/kernel/acpi/realmode/wakeup.S
13025+++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13026@@ -108,6 +108,9 @@ wakeup_code:
13027 /* Do any other stuff... */
13028
13029 #ifndef CONFIG_64BIT
13030+ /* Recheck NX bit overrides (64bit path does this in trampoline */
13031+ call verify_cpu
13032+
13033 /* This could also be done in C code... */
13034 movl pmode_cr3, %eax
13035 movl %eax, %cr3
13036@@ -131,6 +134,7 @@ wakeup_code:
13037 movl pmode_cr0, %eax
13038 movl %eax, %cr0
13039 jmp pmode_return
13040+# include "../../verify_cpu.S"
13041 #else
13042 pushw $0
13043 pushw trampoline_segment
13044diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13045index 103b6ab..2004d0a 100644
13046--- a/arch/x86/kernel/acpi/sleep.c
13047+++ b/arch/x86/kernel/acpi/sleep.c
13048@@ -94,8 +94,12 @@ int acpi_suspend_lowlevel(void)
13049 header->trampoline_segment = trampoline_address() >> 4;
13050 #ifdef CONFIG_SMP
13051 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13052+
13053+ pax_open_kernel();
13054 early_gdt_descr.address =
13055 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13056+ pax_close_kernel();
13057+
13058 initial_gs = per_cpu_offset(smp_processor_id());
13059 #endif
13060 initial_code = (unsigned long)wakeup_long64;
13061diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13062index 13ab720..95d5442 100644
13063--- a/arch/x86/kernel/acpi/wakeup_32.S
13064+++ b/arch/x86/kernel/acpi/wakeup_32.S
13065@@ -30,13 +30,11 @@ wakeup_pmode_return:
13066 # and restore the stack ... but you need gdt for this to work
13067 movl saved_context_esp, %esp
13068
13069- movl %cs:saved_magic, %eax
13070- cmpl $0x12345678, %eax
13071+ cmpl $0x12345678, saved_magic
13072 jne bogus_magic
13073
13074 # jump to place where we left off
13075- movl saved_eip, %eax
13076- jmp *%eax
13077+ jmp *(saved_eip)
13078
13079 bogus_magic:
13080 jmp bogus_magic
13081diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13082index 1f84794..e23f862 100644
13083--- a/arch/x86/kernel/alternative.c
13084+++ b/arch/x86/kernel/alternative.c
13085@@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13086 */
13087 for (a = start; a < end; a++) {
13088 instr = (u8 *)&a->instr_offset + a->instr_offset;
13089+
13090+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13091+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13092+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13093+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13094+#endif
13095+
13096 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13097 BUG_ON(a->replacementlen > a->instrlen);
13098 BUG_ON(a->instrlen > sizeof(insnbuf));
13099@@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13100 for (poff = start; poff < end; poff++) {
13101 u8 *ptr = (u8 *)poff + *poff;
13102
13103+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13104+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13105+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13106+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13107+#endif
13108+
13109 if (!*poff || ptr < text || ptr >= text_end)
13110 continue;
13111 /* turn DS segment override prefix into lock prefix */
13112- if (*ptr == 0x3e)
13113+ if (*ktla_ktva(ptr) == 0x3e)
13114 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13115 };
13116 mutex_unlock(&text_mutex);
13117@@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13118 for (poff = start; poff < end; poff++) {
13119 u8 *ptr = (u8 *)poff + *poff;
13120
13121+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13122+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13123+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13124+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13125+#endif
13126+
13127 if (!*poff || ptr < text || ptr >= text_end)
13128 continue;
13129 /* turn lock prefix into DS segment override prefix */
13130- if (*ptr == 0xf0)
13131+ if (*ktla_ktva(ptr) == 0xf0)
13132 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13133 };
13134 mutex_unlock(&text_mutex);
13135@@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13136
13137 BUG_ON(p->len > MAX_PATCH_LEN);
13138 /* prep the buffer with the original instructions */
13139- memcpy(insnbuf, p->instr, p->len);
13140+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13141 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13142 (unsigned long)p->instr, p->len);
13143
13144@@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13145 if (smp_alt_once)
13146 free_init_pages("SMP alternatives",
13147 (unsigned long)__smp_locks,
13148- (unsigned long)__smp_locks_end);
13149+ PAGE_ALIGN((unsigned long)__smp_locks_end));
13150
13151 restart_nmi();
13152 }
13153@@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13154 * instructions. And on the local CPU you need to be protected again NMI or MCE
13155 * handlers seeing an inconsistent instruction while you patch.
13156 */
13157-void *__init_or_module text_poke_early(void *addr, const void *opcode,
13158+void *__kprobes text_poke_early(void *addr, const void *opcode,
13159 size_t len)
13160 {
13161 unsigned long flags;
13162 local_irq_save(flags);
13163- memcpy(addr, opcode, len);
13164+
13165+ pax_open_kernel();
13166+ memcpy(ktla_ktva(addr), opcode, len);
13167 sync_core();
13168+ pax_close_kernel();
13169+
13170 local_irq_restore(flags);
13171 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13172 that causes hangs on some VIA CPUs. */
13173@@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13174 */
13175 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13176 {
13177- unsigned long flags;
13178- char *vaddr;
13179+ unsigned char *vaddr = ktla_ktva(addr);
13180 struct page *pages[2];
13181- int i;
13182+ size_t i;
13183
13184 if (!core_kernel_text((unsigned long)addr)) {
13185- pages[0] = vmalloc_to_page(addr);
13186- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13187+ pages[0] = vmalloc_to_page(vaddr);
13188+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13189 } else {
13190- pages[0] = virt_to_page(addr);
13191+ pages[0] = virt_to_page(vaddr);
13192 WARN_ON(!PageReserved(pages[0]));
13193- pages[1] = virt_to_page(addr + PAGE_SIZE);
13194+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13195 }
13196 BUG_ON(!pages[0]);
13197- local_irq_save(flags);
13198- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13199- if (pages[1])
13200- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13201- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13202- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13203- clear_fixmap(FIX_TEXT_POKE0);
13204- if (pages[1])
13205- clear_fixmap(FIX_TEXT_POKE1);
13206- local_flush_tlb();
13207- sync_core();
13208- /* Could also do a CLFLUSH here to speed up CPU recovery; but
13209- that causes hangs on some VIA CPUs. */
13210+ text_poke_early(addr, opcode, len);
13211 for (i = 0; i < len; i++)
13212- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13213- local_irq_restore(flags);
13214+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13215 return addr;
13216 }
13217
13218diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13219index 2eec05b..fef012b 100644
13220--- a/arch/x86/kernel/apic/apic.c
13221+++ b/arch/x86/kernel/apic/apic.c
13222@@ -184,7 +184,7 @@ int first_system_vector = 0xfe;
13223 /*
13224 * Debug level, exported for io_apic.c
13225 */
13226-unsigned int apic_verbosity;
13227+int apic_verbosity;
13228
13229 int pic_mode;
13230
13231@@ -1908,7 +1908,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13232 apic_write(APIC_ESR, 0);
13233 v1 = apic_read(APIC_ESR);
13234 ack_APIC_irq();
13235- atomic_inc(&irq_err_count);
13236+ atomic_inc_unchecked(&irq_err_count);
13237
13238 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13239 smp_processor_id(), v0 , v1);
13240diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13241index 6d10a66..f4687b8 100644
13242--- a/arch/x86/kernel/apic/io_apic.c
13243+++ b/arch/x86/kernel/apic/io_apic.c
13244@@ -1096,7 +1096,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13245 }
13246 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13247
13248-void lock_vector_lock(void)
13249+void lock_vector_lock(void) __acquires(vector_lock)
13250 {
13251 /* Used to the online set of cpus does not change
13252 * during assign_irq_vector.
13253@@ -1104,7 +1104,7 @@ void lock_vector_lock(void)
13254 raw_spin_lock(&vector_lock);
13255 }
13256
13257-void unlock_vector_lock(void)
13258+void unlock_vector_lock(void) __releases(vector_lock)
13259 {
13260 raw_spin_unlock(&vector_lock);
13261 }
13262@@ -2510,7 +2510,7 @@ static void ack_apic_edge(struct irq_data *data)
13263 ack_APIC_irq();
13264 }
13265
13266-atomic_t irq_mis_count;
13267+atomic_unchecked_t irq_mis_count;
13268
13269 static void ack_apic_level(struct irq_data *data)
13270 {
13271@@ -2576,7 +2576,7 @@ static void ack_apic_level(struct irq_data *data)
13272 * at the cpu.
13273 */
13274 if (!(v & (1 << (i & 0x1f)))) {
13275- atomic_inc(&irq_mis_count);
13276+ atomic_inc_unchecked(&irq_mis_count);
13277
13278 eoi_ioapic_irq(irq, cfg);
13279 }
13280diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13281index f76623c..aab694f 100644
13282--- a/arch/x86/kernel/apm_32.c
13283+++ b/arch/x86/kernel/apm_32.c
13284@@ -411,7 +411,7 @@ static DEFINE_MUTEX(apm_mutex);
13285 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13286 * even though they are called in protected mode.
13287 */
13288-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13289+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13290 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13291
13292 static const char driver_version[] = "1.16ac"; /* no spaces */
13293@@ -589,7 +589,10 @@ static long __apm_bios_call(void *_call)
13294 BUG_ON(cpu != 0);
13295 gdt = get_cpu_gdt_table(cpu);
13296 save_desc_40 = gdt[0x40 / 8];
13297+
13298+ pax_open_kernel();
13299 gdt[0x40 / 8] = bad_bios_desc;
13300+ pax_close_kernel();
13301
13302 apm_irq_save(flags);
13303 APM_DO_SAVE_SEGS;
13304@@ -598,7 +601,11 @@ static long __apm_bios_call(void *_call)
13305 &call->esi);
13306 APM_DO_RESTORE_SEGS;
13307 apm_irq_restore(flags);
13308+
13309+ pax_open_kernel();
13310 gdt[0x40 / 8] = save_desc_40;
13311+ pax_close_kernel();
13312+
13313 put_cpu();
13314
13315 return call->eax & 0xff;
13316@@ -665,7 +672,10 @@ static long __apm_bios_call_simple(void *_call)
13317 BUG_ON(cpu != 0);
13318 gdt = get_cpu_gdt_table(cpu);
13319 save_desc_40 = gdt[0x40 / 8];
13320+
13321+ pax_open_kernel();
13322 gdt[0x40 / 8] = bad_bios_desc;
13323+ pax_close_kernel();
13324
13325 apm_irq_save(flags);
13326 APM_DO_SAVE_SEGS;
13327@@ -673,7 +683,11 @@ static long __apm_bios_call_simple(void *_call)
13328 &call->eax);
13329 APM_DO_RESTORE_SEGS;
13330 apm_irq_restore(flags);
13331+
13332+ pax_open_kernel();
13333 gdt[0x40 / 8] = save_desc_40;
13334+ pax_close_kernel();
13335+
13336 put_cpu();
13337 return error;
13338 }
13339@@ -2347,12 +2361,15 @@ static int __init apm_init(void)
13340 * code to that CPU.
13341 */
13342 gdt = get_cpu_gdt_table(0);
13343+
13344+ pax_open_kernel();
13345 set_desc_base(&gdt[APM_CS >> 3],
13346 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13347 set_desc_base(&gdt[APM_CS_16 >> 3],
13348 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13349 set_desc_base(&gdt[APM_DS >> 3],
13350 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13351+ pax_close_kernel();
13352
13353 proc_create("apm", 0, NULL, &apm_file_ops);
13354
13355diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
13356index 68de2dc..1f3c720 100644
13357--- a/arch/x86/kernel/asm-offsets.c
13358+++ b/arch/x86/kernel/asm-offsets.c
13359@@ -33,6 +33,8 @@ void common(void) {
13360 OFFSET(TI_status, thread_info, status);
13361 OFFSET(TI_addr_limit, thread_info, addr_limit);
13362 OFFSET(TI_preempt_count, thread_info, preempt_count);
13363+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
13364+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13365
13366 BLANK();
13367 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
13368@@ -53,8 +55,26 @@ void common(void) {
13369 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13370 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13371 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
13372+
13373+#ifdef CONFIG_PAX_KERNEXEC
13374+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13375 #endif
13376
13377+#ifdef CONFIG_PAX_MEMORY_UDEREF
13378+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13379+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13380+#ifdef CONFIG_X86_64
13381+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
13382+#endif
13383+#endif
13384+
13385+#endif
13386+
13387+ BLANK();
13388+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13389+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13390+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13391+
13392 #ifdef CONFIG_XEN
13393 BLANK();
13394 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
13395diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
13396index 834e897..dacddc8 100644
13397--- a/arch/x86/kernel/asm-offsets_64.c
13398+++ b/arch/x86/kernel/asm-offsets_64.c
13399@@ -70,6 +70,7 @@ int main(void)
13400 BLANK();
13401 #undef ENTRY
13402
13403+ DEFINE(TSS_size, sizeof(struct tss_struct));
13404 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
13405 BLANK();
13406
13407diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
13408index 25f24dc..4094a7f 100644
13409--- a/arch/x86/kernel/cpu/Makefile
13410+++ b/arch/x86/kernel/cpu/Makefile
13411@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
13412 CFLAGS_REMOVE_perf_event.o = -pg
13413 endif
13414
13415-# Make sure load_percpu_segment has no stackprotector
13416-nostackp := $(call cc-option, -fno-stack-protector)
13417-CFLAGS_common.o := $(nostackp)
13418-
13419 obj-y := intel_cacheinfo.o scattered.o topology.o
13420 obj-y += proc.o capflags.o powerflags.o common.o
13421 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
13422diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
13423index f4773f4..b3fb13c 100644
13424--- a/arch/x86/kernel/cpu/amd.c
13425+++ b/arch/x86/kernel/cpu/amd.c
13426@@ -669,7 +669,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
13427 unsigned int size)
13428 {
13429 /* AMD errata T13 (order #21922) */
13430- if ((c->x86 == 6)) {
13431+ if (c->x86 == 6) {
13432 /* Duron Rev A0 */
13433 if (c->x86_model == 3 && c->x86_mask == 0)
13434 size = 64;
13435diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
13436index c0f7d68..aa418f9 100644
13437--- a/arch/x86/kernel/cpu/common.c
13438+++ b/arch/x86/kernel/cpu/common.c
13439@@ -84,60 +84,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
13440
13441 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
13442
13443-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
13444-#ifdef CONFIG_X86_64
13445- /*
13446- * We need valid kernel segments for data and code in long mode too
13447- * IRET will check the segment types kkeil 2000/10/28
13448- * Also sysret mandates a special GDT layout
13449- *
13450- * TLS descriptors are currently at a different place compared to i386.
13451- * Hopefully nobody expects them at a fixed place (Wine?)
13452- */
13453- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
13454- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
13455- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
13456- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
13457- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
13458- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
13459-#else
13460- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
13461- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13462- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
13463- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
13464- /*
13465- * Segments used for calling PnP BIOS have byte granularity.
13466- * They code segments and data segments have fixed 64k limits,
13467- * the transfer segment sizes are set at run time.
13468- */
13469- /* 32-bit code */
13470- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13471- /* 16-bit code */
13472- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13473- /* 16-bit data */
13474- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
13475- /* 16-bit data */
13476- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
13477- /* 16-bit data */
13478- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
13479- /*
13480- * The APM segments have byte granularity and their bases
13481- * are set at run time. All have 64k limits.
13482- */
13483- /* 32-bit code */
13484- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13485- /* 16-bit code */
13486- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13487- /* data */
13488- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
13489-
13490- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13491- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13492- GDT_STACK_CANARY_INIT
13493-#endif
13494-} };
13495-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
13496-
13497 static int __init x86_xsave_setup(char *s)
13498 {
13499 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
13500@@ -372,7 +318,7 @@ void switch_to_new_gdt(int cpu)
13501 {
13502 struct desc_ptr gdt_descr;
13503
13504- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
13505+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
13506 gdt_descr.size = GDT_SIZE - 1;
13507 load_gdt(&gdt_descr);
13508 /* Reload the per-cpu base */
13509@@ -839,6 +785,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
13510 /* Filter out anything that depends on CPUID levels we don't have */
13511 filter_cpuid_features(c, true);
13512
13513+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
13514+ setup_clear_cpu_cap(X86_FEATURE_SEP);
13515+#endif
13516+
13517 /* If the model name is still unset, do table lookup. */
13518 if (!c->x86_model_id[0]) {
13519 const char *p;
13520@@ -1019,10 +969,12 @@ static __init int setup_disablecpuid(char *arg)
13521 }
13522 __setup("clearcpuid=", setup_disablecpuid);
13523
13524+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
13525+EXPORT_PER_CPU_SYMBOL(current_tinfo);
13526+
13527 #ifdef CONFIG_X86_64
13528 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
13529-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
13530- (unsigned long) nmi_idt_table };
13531+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
13532
13533 DEFINE_PER_CPU_FIRST(union irq_stack_union,
13534 irq_stack_union) __aligned(PAGE_SIZE);
13535@@ -1036,7 +988,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
13536 EXPORT_PER_CPU_SYMBOL(current_task);
13537
13538 DEFINE_PER_CPU(unsigned long, kernel_stack) =
13539- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
13540+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
13541 EXPORT_PER_CPU_SYMBOL(kernel_stack);
13542
13543 DEFINE_PER_CPU(char *, irq_stack_ptr) =
13544@@ -1126,7 +1078,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
13545 {
13546 memset(regs, 0, sizeof(struct pt_regs));
13547 regs->fs = __KERNEL_PERCPU;
13548- regs->gs = __KERNEL_STACK_CANARY;
13549+ savesegment(gs, regs->gs);
13550
13551 return regs;
13552 }
13553@@ -1190,7 +1142,7 @@ void __cpuinit cpu_init(void)
13554 int i;
13555
13556 cpu = stack_smp_processor_id();
13557- t = &per_cpu(init_tss, cpu);
13558+ t = init_tss + cpu;
13559 oist = &per_cpu(orig_ist, cpu);
13560
13561 #ifdef CONFIG_NUMA
13562@@ -1216,7 +1168,7 @@ void __cpuinit cpu_init(void)
13563 switch_to_new_gdt(cpu);
13564 loadsegment(fs, 0);
13565
13566- load_idt((const struct desc_ptr *)&idt_descr);
13567+ load_idt(&idt_descr);
13568
13569 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
13570 syscall_init();
13571@@ -1225,7 +1177,6 @@ void __cpuinit cpu_init(void)
13572 wrmsrl(MSR_KERNEL_GS_BASE, 0);
13573 barrier();
13574
13575- x86_configure_nx();
13576 if (cpu != 0)
13577 enable_x2apic();
13578
13579@@ -1281,7 +1232,7 @@ void __cpuinit cpu_init(void)
13580 {
13581 int cpu = smp_processor_id();
13582 struct task_struct *curr = current;
13583- struct tss_struct *t = &per_cpu(init_tss, cpu);
13584+ struct tss_struct *t = init_tss + cpu;
13585 struct thread_struct *thread = &curr->thread;
13586
13587 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
13588diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
13589index 3e6ff6c..54b4992 100644
13590--- a/arch/x86/kernel/cpu/intel.c
13591+++ b/arch/x86/kernel/cpu/intel.c
13592@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
13593 * Update the IDT descriptor and reload the IDT so that
13594 * it uses the read-only mapped virtual address.
13595 */
13596- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
13597+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
13598 load_idt(&idt_descr);
13599 }
13600 #endif
13601diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
13602index 5a11ae2..a1a1c8a 100644
13603--- a/arch/x86/kernel/cpu/mcheck/mce.c
13604+++ b/arch/x86/kernel/cpu/mcheck/mce.c
13605@@ -42,6 +42,7 @@
13606 #include <asm/processor.h>
13607 #include <asm/mce.h>
13608 #include <asm/msr.h>
13609+#include <asm/local.h>
13610
13611 #include "mce-internal.h"
13612
13613@@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
13614 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
13615 m->cs, m->ip);
13616
13617- if (m->cs == __KERNEL_CS)
13618+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
13619 print_symbol("{%s}", m->ip);
13620 pr_cont("\n");
13621 }
13622@@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
13623
13624 #define PANIC_TIMEOUT 5 /* 5 seconds */
13625
13626-static atomic_t mce_paniced;
13627+static atomic_unchecked_t mce_paniced;
13628
13629 static int fake_panic;
13630-static atomic_t mce_fake_paniced;
13631+static atomic_unchecked_t mce_fake_paniced;
13632
13633 /* Panic in progress. Enable interrupts and wait for final IPI */
13634 static void wait_for_panic(void)
13635@@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13636 /*
13637 * Make sure only one CPU runs in machine check panic
13638 */
13639- if (atomic_inc_return(&mce_paniced) > 1)
13640+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
13641 wait_for_panic();
13642 barrier();
13643
13644@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13645 console_verbose();
13646 } else {
13647 /* Don't log too much for fake panic */
13648- if (atomic_inc_return(&mce_fake_paniced) > 1)
13649+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
13650 return;
13651 }
13652 /* First print corrected ones that are still unlogged */
13653@@ -658,7 +659,7 @@ static int mce_timed_out(u64 *t)
13654 * might have been modified by someone else.
13655 */
13656 rmb();
13657- if (atomic_read(&mce_paniced))
13658+ if (atomic_read_unchecked(&mce_paniced))
13659 wait_for_panic();
13660 if (!monarch_timeout)
13661 goto out;
13662@@ -1446,7 +1447,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
13663 }
13664
13665 /* Call the installed machine check handler for this CPU setup. */
13666-void (*machine_check_vector)(struct pt_regs *, long error_code) =
13667+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
13668 unexpected_machine_check;
13669
13670 /*
13671@@ -1469,7 +1470,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
13672 return;
13673 }
13674
13675+ pax_open_kernel();
13676 machine_check_vector = do_machine_check;
13677+ pax_close_kernel();
13678
13679 __mcheck_cpu_init_generic();
13680 __mcheck_cpu_init_vendor(c);
13681@@ -1483,7 +1486,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
13682 */
13683
13684 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
13685-static int mce_chrdev_open_count; /* #times opened */
13686+static local_t mce_chrdev_open_count; /* #times opened */
13687 static int mce_chrdev_open_exclu; /* already open exclusive? */
13688
13689 static int mce_chrdev_open(struct inode *inode, struct file *file)
13690@@ -1491,7 +1494,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
13691 spin_lock(&mce_chrdev_state_lock);
13692
13693 if (mce_chrdev_open_exclu ||
13694- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
13695+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
13696 spin_unlock(&mce_chrdev_state_lock);
13697
13698 return -EBUSY;
13699@@ -1499,7 +1502,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
13700
13701 if (file->f_flags & O_EXCL)
13702 mce_chrdev_open_exclu = 1;
13703- mce_chrdev_open_count++;
13704+ local_inc(&mce_chrdev_open_count);
13705
13706 spin_unlock(&mce_chrdev_state_lock);
13707
13708@@ -1510,7 +1513,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
13709 {
13710 spin_lock(&mce_chrdev_state_lock);
13711
13712- mce_chrdev_open_count--;
13713+ local_dec(&mce_chrdev_open_count);
13714 mce_chrdev_open_exclu = 0;
13715
13716 spin_unlock(&mce_chrdev_state_lock);
13717@@ -2229,7 +2232,7 @@ struct dentry *mce_get_debugfs_dir(void)
13718 static void mce_reset(void)
13719 {
13720 cpu_missing = 0;
13721- atomic_set(&mce_fake_paniced, 0);
13722+ atomic_set_unchecked(&mce_fake_paniced, 0);
13723 atomic_set(&mce_executing, 0);
13724 atomic_set(&mce_callin, 0);
13725 atomic_set(&global_nwo, 0);
13726diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
13727index 5c0e653..0882b0a 100644
13728--- a/arch/x86/kernel/cpu/mcheck/p5.c
13729+++ b/arch/x86/kernel/cpu/mcheck/p5.c
13730@@ -12,6 +12,7 @@
13731 #include <asm/system.h>
13732 #include <asm/mce.h>
13733 #include <asm/msr.h>
13734+#include <asm/pgtable.h>
13735
13736 /* By default disabled */
13737 int mce_p5_enabled __read_mostly;
13738@@ -50,7 +51,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
13739 if (!cpu_has(c, X86_FEATURE_MCE))
13740 return;
13741
13742+ pax_open_kernel();
13743 machine_check_vector = pentium_machine_check;
13744+ pax_close_kernel();
13745 /* Make sure the vector pointer is visible before we enable MCEs: */
13746 wmb();
13747
13748diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
13749index 54060f5..c1a7577 100644
13750--- a/arch/x86/kernel/cpu/mcheck/winchip.c
13751+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
13752@@ -11,6 +11,7 @@
13753 #include <asm/system.h>
13754 #include <asm/mce.h>
13755 #include <asm/msr.h>
13756+#include <asm/pgtable.h>
13757
13758 /* Machine check handler for WinChip C6: */
13759 static void winchip_machine_check(struct pt_regs *regs, long error_code)
13760@@ -24,7 +25,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
13761 {
13762 u32 lo, hi;
13763
13764+ pax_open_kernel();
13765 machine_check_vector = winchip_machine_check;
13766+ pax_close_kernel();
13767 /* Make sure the vector pointer is visible before we enable MCEs: */
13768 wmb();
13769
13770diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
13771index 6b96110..0da73eb 100644
13772--- a/arch/x86/kernel/cpu/mtrr/main.c
13773+++ b/arch/x86/kernel/cpu/mtrr/main.c
13774@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
13775 u64 size_or_mask, size_and_mask;
13776 static bool mtrr_aps_delayed_init;
13777
13778-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
13779+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
13780
13781 const struct mtrr_ops *mtrr_if;
13782
13783diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
13784index df5e41f..816c719 100644
13785--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
13786+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
13787@@ -25,7 +25,7 @@ struct mtrr_ops {
13788 int (*validate_add_page)(unsigned long base, unsigned long size,
13789 unsigned int type);
13790 int (*have_wrcomb)(void);
13791-};
13792+} __do_const;
13793
13794 extern int generic_get_free_region(unsigned long base, unsigned long size,
13795 int replace_reg);
13796diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
13797index 5adce10..99284ec 100644
13798--- a/arch/x86/kernel/cpu/perf_event.c
13799+++ b/arch/x86/kernel/cpu/perf_event.c
13800@@ -1665,7 +1665,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
13801 break;
13802
13803 perf_callchain_store(entry, frame.return_address);
13804- fp = frame.next_frame;
13805+ fp = (const void __force_user *)frame.next_frame;
13806 }
13807 }
13808
13809diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
13810index 13ad899..f642b9a 100644
13811--- a/arch/x86/kernel/crash.c
13812+++ b/arch/x86/kernel/crash.c
13813@@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
13814 {
13815 #ifdef CONFIG_X86_32
13816 struct pt_regs fixed_regs;
13817-#endif
13818
13819-#ifdef CONFIG_X86_32
13820- if (!user_mode_vm(regs)) {
13821+ if (!user_mode(regs)) {
13822 crash_fixup_ss_esp(&fixed_regs, regs);
13823 regs = &fixed_regs;
13824 }
13825diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
13826index 37250fe..bf2ec74 100644
13827--- a/arch/x86/kernel/doublefault_32.c
13828+++ b/arch/x86/kernel/doublefault_32.c
13829@@ -11,7 +11,7 @@
13830
13831 #define DOUBLEFAULT_STACKSIZE (1024)
13832 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
13833-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
13834+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
13835
13836 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
13837
13838@@ -21,7 +21,7 @@ static void doublefault_fn(void)
13839 unsigned long gdt, tss;
13840
13841 store_gdt(&gdt_desc);
13842- gdt = gdt_desc.address;
13843+ gdt = (unsigned long)gdt_desc.address;
13844
13845 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
13846
13847@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
13848 /* 0x2 bit is always set */
13849 .flags = X86_EFLAGS_SF | 0x2,
13850 .sp = STACK_START,
13851- .es = __USER_DS,
13852+ .es = __KERNEL_DS,
13853 .cs = __KERNEL_CS,
13854 .ss = __KERNEL_DS,
13855- .ds = __USER_DS,
13856+ .ds = __KERNEL_DS,
13857 .fs = __KERNEL_PERCPU,
13858
13859 .__cr3 = __pa_nodebug(swapper_pg_dir),
13860diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
13861index 4025fe4..d8451c6 100644
13862--- a/arch/x86/kernel/dumpstack.c
13863+++ b/arch/x86/kernel/dumpstack.c
13864@@ -2,6 +2,9 @@
13865 * Copyright (C) 1991, 1992 Linus Torvalds
13866 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
13867 */
13868+#ifdef CONFIG_GRKERNSEC_HIDESYM
13869+#define __INCLUDED_BY_HIDESYM 1
13870+#endif
13871 #include <linux/kallsyms.h>
13872 #include <linux/kprobes.h>
13873 #include <linux/uaccess.h>
13874@@ -35,9 +38,8 @@ void printk_address(unsigned long address, int reliable)
13875 static void
13876 print_ftrace_graph_addr(unsigned long addr, void *data,
13877 const struct stacktrace_ops *ops,
13878- struct thread_info *tinfo, int *graph)
13879+ struct task_struct *task, int *graph)
13880 {
13881- struct task_struct *task = tinfo->task;
13882 unsigned long ret_addr;
13883 int index = task->curr_ret_stack;
13884
13885@@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
13886 static inline void
13887 print_ftrace_graph_addr(unsigned long addr, void *data,
13888 const struct stacktrace_ops *ops,
13889- struct thread_info *tinfo, int *graph)
13890+ struct task_struct *task, int *graph)
13891 { }
13892 #endif
13893
13894@@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
13895 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
13896 */
13897
13898-static inline int valid_stack_ptr(struct thread_info *tinfo,
13899- void *p, unsigned int size, void *end)
13900+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
13901 {
13902- void *t = tinfo;
13903 if (end) {
13904 if (p < end && p >= (end-THREAD_SIZE))
13905 return 1;
13906@@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
13907 }
13908
13909 unsigned long
13910-print_context_stack(struct thread_info *tinfo,
13911+print_context_stack(struct task_struct *task, void *stack_start,
13912 unsigned long *stack, unsigned long bp,
13913 const struct stacktrace_ops *ops, void *data,
13914 unsigned long *end, int *graph)
13915 {
13916 struct stack_frame *frame = (struct stack_frame *)bp;
13917
13918- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
13919+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
13920 unsigned long addr;
13921
13922 addr = *stack;
13923@@ -102,7 +102,7 @@ print_context_stack(struct thread_info *tinfo,
13924 } else {
13925 ops->address(data, addr, 0);
13926 }
13927- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
13928+ print_ftrace_graph_addr(addr, data, ops, task, graph);
13929 }
13930 stack++;
13931 }
13932@@ -111,7 +111,7 @@ print_context_stack(struct thread_info *tinfo,
13933 EXPORT_SYMBOL_GPL(print_context_stack);
13934
13935 unsigned long
13936-print_context_stack_bp(struct thread_info *tinfo,
13937+print_context_stack_bp(struct task_struct *task, void *stack_start,
13938 unsigned long *stack, unsigned long bp,
13939 const struct stacktrace_ops *ops, void *data,
13940 unsigned long *end, int *graph)
13941@@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_info *tinfo,
13942 struct stack_frame *frame = (struct stack_frame *)bp;
13943 unsigned long *ret_addr = &frame->return_address;
13944
13945- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
13946+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
13947 unsigned long addr = *ret_addr;
13948
13949 if (!__kernel_text_address(addr))
13950@@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_info *tinfo,
13951 ops->address(data, addr, 1);
13952 frame = frame->next_frame;
13953 ret_addr = &frame->return_address;
13954- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
13955+ print_ftrace_graph_addr(addr, data, ops, task, graph);
13956 }
13957
13958 return (unsigned long)frame;
13959@@ -186,7 +186,7 @@ void dump_stack(void)
13960
13961 bp = stack_frame(current, NULL);
13962 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
13963- current->pid, current->comm, print_tainted(),
13964+ task_pid_nr(current), current->comm, print_tainted(),
13965 init_utsname()->release,
13966 (int)strcspn(init_utsname()->version, " "),
13967 init_utsname()->version);
13968@@ -222,6 +222,8 @@ unsigned __kprobes long oops_begin(void)
13969 }
13970 EXPORT_SYMBOL_GPL(oops_begin);
13971
13972+extern void gr_handle_kernel_exploit(void);
13973+
13974 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
13975 {
13976 if (regs && kexec_should_crash(current))
13977@@ -243,7 +245,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
13978 panic("Fatal exception in interrupt");
13979 if (panic_on_oops)
13980 panic("Fatal exception");
13981- do_exit(signr);
13982+
13983+ gr_handle_kernel_exploit();
13984+
13985+ do_group_exit(signr);
13986 }
13987
13988 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
13989@@ -270,7 +275,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
13990
13991 show_registers(regs);
13992 #ifdef CONFIG_X86_32
13993- if (user_mode_vm(regs)) {
13994+ if (user_mode(regs)) {
13995 sp = regs->sp;
13996 ss = regs->ss & 0xffff;
13997 } else {
13998@@ -298,7 +303,7 @@ void die(const char *str, struct pt_regs *regs, long err)
13999 unsigned long flags = oops_begin();
14000 int sig = SIGSEGV;
14001
14002- if (!user_mode_vm(regs))
14003+ if (!user_mode(regs))
14004 report_bug(regs->ip, regs);
14005
14006 if (__die(str, regs, err))
14007diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14008index c99f9ed..2a15d80 100644
14009--- a/arch/x86/kernel/dumpstack_32.c
14010+++ b/arch/x86/kernel/dumpstack_32.c
14011@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14012 bp = stack_frame(task, regs);
14013
14014 for (;;) {
14015- struct thread_info *context;
14016+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14017
14018- context = (struct thread_info *)
14019- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14020- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14021+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14022
14023- stack = (unsigned long *)context->previous_esp;
14024- if (!stack)
14025+ if (stack_start == task_stack_page(task))
14026 break;
14027+ stack = *(unsigned long **)stack_start;
14028 if (ops->stack(data, "IRQ") < 0)
14029 break;
14030 touch_nmi_watchdog();
14031@@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
14032 * When in-kernel, we also print out the stack and code at the
14033 * time of the fault..
14034 */
14035- if (!user_mode_vm(regs)) {
14036+ if (!user_mode(regs)) {
14037 unsigned int code_prologue = code_bytes * 43 / 64;
14038 unsigned int code_len = code_bytes;
14039 unsigned char c;
14040 u8 *ip;
14041+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14042
14043 printk(KERN_EMERG "Stack:\n");
14044 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14045
14046 printk(KERN_EMERG "Code: ");
14047
14048- ip = (u8 *)regs->ip - code_prologue;
14049+ ip = (u8 *)regs->ip - code_prologue + cs_base;
14050 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14051 /* try starting at IP */
14052- ip = (u8 *)regs->ip;
14053+ ip = (u8 *)regs->ip + cs_base;
14054 code_len = code_len - code_prologue + 1;
14055 }
14056 for (i = 0; i < code_len; i++, ip++) {
14057@@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
14058 printk(KERN_CONT " Bad EIP value.");
14059 break;
14060 }
14061- if (ip == (u8 *)regs->ip)
14062+ if (ip == (u8 *)regs->ip + cs_base)
14063 printk(KERN_CONT "<%02x> ", c);
14064 else
14065 printk(KERN_CONT "%02x ", c);
14066@@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14067 {
14068 unsigned short ud2;
14069
14070+ ip = ktla_ktva(ip);
14071 if (ip < PAGE_OFFSET)
14072 return 0;
14073 if (probe_kernel_address((unsigned short *)ip, ud2))
14074@@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14075
14076 return ud2 == 0x0b0f;
14077 }
14078+
14079+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14080+void pax_check_alloca(unsigned long size)
14081+{
14082+ unsigned long sp = (unsigned long)&sp, stack_left;
14083+
14084+ /* all kernel stacks are of the same size */
14085+ stack_left = sp & (THREAD_SIZE - 1);
14086+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14087+}
14088+EXPORT_SYMBOL(pax_check_alloca);
14089+#endif
14090diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14091index 17107bd..b2deecf 100644
14092--- a/arch/x86/kernel/dumpstack_64.c
14093+++ b/arch/x86/kernel/dumpstack_64.c
14094@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14095 unsigned long *irq_stack_end =
14096 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14097 unsigned used = 0;
14098- struct thread_info *tinfo;
14099 int graph = 0;
14100 unsigned long dummy;
14101+ void *stack_start;
14102
14103 if (!task)
14104 task = current;
14105@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14106 * current stack address. If the stacks consist of nested
14107 * exceptions
14108 */
14109- tinfo = task_thread_info(task);
14110 for (;;) {
14111 char *id;
14112 unsigned long *estack_end;
14113+
14114 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14115 &used, &id);
14116
14117@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14118 if (ops->stack(data, id) < 0)
14119 break;
14120
14121- bp = ops->walk_stack(tinfo, stack, bp, ops,
14122+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14123 data, estack_end, &graph);
14124 ops->stack(data, "<EOE>");
14125 /*
14126@@ -172,7 +172,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14127 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14128 if (ops->stack(data, "IRQ") < 0)
14129 break;
14130- bp = ops->walk_stack(tinfo, stack, bp,
14131+ bp = ops->walk_stack(task, irq_stack, stack, bp,
14132 ops, data, irq_stack_end, &graph);
14133 /*
14134 * We link to the next stack (which would be
14135@@ -191,7 +191,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14136 /*
14137 * This handles the process stack:
14138 */
14139- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14140+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14141+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14142 put_cpu();
14143 }
14144 EXPORT_SYMBOL(dump_trace);
14145@@ -305,3 +306,50 @@ int is_valid_bugaddr(unsigned long ip)
14146
14147 return ud2 == 0x0b0f;
14148 }
14149+
14150+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14151+void pax_check_alloca(unsigned long size)
14152+{
14153+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14154+ unsigned cpu, used;
14155+ char *id;
14156+
14157+ /* check the process stack first */
14158+ stack_start = (unsigned long)task_stack_page(current);
14159+ stack_end = stack_start + THREAD_SIZE;
14160+ if (likely(stack_start <= sp && sp < stack_end)) {
14161+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
14162+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14163+ return;
14164+ }
14165+
14166+ cpu = get_cpu();
14167+
14168+ /* check the irq stacks */
14169+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14170+ stack_start = stack_end - IRQ_STACK_SIZE;
14171+ if (stack_start <= sp && sp < stack_end) {
14172+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14173+ put_cpu();
14174+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14175+ return;
14176+ }
14177+
14178+ /* check the exception stacks */
14179+ used = 0;
14180+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14181+ stack_start = stack_end - EXCEPTION_STKSZ;
14182+ if (stack_end && stack_start <= sp && sp < stack_end) {
14183+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14184+ put_cpu();
14185+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14186+ return;
14187+ }
14188+
14189+ put_cpu();
14190+
14191+ /* unknown stack */
14192+ BUG();
14193+}
14194+EXPORT_SYMBOL(pax_check_alloca);
14195+#endif
14196diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14197index 9b9f18b..9fcaa04 100644
14198--- a/arch/x86/kernel/early_printk.c
14199+++ b/arch/x86/kernel/early_printk.c
14200@@ -7,6 +7,7 @@
14201 #include <linux/pci_regs.h>
14202 #include <linux/pci_ids.h>
14203 #include <linux/errno.h>
14204+#include <linux/sched.h>
14205 #include <asm/io.h>
14206 #include <asm/processor.h>
14207 #include <asm/fcntl.h>
14208diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14209index 7b784f4..76aaad7 100644
14210--- a/arch/x86/kernel/entry_32.S
14211+++ b/arch/x86/kernel/entry_32.S
14212@@ -179,13 +179,146 @@
14213 /*CFI_REL_OFFSET gs, PT_GS*/
14214 .endm
14215 .macro SET_KERNEL_GS reg
14216+
14217+#ifdef CONFIG_CC_STACKPROTECTOR
14218 movl $(__KERNEL_STACK_CANARY), \reg
14219+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14220+ movl $(__USER_DS), \reg
14221+#else
14222+ xorl \reg, \reg
14223+#endif
14224+
14225 movl \reg, %gs
14226 .endm
14227
14228 #endif /* CONFIG_X86_32_LAZY_GS */
14229
14230-.macro SAVE_ALL
14231+.macro pax_enter_kernel
14232+#ifdef CONFIG_PAX_KERNEXEC
14233+ call pax_enter_kernel
14234+#endif
14235+.endm
14236+
14237+.macro pax_exit_kernel
14238+#ifdef CONFIG_PAX_KERNEXEC
14239+ call pax_exit_kernel
14240+#endif
14241+.endm
14242+
14243+#ifdef CONFIG_PAX_KERNEXEC
14244+ENTRY(pax_enter_kernel)
14245+#ifdef CONFIG_PARAVIRT
14246+ pushl %eax
14247+ pushl %ecx
14248+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14249+ mov %eax, %esi
14250+#else
14251+ mov %cr0, %esi
14252+#endif
14253+ bts $16, %esi
14254+ jnc 1f
14255+ mov %cs, %esi
14256+ cmp $__KERNEL_CS, %esi
14257+ jz 3f
14258+ ljmp $__KERNEL_CS, $3f
14259+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14260+2:
14261+#ifdef CONFIG_PARAVIRT
14262+ mov %esi, %eax
14263+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14264+#else
14265+ mov %esi, %cr0
14266+#endif
14267+3:
14268+#ifdef CONFIG_PARAVIRT
14269+ popl %ecx
14270+ popl %eax
14271+#endif
14272+ ret
14273+ENDPROC(pax_enter_kernel)
14274+
14275+ENTRY(pax_exit_kernel)
14276+#ifdef CONFIG_PARAVIRT
14277+ pushl %eax
14278+ pushl %ecx
14279+#endif
14280+ mov %cs, %esi
14281+ cmp $__KERNEXEC_KERNEL_CS, %esi
14282+ jnz 2f
14283+#ifdef CONFIG_PARAVIRT
14284+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14285+ mov %eax, %esi
14286+#else
14287+ mov %cr0, %esi
14288+#endif
14289+ btr $16, %esi
14290+ ljmp $__KERNEL_CS, $1f
14291+1:
14292+#ifdef CONFIG_PARAVIRT
14293+ mov %esi, %eax
14294+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14295+#else
14296+ mov %esi, %cr0
14297+#endif
14298+2:
14299+#ifdef CONFIG_PARAVIRT
14300+ popl %ecx
14301+ popl %eax
14302+#endif
14303+ ret
14304+ENDPROC(pax_exit_kernel)
14305+#endif
14306+
14307+.macro pax_erase_kstack
14308+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14309+ call pax_erase_kstack
14310+#endif
14311+.endm
14312+
14313+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14314+/*
14315+ * ebp: thread_info
14316+ * ecx, edx: can be clobbered
14317+ */
14318+ENTRY(pax_erase_kstack)
14319+ pushl %edi
14320+ pushl %eax
14321+
14322+ mov TI_lowest_stack(%ebp), %edi
14323+ mov $-0xBEEF, %eax
14324+ std
14325+
14326+1: mov %edi, %ecx
14327+ and $THREAD_SIZE_asm - 1, %ecx
14328+ shr $2, %ecx
14329+ repne scasl
14330+ jecxz 2f
14331+
14332+ cmp $2*16, %ecx
14333+ jc 2f
14334+
14335+ mov $2*16, %ecx
14336+ repe scasl
14337+ jecxz 2f
14338+ jne 1b
14339+
14340+2: cld
14341+ mov %esp, %ecx
14342+ sub %edi, %ecx
14343+ shr $2, %ecx
14344+ rep stosl
14345+
14346+ mov TI_task_thread_sp0(%ebp), %edi
14347+ sub $128, %edi
14348+ mov %edi, TI_lowest_stack(%ebp)
14349+
14350+ popl %eax
14351+ popl %edi
14352+ ret
14353+ENDPROC(pax_erase_kstack)
14354+#endif
14355+
14356+.macro __SAVE_ALL _DS
14357 cld
14358 PUSH_GS
14359 pushl_cfi %fs
14360@@ -208,7 +341,7 @@
14361 CFI_REL_OFFSET ecx, 0
14362 pushl_cfi %ebx
14363 CFI_REL_OFFSET ebx, 0
14364- movl $(__USER_DS), %edx
14365+ movl $\_DS, %edx
14366 movl %edx, %ds
14367 movl %edx, %es
14368 movl $(__KERNEL_PERCPU), %edx
14369@@ -216,6 +349,15 @@
14370 SET_KERNEL_GS %edx
14371 .endm
14372
14373+.macro SAVE_ALL
14374+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
14375+ __SAVE_ALL __KERNEL_DS
14376+ pax_enter_kernel
14377+#else
14378+ __SAVE_ALL __USER_DS
14379+#endif
14380+.endm
14381+
14382 .macro RESTORE_INT_REGS
14383 popl_cfi %ebx
14384 CFI_RESTORE ebx
14385@@ -301,7 +443,7 @@ ENTRY(ret_from_fork)
14386 popfl_cfi
14387 jmp syscall_exit
14388 CFI_ENDPROC
14389-END(ret_from_fork)
14390+ENDPROC(ret_from_fork)
14391
14392 /*
14393 * Interrupt exit functions should be protected against kprobes
14394@@ -335,7 +477,15 @@ resume_userspace_sig:
14395 andl $SEGMENT_RPL_MASK, %eax
14396 #endif
14397 cmpl $USER_RPL, %eax
14398+
14399+#ifdef CONFIG_PAX_KERNEXEC
14400+ jae resume_userspace
14401+
14402+ PAX_EXIT_KERNEL
14403+ jmp resume_kernel
14404+#else
14405 jb resume_kernel # not returning to v8086 or userspace
14406+#endif
14407
14408 ENTRY(resume_userspace)
14409 LOCKDEP_SYS_EXIT
14410@@ -347,8 +497,8 @@ ENTRY(resume_userspace)
14411 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
14412 # int/exception return?
14413 jne work_pending
14414- jmp restore_all
14415-END(ret_from_exception)
14416+ jmp restore_all_pax
14417+ENDPROC(ret_from_exception)
14418
14419 #ifdef CONFIG_PREEMPT
14420 ENTRY(resume_kernel)
14421@@ -363,7 +513,7 @@ need_resched:
14422 jz restore_all
14423 call preempt_schedule_irq
14424 jmp need_resched
14425-END(resume_kernel)
14426+ENDPROC(resume_kernel)
14427 #endif
14428 CFI_ENDPROC
14429 /*
14430@@ -397,23 +547,34 @@ sysenter_past_esp:
14431 /*CFI_REL_OFFSET cs, 0*/
14432 /*
14433 * Push current_thread_info()->sysenter_return to the stack.
14434- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
14435- * pushed above; +8 corresponds to copy_thread's esp0 setting.
14436 */
14437- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
14438+ pushl_cfi $0
14439 CFI_REL_OFFSET eip, 0
14440
14441 pushl_cfi %eax
14442 SAVE_ALL
14443+ GET_THREAD_INFO(%ebp)
14444+ movl TI_sysenter_return(%ebp),%ebp
14445+ movl %ebp,PT_EIP(%esp)
14446 ENABLE_INTERRUPTS(CLBR_NONE)
14447
14448 /*
14449 * Load the potential sixth argument from user stack.
14450 * Careful about security.
14451 */
14452+ movl PT_OLDESP(%esp),%ebp
14453+
14454+#ifdef CONFIG_PAX_MEMORY_UDEREF
14455+ mov PT_OLDSS(%esp),%ds
14456+1: movl %ds:(%ebp),%ebp
14457+ push %ss
14458+ pop %ds
14459+#else
14460 cmpl $__PAGE_OFFSET-3,%ebp
14461 jae syscall_fault
14462 1: movl (%ebp),%ebp
14463+#endif
14464+
14465 movl %ebp,PT_EBP(%esp)
14466 .section __ex_table,"a"
14467 .align 4
14468@@ -436,12 +597,24 @@ sysenter_do_call:
14469 testl $_TIF_ALLWORK_MASK, %ecx
14470 jne sysexit_audit
14471 sysenter_exit:
14472+
14473+#ifdef CONFIG_PAX_RANDKSTACK
14474+ pushl_cfi %eax
14475+ movl %esp, %eax
14476+ call pax_randomize_kstack
14477+ popl_cfi %eax
14478+#endif
14479+
14480+ pax_erase_kstack
14481+
14482 /* if something modifies registers it must also disable sysexit */
14483 movl PT_EIP(%esp), %edx
14484 movl PT_OLDESP(%esp), %ecx
14485 xorl %ebp,%ebp
14486 TRACE_IRQS_ON
14487 1: mov PT_FS(%esp), %fs
14488+2: mov PT_DS(%esp), %ds
14489+3: mov PT_ES(%esp), %es
14490 PTGS_TO_GS
14491 ENABLE_INTERRUPTS_SYSEXIT
14492
14493@@ -458,6 +631,9 @@ sysenter_audit:
14494 movl %eax,%edx /* 2nd arg: syscall number */
14495 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
14496 call __audit_syscall_entry
14497+
14498+ pax_erase_kstack
14499+
14500 pushl_cfi %ebx
14501 movl PT_EAX(%esp),%eax /* reload syscall number */
14502 jmp sysenter_do_call
14503@@ -483,11 +659,17 @@ sysexit_audit:
14504
14505 CFI_ENDPROC
14506 .pushsection .fixup,"ax"
14507-2: movl $0,PT_FS(%esp)
14508+4: movl $0,PT_FS(%esp)
14509+ jmp 1b
14510+5: movl $0,PT_DS(%esp)
14511+ jmp 1b
14512+6: movl $0,PT_ES(%esp)
14513 jmp 1b
14514 .section __ex_table,"a"
14515 .align 4
14516- .long 1b,2b
14517+ .long 1b,4b
14518+ .long 2b,5b
14519+ .long 3b,6b
14520 .popsection
14521 PTGS_TO_GS_EX
14522 ENDPROC(ia32_sysenter_target)
14523@@ -520,6 +702,15 @@ syscall_exit:
14524 testl $_TIF_ALLWORK_MASK, %ecx # current->work
14525 jne syscall_exit_work
14526
14527+restore_all_pax:
14528+
14529+#ifdef CONFIG_PAX_RANDKSTACK
14530+ movl %esp, %eax
14531+ call pax_randomize_kstack
14532+#endif
14533+
14534+ pax_erase_kstack
14535+
14536 restore_all:
14537 TRACE_IRQS_IRET
14538 restore_all_notrace:
14539@@ -579,14 +770,34 @@ ldt_ss:
14540 * compensating for the offset by changing to the ESPFIX segment with
14541 * a base address that matches for the difference.
14542 */
14543-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
14544+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
14545 mov %esp, %edx /* load kernel esp */
14546 mov PT_OLDESP(%esp), %eax /* load userspace esp */
14547 mov %dx, %ax /* eax: new kernel esp */
14548 sub %eax, %edx /* offset (low word is 0) */
14549+#ifdef CONFIG_SMP
14550+ movl PER_CPU_VAR(cpu_number), %ebx
14551+ shll $PAGE_SHIFT_asm, %ebx
14552+ addl $cpu_gdt_table, %ebx
14553+#else
14554+ movl $cpu_gdt_table, %ebx
14555+#endif
14556 shr $16, %edx
14557- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
14558- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
14559+
14560+#ifdef CONFIG_PAX_KERNEXEC
14561+ mov %cr0, %esi
14562+ btr $16, %esi
14563+ mov %esi, %cr0
14564+#endif
14565+
14566+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
14567+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
14568+
14569+#ifdef CONFIG_PAX_KERNEXEC
14570+ bts $16, %esi
14571+ mov %esi, %cr0
14572+#endif
14573+
14574 pushl_cfi $__ESPFIX_SS
14575 pushl_cfi %eax /* new kernel esp */
14576 /* Disable interrupts, but do not irqtrace this section: we
14577@@ -615,38 +826,30 @@ work_resched:
14578 movl TI_flags(%ebp), %ecx
14579 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
14580 # than syscall tracing?
14581- jz restore_all
14582+ jz restore_all_pax
14583 testb $_TIF_NEED_RESCHED, %cl
14584 jnz work_resched
14585
14586 work_notifysig: # deal with pending signals and
14587 # notify-resume requests
14588+ movl %esp, %eax
14589 #ifdef CONFIG_VM86
14590 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
14591- movl %esp, %eax
14592- jne work_notifysig_v86 # returning to kernel-space or
14593+ jz 1f # returning to kernel-space or
14594 # vm86-space
14595- TRACE_IRQS_ON
14596- ENABLE_INTERRUPTS(CLBR_NONE)
14597- xorl %edx, %edx
14598- call do_notify_resume
14599- jmp resume_userspace_sig
14600
14601- ALIGN
14602-work_notifysig_v86:
14603 pushl_cfi %ecx # save ti_flags for do_notify_resume
14604 call save_v86_state # %eax contains pt_regs pointer
14605 popl_cfi %ecx
14606 movl %eax, %esp
14607-#else
14608- movl %esp, %eax
14609+1:
14610 #endif
14611 TRACE_IRQS_ON
14612 ENABLE_INTERRUPTS(CLBR_NONE)
14613 xorl %edx, %edx
14614 call do_notify_resume
14615 jmp resume_userspace_sig
14616-END(work_pending)
14617+ENDPROC(work_pending)
14618
14619 # perform syscall exit tracing
14620 ALIGN
14621@@ -654,11 +857,14 @@ syscall_trace_entry:
14622 movl $-ENOSYS,PT_EAX(%esp)
14623 movl %esp, %eax
14624 call syscall_trace_enter
14625+
14626+ pax_erase_kstack
14627+
14628 /* What it returned is what we'll actually use. */
14629 cmpl $(NR_syscalls), %eax
14630 jnae syscall_call
14631 jmp syscall_exit
14632-END(syscall_trace_entry)
14633+ENDPROC(syscall_trace_entry)
14634
14635 # perform syscall exit tracing
14636 ALIGN
14637@@ -671,20 +877,24 @@ syscall_exit_work:
14638 movl %esp, %eax
14639 call syscall_trace_leave
14640 jmp resume_userspace
14641-END(syscall_exit_work)
14642+ENDPROC(syscall_exit_work)
14643 CFI_ENDPROC
14644
14645 RING0_INT_FRAME # can't unwind into user space anyway
14646 syscall_fault:
14647+#ifdef CONFIG_PAX_MEMORY_UDEREF
14648+ push %ss
14649+ pop %ds
14650+#endif
14651 GET_THREAD_INFO(%ebp)
14652 movl $-EFAULT,PT_EAX(%esp)
14653 jmp resume_userspace
14654-END(syscall_fault)
14655+ENDPROC(syscall_fault)
14656
14657 syscall_badsys:
14658 movl $-ENOSYS,PT_EAX(%esp)
14659 jmp resume_userspace
14660-END(syscall_badsys)
14661+ENDPROC(syscall_badsys)
14662 CFI_ENDPROC
14663 /*
14664 * End of kprobes section
14665@@ -756,6 +966,36 @@ ENTRY(ptregs_clone)
14666 CFI_ENDPROC
14667 ENDPROC(ptregs_clone)
14668
14669+ ALIGN;
14670+ENTRY(kernel_execve)
14671+ CFI_STARTPROC
14672+ pushl_cfi %ebp
14673+ sub $PT_OLDSS+4,%esp
14674+ pushl_cfi %edi
14675+ pushl_cfi %ecx
14676+ pushl_cfi %eax
14677+ lea 3*4(%esp),%edi
14678+ mov $PT_OLDSS/4+1,%ecx
14679+ xorl %eax,%eax
14680+ rep stosl
14681+ popl_cfi %eax
14682+ popl_cfi %ecx
14683+ popl_cfi %edi
14684+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
14685+ pushl_cfi %esp
14686+ call sys_execve
14687+ add $4,%esp
14688+ CFI_ADJUST_CFA_OFFSET -4
14689+ GET_THREAD_INFO(%ebp)
14690+ test %eax,%eax
14691+ jz syscall_exit
14692+ add $PT_OLDSS+4,%esp
14693+ CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
14694+ popl_cfi %ebp
14695+ ret
14696+ CFI_ENDPROC
14697+ENDPROC(kernel_execve)
14698+
14699 .macro FIXUP_ESPFIX_STACK
14700 /*
14701 * Switch back for ESPFIX stack to the normal zerobased stack
14702@@ -765,8 +1005,15 @@ ENDPROC(ptregs_clone)
14703 * normal stack and adjusts ESP with the matching offset.
14704 */
14705 /* fixup the stack */
14706- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
14707- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
14708+#ifdef CONFIG_SMP
14709+ movl PER_CPU_VAR(cpu_number), %ebx
14710+ shll $PAGE_SHIFT_asm, %ebx
14711+ addl $cpu_gdt_table, %ebx
14712+#else
14713+ movl $cpu_gdt_table, %ebx
14714+#endif
14715+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
14716+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
14717 shl $16, %eax
14718 addl %esp, %eax /* the adjusted stack pointer */
14719 pushl_cfi $__KERNEL_DS
14720@@ -819,7 +1066,7 @@ vector=vector+1
14721 .endr
14722 2: jmp common_interrupt
14723 .endr
14724-END(irq_entries_start)
14725+ENDPROC(irq_entries_start)
14726
14727 .previous
14728 END(interrupt)
14729@@ -867,7 +1114,7 @@ ENTRY(coprocessor_error)
14730 pushl_cfi $do_coprocessor_error
14731 jmp error_code
14732 CFI_ENDPROC
14733-END(coprocessor_error)
14734+ENDPROC(coprocessor_error)
14735
14736 ENTRY(simd_coprocessor_error)
14737 RING0_INT_FRAME
14738@@ -888,7 +1135,7 @@ ENTRY(simd_coprocessor_error)
14739 #endif
14740 jmp error_code
14741 CFI_ENDPROC
14742-END(simd_coprocessor_error)
14743+ENDPROC(simd_coprocessor_error)
14744
14745 ENTRY(device_not_available)
14746 RING0_INT_FRAME
14747@@ -896,7 +1143,7 @@ ENTRY(device_not_available)
14748 pushl_cfi $do_device_not_available
14749 jmp error_code
14750 CFI_ENDPROC
14751-END(device_not_available)
14752+ENDPROC(device_not_available)
14753
14754 #ifdef CONFIG_PARAVIRT
14755 ENTRY(native_iret)
14756@@ -905,12 +1152,12 @@ ENTRY(native_iret)
14757 .align 4
14758 .long native_iret, iret_exc
14759 .previous
14760-END(native_iret)
14761+ENDPROC(native_iret)
14762
14763 ENTRY(native_irq_enable_sysexit)
14764 sti
14765 sysexit
14766-END(native_irq_enable_sysexit)
14767+ENDPROC(native_irq_enable_sysexit)
14768 #endif
14769
14770 ENTRY(overflow)
14771@@ -919,7 +1166,7 @@ ENTRY(overflow)
14772 pushl_cfi $do_overflow
14773 jmp error_code
14774 CFI_ENDPROC
14775-END(overflow)
14776+ENDPROC(overflow)
14777
14778 ENTRY(bounds)
14779 RING0_INT_FRAME
14780@@ -927,7 +1174,7 @@ ENTRY(bounds)
14781 pushl_cfi $do_bounds
14782 jmp error_code
14783 CFI_ENDPROC
14784-END(bounds)
14785+ENDPROC(bounds)
14786
14787 ENTRY(invalid_op)
14788 RING0_INT_FRAME
14789@@ -935,7 +1182,7 @@ ENTRY(invalid_op)
14790 pushl_cfi $do_invalid_op
14791 jmp error_code
14792 CFI_ENDPROC
14793-END(invalid_op)
14794+ENDPROC(invalid_op)
14795
14796 ENTRY(coprocessor_segment_overrun)
14797 RING0_INT_FRAME
14798@@ -943,35 +1190,35 @@ ENTRY(coprocessor_segment_overrun)
14799 pushl_cfi $do_coprocessor_segment_overrun
14800 jmp error_code
14801 CFI_ENDPROC
14802-END(coprocessor_segment_overrun)
14803+ENDPROC(coprocessor_segment_overrun)
14804
14805 ENTRY(invalid_TSS)
14806 RING0_EC_FRAME
14807 pushl_cfi $do_invalid_TSS
14808 jmp error_code
14809 CFI_ENDPROC
14810-END(invalid_TSS)
14811+ENDPROC(invalid_TSS)
14812
14813 ENTRY(segment_not_present)
14814 RING0_EC_FRAME
14815 pushl_cfi $do_segment_not_present
14816 jmp error_code
14817 CFI_ENDPROC
14818-END(segment_not_present)
14819+ENDPROC(segment_not_present)
14820
14821 ENTRY(stack_segment)
14822 RING0_EC_FRAME
14823 pushl_cfi $do_stack_segment
14824 jmp error_code
14825 CFI_ENDPROC
14826-END(stack_segment)
14827+ENDPROC(stack_segment)
14828
14829 ENTRY(alignment_check)
14830 RING0_EC_FRAME
14831 pushl_cfi $do_alignment_check
14832 jmp error_code
14833 CFI_ENDPROC
14834-END(alignment_check)
14835+ENDPROC(alignment_check)
14836
14837 ENTRY(divide_error)
14838 RING0_INT_FRAME
14839@@ -979,7 +1226,7 @@ ENTRY(divide_error)
14840 pushl_cfi $do_divide_error
14841 jmp error_code
14842 CFI_ENDPROC
14843-END(divide_error)
14844+ENDPROC(divide_error)
14845
14846 #ifdef CONFIG_X86_MCE
14847 ENTRY(machine_check)
14848@@ -988,7 +1235,7 @@ ENTRY(machine_check)
14849 pushl_cfi machine_check_vector
14850 jmp error_code
14851 CFI_ENDPROC
14852-END(machine_check)
14853+ENDPROC(machine_check)
14854 #endif
14855
14856 ENTRY(spurious_interrupt_bug)
14857@@ -997,7 +1244,7 @@ ENTRY(spurious_interrupt_bug)
14858 pushl_cfi $do_spurious_interrupt_bug
14859 jmp error_code
14860 CFI_ENDPROC
14861-END(spurious_interrupt_bug)
14862+ENDPROC(spurious_interrupt_bug)
14863 /*
14864 * End of kprobes section
14865 */
14866@@ -1112,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
14867
14868 ENTRY(mcount)
14869 ret
14870-END(mcount)
14871+ENDPROC(mcount)
14872
14873 ENTRY(ftrace_caller)
14874 cmpl $0, function_trace_stop
14875@@ -1141,7 +1388,7 @@ ftrace_graph_call:
14876 .globl ftrace_stub
14877 ftrace_stub:
14878 ret
14879-END(ftrace_caller)
14880+ENDPROC(ftrace_caller)
14881
14882 #else /* ! CONFIG_DYNAMIC_FTRACE */
14883
14884@@ -1177,7 +1424,7 @@ trace:
14885 popl %ecx
14886 popl %eax
14887 jmp ftrace_stub
14888-END(mcount)
14889+ENDPROC(mcount)
14890 #endif /* CONFIG_DYNAMIC_FTRACE */
14891 #endif /* CONFIG_FUNCTION_TRACER */
14892
14893@@ -1198,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
14894 popl %ecx
14895 popl %eax
14896 ret
14897-END(ftrace_graph_caller)
14898+ENDPROC(ftrace_graph_caller)
14899
14900 .globl return_to_handler
14901 return_to_handler:
14902@@ -1253,15 +1500,18 @@ error_code:
14903 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
14904 REG_TO_PTGS %ecx
14905 SET_KERNEL_GS %ecx
14906- movl $(__USER_DS), %ecx
14907+ movl $(__KERNEL_DS), %ecx
14908 movl %ecx, %ds
14909 movl %ecx, %es
14910+
14911+ pax_enter_kernel
14912+
14913 TRACE_IRQS_OFF
14914 movl %esp,%eax # pt_regs pointer
14915 call *%edi
14916 jmp ret_from_exception
14917 CFI_ENDPROC
14918-END(page_fault)
14919+ENDPROC(page_fault)
14920
14921 /*
14922 * Debug traps and NMI can happen at the one SYSENTER instruction
14923@@ -1303,7 +1553,7 @@ debug_stack_correct:
14924 call do_debug
14925 jmp ret_from_exception
14926 CFI_ENDPROC
14927-END(debug)
14928+ENDPROC(debug)
14929
14930 /*
14931 * NMI is doubly nasty. It can happen _while_ we're handling
14932@@ -1340,6 +1590,9 @@ nmi_stack_correct:
14933 xorl %edx,%edx # zero error code
14934 movl %esp,%eax # pt_regs pointer
14935 call do_nmi
14936+
14937+ pax_exit_kernel
14938+
14939 jmp restore_all_notrace
14940 CFI_ENDPROC
14941
14942@@ -1376,12 +1629,15 @@ nmi_espfix_stack:
14943 FIXUP_ESPFIX_STACK # %eax == %esp
14944 xorl %edx,%edx # zero error code
14945 call do_nmi
14946+
14947+ pax_exit_kernel
14948+
14949 RESTORE_REGS
14950 lss 12+4(%esp), %esp # back to espfix stack
14951 CFI_ADJUST_CFA_OFFSET -24
14952 jmp irq_return
14953 CFI_ENDPROC
14954-END(nmi)
14955+ENDPROC(nmi)
14956
14957 ENTRY(int3)
14958 RING0_INT_FRAME
14959@@ -1393,14 +1649,14 @@ ENTRY(int3)
14960 call do_int3
14961 jmp ret_from_exception
14962 CFI_ENDPROC
14963-END(int3)
14964+ENDPROC(int3)
14965
14966 ENTRY(general_protection)
14967 RING0_EC_FRAME
14968 pushl_cfi $do_general_protection
14969 jmp error_code
14970 CFI_ENDPROC
14971-END(general_protection)
14972+ENDPROC(general_protection)
14973
14974 #ifdef CONFIG_KVM_GUEST
14975 ENTRY(async_page_fault)
14976@@ -1408,7 +1664,7 @@ ENTRY(async_page_fault)
14977 pushl_cfi $do_async_page_fault
14978 jmp error_code
14979 CFI_ENDPROC
14980-END(async_page_fault)
14981+ENDPROC(async_page_fault)
14982 #endif
14983
14984 /*
14985diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
14986index 1333d98..b340ca2 100644
14987--- a/arch/x86/kernel/entry_64.S
14988+++ b/arch/x86/kernel/entry_64.S
14989@@ -56,6 +56,8 @@
14990 #include <asm/ftrace.h>
14991 #include <asm/percpu.h>
14992 #include <linux/err.h>
14993+#include <asm/pgtable.h>
14994+#include <asm/alternative-asm.h>
14995
14996 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14997 #include <linux/elf-em.h>
14998@@ -69,8 +71,9 @@
14999 #ifdef CONFIG_FUNCTION_TRACER
15000 #ifdef CONFIG_DYNAMIC_FTRACE
15001 ENTRY(mcount)
15002+ pax_force_retaddr
15003 retq
15004-END(mcount)
15005+ENDPROC(mcount)
15006
15007 ENTRY(ftrace_caller)
15008 cmpl $0, function_trace_stop
15009@@ -93,8 +96,9 @@ GLOBAL(ftrace_graph_call)
15010 #endif
15011
15012 GLOBAL(ftrace_stub)
15013+ pax_force_retaddr
15014 retq
15015-END(ftrace_caller)
15016+ENDPROC(ftrace_caller)
15017
15018 #else /* ! CONFIG_DYNAMIC_FTRACE */
15019 ENTRY(mcount)
15020@@ -113,6 +117,7 @@ ENTRY(mcount)
15021 #endif
15022
15023 GLOBAL(ftrace_stub)
15024+ pax_force_retaddr
15025 retq
15026
15027 trace:
15028@@ -122,12 +127,13 @@ trace:
15029 movq 8(%rbp), %rsi
15030 subq $MCOUNT_INSN_SIZE, %rdi
15031
15032+ pax_force_fptr ftrace_trace_function
15033 call *ftrace_trace_function
15034
15035 MCOUNT_RESTORE_FRAME
15036
15037 jmp ftrace_stub
15038-END(mcount)
15039+ENDPROC(mcount)
15040 #endif /* CONFIG_DYNAMIC_FTRACE */
15041 #endif /* CONFIG_FUNCTION_TRACER */
15042
15043@@ -147,8 +153,9 @@ ENTRY(ftrace_graph_caller)
15044
15045 MCOUNT_RESTORE_FRAME
15046
15047+ pax_force_retaddr
15048 retq
15049-END(ftrace_graph_caller)
15050+ENDPROC(ftrace_graph_caller)
15051
15052 GLOBAL(return_to_handler)
15053 subq $24, %rsp
15054@@ -164,6 +171,7 @@ GLOBAL(return_to_handler)
15055 movq 8(%rsp), %rdx
15056 movq (%rsp), %rax
15057 addq $24, %rsp
15058+ pax_force_fptr %rdi
15059 jmp *%rdi
15060 #endif
15061
15062@@ -179,6 +187,282 @@ ENTRY(native_usergs_sysret64)
15063 ENDPROC(native_usergs_sysret64)
15064 #endif /* CONFIG_PARAVIRT */
15065
15066+ .macro ljmpq sel, off
15067+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15068+ .byte 0x48; ljmp *1234f(%rip)
15069+ .pushsection .rodata
15070+ .align 16
15071+ 1234: .quad \off; .word \sel
15072+ .popsection
15073+#else
15074+ pushq $\sel
15075+ pushq $\off
15076+ lretq
15077+#endif
15078+ .endm
15079+
15080+ .macro pax_enter_kernel
15081+ pax_set_fptr_mask
15082+#ifdef CONFIG_PAX_KERNEXEC
15083+ call pax_enter_kernel
15084+#endif
15085+ .endm
15086+
15087+ .macro pax_exit_kernel
15088+#ifdef CONFIG_PAX_KERNEXEC
15089+ call pax_exit_kernel
15090+#endif
15091+ .endm
15092+
15093+#ifdef CONFIG_PAX_KERNEXEC
15094+ENTRY(pax_enter_kernel)
15095+ pushq %rdi
15096+
15097+#ifdef CONFIG_PARAVIRT
15098+ PV_SAVE_REGS(CLBR_RDI)
15099+#endif
15100+
15101+ GET_CR0_INTO_RDI
15102+ bts $16,%rdi
15103+ jnc 3f
15104+ mov %cs,%edi
15105+ cmp $__KERNEL_CS,%edi
15106+ jnz 2f
15107+1:
15108+
15109+#ifdef CONFIG_PARAVIRT
15110+ PV_RESTORE_REGS(CLBR_RDI)
15111+#endif
15112+
15113+ popq %rdi
15114+ pax_force_retaddr
15115+ retq
15116+
15117+2: ljmpq __KERNEL_CS,1f
15118+3: ljmpq __KERNEXEC_KERNEL_CS,4f
15119+4: SET_RDI_INTO_CR0
15120+ jmp 1b
15121+ENDPROC(pax_enter_kernel)
15122+
15123+ENTRY(pax_exit_kernel)
15124+ pushq %rdi
15125+
15126+#ifdef CONFIG_PARAVIRT
15127+ PV_SAVE_REGS(CLBR_RDI)
15128+#endif
15129+
15130+ mov %cs,%rdi
15131+ cmp $__KERNEXEC_KERNEL_CS,%edi
15132+ jz 2f
15133+1:
15134+
15135+#ifdef CONFIG_PARAVIRT
15136+ PV_RESTORE_REGS(CLBR_RDI);
15137+#endif
15138+
15139+ popq %rdi
15140+ pax_force_retaddr
15141+ retq
15142+
15143+2: GET_CR0_INTO_RDI
15144+ btr $16,%rdi
15145+ ljmpq __KERNEL_CS,3f
15146+3: SET_RDI_INTO_CR0
15147+ jmp 1b
15148+#ifdef CONFIG_PARAVIRT
15149+ PV_RESTORE_REGS(CLBR_RDI);
15150+#endif
15151+
15152+ popq %rdi
15153+ pax_force_retaddr
15154+ retq
15155+ENDPROC(pax_exit_kernel)
15156+#endif
15157+
15158+ .macro pax_enter_kernel_user
15159+ pax_set_fptr_mask
15160+#ifdef CONFIG_PAX_MEMORY_UDEREF
15161+ call pax_enter_kernel_user
15162+#endif
15163+ .endm
15164+
15165+ .macro pax_exit_kernel_user
15166+#ifdef CONFIG_PAX_MEMORY_UDEREF
15167+ call pax_exit_kernel_user
15168+#endif
15169+#ifdef CONFIG_PAX_RANDKSTACK
15170+ pushq %rax
15171+ call pax_randomize_kstack
15172+ popq %rax
15173+#endif
15174+ .endm
15175+
15176+#ifdef CONFIG_PAX_MEMORY_UDEREF
15177+ENTRY(pax_enter_kernel_user)
15178+ pushq %rdi
15179+ pushq %rbx
15180+
15181+#ifdef CONFIG_PARAVIRT
15182+ PV_SAVE_REGS(CLBR_RDI)
15183+#endif
15184+
15185+ GET_CR3_INTO_RDI
15186+ mov %rdi,%rbx
15187+ add $__START_KERNEL_map,%rbx
15188+ sub phys_base(%rip),%rbx
15189+
15190+#ifdef CONFIG_PARAVIRT
15191+ pushq %rdi
15192+ cmpl $0, pv_info+PARAVIRT_enabled
15193+ jz 1f
15194+ i = 0
15195+ .rept USER_PGD_PTRS
15196+ mov i*8(%rbx),%rsi
15197+ mov $0,%sil
15198+ lea i*8(%rbx),%rdi
15199+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15200+ i = i + 1
15201+ .endr
15202+ jmp 2f
15203+1:
15204+#endif
15205+
15206+ i = 0
15207+ .rept USER_PGD_PTRS
15208+ movb $0,i*8(%rbx)
15209+ i = i + 1
15210+ .endr
15211+
15212+#ifdef CONFIG_PARAVIRT
15213+2: popq %rdi
15214+#endif
15215+ SET_RDI_INTO_CR3
15216+
15217+#ifdef CONFIG_PAX_KERNEXEC
15218+ GET_CR0_INTO_RDI
15219+ bts $16,%rdi
15220+ SET_RDI_INTO_CR0
15221+#endif
15222+
15223+#ifdef CONFIG_PARAVIRT
15224+ PV_RESTORE_REGS(CLBR_RDI)
15225+#endif
15226+
15227+ popq %rbx
15228+ popq %rdi
15229+ pax_force_retaddr
15230+ retq
15231+ENDPROC(pax_enter_kernel_user)
15232+
15233+ENTRY(pax_exit_kernel_user)
15234+ push %rdi
15235+
15236+#ifdef CONFIG_PARAVIRT
15237+ pushq %rbx
15238+ PV_SAVE_REGS(CLBR_RDI)
15239+#endif
15240+
15241+#ifdef CONFIG_PAX_KERNEXEC
15242+ GET_CR0_INTO_RDI
15243+ btr $16,%rdi
15244+ SET_RDI_INTO_CR0
15245+#endif
15246+
15247+ GET_CR3_INTO_RDI
15248+ add $__START_KERNEL_map,%rdi
15249+ sub phys_base(%rip),%rdi
15250+
15251+#ifdef CONFIG_PARAVIRT
15252+ cmpl $0, pv_info+PARAVIRT_enabled
15253+ jz 1f
15254+ mov %rdi,%rbx
15255+ i = 0
15256+ .rept USER_PGD_PTRS
15257+ mov i*8(%rbx),%rsi
15258+ mov $0x67,%sil
15259+ lea i*8(%rbx),%rdi
15260+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15261+ i = i + 1
15262+ .endr
15263+ jmp 2f
15264+1:
15265+#endif
15266+
15267+ i = 0
15268+ .rept USER_PGD_PTRS
15269+ movb $0x67,i*8(%rdi)
15270+ i = i + 1
15271+ .endr
15272+
15273+#ifdef CONFIG_PARAVIRT
15274+2: PV_RESTORE_REGS(CLBR_RDI)
15275+ popq %rbx
15276+#endif
15277+
15278+ popq %rdi
15279+ pax_force_retaddr
15280+ retq
15281+ENDPROC(pax_exit_kernel_user)
15282+#endif
15283+
15284+.macro pax_erase_kstack
15285+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15286+ call pax_erase_kstack
15287+#endif
15288+.endm
15289+
15290+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15291+/*
15292+ * r11: thread_info
15293+ * rcx, rdx: can be clobbered
15294+ */
15295+ENTRY(pax_erase_kstack)
15296+ pushq %rdi
15297+ pushq %rax
15298+ pushq %r11
15299+
15300+ GET_THREAD_INFO(%r11)
15301+ mov TI_lowest_stack(%r11), %rdi
15302+ mov $-0xBEEF, %rax
15303+ std
15304+
15305+1: mov %edi, %ecx
15306+ and $THREAD_SIZE_asm - 1, %ecx
15307+ shr $3, %ecx
15308+ repne scasq
15309+ jecxz 2f
15310+
15311+ cmp $2*8, %ecx
15312+ jc 2f
15313+
15314+ mov $2*8, %ecx
15315+ repe scasq
15316+ jecxz 2f
15317+ jne 1b
15318+
15319+2: cld
15320+ mov %esp, %ecx
15321+ sub %edi, %ecx
15322+
15323+ cmp $THREAD_SIZE_asm, %rcx
15324+ jb 3f
15325+ ud2
15326+3:
15327+
15328+ shr $3, %ecx
15329+ rep stosq
15330+
15331+ mov TI_task_thread_sp0(%r11), %rdi
15332+ sub $256, %rdi
15333+ mov %rdi, TI_lowest_stack(%r11)
15334+
15335+ popq %r11
15336+ popq %rax
15337+ popq %rdi
15338+ pax_force_retaddr
15339+ ret
15340+ENDPROC(pax_erase_kstack)
15341+#endif
15342
15343 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
15344 #ifdef CONFIG_TRACE_IRQFLAGS
15345@@ -232,8 +516,8 @@ ENDPROC(native_usergs_sysret64)
15346 .endm
15347
15348 .macro UNFAKE_STACK_FRAME
15349- addq $8*6, %rsp
15350- CFI_ADJUST_CFA_OFFSET -(6*8)
15351+ addq $8*6 + ARG_SKIP, %rsp
15352+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
15353 .endm
15354
15355 /*
15356@@ -320,7 +604,7 @@ ENDPROC(native_usergs_sysret64)
15357 movq %rsp, %rsi
15358
15359 leaq -RBP(%rsp),%rdi /* arg1 for handler */
15360- testl $3, CS(%rdi)
15361+ testb $3, CS(%rdi)
15362 je 1f
15363 SWAPGS
15364 /*
15365@@ -356,9 +640,10 @@ ENTRY(save_rest)
15366 movq_cfi r15, R15+16
15367 movq %r11, 8(%rsp) /* return address */
15368 FIXUP_TOP_OF_STACK %r11, 16
15369+ pax_force_retaddr
15370 ret
15371 CFI_ENDPROC
15372-END(save_rest)
15373+ENDPROC(save_rest)
15374
15375 /* save complete stack frame */
15376 .pushsection .kprobes.text, "ax"
15377@@ -387,9 +672,10 @@ ENTRY(save_paranoid)
15378 js 1f /* negative -> in kernel */
15379 SWAPGS
15380 xorl %ebx,%ebx
15381-1: ret
15382+1: pax_force_retaddr_bts
15383+ ret
15384 CFI_ENDPROC
15385-END(save_paranoid)
15386+ENDPROC(save_paranoid)
15387 .popsection
15388
15389 /*
15390@@ -411,7 +697,7 @@ ENTRY(ret_from_fork)
15391
15392 RESTORE_REST
15393
15394- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15395+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15396 jz retint_restore_args
15397
15398 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
15399@@ -421,7 +707,7 @@ ENTRY(ret_from_fork)
15400 jmp ret_from_sys_call # go to the SYSRET fastpath
15401
15402 CFI_ENDPROC
15403-END(ret_from_fork)
15404+ENDPROC(ret_from_fork)
15405
15406 /*
15407 * System call entry. Up to 6 arguments in registers are supported.
15408@@ -457,7 +743,7 @@ END(ret_from_fork)
15409 ENTRY(system_call)
15410 CFI_STARTPROC simple
15411 CFI_SIGNAL_FRAME
15412- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15413+ CFI_DEF_CFA rsp,0
15414 CFI_REGISTER rip,rcx
15415 /*CFI_REGISTER rflags,r11*/
15416 SWAPGS_UNSAFE_STACK
15417@@ -470,21 +756,23 @@ GLOBAL(system_call_after_swapgs)
15418
15419 movq %rsp,PER_CPU_VAR(old_rsp)
15420 movq PER_CPU_VAR(kernel_stack),%rsp
15421+ SAVE_ARGS 8*6,0
15422+ pax_enter_kernel_user
15423 /*
15424 * No need to follow this irqs off/on section - it's straight
15425 * and short:
15426 */
15427 ENABLE_INTERRUPTS(CLBR_NONE)
15428- SAVE_ARGS 8,0
15429 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15430 movq %rcx,RIP-ARGOFFSET(%rsp)
15431 CFI_REL_OFFSET rip,RIP-ARGOFFSET
15432- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15433+ GET_THREAD_INFO(%rcx)
15434+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
15435 jnz tracesys
15436 system_call_fastpath:
15437 cmpq $__NR_syscall_max,%rax
15438 ja badsys
15439- movq %r10,%rcx
15440+ movq R10-ARGOFFSET(%rsp),%rcx
15441 call *sys_call_table(,%rax,8) # XXX: rip relative
15442 movq %rax,RAX-ARGOFFSET(%rsp)
15443 /*
15444@@ -498,10 +786,13 @@ sysret_check:
15445 LOCKDEP_SYS_EXIT
15446 DISABLE_INTERRUPTS(CLBR_NONE)
15447 TRACE_IRQS_OFF
15448- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
15449+ GET_THREAD_INFO(%rcx)
15450+ movl TI_flags(%rcx),%edx
15451 andl %edi,%edx
15452 jnz sysret_careful
15453 CFI_REMEMBER_STATE
15454+ pax_exit_kernel_user
15455+ pax_erase_kstack
15456 /*
15457 * sysretq will re-enable interrupts:
15458 */
15459@@ -553,14 +844,18 @@ badsys:
15460 * jump back to the normal fast path.
15461 */
15462 auditsys:
15463- movq %r10,%r9 /* 6th arg: 4th syscall arg */
15464+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
15465 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
15466 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
15467 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
15468 movq %rax,%rsi /* 2nd arg: syscall number */
15469 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
15470 call __audit_syscall_entry
15471+
15472+ pax_erase_kstack
15473+
15474 LOAD_ARGS 0 /* reload call-clobbered registers */
15475+ pax_set_fptr_mask
15476 jmp system_call_fastpath
15477
15478 /*
15479@@ -581,7 +876,7 @@ sysret_audit:
15480 /* Do syscall tracing */
15481 tracesys:
15482 #ifdef CONFIG_AUDITSYSCALL
15483- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15484+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
15485 jz auditsys
15486 #endif
15487 SAVE_REST
15488@@ -589,16 +884,20 @@ tracesys:
15489 FIXUP_TOP_OF_STACK %rdi
15490 movq %rsp,%rdi
15491 call syscall_trace_enter
15492+
15493+ pax_erase_kstack
15494+
15495 /*
15496 * Reload arg registers from stack in case ptrace changed them.
15497 * We don't reload %rax because syscall_trace_enter() returned
15498 * the value it wants us to use in the table lookup.
15499 */
15500 LOAD_ARGS ARGOFFSET, 1
15501+ pax_set_fptr_mask
15502 RESTORE_REST
15503 cmpq $__NR_syscall_max,%rax
15504 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
15505- movq %r10,%rcx /* fixup for C */
15506+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
15507 call *sys_call_table(,%rax,8)
15508 movq %rax,RAX-ARGOFFSET(%rsp)
15509 /* Use IRET because user could have changed frame */
15510@@ -619,6 +918,7 @@ GLOBAL(int_with_check)
15511 andl %edi,%edx
15512 jnz int_careful
15513 andl $~TS_COMPAT,TI_status(%rcx)
15514+ pax_erase_kstack
15515 jmp retint_swapgs
15516
15517 /* Either reschedule or signal or syscall exit tracking needed. */
15518@@ -665,7 +965,7 @@ int_restore_rest:
15519 TRACE_IRQS_OFF
15520 jmp int_with_check
15521 CFI_ENDPROC
15522-END(system_call)
15523+ENDPROC(system_call)
15524
15525 /*
15526 * Certain special system calls that need to save a complete full stack frame.
15527@@ -681,7 +981,7 @@ ENTRY(\label)
15528 call \func
15529 jmp ptregscall_common
15530 CFI_ENDPROC
15531-END(\label)
15532+ENDPROC(\label)
15533 .endm
15534
15535 PTREGSCALL stub_clone, sys_clone, %r8
15536@@ -699,9 +999,10 @@ ENTRY(ptregscall_common)
15537 movq_cfi_restore R12+8, r12
15538 movq_cfi_restore RBP+8, rbp
15539 movq_cfi_restore RBX+8, rbx
15540+ pax_force_retaddr
15541 ret $REST_SKIP /* pop extended registers */
15542 CFI_ENDPROC
15543-END(ptregscall_common)
15544+ENDPROC(ptregscall_common)
15545
15546 ENTRY(stub_execve)
15547 CFI_STARTPROC
15548@@ -716,7 +1017,7 @@ ENTRY(stub_execve)
15549 RESTORE_REST
15550 jmp int_ret_from_sys_call
15551 CFI_ENDPROC
15552-END(stub_execve)
15553+ENDPROC(stub_execve)
15554
15555 /*
15556 * sigreturn is special because it needs to restore all registers on return.
15557@@ -734,7 +1035,7 @@ ENTRY(stub_rt_sigreturn)
15558 RESTORE_REST
15559 jmp int_ret_from_sys_call
15560 CFI_ENDPROC
15561-END(stub_rt_sigreturn)
15562+ENDPROC(stub_rt_sigreturn)
15563
15564 /*
15565 * Build the entry stubs and pointer table with some assembler magic.
15566@@ -769,7 +1070,7 @@ vector=vector+1
15567 2: jmp common_interrupt
15568 .endr
15569 CFI_ENDPROC
15570-END(irq_entries_start)
15571+ENDPROC(irq_entries_start)
15572
15573 .previous
15574 END(interrupt)
15575@@ -789,6 +1090,16 @@ END(interrupt)
15576 subq $ORIG_RAX-RBP, %rsp
15577 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
15578 SAVE_ARGS_IRQ
15579+#ifdef CONFIG_PAX_MEMORY_UDEREF
15580+ testb $3, CS(%rdi)
15581+ jnz 1f
15582+ pax_enter_kernel
15583+ jmp 2f
15584+1: pax_enter_kernel_user
15585+2:
15586+#else
15587+ pax_enter_kernel
15588+#endif
15589 call \func
15590 .endm
15591
15592@@ -820,7 +1131,7 @@ ret_from_intr:
15593
15594 exit_intr:
15595 GET_THREAD_INFO(%rcx)
15596- testl $3,CS-ARGOFFSET(%rsp)
15597+ testb $3,CS-ARGOFFSET(%rsp)
15598 je retint_kernel
15599
15600 /* Interrupt came from user space */
15601@@ -842,12 +1153,15 @@ retint_swapgs: /* return to user-space */
15602 * The iretq could re-enable interrupts:
15603 */
15604 DISABLE_INTERRUPTS(CLBR_ANY)
15605+ pax_exit_kernel_user
15606 TRACE_IRQS_IRETQ
15607 SWAPGS
15608 jmp restore_args
15609
15610 retint_restore_args: /* return to kernel space */
15611 DISABLE_INTERRUPTS(CLBR_ANY)
15612+ pax_exit_kernel
15613+ pax_force_retaddr RIP-ARGOFFSET
15614 /*
15615 * The iretq could re-enable interrupts:
15616 */
15617@@ -936,7 +1250,7 @@ ENTRY(retint_kernel)
15618 #endif
15619
15620 CFI_ENDPROC
15621-END(common_interrupt)
15622+ENDPROC(common_interrupt)
15623 /*
15624 * End of kprobes section
15625 */
15626@@ -953,7 +1267,7 @@ ENTRY(\sym)
15627 interrupt \do_sym
15628 jmp ret_from_intr
15629 CFI_ENDPROC
15630-END(\sym)
15631+ENDPROC(\sym)
15632 .endm
15633
15634 #ifdef CONFIG_SMP
15635@@ -1026,12 +1340,22 @@ ENTRY(\sym)
15636 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15637 call error_entry
15638 DEFAULT_FRAME 0
15639+#ifdef CONFIG_PAX_MEMORY_UDEREF
15640+ testb $3, CS(%rsp)
15641+ jnz 1f
15642+ pax_enter_kernel
15643+ jmp 2f
15644+1: pax_enter_kernel_user
15645+2:
15646+#else
15647+ pax_enter_kernel
15648+#endif
15649 movq %rsp,%rdi /* pt_regs pointer */
15650 xorl %esi,%esi /* no error code */
15651 call \do_sym
15652 jmp error_exit /* %ebx: no swapgs flag */
15653 CFI_ENDPROC
15654-END(\sym)
15655+ENDPROC(\sym)
15656 .endm
15657
15658 .macro paranoidzeroentry sym do_sym
15659@@ -1043,15 +1367,25 @@ ENTRY(\sym)
15660 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15661 call save_paranoid
15662 TRACE_IRQS_OFF
15663+#ifdef CONFIG_PAX_MEMORY_UDEREF
15664+ testb $3, CS(%rsp)
15665+ jnz 1f
15666+ pax_enter_kernel
15667+ jmp 2f
15668+1: pax_enter_kernel_user
15669+2:
15670+#else
15671+ pax_enter_kernel
15672+#endif
15673 movq %rsp,%rdi /* pt_regs pointer */
15674 xorl %esi,%esi /* no error code */
15675 call \do_sym
15676 jmp paranoid_exit /* %ebx: no swapgs flag */
15677 CFI_ENDPROC
15678-END(\sym)
15679+ENDPROC(\sym)
15680 .endm
15681
15682-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
15683+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
15684 .macro paranoidzeroentry_ist sym do_sym ist
15685 ENTRY(\sym)
15686 INTR_FRAME
15687@@ -1061,14 +1395,30 @@ ENTRY(\sym)
15688 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15689 call save_paranoid
15690 TRACE_IRQS_OFF
15691+#ifdef CONFIG_PAX_MEMORY_UDEREF
15692+ testb $3, CS(%rsp)
15693+ jnz 1f
15694+ pax_enter_kernel
15695+ jmp 2f
15696+1: pax_enter_kernel_user
15697+2:
15698+#else
15699+ pax_enter_kernel
15700+#endif
15701 movq %rsp,%rdi /* pt_regs pointer */
15702 xorl %esi,%esi /* no error code */
15703+#ifdef CONFIG_SMP
15704+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
15705+ lea init_tss(%r12), %r12
15706+#else
15707+ lea init_tss(%rip), %r12
15708+#endif
15709 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
15710 call \do_sym
15711 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
15712 jmp paranoid_exit /* %ebx: no swapgs flag */
15713 CFI_ENDPROC
15714-END(\sym)
15715+ENDPROC(\sym)
15716 .endm
15717
15718 .macro errorentry sym do_sym
15719@@ -1079,13 +1429,23 @@ ENTRY(\sym)
15720 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
15721 call error_entry
15722 DEFAULT_FRAME 0
15723+#ifdef CONFIG_PAX_MEMORY_UDEREF
15724+ testb $3, CS(%rsp)
15725+ jnz 1f
15726+ pax_enter_kernel
15727+ jmp 2f
15728+1: pax_enter_kernel_user
15729+2:
15730+#else
15731+ pax_enter_kernel
15732+#endif
15733 movq %rsp,%rdi /* pt_regs pointer */
15734 movq ORIG_RAX(%rsp),%rsi /* get error code */
15735 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
15736 call \do_sym
15737 jmp error_exit /* %ebx: no swapgs flag */
15738 CFI_ENDPROC
15739-END(\sym)
15740+ENDPROC(\sym)
15741 .endm
15742
15743 /* error code is on the stack already */
15744@@ -1098,13 +1458,23 @@ ENTRY(\sym)
15745 call save_paranoid
15746 DEFAULT_FRAME 0
15747 TRACE_IRQS_OFF
15748+#ifdef CONFIG_PAX_MEMORY_UDEREF
15749+ testb $3, CS(%rsp)
15750+ jnz 1f
15751+ pax_enter_kernel
15752+ jmp 2f
15753+1: pax_enter_kernel_user
15754+2:
15755+#else
15756+ pax_enter_kernel
15757+#endif
15758 movq %rsp,%rdi /* pt_regs pointer */
15759 movq ORIG_RAX(%rsp),%rsi /* get error code */
15760 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
15761 call \do_sym
15762 jmp paranoid_exit /* %ebx: no swapgs flag */
15763 CFI_ENDPROC
15764-END(\sym)
15765+ENDPROC(\sym)
15766 .endm
15767
15768 zeroentry divide_error do_divide_error
15769@@ -1134,9 +1504,10 @@ gs_change:
15770 2: mfence /* workaround */
15771 SWAPGS
15772 popfq_cfi
15773+ pax_force_retaddr
15774 ret
15775 CFI_ENDPROC
15776-END(native_load_gs_index)
15777+ENDPROC(native_load_gs_index)
15778
15779 .section __ex_table,"a"
15780 .align 8
15781@@ -1158,13 +1529,14 @@ ENTRY(kernel_thread_helper)
15782 * Here we are in the child and the registers are set as they were
15783 * at kernel_thread() invocation in the parent.
15784 */
15785+ pax_force_fptr %rsi
15786 call *%rsi
15787 # exit
15788 mov %eax, %edi
15789 call do_exit
15790 ud2 # padding for call trace
15791 CFI_ENDPROC
15792-END(kernel_thread_helper)
15793+ENDPROC(kernel_thread_helper)
15794
15795 /*
15796 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
15797@@ -1191,11 +1563,11 @@ ENTRY(kernel_execve)
15798 RESTORE_REST
15799 testq %rax,%rax
15800 je int_ret_from_sys_call
15801- RESTORE_ARGS
15802 UNFAKE_STACK_FRAME
15803+ pax_force_retaddr
15804 ret
15805 CFI_ENDPROC
15806-END(kernel_execve)
15807+ENDPROC(kernel_execve)
15808
15809 /* Call softirq on interrupt stack. Interrupts are off. */
15810 ENTRY(call_softirq)
15811@@ -1213,9 +1585,10 @@ ENTRY(call_softirq)
15812 CFI_DEF_CFA_REGISTER rsp
15813 CFI_ADJUST_CFA_OFFSET -8
15814 decl PER_CPU_VAR(irq_count)
15815+ pax_force_retaddr
15816 ret
15817 CFI_ENDPROC
15818-END(call_softirq)
15819+ENDPROC(call_softirq)
15820
15821 #ifdef CONFIG_XEN
15822 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
15823@@ -1253,7 +1626,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
15824 decl PER_CPU_VAR(irq_count)
15825 jmp error_exit
15826 CFI_ENDPROC
15827-END(xen_do_hypervisor_callback)
15828+ENDPROC(xen_do_hypervisor_callback)
15829
15830 /*
15831 * Hypervisor uses this for application faults while it executes.
15832@@ -1312,7 +1685,7 @@ ENTRY(xen_failsafe_callback)
15833 SAVE_ALL
15834 jmp error_exit
15835 CFI_ENDPROC
15836-END(xen_failsafe_callback)
15837+ENDPROC(xen_failsafe_callback)
15838
15839 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
15840 xen_hvm_callback_vector xen_evtchn_do_upcall
15841@@ -1361,16 +1734,31 @@ ENTRY(paranoid_exit)
15842 TRACE_IRQS_OFF
15843 testl %ebx,%ebx /* swapgs needed? */
15844 jnz paranoid_restore
15845- testl $3,CS(%rsp)
15846+ testb $3,CS(%rsp)
15847 jnz paranoid_userspace
15848+#ifdef CONFIG_PAX_MEMORY_UDEREF
15849+ pax_exit_kernel
15850+ TRACE_IRQS_IRETQ 0
15851+ SWAPGS_UNSAFE_STACK
15852+ RESTORE_ALL 8
15853+ pax_force_retaddr_bts
15854+ jmp irq_return
15855+#endif
15856 paranoid_swapgs:
15857+#ifdef CONFIG_PAX_MEMORY_UDEREF
15858+ pax_exit_kernel_user
15859+#else
15860+ pax_exit_kernel
15861+#endif
15862 TRACE_IRQS_IRETQ 0
15863 SWAPGS_UNSAFE_STACK
15864 RESTORE_ALL 8
15865 jmp irq_return
15866 paranoid_restore:
15867+ pax_exit_kernel
15868 TRACE_IRQS_IRETQ 0
15869 RESTORE_ALL 8
15870+ pax_force_retaddr_bts
15871 jmp irq_return
15872 paranoid_userspace:
15873 GET_THREAD_INFO(%rcx)
15874@@ -1399,7 +1787,7 @@ paranoid_schedule:
15875 TRACE_IRQS_OFF
15876 jmp paranoid_userspace
15877 CFI_ENDPROC
15878-END(paranoid_exit)
15879+ENDPROC(paranoid_exit)
15880
15881 /*
15882 * Exception entry point. This expects an error code/orig_rax on the stack.
15883@@ -1426,12 +1814,13 @@ ENTRY(error_entry)
15884 movq_cfi r14, R14+8
15885 movq_cfi r15, R15+8
15886 xorl %ebx,%ebx
15887- testl $3,CS+8(%rsp)
15888+ testb $3,CS+8(%rsp)
15889 je error_kernelspace
15890 error_swapgs:
15891 SWAPGS
15892 error_sti:
15893 TRACE_IRQS_OFF
15894+ pax_force_retaddr_bts
15895 ret
15896
15897 /*
15898@@ -1458,7 +1847,7 @@ bstep_iret:
15899 movq %rcx,RIP+8(%rsp)
15900 jmp error_swapgs
15901 CFI_ENDPROC
15902-END(error_entry)
15903+ENDPROC(error_entry)
15904
15905
15906 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
15907@@ -1478,7 +1867,7 @@ ENTRY(error_exit)
15908 jnz retint_careful
15909 jmp retint_swapgs
15910 CFI_ENDPROC
15911-END(error_exit)
15912+ENDPROC(error_exit)
15913
15914 /*
15915 * Test if a given stack is an NMI stack or not.
15916@@ -1535,9 +1924,11 @@ ENTRY(nmi)
15917 * If %cs was not the kernel segment, then the NMI triggered in user
15918 * space, which means it is definitely not nested.
15919 */
15920+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
15921+ je 1f
15922 cmpl $__KERNEL_CS, 16(%rsp)
15923 jne first_nmi
15924-
15925+1:
15926 /*
15927 * Check the special variable on the stack to see if NMIs are
15928 * executing.
15929@@ -1659,6 +2050,16 @@ restart_nmi:
15930 */
15931 call save_paranoid
15932 DEFAULT_FRAME 0
15933+#ifdef CONFIG_PAX_MEMORY_UDEREF
15934+ testb $3, CS(%rsp)
15935+ jnz 1f
15936+ pax_enter_kernel
15937+ jmp 2f
15938+1: pax_enter_kernel_user
15939+2:
15940+#else
15941+ pax_enter_kernel
15942+#endif
15943 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
15944 movq %rsp,%rdi
15945 movq $-1,%rsi
15946@@ -1666,14 +2067,25 @@ restart_nmi:
15947 testl %ebx,%ebx /* swapgs needed? */
15948 jnz nmi_restore
15949 nmi_swapgs:
15950+#ifdef CONFIG_PAX_MEMORY_UDEREF
15951+ pax_exit_kernel_user
15952+#else
15953+ pax_exit_kernel
15954+#endif
15955 SWAPGS_UNSAFE_STACK
15956+ RESTORE_ALL 8
15957+ /* Clear the NMI executing stack variable */
15958+ movq $0, 10*8(%rsp)
15959+ jmp irq_return
15960 nmi_restore:
15961+ pax_exit_kernel
15962 RESTORE_ALL 8
15963+ pax_force_retaddr_bts
15964 /* Clear the NMI executing stack variable */
15965 movq $0, 10*8(%rsp)
15966 jmp irq_return
15967 CFI_ENDPROC
15968-END(nmi)
15969+ENDPROC(nmi)
15970
15971 /*
15972 * If an NMI hit an iret because of an exception or breakpoint,
15973@@ -1700,7 +2112,7 @@ ENTRY(ignore_sysret)
15974 mov $-ENOSYS,%eax
15975 sysret
15976 CFI_ENDPROC
15977-END(ignore_sysret)
15978+ENDPROC(ignore_sysret)
15979
15980 /*
15981 * End of kprobes section
15982diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
15983index c9a281f..ce2f317 100644
15984--- a/arch/x86/kernel/ftrace.c
15985+++ b/arch/x86/kernel/ftrace.c
15986@@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
15987 static const void *mod_code_newcode; /* holds the text to write to the IP */
15988
15989 static unsigned nmi_wait_count;
15990-static atomic_t nmi_update_count = ATOMIC_INIT(0);
15991+static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
15992
15993 int ftrace_arch_read_dyn_info(char *buf, int size)
15994 {
15995@@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
15996
15997 r = snprintf(buf, size, "%u %u",
15998 nmi_wait_count,
15999- atomic_read(&nmi_update_count));
16000+ atomic_read_unchecked(&nmi_update_count));
16001 return r;
16002 }
16003
16004@@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
16005
16006 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
16007 smp_rmb();
16008+ pax_open_kernel();
16009 ftrace_mod_code();
16010- atomic_inc(&nmi_update_count);
16011+ pax_close_kernel();
16012+ atomic_inc_unchecked(&nmi_update_count);
16013 }
16014 /* Must have previous changes seen before executions */
16015 smp_mb();
16016@@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
16017 {
16018 unsigned char replaced[MCOUNT_INSN_SIZE];
16019
16020+ ip = ktla_ktva(ip);
16021+
16022 /*
16023 * Note: Due to modules and __init, code can
16024 * disappear and change, we need to protect against faulting
16025@@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16026 unsigned char old[MCOUNT_INSN_SIZE], *new;
16027 int ret;
16028
16029- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16030+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16031 new = ftrace_call_replace(ip, (unsigned long)func);
16032 ret = ftrace_modify_code(ip, old, new);
16033
16034@@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16035 {
16036 unsigned char code[MCOUNT_INSN_SIZE];
16037
16038+ ip = ktla_ktva(ip);
16039+
16040 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16041 return -EFAULT;
16042
16043diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16044index 51ff186..9e77418 100644
16045--- a/arch/x86/kernel/head32.c
16046+++ b/arch/x86/kernel/head32.c
16047@@ -19,6 +19,7 @@
16048 #include <asm/io_apic.h>
16049 #include <asm/bios_ebda.h>
16050 #include <asm/tlbflush.h>
16051+#include <asm/boot.h>
16052
16053 static void __init i386_default_early_setup(void)
16054 {
16055@@ -31,8 +32,7 @@ static void __init i386_default_early_setup(void)
16056
16057 void __init i386_start_kernel(void)
16058 {
16059- memblock_reserve(__pa_symbol(&_text),
16060- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16061+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16062
16063 #ifdef CONFIG_BLK_DEV_INITRD
16064 /* Reserve INITRD */
16065diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16066index ce0be7c..c41476e 100644
16067--- a/arch/x86/kernel/head_32.S
16068+++ b/arch/x86/kernel/head_32.S
16069@@ -25,6 +25,12 @@
16070 /* Physical address */
16071 #define pa(X) ((X) - __PAGE_OFFSET)
16072
16073+#ifdef CONFIG_PAX_KERNEXEC
16074+#define ta(X) (X)
16075+#else
16076+#define ta(X) ((X) - __PAGE_OFFSET)
16077+#endif
16078+
16079 /*
16080 * References to members of the new_cpu_data structure.
16081 */
16082@@ -54,11 +60,7 @@
16083 * and small than max_low_pfn, otherwise will waste some page table entries
16084 */
16085
16086-#if PTRS_PER_PMD > 1
16087-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16088-#else
16089-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16090-#endif
16091+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16092
16093 /* Number of possible pages in the lowmem region */
16094 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16095@@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16096 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16097
16098 /*
16099+ * Real beginning of normal "text" segment
16100+ */
16101+ENTRY(stext)
16102+ENTRY(_stext)
16103+
16104+/*
16105 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16106 * %esi points to the real-mode code as a 32-bit pointer.
16107 * CS and DS must be 4 GB flat segments, but we don't depend on
16108@@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16109 * can.
16110 */
16111 __HEAD
16112+
16113+#ifdef CONFIG_PAX_KERNEXEC
16114+ jmp startup_32
16115+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16116+.fill PAGE_SIZE-5,1,0xcc
16117+#endif
16118+
16119 ENTRY(startup_32)
16120 movl pa(stack_start),%ecx
16121
16122@@ -105,6 +120,57 @@ ENTRY(startup_32)
16123 2:
16124 leal -__PAGE_OFFSET(%ecx),%esp
16125
16126+#ifdef CONFIG_SMP
16127+ movl $pa(cpu_gdt_table),%edi
16128+ movl $__per_cpu_load,%eax
16129+ movw %ax,__KERNEL_PERCPU + 2(%edi)
16130+ rorl $16,%eax
16131+ movb %al,__KERNEL_PERCPU + 4(%edi)
16132+ movb %ah,__KERNEL_PERCPU + 7(%edi)
16133+ movl $__per_cpu_end - 1,%eax
16134+ subl $__per_cpu_start,%eax
16135+ movw %ax,__KERNEL_PERCPU + 0(%edi)
16136+#endif
16137+
16138+#ifdef CONFIG_PAX_MEMORY_UDEREF
16139+ movl $NR_CPUS,%ecx
16140+ movl $pa(cpu_gdt_table),%edi
16141+1:
16142+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16143+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16144+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16145+ addl $PAGE_SIZE_asm,%edi
16146+ loop 1b
16147+#endif
16148+
16149+#ifdef CONFIG_PAX_KERNEXEC
16150+ movl $pa(boot_gdt),%edi
16151+ movl $__LOAD_PHYSICAL_ADDR,%eax
16152+ movw %ax,__BOOT_CS + 2(%edi)
16153+ rorl $16,%eax
16154+ movb %al,__BOOT_CS + 4(%edi)
16155+ movb %ah,__BOOT_CS + 7(%edi)
16156+ rorl $16,%eax
16157+
16158+ ljmp $(__BOOT_CS),$1f
16159+1:
16160+
16161+ movl $NR_CPUS,%ecx
16162+ movl $pa(cpu_gdt_table),%edi
16163+ addl $__PAGE_OFFSET,%eax
16164+1:
16165+ movw %ax,__KERNEL_CS + 2(%edi)
16166+ movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16167+ rorl $16,%eax
16168+ movb %al,__KERNEL_CS + 4(%edi)
16169+ movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16170+ movb %ah,__KERNEL_CS + 7(%edi)
16171+ movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16172+ rorl $16,%eax
16173+ addl $PAGE_SIZE_asm,%edi
16174+ loop 1b
16175+#endif
16176+
16177 /*
16178 * Clear BSS first so that there are no surprises...
16179 */
16180@@ -195,8 +261,11 @@ ENTRY(startup_32)
16181 movl %eax, pa(max_pfn_mapped)
16182
16183 /* Do early initialization of the fixmap area */
16184- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16185- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16186+#ifdef CONFIG_COMPAT_VDSO
16187+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16188+#else
16189+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16190+#endif
16191 #else /* Not PAE */
16192
16193 page_pde_offset = (__PAGE_OFFSET >> 20);
16194@@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16195 movl %eax, pa(max_pfn_mapped)
16196
16197 /* Do early initialization of the fixmap area */
16198- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16199- movl %eax,pa(initial_page_table+0xffc)
16200+#ifdef CONFIG_COMPAT_VDSO
16201+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16202+#else
16203+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16204+#endif
16205 #endif
16206
16207 #ifdef CONFIG_PARAVIRT
16208@@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16209 cmpl $num_subarch_entries, %eax
16210 jae bad_subarch
16211
16212- movl pa(subarch_entries)(,%eax,4), %eax
16213- subl $__PAGE_OFFSET, %eax
16214- jmp *%eax
16215+ jmp *pa(subarch_entries)(,%eax,4)
16216
16217 bad_subarch:
16218 WEAK(lguest_entry)
16219@@ -255,10 +325,10 @@ WEAK(xen_entry)
16220 __INITDATA
16221
16222 subarch_entries:
16223- .long default_entry /* normal x86/PC */
16224- .long lguest_entry /* lguest hypervisor */
16225- .long xen_entry /* Xen hypervisor */
16226- .long default_entry /* Moorestown MID */
16227+ .long ta(default_entry) /* normal x86/PC */
16228+ .long ta(lguest_entry) /* lguest hypervisor */
16229+ .long ta(xen_entry) /* Xen hypervisor */
16230+ .long ta(default_entry) /* Moorestown MID */
16231 num_subarch_entries = (. - subarch_entries) / 4
16232 .previous
16233 #else
16234@@ -312,6 +382,7 @@ default_entry:
16235 orl %edx,%eax
16236 movl %eax,%cr4
16237
16238+#ifdef CONFIG_X86_PAE
16239 testb $X86_CR4_PAE, %al # check if PAE is enabled
16240 jz 6f
16241
16242@@ -340,6 +411,9 @@ default_entry:
16243 /* Make changes effective */
16244 wrmsr
16245
16246+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16247+#endif
16248+
16249 6:
16250
16251 /*
16252@@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
16253 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16254 movl %eax,%ss # after changing gdt.
16255
16256- movl $(__USER_DS),%eax # DS/ES contains default USER segment
16257+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16258 movl %eax,%ds
16259 movl %eax,%es
16260
16261@@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
16262 */
16263 cmpb $0,ready
16264 jne 1f
16265- movl $gdt_page,%eax
16266+ movl $cpu_gdt_table,%eax
16267 movl $stack_canary,%ecx
16268+#ifdef CONFIG_SMP
16269+ addl $__per_cpu_load,%ecx
16270+#endif
16271 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16272 shrl $16, %ecx
16273 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16274 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
16275 1:
16276-#endif
16277 movl $(__KERNEL_STACK_CANARY),%eax
16278+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16279+ movl $(__USER_DS),%eax
16280+#else
16281+ xorl %eax,%eax
16282+#endif
16283 movl %eax,%gs
16284
16285 xorl %eax,%eax # Clear LDT
16286@@ -558,22 +639,22 @@ early_page_fault:
16287 jmp early_fault
16288
16289 early_fault:
16290- cld
16291 #ifdef CONFIG_PRINTK
16292+ cmpl $1,%ss:early_recursion_flag
16293+ je hlt_loop
16294+ incl %ss:early_recursion_flag
16295+ cld
16296 pusha
16297 movl $(__KERNEL_DS),%eax
16298 movl %eax,%ds
16299 movl %eax,%es
16300- cmpl $2,early_recursion_flag
16301- je hlt_loop
16302- incl early_recursion_flag
16303 movl %cr2,%eax
16304 pushl %eax
16305 pushl %edx /* trapno */
16306 pushl $fault_msg
16307 call printk
16308+; call dump_stack
16309 #endif
16310- call dump_stack
16311 hlt_loop:
16312 hlt
16313 jmp hlt_loop
16314@@ -581,8 +662,11 @@ hlt_loop:
16315 /* This is the default interrupt "handler" :-) */
16316 ALIGN
16317 ignore_int:
16318- cld
16319 #ifdef CONFIG_PRINTK
16320+ cmpl $2,%ss:early_recursion_flag
16321+ je hlt_loop
16322+ incl %ss:early_recursion_flag
16323+ cld
16324 pushl %eax
16325 pushl %ecx
16326 pushl %edx
16327@@ -591,9 +675,6 @@ ignore_int:
16328 movl $(__KERNEL_DS),%eax
16329 movl %eax,%ds
16330 movl %eax,%es
16331- cmpl $2,early_recursion_flag
16332- je hlt_loop
16333- incl early_recursion_flag
16334 pushl 16(%esp)
16335 pushl 24(%esp)
16336 pushl 32(%esp)
16337@@ -622,29 +703,43 @@ ENTRY(initial_code)
16338 /*
16339 * BSS section
16340 */
16341-__PAGE_ALIGNED_BSS
16342- .align PAGE_SIZE
16343 #ifdef CONFIG_X86_PAE
16344+.section .initial_pg_pmd,"a",@progbits
16345 initial_pg_pmd:
16346 .fill 1024*KPMDS,4,0
16347 #else
16348+.section .initial_page_table,"a",@progbits
16349 ENTRY(initial_page_table)
16350 .fill 1024,4,0
16351 #endif
16352+.section .initial_pg_fixmap,"a",@progbits
16353 initial_pg_fixmap:
16354 .fill 1024,4,0
16355+.section .empty_zero_page,"a",@progbits
16356 ENTRY(empty_zero_page)
16357 .fill 4096,1,0
16358+.section .swapper_pg_dir,"a",@progbits
16359 ENTRY(swapper_pg_dir)
16360+#ifdef CONFIG_X86_PAE
16361+ .fill 4,8,0
16362+#else
16363 .fill 1024,4,0
16364+#endif
16365+
16366+/*
16367+ * The IDT has to be page-aligned to simplify the Pentium
16368+ * F0 0F bug workaround.. We have a special link segment
16369+ * for this.
16370+ */
16371+.section .idt,"a",@progbits
16372+ENTRY(idt_table)
16373+ .fill 256,8,0
16374
16375 /*
16376 * This starts the data section.
16377 */
16378 #ifdef CONFIG_X86_PAE
16379-__PAGE_ALIGNED_DATA
16380- /* Page-aligned for the benefit of paravirt? */
16381- .align PAGE_SIZE
16382+.section .initial_page_table,"a",@progbits
16383 ENTRY(initial_page_table)
16384 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
16385 # if KPMDS == 3
16386@@ -663,18 +758,27 @@ ENTRY(initial_page_table)
16387 # error "Kernel PMDs should be 1, 2 or 3"
16388 # endif
16389 .align PAGE_SIZE /* needs to be page-sized too */
16390+
16391+#ifdef CONFIG_PAX_PER_CPU_PGD
16392+ENTRY(cpu_pgd)
16393+ .rept NR_CPUS
16394+ .fill 4,8,0
16395+ .endr
16396+#endif
16397+
16398 #endif
16399
16400 .data
16401 .balign 4
16402 ENTRY(stack_start)
16403- .long init_thread_union+THREAD_SIZE
16404+ .long init_thread_union+THREAD_SIZE-8
16405
16406+ready: .byte 0
16407+
16408+.section .rodata,"a",@progbits
16409 early_recursion_flag:
16410 .long 0
16411
16412-ready: .byte 0
16413-
16414 int_msg:
16415 .asciz "Unknown interrupt or fault at: %p %p %p\n"
16416
16417@@ -707,7 +811,7 @@ fault_msg:
16418 .word 0 # 32 bit align gdt_desc.address
16419 boot_gdt_descr:
16420 .word __BOOT_DS+7
16421- .long boot_gdt - __PAGE_OFFSET
16422+ .long pa(boot_gdt)
16423
16424 .word 0 # 32-bit align idt_desc.address
16425 idt_descr:
16426@@ -718,7 +822,7 @@ idt_descr:
16427 .word 0 # 32 bit align gdt_desc.address
16428 ENTRY(early_gdt_descr)
16429 .word GDT_ENTRIES*8-1
16430- .long gdt_page /* Overwritten for secondary CPUs */
16431+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
16432
16433 /*
16434 * The boot_gdt must mirror the equivalent in setup.S and is
16435@@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
16436 .align L1_CACHE_BYTES
16437 ENTRY(boot_gdt)
16438 .fill GDT_ENTRY_BOOT_CS,8,0
16439- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
16440- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
16441+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
16442+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
16443+
16444+ .align PAGE_SIZE_asm
16445+ENTRY(cpu_gdt_table)
16446+ .rept NR_CPUS
16447+ .quad 0x0000000000000000 /* NULL descriptor */
16448+ .quad 0x0000000000000000 /* 0x0b reserved */
16449+ .quad 0x0000000000000000 /* 0x13 reserved */
16450+ .quad 0x0000000000000000 /* 0x1b reserved */
16451+
16452+#ifdef CONFIG_PAX_KERNEXEC
16453+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
16454+#else
16455+ .quad 0x0000000000000000 /* 0x20 unused */
16456+#endif
16457+
16458+ .quad 0x0000000000000000 /* 0x28 unused */
16459+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
16460+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
16461+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
16462+ .quad 0x0000000000000000 /* 0x4b reserved */
16463+ .quad 0x0000000000000000 /* 0x53 reserved */
16464+ .quad 0x0000000000000000 /* 0x5b reserved */
16465+
16466+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
16467+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
16468+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
16469+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
16470+
16471+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
16472+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
16473+
16474+ /*
16475+ * Segments used for calling PnP BIOS have byte granularity.
16476+ * The code segments and data segments have fixed 64k limits,
16477+ * the transfer segment sizes are set at run time.
16478+ */
16479+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
16480+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
16481+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
16482+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
16483+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
16484+
16485+ /*
16486+ * The APM segments have byte granularity and their bases
16487+ * are set at run time. All have 64k limits.
16488+ */
16489+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
16490+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
16491+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
16492+
16493+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
16494+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
16495+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
16496+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
16497+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
16498+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
16499+
16500+ /* Be sure this is zeroed to avoid false validations in Xen */
16501+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
16502+ .endr
16503diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
16504index 40f4eb3..6d24d9d 100644
16505--- a/arch/x86/kernel/head_64.S
16506+++ b/arch/x86/kernel/head_64.S
16507@@ -19,6 +19,8 @@
16508 #include <asm/cache.h>
16509 #include <asm/processor-flags.h>
16510 #include <asm/percpu.h>
16511+#include <asm/cpufeature.h>
16512+#include <asm/alternative-asm.h>
16513
16514 #ifdef CONFIG_PARAVIRT
16515 #include <asm/asm-offsets.h>
16516@@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
16517 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
16518 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
16519 L3_START_KERNEL = pud_index(__START_KERNEL_map)
16520+L4_VMALLOC_START = pgd_index(VMALLOC_START)
16521+L3_VMALLOC_START = pud_index(VMALLOC_START)
16522+L4_VMALLOC_END = pgd_index(VMALLOC_END)
16523+L3_VMALLOC_END = pud_index(VMALLOC_END)
16524+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
16525+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
16526
16527 .text
16528 __HEAD
16529@@ -85,35 +93,23 @@ startup_64:
16530 */
16531 addq %rbp, init_level4_pgt + 0(%rip)
16532 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
16533+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
16534+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
16535+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
16536 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
16537
16538 addq %rbp, level3_ident_pgt + 0(%rip)
16539+#ifndef CONFIG_XEN
16540+ addq %rbp, level3_ident_pgt + 8(%rip)
16541+#endif
16542
16543- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
16544- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
16545+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
16546+
16547+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
16548+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
16549
16550 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
16551-
16552- /* Add an Identity mapping if I am above 1G */
16553- leaq _text(%rip), %rdi
16554- andq $PMD_PAGE_MASK, %rdi
16555-
16556- movq %rdi, %rax
16557- shrq $PUD_SHIFT, %rax
16558- andq $(PTRS_PER_PUD - 1), %rax
16559- jz ident_complete
16560-
16561- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
16562- leaq level3_ident_pgt(%rip), %rbx
16563- movq %rdx, 0(%rbx, %rax, 8)
16564-
16565- movq %rdi, %rax
16566- shrq $PMD_SHIFT, %rax
16567- andq $(PTRS_PER_PMD - 1), %rax
16568- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
16569- leaq level2_spare_pgt(%rip), %rbx
16570- movq %rdx, 0(%rbx, %rax, 8)
16571-ident_complete:
16572+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
16573
16574 /*
16575 * Fixup the kernel text+data virtual addresses. Note that
16576@@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
16577 * after the boot processor executes this code.
16578 */
16579
16580- /* Enable PAE mode and PGE */
16581- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
16582+ /* Enable PAE mode and PSE/PGE */
16583+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
16584 movq %rax, %cr4
16585
16586 /* Setup early boot stage 4 level pagetables. */
16587@@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
16588 movl $MSR_EFER, %ecx
16589 rdmsr
16590 btsl $_EFER_SCE, %eax /* Enable System Call */
16591- btl $20,%edi /* No Execute supported? */
16592+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
16593 jnc 1f
16594 btsl $_EFER_NX, %eax
16595+ leaq init_level4_pgt(%rip), %rdi
16596+#ifndef CONFIG_EFI
16597+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
16598+#endif
16599+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
16600+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
16601+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
16602+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
16603 1: wrmsr /* Make changes effective */
16604
16605 /* Setup cr0 */
16606@@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
16607 * jump. In addition we need to ensure %cs is set so we make this
16608 * a far return.
16609 */
16610+ pax_set_fptr_mask
16611 movq initial_code(%rip),%rax
16612 pushq $0 # fake return address to stop unwinder
16613 pushq $__KERNEL_CS # set correct cs
16614@@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
16615 bad_address:
16616 jmp bad_address
16617
16618- .section ".init.text","ax"
16619+ __INIT
16620 #ifdef CONFIG_EARLY_PRINTK
16621 .globl early_idt_handlers
16622 early_idt_handlers:
16623@@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
16624 #endif /* EARLY_PRINTK */
16625 1: hlt
16626 jmp 1b
16627+ .previous
16628
16629 #ifdef CONFIG_EARLY_PRINTK
16630+ __INITDATA
16631 early_recursion_flag:
16632 .long 0
16633+ .previous
16634
16635+ .section .rodata,"a",@progbits
16636 early_idt_msg:
16637 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
16638 early_idt_ripmsg:
16639 .asciz "RIP %s\n"
16640+ .previous
16641 #endif /* CONFIG_EARLY_PRINTK */
16642- .previous
16643
16644+ .section .rodata,"a",@progbits
16645 #define NEXT_PAGE(name) \
16646 .balign PAGE_SIZE; \
16647 ENTRY(name)
16648@@ -338,7 +348,6 @@ ENTRY(name)
16649 i = i + 1 ; \
16650 .endr
16651
16652- .data
16653 /*
16654 * This default setting generates an ident mapping at address 0x100000
16655 * and a mapping for the kernel that precisely maps virtual address
16656@@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
16657 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16658 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
16659 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16660+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
16661+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
16662+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
16663+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
16664+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
16665+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
16666 .org init_level4_pgt + L4_START_KERNEL*8, 0
16667 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
16668 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
16669
16670+#ifdef CONFIG_PAX_PER_CPU_PGD
16671+NEXT_PAGE(cpu_pgd)
16672+ .rept NR_CPUS
16673+ .fill 512,8,0
16674+ .endr
16675+#endif
16676+
16677 NEXT_PAGE(level3_ident_pgt)
16678 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
16679+#ifdef CONFIG_XEN
16680 .fill 511,8,0
16681+#else
16682+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
16683+ .fill 510,8,0
16684+#endif
16685+
16686+NEXT_PAGE(level3_vmalloc_start_pgt)
16687+ .fill 512,8,0
16688+
16689+NEXT_PAGE(level3_vmalloc_end_pgt)
16690+ .fill 512,8,0
16691+
16692+NEXT_PAGE(level3_vmemmap_pgt)
16693+ .fill L3_VMEMMAP_START,8,0
16694+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
16695
16696 NEXT_PAGE(level3_kernel_pgt)
16697 .fill L3_START_KERNEL,8,0
16698@@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
16699 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
16700 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
16701
16702+NEXT_PAGE(level2_vmemmap_pgt)
16703+ .fill 512,8,0
16704+
16705 NEXT_PAGE(level2_fixmap_pgt)
16706- .fill 506,8,0
16707- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
16708- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
16709- .fill 5,8,0
16710+ .fill 507,8,0
16711+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
16712+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
16713+ .fill 4,8,0
16714
16715-NEXT_PAGE(level1_fixmap_pgt)
16716+NEXT_PAGE(level1_vsyscall_pgt)
16717 .fill 512,8,0
16718
16719-NEXT_PAGE(level2_ident_pgt)
16720- /* Since I easily can, map the first 1G.
16721+ /* Since I easily can, map the first 2G.
16722 * Don't set NX because code runs from these pages.
16723 */
16724- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
16725+NEXT_PAGE(level2_ident_pgt)
16726+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
16727
16728 NEXT_PAGE(level2_kernel_pgt)
16729 /*
16730@@ -389,37 +429,59 @@ NEXT_PAGE(level2_kernel_pgt)
16731 * If you want to increase this then increase MODULES_VADDR
16732 * too.)
16733 */
16734- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
16735- KERNEL_IMAGE_SIZE/PMD_SIZE)
16736-
16737-NEXT_PAGE(level2_spare_pgt)
16738- .fill 512, 8, 0
16739+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
16740
16741 #undef PMDS
16742 #undef NEXT_PAGE
16743
16744- .data
16745+ .align PAGE_SIZE
16746+ENTRY(cpu_gdt_table)
16747+ .rept NR_CPUS
16748+ .quad 0x0000000000000000 /* NULL descriptor */
16749+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
16750+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
16751+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
16752+ .quad 0x00cffb000000ffff /* __USER32_CS */
16753+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
16754+ .quad 0x00affb000000ffff /* __USER_CS */
16755+
16756+#ifdef CONFIG_PAX_KERNEXEC
16757+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
16758+#else
16759+ .quad 0x0 /* unused */
16760+#endif
16761+
16762+ .quad 0,0 /* TSS */
16763+ .quad 0,0 /* LDT */
16764+ .quad 0,0,0 /* three TLS descriptors */
16765+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
16766+ /* asm/segment.h:GDT_ENTRIES must match this */
16767+
16768+ /* zero the remaining page */
16769+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
16770+ .endr
16771+
16772 .align 16
16773 .globl early_gdt_descr
16774 early_gdt_descr:
16775 .word GDT_ENTRIES*8-1
16776 early_gdt_descr_base:
16777- .quad INIT_PER_CPU_VAR(gdt_page)
16778+ .quad cpu_gdt_table
16779
16780 ENTRY(phys_base)
16781 /* This must match the first entry in level2_kernel_pgt */
16782 .quad 0x0000000000000000
16783
16784 #include "../../x86/xen/xen-head.S"
16785-
16786- .section .bss, "aw", @nobits
16787+
16788+ .section .rodata,"a",@progbits
16789 .align L1_CACHE_BYTES
16790 ENTRY(idt_table)
16791- .skip IDT_ENTRIES * 16
16792+ .fill 512,8,0
16793
16794 .align L1_CACHE_BYTES
16795 ENTRY(nmi_idt_table)
16796- .skip IDT_ENTRIES * 16
16797+ .fill 512,8,0
16798
16799 __PAGE_ALIGNED_BSS
16800 .align PAGE_SIZE
16801diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
16802index 9c3bd4a..e1d9b35 100644
16803--- a/arch/x86/kernel/i386_ksyms_32.c
16804+++ b/arch/x86/kernel/i386_ksyms_32.c
16805@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
16806 EXPORT_SYMBOL(cmpxchg8b_emu);
16807 #endif
16808
16809+EXPORT_SYMBOL_GPL(cpu_gdt_table);
16810+
16811 /* Networking helper routines. */
16812 EXPORT_SYMBOL(csum_partial_copy_generic);
16813+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
16814+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
16815
16816 EXPORT_SYMBOL(__get_user_1);
16817 EXPORT_SYMBOL(__get_user_2);
16818@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
16819
16820 EXPORT_SYMBOL(csum_partial);
16821 EXPORT_SYMBOL(empty_zero_page);
16822+
16823+#ifdef CONFIG_PAX_KERNEXEC
16824+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
16825+#endif
16826diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
16827index 6104852..6114160 100644
16828--- a/arch/x86/kernel/i8259.c
16829+++ b/arch/x86/kernel/i8259.c
16830@@ -210,7 +210,7 @@ spurious_8259A_irq:
16831 "spurious 8259A interrupt: IRQ%d.\n", irq);
16832 spurious_irq_mask |= irqmask;
16833 }
16834- atomic_inc(&irq_err_count);
16835+ atomic_inc_unchecked(&irq_err_count);
16836 /*
16837 * Theoretically we do not have to handle this IRQ,
16838 * but in Linux this does not cause problems and is
16839diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
16840index 43e9ccf..44ccf6f 100644
16841--- a/arch/x86/kernel/init_task.c
16842+++ b/arch/x86/kernel/init_task.c
16843@@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
16844 * way process stacks are handled. This is done by having a special
16845 * "init_task" linker map entry..
16846 */
16847-union thread_union init_thread_union __init_task_data =
16848- { INIT_THREAD_INFO(init_task) };
16849+union thread_union init_thread_union __init_task_data;
16850
16851 /*
16852 * Initial task structure.
16853@@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
16854 * section. Since TSS's are completely CPU-local, we want them
16855 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
16856 */
16857-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
16858-
16859+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
16860+EXPORT_SYMBOL(init_tss);
16861diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
16862index 8c96897..be66bfa 100644
16863--- a/arch/x86/kernel/ioport.c
16864+++ b/arch/x86/kernel/ioport.c
16865@@ -6,6 +6,7 @@
16866 #include <linux/sched.h>
16867 #include <linux/kernel.h>
16868 #include <linux/capability.h>
16869+#include <linux/security.h>
16870 #include <linux/errno.h>
16871 #include <linux/types.h>
16872 #include <linux/ioport.h>
16873@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
16874
16875 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
16876 return -EINVAL;
16877+#ifdef CONFIG_GRKERNSEC_IO
16878+ if (turn_on && grsec_disable_privio) {
16879+ gr_handle_ioperm();
16880+ return -EPERM;
16881+ }
16882+#endif
16883 if (turn_on && !capable(CAP_SYS_RAWIO))
16884 return -EPERM;
16885
16886@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
16887 * because the ->io_bitmap_max value must match the bitmap
16888 * contents:
16889 */
16890- tss = &per_cpu(init_tss, get_cpu());
16891+ tss = init_tss + get_cpu();
16892
16893 if (turn_on)
16894 bitmap_clear(t->io_bitmap_ptr, from, num);
16895@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
16896 return -EINVAL;
16897 /* Trying to gain more privileges? */
16898 if (level > old) {
16899+#ifdef CONFIG_GRKERNSEC_IO
16900+ if (grsec_disable_privio) {
16901+ gr_handle_iopl();
16902+ return -EPERM;
16903+ }
16904+#endif
16905 if (!capable(CAP_SYS_RAWIO))
16906 return -EPERM;
16907 }
16908diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
16909index 7943e0c..dd32c5c 100644
16910--- a/arch/x86/kernel/irq.c
16911+++ b/arch/x86/kernel/irq.c
16912@@ -18,7 +18,7 @@
16913 #include <asm/mce.h>
16914 #include <asm/hw_irq.h>
16915
16916-atomic_t irq_err_count;
16917+atomic_unchecked_t irq_err_count;
16918
16919 /* Function pointer for generic interrupt vector handling */
16920 void (*x86_platform_ipi_callback)(void) = NULL;
16921@@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
16922 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
16923 seq_printf(p, " Machine check polls\n");
16924 #endif
16925- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
16926+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
16927 #if defined(CONFIG_X86_IO_APIC)
16928- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
16929+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
16930 #endif
16931 return 0;
16932 }
16933@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
16934
16935 u64 arch_irq_stat(void)
16936 {
16937- u64 sum = atomic_read(&irq_err_count);
16938+ u64 sum = atomic_read_unchecked(&irq_err_count);
16939
16940 #ifdef CONFIG_X86_IO_APIC
16941- sum += atomic_read(&irq_mis_count);
16942+ sum += atomic_read_unchecked(&irq_mis_count);
16943 #endif
16944 return sum;
16945 }
16946diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
16947index 40fc861..9b8739b 100644
16948--- a/arch/x86/kernel/irq_32.c
16949+++ b/arch/x86/kernel/irq_32.c
16950@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
16951 __asm__ __volatile__("andl %%esp,%0" :
16952 "=r" (sp) : "0" (THREAD_SIZE - 1));
16953
16954- return sp < (sizeof(struct thread_info) + STACK_WARN);
16955+ return sp < STACK_WARN;
16956 }
16957
16958 static void print_stack_overflow(void)
16959@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
16960 * per-CPU IRQ handling contexts (thread information and stack)
16961 */
16962 union irq_ctx {
16963- struct thread_info tinfo;
16964- u32 stack[THREAD_SIZE/sizeof(u32)];
16965+ unsigned long previous_esp;
16966+ u32 stack[THREAD_SIZE/sizeof(u32)];
16967 } __attribute__((aligned(THREAD_SIZE)));
16968
16969 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
16970@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
16971 static inline int
16972 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
16973 {
16974- union irq_ctx *curctx, *irqctx;
16975+ union irq_ctx *irqctx;
16976 u32 *isp, arg1, arg2;
16977
16978- curctx = (union irq_ctx *) current_thread_info();
16979 irqctx = __this_cpu_read(hardirq_ctx);
16980
16981 /*
16982@@ -92,21 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
16983 * handler) we can't do that and just have to keep using the
16984 * current stack (which is the irq stack already after all)
16985 */
16986- if (unlikely(curctx == irqctx))
16987+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
16988 return 0;
16989
16990 /* build the stack frame on the IRQ stack */
16991- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
16992- irqctx->tinfo.task = curctx->tinfo.task;
16993- irqctx->tinfo.previous_esp = current_stack_pointer;
16994+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
16995+ irqctx->previous_esp = current_stack_pointer;
16996
16997- /*
16998- * Copy the softirq bits in preempt_count so that the
16999- * softirq checks work in the hardirq context.
17000- */
17001- irqctx->tinfo.preempt_count =
17002- (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
17003- (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
17004+#ifdef CONFIG_PAX_MEMORY_UDEREF
17005+ __set_fs(MAKE_MM_SEG(0));
17006+#endif
17007
17008 if (unlikely(overflow))
17009 call_on_stack(print_stack_overflow, isp);
17010@@ -118,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17011 : "0" (irq), "1" (desc), "2" (isp),
17012 "D" (desc->handle_irq)
17013 : "memory", "cc", "ecx");
17014+
17015+#ifdef CONFIG_PAX_MEMORY_UDEREF
17016+ __set_fs(current_thread_info()->addr_limit);
17017+#endif
17018+
17019 return 1;
17020 }
17021
17022@@ -126,29 +125,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17023 */
17024 void __cpuinit irq_ctx_init(int cpu)
17025 {
17026- union irq_ctx *irqctx;
17027-
17028 if (per_cpu(hardirq_ctx, cpu))
17029 return;
17030
17031- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17032- THREAD_FLAGS,
17033- THREAD_ORDER));
17034- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17035- irqctx->tinfo.cpu = cpu;
17036- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17037- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17038-
17039- per_cpu(hardirq_ctx, cpu) = irqctx;
17040-
17041- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17042- THREAD_FLAGS,
17043- THREAD_ORDER));
17044- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17045- irqctx->tinfo.cpu = cpu;
17046- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17047-
17048- per_cpu(softirq_ctx, cpu) = irqctx;
17049+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17050+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17051
17052 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17053 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17054@@ -157,7 +138,6 @@ void __cpuinit irq_ctx_init(int cpu)
17055 asmlinkage void do_softirq(void)
17056 {
17057 unsigned long flags;
17058- struct thread_info *curctx;
17059 union irq_ctx *irqctx;
17060 u32 *isp;
17061
17062@@ -167,15 +147,22 @@ asmlinkage void do_softirq(void)
17063 local_irq_save(flags);
17064
17065 if (local_softirq_pending()) {
17066- curctx = current_thread_info();
17067 irqctx = __this_cpu_read(softirq_ctx);
17068- irqctx->tinfo.task = curctx->task;
17069- irqctx->tinfo.previous_esp = current_stack_pointer;
17070+ irqctx->previous_esp = current_stack_pointer;
17071
17072 /* build the stack frame on the softirq stack */
17073- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17074+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17075+
17076+#ifdef CONFIG_PAX_MEMORY_UDEREF
17077+ __set_fs(MAKE_MM_SEG(0));
17078+#endif
17079
17080 call_on_stack(__do_softirq, isp);
17081+
17082+#ifdef CONFIG_PAX_MEMORY_UDEREF
17083+ __set_fs(current_thread_info()->addr_limit);
17084+#endif
17085+
17086 /*
17087 * Shouldn't happen, we returned above if in_interrupt():
17088 */
17089diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17090index d04d3ec..ea4b374 100644
17091--- a/arch/x86/kernel/irq_64.c
17092+++ b/arch/x86/kernel/irq_64.c
17093@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17094 u64 estack_top, estack_bottom;
17095 u64 curbase = (u64)task_stack_page(current);
17096
17097- if (user_mode_vm(regs))
17098+ if (user_mode(regs))
17099 return;
17100
17101 if (regs->sp >= curbase + sizeof(struct thread_info) +
17102diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17103index faba577..93b9e71 100644
17104--- a/arch/x86/kernel/kgdb.c
17105+++ b/arch/x86/kernel/kgdb.c
17106@@ -124,11 +124,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17107 #ifdef CONFIG_X86_32
17108 switch (regno) {
17109 case GDB_SS:
17110- if (!user_mode_vm(regs))
17111+ if (!user_mode(regs))
17112 *(unsigned long *)mem = __KERNEL_DS;
17113 break;
17114 case GDB_SP:
17115- if (!user_mode_vm(regs))
17116+ if (!user_mode(regs))
17117 *(unsigned long *)mem = kernel_stack_pointer(regs);
17118 break;
17119 case GDB_GS:
17120@@ -473,12 +473,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17121 case 'k':
17122 /* clear the trace bit */
17123 linux_regs->flags &= ~X86_EFLAGS_TF;
17124- atomic_set(&kgdb_cpu_doing_single_step, -1);
17125+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17126
17127 /* set the trace bit if we're stepping */
17128 if (remcomInBuffer[0] == 's') {
17129 linux_regs->flags |= X86_EFLAGS_TF;
17130- atomic_set(&kgdb_cpu_doing_single_step,
17131+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17132 raw_smp_processor_id());
17133 }
17134
17135@@ -543,7 +543,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17136
17137 switch (cmd) {
17138 case DIE_DEBUG:
17139- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17140+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17141 if (user_mode(regs))
17142 return single_step_cont(regs, args);
17143 break;
17144diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17145index 7da647d..56fe348 100644
17146--- a/arch/x86/kernel/kprobes.c
17147+++ b/arch/x86/kernel/kprobes.c
17148@@ -118,8 +118,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17149 } __attribute__((packed)) *insn;
17150
17151 insn = (struct __arch_relative_insn *)from;
17152+
17153+ pax_open_kernel();
17154 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17155 insn->op = op;
17156+ pax_close_kernel();
17157 }
17158
17159 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17160@@ -156,7 +159,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
17161 kprobe_opcode_t opcode;
17162 kprobe_opcode_t *orig_opcodes = opcodes;
17163
17164- if (search_exception_tables((unsigned long)opcodes))
17165+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17166 return 0; /* Page fault may occur on this address. */
17167
17168 retry:
17169@@ -317,7 +320,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17170 }
17171 }
17172 insn_get_length(&insn);
17173+ pax_open_kernel();
17174 memcpy(dest, insn.kaddr, insn.length);
17175+ pax_close_kernel();
17176
17177 #ifdef CONFIG_X86_64
17178 if (insn_rip_relative(&insn)) {
17179@@ -341,7 +346,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17180 (u8 *) dest;
17181 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17182 disp = (u8 *) dest + insn_offset_displacement(&insn);
17183+ pax_open_kernel();
17184 *(s32 *) disp = (s32) newdisp;
17185+ pax_close_kernel();
17186 }
17187 #endif
17188 return insn.length;
17189@@ -355,12 +362,12 @@ static void __kprobes arch_copy_kprobe(struct kprobe *p)
17190 */
17191 __copy_instruction(p->ainsn.insn, p->addr, 0);
17192
17193- if (can_boost(p->addr))
17194+ if (can_boost(ktla_ktva(p->addr)))
17195 p->ainsn.boostable = 0;
17196 else
17197 p->ainsn.boostable = -1;
17198
17199- p->opcode = *p->addr;
17200+ p->opcode = *(ktla_ktva(p->addr));
17201 }
17202
17203 int __kprobes arch_prepare_kprobe(struct kprobe *p)
17204@@ -477,7 +484,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17205 * nor set current_kprobe, because it doesn't use single
17206 * stepping.
17207 */
17208- regs->ip = (unsigned long)p->ainsn.insn;
17209+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17210 preempt_enable_no_resched();
17211 return;
17212 }
17213@@ -496,7 +503,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17214 if (p->opcode == BREAKPOINT_INSTRUCTION)
17215 regs->ip = (unsigned long)p->addr;
17216 else
17217- regs->ip = (unsigned long)p->ainsn.insn;
17218+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17219 }
17220
17221 /*
17222@@ -575,7 +582,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17223 setup_singlestep(p, regs, kcb, 0);
17224 return 1;
17225 }
17226- } else if (*addr != BREAKPOINT_INSTRUCTION) {
17227+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17228 /*
17229 * The breakpoint instruction was removed right
17230 * after we hit it. Another cpu has removed
17231@@ -683,6 +690,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17232 " movq %rax, 152(%rsp)\n"
17233 RESTORE_REGS_STRING
17234 " popfq\n"
17235+#ifdef KERNEXEC_PLUGIN
17236+ " btsq $63,(%rsp)\n"
17237+#endif
17238 #else
17239 " pushf\n"
17240 SAVE_REGS_STRING
17241@@ -820,7 +830,7 @@ static void __kprobes resume_execution(struct kprobe *p,
17242 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17243 {
17244 unsigned long *tos = stack_addr(regs);
17245- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17246+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17247 unsigned long orig_ip = (unsigned long)p->addr;
17248 kprobe_opcode_t *insn = p->ainsn.insn;
17249
17250@@ -1002,7 +1012,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
17251 struct die_args *args = data;
17252 int ret = NOTIFY_DONE;
17253
17254- if (args->regs && user_mode_vm(args->regs))
17255+ if (args->regs && user_mode(args->regs))
17256 return ret;
17257
17258 switch (val) {
17259@@ -1384,7 +1394,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17260 * Verify if the address gap is in 2GB range, because this uses
17261 * a relative jump.
17262 */
17263- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17264+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17265 if (abs(rel) > 0x7fffffff)
17266 return -ERANGE;
17267
17268@@ -1405,11 +1415,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17269 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17270
17271 /* Set probe function call */
17272- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17273+ synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17274
17275 /* Set returning jmp instruction at the tail of out-of-line buffer */
17276 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17277- (u8 *)op->kp.addr + op->optinsn.size);
17278+ (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17279
17280 flush_icache_range((unsigned long) buf,
17281 (unsigned long) buf + TMPL_END_IDX +
17282@@ -1431,7 +1441,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17283 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17284
17285 /* Backup instructions which will be replaced by jump address */
17286- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17287+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17288 RELATIVE_ADDR_SIZE);
17289
17290 insn_buf[0] = RELATIVEJUMP_OPCODE;
17291diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17292index ea69726..604d066 100644
17293--- a/arch/x86/kernel/ldt.c
17294+++ b/arch/x86/kernel/ldt.c
17295@@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17296 if (reload) {
17297 #ifdef CONFIG_SMP
17298 preempt_disable();
17299- load_LDT(pc);
17300+ load_LDT_nolock(pc);
17301 if (!cpumask_equal(mm_cpumask(current->mm),
17302 cpumask_of(smp_processor_id())))
17303 smp_call_function(flush_ldt, current->mm, 1);
17304 preempt_enable();
17305 #else
17306- load_LDT(pc);
17307+ load_LDT_nolock(pc);
17308 #endif
17309 }
17310 if (oldsize) {
17311@@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17312 return err;
17313
17314 for (i = 0; i < old->size; i++)
17315- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
17316+ write_ldt_entry(new->ldt, i, old->ldt + i);
17317 return 0;
17318 }
17319
17320@@ -116,6 +116,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
17321 retval = copy_ldt(&mm->context, &old_mm->context);
17322 mutex_unlock(&old_mm->context.lock);
17323 }
17324+
17325+ if (tsk == current) {
17326+ mm->context.vdso = 0;
17327+
17328+#ifdef CONFIG_X86_32
17329+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17330+ mm->context.user_cs_base = 0UL;
17331+ mm->context.user_cs_limit = ~0UL;
17332+
17333+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17334+ cpus_clear(mm->context.cpu_user_cs_mask);
17335+#endif
17336+
17337+#endif
17338+#endif
17339+
17340+ }
17341+
17342 return retval;
17343 }
17344
17345@@ -230,6 +248,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
17346 }
17347 }
17348
17349+#ifdef CONFIG_PAX_SEGMEXEC
17350+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
17351+ error = -EINVAL;
17352+ goto out_unlock;
17353+ }
17354+#endif
17355+
17356 fill_ldt(&ldt, &ldt_info);
17357 if (oldmode)
17358 ldt.avl = 0;
17359diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
17360index a3fa43b..8966f4c 100644
17361--- a/arch/x86/kernel/machine_kexec_32.c
17362+++ b/arch/x86/kernel/machine_kexec_32.c
17363@@ -27,7 +27,7 @@
17364 #include <asm/cacheflush.h>
17365 #include <asm/debugreg.h>
17366
17367-static void set_idt(void *newidt, __u16 limit)
17368+static void set_idt(struct desc_struct *newidt, __u16 limit)
17369 {
17370 struct desc_ptr curidt;
17371
17372@@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16 limit)
17373 }
17374
17375
17376-static void set_gdt(void *newgdt, __u16 limit)
17377+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
17378 {
17379 struct desc_ptr curgdt;
17380
17381@@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
17382 }
17383
17384 control_page = page_address(image->control_code_page);
17385- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
17386+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
17387
17388 relocate_kernel_ptr = control_page;
17389 page_list[PA_CONTROL_PAGE] = __pa(control_page);
17390diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
17391index 3ca42d0..7cff8cc 100644
17392--- a/arch/x86/kernel/microcode_intel.c
17393+++ b/arch/x86/kernel/microcode_intel.c
17394@@ -436,13 +436,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
17395
17396 static int get_ucode_user(void *to, const void *from, size_t n)
17397 {
17398- return copy_from_user(to, from, n);
17399+ return copy_from_user(to, (const void __force_user *)from, n);
17400 }
17401
17402 static enum ucode_state
17403 request_microcode_user(int cpu, const void __user *buf, size_t size)
17404 {
17405- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
17406+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
17407 }
17408
17409 static void microcode_fini_cpu(int cpu)
17410diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
17411index 925179f..267ac7a 100644
17412--- a/arch/x86/kernel/module.c
17413+++ b/arch/x86/kernel/module.c
17414@@ -36,15 +36,60 @@
17415 #define DEBUGP(fmt...)
17416 #endif
17417
17418-void *module_alloc(unsigned long size)
17419+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
17420 {
17421- if (PAGE_ALIGN(size) > MODULES_LEN)
17422+ if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
17423 return NULL;
17424 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
17425- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
17426+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
17427 -1, __builtin_return_address(0));
17428 }
17429
17430+void *module_alloc(unsigned long size)
17431+{
17432+
17433+#ifdef CONFIG_PAX_KERNEXEC
17434+ return __module_alloc(size, PAGE_KERNEL);
17435+#else
17436+ return __module_alloc(size, PAGE_KERNEL_EXEC);
17437+#endif
17438+
17439+}
17440+
17441+#ifdef CONFIG_PAX_KERNEXEC
17442+#ifdef CONFIG_X86_32
17443+void *module_alloc_exec(unsigned long size)
17444+{
17445+ struct vm_struct *area;
17446+
17447+ if (size == 0)
17448+ return NULL;
17449+
17450+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
17451+ return area ? area->addr : NULL;
17452+}
17453+EXPORT_SYMBOL(module_alloc_exec);
17454+
17455+void module_free_exec(struct module *mod, void *module_region)
17456+{
17457+ vunmap(module_region);
17458+}
17459+EXPORT_SYMBOL(module_free_exec);
17460+#else
17461+void module_free_exec(struct module *mod, void *module_region)
17462+{
17463+ module_free(mod, module_region);
17464+}
17465+EXPORT_SYMBOL(module_free_exec);
17466+
17467+void *module_alloc_exec(unsigned long size)
17468+{
17469+ return __module_alloc(size, PAGE_KERNEL_RX);
17470+}
17471+EXPORT_SYMBOL(module_alloc_exec);
17472+#endif
17473+#endif
17474+
17475 #ifdef CONFIG_X86_32
17476 int apply_relocate(Elf32_Shdr *sechdrs,
17477 const char *strtab,
17478@@ -55,14 +100,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
17479 unsigned int i;
17480 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
17481 Elf32_Sym *sym;
17482- uint32_t *location;
17483+ uint32_t *plocation, location;
17484
17485 DEBUGP("Applying relocate section %u to %u\n", relsec,
17486 sechdrs[relsec].sh_info);
17487 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
17488 /* This is where to make the change */
17489- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
17490- + rel[i].r_offset;
17491+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
17492+ location = (uint32_t)plocation;
17493+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
17494+ plocation = ktla_ktva((void *)plocation);
17495 /* This is the symbol it is referring to. Note that all
17496 undefined symbols have been resolved. */
17497 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
17498@@ -71,11 +118,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
17499 switch (ELF32_R_TYPE(rel[i].r_info)) {
17500 case R_386_32:
17501 /* We add the value into the location given */
17502- *location += sym->st_value;
17503+ pax_open_kernel();
17504+ *plocation += sym->st_value;
17505+ pax_close_kernel();
17506 break;
17507 case R_386_PC32:
17508 /* Add the value, subtract its postition */
17509- *location += sym->st_value - (uint32_t)location;
17510+ pax_open_kernel();
17511+ *plocation += sym->st_value - location;
17512+ pax_close_kernel();
17513 break;
17514 default:
17515 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
17516@@ -120,21 +171,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
17517 case R_X86_64_NONE:
17518 break;
17519 case R_X86_64_64:
17520+ pax_open_kernel();
17521 *(u64 *)loc = val;
17522+ pax_close_kernel();
17523 break;
17524 case R_X86_64_32:
17525+ pax_open_kernel();
17526 *(u32 *)loc = val;
17527+ pax_close_kernel();
17528 if (val != *(u32 *)loc)
17529 goto overflow;
17530 break;
17531 case R_X86_64_32S:
17532+ pax_open_kernel();
17533 *(s32 *)loc = val;
17534+ pax_close_kernel();
17535 if ((s64)val != *(s32 *)loc)
17536 goto overflow;
17537 break;
17538 case R_X86_64_PC32:
17539 val -= (u64)loc;
17540+ pax_open_kernel();
17541 *(u32 *)loc = val;
17542+ pax_close_kernel();
17543+
17544 #if 0
17545 if ((s64)val != *(s32 *)loc)
17546 goto overflow;
17547diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
17548index 47acaf3..ec48ab6 100644
17549--- a/arch/x86/kernel/nmi.c
17550+++ b/arch/x86/kernel/nmi.c
17551@@ -505,6 +505,17 @@ static inline void nmi_nesting_postprocess(void)
17552 dotraplinkage notrace __kprobes void
17553 do_nmi(struct pt_regs *regs, long error_code)
17554 {
17555+
17556+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17557+ if (!user_mode(regs)) {
17558+ unsigned long cs = regs->cs & 0xFFFF;
17559+ unsigned long ip = ktva_ktla(regs->ip);
17560+
17561+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
17562+ regs->ip = ip;
17563+ }
17564+#endif
17565+
17566 nmi_nesting_preprocess(regs);
17567
17568 nmi_enter();
17569diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
17570index 676b8c7..870ba04 100644
17571--- a/arch/x86/kernel/paravirt-spinlocks.c
17572+++ b/arch/x86/kernel/paravirt-spinlocks.c
17573@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
17574 arch_spin_lock(lock);
17575 }
17576
17577-struct pv_lock_ops pv_lock_ops = {
17578+struct pv_lock_ops pv_lock_ops __read_only = {
17579 #ifdef CONFIG_SMP
17580 .spin_is_locked = __ticket_spin_is_locked,
17581 .spin_is_contended = __ticket_spin_is_contended,
17582diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
17583index d90272e..6bb013b 100644
17584--- a/arch/x86/kernel/paravirt.c
17585+++ b/arch/x86/kernel/paravirt.c
17586@@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
17587 {
17588 return x;
17589 }
17590+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
17591+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
17592+#endif
17593
17594 void __init default_banner(void)
17595 {
17596@@ -145,15 +148,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
17597 if (opfunc == NULL)
17598 /* If there's no function, patch it with a ud2a (BUG) */
17599 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
17600- else if (opfunc == _paravirt_nop)
17601+ else if (opfunc == (void *)_paravirt_nop)
17602 /* If the operation is a nop, then nop the callsite */
17603 ret = paravirt_patch_nop();
17604
17605 /* identity functions just return their single argument */
17606- else if (opfunc == _paravirt_ident_32)
17607+ else if (opfunc == (void *)_paravirt_ident_32)
17608 ret = paravirt_patch_ident_32(insnbuf, len);
17609- else if (opfunc == _paravirt_ident_64)
17610+ else if (opfunc == (void *)_paravirt_ident_64)
17611 ret = paravirt_patch_ident_64(insnbuf, len);
17612+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
17613+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
17614+ ret = paravirt_patch_ident_64(insnbuf, len);
17615+#endif
17616
17617 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
17618 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
17619@@ -178,7 +185,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
17620 if (insn_len > len || start == NULL)
17621 insn_len = len;
17622 else
17623- memcpy(insnbuf, start, insn_len);
17624+ memcpy(insnbuf, ktla_ktva(start), insn_len);
17625
17626 return insn_len;
17627 }
17628@@ -302,7 +309,7 @@ void arch_flush_lazy_mmu_mode(void)
17629 preempt_enable();
17630 }
17631
17632-struct pv_info pv_info = {
17633+struct pv_info pv_info __read_only = {
17634 .name = "bare hardware",
17635 .paravirt_enabled = 0,
17636 .kernel_rpl = 0,
17637@@ -313,16 +320,16 @@ struct pv_info pv_info = {
17638 #endif
17639 };
17640
17641-struct pv_init_ops pv_init_ops = {
17642+struct pv_init_ops pv_init_ops __read_only = {
17643 .patch = native_patch,
17644 };
17645
17646-struct pv_time_ops pv_time_ops = {
17647+struct pv_time_ops pv_time_ops __read_only = {
17648 .sched_clock = native_sched_clock,
17649 .steal_clock = native_steal_clock,
17650 };
17651
17652-struct pv_irq_ops pv_irq_ops = {
17653+struct pv_irq_ops pv_irq_ops __read_only = {
17654 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
17655 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
17656 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
17657@@ -334,7 +341,7 @@ struct pv_irq_ops pv_irq_ops = {
17658 #endif
17659 };
17660
17661-struct pv_cpu_ops pv_cpu_ops = {
17662+struct pv_cpu_ops pv_cpu_ops __read_only = {
17663 .cpuid = native_cpuid,
17664 .get_debugreg = native_get_debugreg,
17665 .set_debugreg = native_set_debugreg,
17666@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
17667 .end_context_switch = paravirt_nop,
17668 };
17669
17670-struct pv_apic_ops pv_apic_ops = {
17671+struct pv_apic_ops pv_apic_ops __read_only = {
17672 #ifdef CONFIG_X86_LOCAL_APIC
17673 .startup_ipi_hook = paravirt_nop,
17674 #endif
17675 };
17676
17677-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
17678+#ifdef CONFIG_X86_32
17679+#ifdef CONFIG_X86_PAE
17680+/* 64-bit pagetable entries */
17681+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
17682+#else
17683 /* 32-bit pagetable entries */
17684 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
17685+#endif
17686 #else
17687 /* 64-bit pagetable entries */
17688 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
17689 #endif
17690
17691-struct pv_mmu_ops pv_mmu_ops = {
17692+struct pv_mmu_ops pv_mmu_ops __read_only = {
17693
17694 .read_cr2 = native_read_cr2,
17695 .write_cr2 = native_write_cr2,
17696@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
17697 .make_pud = PTE_IDENT,
17698
17699 .set_pgd = native_set_pgd,
17700+ .set_pgd_batched = native_set_pgd_batched,
17701 #endif
17702 #endif /* PAGETABLE_LEVELS >= 3 */
17703
17704@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
17705 },
17706
17707 .set_fixmap = native_set_fixmap,
17708+
17709+#ifdef CONFIG_PAX_KERNEXEC
17710+ .pax_open_kernel = native_pax_open_kernel,
17711+ .pax_close_kernel = native_pax_close_kernel,
17712+#endif
17713+
17714 };
17715
17716 EXPORT_SYMBOL_GPL(pv_time_ops);
17717diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
17718index 35ccf75..7a15747 100644
17719--- a/arch/x86/kernel/pci-iommu_table.c
17720+++ b/arch/x86/kernel/pci-iommu_table.c
17721@@ -2,7 +2,7 @@
17722 #include <asm/iommu_table.h>
17723 #include <linux/string.h>
17724 #include <linux/kallsyms.h>
17725-
17726+#include <linux/sched.h>
17727
17728 #define DEBUG 1
17729
17730diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
17731index 15763af..da59ada 100644
17732--- a/arch/x86/kernel/process.c
17733+++ b/arch/x86/kernel/process.c
17734@@ -48,16 +48,33 @@ void free_thread_xstate(struct task_struct *tsk)
17735
17736 void free_thread_info(struct thread_info *ti)
17737 {
17738- free_thread_xstate(ti->task);
17739 free_pages((unsigned long)ti, THREAD_ORDER);
17740 }
17741
17742+static struct kmem_cache *task_struct_cachep;
17743+
17744 void arch_task_cache_init(void)
17745 {
17746- task_xstate_cachep =
17747- kmem_cache_create("task_xstate", xstate_size,
17748+ /* create a slab on which task_structs can be allocated */
17749+ task_struct_cachep =
17750+ kmem_cache_create("task_struct", sizeof(struct task_struct),
17751+ ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
17752+
17753+ task_xstate_cachep =
17754+ kmem_cache_create("task_xstate", xstate_size,
17755 __alignof__(union thread_xstate),
17756- SLAB_PANIC | SLAB_NOTRACK, NULL);
17757+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
17758+}
17759+
17760+struct task_struct *alloc_task_struct_node(int node)
17761+{
17762+ return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
17763+}
17764+
17765+void free_task_struct(struct task_struct *task)
17766+{
17767+ free_thread_xstate(task);
17768+ kmem_cache_free(task_struct_cachep, task);
17769 }
17770
17771 /*
17772@@ -70,7 +87,7 @@ void exit_thread(void)
17773 unsigned long *bp = t->io_bitmap_ptr;
17774
17775 if (bp) {
17776- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
17777+ struct tss_struct *tss = init_tss + get_cpu();
17778
17779 t->io_bitmap_ptr = NULL;
17780 clear_thread_flag(TIF_IO_BITMAP);
17781@@ -106,7 +123,7 @@ void show_regs_common(void)
17782
17783 printk(KERN_CONT "\n");
17784 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
17785- current->pid, current->comm, print_tainted(),
17786+ task_pid_nr(current), current->comm, print_tainted(),
17787 init_utsname()->release,
17788 (int)strcspn(init_utsname()->version, " "),
17789 init_utsname()->version);
17790@@ -120,6 +137,9 @@ void flush_thread(void)
17791 {
17792 struct task_struct *tsk = current;
17793
17794+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
17795+ loadsegment(gs, 0);
17796+#endif
17797 flush_ptrace_hw_breakpoint(tsk);
17798 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
17799 /*
17800@@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
17801 regs.di = (unsigned long) arg;
17802
17803 #ifdef CONFIG_X86_32
17804- regs.ds = __USER_DS;
17805- regs.es = __USER_DS;
17806+ regs.ds = __KERNEL_DS;
17807+ regs.es = __KERNEL_DS;
17808 regs.fs = __KERNEL_PERCPU;
17809- regs.gs = __KERNEL_STACK_CANARY;
17810+ savesegment(gs, regs.gs);
17811 #else
17812 regs.ss = __KERNEL_DS;
17813 #endif
17814@@ -411,7 +431,7 @@ bool set_pm_idle_to_default(void)
17815
17816 return ret;
17817 }
17818-void stop_this_cpu(void *dummy)
17819+__noreturn void stop_this_cpu(void *dummy)
17820 {
17821 local_irq_disable();
17822 /*
17823@@ -653,16 +673,37 @@ static int __init idle_setup(char *str)
17824 }
17825 early_param("idle", idle_setup);
17826
17827-unsigned long arch_align_stack(unsigned long sp)
17828+#ifdef CONFIG_PAX_RANDKSTACK
17829+void pax_randomize_kstack(struct pt_regs *regs)
17830 {
17831- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
17832- sp -= get_random_int() % 8192;
17833- return sp & ~0xf;
17834-}
17835+ struct thread_struct *thread = &current->thread;
17836+ unsigned long time;
17837
17838-unsigned long arch_randomize_brk(struct mm_struct *mm)
17839-{
17840- unsigned long range_end = mm->brk + 0x02000000;
17841- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
17842-}
17843+ if (!randomize_va_space)
17844+ return;
17845+
17846+ if (v8086_mode(regs))
17847+ return;
17848
17849+ rdtscl(time);
17850+
17851+ /* P4 seems to return a 0 LSB, ignore it */
17852+#ifdef CONFIG_MPENTIUM4
17853+ time &= 0x3EUL;
17854+ time <<= 2;
17855+#elif defined(CONFIG_X86_64)
17856+ time &= 0xFUL;
17857+ time <<= 4;
17858+#else
17859+ time &= 0x1FUL;
17860+ time <<= 3;
17861+#endif
17862+
17863+ thread->sp0 ^= time;
17864+ load_sp0(init_tss + smp_processor_id(), thread);
17865+
17866+#ifdef CONFIG_X86_64
17867+ percpu_write(kernel_stack, thread->sp0);
17868+#endif
17869+}
17870+#endif
17871diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
17872index c08d1ff..6ae1c81 100644
17873--- a/arch/x86/kernel/process_32.c
17874+++ b/arch/x86/kernel/process_32.c
17875@@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
17876 unsigned long thread_saved_pc(struct task_struct *tsk)
17877 {
17878 return ((unsigned long *)tsk->thread.sp)[3];
17879+//XXX return tsk->thread.eip;
17880 }
17881
17882 #ifndef CONFIG_SMP
17883@@ -132,15 +133,14 @@ void __show_regs(struct pt_regs *regs, int all)
17884 unsigned long sp;
17885 unsigned short ss, gs;
17886
17887- if (user_mode_vm(regs)) {
17888+ if (user_mode(regs)) {
17889 sp = regs->sp;
17890 ss = regs->ss & 0xffff;
17891- gs = get_user_gs(regs);
17892 } else {
17893 sp = kernel_stack_pointer(regs);
17894 savesegment(ss, ss);
17895- savesegment(gs, gs);
17896 }
17897+ gs = get_user_gs(regs);
17898
17899 show_regs_common();
17900
17901@@ -202,13 +202,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
17902 struct task_struct *tsk;
17903 int err;
17904
17905- childregs = task_pt_regs(p);
17906+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
17907 *childregs = *regs;
17908 childregs->ax = 0;
17909 childregs->sp = sp;
17910
17911 p->thread.sp = (unsigned long) childregs;
17912 p->thread.sp0 = (unsigned long) (childregs+1);
17913+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
17914
17915 p->thread.ip = (unsigned long) ret_from_fork;
17916
17917@@ -299,7 +300,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17918 struct thread_struct *prev = &prev_p->thread,
17919 *next = &next_p->thread;
17920 int cpu = smp_processor_id();
17921- struct tss_struct *tss = &per_cpu(init_tss, cpu);
17922+ struct tss_struct *tss = init_tss + cpu;
17923 fpu_switch_t fpu;
17924
17925 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
17926@@ -323,6 +324,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17927 */
17928 lazy_save_gs(prev->gs);
17929
17930+#ifdef CONFIG_PAX_MEMORY_UDEREF
17931+ __set_fs(task_thread_info(next_p)->addr_limit);
17932+#endif
17933+
17934 /*
17935 * Load the per-thread Thread-Local Storage descriptor.
17936 */
17937@@ -353,6 +358,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17938 */
17939 arch_end_context_switch(next_p);
17940
17941+ percpu_write(current_task, next_p);
17942+ percpu_write(current_tinfo, &next_p->tinfo);
17943+
17944 /*
17945 * Restore %gs if needed (which is common)
17946 */
17947@@ -361,8 +369,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17948
17949 switch_fpu_finish(next_p, fpu);
17950
17951- percpu_write(current_task, next_p);
17952-
17953 return prev_p;
17954 }
17955
17956@@ -392,4 +398,3 @@ unsigned long get_wchan(struct task_struct *p)
17957 } while (count++ < 16);
17958 return 0;
17959 }
17960-
17961diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
17962index cfa5c90..4facd28 100644
17963--- a/arch/x86/kernel/process_64.c
17964+++ b/arch/x86/kernel/process_64.c
17965@@ -89,7 +89,7 @@ static void __exit_idle(void)
17966 void exit_idle(void)
17967 {
17968 /* idle loop has pid 0 */
17969- if (current->pid)
17970+ if (task_pid_nr(current))
17971 return;
17972 __exit_idle();
17973 }
17974@@ -270,8 +270,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
17975 struct pt_regs *childregs;
17976 struct task_struct *me = current;
17977
17978- childregs = ((struct pt_regs *)
17979- (THREAD_SIZE + task_stack_page(p))) - 1;
17980+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
17981 *childregs = *regs;
17982
17983 childregs->ax = 0;
17984@@ -283,6 +282,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
17985 p->thread.sp = (unsigned long) childregs;
17986 p->thread.sp0 = (unsigned long) (childregs+1);
17987 p->thread.usersp = me->thread.usersp;
17988+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
17989
17990 set_tsk_thread_flag(p, TIF_FORK);
17991
17992@@ -385,7 +385,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
17993 struct thread_struct *prev = &prev_p->thread;
17994 struct thread_struct *next = &next_p->thread;
17995 int cpu = smp_processor_id();
17996- struct tss_struct *tss = &per_cpu(init_tss, cpu);
17997+ struct tss_struct *tss = init_tss + cpu;
17998 unsigned fsindex, gsindex;
17999 fpu_switch_t fpu;
18000
18001@@ -467,10 +467,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18002 prev->usersp = percpu_read(old_rsp);
18003 percpu_write(old_rsp, next->usersp);
18004 percpu_write(current_task, next_p);
18005+ percpu_write(current_tinfo, &next_p->tinfo);
18006
18007- percpu_write(kernel_stack,
18008- (unsigned long)task_stack_page(next_p) +
18009- THREAD_SIZE - KERNEL_STACK_OFFSET);
18010+ percpu_write(kernel_stack, next->sp0);
18011
18012 /*
18013 * Now maybe reload the debug registers and handle I/O bitmaps
18014@@ -525,12 +524,11 @@ unsigned long get_wchan(struct task_struct *p)
18015 if (!p || p == current || p->state == TASK_RUNNING)
18016 return 0;
18017 stack = (unsigned long)task_stack_page(p);
18018- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18019+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18020 return 0;
18021 fp = *(u64 *)(p->thread.sp);
18022 do {
18023- if (fp < (unsigned long)stack ||
18024- fp >= (unsigned long)stack+THREAD_SIZE)
18025+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18026 return 0;
18027 ip = *(u64 *)(fp+8);
18028 if (!in_sched_functions(ip))
18029diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18030index 5026738..9e6d6dc 100644
18031--- a/arch/x86/kernel/ptrace.c
18032+++ b/arch/x86/kernel/ptrace.c
18033@@ -823,7 +823,7 @@ long arch_ptrace(struct task_struct *child, long request,
18034 unsigned long addr, unsigned long data)
18035 {
18036 int ret;
18037- unsigned long __user *datap = (unsigned long __user *)data;
18038+ unsigned long __user *datap = (__force unsigned long __user *)data;
18039
18040 switch (request) {
18041 /* read the word at location addr in the USER area. */
18042@@ -908,14 +908,14 @@ long arch_ptrace(struct task_struct *child, long request,
18043 if ((int) addr < 0)
18044 return -EIO;
18045 ret = do_get_thread_area(child, addr,
18046- (struct user_desc __user *)data);
18047+ (__force struct user_desc __user *) data);
18048 break;
18049
18050 case PTRACE_SET_THREAD_AREA:
18051 if ((int) addr < 0)
18052 return -EIO;
18053 ret = do_set_thread_area(child, addr,
18054- (struct user_desc __user *)data, 0);
18055+ (__force struct user_desc __user *) data, 0);
18056 break;
18057 #endif
18058
18059@@ -1332,7 +1332,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18060 memset(info, 0, sizeof(*info));
18061 info->si_signo = SIGTRAP;
18062 info->si_code = si_code;
18063- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18064+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18065 }
18066
18067 void user_single_step_siginfo(struct task_struct *tsk,
18068diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18069index 42eb330..139955c 100644
18070--- a/arch/x86/kernel/pvclock.c
18071+++ b/arch/x86/kernel/pvclock.c
18072@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18073 return pv_tsc_khz;
18074 }
18075
18076-static atomic64_t last_value = ATOMIC64_INIT(0);
18077+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18078
18079 void pvclock_resume(void)
18080 {
18081- atomic64_set(&last_value, 0);
18082+ atomic64_set_unchecked(&last_value, 0);
18083 }
18084
18085 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18086@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18087 * updating at the same time, and one of them could be slightly behind,
18088 * making the assumption that last_value always go forward fail to hold.
18089 */
18090- last = atomic64_read(&last_value);
18091+ last = atomic64_read_unchecked(&last_value);
18092 do {
18093 if (ret < last)
18094 return last;
18095- last = atomic64_cmpxchg(&last_value, last, ret);
18096+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18097 } while (unlikely(last != ret));
18098
18099 return ret;
18100diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18101index d840e69..98e9581 100644
18102--- a/arch/x86/kernel/reboot.c
18103+++ b/arch/x86/kernel/reboot.c
18104@@ -35,7 +35,7 @@ void (*pm_power_off)(void);
18105 EXPORT_SYMBOL(pm_power_off);
18106
18107 static const struct desc_ptr no_idt = {};
18108-static int reboot_mode;
18109+static unsigned short reboot_mode;
18110 enum reboot_type reboot_type = BOOT_ACPI;
18111 int reboot_force;
18112
18113@@ -335,13 +335,17 @@ core_initcall(reboot_init);
18114 extern const unsigned char machine_real_restart_asm[];
18115 extern const u64 machine_real_restart_gdt[3];
18116
18117-void machine_real_restart(unsigned int type)
18118+__noreturn void machine_real_restart(unsigned int type)
18119 {
18120 void *restart_va;
18121 unsigned long restart_pa;
18122- void (*restart_lowmem)(unsigned int);
18123+ void (* __noreturn restart_lowmem)(unsigned int);
18124 u64 *lowmem_gdt;
18125
18126+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18127+ struct desc_struct *gdt;
18128+#endif
18129+
18130 local_irq_disable();
18131
18132 /* Write zero to CMOS register number 0x0f, which the BIOS POST
18133@@ -367,14 +371,14 @@ void machine_real_restart(unsigned int type)
18134 boot)". This seems like a fairly standard thing that gets set by
18135 REBOOT.COM programs, and the previous reset routine did this
18136 too. */
18137- *((unsigned short *)0x472) = reboot_mode;
18138+ *(unsigned short *)(__va(0x472)) = reboot_mode;
18139
18140 /* Patch the GDT in the low memory trampoline */
18141 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
18142
18143 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
18144 restart_pa = virt_to_phys(restart_va);
18145- restart_lowmem = (void (*)(unsigned int))restart_pa;
18146+ restart_lowmem = (void *)restart_pa;
18147
18148 /* GDT[0]: GDT self-pointer */
18149 lowmem_gdt[0] =
18150@@ -385,7 +389,33 @@ void machine_real_restart(unsigned int type)
18151 GDT_ENTRY(0x009b, restart_pa, 0xffff);
18152
18153 /* Jump to the identity-mapped low memory code */
18154+
18155+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18156+ gdt = get_cpu_gdt_table(smp_processor_id());
18157+ pax_open_kernel();
18158+#ifdef CONFIG_PAX_MEMORY_UDEREF
18159+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18160+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18161+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18162+#endif
18163+#ifdef CONFIG_PAX_KERNEXEC
18164+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18165+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18166+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18167+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18168+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18169+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18170+#endif
18171+ pax_close_kernel();
18172+#endif
18173+
18174+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18175+ asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18176+ unreachable();
18177+#else
18178 restart_lowmem(type);
18179+#endif
18180+
18181 }
18182 #ifdef CONFIG_APM_MODULE
18183 EXPORT_SYMBOL(machine_real_restart);
18184@@ -556,7 +586,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18185 * try to force a triple fault and then cycle between hitting the keyboard
18186 * controller and doing that
18187 */
18188-static void native_machine_emergency_restart(void)
18189+__noreturn static void native_machine_emergency_restart(void)
18190 {
18191 int i;
18192 int attempt = 0;
18193@@ -680,13 +710,13 @@ void native_machine_shutdown(void)
18194 #endif
18195 }
18196
18197-static void __machine_emergency_restart(int emergency)
18198+static __noreturn void __machine_emergency_restart(int emergency)
18199 {
18200 reboot_emergency = emergency;
18201 machine_ops.emergency_restart();
18202 }
18203
18204-static void native_machine_restart(char *__unused)
18205+static __noreturn void native_machine_restart(char *__unused)
18206 {
18207 printk("machine restart\n");
18208
18209@@ -695,7 +725,7 @@ static void native_machine_restart(char *__unused)
18210 __machine_emergency_restart(0);
18211 }
18212
18213-static void native_machine_halt(void)
18214+static __noreturn void native_machine_halt(void)
18215 {
18216 /* stop other cpus and apics */
18217 machine_shutdown();
18218@@ -706,7 +736,7 @@ static void native_machine_halt(void)
18219 stop_this_cpu(NULL);
18220 }
18221
18222-static void native_machine_power_off(void)
18223+__noreturn static void native_machine_power_off(void)
18224 {
18225 if (pm_power_off) {
18226 if (!reboot_force)
18227@@ -715,6 +745,7 @@ static void native_machine_power_off(void)
18228 }
18229 /* a fallback in case there is no PM info available */
18230 tboot_shutdown(TB_SHUTDOWN_HALT);
18231+ unreachable();
18232 }
18233
18234 struct machine_ops machine_ops = {
18235diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18236index 7a6f3b3..bed145d7 100644
18237--- a/arch/x86/kernel/relocate_kernel_64.S
18238+++ b/arch/x86/kernel/relocate_kernel_64.S
18239@@ -11,6 +11,7 @@
18240 #include <asm/kexec.h>
18241 #include <asm/processor-flags.h>
18242 #include <asm/pgtable_types.h>
18243+#include <asm/alternative-asm.h>
18244
18245 /*
18246 * Must be relocatable PIC code callable as a C function
18247@@ -160,13 +161,14 @@ identity_mapped:
18248 xorq %rbp, %rbp
18249 xorq %r8, %r8
18250 xorq %r9, %r9
18251- xorq %r10, %r9
18252+ xorq %r10, %r10
18253 xorq %r11, %r11
18254 xorq %r12, %r12
18255 xorq %r13, %r13
18256 xorq %r14, %r14
18257 xorq %r15, %r15
18258
18259+ pax_force_retaddr 0, 1
18260 ret
18261
18262 1:
18263diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18264index d7d5099..28555d0 100644
18265--- a/arch/x86/kernel/setup.c
18266+++ b/arch/x86/kernel/setup.c
18267@@ -448,7 +448,7 @@ static void __init parse_setup_data(void)
18268
18269 switch (data->type) {
18270 case SETUP_E820_EXT:
18271- parse_e820_ext(data);
18272+ parse_e820_ext((struct setup_data __force_kernel *)data);
18273 break;
18274 case SETUP_DTB:
18275 add_dtb(pa_data);
18276@@ -649,7 +649,7 @@ static void __init trim_bios_range(void)
18277 * area (640->1Mb) as ram even though it is not.
18278 * take them out.
18279 */
18280- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
18281+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
18282 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
18283 }
18284
18285@@ -767,14 +767,14 @@ void __init setup_arch(char **cmdline_p)
18286
18287 if (!boot_params.hdr.root_flags)
18288 root_mountflags &= ~MS_RDONLY;
18289- init_mm.start_code = (unsigned long) _text;
18290- init_mm.end_code = (unsigned long) _etext;
18291+ init_mm.start_code = ktla_ktva((unsigned long) _text);
18292+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
18293 init_mm.end_data = (unsigned long) _edata;
18294 init_mm.brk = _brk_end;
18295
18296- code_resource.start = virt_to_phys(_text);
18297- code_resource.end = virt_to_phys(_etext)-1;
18298- data_resource.start = virt_to_phys(_etext);
18299+ code_resource.start = virt_to_phys(ktla_ktva(_text));
18300+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
18301+ data_resource.start = virt_to_phys(_sdata);
18302 data_resource.end = virt_to_phys(_edata)-1;
18303 bss_resource.start = virt_to_phys(&__bss_start);
18304 bss_resource.end = virt_to_phys(&__bss_stop)-1;
18305diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
18306index 71f4727..16dc9f7 100644
18307--- a/arch/x86/kernel/setup_percpu.c
18308+++ b/arch/x86/kernel/setup_percpu.c
18309@@ -21,19 +21,17 @@
18310 #include <asm/cpu.h>
18311 #include <asm/stackprotector.h>
18312
18313-DEFINE_PER_CPU(int, cpu_number);
18314+#ifdef CONFIG_SMP
18315+DEFINE_PER_CPU(unsigned int, cpu_number);
18316 EXPORT_PER_CPU_SYMBOL(cpu_number);
18317+#endif
18318
18319-#ifdef CONFIG_X86_64
18320 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
18321-#else
18322-#define BOOT_PERCPU_OFFSET 0
18323-#endif
18324
18325 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
18326 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
18327
18328-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
18329+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
18330 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
18331 };
18332 EXPORT_SYMBOL(__per_cpu_offset);
18333@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
18334 {
18335 #ifdef CONFIG_X86_32
18336 struct desc_struct gdt;
18337+ unsigned long base = per_cpu_offset(cpu);
18338
18339- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
18340- 0x2 | DESCTYPE_S, 0x8);
18341- gdt.s = 1;
18342+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
18343+ 0x83 | DESCTYPE_S, 0xC);
18344 write_gdt_entry(get_cpu_gdt_table(cpu),
18345 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
18346 #endif
18347@@ -207,6 +205,11 @@ void __init setup_per_cpu_areas(void)
18348 /* alrighty, percpu areas up and running */
18349 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
18350 for_each_possible_cpu(cpu) {
18351+#ifdef CONFIG_CC_STACKPROTECTOR
18352+#ifdef CONFIG_X86_32
18353+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
18354+#endif
18355+#endif
18356 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
18357 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
18358 per_cpu(cpu_number, cpu) = cpu;
18359@@ -247,6 +250,12 @@ void __init setup_per_cpu_areas(void)
18360 */
18361 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
18362 #endif
18363+#ifdef CONFIG_CC_STACKPROTECTOR
18364+#ifdef CONFIG_X86_32
18365+ if (!cpu)
18366+ per_cpu(stack_canary.canary, cpu) = canary;
18367+#endif
18368+#endif
18369 /*
18370 * Up to this point, the boot CPU has been using .init.data
18371 * area. Reload any changed state for the boot CPU.
18372diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
18373index 46a01bd..2e88e6d 100644
18374--- a/arch/x86/kernel/signal.c
18375+++ b/arch/x86/kernel/signal.c
18376@@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsigned long sp)
18377 * Align the stack pointer according to the i386 ABI,
18378 * i.e. so that on function entry ((sp + 4) & 15) == 0.
18379 */
18380- sp = ((sp + 4) & -16ul) - 4;
18381+ sp = ((sp - 12) & -16ul) - 4;
18382 #else /* !CONFIG_X86_32 */
18383 sp = round_down(sp, 16) - 8;
18384 #endif
18385@@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
18386 * Return an always-bogus address instead so we will die with SIGSEGV.
18387 */
18388 if (onsigstack && !likely(on_sig_stack(sp)))
18389- return (void __user *)-1L;
18390+ return (__force void __user *)-1L;
18391
18392 /* save i387 state */
18393 if (used_math() && save_i387_xstate(*fpstate) < 0)
18394- return (void __user *)-1L;
18395+ return (__force void __user *)-1L;
18396
18397 return (void __user *)sp;
18398 }
18399@@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18400 }
18401
18402 if (current->mm->context.vdso)
18403- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18404+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18405 else
18406- restorer = &frame->retcode;
18407+ restorer = (void __user *)&frame->retcode;
18408 if (ka->sa.sa_flags & SA_RESTORER)
18409 restorer = ka->sa.sa_restorer;
18410
18411@@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18412 * reasons and because gdb uses it as a signature to notice
18413 * signal handler stack frames.
18414 */
18415- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
18416+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
18417
18418 if (err)
18419 return -EFAULT;
18420@@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18421 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
18422
18423 /* Set up to return from userspace. */
18424- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18425+ if (current->mm->context.vdso)
18426+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
18427+ else
18428+ restorer = (void __user *)&frame->retcode;
18429 if (ka->sa.sa_flags & SA_RESTORER)
18430 restorer = ka->sa.sa_restorer;
18431 put_user_ex(restorer, &frame->pretcode);
18432@@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
18433 * reasons and because gdb uses it as a signature to notice
18434 * signal handler stack frames.
18435 */
18436- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
18437+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
18438 } put_user_catch(err);
18439
18440 if (err)
18441@@ -765,7 +768,7 @@ static void do_signal(struct pt_regs *regs)
18442 * X86_32: vm86 regs switched out by assembly code before reaching
18443 * here, so testing against kernel CS suffices.
18444 */
18445- if (!user_mode(regs))
18446+ if (!user_mode_novm(regs))
18447 return;
18448
18449 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
18450diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
18451index 66d250c..f1b10bd 100644
18452--- a/arch/x86/kernel/smpboot.c
18453+++ b/arch/x86/kernel/smpboot.c
18454@@ -715,17 +715,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
18455 set_idle_for_cpu(cpu, c_idle.idle);
18456 do_rest:
18457 per_cpu(current_task, cpu) = c_idle.idle;
18458+ per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
18459 #ifdef CONFIG_X86_32
18460 /* Stack for startup_32 can be just as for start_secondary onwards */
18461 irq_ctx_init(cpu);
18462 #else
18463 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
18464 initial_gs = per_cpu_offset(cpu);
18465- per_cpu(kernel_stack, cpu) =
18466- (unsigned long)task_stack_page(c_idle.idle) -
18467- KERNEL_STACK_OFFSET + THREAD_SIZE;
18468+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
18469 #endif
18470+
18471+ pax_open_kernel();
18472 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
18473+ pax_close_kernel();
18474+
18475 initial_code = (unsigned long)start_secondary;
18476 stack_start = c_idle.idle->thread.sp;
18477
18478@@ -868,6 +871,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
18479
18480 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
18481
18482+#ifdef CONFIG_PAX_PER_CPU_PGD
18483+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
18484+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
18485+ KERNEL_PGD_PTRS);
18486+#endif
18487+
18488 err = do_boot_cpu(apicid, cpu);
18489 if (err) {
18490 pr_debug("do_boot_cpu failed %d\n", err);
18491diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
18492index c346d11..d43b163 100644
18493--- a/arch/x86/kernel/step.c
18494+++ b/arch/x86/kernel/step.c
18495@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
18496 struct desc_struct *desc;
18497 unsigned long base;
18498
18499- seg &= ~7UL;
18500+ seg >>= 3;
18501
18502 mutex_lock(&child->mm->context.lock);
18503- if (unlikely((seg >> 3) >= child->mm->context.size))
18504+ if (unlikely(seg >= child->mm->context.size))
18505 addr = -1L; /* bogus selector, access would fault */
18506 else {
18507 desc = child->mm->context.ldt + seg;
18508@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
18509 addr += base;
18510 }
18511 mutex_unlock(&child->mm->context.lock);
18512- }
18513+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
18514+ addr = ktla_ktva(addr);
18515
18516 return addr;
18517 }
18518@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
18519 unsigned char opcode[15];
18520 unsigned long addr = convert_ip_to_linear(child, regs);
18521
18522+ if (addr == -EINVAL)
18523+ return 0;
18524+
18525 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
18526 for (i = 0; i < copied; i++) {
18527 switch (opcode[i]) {
18528diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
18529index 0b0cb5f..db6b9ed 100644
18530--- a/arch/x86/kernel/sys_i386_32.c
18531+++ b/arch/x86/kernel/sys_i386_32.c
18532@@ -24,17 +24,224 @@
18533
18534 #include <asm/syscalls.h>
18535
18536-/*
18537- * Do a system call from kernel instead of calling sys_execve so we
18538- * end up with proper pt_regs.
18539- */
18540-int kernel_execve(const char *filename,
18541- const char *const argv[],
18542- const char *const envp[])
18543+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
18544 {
18545- long __res;
18546- asm volatile ("int $0x80"
18547- : "=a" (__res)
18548- : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
18549- return __res;
18550+ unsigned long pax_task_size = TASK_SIZE;
18551+
18552+#ifdef CONFIG_PAX_SEGMEXEC
18553+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
18554+ pax_task_size = SEGMEXEC_TASK_SIZE;
18555+#endif
18556+
18557+ if (len > pax_task_size || addr > pax_task_size - len)
18558+ return -EINVAL;
18559+
18560+ return 0;
18561+}
18562+
18563+unsigned long
18564+arch_get_unmapped_area(struct file *filp, unsigned long addr,
18565+ unsigned long len, unsigned long pgoff, unsigned long flags)
18566+{
18567+ struct mm_struct *mm = current->mm;
18568+ struct vm_area_struct *vma;
18569+ unsigned long start_addr, pax_task_size = TASK_SIZE;
18570+
18571+#ifdef CONFIG_PAX_SEGMEXEC
18572+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
18573+ pax_task_size = SEGMEXEC_TASK_SIZE;
18574+#endif
18575+
18576+ pax_task_size -= PAGE_SIZE;
18577+
18578+ if (len > pax_task_size)
18579+ return -ENOMEM;
18580+
18581+ if (flags & MAP_FIXED)
18582+ return addr;
18583+
18584+#ifdef CONFIG_PAX_RANDMMAP
18585+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18586+#endif
18587+
18588+ if (addr) {
18589+ addr = PAGE_ALIGN(addr);
18590+ if (pax_task_size - len >= addr) {
18591+ vma = find_vma(mm, addr);
18592+ if (check_heap_stack_gap(vma, addr, len))
18593+ return addr;
18594+ }
18595+ }
18596+ if (len > mm->cached_hole_size) {
18597+ start_addr = addr = mm->free_area_cache;
18598+ } else {
18599+ start_addr = addr = mm->mmap_base;
18600+ mm->cached_hole_size = 0;
18601+ }
18602+
18603+#ifdef CONFIG_PAX_PAGEEXEC
18604+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
18605+ start_addr = 0x00110000UL;
18606+
18607+#ifdef CONFIG_PAX_RANDMMAP
18608+ if (mm->pax_flags & MF_PAX_RANDMMAP)
18609+ start_addr += mm->delta_mmap & 0x03FFF000UL;
18610+#endif
18611+
18612+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
18613+ start_addr = addr = mm->mmap_base;
18614+ else
18615+ addr = start_addr;
18616+ }
18617+#endif
18618+
18619+full_search:
18620+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
18621+ /* At this point: (!vma || addr < vma->vm_end). */
18622+ if (pax_task_size - len < addr) {
18623+ /*
18624+ * Start a new search - just in case we missed
18625+ * some holes.
18626+ */
18627+ if (start_addr != mm->mmap_base) {
18628+ start_addr = addr = mm->mmap_base;
18629+ mm->cached_hole_size = 0;
18630+ goto full_search;
18631+ }
18632+ return -ENOMEM;
18633+ }
18634+ if (check_heap_stack_gap(vma, addr, len))
18635+ break;
18636+ if (addr + mm->cached_hole_size < vma->vm_start)
18637+ mm->cached_hole_size = vma->vm_start - addr;
18638+ addr = vma->vm_end;
18639+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
18640+ start_addr = addr = mm->mmap_base;
18641+ mm->cached_hole_size = 0;
18642+ goto full_search;
18643+ }
18644+ }
18645+
18646+ /*
18647+ * Remember the place where we stopped the search:
18648+ */
18649+ mm->free_area_cache = addr + len;
18650+ return addr;
18651+}
18652+
18653+unsigned long
18654+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18655+ const unsigned long len, const unsigned long pgoff,
18656+ const unsigned long flags)
18657+{
18658+ struct vm_area_struct *vma;
18659+ struct mm_struct *mm = current->mm;
18660+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
18661+
18662+#ifdef CONFIG_PAX_SEGMEXEC
18663+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
18664+ pax_task_size = SEGMEXEC_TASK_SIZE;
18665+#endif
18666+
18667+ pax_task_size -= PAGE_SIZE;
18668+
18669+ /* requested length too big for entire address space */
18670+ if (len > pax_task_size)
18671+ return -ENOMEM;
18672+
18673+ if (flags & MAP_FIXED)
18674+ return addr;
18675+
18676+#ifdef CONFIG_PAX_PAGEEXEC
18677+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
18678+ goto bottomup;
18679+#endif
18680+
18681+#ifdef CONFIG_PAX_RANDMMAP
18682+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18683+#endif
18684+
18685+ /* requesting a specific address */
18686+ if (addr) {
18687+ addr = PAGE_ALIGN(addr);
18688+ if (pax_task_size - len >= addr) {
18689+ vma = find_vma(mm, addr);
18690+ if (check_heap_stack_gap(vma, addr, len))
18691+ return addr;
18692+ }
18693+ }
18694+
18695+ /* check if free_area_cache is useful for us */
18696+ if (len <= mm->cached_hole_size) {
18697+ mm->cached_hole_size = 0;
18698+ mm->free_area_cache = mm->mmap_base;
18699+ }
18700+
18701+ /* either no address requested or can't fit in requested address hole */
18702+ addr = mm->free_area_cache;
18703+
18704+ /* make sure it can fit in the remaining address space */
18705+ if (addr > len) {
18706+ vma = find_vma(mm, addr-len);
18707+ if (check_heap_stack_gap(vma, addr - len, len))
18708+ /* remember the address as a hint for next time */
18709+ return (mm->free_area_cache = addr-len);
18710+ }
18711+
18712+ if (mm->mmap_base < len)
18713+ goto bottomup;
18714+
18715+ addr = mm->mmap_base-len;
18716+
18717+ do {
18718+ /*
18719+ * Lookup failure means no vma is above this address,
18720+ * else if new region fits below vma->vm_start,
18721+ * return with success:
18722+ */
18723+ vma = find_vma(mm, addr);
18724+ if (check_heap_stack_gap(vma, addr, len))
18725+ /* remember the address as a hint for next time */
18726+ return (mm->free_area_cache = addr);
18727+
18728+ /* remember the largest hole we saw so far */
18729+ if (addr + mm->cached_hole_size < vma->vm_start)
18730+ mm->cached_hole_size = vma->vm_start - addr;
18731+
18732+ /* try just below the current vma->vm_start */
18733+ addr = skip_heap_stack_gap(vma, len);
18734+ } while (!IS_ERR_VALUE(addr));
18735+
18736+bottomup:
18737+ /*
18738+ * A failed mmap() very likely causes application failure,
18739+ * so fall back to the bottom-up function here. This scenario
18740+ * can happen with large stack limits and large mmap()
18741+ * allocations.
18742+ */
18743+
18744+#ifdef CONFIG_PAX_SEGMEXEC
18745+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
18746+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
18747+ else
18748+#endif
18749+
18750+ mm->mmap_base = TASK_UNMAPPED_BASE;
18751+
18752+#ifdef CONFIG_PAX_RANDMMAP
18753+ if (mm->pax_flags & MF_PAX_RANDMMAP)
18754+ mm->mmap_base += mm->delta_mmap;
18755+#endif
18756+
18757+ mm->free_area_cache = mm->mmap_base;
18758+ mm->cached_hole_size = ~0UL;
18759+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
18760+ /*
18761+ * Restore the topdown base:
18762+ */
18763+ mm->mmap_base = base;
18764+ mm->free_area_cache = base;
18765+ mm->cached_hole_size = ~0UL;
18766+
18767+ return addr;
18768 }
18769diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
18770index 0514890..3dbebce 100644
18771--- a/arch/x86/kernel/sys_x86_64.c
18772+++ b/arch/x86/kernel/sys_x86_64.c
18773@@ -95,8 +95,8 @@ out:
18774 return error;
18775 }
18776
18777-static void find_start_end(unsigned long flags, unsigned long *begin,
18778- unsigned long *end)
18779+static void find_start_end(struct mm_struct *mm, unsigned long flags,
18780+ unsigned long *begin, unsigned long *end)
18781 {
18782 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
18783 unsigned long new_begin;
18784@@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
18785 *begin = new_begin;
18786 }
18787 } else {
18788- *begin = TASK_UNMAPPED_BASE;
18789+ *begin = mm->mmap_base;
18790 *end = TASK_SIZE;
18791 }
18792 }
18793@@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
18794 if (flags & MAP_FIXED)
18795 return addr;
18796
18797- find_start_end(flags, &begin, &end);
18798+ find_start_end(mm, flags, &begin, &end);
18799
18800 if (len > end)
18801 return -ENOMEM;
18802
18803+#ifdef CONFIG_PAX_RANDMMAP
18804+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18805+#endif
18806+
18807 if (addr) {
18808 addr = PAGE_ALIGN(addr);
18809 vma = find_vma(mm, addr);
18810- if (end - len >= addr &&
18811- (!vma || addr + len <= vma->vm_start))
18812+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
18813 return addr;
18814 }
18815 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
18816@@ -172,7 +175,7 @@ full_search:
18817 }
18818 return -ENOMEM;
18819 }
18820- if (!vma || addr + len <= vma->vm_start) {
18821+ if (check_heap_stack_gap(vma, addr, len)) {
18822 /*
18823 * Remember the place where we stopped the search:
18824 */
18825@@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18826 {
18827 struct vm_area_struct *vma;
18828 struct mm_struct *mm = current->mm;
18829- unsigned long addr = addr0;
18830+ unsigned long base = mm->mmap_base, addr = addr0;
18831
18832 /* requested length too big for entire address space */
18833 if (len > TASK_SIZE)
18834@@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18835 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
18836 goto bottomup;
18837
18838+#ifdef CONFIG_PAX_RANDMMAP
18839+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
18840+#endif
18841+
18842 /* requesting a specific address */
18843 if (addr) {
18844 addr = PAGE_ALIGN(addr);
18845- vma = find_vma(mm, addr);
18846- if (TASK_SIZE - len >= addr &&
18847- (!vma || addr + len <= vma->vm_start))
18848- return addr;
18849+ if (TASK_SIZE - len >= addr) {
18850+ vma = find_vma(mm, addr);
18851+ if (check_heap_stack_gap(vma, addr, len))
18852+ return addr;
18853+ }
18854 }
18855
18856 /* check if free_area_cache is useful for us */
18857@@ -232,7 +240,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18858 ALIGN_TOPDOWN);
18859
18860 vma = find_vma(mm, tmp_addr);
18861- if (!vma || tmp_addr + len <= vma->vm_start)
18862+ if (check_heap_stack_gap(vma, tmp_addr, len))
18863 /* remember the address as a hint for next time */
18864 return mm->free_area_cache = tmp_addr;
18865 }
18866@@ -251,7 +259,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18867 * return with success:
18868 */
18869 vma = find_vma(mm, addr);
18870- if (!vma || addr+len <= vma->vm_start)
18871+ if (check_heap_stack_gap(vma, addr, len))
18872 /* remember the address as a hint for next time */
18873 return mm->free_area_cache = addr;
18874
18875@@ -260,8 +268,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
18876 mm->cached_hole_size = vma->vm_start - addr;
18877
18878 /* try just below the current vma->vm_start */
18879- addr = vma->vm_start-len;
18880- } while (len < vma->vm_start);
18881+ addr = skip_heap_stack_gap(vma, len);
18882+ } while (!IS_ERR_VALUE(addr));
18883
18884 bottomup:
18885 /*
18886@@ -270,13 +278,21 @@ bottomup:
18887 * can happen with large stack limits and large mmap()
18888 * allocations.
18889 */
18890+ mm->mmap_base = TASK_UNMAPPED_BASE;
18891+
18892+#ifdef CONFIG_PAX_RANDMMAP
18893+ if (mm->pax_flags & MF_PAX_RANDMMAP)
18894+ mm->mmap_base += mm->delta_mmap;
18895+#endif
18896+
18897+ mm->free_area_cache = mm->mmap_base;
18898 mm->cached_hole_size = ~0UL;
18899- mm->free_area_cache = TASK_UNMAPPED_BASE;
18900 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
18901 /*
18902 * Restore the topdown base:
18903 */
18904- mm->free_area_cache = mm->mmap_base;
18905+ mm->mmap_base = base;
18906+ mm->free_area_cache = base;
18907 mm->cached_hole_size = ~0UL;
18908
18909 return addr;
18910diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
18911index e2410e2..4fe3fbc 100644
18912--- a/arch/x86/kernel/tboot.c
18913+++ b/arch/x86/kernel/tboot.c
18914@@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
18915
18916 void tboot_shutdown(u32 shutdown_type)
18917 {
18918- void (*shutdown)(void);
18919+ void (* __noreturn shutdown)(void);
18920
18921 if (!tboot_enabled())
18922 return;
18923@@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
18924
18925 switch_to_tboot_pt();
18926
18927- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
18928+ shutdown = (void *)tboot->shutdown_entry;
18929 shutdown();
18930
18931 /* should not reach here */
18932@@ -298,7 +298,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
18933 tboot_shutdown(acpi_shutdown_map[sleep_state]);
18934 }
18935
18936-static atomic_t ap_wfs_count;
18937+static atomic_unchecked_t ap_wfs_count;
18938
18939 static int tboot_wait_for_aps(int num_aps)
18940 {
18941@@ -322,9 +322,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
18942 {
18943 switch (action) {
18944 case CPU_DYING:
18945- atomic_inc(&ap_wfs_count);
18946+ atomic_inc_unchecked(&ap_wfs_count);
18947 if (num_online_cpus() == 1)
18948- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
18949+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
18950 return NOTIFY_BAD;
18951 break;
18952 }
18953@@ -343,7 +343,7 @@ static __init int tboot_late_init(void)
18954
18955 tboot_create_trampoline();
18956
18957- atomic_set(&ap_wfs_count, 0);
18958+ atomic_set_unchecked(&ap_wfs_count, 0);
18959 register_hotcpu_notifier(&tboot_cpu_notifier);
18960 return 0;
18961 }
18962diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
18963index dd5fbf4..b7f2232 100644
18964--- a/arch/x86/kernel/time.c
18965+++ b/arch/x86/kernel/time.c
18966@@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
18967 {
18968 unsigned long pc = instruction_pointer(regs);
18969
18970- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
18971+ if (!user_mode(regs) && in_lock_functions(pc)) {
18972 #ifdef CONFIG_FRAME_POINTER
18973- return *(unsigned long *)(regs->bp + sizeof(long));
18974+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
18975 #else
18976 unsigned long *sp =
18977 (unsigned long *)kernel_stack_pointer(regs);
18978@@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
18979 * or above a saved flags. Eflags has bits 22-31 zero,
18980 * kernel addresses don't.
18981 */
18982+
18983+#ifdef CONFIG_PAX_KERNEXEC
18984+ return ktla_ktva(sp[0]);
18985+#else
18986 if (sp[0] >> 22)
18987 return sp[0];
18988 if (sp[1] >> 22)
18989 return sp[1];
18990 #endif
18991+
18992+#endif
18993 }
18994 return pc;
18995 }
18996diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
18997index bcfec2d..8f88b4a 100644
18998--- a/arch/x86/kernel/tls.c
18999+++ b/arch/x86/kernel/tls.c
19000@@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19001 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19002 return -EINVAL;
19003
19004+#ifdef CONFIG_PAX_SEGMEXEC
19005+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19006+ return -EINVAL;
19007+#endif
19008+
19009 set_tls_desc(p, idx, &info, 1);
19010
19011 return 0;
19012diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19013index 451c0a7..e57f551 100644
19014--- a/arch/x86/kernel/trampoline_32.S
19015+++ b/arch/x86/kernel/trampoline_32.S
19016@@ -32,6 +32,12 @@
19017 #include <asm/segment.h>
19018 #include <asm/page_types.h>
19019
19020+#ifdef CONFIG_PAX_KERNEXEC
19021+#define ta(X) (X)
19022+#else
19023+#define ta(X) ((X) - __PAGE_OFFSET)
19024+#endif
19025+
19026 #ifdef CONFIG_SMP
19027
19028 .section ".x86_trampoline","a"
19029@@ -62,7 +68,7 @@ r_base = .
19030 inc %ax # protected mode (PE) bit
19031 lmsw %ax # into protected mode
19032 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
19033- ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
19034+ ljmpl $__BOOT_CS, $ta(startup_32_smp)
19035
19036 # These need to be in the same 64K segment as the above;
19037 # hence we don't use the boot_gdt_descr defined in head.S
19038diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19039index 09ff517..df19fbff 100644
19040--- a/arch/x86/kernel/trampoline_64.S
19041+++ b/arch/x86/kernel/trampoline_64.S
19042@@ -90,7 +90,7 @@ startup_32:
19043 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
19044 movl %eax, %ds
19045
19046- movl $X86_CR4_PAE, %eax
19047+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19048 movl %eax, %cr4 # Enable PAE mode
19049
19050 # Setup trampoline 4 level pagetables
19051@@ -138,7 +138,7 @@ tidt:
19052 # so the kernel can live anywhere
19053 .balign 4
19054 tgdt:
19055- .short tgdt_end - tgdt # gdt limit
19056+ .short tgdt_end - tgdt - 1 # gdt limit
19057 .long tgdt - r_base
19058 .short 0
19059 .quad 0x00cf9b000000ffff # __KERNEL32_CS
19060diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19061index 4bbe04d..41d0943 100644
19062--- a/arch/x86/kernel/traps.c
19063+++ b/arch/x86/kernel/traps.c
19064@@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19065
19066 /* Do we ignore FPU interrupts ? */
19067 char ignore_fpu_irq;
19068-
19069-/*
19070- * The IDT has to be page-aligned to simplify the Pentium
19071- * F0 0F bug workaround.
19072- */
19073-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19074 #endif
19075
19076 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19077@@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19078 }
19079
19080 static void __kprobes
19081-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19082+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19083 long error_code, siginfo_t *info)
19084 {
19085 struct task_struct *tsk = current;
19086
19087 #ifdef CONFIG_X86_32
19088- if (regs->flags & X86_VM_MASK) {
19089+ if (v8086_mode(regs)) {
19090 /*
19091 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19092 * On nmi (interrupt 2), do_trap should not be called.
19093@@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19094 }
19095 #endif
19096
19097- if (!user_mode(regs))
19098+ if (!user_mode_novm(regs))
19099 goto kernel_trap;
19100
19101 #ifdef CONFIG_X86_32
19102@@ -148,7 +142,7 @@ trap_signal:
19103 printk_ratelimit()) {
19104 printk(KERN_INFO
19105 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19106- tsk->comm, tsk->pid, str,
19107+ tsk->comm, task_pid_nr(tsk), str,
19108 regs->ip, regs->sp, error_code);
19109 print_vma_addr(" in ", regs->ip);
19110 printk("\n");
19111@@ -165,8 +159,20 @@ kernel_trap:
19112 if (!fixup_exception(regs)) {
19113 tsk->thread.error_code = error_code;
19114 tsk->thread.trap_no = trapnr;
19115+
19116+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19117+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19118+ str = "PAX: suspicious stack segment fault";
19119+#endif
19120+
19121 die(str, regs, error_code);
19122 }
19123+
19124+#ifdef CONFIG_PAX_REFCOUNT
19125+ if (trapnr == 4)
19126+ pax_report_refcount_overflow(regs);
19127+#endif
19128+
19129 return;
19130
19131 #ifdef CONFIG_X86_32
19132@@ -255,14 +261,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19133 conditional_sti(regs);
19134
19135 #ifdef CONFIG_X86_32
19136- if (regs->flags & X86_VM_MASK)
19137+ if (v8086_mode(regs))
19138 goto gp_in_vm86;
19139 #endif
19140
19141 tsk = current;
19142- if (!user_mode(regs))
19143+ if (!user_mode_novm(regs))
19144 goto gp_in_kernel;
19145
19146+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19147+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19148+ struct mm_struct *mm = tsk->mm;
19149+ unsigned long limit;
19150+
19151+ down_write(&mm->mmap_sem);
19152+ limit = mm->context.user_cs_limit;
19153+ if (limit < TASK_SIZE) {
19154+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19155+ up_write(&mm->mmap_sem);
19156+ return;
19157+ }
19158+ up_write(&mm->mmap_sem);
19159+ }
19160+#endif
19161+
19162 tsk->thread.error_code = error_code;
19163 tsk->thread.trap_no = 13;
19164
19165@@ -295,6 +317,13 @@ gp_in_kernel:
19166 if (notify_die(DIE_GPF, "general protection fault", regs,
19167 error_code, 13, SIGSEGV) == NOTIFY_STOP)
19168 return;
19169+
19170+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19171+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19172+ die("PAX: suspicious general protection fault", regs, error_code);
19173+ else
19174+#endif
19175+
19176 die("general protection fault", regs, error_code);
19177 }
19178
19179@@ -421,7 +450,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19180 /* It's safe to allow irq's after DR6 has been saved */
19181 preempt_conditional_sti(regs);
19182
19183- if (regs->flags & X86_VM_MASK) {
19184+ if (v8086_mode(regs)) {
19185 handle_vm86_trap((struct kernel_vm86_regs *) regs,
19186 error_code, 1);
19187 preempt_conditional_cli(regs);
19188@@ -436,7 +465,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19189 * We already checked v86 mode above, so we can check for kernel mode
19190 * by just checking the CPL of CS.
19191 */
19192- if ((dr6 & DR_STEP) && !user_mode(regs)) {
19193+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19194 tsk->thread.debugreg6 &= ~DR_STEP;
19195 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19196 regs->flags &= ~X86_EFLAGS_TF;
19197@@ -466,7 +495,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19198 return;
19199 conditional_sti(regs);
19200
19201- if (!user_mode_vm(regs))
19202+ if (!user_mode(regs))
19203 {
19204 if (!fixup_exception(regs)) {
19205 task->thread.error_code = error_code;
19206diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19207index b9242ba..50c5edd 100644
19208--- a/arch/x86/kernel/verify_cpu.S
19209+++ b/arch/x86/kernel/verify_cpu.S
19210@@ -20,6 +20,7 @@
19211 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19212 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19213 * arch/x86/kernel/head_32.S: processor startup
19214+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19215 *
19216 * verify_cpu, returns the status of longmode and SSE in register %eax.
19217 * 0: Success 1: Failure
19218diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19219index 328cb37..56556b4 100644
19220--- a/arch/x86/kernel/vm86_32.c
19221+++ b/arch/x86/kernel/vm86_32.c
19222@@ -41,6 +41,7 @@
19223 #include <linux/ptrace.h>
19224 #include <linux/audit.h>
19225 #include <linux/stddef.h>
19226+#include <linux/grsecurity.h>
19227
19228 #include <asm/uaccess.h>
19229 #include <asm/io.h>
19230@@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19231 do_exit(SIGSEGV);
19232 }
19233
19234- tss = &per_cpu(init_tss, get_cpu());
19235+ tss = init_tss + get_cpu();
19236 current->thread.sp0 = current->thread.saved_sp0;
19237 current->thread.sysenter_cs = __KERNEL_CS;
19238 load_sp0(tss, &current->thread);
19239@@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19240 struct task_struct *tsk;
19241 int tmp, ret = -EPERM;
19242
19243+#ifdef CONFIG_GRKERNSEC_VM86
19244+ if (!capable(CAP_SYS_RAWIO)) {
19245+ gr_handle_vm86();
19246+ goto out;
19247+ }
19248+#endif
19249+
19250 tsk = current;
19251 if (tsk->thread.saved_sp0)
19252 goto out;
19253@@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19254 int tmp, ret;
19255 struct vm86plus_struct __user *v86;
19256
19257+#ifdef CONFIG_GRKERNSEC_VM86
19258+ if (!capable(CAP_SYS_RAWIO)) {
19259+ gr_handle_vm86();
19260+ ret = -EPERM;
19261+ goto out;
19262+ }
19263+#endif
19264+
19265 tsk = current;
19266 switch (cmd) {
19267 case VM86_REQUEST_IRQ:
19268@@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19269 tsk->thread.saved_fs = info->regs32->fs;
19270 tsk->thread.saved_gs = get_user_gs(info->regs32);
19271
19272- tss = &per_cpu(init_tss, get_cpu());
19273+ tss = init_tss + get_cpu();
19274 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19275 if (cpu_has_sep)
19276 tsk->thread.sysenter_cs = 0;
19277@@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19278 goto cannot_handle;
19279 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19280 goto cannot_handle;
19281- intr_ptr = (unsigned long __user *) (i << 2);
19282+ intr_ptr = (__force unsigned long __user *) (i << 2);
19283 if (get_user(segoffs, intr_ptr))
19284 goto cannot_handle;
19285 if ((segoffs >> 16) == BIOSSEG)
19286diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19287index 0f703f1..9e15f64 100644
19288--- a/arch/x86/kernel/vmlinux.lds.S
19289+++ b/arch/x86/kernel/vmlinux.lds.S
19290@@ -26,6 +26,13 @@
19291 #include <asm/page_types.h>
19292 #include <asm/cache.h>
19293 #include <asm/boot.h>
19294+#include <asm/segment.h>
19295+
19296+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19297+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19298+#else
19299+#define __KERNEL_TEXT_OFFSET 0
19300+#endif
19301
19302 #undef i386 /* in case the preprocessor is a 32bit one */
19303
19304@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
19305
19306 PHDRS {
19307 text PT_LOAD FLAGS(5); /* R_E */
19308+#ifdef CONFIG_X86_32
19309+ module PT_LOAD FLAGS(5); /* R_E */
19310+#endif
19311+#ifdef CONFIG_XEN
19312+ rodata PT_LOAD FLAGS(5); /* R_E */
19313+#else
19314+ rodata PT_LOAD FLAGS(4); /* R__ */
19315+#endif
19316 data PT_LOAD FLAGS(6); /* RW_ */
19317-#ifdef CONFIG_X86_64
19318+ init.begin PT_LOAD FLAGS(6); /* RW_ */
19319 #ifdef CONFIG_SMP
19320 percpu PT_LOAD FLAGS(6); /* RW_ */
19321 #endif
19322+ text.init PT_LOAD FLAGS(5); /* R_E */
19323+ text.exit PT_LOAD FLAGS(5); /* R_E */
19324 init PT_LOAD FLAGS(7); /* RWE */
19325-#endif
19326 note PT_NOTE FLAGS(0); /* ___ */
19327 }
19328
19329 SECTIONS
19330 {
19331 #ifdef CONFIG_X86_32
19332- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19333- phys_startup_32 = startup_32 - LOAD_OFFSET;
19334+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19335 #else
19336- . = __START_KERNEL;
19337- phys_startup_64 = startup_64 - LOAD_OFFSET;
19338+ . = __START_KERNEL;
19339 #endif
19340
19341 /* Text and read-only data */
19342- .text : AT(ADDR(.text) - LOAD_OFFSET) {
19343- _text = .;
19344+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19345 /* bootstrapping code */
19346+#ifdef CONFIG_X86_32
19347+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19348+#else
19349+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19350+#endif
19351+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19352+ _text = .;
19353 HEAD_TEXT
19354 #ifdef CONFIG_X86_32
19355 . = ALIGN(PAGE_SIZE);
19356@@ -108,13 +128,47 @@ SECTIONS
19357 IRQENTRY_TEXT
19358 *(.fixup)
19359 *(.gnu.warning)
19360- /* End of text section */
19361- _etext = .;
19362 } :text = 0x9090
19363
19364- NOTES :text :note
19365+ . += __KERNEL_TEXT_OFFSET;
19366
19367- EXCEPTION_TABLE(16) :text = 0x9090
19368+#ifdef CONFIG_X86_32
19369+ . = ALIGN(PAGE_SIZE);
19370+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19371+
19372+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19373+ MODULES_EXEC_VADDR = .;
19374+ BYTE(0)
19375+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19376+ . = ALIGN(HPAGE_SIZE);
19377+ MODULES_EXEC_END = . - 1;
19378+#endif
19379+
19380+ } :module
19381+#endif
19382+
19383+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
19384+ /* End of text section */
19385+ _etext = . - __KERNEL_TEXT_OFFSET;
19386+ }
19387+
19388+#ifdef CONFIG_X86_32
19389+ . = ALIGN(PAGE_SIZE);
19390+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
19391+ *(.idt)
19392+ . = ALIGN(PAGE_SIZE);
19393+ *(.empty_zero_page)
19394+ *(.initial_pg_fixmap)
19395+ *(.initial_pg_pmd)
19396+ *(.initial_page_table)
19397+ *(.swapper_pg_dir)
19398+ } :rodata
19399+#endif
19400+
19401+ . = ALIGN(PAGE_SIZE);
19402+ NOTES :rodata :note
19403+
19404+ EXCEPTION_TABLE(16) :rodata
19405
19406 #if defined(CONFIG_DEBUG_RODATA)
19407 /* .text should occupy whole number of pages */
19408@@ -126,16 +180,20 @@ SECTIONS
19409
19410 /* Data */
19411 .data : AT(ADDR(.data) - LOAD_OFFSET) {
19412+
19413+#ifdef CONFIG_PAX_KERNEXEC
19414+ . = ALIGN(HPAGE_SIZE);
19415+#else
19416+ . = ALIGN(PAGE_SIZE);
19417+#endif
19418+
19419 /* Start of data section */
19420 _sdata = .;
19421
19422 /* init_task */
19423 INIT_TASK_DATA(THREAD_SIZE)
19424
19425-#ifdef CONFIG_X86_32
19426- /* 32 bit has nosave before _edata */
19427 NOSAVE_DATA
19428-#endif
19429
19430 PAGE_ALIGNED_DATA(PAGE_SIZE)
19431
19432@@ -176,12 +234,19 @@ SECTIONS
19433 #endif /* CONFIG_X86_64 */
19434
19435 /* Init code and data - will be freed after init */
19436- . = ALIGN(PAGE_SIZE);
19437 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
19438+ BYTE(0)
19439+
19440+#ifdef CONFIG_PAX_KERNEXEC
19441+ . = ALIGN(HPAGE_SIZE);
19442+#else
19443+ . = ALIGN(PAGE_SIZE);
19444+#endif
19445+
19446 __init_begin = .; /* paired with __init_end */
19447- }
19448+ } :init.begin
19449
19450-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
19451+#ifdef CONFIG_SMP
19452 /*
19453 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
19454 * output PHDR, so the next output section - .init.text - should
19455@@ -190,12 +255,27 @@ SECTIONS
19456 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
19457 #endif
19458
19459- INIT_TEXT_SECTION(PAGE_SIZE)
19460-#ifdef CONFIG_X86_64
19461- :init
19462-#endif
19463+ . = ALIGN(PAGE_SIZE);
19464+ init_begin = .;
19465+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
19466+ VMLINUX_SYMBOL(_sinittext) = .;
19467+ INIT_TEXT
19468+ VMLINUX_SYMBOL(_einittext) = .;
19469+ . = ALIGN(PAGE_SIZE);
19470+ } :text.init
19471
19472- INIT_DATA_SECTION(16)
19473+ /*
19474+ * .exit.text is discard at runtime, not link time, to deal with
19475+ * references from .altinstructions and .eh_frame
19476+ */
19477+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19478+ EXIT_TEXT
19479+ . = ALIGN(16);
19480+ } :text.exit
19481+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
19482+
19483+ . = ALIGN(PAGE_SIZE);
19484+ INIT_DATA_SECTION(16) :init
19485
19486 /*
19487 * Code and data for a variety of lowlevel trampolines, to be
19488@@ -269,19 +349,12 @@ SECTIONS
19489 }
19490
19491 . = ALIGN(8);
19492- /*
19493- * .exit.text is discard at runtime, not link time, to deal with
19494- * references from .altinstructions and .eh_frame
19495- */
19496- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
19497- EXIT_TEXT
19498- }
19499
19500 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
19501 EXIT_DATA
19502 }
19503
19504-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
19505+#ifndef CONFIG_SMP
19506 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
19507 #endif
19508
19509@@ -300,16 +373,10 @@ SECTIONS
19510 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
19511 __smp_locks = .;
19512 *(.smp_locks)
19513- . = ALIGN(PAGE_SIZE);
19514 __smp_locks_end = .;
19515+ . = ALIGN(PAGE_SIZE);
19516 }
19517
19518-#ifdef CONFIG_X86_64
19519- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
19520- NOSAVE_DATA
19521- }
19522-#endif
19523-
19524 /* BSS */
19525 . = ALIGN(PAGE_SIZE);
19526 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
19527@@ -325,6 +392,7 @@ SECTIONS
19528 __brk_base = .;
19529 . += 64 * 1024; /* 64k alignment slop space */
19530 *(.brk_reservation) /* areas brk users have reserved */
19531+ . = ALIGN(HPAGE_SIZE);
19532 __brk_limit = .;
19533 }
19534
19535@@ -351,13 +419,12 @@ SECTIONS
19536 * for the boot processor.
19537 */
19538 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
19539-INIT_PER_CPU(gdt_page);
19540 INIT_PER_CPU(irq_stack_union);
19541
19542 /*
19543 * Build-time check on the image size:
19544 */
19545-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
19546+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
19547 "kernel image bigger than KERNEL_IMAGE_SIZE");
19548
19549 #ifdef CONFIG_SMP
19550diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
19551index b07ba93..a212969 100644
19552--- a/arch/x86/kernel/vsyscall_64.c
19553+++ b/arch/x86/kernel/vsyscall_64.c
19554@@ -57,15 +57,13 @@ DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data) =
19555 .lock = __SEQLOCK_UNLOCKED(__vsyscall_gtod_data.lock),
19556 };
19557
19558-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
19559+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
19560
19561 static int __init vsyscall_setup(char *str)
19562 {
19563 if (str) {
19564 if (!strcmp("emulate", str))
19565 vsyscall_mode = EMULATE;
19566- else if (!strcmp("native", str))
19567- vsyscall_mode = NATIVE;
19568 else if (!strcmp("none", str))
19569 vsyscall_mode = NONE;
19570 else
19571@@ -207,7 +205,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
19572
19573 tsk = current;
19574 if (seccomp_mode(&tsk->seccomp))
19575- do_exit(SIGKILL);
19576+ do_group_exit(SIGKILL);
19577
19578 /*
19579 * With a real vsyscall, page faults cause SIGSEGV. We want to
19580@@ -279,8 +277,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
19581 return true;
19582
19583 sigsegv:
19584- force_sig(SIGSEGV, current);
19585- return true;
19586+ do_group_exit(SIGKILL);
19587 }
19588
19589 /*
19590@@ -333,10 +330,7 @@ void __init map_vsyscall(void)
19591 extern char __vvar_page;
19592 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
19593
19594- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
19595- vsyscall_mode == NATIVE
19596- ? PAGE_KERNEL_VSYSCALL
19597- : PAGE_KERNEL_VVAR);
19598+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
19599 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
19600 (unsigned long)VSYSCALL_START);
19601
19602diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
19603index 9796c2f..f686fbf 100644
19604--- a/arch/x86/kernel/x8664_ksyms_64.c
19605+++ b/arch/x86/kernel/x8664_ksyms_64.c
19606@@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
19607 EXPORT_SYMBOL(copy_user_generic_string);
19608 EXPORT_SYMBOL(copy_user_generic_unrolled);
19609 EXPORT_SYMBOL(__copy_user_nocache);
19610-EXPORT_SYMBOL(_copy_from_user);
19611-EXPORT_SYMBOL(_copy_to_user);
19612
19613 EXPORT_SYMBOL(copy_page);
19614 EXPORT_SYMBOL(clear_page);
19615diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
19616index 7110911..e8cdee5 100644
19617--- a/arch/x86/kernel/xsave.c
19618+++ b/arch/x86/kernel/xsave.c
19619@@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
19620 fx_sw_user->xstate_size > fx_sw_user->extended_size)
19621 return -EINVAL;
19622
19623- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
19624+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
19625 fx_sw_user->extended_size -
19626 FP_XSTATE_MAGIC2_SIZE));
19627 if (err)
19628@@ -266,7 +266,7 @@ fx_only:
19629 * the other extended state.
19630 */
19631 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
19632- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
19633+ return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
19634 }
19635
19636 /*
19637@@ -295,7 +295,7 @@ int restore_i387_xstate(void __user *buf)
19638 if (use_xsave())
19639 err = restore_user_xstate(buf);
19640 else
19641- err = fxrstor_checking((__force struct i387_fxsave_struct *)
19642+ err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
19643 buf);
19644 if (unlikely(err)) {
19645 /*
19646diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
19647index 89b02bf..0f6511d 100644
19648--- a/arch/x86/kvm/cpuid.c
19649+++ b/arch/x86/kvm/cpuid.c
19650@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
19651 struct kvm_cpuid2 *cpuid,
19652 struct kvm_cpuid_entry2 __user *entries)
19653 {
19654- int r;
19655+ int r, i;
19656
19657 r = -E2BIG;
19658 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
19659 goto out;
19660 r = -EFAULT;
19661- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
19662- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
19663+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
19664 goto out;
19665+ for (i = 0; i < cpuid->nent; ++i) {
19666+ struct kvm_cpuid_entry2 cpuid_entry;
19667+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
19668+ goto out;
19669+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
19670+ }
19671 vcpu->arch.cpuid_nent = cpuid->nent;
19672 kvm_apic_set_version(vcpu);
19673 kvm_x86_ops->cpuid_update(vcpu);
19674@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
19675 struct kvm_cpuid2 *cpuid,
19676 struct kvm_cpuid_entry2 __user *entries)
19677 {
19678- int r;
19679+ int r, i;
19680
19681 r = -E2BIG;
19682 if (cpuid->nent < vcpu->arch.cpuid_nent)
19683 goto out;
19684 r = -EFAULT;
19685- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
19686- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
19687+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
19688 goto out;
19689+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
19690+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
19691+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
19692+ goto out;
19693+ }
19694 return 0;
19695
19696 out:
19697diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
19698index 0982507..7f6d72f 100644
19699--- a/arch/x86/kvm/emulate.c
19700+++ b/arch/x86/kvm/emulate.c
19701@@ -250,6 +250,7 @@ struct gprefix {
19702
19703 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
19704 do { \
19705+ unsigned long _tmp; \
19706 __asm__ __volatile__ ( \
19707 _PRE_EFLAGS("0", "4", "2") \
19708 _op _suffix " %"_x"3,%1; " \
19709@@ -264,8 +265,6 @@ struct gprefix {
19710 /* Raw emulation: instruction has two explicit operands. */
19711 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
19712 do { \
19713- unsigned long _tmp; \
19714- \
19715 switch ((ctxt)->dst.bytes) { \
19716 case 2: \
19717 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
19718@@ -281,7 +280,6 @@ struct gprefix {
19719
19720 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
19721 do { \
19722- unsigned long _tmp; \
19723 switch ((ctxt)->dst.bytes) { \
19724 case 1: \
19725 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
19726diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
19727index cfdc6e0..ab92e84 100644
19728--- a/arch/x86/kvm/lapic.c
19729+++ b/arch/x86/kvm/lapic.c
19730@@ -54,7 +54,7 @@
19731 #define APIC_BUS_CYCLE_NS 1
19732
19733 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
19734-#define apic_debug(fmt, arg...)
19735+#define apic_debug(fmt, arg...) do {} while (0)
19736
19737 #define APIC_LVT_NUM 6
19738 /* 14 is the version for Xeon and Pentium 8.4.8*/
19739diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
19740index 1561028..0ed7f14 100644
19741--- a/arch/x86/kvm/paging_tmpl.h
19742+++ b/arch/x86/kvm/paging_tmpl.h
19743@@ -197,7 +197,7 @@ retry_walk:
19744 if (unlikely(kvm_is_error_hva(host_addr)))
19745 goto error;
19746
19747- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
19748+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
19749 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
19750 goto error;
19751
19752diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
19753index e385214..f8df033 100644
19754--- a/arch/x86/kvm/svm.c
19755+++ b/arch/x86/kvm/svm.c
19756@@ -3420,7 +3420,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
19757 int cpu = raw_smp_processor_id();
19758
19759 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
19760+
19761+ pax_open_kernel();
19762 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
19763+ pax_close_kernel();
19764+
19765 load_TR_desc();
19766 }
19767
19768@@ -3798,6 +3802,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
19769 #endif
19770 #endif
19771
19772+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19773+ __set_fs(current_thread_info()->addr_limit);
19774+#endif
19775+
19776 reload_tss(vcpu);
19777
19778 local_irq_disable();
19779diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
19780index 3b4c8d8..f457b63 100644
19781--- a/arch/x86/kvm/vmx.c
19782+++ b/arch/x86/kvm/vmx.c
19783@@ -1306,7 +1306,11 @@ static void reload_tss(void)
19784 struct desc_struct *descs;
19785
19786 descs = (void *)gdt->address;
19787+
19788+ pax_open_kernel();
19789 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
19790+ pax_close_kernel();
19791+
19792 load_TR_desc();
19793 }
19794
19795@@ -2631,8 +2635,11 @@ static __init int hardware_setup(void)
19796 if (!cpu_has_vmx_flexpriority())
19797 flexpriority_enabled = 0;
19798
19799- if (!cpu_has_vmx_tpr_shadow())
19800- kvm_x86_ops->update_cr8_intercept = NULL;
19801+ if (!cpu_has_vmx_tpr_shadow()) {
19802+ pax_open_kernel();
19803+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
19804+ pax_close_kernel();
19805+ }
19806
19807 if (enable_ept && !cpu_has_vmx_ept_2m_page())
19808 kvm_disable_largepages();
19809@@ -3648,7 +3655,7 @@ static void vmx_set_constant_host_state(void)
19810 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
19811
19812 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
19813- vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
19814+ vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
19815
19816 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
19817 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
19818@@ -6184,6 +6191,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
19819 "jmp .Lkvm_vmx_return \n\t"
19820 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
19821 ".Lkvm_vmx_return: "
19822+
19823+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19824+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
19825+ ".Lkvm_vmx_return2: "
19826+#endif
19827+
19828 /* Save guest registers, load host registers, keep flags */
19829 "mov %0, %c[wordsize](%%"R"sp) \n\t"
19830 "pop %0 \n\t"
19831@@ -6232,6 +6245,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
19832 #endif
19833 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
19834 [wordsize]"i"(sizeof(ulong))
19835+
19836+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19837+ ,[cs]"i"(__KERNEL_CS)
19838+#endif
19839+
19840 : "cc", "memory"
19841 , R"ax", R"bx", R"di", R"si"
19842 #ifdef CONFIG_X86_64
19843@@ -6260,7 +6278,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
19844 }
19845 }
19846
19847- asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
19848+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
19849+
19850+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19851+ loadsegment(fs, __KERNEL_PERCPU);
19852+#endif
19853+
19854+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19855+ __set_fs(current_thread_info()->addr_limit);
19856+#endif
19857+
19858 vmx->loaded_vmcs->launched = 1;
19859
19860 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
19861diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
19862index 9cbfc06..7ddc9fa 100644
19863--- a/arch/x86/kvm/x86.c
19864+++ b/arch/x86/kvm/x86.c
19865@@ -1311,8 +1311,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
19866 {
19867 struct kvm *kvm = vcpu->kvm;
19868 int lm = is_long_mode(vcpu);
19869- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
19870- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
19871+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
19872+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
19873 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
19874 : kvm->arch.xen_hvm_config.blob_size_32;
19875 u32 page_num = data & ~PAGE_MASK;
19876@@ -2145,6 +2145,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
19877 if (n < msr_list.nmsrs)
19878 goto out;
19879 r = -EFAULT;
19880+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
19881+ goto out;
19882 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
19883 num_msrs_to_save * sizeof(u32)))
19884 goto out;
19885@@ -2266,7 +2268,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
19886 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
19887 struct kvm_interrupt *irq)
19888 {
19889- if (irq->irq < 0 || irq->irq >= 256)
19890+ if (irq->irq >= 256)
19891 return -EINVAL;
19892 if (irqchip_in_kernel(vcpu->kvm))
19893 return -ENXIO;
19894@@ -4780,7 +4782,7 @@ static void kvm_set_mmio_spte_mask(void)
19895 kvm_mmu_set_mmio_spte_mask(mask);
19896 }
19897
19898-int kvm_arch_init(void *opaque)
19899+int kvm_arch_init(const void *opaque)
19900 {
19901 int r;
19902 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
19903diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
19904index 642d880..44e0f3f 100644
19905--- a/arch/x86/lguest/boot.c
19906+++ b/arch/x86/lguest/boot.c
19907@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
19908 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
19909 * Launcher to reboot us.
19910 */
19911-static void lguest_restart(char *reason)
19912+static __noreturn void lguest_restart(char *reason)
19913 {
19914 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
19915+ BUG();
19916 }
19917
19918 /*G:050
19919diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
19920index 042f682..c92afb6 100644
19921--- a/arch/x86/lib/atomic64_32.c
19922+++ b/arch/x86/lib/atomic64_32.c
19923@@ -8,18 +8,30 @@
19924
19925 long long atomic64_read_cx8(long long, const atomic64_t *v);
19926 EXPORT_SYMBOL(atomic64_read_cx8);
19927+long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
19928+EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
19929 long long atomic64_set_cx8(long long, const atomic64_t *v);
19930 EXPORT_SYMBOL(atomic64_set_cx8);
19931+long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
19932+EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
19933 long long atomic64_xchg_cx8(long long, unsigned high);
19934 EXPORT_SYMBOL(atomic64_xchg_cx8);
19935 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
19936 EXPORT_SYMBOL(atomic64_add_return_cx8);
19937+long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
19938+EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
19939 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
19940 EXPORT_SYMBOL(atomic64_sub_return_cx8);
19941+long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
19942+EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
19943 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
19944 EXPORT_SYMBOL(atomic64_inc_return_cx8);
19945+long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
19946+EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
19947 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
19948 EXPORT_SYMBOL(atomic64_dec_return_cx8);
19949+long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
19950+EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
19951 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
19952 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
19953 int atomic64_inc_not_zero_cx8(atomic64_t *v);
19954@@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
19955 #ifndef CONFIG_X86_CMPXCHG64
19956 long long atomic64_read_386(long long, const atomic64_t *v);
19957 EXPORT_SYMBOL(atomic64_read_386);
19958+long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
19959+EXPORT_SYMBOL(atomic64_read_unchecked_386);
19960 long long atomic64_set_386(long long, const atomic64_t *v);
19961 EXPORT_SYMBOL(atomic64_set_386);
19962+long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
19963+EXPORT_SYMBOL(atomic64_set_unchecked_386);
19964 long long atomic64_xchg_386(long long, unsigned high);
19965 EXPORT_SYMBOL(atomic64_xchg_386);
19966 long long atomic64_add_return_386(long long a, atomic64_t *v);
19967 EXPORT_SYMBOL(atomic64_add_return_386);
19968+long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
19969+EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
19970 long long atomic64_sub_return_386(long long a, atomic64_t *v);
19971 EXPORT_SYMBOL(atomic64_sub_return_386);
19972+long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
19973+EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
19974 long long atomic64_inc_return_386(long long a, atomic64_t *v);
19975 EXPORT_SYMBOL(atomic64_inc_return_386);
19976+long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
19977+EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
19978 long long atomic64_dec_return_386(long long a, atomic64_t *v);
19979 EXPORT_SYMBOL(atomic64_dec_return_386);
19980+long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
19981+EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
19982 long long atomic64_add_386(long long a, atomic64_t *v);
19983 EXPORT_SYMBOL(atomic64_add_386);
19984+long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
19985+EXPORT_SYMBOL(atomic64_add_unchecked_386);
19986 long long atomic64_sub_386(long long a, atomic64_t *v);
19987 EXPORT_SYMBOL(atomic64_sub_386);
19988+long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
19989+EXPORT_SYMBOL(atomic64_sub_unchecked_386);
19990 long long atomic64_inc_386(long long a, atomic64_t *v);
19991 EXPORT_SYMBOL(atomic64_inc_386);
19992+long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
19993+EXPORT_SYMBOL(atomic64_inc_unchecked_386);
19994 long long atomic64_dec_386(long long a, atomic64_t *v);
19995 EXPORT_SYMBOL(atomic64_dec_386);
19996+long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
19997+EXPORT_SYMBOL(atomic64_dec_unchecked_386);
19998 long long atomic64_dec_if_positive_386(atomic64_t *v);
19999 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
20000 int atomic64_inc_not_zero_386(atomic64_t *v);
20001diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20002index e8e7e0d..56fd1b0 100644
20003--- a/arch/x86/lib/atomic64_386_32.S
20004+++ b/arch/x86/lib/atomic64_386_32.S
20005@@ -48,6 +48,10 @@ BEGIN(read)
20006 movl (v), %eax
20007 movl 4(v), %edx
20008 RET_ENDP
20009+BEGIN(read_unchecked)
20010+ movl (v), %eax
20011+ movl 4(v), %edx
20012+RET_ENDP
20013 #undef v
20014
20015 #define v %esi
20016@@ -55,6 +59,10 @@ BEGIN(set)
20017 movl %ebx, (v)
20018 movl %ecx, 4(v)
20019 RET_ENDP
20020+BEGIN(set_unchecked)
20021+ movl %ebx, (v)
20022+ movl %ecx, 4(v)
20023+RET_ENDP
20024 #undef v
20025
20026 #define v %esi
20027@@ -70,6 +78,20 @@ RET_ENDP
20028 BEGIN(add)
20029 addl %eax, (v)
20030 adcl %edx, 4(v)
20031+
20032+#ifdef CONFIG_PAX_REFCOUNT
20033+ jno 0f
20034+ subl %eax, (v)
20035+ sbbl %edx, 4(v)
20036+ int $4
20037+0:
20038+ _ASM_EXTABLE(0b, 0b)
20039+#endif
20040+
20041+RET_ENDP
20042+BEGIN(add_unchecked)
20043+ addl %eax, (v)
20044+ adcl %edx, 4(v)
20045 RET_ENDP
20046 #undef v
20047
20048@@ -77,6 +99,24 @@ RET_ENDP
20049 BEGIN(add_return)
20050 addl (v), %eax
20051 adcl 4(v), %edx
20052+
20053+#ifdef CONFIG_PAX_REFCOUNT
20054+ into
20055+1234:
20056+ _ASM_EXTABLE(1234b, 2f)
20057+#endif
20058+
20059+ movl %eax, (v)
20060+ movl %edx, 4(v)
20061+
20062+#ifdef CONFIG_PAX_REFCOUNT
20063+2:
20064+#endif
20065+
20066+RET_ENDP
20067+BEGIN(add_return_unchecked)
20068+ addl (v), %eax
20069+ adcl 4(v), %edx
20070 movl %eax, (v)
20071 movl %edx, 4(v)
20072 RET_ENDP
20073@@ -86,6 +126,20 @@ RET_ENDP
20074 BEGIN(sub)
20075 subl %eax, (v)
20076 sbbl %edx, 4(v)
20077+
20078+#ifdef CONFIG_PAX_REFCOUNT
20079+ jno 0f
20080+ addl %eax, (v)
20081+ adcl %edx, 4(v)
20082+ int $4
20083+0:
20084+ _ASM_EXTABLE(0b, 0b)
20085+#endif
20086+
20087+RET_ENDP
20088+BEGIN(sub_unchecked)
20089+ subl %eax, (v)
20090+ sbbl %edx, 4(v)
20091 RET_ENDP
20092 #undef v
20093
20094@@ -96,6 +150,27 @@ BEGIN(sub_return)
20095 sbbl $0, %edx
20096 addl (v), %eax
20097 adcl 4(v), %edx
20098+
20099+#ifdef CONFIG_PAX_REFCOUNT
20100+ into
20101+1234:
20102+ _ASM_EXTABLE(1234b, 2f)
20103+#endif
20104+
20105+ movl %eax, (v)
20106+ movl %edx, 4(v)
20107+
20108+#ifdef CONFIG_PAX_REFCOUNT
20109+2:
20110+#endif
20111+
20112+RET_ENDP
20113+BEGIN(sub_return_unchecked)
20114+ negl %edx
20115+ negl %eax
20116+ sbbl $0, %edx
20117+ addl (v), %eax
20118+ adcl 4(v), %edx
20119 movl %eax, (v)
20120 movl %edx, 4(v)
20121 RET_ENDP
20122@@ -105,6 +180,20 @@ RET_ENDP
20123 BEGIN(inc)
20124 addl $1, (v)
20125 adcl $0, 4(v)
20126+
20127+#ifdef CONFIG_PAX_REFCOUNT
20128+ jno 0f
20129+ subl $1, (v)
20130+ sbbl $0, 4(v)
20131+ int $4
20132+0:
20133+ _ASM_EXTABLE(0b, 0b)
20134+#endif
20135+
20136+RET_ENDP
20137+BEGIN(inc_unchecked)
20138+ addl $1, (v)
20139+ adcl $0, 4(v)
20140 RET_ENDP
20141 #undef v
20142
20143@@ -114,6 +203,26 @@ BEGIN(inc_return)
20144 movl 4(v), %edx
20145 addl $1, %eax
20146 adcl $0, %edx
20147+
20148+#ifdef CONFIG_PAX_REFCOUNT
20149+ into
20150+1234:
20151+ _ASM_EXTABLE(1234b, 2f)
20152+#endif
20153+
20154+ movl %eax, (v)
20155+ movl %edx, 4(v)
20156+
20157+#ifdef CONFIG_PAX_REFCOUNT
20158+2:
20159+#endif
20160+
20161+RET_ENDP
20162+BEGIN(inc_return_unchecked)
20163+ movl (v), %eax
20164+ movl 4(v), %edx
20165+ addl $1, %eax
20166+ adcl $0, %edx
20167 movl %eax, (v)
20168 movl %edx, 4(v)
20169 RET_ENDP
20170@@ -123,6 +232,20 @@ RET_ENDP
20171 BEGIN(dec)
20172 subl $1, (v)
20173 sbbl $0, 4(v)
20174+
20175+#ifdef CONFIG_PAX_REFCOUNT
20176+ jno 0f
20177+ addl $1, (v)
20178+ adcl $0, 4(v)
20179+ int $4
20180+0:
20181+ _ASM_EXTABLE(0b, 0b)
20182+#endif
20183+
20184+RET_ENDP
20185+BEGIN(dec_unchecked)
20186+ subl $1, (v)
20187+ sbbl $0, 4(v)
20188 RET_ENDP
20189 #undef v
20190
20191@@ -132,6 +255,26 @@ BEGIN(dec_return)
20192 movl 4(v), %edx
20193 subl $1, %eax
20194 sbbl $0, %edx
20195+
20196+#ifdef CONFIG_PAX_REFCOUNT
20197+ into
20198+1234:
20199+ _ASM_EXTABLE(1234b, 2f)
20200+#endif
20201+
20202+ movl %eax, (v)
20203+ movl %edx, 4(v)
20204+
20205+#ifdef CONFIG_PAX_REFCOUNT
20206+2:
20207+#endif
20208+
20209+RET_ENDP
20210+BEGIN(dec_return_unchecked)
20211+ movl (v), %eax
20212+ movl 4(v), %edx
20213+ subl $1, %eax
20214+ sbbl $0, %edx
20215 movl %eax, (v)
20216 movl %edx, 4(v)
20217 RET_ENDP
20218@@ -143,6 +286,13 @@ BEGIN(add_unless)
20219 adcl %edx, %edi
20220 addl (v), %eax
20221 adcl 4(v), %edx
20222+
20223+#ifdef CONFIG_PAX_REFCOUNT
20224+ into
20225+1234:
20226+ _ASM_EXTABLE(1234b, 2f)
20227+#endif
20228+
20229 cmpl %eax, %esi
20230 je 3f
20231 1:
20232@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20233 1:
20234 addl $1, %eax
20235 adcl $0, %edx
20236+
20237+#ifdef CONFIG_PAX_REFCOUNT
20238+ into
20239+1234:
20240+ _ASM_EXTABLE(1234b, 2f)
20241+#endif
20242+
20243 movl %eax, (v)
20244 movl %edx, 4(v)
20245 movl $1, %eax
20246@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20247 movl 4(v), %edx
20248 subl $1, %eax
20249 sbbl $0, %edx
20250+
20251+#ifdef CONFIG_PAX_REFCOUNT
20252+ into
20253+1234:
20254+ _ASM_EXTABLE(1234b, 1f)
20255+#endif
20256+
20257 js 1f
20258 movl %eax, (v)
20259 movl %edx, 4(v)
20260diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20261index 391a083..d658e9f 100644
20262--- a/arch/x86/lib/atomic64_cx8_32.S
20263+++ b/arch/x86/lib/atomic64_cx8_32.S
20264@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20265 CFI_STARTPROC
20266
20267 read64 %ecx
20268+ pax_force_retaddr
20269 ret
20270 CFI_ENDPROC
20271 ENDPROC(atomic64_read_cx8)
20272
20273+ENTRY(atomic64_read_unchecked_cx8)
20274+ CFI_STARTPROC
20275+
20276+ read64 %ecx
20277+ pax_force_retaddr
20278+ ret
20279+ CFI_ENDPROC
20280+ENDPROC(atomic64_read_unchecked_cx8)
20281+
20282 ENTRY(atomic64_set_cx8)
20283 CFI_STARTPROC
20284
20285@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20286 cmpxchg8b (%esi)
20287 jne 1b
20288
20289+ pax_force_retaddr
20290 ret
20291 CFI_ENDPROC
20292 ENDPROC(atomic64_set_cx8)
20293
20294+ENTRY(atomic64_set_unchecked_cx8)
20295+ CFI_STARTPROC
20296+
20297+1:
20298+/* we don't need LOCK_PREFIX since aligned 64-bit writes
20299+ * are atomic on 586 and newer */
20300+ cmpxchg8b (%esi)
20301+ jne 1b
20302+
20303+ pax_force_retaddr
20304+ ret
20305+ CFI_ENDPROC
20306+ENDPROC(atomic64_set_unchecked_cx8)
20307+
20308 ENTRY(atomic64_xchg_cx8)
20309 CFI_STARTPROC
20310
20311@@ -62,12 +87,13 @@ ENTRY(atomic64_xchg_cx8)
20312 cmpxchg8b (%esi)
20313 jne 1b
20314
20315+ pax_force_retaddr
20316 ret
20317 CFI_ENDPROC
20318 ENDPROC(atomic64_xchg_cx8)
20319
20320-.macro addsub_return func ins insc
20321-ENTRY(atomic64_\func\()_return_cx8)
20322+.macro addsub_return func ins insc unchecked=""
20323+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20324 CFI_STARTPROC
20325 SAVE ebp
20326 SAVE ebx
20327@@ -84,27 +110,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20328 movl %edx, %ecx
20329 \ins\()l %esi, %ebx
20330 \insc\()l %edi, %ecx
20331+
20332+.ifb \unchecked
20333+#ifdef CONFIG_PAX_REFCOUNT
20334+ into
20335+2:
20336+ _ASM_EXTABLE(2b, 3f)
20337+#endif
20338+.endif
20339+
20340 LOCK_PREFIX
20341 cmpxchg8b (%ebp)
20342 jne 1b
20343-
20344-10:
20345 movl %ebx, %eax
20346 movl %ecx, %edx
20347+
20348+.ifb \unchecked
20349+#ifdef CONFIG_PAX_REFCOUNT
20350+3:
20351+#endif
20352+.endif
20353+
20354 RESTORE edi
20355 RESTORE esi
20356 RESTORE ebx
20357 RESTORE ebp
20358+ pax_force_retaddr
20359 ret
20360 CFI_ENDPROC
20361-ENDPROC(atomic64_\func\()_return_cx8)
20362+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20363 .endm
20364
20365 addsub_return add add adc
20366 addsub_return sub sub sbb
20367+addsub_return add add adc _unchecked
20368+addsub_return sub sub sbb _unchecked
20369
20370-.macro incdec_return func ins insc
20371-ENTRY(atomic64_\func\()_return_cx8)
20372+.macro incdec_return func ins insc unchecked
20373+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20374 CFI_STARTPROC
20375 SAVE ebx
20376
20377@@ -114,21 +157,39 @@ ENTRY(atomic64_\func\()_return_cx8)
20378 movl %edx, %ecx
20379 \ins\()l $1, %ebx
20380 \insc\()l $0, %ecx
20381+
20382+.ifb \unchecked
20383+#ifdef CONFIG_PAX_REFCOUNT
20384+ into
20385+2:
20386+ _ASM_EXTABLE(2b, 3f)
20387+#endif
20388+.endif
20389+
20390 LOCK_PREFIX
20391 cmpxchg8b (%esi)
20392 jne 1b
20393
20394-10:
20395 movl %ebx, %eax
20396 movl %ecx, %edx
20397+
20398+.ifb \unchecked
20399+#ifdef CONFIG_PAX_REFCOUNT
20400+3:
20401+#endif
20402+.endif
20403+
20404 RESTORE ebx
20405+ pax_force_retaddr
20406 ret
20407 CFI_ENDPROC
20408-ENDPROC(atomic64_\func\()_return_cx8)
20409+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20410 .endm
20411
20412 incdec_return inc add adc
20413 incdec_return dec sub sbb
20414+incdec_return inc add adc _unchecked
20415+incdec_return dec sub sbb _unchecked
20416
20417 ENTRY(atomic64_dec_if_positive_cx8)
20418 CFI_STARTPROC
20419@@ -140,6 +201,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
20420 movl %edx, %ecx
20421 subl $1, %ebx
20422 sbb $0, %ecx
20423+
20424+#ifdef CONFIG_PAX_REFCOUNT
20425+ into
20426+1234:
20427+ _ASM_EXTABLE(1234b, 2f)
20428+#endif
20429+
20430 js 2f
20431 LOCK_PREFIX
20432 cmpxchg8b (%esi)
20433@@ -149,6 +217,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
20434 movl %ebx, %eax
20435 movl %ecx, %edx
20436 RESTORE ebx
20437+ pax_force_retaddr
20438 ret
20439 CFI_ENDPROC
20440 ENDPROC(atomic64_dec_if_positive_cx8)
20441@@ -174,6 +243,13 @@ ENTRY(atomic64_add_unless_cx8)
20442 movl %edx, %ecx
20443 addl %esi, %ebx
20444 adcl %edi, %ecx
20445+
20446+#ifdef CONFIG_PAX_REFCOUNT
20447+ into
20448+1234:
20449+ _ASM_EXTABLE(1234b, 3f)
20450+#endif
20451+
20452 LOCK_PREFIX
20453 cmpxchg8b (%ebp)
20454 jne 1b
20455@@ -184,6 +260,7 @@ ENTRY(atomic64_add_unless_cx8)
20456 CFI_ADJUST_CFA_OFFSET -8
20457 RESTORE ebx
20458 RESTORE ebp
20459+ pax_force_retaddr
20460 ret
20461 4:
20462 cmpl %edx, 4(%esp)
20463@@ -206,6 +283,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
20464 movl %edx, %ecx
20465 addl $1, %ebx
20466 adcl $0, %ecx
20467+
20468+#ifdef CONFIG_PAX_REFCOUNT
20469+ into
20470+1234:
20471+ _ASM_EXTABLE(1234b, 3f)
20472+#endif
20473+
20474 LOCK_PREFIX
20475 cmpxchg8b (%esi)
20476 jne 1b
20477@@ -213,6 +297,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
20478 movl $1, %eax
20479 3:
20480 RESTORE ebx
20481+ pax_force_retaddr
20482 ret
20483 4:
20484 testl %edx, %edx
20485diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
20486index 78d16a5..fbcf666 100644
20487--- a/arch/x86/lib/checksum_32.S
20488+++ b/arch/x86/lib/checksum_32.S
20489@@ -28,7 +28,8 @@
20490 #include <linux/linkage.h>
20491 #include <asm/dwarf2.h>
20492 #include <asm/errno.h>
20493-
20494+#include <asm/segment.h>
20495+
20496 /*
20497 * computes a partial checksum, e.g. for TCP/UDP fragments
20498 */
20499@@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
20500
20501 #define ARGBASE 16
20502 #define FP 12
20503-
20504-ENTRY(csum_partial_copy_generic)
20505+
20506+ENTRY(csum_partial_copy_generic_to_user)
20507 CFI_STARTPROC
20508+
20509+#ifdef CONFIG_PAX_MEMORY_UDEREF
20510+ pushl_cfi %gs
20511+ popl_cfi %es
20512+ jmp csum_partial_copy_generic
20513+#endif
20514+
20515+ENTRY(csum_partial_copy_generic_from_user)
20516+
20517+#ifdef CONFIG_PAX_MEMORY_UDEREF
20518+ pushl_cfi %gs
20519+ popl_cfi %ds
20520+#endif
20521+
20522+ENTRY(csum_partial_copy_generic)
20523 subl $4,%esp
20524 CFI_ADJUST_CFA_OFFSET 4
20525 pushl_cfi %edi
20526@@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
20527 jmp 4f
20528 SRC(1: movw (%esi), %bx )
20529 addl $2, %esi
20530-DST( movw %bx, (%edi) )
20531+DST( movw %bx, %es:(%edi) )
20532 addl $2, %edi
20533 addw %bx, %ax
20534 adcl $0, %eax
20535@@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
20536 SRC(1: movl (%esi), %ebx )
20537 SRC( movl 4(%esi), %edx )
20538 adcl %ebx, %eax
20539-DST( movl %ebx, (%edi) )
20540+DST( movl %ebx, %es:(%edi) )
20541 adcl %edx, %eax
20542-DST( movl %edx, 4(%edi) )
20543+DST( movl %edx, %es:4(%edi) )
20544
20545 SRC( movl 8(%esi), %ebx )
20546 SRC( movl 12(%esi), %edx )
20547 adcl %ebx, %eax
20548-DST( movl %ebx, 8(%edi) )
20549+DST( movl %ebx, %es:8(%edi) )
20550 adcl %edx, %eax
20551-DST( movl %edx, 12(%edi) )
20552+DST( movl %edx, %es:12(%edi) )
20553
20554 SRC( movl 16(%esi), %ebx )
20555 SRC( movl 20(%esi), %edx )
20556 adcl %ebx, %eax
20557-DST( movl %ebx, 16(%edi) )
20558+DST( movl %ebx, %es:16(%edi) )
20559 adcl %edx, %eax
20560-DST( movl %edx, 20(%edi) )
20561+DST( movl %edx, %es:20(%edi) )
20562
20563 SRC( movl 24(%esi), %ebx )
20564 SRC( movl 28(%esi), %edx )
20565 adcl %ebx, %eax
20566-DST( movl %ebx, 24(%edi) )
20567+DST( movl %ebx, %es:24(%edi) )
20568 adcl %edx, %eax
20569-DST( movl %edx, 28(%edi) )
20570+DST( movl %edx, %es:28(%edi) )
20571
20572 lea 32(%esi), %esi
20573 lea 32(%edi), %edi
20574@@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
20575 shrl $2, %edx # This clears CF
20576 SRC(3: movl (%esi), %ebx )
20577 adcl %ebx, %eax
20578-DST( movl %ebx, (%edi) )
20579+DST( movl %ebx, %es:(%edi) )
20580 lea 4(%esi), %esi
20581 lea 4(%edi), %edi
20582 dec %edx
20583@@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
20584 jb 5f
20585 SRC( movw (%esi), %cx )
20586 leal 2(%esi), %esi
20587-DST( movw %cx, (%edi) )
20588+DST( movw %cx, %es:(%edi) )
20589 leal 2(%edi), %edi
20590 je 6f
20591 shll $16,%ecx
20592 SRC(5: movb (%esi), %cl )
20593-DST( movb %cl, (%edi) )
20594+DST( movb %cl, %es:(%edi) )
20595 6: addl %ecx, %eax
20596 adcl $0, %eax
20597 7:
20598@@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
20599
20600 6001:
20601 movl ARGBASE+20(%esp), %ebx # src_err_ptr
20602- movl $-EFAULT, (%ebx)
20603+ movl $-EFAULT, %ss:(%ebx)
20604
20605 # zero the complete destination - computing the rest
20606 # is too much work
20607@@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
20608
20609 6002:
20610 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
20611- movl $-EFAULT,(%ebx)
20612+ movl $-EFAULT,%ss:(%ebx)
20613 jmp 5000b
20614
20615 .previous
20616
20617+ pushl_cfi %ss
20618+ popl_cfi %ds
20619+ pushl_cfi %ss
20620+ popl_cfi %es
20621 popl_cfi %ebx
20622 CFI_RESTORE ebx
20623 popl_cfi %esi
20624@@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
20625 popl_cfi %ecx # equivalent to addl $4,%esp
20626 ret
20627 CFI_ENDPROC
20628-ENDPROC(csum_partial_copy_generic)
20629+ENDPROC(csum_partial_copy_generic_to_user)
20630
20631 #else
20632
20633 /* Version for PentiumII/PPro */
20634
20635 #define ROUND1(x) \
20636+ nop; nop; nop; \
20637 SRC(movl x(%esi), %ebx ) ; \
20638 addl %ebx, %eax ; \
20639- DST(movl %ebx, x(%edi) ) ;
20640+ DST(movl %ebx, %es:x(%edi)) ;
20641
20642 #define ROUND(x) \
20643+ nop; nop; nop; \
20644 SRC(movl x(%esi), %ebx ) ; \
20645 adcl %ebx, %eax ; \
20646- DST(movl %ebx, x(%edi) ) ;
20647+ DST(movl %ebx, %es:x(%edi)) ;
20648
20649 #define ARGBASE 12
20650-
20651-ENTRY(csum_partial_copy_generic)
20652+
20653+ENTRY(csum_partial_copy_generic_to_user)
20654 CFI_STARTPROC
20655+
20656+#ifdef CONFIG_PAX_MEMORY_UDEREF
20657+ pushl_cfi %gs
20658+ popl_cfi %es
20659+ jmp csum_partial_copy_generic
20660+#endif
20661+
20662+ENTRY(csum_partial_copy_generic_from_user)
20663+
20664+#ifdef CONFIG_PAX_MEMORY_UDEREF
20665+ pushl_cfi %gs
20666+ popl_cfi %ds
20667+#endif
20668+
20669+ENTRY(csum_partial_copy_generic)
20670 pushl_cfi %ebx
20671 CFI_REL_OFFSET ebx, 0
20672 pushl_cfi %edi
20673@@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
20674 subl %ebx, %edi
20675 lea -1(%esi),%edx
20676 andl $-32,%edx
20677- lea 3f(%ebx,%ebx), %ebx
20678+ lea 3f(%ebx,%ebx,2), %ebx
20679 testl %esi, %esi
20680 jmp *%ebx
20681 1: addl $64,%esi
20682@@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
20683 jb 5f
20684 SRC( movw (%esi), %dx )
20685 leal 2(%esi), %esi
20686-DST( movw %dx, (%edi) )
20687+DST( movw %dx, %es:(%edi) )
20688 leal 2(%edi), %edi
20689 je 6f
20690 shll $16,%edx
20691 5:
20692 SRC( movb (%esi), %dl )
20693-DST( movb %dl, (%edi) )
20694+DST( movb %dl, %es:(%edi) )
20695 6: addl %edx, %eax
20696 adcl $0, %eax
20697 7:
20698 .section .fixup, "ax"
20699 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
20700- movl $-EFAULT, (%ebx)
20701+ movl $-EFAULT, %ss:(%ebx)
20702 # zero the complete destination (computing the rest is too much work)
20703 movl ARGBASE+8(%esp),%edi # dst
20704 movl ARGBASE+12(%esp),%ecx # len
20705@@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
20706 rep; stosb
20707 jmp 7b
20708 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
20709- movl $-EFAULT, (%ebx)
20710+ movl $-EFAULT, %ss:(%ebx)
20711 jmp 7b
20712 .previous
20713
20714+#ifdef CONFIG_PAX_MEMORY_UDEREF
20715+ pushl_cfi %ss
20716+ popl_cfi %ds
20717+ pushl_cfi %ss
20718+ popl_cfi %es
20719+#endif
20720+
20721 popl_cfi %esi
20722 CFI_RESTORE esi
20723 popl_cfi %edi
20724@@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
20725 CFI_RESTORE ebx
20726 ret
20727 CFI_ENDPROC
20728-ENDPROC(csum_partial_copy_generic)
20729+ENDPROC(csum_partial_copy_generic_to_user)
20730
20731 #undef ROUND
20732 #undef ROUND1
20733diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
20734index f2145cf..cea889d 100644
20735--- a/arch/x86/lib/clear_page_64.S
20736+++ b/arch/x86/lib/clear_page_64.S
20737@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
20738 movl $4096/8,%ecx
20739 xorl %eax,%eax
20740 rep stosq
20741+ pax_force_retaddr
20742 ret
20743 CFI_ENDPROC
20744 ENDPROC(clear_page_c)
20745@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
20746 movl $4096,%ecx
20747 xorl %eax,%eax
20748 rep stosb
20749+ pax_force_retaddr
20750 ret
20751 CFI_ENDPROC
20752 ENDPROC(clear_page_c_e)
20753@@ -43,6 +45,7 @@ ENTRY(clear_page)
20754 leaq 64(%rdi),%rdi
20755 jnz .Lloop
20756 nop
20757+ pax_force_retaddr
20758 ret
20759 CFI_ENDPROC
20760 .Lclear_page_end:
20761@@ -58,7 +61,7 @@ ENDPROC(clear_page)
20762
20763 #include <asm/cpufeature.h>
20764
20765- .section .altinstr_replacement,"ax"
20766+ .section .altinstr_replacement,"a"
20767 1: .byte 0xeb /* jmp <disp8> */
20768 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
20769 2: .byte 0xeb /* jmp <disp8> */
20770diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
20771index 1e572c5..2a162cd 100644
20772--- a/arch/x86/lib/cmpxchg16b_emu.S
20773+++ b/arch/x86/lib/cmpxchg16b_emu.S
20774@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
20775
20776 popf
20777 mov $1, %al
20778+ pax_force_retaddr
20779 ret
20780
20781 not_same:
20782 popf
20783 xor %al,%al
20784+ pax_force_retaddr
20785 ret
20786
20787 CFI_ENDPROC
20788diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
20789index 01c805b..dccb07f 100644
20790--- a/arch/x86/lib/copy_page_64.S
20791+++ b/arch/x86/lib/copy_page_64.S
20792@@ -9,6 +9,7 @@ copy_page_c:
20793 CFI_STARTPROC
20794 movl $4096/8,%ecx
20795 rep movsq
20796+ pax_force_retaddr
20797 ret
20798 CFI_ENDPROC
20799 ENDPROC(copy_page_c)
20800@@ -39,7 +40,7 @@ ENTRY(copy_page)
20801 movq 16 (%rsi), %rdx
20802 movq 24 (%rsi), %r8
20803 movq 32 (%rsi), %r9
20804- movq 40 (%rsi), %r10
20805+ movq 40 (%rsi), %r13
20806 movq 48 (%rsi), %r11
20807 movq 56 (%rsi), %r12
20808
20809@@ -50,7 +51,7 @@ ENTRY(copy_page)
20810 movq %rdx, 16 (%rdi)
20811 movq %r8, 24 (%rdi)
20812 movq %r9, 32 (%rdi)
20813- movq %r10, 40 (%rdi)
20814+ movq %r13, 40 (%rdi)
20815 movq %r11, 48 (%rdi)
20816 movq %r12, 56 (%rdi)
20817
20818@@ -69,7 +70,7 @@ ENTRY(copy_page)
20819 movq 16 (%rsi), %rdx
20820 movq 24 (%rsi), %r8
20821 movq 32 (%rsi), %r9
20822- movq 40 (%rsi), %r10
20823+ movq 40 (%rsi), %r13
20824 movq 48 (%rsi), %r11
20825 movq 56 (%rsi), %r12
20826
20827@@ -78,7 +79,7 @@ ENTRY(copy_page)
20828 movq %rdx, 16 (%rdi)
20829 movq %r8, 24 (%rdi)
20830 movq %r9, 32 (%rdi)
20831- movq %r10, 40 (%rdi)
20832+ movq %r13, 40 (%rdi)
20833 movq %r11, 48 (%rdi)
20834 movq %r12, 56 (%rdi)
20835
20836@@ -95,6 +96,7 @@ ENTRY(copy_page)
20837 CFI_RESTORE r13
20838 addq $3*8,%rsp
20839 CFI_ADJUST_CFA_OFFSET -3*8
20840+ pax_force_retaddr
20841 ret
20842 .Lcopy_page_end:
20843 CFI_ENDPROC
20844@@ -105,7 +107,7 @@ ENDPROC(copy_page)
20845
20846 #include <asm/cpufeature.h>
20847
20848- .section .altinstr_replacement,"ax"
20849+ .section .altinstr_replacement,"a"
20850 1: .byte 0xeb /* jmp <disp8> */
20851 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
20852 2:
20853diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
20854index 0248402..821c786 100644
20855--- a/arch/x86/lib/copy_user_64.S
20856+++ b/arch/x86/lib/copy_user_64.S
20857@@ -16,6 +16,7 @@
20858 #include <asm/thread_info.h>
20859 #include <asm/cpufeature.h>
20860 #include <asm/alternative-asm.h>
20861+#include <asm/pgtable.h>
20862
20863 /*
20864 * By placing feature2 after feature1 in altinstructions section, we logically
20865@@ -29,7 +30,7 @@
20866 .byte 0xe9 /* 32bit jump */
20867 .long \orig-1f /* by default jump to orig */
20868 1:
20869- .section .altinstr_replacement,"ax"
20870+ .section .altinstr_replacement,"a"
20871 2: .byte 0xe9 /* near jump with 32bit immediate */
20872 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
20873 3: .byte 0xe9 /* near jump with 32bit immediate */
20874@@ -71,47 +72,20 @@
20875 #endif
20876 .endm
20877
20878-/* Standard copy_to_user with segment limit checking */
20879-ENTRY(_copy_to_user)
20880- CFI_STARTPROC
20881- GET_THREAD_INFO(%rax)
20882- movq %rdi,%rcx
20883- addq %rdx,%rcx
20884- jc bad_to_user
20885- cmpq TI_addr_limit(%rax),%rcx
20886- ja bad_to_user
20887- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
20888- copy_user_generic_unrolled,copy_user_generic_string, \
20889- copy_user_enhanced_fast_string
20890- CFI_ENDPROC
20891-ENDPROC(_copy_to_user)
20892-
20893-/* Standard copy_from_user with segment limit checking */
20894-ENTRY(_copy_from_user)
20895- CFI_STARTPROC
20896- GET_THREAD_INFO(%rax)
20897- movq %rsi,%rcx
20898- addq %rdx,%rcx
20899- jc bad_from_user
20900- cmpq TI_addr_limit(%rax),%rcx
20901- ja bad_from_user
20902- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
20903- copy_user_generic_unrolled,copy_user_generic_string, \
20904- copy_user_enhanced_fast_string
20905- CFI_ENDPROC
20906-ENDPROC(_copy_from_user)
20907-
20908 .section .fixup,"ax"
20909 /* must zero dest */
20910 ENTRY(bad_from_user)
20911 bad_from_user:
20912 CFI_STARTPROC
20913+ testl %edx,%edx
20914+ js bad_to_user
20915 movl %edx,%ecx
20916 xorl %eax,%eax
20917 rep
20918 stosb
20919 bad_to_user:
20920 movl %edx,%eax
20921+ pax_force_retaddr
20922 ret
20923 CFI_ENDPROC
20924 ENDPROC(bad_from_user)
20925@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
20926 jz 17f
20927 1: movq (%rsi),%r8
20928 2: movq 1*8(%rsi),%r9
20929-3: movq 2*8(%rsi),%r10
20930+3: movq 2*8(%rsi),%rax
20931 4: movq 3*8(%rsi),%r11
20932 5: movq %r8,(%rdi)
20933 6: movq %r9,1*8(%rdi)
20934-7: movq %r10,2*8(%rdi)
20935+7: movq %rax,2*8(%rdi)
20936 8: movq %r11,3*8(%rdi)
20937 9: movq 4*8(%rsi),%r8
20938 10: movq 5*8(%rsi),%r9
20939-11: movq 6*8(%rsi),%r10
20940+11: movq 6*8(%rsi),%rax
20941 12: movq 7*8(%rsi),%r11
20942 13: movq %r8,4*8(%rdi)
20943 14: movq %r9,5*8(%rdi)
20944-15: movq %r10,6*8(%rdi)
20945+15: movq %rax,6*8(%rdi)
20946 16: movq %r11,7*8(%rdi)
20947 leaq 64(%rsi),%rsi
20948 leaq 64(%rdi),%rdi
20949@@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
20950 decl %ecx
20951 jnz 21b
20952 23: xor %eax,%eax
20953+ pax_force_retaddr
20954 ret
20955
20956 .section .fixup,"ax"
20957@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
20958 3: rep
20959 movsb
20960 4: xorl %eax,%eax
20961+ pax_force_retaddr
20962 ret
20963
20964 .section .fixup,"ax"
20965@@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
20966 1: rep
20967 movsb
20968 2: xorl %eax,%eax
20969+ pax_force_retaddr
20970 ret
20971
20972 .section .fixup,"ax"
20973diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
20974index cb0c112..e3a6895 100644
20975--- a/arch/x86/lib/copy_user_nocache_64.S
20976+++ b/arch/x86/lib/copy_user_nocache_64.S
20977@@ -8,12 +8,14 @@
20978
20979 #include <linux/linkage.h>
20980 #include <asm/dwarf2.h>
20981+#include <asm/alternative-asm.h>
20982
20983 #define FIX_ALIGNMENT 1
20984
20985 #include <asm/current.h>
20986 #include <asm/asm-offsets.h>
20987 #include <asm/thread_info.h>
20988+#include <asm/pgtable.h>
20989
20990 .macro ALIGN_DESTINATION
20991 #ifdef FIX_ALIGNMENT
20992@@ -50,6 +52,15 @@
20993 */
20994 ENTRY(__copy_user_nocache)
20995 CFI_STARTPROC
20996+
20997+#ifdef CONFIG_PAX_MEMORY_UDEREF
20998+ mov $PAX_USER_SHADOW_BASE,%rcx
20999+ cmp %rcx,%rsi
21000+ jae 1f
21001+ add %rcx,%rsi
21002+1:
21003+#endif
21004+
21005 cmpl $8,%edx
21006 jb 20f /* less then 8 bytes, go to byte copy loop */
21007 ALIGN_DESTINATION
21008@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
21009 jz 17f
21010 1: movq (%rsi),%r8
21011 2: movq 1*8(%rsi),%r9
21012-3: movq 2*8(%rsi),%r10
21013+3: movq 2*8(%rsi),%rax
21014 4: movq 3*8(%rsi),%r11
21015 5: movnti %r8,(%rdi)
21016 6: movnti %r9,1*8(%rdi)
21017-7: movnti %r10,2*8(%rdi)
21018+7: movnti %rax,2*8(%rdi)
21019 8: movnti %r11,3*8(%rdi)
21020 9: movq 4*8(%rsi),%r8
21021 10: movq 5*8(%rsi),%r9
21022-11: movq 6*8(%rsi),%r10
21023+11: movq 6*8(%rsi),%rax
21024 12: movq 7*8(%rsi),%r11
21025 13: movnti %r8,4*8(%rdi)
21026 14: movnti %r9,5*8(%rdi)
21027-15: movnti %r10,6*8(%rdi)
21028+15: movnti %rax,6*8(%rdi)
21029 16: movnti %r11,7*8(%rdi)
21030 leaq 64(%rsi),%rsi
21031 leaq 64(%rdi),%rdi
21032@@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
21033 jnz 21b
21034 23: xorl %eax,%eax
21035 sfence
21036+ pax_force_retaddr
21037 ret
21038
21039 .section .fixup,"ax"
21040diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21041index fb903b7..c92b7f7 100644
21042--- a/arch/x86/lib/csum-copy_64.S
21043+++ b/arch/x86/lib/csum-copy_64.S
21044@@ -8,6 +8,7 @@
21045 #include <linux/linkage.h>
21046 #include <asm/dwarf2.h>
21047 #include <asm/errno.h>
21048+#include <asm/alternative-asm.h>
21049
21050 /*
21051 * Checksum copy with exception handling.
21052@@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
21053 CFI_RESTORE rbp
21054 addq $7*8, %rsp
21055 CFI_ADJUST_CFA_OFFSET -7*8
21056+ pax_force_retaddr 0, 1
21057 ret
21058 CFI_RESTORE_STATE
21059
21060diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21061index 459b58a..9570bc7 100644
21062--- a/arch/x86/lib/csum-wrappers_64.c
21063+++ b/arch/x86/lib/csum-wrappers_64.c
21064@@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21065 len -= 2;
21066 }
21067 }
21068- isum = csum_partial_copy_generic((__force const void *)src,
21069+
21070+#ifdef CONFIG_PAX_MEMORY_UDEREF
21071+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21072+ src += PAX_USER_SHADOW_BASE;
21073+#endif
21074+
21075+ isum = csum_partial_copy_generic((const void __force_kernel *)src,
21076 dst, len, isum, errp, NULL);
21077 if (unlikely(*errp))
21078 goto out_err;
21079@@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21080 }
21081
21082 *errp = 0;
21083- return csum_partial_copy_generic(src, (void __force *)dst,
21084+
21085+#ifdef CONFIG_PAX_MEMORY_UDEREF
21086+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21087+ dst += PAX_USER_SHADOW_BASE;
21088+#endif
21089+
21090+ return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21091 len, isum, NULL, errp);
21092 }
21093 EXPORT_SYMBOL(csum_partial_copy_to_user);
21094diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21095index 51f1504..ddac4c1 100644
21096--- a/arch/x86/lib/getuser.S
21097+++ b/arch/x86/lib/getuser.S
21098@@ -33,15 +33,38 @@
21099 #include <asm/asm-offsets.h>
21100 #include <asm/thread_info.h>
21101 #include <asm/asm.h>
21102+#include <asm/segment.h>
21103+#include <asm/pgtable.h>
21104+#include <asm/alternative-asm.h>
21105+
21106+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21107+#define __copyuser_seg gs;
21108+#else
21109+#define __copyuser_seg
21110+#endif
21111
21112 .text
21113 ENTRY(__get_user_1)
21114 CFI_STARTPROC
21115+
21116+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21117 GET_THREAD_INFO(%_ASM_DX)
21118 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21119 jae bad_get_user
21120-1: movzb (%_ASM_AX),%edx
21121+
21122+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21123+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21124+ cmp %_ASM_DX,%_ASM_AX
21125+ jae 1234f
21126+ add %_ASM_DX,%_ASM_AX
21127+1234:
21128+#endif
21129+
21130+#endif
21131+
21132+1: __copyuser_seg movzb (%_ASM_AX),%edx
21133 xor %eax,%eax
21134+ pax_force_retaddr
21135 ret
21136 CFI_ENDPROC
21137 ENDPROC(__get_user_1)
21138@@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21139 ENTRY(__get_user_2)
21140 CFI_STARTPROC
21141 add $1,%_ASM_AX
21142+
21143+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21144 jc bad_get_user
21145 GET_THREAD_INFO(%_ASM_DX)
21146 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21147 jae bad_get_user
21148-2: movzwl -1(%_ASM_AX),%edx
21149+
21150+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21151+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21152+ cmp %_ASM_DX,%_ASM_AX
21153+ jae 1234f
21154+ add %_ASM_DX,%_ASM_AX
21155+1234:
21156+#endif
21157+
21158+#endif
21159+
21160+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21161 xor %eax,%eax
21162+ pax_force_retaddr
21163 ret
21164 CFI_ENDPROC
21165 ENDPROC(__get_user_2)
21166@@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21167 ENTRY(__get_user_4)
21168 CFI_STARTPROC
21169 add $3,%_ASM_AX
21170+
21171+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21172 jc bad_get_user
21173 GET_THREAD_INFO(%_ASM_DX)
21174 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21175 jae bad_get_user
21176-3: mov -3(%_ASM_AX),%edx
21177+
21178+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21179+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21180+ cmp %_ASM_DX,%_ASM_AX
21181+ jae 1234f
21182+ add %_ASM_DX,%_ASM_AX
21183+1234:
21184+#endif
21185+
21186+#endif
21187+
21188+3: __copyuser_seg mov -3(%_ASM_AX),%edx
21189 xor %eax,%eax
21190+ pax_force_retaddr
21191 ret
21192 CFI_ENDPROC
21193 ENDPROC(__get_user_4)
21194@@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21195 GET_THREAD_INFO(%_ASM_DX)
21196 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21197 jae bad_get_user
21198+
21199+#ifdef CONFIG_PAX_MEMORY_UDEREF
21200+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21201+ cmp %_ASM_DX,%_ASM_AX
21202+ jae 1234f
21203+ add %_ASM_DX,%_ASM_AX
21204+1234:
21205+#endif
21206+
21207 4: movq -7(%_ASM_AX),%_ASM_DX
21208 xor %eax,%eax
21209+ pax_force_retaddr
21210 ret
21211 CFI_ENDPROC
21212 ENDPROC(__get_user_8)
21213@@ -91,6 +152,7 @@ bad_get_user:
21214 CFI_STARTPROC
21215 xor %edx,%edx
21216 mov $(-EFAULT),%_ASM_AX
21217+ pax_force_retaddr
21218 ret
21219 CFI_ENDPROC
21220 END(bad_get_user)
21221diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21222index 5a1f9f3..ba9f577 100644
21223--- a/arch/x86/lib/insn.c
21224+++ b/arch/x86/lib/insn.c
21225@@ -21,6 +21,11 @@
21226 #include <linux/string.h>
21227 #include <asm/inat.h>
21228 #include <asm/insn.h>
21229+#ifdef __KERNEL__
21230+#include <asm/pgtable_types.h>
21231+#else
21232+#define ktla_ktva(addr) addr
21233+#endif
21234
21235 /* Verify next sizeof(t) bytes can be on the same instruction */
21236 #define validate_next(t, insn, n) \
21237@@ -49,8 +54,8 @@
21238 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21239 {
21240 memset(insn, 0, sizeof(*insn));
21241- insn->kaddr = kaddr;
21242- insn->next_byte = kaddr;
21243+ insn->kaddr = ktla_ktva(kaddr);
21244+ insn->next_byte = ktla_ktva(kaddr);
21245 insn->x86_64 = x86_64 ? 1 : 0;
21246 insn->opnd_bytes = 4;
21247 if (x86_64)
21248diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21249index 05a95e7..326f2fa 100644
21250--- a/arch/x86/lib/iomap_copy_64.S
21251+++ b/arch/x86/lib/iomap_copy_64.S
21252@@ -17,6 +17,7 @@
21253
21254 #include <linux/linkage.h>
21255 #include <asm/dwarf2.h>
21256+#include <asm/alternative-asm.h>
21257
21258 /*
21259 * override generic version in lib/iomap_copy.c
21260@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21261 CFI_STARTPROC
21262 movl %edx,%ecx
21263 rep movsd
21264+ pax_force_retaddr
21265 ret
21266 CFI_ENDPROC
21267 ENDPROC(__iowrite32_copy)
21268diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21269index efbf2a0..8893637 100644
21270--- a/arch/x86/lib/memcpy_64.S
21271+++ b/arch/x86/lib/memcpy_64.S
21272@@ -34,6 +34,7 @@
21273 rep movsq
21274 movl %edx, %ecx
21275 rep movsb
21276+ pax_force_retaddr
21277 ret
21278 .Lmemcpy_e:
21279 .previous
21280@@ -51,6 +52,7 @@
21281
21282 movl %edx, %ecx
21283 rep movsb
21284+ pax_force_retaddr
21285 ret
21286 .Lmemcpy_e_e:
21287 .previous
21288@@ -81,13 +83,13 @@ ENTRY(memcpy)
21289 */
21290 movq 0*8(%rsi), %r8
21291 movq 1*8(%rsi), %r9
21292- movq 2*8(%rsi), %r10
21293+ movq 2*8(%rsi), %rcx
21294 movq 3*8(%rsi), %r11
21295 leaq 4*8(%rsi), %rsi
21296
21297 movq %r8, 0*8(%rdi)
21298 movq %r9, 1*8(%rdi)
21299- movq %r10, 2*8(%rdi)
21300+ movq %rcx, 2*8(%rdi)
21301 movq %r11, 3*8(%rdi)
21302 leaq 4*8(%rdi), %rdi
21303 jae .Lcopy_forward_loop
21304@@ -110,12 +112,12 @@ ENTRY(memcpy)
21305 subq $0x20, %rdx
21306 movq -1*8(%rsi), %r8
21307 movq -2*8(%rsi), %r9
21308- movq -3*8(%rsi), %r10
21309+ movq -3*8(%rsi), %rcx
21310 movq -4*8(%rsi), %r11
21311 leaq -4*8(%rsi), %rsi
21312 movq %r8, -1*8(%rdi)
21313 movq %r9, -2*8(%rdi)
21314- movq %r10, -3*8(%rdi)
21315+ movq %rcx, -3*8(%rdi)
21316 movq %r11, -4*8(%rdi)
21317 leaq -4*8(%rdi), %rdi
21318 jae .Lcopy_backward_loop
21319@@ -135,12 +137,13 @@ ENTRY(memcpy)
21320 */
21321 movq 0*8(%rsi), %r8
21322 movq 1*8(%rsi), %r9
21323- movq -2*8(%rsi, %rdx), %r10
21324+ movq -2*8(%rsi, %rdx), %rcx
21325 movq -1*8(%rsi, %rdx), %r11
21326 movq %r8, 0*8(%rdi)
21327 movq %r9, 1*8(%rdi)
21328- movq %r10, -2*8(%rdi, %rdx)
21329+ movq %rcx, -2*8(%rdi, %rdx)
21330 movq %r11, -1*8(%rdi, %rdx)
21331+ pax_force_retaddr
21332 retq
21333 .p2align 4
21334 .Lless_16bytes:
21335@@ -153,6 +156,7 @@ ENTRY(memcpy)
21336 movq -1*8(%rsi, %rdx), %r9
21337 movq %r8, 0*8(%rdi)
21338 movq %r9, -1*8(%rdi, %rdx)
21339+ pax_force_retaddr
21340 retq
21341 .p2align 4
21342 .Lless_8bytes:
21343@@ -166,6 +170,7 @@ ENTRY(memcpy)
21344 movl -4(%rsi, %rdx), %r8d
21345 movl %ecx, (%rdi)
21346 movl %r8d, -4(%rdi, %rdx)
21347+ pax_force_retaddr
21348 retq
21349 .p2align 4
21350 .Lless_3bytes:
21351@@ -183,6 +188,7 @@ ENTRY(memcpy)
21352 jnz .Lloop_1
21353
21354 .Lend:
21355+ pax_force_retaddr
21356 retq
21357 CFI_ENDPROC
21358 ENDPROC(memcpy)
21359diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
21360index ee16461..c39c199 100644
21361--- a/arch/x86/lib/memmove_64.S
21362+++ b/arch/x86/lib/memmove_64.S
21363@@ -61,13 +61,13 @@ ENTRY(memmove)
21364 5:
21365 sub $0x20, %rdx
21366 movq 0*8(%rsi), %r11
21367- movq 1*8(%rsi), %r10
21368+ movq 1*8(%rsi), %rcx
21369 movq 2*8(%rsi), %r9
21370 movq 3*8(%rsi), %r8
21371 leaq 4*8(%rsi), %rsi
21372
21373 movq %r11, 0*8(%rdi)
21374- movq %r10, 1*8(%rdi)
21375+ movq %rcx, 1*8(%rdi)
21376 movq %r9, 2*8(%rdi)
21377 movq %r8, 3*8(%rdi)
21378 leaq 4*8(%rdi), %rdi
21379@@ -81,10 +81,10 @@ ENTRY(memmove)
21380 4:
21381 movq %rdx, %rcx
21382 movq -8(%rsi, %rdx), %r11
21383- lea -8(%rdi, %rdx), %r10
21384+ lea -8(%rdi, %rdx), %r9
21385 shrq $3, %rcx
21386 rep movsq
21387- movq %r11, (%r10)
21388+ movq %r11, (%r9)
21389 jmp 13f
21390 .Lmemmove_end_forward:
21391
21392@@ -95,14 +95,14 @@ ENTRY(memmove)
21393 7:
21394 movq %rdx, %rcx
21395 movq (%rsi), %r11
21396- movq %rdi, %r10
21397+ movq %rdi, %r9
21398 leaq -8(%rsi, %rdx), %rsi
21399 leaq -8(%rdi, %rdx), %rdi
21400 shrq $3, %rcx
21401 std
21402 rep movsq
21403 cld
21404- movq %r11, (%r10)
21405+ movq %r11, (%r9)
21406 jmp 13f
21407
21408 /*
21409@@ -127,13 +127,13 @@ ENTRY(memmove)
21410 8:
21411 subq $0x20, %rdx
21412 movq -1*8(%rsi), %r11
21413- movq -2*8(%rsi), %r10
21414+ movq -2*8(%rsi), %rcx
21415 movq -3*8(%rsi), %r9
21416 movq -4*8(%rsi), %r8
21417 leaq -4*8(%rsi), %rsi
21418
21419 movq %r11, -1*8(%rdi)
21420- movq %r10, -2*8(%rdi)
21421+ movq %rcx, -2*8(%rdi)
21422 movq %r9, -3*8(%rdi)
21423 movq %r8, -4*8(%rdi)
21424 leaq -4*8(%rdi), %rdi
21425@@ -151,11 +151,11 @@ ENTRY(memmove)
21426 * Move data from 16 bytes to 31 bytes.
21427 */
21428 movq 0*8(%rsi), %r11
21429- movq 1*8(%rsi), %r10
21430+ movq 1*8(%rsi), %rcx
21431 movq -2*8(%rsi, %rdx), %r9
21432 movq -1*8(%rsi, %rdx), %r8
21433 movq %r11, 0*8(%rdi)
21434- movq %r10, 1*8(%rdi)
21435+ movq %rcx, 1*8(%rdi)
21436 movq %r9, -2*8(%rdi, %rdx)
21437 movq %r8, -1*8(%rdi, %rdx)
21438 jmp 13f
21439@@ -167,9 +167,9 @@ ENTRY(memmove)
21440 * Move data from 8 bytes to 15 bytes.
21441 */
21442 movq 0*8(%rsi), %r11
21443- movq -1*8(%rsi, %rdx), %r10
21444+ movq -1*8(%rsi, %rdx), %r9
21445 movq %r11, 0*8(%rdi)
21446- movq %r10, -1*8(%rdi, %rdx)
21447+ movq %r9, -1*8(%rdi, %rdx)
21448 jmp 13f
21449 10:
21450 cmpq $4, %rdx
21451@@ -178,9 +178,9 @@ ENTRY(memmove)
21452 * Move data from 4 bytes to 7 bytes.
21453 */
21454 movl (%rsi), %r11d
21455- movl -4(%rsi, %rdx), %r10d
21456+ movl -4(%rsi, %rdx), %r9d
21457 movl %r11d, (%rdi)
21458- movl %r10d, -4(%rdi, %rdx)
21459+ movl %r9d, -4(%rdi, %rdx)
21460 jmp 13f
21461 11:
21462 cmp $2, %rdx
21463@@ -189,9 +189,9 @@ ENTRY(memmove)
21464 * Move data from 2 bytes to 3 bytes.
21465 */
21466 movw (%rsi), %r11w
21467- movw -2(%rsi, %rdx), %r10w
21468+ movw -2(%rsi, %rdx), %r9w
21469 movw %r11w, (%rdi)
21470- movw %r10w, -2(%rdi, %rdx)
21471+ movw %r9w, -2(%rdi, %rdx)
21472 jmp 13f
21473 12:
21474 cmp $1, %rdx
21475@@ -202,6 +202,7 @@ ENTRY(memmove)
21476 movb (%rsi), %r11b
21477 movb %r11b, (%rdi)
21478 13:
21479+ pax_force_retaddr
21480 retq
21481 CFI_ENDPROC
21482
21483@@ -210,6 +211,7 @@ ENTRY(memmove)
21484 /* Forward moving data. */
21485 movq %rdx, %rcx
21486 rep movsb
21487+ pax_force_retaddr
21488 retq
21489 .Lmemmove_end_forward_efs:
21490 .previous
21491diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
21492index 79bd454..dff325a 100644
21493--- a/arch/x86/lib/memset_64.S
21494+++ b/arch/x86/lib/memset_64.S
21495@@ -31,6 +31,7 @@
21496 movl %r8d,%ecx
21497 rep stosb
21498 movq %r9,%rax
21499+ pax_force_retaddr
21500 ret
21501 .Lmemset_e:
21502 .previous
21503@@ -53,6 +54,7 @@
21504 movl %edx,%ecx
21505 rep stosb
21506 movq %r9,%rax
21507+ pax_force_retaddr
21508 ret
21509 .Lmemset_e_e:
21510 .previous
21511@@ -60,13 +62,13 @@
21512 ENTRY(memset)
21513 ENTRY(__memset)
21514 CFI_STARTPROC
21515- movq %rdi,%r10
21516 movq %rdx,%r11
21517
21518 /* expand byte value */
21519 movzbl %sil,%ecx
21520 movabs $0x0101010101010101,%rax
21521 mul %rcx /* with rax, clobbers rdx */
21522+ movq %rdi,%rdx
21523
21524 /* align dst */
21525 movl %edi,%r9d
21526@@ -120,7 +122,8 @@ ENTRY(__memset)
21527 jnz .Lloop_1
21528
21529 .Lende:
21530- movq %r10,%rax
21531+ movq %rdx,%rax
21532+ pax_force_retaddr
21533 ret
21534
21535 CFI_RESTORE_STATE
21536diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
21537index c9f2d9b..e7fd2c0 100644
21538--- a/arch/x86/lib/mmx_32.c
21539+++ b/arch/x86/lib/mmx_32.c
21540@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
21541 {
21542 void *p;
21543 int i;
21544+ unsigned long cr0;
21545
21546 if (unlikely(in_interrupt()))
21547 return __memcpy(to, from, len);
21548@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
21549 kernel_fpu_begin();
21550
21551 __asm__ __volatile__ (
21552- "1: prefetch (%0)\n" /* This set is 28 bytes */
21553- " prefetch 64(%0)\n"
21554- " prefetch 128(%0)\n"
21555- " prefetch 192(%0)\n"
21556- " prefetch 256(%0)\n"
21557+ "1: prefetch (%1)\n" /* This set is 28 bytes */
21558+ " prefetch 64(%1)\n"
21559+ " prefetch 128(%1)\n"
21560+ " prefetch 192(%1)\n"
21561+ " prefetch 256(%1)\n"
21562 "2: \n"
21563 ".section .fixup, \"ax\"\n"
21564- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21565+ "3: \n"
21566+
21567+#ifdef CONFIG_PAX_KERNEXEC
21568+ " movl %%cr0, %0\n"
21569+ " movl %0, %%eax\n"
21570+ " andl $0xFFFEFFFF, %%eax\n"
21571+ " movl %%eax, %%cr0\n"
21572+#endif
21573+
21574+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21575+
21576+#ifdef CONFIG_PAX_KERNEXEC
21577+ " movl %0, %%cr0\n"
21578+#endif
21579+
21580 " jmp 2b\n"
21581 ".previous\n"
21582 _ASM_EXTABLE(1b, 3b)
21583- : : "r" (from));
21584+ : "=&r" (cr0) : "r" (from) : "ax");
21585
21586 for ( ; i > 5; i--) {
21587 __asm__ __volatile__ (
21588- "1: prefetch 320(%0)\n"
21589- "2: movq (%0), %%mm0\n"
21590- " movq 8(%0), %%mm1\n"
21591- " movq 16(%0), %%mm2\n"
21592- " movq 24(%0), %%mm3\n"
21593- " movq %%mm0, (%1)\n"
21594- " movq %%mm1, 8(%1)\n"
21595- " movq %%mm2, 16(%1)\n"
21596- " movq %%mm3, 24(%1)\n"
21597- " movq 32(%0), %%mm0\n"
21598- " movq 40(%0), %%mm1\n"
21599- " movq 48(%0), %%mm2\n"
21600- " movq 56(%0), %%mm3\n"
21601- " movq %%mm0, 32(%1)\n"
21602- " movq %%mm1, 40(%1)\n"
21603- " movq %%mm2, 48(%1)\n"
21604- " movq %%mm3, 56(%1)\n"
21605+ "1: prefetch 320(%1)\n"
21606+ "2: movq (%1), %%mm0\n"
21607+ " movq 8(%1), %%mm1\n"
21608+ " movq 16(%1), %%mm2\n"
21609+ " movq 24(%1), %%mm3\n"
21610+ " movq %%mm0, (%2)\n"
21611+ " movq %%mm1, 8(%2)\n"
21612+ " movq %%mm2, 16(%2)\n"
21613+ " movq %%mm3, 24(%2)\n"
21614+ " movq 32(%1), %%mm0\n"
21615+ " movq 40(%1), %%mm1\n"
21616+ " movq 48(%1), %%mm2\n"
21617+ " movq 56(%1), %%mm3\n"
21618+ " movq %%mm0, 32(%2)\n"
21619+ " movq %%mm1, 40(%2)\n"
21620+ " movq %%mm2, 48(%2)\n"
21621+ " movq %%mm3, 56(%2)\n"
21622 ".section .fixup, \"ax\"\n"
21623- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21624+ "3:\n"
21625+
21626+#ifdef CONFIG_PAX_KERNEXEC
21627+ " movl %%cr0, %0\n"
21628+ " movl %0, %%eax\n"
21629+ " andl $0xFFFEFFFF, %%eax\n"
21630+ " movl %%eax, %%cr0\n"
21631+#endif
21632+
21633+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21634+
21635+#ifdef CONFIG_PAX_KERNEXEC
21636+ " movl %0, %%cr0\n"
21637+#endif
21638+
21639 " jmp 2b\n"
21640 ".previous\n"
21641 _ASM_EXTABLE(1b, 3b)
21642- : : "r" (from), "r" (to) : "memory");
21643+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
21644
21645 from += 64;
21646 to += 64;
21647@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
21648 static void fast_copy_page(void *to, void *from)
21649 {
21650 int i;
21651+ unsigned long cr0;
21652
21653 kernel_fpu_begin();
21654
21655@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
21656 * but that is for later. -AV
21657 */
21658 __asm__ __volatile__(
21659- "1: prefetch (%0)\n"
21660- " prefetch 64(%0)\n"
21661- " prefetch 128(%0)\n"
21662- " prefetch 192(%0)\n"
21663- " prefetch 256(%0)\n"
21664+ "1: prefetch (%1)\n"
21665+ " prefetch 64(%1)\n"
21666+ " prefetch 128(%1)\n"
21667+ " prefetch 192(%1)\n"
21668+ " prefetch 256(%1)\n"
21669 "2: \n"
21670 ".section .fixup, \"ax\"\n"
21671- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21672+ "3: \n"
21673+
21674+#ifdef CONFIG_PAX_KERNEXEC
21675+ " movl %%cr0, %0\n"
21676+ " movl %0, %%eax\n"
21677+ " andl $0xFFFEFFFF, %%eax\n"
21678+ " movl %%eax, %%cr0\n"
21679+#endif
21680+
21681+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21682+
21683+#ifdef CONFIG_PAX_KERNEXEC
21684+ " movl %0, %%cr0\n"
21685+#endif
21686+
21687 " jmp 2b\n"
21688 ".previous\n"
21689- _ASM_EXTABLE(1b, 3b) : : "r" (from));
21690+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
21691
21692 for (i = 0; i < (4096-320)/64; i++) {
21693 __asm__ __volatile__ (
21694- "1: prefetch 320(%0)\n"
21695- "2: movq (%0), %%mm0\n"
21696- " movntq %%mm0, (%1)\n"
21697- " movq 8(%0), %%mm1\n"
21698- " movntq %%mm1, 8(%1)\n"
21699- " movq 16(%0), %%mm2\n"
21700- " movntq %%mm2, 16(%1)\n"
21701- " movq 24(%0), %%mm3\n"
21702- " movntq %%mm3, 24(%1)\n"
21703- " movq 32(%0), %%mm4\n"
21704- " movntq %%mm4, 32(%1)\n"
21705- " movq 40(%0), %%mm5\n"
21706- " movntq %%mm5, 40(%1)\n"
21707- " movq 48(%0), %%mm6\n"
21708- " movntq %%mm6, 48(%1)\n"
21709- " movq 56(%0), %%mm7\n"
21710- " movntq %%mm7, 56(%1)\n"
21711+ "1: prefetch 320(%1)\n"
21712+ "2: movq (%1), %%mm0\n"
21713+ " movntq %%mm0, (%2)\n"
21714+ " movq 8(%1), %%mm1\n"
21715+ " movntq %%mm1, 8(%2)\n"
21716+ " movq 16(%1), %%mm2\n"
21717+ " movntq %%mm2, 16(%2)\n"
21718+ " movq 24(%1), %%mm3\n"
21719+ " movntq %%mm3, 24(%2)\n"
21720+ " movq 32(%1), %%mm4\n"
21721+ " movntq %%mm4, 32(%2)\n"
21722+ " movq 40(%1), %%mm5\n"
21723+ " movntq %%mm5, 40(%2)\n"
21724+ " movq 48(%1), %%mm6\n"
21725+ " movntq %%mm6, 48(%2)\n"
21726+ " movq 56(%1), %%mm7\n"
21727+ " movntq %%mm7, 56(%2)\n"
21728 ".section .fixup, \"ax\"\n"
21729- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21730+ "3:\n"
21731+
21732+#ifdef CONFIG_PAX_KERNEXEC
21733+ " movl %%cr0, %0\n"
21734+ " movl %0, %%eax\n"
21735+ " andl $0xFFFEFFFF, %%eax\n"
21736+ " movl %%eax, %%cr0\n"
21737+#endif
21738+
21739+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21740+
21741+#ifdef CONFIG_PAX_KERNEXEC
21742+ " movl %0, %%cr0\n"
21743+#endif
21744+
21745 " jmp 2b\n"
21746 ".previous\n"
21747- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
21748+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
21749
21750 from += 64;
21751 to += 64;
21752@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
21753 static void fast_copy_page(void *to, void *from)
21754 {
21755 int i;
21756+ unsigned long cr0;
21757
21758 kernel_fpu_begin();
21759
21760 __asm__ __volatile__ (
21761- "1: prefetch (%0)\n"
21762- " prefetch 64(%0)\n"
21763- " prefetch 128(%0)\n"
21764- " prefetch 192(%0)\n"
21765- " prefetch 256(%0)\n"
21766+ "1: prefetch (%1)\n"
21767+ " prefetch 64(%1)\n"
21768+ " prefetch 128(%1)\n"
21769+ " prefetch 192(%1)\n"
21770+ " prefetch 256(%1)\n"
21771 "2: \n"
21772 ".section .fixup, \"ax\"\n"
21773- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21774+ "3: \n"
21775+
21776+#ifdef CONFIG_PAX_KERNEXEC
21777+ " movl %%cr0, %0\n"
21778+ " movl %0, %%eax\n"
21779+ " andl $0xFFFEFFFF, %%eax\n"
21780+ " movl %%eax, %%cr0\n"
21781+#endif
21782+
21783+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
21784+
21785+#ifdef CONFIG_PAX_KERNEXEC
21786+ " movl %0, %%cr0\n"
21787+#endif
21788+
21789 " jmp 2b\n"
21790 ".previous\n"
21791- _ASM_EXTABLE(1b, 3b) : : "r" (from));
21792+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
21793
21794 for (i = 0; i < 4096/64; i++) {
21795 __asm__ __volatile__ (
21796- "1: prefetch 320(%0)\n"
21797- "2: movq (%0), %%mm0\n"
21798- " movq 8(%0), %%mm1\n"
21799- " movq 16(%0), %%mm2\n"
21800- " movq 24(%0), %%mm3\n"
21801- " movq %%mm0, (%1)\n"
21802- " movq %%mm1, 8(%1)\n"
21803- " movq %%mm2, 16(%1)\n"
21804- " movq %%mm3, 24(%1)\n"
21805- " movq 32(%0), %%mm0\n"
21806- " movq 40(%0), %%mm1\n"
21807- " movq 48(%0), %%mm2\n"
21808- " movq 56(%0), %%mm3\n"
21809- " movq %%mm0, 32(%1)\n"
21810- " movq %%mm1, 40(%1)\n"
21811- " movq %%mm2, 48(%1)\n"
21812- " movq %%mm3, 56(%1)\n"
21813+ "1: prefetch 320(%1)\n"
21814+ "2: movq (%1), %%mm0\n"
21815+ " movq 8(%1), %%mm1\n"
21816+ " movq 16(%1), %%mm2\n"
21817+ " movq 24(%1), %%mm3\n"
21818+ " movq %%mm0, (%2)\n"
21819+ " movq %%mm1, 8(%2)\n"
21820+ " movq %%mm2, 16(%2)\n"
21821+ " movq %%mm3, 24(%2)\n"
21822+ " movq 32(%1), %%mm0\n"
21823+ " movq 40(%1), %%mm1\n"
21824+ " movq 48(%1), %%mm2\n"
21825+ " movq 56(%1), %%mm3\n"
21826+ " movq %%mm0, 32(%2)\n"
21827+ " movq %%mm1, 40(%2)\n"
21828+ " movq %%mm2, 48(%2)\n"
21829+ " movq %%mm3, 56(%2)\n"
21830 ".section .fixup, \"ax\"\n"
21831- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21832+ "3:\n"
21833+
21834+#ifdef CONFIG_PAX_KERNEXEC
21835+ " movl %%cr0, %0\n"
21836+ " movl %0, %%eax\n"
21837+ " andl $0xFFFEFFFF, %%eax\n"
21838+ " movl %%eax, %%cr0\n"
21839+#endif
21840+
21841+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
21842+
21843+#ifdef CONFIG_PAX_KERNEXEC
21844+ " movl %0, %%cr0\n"
21845+#endif
21846+
21847 " jmp 2b\n"
21848 ".previous\n"
21849 _ASM_EXTABLE(1b, 3b)
21850- : : "r" (from), "r" (to) : "memory");
21851+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
21852
21853 from += 64;
21854 to += 64;
21855diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
21856index 69fa106..adda88b 100644
21857--- a/arch/x86/lib/msr-reg.S
21858+++ b/arch/x86/lib/msr-reg.S
21859@@ -3,6 +3,7 @@
21860 #include <asm/dwarf2.h>
21861 #include <asm/asm.h>
21862 #include <asm/msr.h>
21863+#include <asm/alternative-asm.h>
21864
21865 #ifdef CONFIG_X86_64
21866 /*
21867@@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
21868 CFI_STARTPROC
21869 pushq_cfi %rbx
21870 pushq_cfi %rbp
21871- movq %rdi, %r10 /* Save pointer */
21872+ movq %rdi, %r9 /* Save pointer */
21873 xorl %r11d, %r11d /* Return value */
21874 movl (%rdi), %eax
21875 movl 4(%rdi), %ecx
21876@@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
21877 movl 28(%rdi), %edi
21878 CFI_REMEMBER_STATE
21879 1: \op
21880-2: movl %eax, (%r10)
21881+2: movl %eax, (%r9)
21882 movl %r11d, %eax /* Return value */
21883- movl %ecx, 4(%r10)
21884- movl %edx, 8(%r10)
21885- movl %ebx, 12(%r10)
21886- movl %ebp, 20(%r10)
21887- movl %esi, 24(%r10)
21888- movl %edi, 28(%r10)
21889+ movl %ecx, 4(%r9)
21890+ movl %edx, 8(%r9)
21891+ movl %ebx, 12(%r9)
21892+ movl %ebp, 20(%r9)
21893+ movl %esi, 24(%r9)
21894+ movl %edi, 28(%r9)
21895 popq_cfi %rbp
21896 popq_cfi %rbx
21897+ pax_force_retaddr
21898 ret
21899 3:
21900 CFI_RESTORE_STATE
21901diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
21902index 36b0d15..d381858 100644
21903--- a/arch/x86/lib/putuser.S
21904+++ b/arch/x86/lib/putuser.S
21905@@ -15,7 +15,9 @@
21906 #include <asm/thread_info.h>
21907 #include <asm/errno.h>
21908 #include <asm/asm.h>
21909-
21910+#include <asm/segment.h>
21911+#include <asm/pgtable.h>
21912+#include <asm/alternative-asm.h>
21913
21914 /*
21915 * __put_user_X
21916@@ -29,52 +31,119 @@
21917 * as they get called from within inline assembly.
21918 */
21919
21920-#define ENTER CFI_STARTPROC ; \
21921- GET_THREAD_INFO(%_ASM_BX)
21922-#define EXIT ret ; \
21923+#define ENTER CFI_STARTPROC
21924+#define EXIT pax_force_retaddr; ret ; \
21925 CFI_ENDPROC
21926
21927+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21928+#define _DEST %_ASM_CX,%_ASM_BX
21929+#else
21930+#define _DEST %_ASM_CX
21931+#endif
21932+
21933+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21934+#define __copyuser_seg gs;
21935+#else
21936+#define __copyuser_seg
21937+#endif
21938+
21939 .text
21940 ENTRY(__put_user_1)
21941 ENTER
21942+
21943+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21944+ GET_THREAD_INFO(%_ASM_BX)
21945 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
21946 jae bad_put_user
21947-1: movb %al,(%_ASM_CX)
21948+
21949+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21950+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
21951+ cmp %_ASM_BX,%_ASM_CX
21952+ jb 1234f
21953+ xor %ebx,%ebx
21954+1234:
21955+#endif
21956+
21957+#endif
21958+
21959+1: __copyuser_seg movb %al,(_DEST)
21960 xor %eax,%eax
21961 EXIT
21962 ENDPROC(__put_user_1)
21963
21964 ENTRY(__put_user_2)
21965 ENTER
21966+
21967+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21968+ GET_THREAD_INFO(%_ASM_BX)
21969 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
21970 sub $1,%_ASM_BX
21971 cmp %_ASM_BX,%_ASM_CX
21972 jae bad_put_user
21973-2: movw %ax,(%_ASM_CX)
21974+
21975+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21976+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
21977+ cmp %_ASM_BX,%_ASM_CX
21978+ jb 1234f
21979+ xor %ebx,%ebx
21980+1234:
21981+#endif
21982+
21983+#endif
21984+
21985+2: __copyuser_seg movw %ax,(_DEST)
21986 xor %eax,%eax
21987 EXIT
21988 ENDPROC(__put_user_2)
21989
21990 ENTRY(__put_user_4)
21991 ENTER
21992+
21993+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21994+ GET_THREAD_INFO(%_ASM_BX)
21995 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
21996 sub $3,%_ASM_BX
21997 cmp %_ASM_BX,%_ASM_CX
21998 jae bad_put_user
21999-3: movl %eax,(%_ASM_CX)
22000+
22001+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22002+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22003+ cmp %_ASM_BX,%_ASM_CX
22004+ jb 1234f
22005+ xor %ebx,%ebx
22006+1234:
22007+#endif
22008+
22009+#endif
22010+
22011+3: __copyuser_seg movl %eax,(_DEST)
22012 xor %eax,%eax
22013 EXIT
22014 ENDPROC(__put_user_4)
22015
22016 ENTRY(__put_user_8)
22017 ENTER
22018+
22019+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22020+ GET_THREAD_INFO(%_ASM_BX)
22021 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22022 sub $7,%_ASM_BX
22023 cmp %_ASM_BX,%_ASM_CX
22024 jae bad_put_user
22025-4: mov %_ASM_AX,(%_ASM_CX)
22026+
22027+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22028+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22029+ cmp %_ASM_BX,%_ASM_CX
22030+ jb 1234f
22031+ xor %ebx,%ebx
22032+1234:
22033+#endif
22034+
22035+#endif
22036+
22037+4: __copyuser_seg mov %_ASM_AX,(_DEST)
22038 #ifdef CONFIG_X86_32
22039-5: movl %edx,4(%_ASM_CX)
22040+5: __copyuser_seg movl %edx,4(_DEST)
22041 #endif
22042 xor %eax,%eax
22043 EXIT
22044diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22045index 1cad221..de671ee 100644
22046--- a/arch/x86/lib/rwlock.S
22047+++ b/arch/x86/lib/rwlock.S
22048@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22049 FRAME
22050 0: LOCK_PREFIX
22051 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22052+
22053+#ifdef CONFIG_PAX_REFCOUNT
22054+ jno 1234f
22055+ LOCK_PREFIX
22056+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22057+ int $4
22058+1234:
22059+ _ASM_EXTABLE(1234b, 1234b)
22060+#endif
22061+
22062 1: rep; nop
22063 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22064 jne 1b
22065 LOCK_PREFIX
22066 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22067+
22068+#ifdef CONFIG_PAX_REFCOUNT
22069+ jno 1234f
22070+ LOCK_PREFIX
22071+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22072+ int $4
22073+1234:
22074+ _ASM_EXTABLE(1234b, 1234b)
22075+#endif
22076+
22077 jnz 0b
22078 ENDFRAME
22079+ pax_force_retaddr
22080 ret
22081 CFI_ENDPROC
22082 END(__write_lock_failed)
22083@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22084 FRAME
22085 0: LOCK_PREFIX
22086 READ_LOCK_SIZE(inc) (%__lock_ptr)
22087+
22088+#ifdef CONFIG_PAX_REFCOUNT
22089+ jno 1234f
22090+ LOCK_PREFIX
22091+ READ_LOCK_SIZE(dec) (%__lock_ptr)
22092+ int $4
22093+1234:
22094+ _ASM_EXTABLE(1234b, 1234b)
22095+#endif
22096+
22097 1: rep; nop
22098 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22099 js 1b
22100 LOCK_PREFIX
22101 READ_LOCK_SIZE(dec) (%__lock_ptr)
22102+
22103+#ifdef CONFIG_PAX_REFCOUNT
22104+ jno 1234f
22105+ LOCK_PREFIX
22106+ READ_LOCK_SIZE(inc) (%__lock_ptr)
22107+ int $4
22108+1234:
22109+ _ASM_EXTABLE(1234b, 1234b)
22110+#endif
22111+
22112 js 0b
22113 ENDFRAME
22114+ pax_force_retaddr
22115 ret
22116 CFI_ENDPROC
22117 END(__read_lock_failed)
22118diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22119index 5dff5f0..cadebf4 100644
22120--- a/arch/x86/lib/rwsem.S
22121+++ b/arch/x86/lib/rwsem.S
22122@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22123 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22124 CFI_RESTORE __ASM_REG(dx)
22125 restore_common_regs
22126+ pax_force_retaddr
22127 ret
22128 CFI_ENDPROC
22129 ENDPROC(call_rwsem_down_read_failed)
22130@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22131 movq %rax,%rdi
22132 call rwsem_down_write_failed
22133 restore_common_regs
22134+ pax_force_retaddr
22135 ret
22136 CFI_ENDPROC
22137 ENDPROC(call_rwsem_down_write_failed)
22138@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22139 movq %rax,%rdi
22140 call rwsem_wake
22141 restore_common_regs
22142-1: ret
22143+1: pax_force_retaddr
22144+ ret
22145 CFI_ENDPROC
22146 ENDPROC(call_rwsem_wake)
22147
22148@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22149 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22150 CFI_RESTORE __ASM_REG(dx)
22151 restore_common_regs
22152+ pax_force_retaddr
22153 ret
22154 CFI_ENDPROC
22155 ENDPROC(call_rwsem_downgrade_wake)
22156diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22157index a63efd6..ccecad8 100644
22158--- a/arch/x86/lib/thunk_64.S
22159+++ b/arch/x86/lib/thunk_64.S
22160@@ -8,6 +8,7 @@
22161 #include <linux/linkage.h>
22162 #include <asm/dwarf2.h>
22163 #include <asm/calling.h>
22164+#include <asm/alternative-asm.h>
22165
22166 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22167 .macro THUNK name, func, put_ret_addr_in_rdi=0
22168@@ -41,5 +42,6 @@
22169 SAVE_ARGS
22170 restore:
22171 RESTORE_ARGS
22172+ pax_force_retaddr
22173 ret
22174 CFI_ENDPROC
22175diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22176index e218d5d..35679b4 100644
22177--- a/arch/x86/lib/usercopy_32.c
22178+++ b/arch/x86/lib/usercopy_32.c
22179@@ -43,7 +43,7 @@ do { \
22180 __asm__ __volatile__( \
22181 " testl %1,%1\n" \
22182 " jz 2f\n" \
22183- "0: lodsb\n" \
22184+ "0: "__copyuser_seg"lodsb\n" \
22185 " stosb\n" \
22186 " testb %%al,%%al\n" \
22187 " jz 1f\n" \
22188@@ -128,10 +128,12 @@ do { \
22189 int __d0; \
22190 might_fault(); \
22191 __asm__ __volatile__( \
22192+ __COPYUSER_SET_ES \
22193 "0: rep; stosl\n" \
22194 " movl %2,%0\n" \
22195 "1: rep; stosb\n" \
22196 "2:\n" \
22197+ __COPYUSER_RESTORE_ES \
22198 ".section .fixup,\"ax\"\n" \
22199 "3: lea 0(%2,%0,4),%0\n" \
22200 " jmp 2b\n" \
22201@@ -200,6 +202,7 @@ long strnlen_user(const char __user *s, long n)
22202 might_fault();
22203
22204 __asm__ __volatile__(
22205+ __COPYUSER_SET_ES
22206 " testl %0, %0\n"
22207 " jz 3f\n"
22208 " andl %0,%%ecx\n"
22209@@ -208,6 +211,7 @@ long strnlen_user(const char __user *s, long n)
22210 " subl %%ecx,%0\n"
22211 " addl %0,%%eax\n"
22212 "1:\n"
22213+ __COPYUSER_RESTORE_ES
22214 ".section .fixup,\"ax\"\n"
22215 "2: xorl %%eax,%%eax\n"
22216 " jmp 1b\n"
22217@@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
22218
22219 #ifdef CONFIG_X86_INTEL_USERCOPY
22220 static unsigned long
22221-__copy_user_intel(void __user *to, const void *from, unsigned long size)
22222+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22223 {
22224 int d0, d1;
22225 __asm__ __volatile__(
22226@@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22227 " .align 2,0x90\n"
22228 "3: movl 0(%4), %%eax\n"
22229 "4: movl 4(%4), %%edx\n"
22230- "5: movl %%eax, 0(%3)\n"
22231- "6: movl %%edx, 4(%3)\n"
22232+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22233+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22234 "7: movl 8(%4), %%eax\n"
22235 "8: movl 12(%4),%%edx\n"
22236- "9: movl %%eax, 8(%3)\n"
22237- "10: movl %%edx, 12(%3)\n"
22238+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22239+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22240 "11: movl 16(%4), %%eax\n"
22241 "12: movl 20(%4), %%edx\n"
22242- "13: movl %%eax, 16(%3)\n"
22243- "14: movl %%edx, 20(%3)\n"
22244+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22245+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22246 "15: movl 24(%4), %%eax\n"
22247 "16: movl 28(%4), %%edx\n"
22248- "17: movl %%eax, 24(%3)\n"
22249- "18: movl %%edx, 28(%3)\n"
22250+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22251+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22252 "19: movl 32(%4), %%eax\n"
22253 "20: movl 36(%4), %%edx\n"
22254- "21: movl %%eax, 32(%3)\n"
22255- "22: movl %%edx, 36(%3)\n"
22256+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22257+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22258 "23: movl 40(%4), %%eax\n"
22259 "24: movl 44(%4), %%edx\n"
22260- "25: movl %%eax, 40(%3)\n"
22261- "26: movl %%edx, 44(%3)\n"
22262+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22263+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22264 "27: movl 48(%4), %%eax\n"
22265 "28: movl 52(%4), %%edx\n"
22266- "29: movl %%eax, 48(%3)\n"
22267- "30: movl %%edx, 52(%3)\n"
22268+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22269+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22270 "31: movl 56(%4), %%eax\n"
22271 "32: movl 60(%4), %%edx\n"
22272- "33: movl %%eax, 56(%3)\n"
22273- "34: movl %%edx, 60(%3)\n"
22274+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22275+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22276 " addl $-64, %0\n"
22277 " addl $64, %4\n"
22278 " addl $64, %3\n"
22279@@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22280 " shrl $2, %0\n"
22281 " andl $3, %%eax\n"
22282 " cld\n"
22283+ __COPYUSER_SET_ES
22284 "99: rep; movsl\n"
22285 "36: movl %%eax, %0\n"
22286 "37: rep; movsb\n"
22287 "100:\n"
22288+ __COPYUSER_RESTORE_ES
22289+ ".section .fixup,\"ax\"\n"
22290+ "101: lea 0(%%eax,%0,4),%0\n"
22291+ " jmp 100b\n"
22292+ ".previous\n"
22293+ ".section __ex_table,\"a\"\n"
22294+ " .align 4\n"
22295+ " .long 1b,100b\n"
22296+ " .long 2b,100b\n"
22297+ " .long 3b,100b\n"
22298+ " .long 4b,100b\n"
22299+ " .long 5b,100b\n"
22300+ " .long 6b,100b\n"
22301+ " .long 7b,100b\n"
22302+ " .long 8b,100b\n"
22303+ " .long 9b,100b\n"
22304+ " .long 10b,100b\n"
22305+ " .long 11b,100b\n"
22306+ " .long 12b,100b\n"
22307+ " .long 13b,100b\n"
22308+ " .long 14b,100b\n"
22309+ " .long 15b,100b\n"
22310+ " .long 16b,100b\n"
22311+ " .long 17b,100b\n"
22312+ " .long 18b,100b\n"
22313+ " .long 19b,100b\n"
22314+ " .long 20b,100b\n"
22315+ " .long 21b,100b\n"
22316+ " .long 22b,100b\n"
22317+ " .long 23b,100b\n"
22318+ " .long 24b,100b\n"
22319+ " .long 25b,100b\n"
22320+ " .long 26b,100b\n"
22321+ " .long 27b,100b\n"
22322+ " .long 28b,100b\n"
22323+ " .long 29b,100b\n"
22324+ " .long 30b,100b\n"
22325+ " .long 31b,100b\n"
22326+ " .long 32b,100b\n"
22327+ " .long 33b,100b\n"
22328+ " .long 34b,100b\n"
22329+ " .long 35b,100b\n"
22330+ " .long 36b,100b\n"
22331+ " .long 37b,100b\n"
22332+ " .long 99b,101b\n"
22333+ ".previous"
22334+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
22335+ : "1"(to), "2"(from), "0"(size)
22336+ : "eax", "edx", "memory");
22337+ return size;
22338+}
22339+
22340+static unsigned long
22341+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22342+{
22343+ int d0, d1;
22344+ __asm__ __volatile__(
22345+ " .align 2,0x90\n"
22346+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22347+ " cmpl $67, %0\n"
22348+ " jbe 3f\n"
22349+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22350+ " .align 2,0x90\n"
22351+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22352+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22353+ "5: movl %%eax, 0(%3)\n"
22354+ "6: movl %%edx, 4(%3)\n"
22355+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22356+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22357+ "9: movl %%eax, 8(%3)\n"
22358+ "10: movl %%edx, 12(%3)\n"
22359+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22360+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22361+ "13: movl %%eax, 16(%3)\n"
22362+ "14: movl %%edx, 20(%3)\n"
22363+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22364+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22365+ "17: movl %%eax, 24(%3)\n"
22366+ "18: movl %%edx, 28(%3)\n"
22367+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22368+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22369+ "21: movl %%eax, 32(%3)\n"
22370+ "22: movl %%edx, 36(%3)\n"
22371+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22372+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22373+ "25: movl %%eax, 40(%3)\n"
22374+ "26: movl %%edx, 44(%3)\n"
22375+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22376+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22377+ "29: movl %%eax, 48(%3)\n"
22378+ "30: movl %%edx, 52(%3)\n"
22379+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22380+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22381+ "33: movl %%eax, 56(%3)\n"
22382+ "34: movl %%edx, 60(%3)\n"
22383+ " addl $-64, %0\n"
22384+ " addl $64, %4\n"
22385+ " addl $64, %3\n"
22386+ " cmpl $63, %0\n"
22387+ " ja 1b\n"
22388+ "35: movl %0, %%eax\n"
22389+ " shrl $2, %0\n"
22390+ " andl $3, %%eax\n"
22391+ " cld\n"
22392+ "99: rep; "__copyuser_seg" movsl\n"
22393+ "36: movl %%eax, %0\n"
22394+ "37: rep; "__copyuser_seg" movsb\n"
22395+ "100:\n"
22396 ".section .fixup,\"ax\"\n"
22397 "101: lea 0(%%eax,%0,4),%0\n"
22398 " jmp 100b\n"
22399@@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22400 int d0, d1;
22401 __asm__ __volatile__(
22402 " .align 2,0x90\n"
22403- "0: movl 32(%4), %%eax\n"
22404+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22405 " cmpl $67, %0\n"
22406 " jbe 2f\n"
22407- "1: movl 64(%4), %%eax\n"
22408+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22409 " .align 2,0x90\n"
22410- "2: movl 0(%4), %%eax\n"
22411- "21: movl 4(%4), %%edx\n"
22412+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22413+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22414 " movl %%eax, 0(%3)\n"
22415 " movl %%edx, 4(%3)\n"
22416- "3: movl 8(%4), %%eax\n"
22417- "31: movl 12(%4),%%edx\n"
22418+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22419+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22420 " movl %%eax, 8(%3)\n"
22421 " movl %%edx, 12(%3)\n"
22422- "4: movl 16(%4), %%eax\n"
22423- "41: movl 20(%4), %%edx\n"
22424+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22425+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22426 " movl %%eax, 16(%3)\n"
22427 " movl %%edx, 20(%3)\n"
22428- "10: movl 24(%4), %%eax\n"
22429- "51: movl 28(%4), %%edx\n"
22430+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22431+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22432 " movl %%eax, 24(%3)\n"
22433 " movl %%edx, 28(%3)\n"
22434- "11: movl 32(%4), %%eax\n"
22435- "61: movl 36(%4), %%edx\n"
22436+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22437+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22438 " movl %%eax, 32(%3)\n"
22439 " movl %%edx, 36(%3)\n"
22440- "12: movl 40(%4), %%eax\n"
22441- "71: movl 44(%4), %%edx\n"
22442+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22443+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22444 " movl %%eax, 40(%3)\n"
22445 " movl %%edx, 44(%3)\n"
22446- "13: movl 48(%4), %%eax\n"
22447- "81: movl 52(%4), %%edx\n"
22448+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22449+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22450 " movl %%eax, 48(%3)\n"
22451 " movl %%edx, 52(%3)\n"
22452- "14: movl 56(%4), %%eax\n"
22453- "91: movl 60(%4), %%edx\n"
22454+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22455+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22456 " movl %%eax, 56(%3)\n"
22457 " movl %%edx, 60(%3)\n"
22458 " addl $-64, %0\n"
22459@@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22460 " shrl $2, %0\n"
22461 " andl $3, %%eax\n"
22462 " cld\n"
22463- "6: rep; movsl\n"
22464+ "6: rep; "__copyuser_seg" movsl\n"
22465 " movl %%eax,%0\n"
22466- "7: rep; movsb\n"
22467+ "7: rep; "__copyuser_seg" movsb\n"
22468 "8:\n"
22469 ".section .fixup,\"ax\"\n"
22470 "9: lea 0(%%eax,%0,4),%0\n"
22471@@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22472
22473 __asm__ __volatile__(
22474 " .align 2,0x90\n"
22475- "0: movl 32(%4), %%eax\n"
22476+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22477 " cmpl $67, %0\n"
22478 " jbe 2f\n"
22479- "1: movl 64(%4), %%eax\n"
22480+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22481 " .align 2,0x90\n"
22482- "2: movl 0(%4), %%eax\n"
22483- "21: movl 4(%4), %%edx\n"
22484+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22485+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22486 " movnti %%eax, 0(%3)\n"
22487 " movnti %%edx, 4(%3)\n"
22488- "3: movl 8(%4), %%eax\n"
22489- "31: movl 12(%4),%%edx\n"
22490+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22491+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22492 " movnti %%eax, 8(%3)\n"
22493 " movnti %%edx, 12(%3)\n"
22494- "4: movl 16(%4), %%eax\n"
22495- "41: movl 20(%4), %%edx\n"
22496+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22497+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22498 " movnti %%eax, 16(%3)\n"
22499 " movnti %%edx, 20(%3)\n"
22500- "10: movl 24(%4), %%eax\n"
22501- "51: movl 28(%4), %%edx\n"
22502+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22503+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22504 " movnti %%eax, 24(%3)\n"
22505 " movnti %%edx, 28(%3)\n"
22506- "11: movl 32(%4), %%eax\n"
22507- "61: movl 36(%4), %%edx\n"
22508+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22509+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22510 " movnti %%eax, 32(%3)\n"
22511 " movnti %%edx, 36(%3)\n"
22512- "12: movl 40(%4), %%eax\n"
22513- "71: movl 44(%4), %%edx\n"
22514+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22515+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22516 " movnti %%eax, 40(%3)\n"
22517 " movnti %%edx, 44(%3)\n"
22518- "13: movl 48(%4), %%eax\n"
22519- "81: movl 52(%4), %%edx\n"
22520+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22521+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22522 " movnti %%eax, 48(%3)\n"
22523 " movnti %%edx, 52(%3)\n"
22524- "14: movl 56(%4), %%eax\n"
22525- "91: movl 60(%4), %%edx\n"
22526+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22527+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22528 " movnti %%eax, 56(%3)\n"
22529 " movnti %%edx, 60(%3)\n"
22530 " addl $-64, %0\n"
22531@@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22532 " shrl $2, %0\n"
22533 " andl $3, %%eax\n"
22534 " cld\n"
22535- "6: rep; movsl\n"
22536+ "6: rep; "__copyuser_seg" movsl\n"
22537 " movl %%eax,%0\n"
22538- "7: rep; movsb\n"
22539+ "7: rep; "__copyuser_seg" movsb\n"
22540 "8:\n"
22541 ".section .fixup,\"ax\"\n"
22542 "9: lea 0(%%eax,%0,4),%0\n"
22543@@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
22544
22545 __asm__ __volatile__(
22546 " .align 2,0x90\n"
22547- "0: movl 32(%4), %%eax\n"
22548+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22549 " cmpl $67, %0\n"
22550 " jbe 2f\n"
22551- "1: movl 64(%4), %%eax\n"
22552+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22553 " .align 2,0x90\n"
22554- "2: movl 0(%4), %%eax\n"
22555- "21: movl 4(%4), %%edx\n"
22556+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22557+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22558 " movnti %%eax, 0(%3)\n"
22559 " movnti %%edx, 4(%3)\n"
22560- "3: movl 8(%4), %%eax\n"
22561- "31: movl 12(%4),%%edx\n"
22562+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22563+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22564 " movnti %%eax, 8(%3)\n"
22565 " movnti %%edx, 12(%3)\n"
22566- "4: movl 16(%4), %%eax\n"
22567- "41: movl 20(%4), %%edx\n"
22568+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22569+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22570 " movnti %%eax, 16(%3)\n"
22571 " movnti %%edx, 20(%3)\n"
22572- "10: movl 24(%4), %%eax\n"
22573- "51: movl 28(%4), %%edx\n"
22574+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22575+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22576 " movnti %%eax, 24(%3)\n"
22577 " movnti %%edx, 28(%3)\n"
22578- "11: movl 32(%4), %%eax\n"
22579- "61: movl 36(%4), %%edx\n"
22580+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22581+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22582 " movnti %%eax, 32(%3)\n"
22583 " movnti %%edx, 36(%3)\n"
22584- "12: movl 40(%4), %%eax\n"
22585- "71: movl 44(%4), %%edx\n"
22586+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22587+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22588 " movnti %%eax, 40(%3)\n"
22589 " movnti %%edx, 44(%3)\n"
22590- "13: movl 48(%4), %%eax\n"
22591- "81: movl 52(%4), %%edx\n"
22592+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22593+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22594 " movnti %%eax, 48(%3)\n"
22595 " movnti %%edx, 52(%3)\n"
22596- "14: movl 56(%4), %%eax\n"
22597- "91: movl 60(%4), %%edx\n"
22598+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22599+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22600 " movnti %%eax, 56(%3)\n"
22601 " movnti %%edx, 60(%3)\n"
22602 " addl $-64, %0\n"
22603@@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
22604 " shrl $2, %0\n"
22605 " andl $3, %%eax\n"
22606 " cld\n"
22607- "6: rep; movsl\n"
22608+ "6: rep; "__copyuser_seg" movsl\n"
22609 " movl %%eax,%0\n"
22610- "7: rep; movsb\n"
22611+ "7: rep; "__copyuser_seg" movsb\n"
22612 "8:\n"
22613 ".section .fixup,\"ax\"\n"
22614 "9: lea 0(%%eax,%0,4),%0\n"
22615@@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
22616 */
22617 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
22618 unsigned long size);
22619-unsigned long __copy_user_intel(void __user *to, const void *from,
22620+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
22621+ unsigned long size);
22622+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
22623 unsigned long size);
22624 unsigned long __copy_user_zeroing_intel_nocache(void *to,
22625 const void __user *from, unsigned long size);
22626 #endif /* CONFIG_X86_INTEL_USERCOPY */
22627
22628 /* Generic arbitrary sized copy. */
22629-#define __copy_user(to, from, size) \
22630+#define __copy_user(to, from, size, prefix, set, restore) \
22631 do { \
22632 int __d0, __d1, __d2; \
22633 __asm__ __volatile__( \
22634+ set \
22635 " cmp $7,%0\n" \
22636 " jbe 1f\n" \
22637 " movl %1,%0\n" \
22638 " negl %0\n" \
22639 " andl $7,%0\n" \
22640 " subl %0,%3\n" \
22641- "4: rep; movsb\n" \
22642+ "4: rep; "prefix"movsb\n" \
22643 " movl %3,%0\n" \
22644 " shrl $2,%0\n" \
22645 " andl $3,%3\n" \
22646 " .align 2,0x90\n" \
22647- "0: rep; movsl\n" \
22648+ "0: rep; "prefix"movsl\n" \
22649 " movl %3,%0\n" \
22650- "1: rep; movsb\n" \
22651+ "1: rep; "prefix"movsb\n" \
22652 "2:\n" \
22653+ restore \
22654 ".section .fixup,\"ax\"\n" \
22655 "5: addl %3,%0\n" \
22656 " jmp 2b\n" \
22657@@ -682,14 +799,14 @@ do { \
22658 " negl %0\n" \
22659 " andl $7,%0\n" \
22660 " subl %0,%3\n" \
22661- "4: rep; movsb\n" \
22662+ "4: rep; "__copyuser_seg"movsb\n" \
22663 " movl %3,%0\n" \
22664 " shrl $2,%0\n" \
22665 " andl $3,%3\n" \
22666 " .align 2,0x90\n" \
22667- "0: rep; movsl\n" \
22668+ "0: rep; "__copyuser_seg"movsl\n" \
22669 " movl %3,%0\n" \
22670- "1: rep; movsb\n" \
22671+ "1: rep; "__copyuser_seg"movsb\n" \
22672 "2:\n" \
22673 ".section .fixup,\"ax\"\n" \
22674 "5: addl %3,%0\n" \
22675@@ -775,9 +892,9 @@ survive:
22676 }
22677 #endif
22678 if (movsl_is_ok(to, from, n))
22679- __copy_user(to, from, n);
22680+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
22681 else
22682- n = __copy_user_intel(to, from, n);
22683+ n = __generic_copy_to_user_intel(to, from, n);
22684 return n;
22685 }
22686 EXPORT_SYMBOL(__copy_to_user_ll);
22687@@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
22688 unsigned long n)
22689 {
22690 if (movsl_is_ok(to, from, n))
22691- __copy_user(to, from, n);
22692+ __copy_user(to, from, n, __copyuser_seg, "", "");
22693 else
22694- n = __copy_user_intel((void __user *)to,
22695- (const void *)from, n);
22696+ n = __generic_copy_from_user_intel(to, from, n);
22697 return n;
22698 }
22699 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
22700@@ -827,65 +943,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
22701 if (n > 64 && cpu_has_xmm2)
22702 n = __copy_user_intel_nocache(to, from, n);
22703 else
22704- __copy_user(to, from, n);
22705+ __copy_user(to, from, n, __copyuser_seg, "", "");
22706 #else
22707- __copy_user(to, from, n);
22708+ __copy_user(to, from, n, __copyuser_seg, "", "");
22709 #endif
22710 return n;
22711 }
22712 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
22713
22714-/**
22715- * copy_to_user: - Copy a block of data into user space.
22716- * @to: Destination address, in user space.
22717- * @from: Source address, in kernel space.
22718- * @n: Number of bytes to copy.
22719- *
22720- * Context: User context only. This function may sleep.
22721- *
22722- * Copy data from kernel space to user space.
22723- *
22724- * Returns number of bytes that could not be copied.
22725- * On success, this will be zero.
22726- */
22727-unsigned long
22728-copy_to_user(void __user *to, const void *from, unsigned long n)
22729-{
22730- if (access_ok(VERIFY_WRITE, to, n))
22731- n = __copy_to_user(to, from, n);
22732- return n;
22733-}
22734-EXPORT_SYMBOL(copy_to_user);
22735-
22736-/**
22737- * copy_from_user: - Copy a block of data from user space.
22738- * @to: Destination address, in kernel space.
22739- * @from: Source address, in user space.
22740- * @n: Number of bytes to copy.
22741- *
22742- * Context: User context only. This function may sleep.
22743- *
22744- * Copy data from user space to kernel space.
22745- *
22746- * Returns number of bytes that could not be copied.
22747- * On success, this will be zero.
22748- *
22749- * If some data could not be copied, this function will pad the copied
22750- * data to the requested size using zero bytes.
22751- */
22752-unsigned long
22753-_copy_from_user(void *to, const void __user *from, unsigned long n)
22754-{
22755- if (access_ok(VERIFY_READ, from, n))
22756- n = __copy_from_user(to, from, n);
22757- else
22758- memset(to, 0, n);
22759- return n;
22760-}
22761-EXPORT_SYMBOL(_copy_from_user);
22762-
22763 void copy_from_user_overflow(void)
22764 {
22765 WARN(1, "Buffer overflow detected!\n");
22766 }
22767 EXPORT_SYMBOL(copy_from_user_overflow);
22768+
22769+void copy_to_user_overflow(void)
22770+{
22771+ WARN(1, "Buffer overflow detected!\n");
22772+}
22773+EXPORT_SYMBOL(copy_to_user_overflow);
22774+
22775+#ifdef CONFIG_PAX_MEMORY_UDEREF
22776+void __set_fs(mm_segment_t x)
22777+{
22778+ switch (x.seg) {
22779+ case 0:
22780+ loadsegment(gs, 0);
22781+ break;
22782+ case TASK_SIZE_MAX:
22783+ loadsegment(gs, __USER_DS);
22784+ break;
22785+ case -1UL:
22786+ loadsegment(gs, __KERNEL_DS);
22787+ break;
22788+ default:
22789+ BUG();
22790+ }
22791+ return;
22792+}
22793+EXPORT_SYMBOL(__set_fs);
22794+
22795+void set_fs(mm_segment_t x)
22796+{
22797+ current_thread_info()->addr_limit = x;
22798+ __set_fs(x);
22799+}
22800+EXPORT_SYMBOL(set_fs);
22801+#endif
22802diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
22803index b7c2849..8633ad8 100644
22804--- a/arch/x86/lib/usercopy_64.c
22805+++ b/arch/x86/lib/usercopy_64.c
22806@@ -42,6 +42,12 @@ long
22807 __strncpy_from_user(char *dst, const char __user *src, long count)
22808 {
22809 long res;
22810+
22811+#ifdef CONFIG_PAX_MEMORY_UDEREF
22812+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
22813+ src += PAX_USER_SHADOW_BASE;
22814+#endif
22815+
22816 __do_strncpy_from_user(dst, src, count, res);
22817 return res;
22818 }
22819@@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
22820 {
22821 long __d0;
22822 might_fault();
22823+
22824+#ifdef CONFIG_PAX_MEMORY_UDEREF
22825+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
22826+ addr += PAX_USER_SHADOW_BASE;
22827+#endif
22828+
22829 /* no memory constraint because it doesn't change any memory gcc knows
22830 about */
22831 asm volatile(
22832@@ -149,12 +161,20 @@ long strlen_user(const char __user *s)
22833 }
22834 EXPORT_SYMBOL(strlen_user);
22835
22836-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
22837+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
22838 {
22839- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
22840- return copy_user_generic((__force void *)to, (__force void *)from, len);
22841- }
22842- return len;
22843+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
22844+
22845+#ifdef CONFIG_PAX_MEMORY_UDEREF
22846+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
22847+ to += PAX_USER_SHADOW_BASE;
22848+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
22849+ from += PAX_USER_SHADOW_BASE;
22850+#endif
22851+
22852+ return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
22853+ }
22854+ return len;
22855 }
22856 EXPORT_SYMBOL(copy_in_user);
22857
22858@@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
22859 * it is not necessary to optimize tail handling.
22860 */
22861 unsigned long
22862-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
22863+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
22864 {
22865 char c;
22866 unsigned zero_len;
22867diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
22868index 1fb85db..8b3540b 100644
22869--- a/arch/x86/mm/extable.c
22870+++ b/arch/x86/mm/extable.c
22871@@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
22872 const struct exception_table_entry *fixup;
22873
22874 #ifdef CONFIG_PNPBIOS
22875- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
22876+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
22877 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
22878 extern u32 pnp_bios_is_utter_crap;
22879 pnp_bios_is_utter_crap = 1;
22880diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
22881index f0b4caf..d92fd42 100644
22882--- a/arch/x86/mm/fault.c
22883+++ b/arch/x86/mm/fault.c
22884@@ -13,11 +13,18 @@
22885 #include <linux/perf_event.h> /* perf_sw_event */
22886 #include <linux/hugetlb.h> /* hstate_index_to_shift */
22887 #include <linux/prefetch.h> /* prefetchw */
22888+#include <linux/unistd.h>
22889+#include <linux/compiler.h>
22890
22891 #include <asm/traps.h> /* dotraplinkage, ... */
22892 #include <asm/pgalloc.h> /* pgd_*(), ... */
22893 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
22894 #include <asm/fixmap.h> /* VSYSCALL_START */
22895+#include <asm/tlbflush.h>
22896+
22897+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22898+#include <asm/stacktrace.h>
22899+#endif
22900
22901 /*
22902 * Page fault error code bits:
22903@@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
22904 int ret = 0;
22905
22906 /* kprobe_running() needs smp_processor_id() */
22907- if (kprobes_built_in() && !user_mode_vm(regs)) {
22908+ if (kprobes_built_in() && !user_mode(regs)) {
22909 preempt_disable();
22910 if (kprobe_running() && kprobe_fault_handler(regs, 14))
22911 ret = 1;
22912@@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
22913 return !instr_lo || (instr_lo>>1) == 1;
22914 case 0x00:
22915 /* Prefetch instruction is 0x0F0D or 0x0F18 */
22916- if (probe_kernel_address(instr, opcode))
22917+ if (user_mode(regs)) {
22918+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
22919+ return 0;
22920+ } else if (probe_kernel_address(instr, opcode))
22921 return 0;
22922
22923 *prefetch = (instr_lo == 0xF) &&
22924@@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
22925 while (instr < max_instr) {
22926 unsigned char opcode;
22927
22928- if (probe_kernel_address(instr, opcode))
22929+ if (user_mode(regs)) {
22930+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
22931+ break;
22932+ } else if (probe_kernel_address(instr, opcode))
22933 break;
22934
22935 instr++;
22936@@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
22937 force_sig_info(si_signo, &info, tsk);
22938 }
22939
22940+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22941+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
22942+#endif
22943+
22944+#ifdef CONFIG_PAX_EMUTRAMP
22945+static int pax_handle_fetch_fault(struct pt_regs *regs);
22946+#endif
22947+
22948+#ifdef CONFIG_PAX_PAGEEXEC
22949+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
22950+{
22951+ pgd_t *pgd;
22952+ pud_t *pud;
22953+ pmd_t *pmd;
22954+
22955+ pgd = pgd_offset(mm, address);
22956+ if (!pgd_present(*pgd))
22957+ return NULL;
22958+ pud = pud_offset(pgd, address);
22959+ if (!pud_present(*pud))
22960+ return NULL;
22961+ pmd = pmd_offset(pud, address);
22962+ if (!pmd_present(*pmd))
22963+ return NULL;
22964+ return pmd;
22965+}
22966+#endif
22967+
22968 DEFINE_SPINLOCK(pgd_lock);
22969 LIST_HEAD(pgd_list);
22970
22971@@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
22972 for (address = VMALLOC_START & PMD_MASK;
22973 address >= TASK_SIZE && address < FIXADDR_TOP;
22974 address += PMD_SIZE) {
22975+
22976+#ifdef CONFIG_PAX_PER_CPU_PGD
22977+ unsigned long cpu;
22978+#else
22979 struct page *page;
22980+#endif
22981
22982 spin_lock(&pgd_lock);
22983+
22984+#ifdef CONFIG_PAX_PER_CPU_PGD
22985+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
22986+ pgd_t *pgd = get_cpu_pgd(cpu);
22987+ pmd_t *ret;
22988+#else
22989 list_for_each_entry(page, &pgd_list, lru) {
22990+ pgd_t *pgd = page_address(page);
22991 spinlock_t *pgt_lock;
22992 pmd_t *ret;
22993
22994@@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
22995 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
22996
22997 spin_lock(pgt_lock);
22998- ret = vmalloc_sync_one(page_address(page), address);
22999+#endif
23000+
23001+ ret = vmalloc_sync_one(pgd, address);
23002+
23003+#ifndef CONFIG_PAX_PER_CPU_PGD
23004 spin_unlock(pgt_lock);
23005+#endif
23006
23007 if (!ret)
23008 break;
23009@@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23010 * an interrupt in the middle of a task switch..
23011 */
23012 pgd_paddr = read_cr3();
23013+
23014+#ifdef CONFIG_PAX_PER_CPU_PGD
23015+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23016+#endif
23017+
23018 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23019 if (!pmd_k)
23020 return -1;
23021@@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23022 * happen within a race in page table update. In the later
23023 * case just flush:
23024 */
23025+
23026+#ifdef CONFIG_PAX_PER_CPU_PGD
23027+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23028+ pgd = pgd_offset_cpu(smp_processor_id(), address);
23029+#else
23030 pgd = pgd_offset(current->active_mm, address);
23031+#endif
23032+
23033 pgd_ref = pgd_offset_k(address);
23034 if (pgd_none(*pgd_ref))
23035 return -1;
23036@@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23037 static int is_errata100(struct pt_regs *regs, unsigned long address)
23038 {
23039 #ifdef CONFIG_X86_64
23040- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23041+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23042 return 1;
23043 #endif
23044 return 0;
23045@@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23046 }
23047
23048 static const char nx_warning[] = KERN_CRIT
23049-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23050+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23051
23052 static void
23053 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23054@@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23055 if (!oops_may_print())
23056 return;
23057
23058- if (error_code & PF_INSTR) {
23059+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23060 unsigned int level;
23061
23062 pte_t *pte = lookup_address(address, &level);
23063
23064 if (pte && pte_present(*pte) && !pte_exec(*pte))
23065- printk(nx_warning, current_uid());
23066+ printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
23067 }
23068
23069+#ifdef CONFIG_PAX_KERNEXEC
23070+ if (init_mm.start_code <= address && address < init_mm.end_code) {
23071+ if (current->signal->curr_ip)
23072+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23073+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23074+ else
23075+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23076+ current->comm, task_pid_nr(current), current_uid(), current_euid());
23077+ }
23078+#endif
23079+
23080 printk(KERN_ALERT "BUG: unable to handle kernel ");
23081 if (address < PAGE_SIZE)
23082 printk(KERN_CONT "NULL pointer dereference");
23083@@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23084 }
23085 #endif
23086
23087+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23088+ if (pax_is_fetch_fault(regs, error_code, address)) {
23089+
23090+#ifdef CONFIG_PAX_EMUTRAMP
23091+ switch (pax_handle_fetch_fault(regs)) {
23092+ case 2:
23093+ return;
23094+ }
23095+#endif
23096+
23097+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23098+ do_group_exit(SIGKILL);
23099+ }
23100+#endif
23101+
23102 if (unlikely(show_unhandled_signals))
23103 show_signal_msg(regs, error_code, address, tsk);
23104
23105@@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23106 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23107 printk(KERN_ERR
23108 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23109- tsk->comm, tsk->pid, address);
23110+ tsk->comm, task_pid_nr(tsk), address);
23111 code = BUS_MCEERR_AR;
23112 }
23113 #endif
23114@@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23115 return 1;
23116 }
23117
23118+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23119+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23120+{
23121+ pte_t *pte;
23122+ pmd_t *pmd;
23123+ spinlock_t *ptl;
23124+ unsigned char pte_mask;
23125+
23126+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23127+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
23128+ return 0;
23129+
23130+ /* PaX: it's our fault, let's handle it if we can */
23131+
23132+ /* PaX: take a look at read faults before acquiring any locks */
23133+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23134+ /* instruction fetch attempt from a protected page in user mode */
23135+ up_read(&mm->mmap_sem);
23136+
23137+#ifdef CONFIG_PAX_EMUTRAMP
23138+ switch (pax_handle_fetch_fault(regs)) {
23139+ case 2:
23140+ return 1;
23141+ }
23142+#endif
23143+
23144+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23145+ do_group_exit(SIGKILL);
23146+ }
23147+
23148+ pmd = pax_get_pmd(mm, address);
23149+ if (unlikely(!pmd))
23150+ return 0;
23151+
23152+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23153+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23154+ pte_unmap_unlock(pte, ptl);
23155+ return 0;
23156+ }
23157+
23158+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23159+ /* write attempt to a protected page in user mode */
23160+ pte_unmap_unlock(pte, ptl);
23161+ return 0;
23162+ }
23163+
23164+#ifdef CONFIG_SMP
23165+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23166+#else
23167+ if (likely(address > get_limit(regs->cs)))
23168+#endif
23169+ {
23170+ set_pte(pte, pte_mkread(*pte));
23171+ __flush_tlb_one(address);
23172+ pte_unmap_unlock(pte, ptl);
23173+ up_read(&mm->mmap_sem);
23174+ return 1;
23175+ }
23176+
23177+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23178+
23179+ /*
23180+ * PaX: fill DTLB with user rights and retry
23181+ */
23182+ __asm__ __volatile__ (
23183+ "orb %2,(%1)\n"
23184+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23185+/*
23186+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23187+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23188+ * page fault when examined during a TLB load attempt. this is true not only
23189+ * for PTEs holding a non-present entry but also present entries that will
23190+ * raise a page fault (such as those set up by PaX, or the copy-on-write
23191+ * mechanism). in effect it means that we do *not* need to flush the TLBs
23192+ * for our target pages since their PTEs are simply not in the TLBs at all.
23193+
23194+ * the best thing in omitting it is that we gain around 15-20% speed in the
23195+ * fast path of the page fault handler and can get rid of tracing since we
23196+ * can no longer flush unintended entries.
23197+ */
23198+ "invlpg (%0)\n"
23199+#endif
23200+ __copyuser_seg"testb $0,(%0)\n"
23201+ "xorb %3,(%1)\n"
23202+ :
23203+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23204+ : "memory", "cc");
23205+ pte_unmap_unlock(pte, ptl);
23206+ up_read(&mm->mmap_sem);
23207+ return 1;
23208+}
23209+#endif
23210+
23211 /*
23212 * Handle a spurious fault caused by a stale TLB entry.
23213 *
23214@@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23215 static inline int
23216 access_error(unsigned long error_code, struct vm_area_struct *vma)
23217 {
23218+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23219+ return 1;
23220+
23221 if (error_code & PF_WRITE) {
23222 /* write, present and write, not present: */
23223 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23224@@ -1005,18 +1197,32 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23225 {
23226 struct vm_area_struct *vma;
23227 struct task_struct *tsk;
23228- unsigned long address;
23229 struct mm_struct *mm;
23230 int fault;
23231 int write = error_code & PF_WRITE;
23232 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23233 (write ? FAULT_FLAG_WRITE : 0);
23234
23235- tsk = current;
23236- mm = tsk->mm;
23237-
23238 /* Get the faulting address: */
23239- address = read_cr2();
23240+ unsigned long address = read_cr2();
23241+
23242+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23243+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23244+ if (!search_exception_tables(regs->ip)) {
23245+ bad_area_nosemaphore(regs, error_code, address);
23246+ return;
23247+ }
23248+ if (address < PAX_USER_SHADOW_BASE) {
23249+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23250+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23251+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23252+ } else
23253+ address -= PAX_USER_SHADOW_BASE;
23254+ }
23255+#endif
23256+
23257+ tsk = current;
23258+ mm = tsk->mm;
23259
23260 /*
23261 * Detect and handle instructions that would cause a page fault for
23262@@ -1077,7 +1283,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23263 * User-mode registers count as a user access even for any
23264 * potential system fault or CPU buglet:
23265 */
23266- if (user_mode_vm(regs)) {
23267+ if (user_mode(regs)) {
23268 local_irq_enable();
23269 error_code |= PF_USER;
23270 } else {
23271@@ -1132,6 +1338,11 @@ retry:
23272 might_sleep();
23273 }
23274
23275+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23276+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23277+ return;
23278+#endif
23279+
23280 vma = find_vma(mm, address);
23281 if (unlikely(!vma)) {
23282 bad_area(regs, error_code, address);
23283@@ -1143,18 +1354,24 @@ retry:
23284 bad_area(regs, error_code, address);
23285 return;
23286 }
23287- if (error_code & PF_USER) {
23288- /*
23289- * Accessing the stack below %sp is always a bug.
23290- * The large cushion allows instructions like enter
23291- * and pusha to work. ("enter $65535, $31" pushes
23292- * 32 pointers and then decrements %sp by 65535.)
23293- */
23294- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23295- bad_area(regs, error_code, address);
23296- return;
23297- }
23298+ /*
23299+ * Accessing the stack below %sp is always a bug.
23300+ * The large cushion allows instructions like enter
23301+ * and pusha to work. ("enter $65535, $31" pushes
23302+ * 32 pointers and then decrements %sp by 65535.)
23303+ */
23304+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23305+ bad_area(regs, error_code, address);
23306+ return;
23307 }
23308+
23309+#ifdef CONFIG_PAX_SEGMEXEC
23310+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23311+ bad_area(regs, error_code, address);
23312+ return;
23313+ }
23314+#endif
23315+
23316 if (unlikely(expand_stack(vma, address))) {
23317 bad_area(regs, error_code, address);
23318 return;
23319@@ -1209,3 +1426,292 @@ good_area:
23320
23321 up_read(&mm->mmap_sem);
23322 }
23323+
23324+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23325+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
23326+{
23327+ struct mm_struct *mm = current->mm;
23328+ unsigned long ip = regs->ip;
23329+
23330+ if (v8086_mode(regs))
23331+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
23332+
23333+#ifdef CONFIG_PAX_PAGEEXEC
23334+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
23335+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
23336+ return true;
23337+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
23338+ return true;
23339+ return false;
23340+ }
23341+#endif
23342+
23343+#ifdef CONFIG_PAX_SEGMEXEC
23344+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
23345+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
23346+ return true;
23347+ return false;
23348+ }
23349+#endif
23350+
23351+ return false;
23352+}
23353+#endif
23354+
23355+#ifdef CONFIG_PAX_EMUTRAMP
23356+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
23357+{
23358+ int err;
23359+
23360+ do { /* PaX: libffi trampoline emulation */
23361+ unsigned char mov, jmp;
23362+ unsigned int addr1, addr2;
23363+
23364+#ifdef CONFIG_X86_64
23365+ if ((regs->ip + 9) >> 32)
23366+ break;
23367+#endif
23368+
23369+ err = get_user(mov, (unsigned char __user *)regs->ip);
23370+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23371+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23372+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23373+
23374+ if (err)
23375+ break;
23376+
23377+ if (mov == 0xB8 && jmp == 0xE9) {
23378+ regs->ax = addr1;
23379+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23380+ return 2;
23381+ }
23382+ } while (0);
23383+
23384+ do { /* PaX: gcc trampoline emulation #1 */
23385+ unsigned char mov1, mov2;
23386+ unsigned short jmp;
23387+ unsigned int addr1, addr2;
23388+
23389+#ifdef CONFIG_X86_64
23390+ if ((regs->ip + 11) >> 32)
23391+ break;
23392+#endif
23393+
23394+ err = get_user(mov1, (unsigned char __user *)regs->ip);
23395+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23396+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
23397+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23398+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
23399+
23400+ if (err)
23401+ break;
23402+
23403+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
23404+ regs->cx = addr1;
23405+ regs->ax = addr2;
23406+ regs->ip = addr2;
23407+ return 2;
23408+ }
23409+ } while (0);
23410+
23411+ do { /* PaX: gcc trampoline emulation #2 */
23412+ unsigned char mov, jmp;
23413+ unsigned int addr1, addr2;
23414+
23415+#ifdef CONFIG_X86_64
23416+ if ((regs->ip + 9) >> 32)
23417+ break;
23418+#endif
23419+
23420+ err = get_user(mov, (unsigned char __user *)regs->ip);
23421+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23422+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23423+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23424+
23425+ if (err)
23426+ break;
23427+
23428+ if (mov == 0xB9 && jmp == 0xE9) {
23429+ regs->cx = addr1;
23430+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23431+ return 2;
23432+ }
23433+ } while (0);
23434+
23435+ return 1; /* PaX in action */
23436+}
23437+
23438+#ifdef CONFIG_X86_64
23439+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
23440+{
23441+ int err;
23442+
23443+ do { /* PaX: libffi trampoline emulation */
23444+ unsigned short mov1, mov2, jmp1;
23445+ unsigned char stcclc, jmp2;
23446+ unsigned long addr1, addr2;
23447+
23448+ err = get_user(mov1, (unsigned short __user *)regs->ip);
23449+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23450+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23451+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23452+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
23453+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
23454+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
23455+
23456+ if (err)
23457+ break;
23458+
23459+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23460+ regs->r11 = addr1;
23461+ regs->r10 = addr2;
23462+ if (stcclc == 0xF8)
23463+ regs->flags &= ~X86_EFLAGS_CF;
23464+ else
23465+ regs->flags |= X86_EFLAGS_CF;
23466+ regs->ip = addr1;
23467+ return 2;
23468+ }
23469+ } while (0);
23470+
23471+ do { /* PaX: gcc trampoline emulation #1 */
23472+ unsigned short mov1, mov2, jmp1;
23473+ unsigned char jmp2;
23474+ unsigned int addr1;
23475+ unsigned long addr2;
23476+
23477+ err = get_user(mov1, (unsigned short __user *)regs->ip);
23478+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
23479+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
23480+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
23481+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
23482+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
23483+
23484+ if (err)
23485+ break;
23486+
23487+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23488+ regs->r11 = addr1;
23489+ regs->r10 = addr2;
23490+ regs->ip = addr1;
23491+ return 2;
23492+ }
23493+ } while (0);
23494+
23495+ do { /* PaX: gcc trampoline emulation #2 */
23496+ unsigned short mov1, mov2, jmp1;
23497+ unsigned char jmp2;
23498+ unsigned long addr1, addr2;
23499+
23500+ err = get_user(mov1, (unsigned short __user *)regs->ip);
23501+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23502+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23503+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23504+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
23505+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
23506+
23507+ if (err)
23508+ break;
23509+
23510+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23511+ regs->r11 = addr1;
23512+ regs->r10 = addr2;
23513+ regs->ip = addr1;
23514+ return 2;
23515+ }
23516+ } while (0);
23517+
23518+ return 1; /* PaX in action */
23519+}
23520+#endif
23521+
23522+/*
23523+ * PaX: decide what to do with offenders (regs->ip = fault address)
23524+ *
23525+ * returns 1 when task should be killed
23526+ * 2 when gcc trampoline was detected
23527+ */
23528+static int pax_handle_fetch_fault(struct pt_regs *regs)
23529+{
23530+ if (v8086_mode(regs))
23531+ return 1;
23532+
23533+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
23534+ return 1;
23535+
23536+#ifdef CONFIG_X86_32
23537+ return pax_handle_fetch_fault_32(regs);
23538+#else
23539+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
23540+ return pax_handle_fetch_fault_32(regs);
23541+ else
23542+ return pax_handle_fetch_fault_64(regs);
23543+#endif
23544+}
23545+#endif
23546+
23547+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23548+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
23549+{
23550+ long i;
23551+
23552+ printk(KERN_ERR "PAX: bytes at PC: ");
23553+ for (i = 0; i < 20; i++) {
23554+ unsigned char c;
23555+ if (get_user(c, (unsigned char __force_user *)pc+i))
23556+ printk(KERN_CONT "?? ");
23557+ else
23558+ printk(KERN_CONT "%02x ", c);
23559+ }
23560+ printk("\n");
23561+
23562+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
23563+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
23564+ unsigned long c;
23565+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
23566+#ifdef CONFIG_X86_32
23567+ printk(KERN_CONT "???????? ");
23568+#else
23569+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
23570+ printk(KERN_CONT "???????? ???????? ");
23571+ else
23572+ printk(KERN_CONT "???????????????? ");
23573+#endif
23574+ } else {
23575+#ifdef CONFIG_X86_64
23576+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
23577+ printk(KERN_CONT "%08x ", (unsigned int)c);
23578+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
23579+ } else
23580+#endif
23581+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
23582+ }
23583+ }
23584+ printk("\n");
23585+}
23586+#endif
23587+
23588+/**
23589+ * probe_kernel_write(): safely attempt to write to a location
23590+ * @dst: address to write to
23591+ * @src: pointer to the data that shall be written
23592+ * @size: size of the data chunk
23593+ *
23594+ * Safely write to address @dst from the buffer at @src. If a kernel fault
23595+ * happens, handle that and return -EFAULT.
23596+ */
23597+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
23598+{
23599+ long ret;
23600+ mm_segment_t old_fs = get_fs();
23601+
23602+ set_fs(KERNEL_DS);
23603+ pagefault_disable();
23604+ pax_open_kernel();
23605+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
23606+ pax_close_kernel();
23607+ pagefault_enable();
23608+ set_fs(old_fs);
23609+
23610+ return ret ? -EFAULT : 0;
23611+}
23612diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
23613index dd74e46..7d26398 100644
23614--- a/arch/x86/mm/gup.c
23615+++ b/arch/x86/mm/gup.c
23616@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
23617 addr = start;
23618 len = (unsigned long) nr_pages << PAGE_SHIFT;
23619 end = start + len;
23620- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
23621+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
23622 (void __user *)start, len)))
23623 return 0;
23624
23625diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
23626index f4f29b1..5cac4fb 100644
23627--- a/arch/x86/mm/highmem_32.c
23628+++ b/arch/x86/mm/highmem_32.c
23629@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
23630 idx = type + KM_TYPE_NR*smp_processor_id();
23631 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
23632 BUG_ON(!pte_none(*(kmap_pte-idx)));
23633+
23634+ pax_open_kernel();
23635 set_pte(kmap_pte-idx, mk_pte(page, prot));
23636+ pax_close_kernel();
23637+
23638 arch_flush_lazy_mmu_mode();
23639
23640 return (void *)vaddr;
23641diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
23642index 8ecbb4b..29efd37 100644
23643--- a/arch/x86/mm/hugetlbpage.c
23644+++ b/arch/x86/mm/hugetlbpage.c
23645@@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
23646 struct hstate *h = hstate_file(file);
23647 struct mm_struct *mm = current->mm;
23648 struct vm_area_struct *vma;
23649- unsigned long start_addr;
23650+ unsigned long start_addr, pax_task_size = TASK_SIZE;
23651+
23652+#ifdef CONFIG_PAX_SEGMEXEC
23653+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23654+ pax_task_size = SEGMEXEC_TASK_SIZE;
23655+#endif
23656+
23657+ pax_task_size -= PAGE_SIZE;
23658
23659 if (len > mm->cached_hole_size) {
23660- start_addr = mm->free_area_cache;
23661+ start_addr = mm->free_area_cache;
23662 } else {
23663- start_addr = TASK_UNMAPPED_BASE;
23664- mm->cached_hole_size = 0;
23665+ start_addr = mm->mmap_base;
23666+ mm->cached_hole_size = 0;
23667 }
23668
23669 full_search:
23670@@ -280,26 +287,27 @@ full_search:
23671
23672 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
23673 /* At this point: (!vma || addr < vma->vm_end). */
23674- if (TASK_SIZE - len < addr) {
23675+ if (pax_task_size - len < addr) {
23676 /*
23677 * Start a new search - just in case we missed
23678 * some holes.
23679 */
23680- if (start_addr != TASK_UNMAPPED_BASE) {
23681- start_addr = TASK_UNMAPPED_BASE;
23682+ if (start_addr != mm->mmap_base) {
23683+ start_addr = mm->mmap_base;
23684 mm->cached_hole_size = 0;
23685 goto full_search;
23686 }
23687 return -ENOMEM;
23688 }
23689- if (!vma || addr + len <= vma->vm_start) {
23690- mm->free_area_cache = addr + len;
23691- return addr;
23692- }
23693+ if (check_heap_stack_gap(vma, addr, len))
23694+ break;
23695 if (addr + mm->cached_hole_size < vma->vm_start)
23696 mm->cached_hole_size = vma->vm_start - addr;
23697 addr = ALIGN(vma->vm_end, huge_page_size(h));
23698 }
23699+
23700+ mm->free_area_cache = addr + len;
23701+ return addr;
23702 }
23703
23704 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
23705@@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
23706 {
23707 struct hstate *h = hstate_file(file);
23708 struct mm_struct *mm = current->mm;
23709- struct vm_area_struct *vma, *prev_vma;
23710- unsigned long base = mm->mmap_base, addr = addr0;
23711+ struct vm_area_struct *vma;
23712+ unsigned long base = mm->mmap_base, addr;
23713 unsigned long largest_hole = mm->cached_hole_size;
23714- int first_time = 1;
23715
23716 /* don't allow allocations above current base */
23717 if (mm->free_area_cache > base)
23718@@ -321,66 +328,63 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
23719 largest_hole = 0;
23720 mm->free_area_cache = base;
23721 }
23722-try_again:
23723+
23724 /* make sure it can fit in the remaining address space */
23725 if (mm->free_area_cache < len)
23726 goto fail;
23727
23728 /* either no address requested or can't fit in requested address hole */
23729- addr = (mm->free_area_cache - len) & huge_page_mask(h);
23730+ addr = (mm->free_area_cache - len);
23731 do {
23732+ addr &= huge_page_mask(h);
23733+ vma = find_vma(mm, addr);
23734 /*
23735 * Lookup failure means no vma is above this address,
23736 * i.e. return with success:
23737- */
23738- vma = find_vma(mm, addr);
23739- if (!vma)
23740- return addr;
23741-
23742- /*
23743 * new region fits between prev_vma->vm_end and
23744 * vma->vm_start, use it:
23745 */
23746- prev_vma = vma->vm_prev;
23747- if (addr + len <= vma->vm_start &&
23748- (!prev_vma || (addr >= prev_vma->vm_end))) {
23749+ if (check_heap_stack_gap(vma, addr, len)) {
23750 /* remember the address as a hint for next time */
23751- mm->cached_hole_size = largest_hole;
23752- return (mm->free_area_cache = addr);
23753- } else {
23754- /* pull free_area_cache down to the first hole */
23755- if (mm->free_area_cache == vma->vm_end) {
23756- mm->free_area_cache = vma->vm_start;
23757- mm->cached_hole_size = largest_hole;
23758- }
23759+ mm->cached_hole_size = largest_hole;
23760+ return (mm->free_area_cache = addr);
23761+ }
23762+ /* pull free_area_cache down to the first hole */
23763+ if (mm->free_area_cache == vma->vm_end) {
23764+ mm->free_area_cache = vma->vm_start;
23765+ mm->cached_hole_size = largest_hole;
23766 }
23767
23768 /* remember the largest hole we saw so far */
23769 if (addr + largest_hole < vma->vm_start)
23770- largest_hole = vma->vm_start - addr;
23771+ largest_hole = vma->vm_start - addr;
23772
23773 /* try just below the current vma->vm_start */
23774- addr = (vma->vm_start - len) & huge_page_mask(h);
23775- } while (len <= vma->vm_start);
23776+ addr = skip_heap_stack_gap(vma, len);
23777+ } while (!IS_ERR_VALUE(addr));
23778
23779 fail:
23780 /*
23781- * if hint left us with no space for the requested
23782- * mapping then try again:
23783- */
23784- if (first_time) {
23785- mm->free_area_cache = base;
23786- largest_hole = 0;
23787- first_time = 0;
23788- goto try_again;
23789- }
23790- /*
23791 * A failed mmap() very likely causes application failure,
23792 * so fall back to the bottom-up function here. This scenario
23793 * can happen with large stack limits and large mmap()
23794 * allocations.
23795 */
23796- mm->free_area_cache = TASK_UNMAPPED_BASE;
23797+
23798+#ifdef CONFIG_PAX_SEGMEXEC
23799+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23800+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
23801+ else
23802+#endif
23803+
23804+ mm->mmap_base = TASK_UNMAPPED_BASE;
23805+
23806+#ifdef CONFIG_PAX_RANDMMAP
23807+ if (mm->pax_flags & MF_PAX_RANDMMAP)
23808+ mm->mmap_base += mm->delta_mmap;
23809+#endif
23810+
23811+ mm->free_area_cache = mm->mmap_base;
23812 mm->cached_hole_size = ~0UL;
23813 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
23814 len, pgoff, flags);
23815@@ -388,6 +392,7 @@ fail:
23816 /*
23817 * Restore the topdown base:
23818 */
23819+ mm->mmap_base = base;
23820 mm->free_area_cache = base;
23821 mm->cached_hole_size = ~0UL;
23822
23823@@ -401,10 +406,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
23824 struct hstate *h = hstate_file(file);
23825 struct mm_struct *mm = current->mm;
23826 struct vm_area_struct *vma;
23827+ unsigned long pax_task_size = TASK_SIZE;
23828
23829 if (len & ~huge_page_mask(h))
23830 return -EINVAL;
23831- if (len > TASK_SIZE)
23832+
23833+#ifdef CONFIG_PAX_SEGMEXEC
23834+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23835+ pax_task_size = SEGMEXEC_TASK_SIZE;
23836+#endif
23837+
23838+ pax_task_size -= PAGE_SIZE;
23839+
23840+ if (len > pax_task_size)
23841 return -ENOMEM;
23842
23843 if (flags & MAP_FIXED) {
23844@@ -416,8 +430,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
23845 if (addr) {
23846 addr = ALIGN(addr, huge_page_size(h));
23847 vma = find_vma(mm, addr);
23848- if (TASK_SIZE - len >= addr &&
23849- (!vma || addr + len <= vma->vm_start))
23850+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
23851 return addr;
23852 }
23853 if (mm->get_unmapped_area == arch_get_unmapped_area)
23854diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
23855index 6cabf65..77e9c1c 100644
23856--- a/arch/x86/mm/init.c
23857+++ b/arch/x86/mm/init.c
23858@@ -17,6 +17,7 @@
23859 #include <asm/tlb.h>
23860 #include <asm/proto.h>
23861 #include <asm/dma.h> /* for MAX_DMA_PFN */
23862+#include <asm/desc.h>
23863
23864 unsigned long __initdata pgt_buf_start;
23865 unsigned long __meminitdata pgt_buf_end;
23866@@ -33,7 +34,7 @@ int direct_gbpages
23867 static void __init find_early_table_space(unsigned long end, int use_pse,
23868 int use_gbpages)
23869 {
23870- unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
23871+ unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
23872 phys_addr_t base;
23873
23874 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
23875@@ -314,8 +315,29 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
23876 */
23877 int devmem_is_allowed(unsigned long pagenr)
23878 {
23879+#ifdef CONFIG_GRKERNSEC_KMEM
23880+ /* allow BDA */
23881+ if (!pagenr)
23882+ return 1;
23883+ /* allow EBDA */
23884+ if ((0x9f000 >> PAGE_SHIFT) == pagenr)
23885+ return 1;
23886+#else
23887+ if (!pagenr)
23888+ return 1;
23889+#ifdef CONFIG_VM86
23890+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
23891+ return 1;
23892+#endif
23893+#endif
23894+
23895+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
23896+ return 1;
23897+#ifdef CONFIG_GRKERNSEC_KMEM
23898+ /* throw out everything else below 1MB */
23899 if (pagenr <= 256)
23900- return 1;
23901+ return 0;
23902+#endif
23903 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
23904 return 0;
23905 if (!page_is_ram(pagenr))
23906@@ -374,6 +396,86 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
23907
23908 void free_initmem(void)
23909 {
23910+
23911+#ifdef CONFIG_PAX_KERNEXEC
23912+#ifdef CONFIG_X86_32
23913+ /* PaX: limit KERNEL_CS to actual size */
23914+ unsigned long addr, limit;
23915+ struct desc_struct d;
23916+ int cpu;
23917+
23918+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
23919+ limit = (limit - 1UL) >> PAGE_SHIFT;
23920+
23921+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
23922+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
23923+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
23924+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
23925+ }
23926+
23927+ /* PaX: make KERNEL_CS read-only */
23928+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
23929+ if (!paravirt_enabled())
23930+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
23931+/*
23932+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
23933+ pgd = pgd_offset_k(addr);
23934+ pud = pud_offset(pgd, addr);
23935+ pmd = pmd_offset(pud, addr);
23936+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
23937+ }
23938+*/
23939+#ifdef CONFIG_X86_PAE
23940+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
23941+/*
23942+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
23943+ pgd = pgd_offset_k(addr);
23944+ pud = pud_offset(pgd, addr);
23945+ pmd = pmd_offset(pud, addr);
23946+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
23947+ }
23948+*/
23949+#endif
23950+
23951+#ifdef CONFIG_MODULES
23952+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
23953+#endif
23954+
23955+#else
23956+ pgd_t *pgd;
23957+ pud_t *pud;
23958+ pmd_t *pmd;
23959+ unsigned long addr, end;
23960+
23961+ /* PaX: make kernel code/rodata read-only, rest non-executable */
23962+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
23963+ pgd = pgd_offset_k(addr);
23964+ pud = pud_offset(pgd, addr);
23965+ pmd = pmd_offset(pud, addr);
23966+ if (!pmd_present(*pmd))
23967+ continue;
23968+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
23969+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
23970+ else
23971+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
23972+ }
23973+
23974+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
23975+ end = addr + KERNEL_IMAGE_SIZE;
23976+ for (; addr < end; addr += PMD_SIZE) {
23977+ pgd = pgd_offset_k(addr);
23978+ pud = pud_offset(pgd, addr);
23979+ pmd = pmd_offset(pud, addr);
23980+ if (!pmd_present(*pmd))
23981+ continue;
23982+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
23983+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
23984+ }
23985+#endif
23986+
23987+ flush_tlb_all();
23988+#endif
23989+
23990 free_init_pages("unused kernel memory",
23991 (unsigned long)(&__init_begin),
23992 (unsigned long)(&__init_end));
23993diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
23994index 8663f6c..829ae76 100644
23995--- a/arch/x86/mm/init_32.c
23996+++ b/arch/x86/mm/init_32.c
23997@@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
23998 }
23999
24000 /*
24001- * Creates a middle page table and puts a pointer to it in the
24002- * given global directory entry. This only returns the gd entry
24003- * in non-PAE compilation mode, since the middle layer is folded.
24004- */
24005-static pmd_t * __init one_md_table_init(pgd_t *pgd)
24006-{
24007- pud_t *pud;
24008- pmd_t *pmd_table;
24009-
24010-#ifdef CONFIG_X86_PAE
24011- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24012- if (after_bootmem)
24013- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24014- else
24015- pmd_table = (pmd_t *)alloc_low_page();
24016- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24017- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24018- pud = pud_offset(pgd, 0);
24019- BUG_ON(pmd_table != pmd_offset(pud, 0));
24020-
24021- return pmd_table;
24022- }
24023-#endif
24024- pud = pud_offset(pgd, 0);
24025- pmd_table = pmd_offset(pud, 0);
24026-
24027- return pmd_table;
24028-}
24029-
24030-/*
24031 * Create a page table and place a pointer to it in a middle page
24032 * directory entry:
24033 */
24034@@ -123,13 +93,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24035 page_table = (pte_t *)alloc_low_page();
24036
24037 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24038+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24039+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24040+#else
24041 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24042+#endif
24043 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24044 }
24045
24046 return pte_offset_kernel(pmd, 0);
24047 }
24048
24049+static pmd_t * __init one_md_table_init(pgd_t *pgd)
24050+{
24051+ pud_t *pud;
24052+ pmd_t *pmd_table;
24053+
24054+ pud = pud_offset(pgd, 0);
24055+ pmd_table = pmd_offset(pud, 0);
24056+
24057+ return pmd_table;
24058+}
24059+
24060 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24061 {
24062 int pgd_idx = pgd_index(vaddr);
24063@@ -203,6 +188,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24064 int pgd_idx, pmd_idx;
24065 unsigned long vaddr;
24066 pgd_t *pgd;
24067+ pud_t *pud;
24068 pmd_t *pmd;
24069 pte_t *pte = NULL;
24070
24071@@ -212,8 +198,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24072 pgd = pgd_base + pgd_idx;
24073
24074 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24075- pmd = one_md_table_init(pgd);
24076- pmd = pmd + pmd_index(vaddr);
24077+ pud = pud_offset(pgd, vaddr);
24078+ pmd = pmd_offset(pud, vaddr);
24079+
24080+#ifdef CONFIG_X86_PAE
24081+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24082+#endif
24083+
24084 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24085 pmd++, pmd_idx++) {
24086 pte = page_table_kmap_check(one_page_table_init(pmd),
24087@@ -225,11 +216,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24088 }
24089 }
24090
24091-static inline int is_kernel_text(unsigned long addr)
24092+static inline int is_kernel_text(unsigned long start, unsigned long end)
24093 {
24094- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24095- return 1;
24096- return 0;
24097+ if ((start > ktla_ktva((unsigned long)_etext) ||
24098+ end <= ktla_ktva((unsigned long)_stext)) &&
24099+ (start > ktla_ktva((unsigned long)_einittext) ||
24100+ end <= ktla_ktva((unsigned long)_sinittext)) &&
24101+
24102+#ifdef CONFIG_ACPI_SLEEP
24103+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24104+#endif
24105+
24106+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24107+ return 0;
24108+ return 1;
24109 }
24110
24111 /*
24112@@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned long start,
24113 unsigned long last_map_addr = end;
24114 unsigned long start_pfn, end_pfn;
24115 pgd_t *pgd_base = swapper_pg_dir;
24116- int pgd_idx, pmd_idx, pte_ofs;
24117+ unsigned int pgd_idx, pmd_idx, pte_ofs;
24118 unsigned long pfn;
24119 pgd_t *pgd;
24120+ pud_t *pud;
24121 pmd_t *pmd;
24122 pte_t *pte;
24123 unsigned pages_2m, pages_4k;
24124@@ -281,8 +282,13 @@ repeat:
24125 pfn = start_pfn;
24126 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24127 pgd = pgd_base + pgd_idx;
24128- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24129- pmd = one_md_table_init(pgd);
24130+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24131+ pud = pud_offset(pgd, 0);
24132+ pmd = pmd_offset(pud, 0);
24133+
24134+#ifdef CONFIG_X86_PAE
24135+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24136+#endif
24137
24138 if (pfn >= end_pfn)
24139 continue;
24140@@ -294,14 +300,13 @@ repeat:
24141 #endif
24142 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24143 pmd++, pmd_idx++) {
24144- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24145+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24146
24147 /*
24148 * Map with big pages if possible, otherwise
24149 * create normal page tables:
24150 */
24151 if (use_pse) {
24152- unsigned int addr2;
24153 pgprot_t prot = PAGE_KERNEL_LARGE;
24154 /*
24155 * first pass will use the same initial
24156@@ -311,11 +316,7 @@ repeat:
24157 __pgprot(PTE_IDENT_ATTR |
24158 _PAGE_PSE);
24159
24160- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24161- PAGE_OFFSET + PAGE_SIZE-1;
24162-
24163- if (is_kernel_text(addr) ||
24164- is_kernel_text(addr2))
24165+ if (is_kernel_text(address, address + PMD_SIZE))
24166 prot = PAGE_KERNEL_LARGE_EXEC;
24167
24168 pages_2m++;
24169@@ -332,7 +333,7 @@ repeat:
24170 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24171 pte += pte_ofs;
24172 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24173- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24174+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24175 pgprot_t prot = PAGE_KERNEL;
24176 /*
24177 * first pass will use the same initial
24178@@ -340,7 +341,7 @@ repeat:
24179 */
24180 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24181
24182- if (is_kernel_text(addr))
24183+ if (is_kernel_text(address, address + PAGE_SIZE))
24184 prot = PAGE_KERNEL_EXEC;
24185
24186 pages_4k++;
24187@@ -466,7 +467,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24188
24189 pud = pud_offset(pgd, va);
24190 pmd = pmd_offset(pud, va);
24191- if (!pmd_present(*pmd))
24192+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
24193 break;
24194
24195 pte = pte_offset_kernel(pmd, va);
24196@@ -518,12 +519,10 @@ void __init early_ioremap_page_table_range_init(void)
24197
24198 static void __init pagetable_init(void)
24199 {
24200- pgd_t *pgd_base = swapper_pg_dir;
24201-
24202- permanent_kmaps_init(pgd_base);
24203+ permanent_kmaps_init(swapper_pg_dir);
24204 }
24205
24206-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24207+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24208 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24209
24210 /* user-defined highmem size */
24211@@ -735,6 +734,12 @@ void __init mem_init(void)
24212
24213 pci_iommu_alloc();
24214
24215+#ifdef CONFIG_PAX_PER_CPU_PGD
24216+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24217+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24218+ KERNEL_PGD_PTRS);
24219+#endif
24220+
24221 #ifdef CONFIG_FLATMEM
24222 BUG_ON(!mem_map);
24223 #endif
24224@@ -761,7 +766,7 @@ void __init mem_init(void)
24225 reservedpages++;
24226
24227 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24228- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24229+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24230 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24231
24232 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24233@@ -802,10 +807,10 @@ void __init mem_init(void)
24234 ((unsigned long)&__init_end -
24235 (unsigned long)&__init_begin) >> 10,
24236
24237- (unsigned long)&_etext, (unsigned long)&_edata,
24238- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24239+ (unsigned long)&_sdata, (unsigned long)&_edata,
24240+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24241
24242- (unsigned long)&_text, (unsigned long)&_etext,
24243+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24244 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24245
24246 /*
24247@@ -883,6 +888,7 @@ void set_kernel_text_rw(void)
24248 if (!kernel_set_to_readonly)
24249 return;
24250
24251+ start = ktla_ktva(start);
24252 pr_debug("Set kernel text: %lx - %lx for read write\n",
24253 start, start+size);
24254
24255@@ -897,6 +903,7 @@ void set_kernel_text_ro(void)
24256 if (!kernel_set_to_readonly)
24257 return;
24258
24259+ start = ktla_ktva(start);
24260 pr_debug("Set kernel text: %lx - %lx for read only\n",
24261 start, start+size);
24262
24263@@ -925,6 +932,7 @@ void mark_rodata_ro(void)
24264 unsigned long start = PFN_ALIGN(_text);
24265 unsigned long size = PFN_ALIGN(_etext) - start;
24266
24267+ start = ktla_ktva(start);
24268 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24269 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24270 size >> 10);
24271diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24272index 436a030..b8596b9 100644
24273--- a/arch/x86/mm/init_64.c
24274+++ b/arch/x86/mm/init_64.c
24275@@ -75,7 +75,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24276 * around without checking the pgd every time.
24277 */
24278
24279-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24280+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24281 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24282
24283 int force_personality32;
24284@@ -108,12 +108,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24285
24286 for (address = start; address <= end; address += PGDIR_SIZE) {
24287 const pgd_t *pgd_ref = pgd_offset_k(address);
24288+
24289+#ifdef CONFIG_PAX_PER_CPU_PGD
24290+ unsigned long cpu;
24291+#else
24292 struct page *page;
24293+#endif
24294
24295 if (pgd_none(*pgd_ref))
24296 continue;
24297
24298 spin_lock(&pgd_lock);
24299+
24300+#ifdef CONFIG_PAX_PER_CPU_PGD
24301+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24302+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
24303+#else
24304 list_for_each_entry(page, &pgd_list, lru) {
24305 pgd_t *pgd;
24306 spinlock_t *pgt_lock;
24307@@ -122,6 +132,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24308 /* the pgt_lock only for Xen */
24309 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24310 spin_lock(pgt_lock);
24311+#endif
24312
24313 if (pgd_none(*pgd))
24314 set_pgd(pgd, *pgd_ref);
24315@@ -129,7 +140,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24316 BUG_ON(pgd_page_vaddr(*pgd)
24317 != pgd_page_vaddr(*pgd_ref));
24318
24319+#ifndef CONFIG_PAX_PER_CPU_PGD
24320 spin_unlock(pgt_lock);
24321+#endif
24322+
24323 }
24324 spin_unlock(&pgd_lock);
24325 }
24326@@ -203,7 +217,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
24327 pmd = fill_pmd(pud, vaddr);
24328 pte = fill_pte(pmd, vaddr);
24329
24330+ pax_open_kernel();
24331 set_pte(pte, new_pte);
24332+ pax_close_kernel();
24333
24334 /*
24335 * It's enough to flush this one mapping.
24336@@ -262,14 +278,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
24337 pgd = pgd_offset_k((unsigned long)__va(phys));
24338 if (pgd_none(*pgd)) {
24339 pud = (pud_t *) spp_getpage();
24340- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
24341- _PAGE_USER));
24342+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
24343 }
24344 pud = pud_offset(pgd, (unsigned long)__va(phys));
24345 if (pud_none(*pud)) {
24346 pmd = (pmd_t *) spp_getpage();
24347- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
24348- _PAGE_USER));
24349+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
24350 }
24351 pmd = pmd_offset(pud, phys);
24352 BUG_ON(!pmd_none(*pmd));
24353@@ -330,7 +344,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
24354 if (pfn >= pgt_buf_top)
24355 panic("alloc_low_page: ran out of memory");
24356
24357- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24358+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24359 clear_page(adr);
24360 *phys = pfn * PAGE_SIZE;
24361 return adr;
24362@@ -346,7 +360,7 @@ static __ref void *map_low_page(void *virt)
24363
24364 phys = __pa(virt);
24365 left = phys & (PAGE_SIZE - 1);
24366- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24367+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24368 adr = (void *)(((unsigned long)adr) | left);
24369
24370 return adr;
24371@@ -684,6 +698,12 @@ void __init mem_init(void)
24372
24373 pci_iommu_alloc();
24374
24375+#ifdef CONFIG_PAX_PER_CPU_PGD
24376+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24377+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24378+ KERNEL_PGD_PTRS);
24379+#endif
24380+
24381 /* clear_bss() already clear the empty_zero_page */
24382
24383 reservedpages = 0;
24384@@ -844,8 +864,8 @@ int kern_addr_valid(unsigned long addr)
24385 static struct vm_area_struct gate_vma = {
24386 .vm_start = VSYSCALL_START,
24387 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
24388- .vm_page_prot = PAGE_READONLY_EXEC,
24389- .vm_flags = VM_READ | VM_EXEC
24390+ .vm_page_prot = PAGE_READONLY,
24391+ .vm_flags = VM_READ
24392 };
24393
24394 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
24395@@ -879,7 +899,7 @@ int in_gate_area_no_mm(unsigned long addr)
24396
24397 const char *arch_vma_name(struct vm_area_struct *vma)
24398 {
24399- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24400+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24401 return "[vdso]";
24402 if (vma == &gate_vma)
24403 return "[vsyscall]";
24404diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
24405index 7b179b4..6bd1777 100644
24406--- a/arch/x86/mm/iomap_32.c
24407+++ b/arch/x86/mm/iomap_32.c
24408@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
24409 type = kmap_atomic_idx_push();
24410 idx = type + KM_TYPE_NR * smp_processor_id();
24411 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24412+
24413+ pax_open_kernel();
24414 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
24415+ pax_close_kernel();
24416+
24417 arch_flush_lazy_mmu_mode();
24418
24419 return (void *)vaddr;
24420diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
24421index be1ef57..55f0160 100644
24422--- a/arch/x86/mm/ioremap.c
24423+++ b/arch/x86/mm/ioremap.c
24424@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
24425 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
24426 int is_ram = page_is_ram(pfn);
24427
24428- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
24429+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
24430 return NULL;
24431 WARN_ON_ONCE(is_ram);
24432 }
24433@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
24434
24435 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
24436 if (page_is_ram(start >> PAGE_SHIFT))
24437+#ifdef CONFIG_HIGHMEM
24438+ if ((start >> PAGE_SHIFT) < max_low_pfn)
24439+#endif
24440 return __va(phys);
24441
24442 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
24443@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
24444 early_param("early_ioremap_debug", early_ioremap_debug_setup);
24445
24446 static __initdata int after_paging_init;
24447-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
24448+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
24449
24450 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
24451 {
24452@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
24453 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
24454
24455 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
24456- memset(bm_pte, 0, sizeof(bm_pte));
24457- pmd_populate_kernel(&init_mm, pmd, bm_pte);
24458+ pmd_populate_user(&init_mm, pmd, bm_pte);
24459
24460 /*
24461 * The boot-ioremap range spans multiple pmds, for which
24462diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
24463index d87dd6d..bf3fa66 100644
24464--- a/arch/x86/mm/kmemcheck/kmemcheck.c
24465+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
24466@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
24467 * memory (e.g. tracked pages)? For now, we need this to avoid
24468 * invoking kmemcheck for PnP BIOS calls.
24469 */
24470- if (regs->flags & X86_VM_MASK)
24471+ if (v8086_mode(regs))
24472 return false;
24473- if (regs->cs != __KERNEL_CS)
24474+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
24475 return false;
24476
24477 pte = kmemcheck_pte_lookup(address);
24478diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
24479index 845df68..1d8d29f 100644
24480--- a/arch/x86/mm/mmap.c
24481+++ b/arch/x86/mm/mmap.c
24482@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
24483 * Leave an at least ~128 MB hole with possible stack randomization.
24484 */
24485 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
24486-#define MAX_GAP (TASK_SIZE/6*5)
24487+#define MAX_GAP (pax_task_size/6*5)
24488
24489 static int mmap_is_legacy(void)
24490 {
24491@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
24492 return rnd << PAGE_SHIFT;
24493 }
24494
24495-static unsigned long mmap_base(void)
24496+static unsigned long mmap_base(struct mm_struct *mm)
24497 {
24498 unsigned long gap = rlimit(RLIMIT_STACK);
24499+ unsigned long pax_task_size = TASK_SIZE;
24500+
24501+#ifdef CONFIG_PAX_SEGMEXEC
24502+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24503+ pax_task_size = SEGMEXEC_TASK_SIZE;
24504+#endif
24505
24506 if (gap < MIN_GAP)
24507 gap = MIN_GAP;
24508 else if (gap > MAX_GAP)
24509 gap = MAX_GAP;
24510
24511- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
24512+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
24513 }
24514
24515 /*
24516 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
24517 * does, but not when emulating X86_32
24518 */
24519-static unsigned long mmap_legacy_base(void)
24520+static unsigned long mmap_legacy_base(struct mm_struct *mm)
24521 {
24522- if (mmap_is_ia32())
24523+ if (mmap_is_ia32()) {
24524+
24525+#ifdef CONFIG_PAX_SEGMEXEC
24526+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24527+ return SEGMEXEC_TASK_UNMAPPED_BASE;
24528+ else
24529+#endif
24530+
24531 return TASK_UNMAPPED_BASE;
24532- else
24533+ } else
24534 return TASK_UNMAPPED_BASE + mmap_rnd();
24535 }
24536
24537@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
24538 void arch_pick_mmap_layout(struct mm_struct *mm)
24539 {
24540 if (mmap_is_legacy()) {
24541- mm->mmap_base = mmap_legacy_base();
24542+ mm->mmap_base = mmap_legacy_base(mm);
24543+
24544+#ifdef CONFIG_PAX_RANDMMAP
24545+ if (mm->pax_flags & MF_PAX_RANDMMAP)
24546+ mm->mmap_base += mm->delta_mmap;
24547+#endif
24548+
24549 mm->get_unmapped_area = arch_get_unmapped_area;
24550 mm->unmap_area = arch_unmap_area;
24551 } else {
24552- mm->mmap_base = mmap_base();
24553+ mm->mmap_base = mmap_base(mm);
24554+
24555+#ifdef CONFIG_PAX_RANDMMAP
24556+ if (mm->pax_flags & MF_PAX_RANDMMAP)
24557+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
24558+#endif
24559+
24560 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
24561 mm->unmap_area = arch_unmap_area_topdown;
24562 }
24563diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
24564index dc0b727..dc9d71a 100644
24565--- a/arch/x86/mm/mmio-mod.c
24566+++ b/arch/x86/mm/mmio-mod.c
24567@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
24568 break;
24569 default:
24570 {
24571- unsigned char *ip = (unsigned char *)instptr;
24572+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
24573 my_trace->opcode = MMIO_UNKNOWN_OP;
24574 my_trace->width = 0;
24575 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
24576@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
24577 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
24578 void __iomem *addr)
24579 {
24580- static atomic_t next_id;
24581+ static atomic_unchecked_t next_id;
24582 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
24583 /* These are page-unaligned. */
24584 struct mmiotrace_map map = {
24585@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
24586 .private = trace
24587 },
24588 .phys = offset,
24589- .id = atomic_inc_return(&next_id)
24590+ .id = atomic_inc_return_unchecked(&next_id)
24591 };
24592 map.map_id = trace->id;
24593
24594diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
24595index b008656..773eac2 100644
24596--- a/arch/x86/mm/pageattr-test.c
24597+++ b/arch/x86/mm/pageattr-test.c
24598@@ -36,7 +36,7 @@ enum {
24599
24600 static int pte_testbit(pte_t pte)
24601 {
24602- return pte_flags(pte) & _PAGE_UNUSED1;
24603+ return pte_flags(pte) & _PAGE_CPA_TEST;
24604 }
24605
24606 struct split_state {
24607diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
24608index e1ebde3..b1e1db38 100644
24609--- a/arch/x86/mm/pageattr.c
24610+++ b/arch/x86/mm/pageattr.c
24611@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
24612 */
24613 #ifdef CONFIG_PCI_BIOS
24614 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
24615- pgprot_val(forbidden) |= _PAGE_NX;
24616+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
24617 #endif
24618
24619 /*
24620@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
24621 * Does not cover __inittext since that is gone later on. On
24622 * 64bit we do not enforce !NX on the low mapping
24623 */
24624- if (within(address, (unsigned long)_text, (unsigned long)_etext))
24625- pgprot_val(forbidden) |= _PAGE_NX;
24626+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
24627+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
24628
24629+#ifdef CONFIG_DEBUG_RODATA
24630 /*
24631 * The .rodata section needs to be read-only. Using the pfn
24632 * catches all aliases.
24633@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
24634 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
24635 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
24636 pgprot_val(forbidden) |= _PAGE_RW;
24637+#endif
24638
24639 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
24640 /*
24641@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
24642 }
24643 #endif
24644
24645+#ifdef CONFIG_PAX_KERNEXEC
24646+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
24647+ pgprot_val(forbidden) |= _PAGE_RW;
24648+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
24649+ }
24650+#endif
24651+
24652 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
24653
24654 return prot;
24655@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
24656 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
24657 {
24658 /* change init_mm */
24659+ pax_open_kernel();
24660 set_pte_atomic(kpte, pte);
24661+
24662 #ifdef CONFIG_X86_32
24663 if (!SHARED_KERNEL_PMD) {
24664+
24665+#ifdef CONFIG_PAX_PER_CPU_PGD
24666+ unsigned long cpu;
24667+#else
24668 struct page *page;
24669+#endif
24670
24671+#ifdef CONFIG_PAX_PER_CPU_PGD
24672+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24673+ pgd_t *pgd = get_cpu_pgd(cpu);
24674+#else
24675 list_for_each_entry(page, &pgd_list, lru) {
24676- pgd_t *pgd;
24677+ pgd_t *pgd = (pgd_t *)page_address(page);
24678+#endif
24679+
24680 pud_t *pud;
24681 pmd_t *pmd;
24682
24683- pgd = (pgd_t *)page_address(page) + pgd_index(address);
24684+ pgd += pgd_index(address);
24685 pud = pud_offset(pgd, address);
24686 pmd = pmd_offset(pud, address);
24687 set_pte_atomic((pte_t *)pmd, pte);
24688 }
24689 }
24690 #endif
24691+ pax_close_kernel();
24692 }
24693
24694 static int
24695diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
24696index f6ff57b..481690f 100644
24697--- a/arch/x86/mm/pat.c
24698+++ b/arch/x86/mm/pat.c
24699@@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
24700
24701 if (!entry) {
24702 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
24703- current->comm, current->pid, start, end);
24704+ current->comm, task_pid_nr(current), start, end);
24705 return -EINVAL;
24706 }
24707
24708@@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
24709 while (cursor < to) {
24710 if (!devmem_is_allowed(pfn)) {
24711 printk(KERN_INFO
24712- "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
24713- current->comm, from, to);
24714+ "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
24715+ current->comm, from, to, cursor);
24716 return 0;
24717 }
24718 cursor += PAGE_SIZE;
24719@@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
24720 printk(KERN_INFO
24721 "%s:%d ioremap_change_attr failed %s "
24722 "for %Lx-%Lx\n",
24723- current->comm, current->pid,
24724+ current->comm, task_pid_nr(current),
24725 cattr_name(flags),
24726 base, (unsigned long long)(base + size));
24727 return -EINVAL;
24728@@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
24729 if (want_flags != flags) {
24730 printk(KERN_WARNING
24731 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
24732- current->comm, current->pid,
24733+ current->comm, task_pid_nr(current),
24734 cattr_name(want_flags),
24735 (unsigned long long)paddr,
24736 (unsigned long long)(paddr + size),
24737@@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
24738 free_memtype(paddr, paddr + size);
24739 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
24740 " for %Lx-%Lx, got %s\n",
24741- current->comm, current->pid,
24742+ current->comm, task_pid_nr(current),
24743 cattr_name(want_flags),
24744 (unsigned long long)paddr,
24745 (unsigned long long)(paddr + size),
24746diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
24747index 9f0614d..92ae64a 100644
24748--- a/arch/x86/mm/pf_in.c
24749+++ b/arch/x86/mm/pf_in.c
24750@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
24751 int i;
24752 enum reason_type rv = OTHERS;
24753
24754- p = (unsigned char *)ins_addr;
24755+ p = (unsigned char *)ktla_ktva(ins_addr);
24756 p += skip_prefix(p, &prf);
24757 p += get_opcode(p, &opcode);
24758
24759@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
24760 struct prefix_bits prf;
24761 int i;
24762
24763- p = (unsigned char *)ins_addr;
24764+ p = (unsigned char *)ktla_ktva(ins_addr);
24765 p += skip_prefix(p, &prf);
24766 p += get_opcode(p, &opcode);
24767
24768@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
24769 struct prefix_bits prf;
24770 int i;
24771
24772- p = (unsigned char *)ins_addr;
24773+ p = (unsigned char *)ktla_ktva(ins_addr);
24774 p += skip_prefix(p, &prf);
24775 p += get_opcode(p, &opcode);
24776
24777@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
24778 struct prefix_bits prf;
24779 int i;
24780
24781- p = (unsigned char *)ins_addr;
24782+ p = (unsigned char *)ktla_ktva(ins_addr);
24783 p += skip_prefix(p, &prf);
24784 p += get_opcode(p, &opcode);
24785 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
24786@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
24787 struct prefix_bits prf;
24788 int i;
24789
24790- p = (unsigned char *)ins_addr;
24791+ p = (unsigned char *)ktla_ktva(ins_addr);
24792 p += skip_prefix(p, &prf);
24793 p += get_opcode(p, &opcode);
24794 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
24795diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
24796index 8573b83..c3b1a30 100644
24797--- a/arch/x86/mm/pgtable.c
24798+++ b/arch/x86/mm/pgtable.c
24799@@ -84,10 +84,52 @@ static inline void pgd_list_del(pgd_t *pgd)
24800 list_del(&page->lru);
24801 }
24802
24803-#define UNSHARED_PTRS_PER_PGD \
24804- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
24805+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24806+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
24807
24808+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
24809+{
24810+ while (count--)
24811+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
24812+}
24813+#endif
24814
24815+#ifdef CONFIG_PAX_PER_CPU_PGD
24816+void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
24817+{
24818+ while (count--)
24819+
24820+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24821+ *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
24822+#else
24823+ *dst++ = *src++;
24824+#endif
24825+
24826+}
24827+#endif
24828+
24829+#ifdef CONFIG_X86_64
24830+#define pxd_t pud_t
24831+#define pyd_t pgd_t
24832+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
24833+#define pxd_free(mm, pud) pud_free((mm), (pud))
24834+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
24835+#define pyd_offset(mm, address) pgd_offset((mm), (address))
24836+#define PYD_SIZE PGDIR_SIZE
24837+#else
24838+#define pxd_t pmd_t
24839+#define pyd_t pud_t
24840+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
24841+#define pxd_free(mm, pud) pmd_free((mm), (pud))
24842+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
24843+#define pyd_offset(mm, address) pud_offset((mm), (address))
24844+#define PYD_SIZE PUD_SIZE
24845+#endif
24846+
24847+#ifdef CONFIG_PAX_PER_CPU_PGD
24848+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
24849+static inline void pgd_dtor(pgd_t *pgd) {}
24850+#else
24851 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
24852 {
24853 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
24854@@ -128,6 +170,7 @@ static void pgd_dtor(pgd_t *pgd)
24855 pgd_list_del(pgd);
24856 spin_unlock(&pgd_lock);
24857 }
24858+#endif
24859
24860 /*
24861 * List of all pgd's needed for non-PAE so it can invalidate entries
24862@@ -140,7 +183,7 @@ static void pgd_dtor(pgd_t *pgd)
24863 * -- wli
24864 */
24865
24866-#ifdef CONFIG_X86_PAE
24867+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24868 /*
24869 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
24870 * updating the top-level pagetable entries to guarantee the
24871@@ -152,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
24872 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
24873 * and initialize the kernel pmds here.
24874 */
24875-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
24876+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
24877
24878 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
24879 {
24880@@ -170,36 +213,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
24881 */
24882 flush_tlb_mm(mm);
24883 }
24884+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
24885+#define PREALLOCATED_PXDS USER_PGD_PTRS
24886 #else /* !CONFIG_X86_PAE */
24887
24888 /* No need to prepopulate any pagetable entries in non-PAE modes. */
24889-#define PREALLOCATED_PMDS 0
24890+#define PREALLOCATED_PXDS 0
24891
24892 #endif /* CONFIG_X86_PAE */
24893
24894-static void free_pmds(pmd_t *pmds[])
24895+static void free_pxds(pxd_t *pxds[])
24896 {
24897 int i;
24898
24899- for(i = 0; i < PREALLOCATED_PMDS; i++)
24900- if (pmds[i])
24901- free_page((unsigned long)pmds[i]);
24902+ for(i = 0; i < PREALLOCATED_PXDS; i++)
24903+ if (pxds[i])
24904+ free_page((unsigned long)pxds[i]);
24905 }
24906
24907-static int preallocate_pmds(pmd_t *pmds[])
24908+static int preallocate_pxds(pxd_t *pxds[])
24909 {
24910 int i;
24911 bool failed = false;
24912
24913- for(i = 0; i < PREALLOCATED_PMDS; i++) {
24914- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
24915- if (pmd == NULL)
24916+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
24917+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
24918+ if (pxd == NULL)
24919 failed = true;
24920- pmds[i] = pmd;
24921+ pxds[i] = pxd;
24922 }
24923
24924 if (failed) {
24925- free_pmds(pmds);
24926+ free_pxds(pxds);
24927 return -ENOMEM;
24928 }
24929
24930@@ -212,51 +257,55 @@ static int preallocate_pmds(pmd_t *pmds[])
24931 * preallocate which never got a corresponding vma will need to be
24932 * freed manually.
24933 */
24934-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
24935+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
24936 {
24937 int i;
24938
24939- for(i = 0; i < PREALLOCATED_PMDS; i++) {
24940+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
24941 pgd_t pgd = pgdp[i];
24942
24943 if (pgd_val(pgd) != 0) {
24944- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
24945+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
24946
24947- pgdp[i] = native_make_pgd(0);
24948+ set_pgd(pgdp + i, native_make_pgd(0));
24949
24950- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
24951- pmd_free(mm, pmd);
24952+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
24953+ pxd_free(mm, pxd);
24954 }
24955 }
24956 }
24957
24958-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
24959+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
24960 {
24961- pud_t *pud;
24962+ pyd_t *pyd;
24963 unsigned long addr;
24964 int i;
24965
24966- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
24967+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
24968 return;
24969
24970- pud = pud_offset(pgd, 0);
24971+#ifdef CONFIG_X86_64
24972+ pyd = pyd_offset(mm, 0L);
24973+#else
24974+ pyd = pyd_offset(pgd, 0L);
24975+#endif
24976
24977- for (addr = i = 0; i < PREALLOCATED_PMDS;
24978- i++, pud++, addr += PUD_SIZE) {
24979- pmd_t *pmd = pmds[i];
24980+ for (addr = i = 0; i < PREALLOCATED_PXDS;
24981+ i++, pyd++, addr += PYD_SIZE) {
24982+ pxd_t *pxd = pxds[i];
24983
24984 if (i >= KERNEL_PGD_BOUNDARY)
24985- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
24986- sizeof(pmd_t) * PTRS_PER_PMD);
24987+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
24988+ sizeof(pxd_t) * PTRS_PER_PMD);
24989
24990- pud_populate(mm, pud, pmd);
24991+ pyd_populate(mm, pyd, pxd);
24992 }
24993 }
24994
24995 pgd_t *pgd_alloc(struct mm_struct *mm)
24996 {
24997 pgd_t *pgd;
24998- pmd_t *pmds[PREALLOCATED_PMDS];
24999+ pxd_t *pxds[PREALLOCATED_PXDS];
25000
25001 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25002
25003@@ -265,11 +314,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25004
25005 mm->pgd = pgd;
25006
25007- if (preallocate_pmds(pmds) != 0)
25008+ if (preallocate_pxds(pxds) != 0)
25009 goto out_free_pgd;
25010
25011 if (paravirt_pgd_alloc(mm) != 0)
25012- goto out_free_pmds;
25013+ goto out_free_pxds;
25014
25015 /*
25016 * Make sure that pre-populating the pmds is atomic with
25017@@ -279,14 +328,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25018 spin_lock(&pgd_lock);
25019
25020 pgd_ctor(mm, pgd);
25021- pgd_prepopulate_pmd(mm, pgd, pmds);
25022+ pgd_prepopulate_pxd(mm, pgd, pxds);
25023
25024 spin_unlock(&pgd_lock);
25025
25026 return pgd;
25027
25028-out_free_pmds:
25029- free_pmds(pmds);
25030+out_free_pxds:
25031+ free_pxds(pxds);
25032 out_free_pgd:
25033 free_page((unsigned long)pgd);
25034 out:
25035@@ -295,7 +344,7 @@ out:
25036
25037 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25038 {
25039- pgd_mop_up_pmds(mm, pgd);
25040+ pgd_mop_up_pxds(mm, pgd);
25041 pgd_dtor(pgd);
25042 paravirt_pgd_free(mm, pgd);
25043 free_page((unsigned long)pgd);
25044diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25045index cac7184..09a39fa 100644
25046--- a/arch/x86/mm/pgtable_32.c
25047+++ b/arch/x86/mm/pgtable_32.c
25048@@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25049 return;
25050 }
25051 pte = pte_offset_kernel(pmd, vaddr);
25052+
25053+ pax_open_kernel();
25054 if (pte_val(pteval))
25055 set_pte_at(&init_mm, vaddr, pte, pteval);
25056 else
25057 pte_clear(&init_mm, vaddr, pte);
25058+ pax_close_kernel();
25059
25060 /*
25061 * It's enough to flush this one mapping.
25062diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25063index 410531d..0f16030 100644
25064--- a/arch/x86/mm/setup_nx.c
25065+++ b/arch/x86/mm/setup_nx.c
25066@@ -5,8 +5,10 @@
25067 #include <asm/pgtable.h>
25068 #include <asm/proto.h>
25069
25070+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25071 static int disable_nx __cpuinitdata;
25072
25073+#ifndef CONFIG_PAX_PAGEEXEC
25074 /*
25075 * noexec = on|off
25076 *
25077@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25078 return 0;
25079 }
25080 early_param("noexec", noexec_setup);
25081+#endif
25082+
25083+#endif
25084
25085 void __cpuinit x86_configure_nx(void)
25086 {
25087+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25088 if (cpu_has_nx && !disable_nx)
25089 __supported_pte_mask |= _PAGE_NX;
25090 else
25091+#endif
25092 __supported_pte_mask &= ~_PAGE_NX;
25093 }
25094
25095diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25096index d6c0418..06a0ad5 100644
25097--- a/arch/x86/mm/tlb.c
25098+++ b/arch/x86/mm/tlb.c
25099@@ -65,7 +65,11 @@ void leave_mm(int cpu)
25100 BUG();
25101 cpumask_clear_cpu(cpu,
25102 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
25103+
25104+#ifndef CONFIG_PAX_PER_CPU_PGD
25105 load_cr3(swapper_pg_dir);
25106+#endif
25107+
25108 }
25109 EXPORT_SYMBOL_GPL(leave_mm);
25110
25111diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25112index 6687022..ceabcfa 100644
25113--- a/arch/x86/net/bpf_jit.S
25114+++ b/arch/x86/net/bpf_jit.S
25115@@ -9,6 +9,7 @@
25116 */
25117 #include <linux/linkage.h>
25118 #include <asm/dwarf2.h>
25119+#include <asm/alternative-asm.h>
25120
25121 /*
25122 * Calling convention :
25123@@ -35,6 +36,7 @@ sk_load_word:
25124 jle bpf_slow_path_word
25125 mov (SKBDATA,%rsi),%eax
25126 bswap %eax /* ntohl() */
25127+ pax_force_retaddr
25128 ret
25129
25130
25131@@ -53,6 +55,7 @@ sk_load_half:
25132 jle bpf_slow_path_half
25133 movzwl (SKBDATA,%rsi),%eax
25134 rol $8,%ax # ntohs()
25135+ pax_force_retaddr
25136 ret
25137
25138 sk_load_byte_ind:
25139@@ -66,6 +69,7 @@ sk_load_byte:
25140 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25141 jle bpf_slow_path_byte
25142 movzbl (SKBDATA,%rsi),%eax
25143+ pax_force_retaddr
25144 ret
25145
25146 /**
25147@@ -82,6 +86,7 @@ ENTRY(sk_load_byte_msh)
25148 movzbl (SKBDATA,%rsi),%ebx
25149 and $15,%bl
25150 shl $2,%bl
25151+ pax_force_retaddr
25152 ret
25153 CFI_ENDPROC
25154 ENDPROC(sk_load_byte_msh)
25155@@ -91,6 +96,7 @@ bpf_error:
25156 xor %eax,%eax
25157 mov -8(%rbp),%rbx
25158 leaveq
25159+ pax_force_retaddr
25160 ret
25161
25162 /* rsi contains offset and can be scratched */
25163@@ -113,6 +119,7 @@ bpf_slow_path_word:
25164 js bpf_error
25165 mov -12(%rbp),%eax
25166 bswap %eax
25167+ pax_force_retaddr
25168 ret
25169
25170 bpf_slow_path_half:
25171@@ -121,12 +128,14 @@ bpf_slow_path_half:
25172 mov -12(%rbp),%ax
25173 rol $8,%ax
25174 movzwl %ax,%eax
25175+ pax_force_retaddr
25176 ret
25177
25178 bpf_slow_path_byte:
25179 bpf_slow_path_common(1)
25180 js bpf_error
25181 movzbl -12(%rbp),%eax
25182+ pax_force_retaddr
25183 ret
25184
25185 bpf_slow_path_byte_msh:
25186@@ -137,4 +146,5 @@ bpf_slow_path_byte_msh:
25187 and $15,%al
25188 shl $2,%al
25189 xchg %eax,%ebx
25190+ pax_force_retaddr
25191 ret
25192diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
25193index 5671752..6838cd1 100644
25194--- a/arch/x86/net/bpf_jit_comp.c
25195+++ b/arch/x86/net/bpf_jit_comp.c
25196@@ -117,6 +117,10 @@ static inline void bpf_flush_icache(void *start, void *end)
25197 set_fs(old_fs);
25198 }
25199
25200+struct bpf_jit_work {
25201+ struct work_struct work;
25202+ void *image;
25203+};
25204
25205 void bpf_jit_compile(struct sk_filter *fp)
25206 {
25207@@ -141,6 +145,10 @@ void bpf_jit_compile(struct sk_filter *fp)
25208 if (addrs == NULL)
25209 return;
25210
25211+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
25212+ if (!fp->work)
25213+ goto out;
25214+
25215 /* Before first pass, make a rough estimation of addrs[]
25216 * each bpf instruction is translated to less than 64 bytes
25217 */
25218@@ -477,7 +485,7 @@ void bpf_jit_compile(struct sk_filter *fp)
25219 common_load: seen |= SEEN_DATAREF;
25220 if ((int)K < 0) {
25221 /* Abort the JIT because __load_pointer() is needed. */
25222- goto out;
25223+ goto error;
25224 }
25225 t_offset = func - (image + addrs[i]);
25226 EMIT1_off32(0xbe, K); /* mov imm32,%esi */
25227@@ -492,7 +500,7 @@ common_load: seen |= SEEN_DATAREF;
25228 case BPF_S_LDX_B_MSH:
25229 if ((int)K < 0) {
25230 /* Abort the JIT because __load_pointer() is needed. */
25231- goto out;
25232+ goto error;
25233 }
25234 seen |= SEEN_DATAREF | SEEN_XREG;
25235 t_offset = sk_load_byte_msh - (image + addrs[i]);
25236@@ -582,17 +590,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25237 break;
25238 default:
25239 /* hmm, too complex filter, give up with jit compiler */
25240- goto out;
25241+ goto error;
25242 }
25243 ilen = prog - temp;
25244 if (image) {
25245 if (unlikely(proglen + ilen > oldproglen)) {
25246 pr_err("bpb_jit_compile fatal error\n");
25247- kfree(addrs);
25248- module_free(NULL, image);
25249- return;
25250+ module_free_exec(NULL, image);
25251+ goto error;
25252 }
25253+ pax_open_kernel();
25254 memcpy(image + proglen, temp, ilen);
25255+ pax_close_kernel();
25256 }
25257 proglen += ilen;
25258 addrs[i] = proglen;
25259@@ -613,11 +622,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25260 break;
25261 }
25262 if (proglen == oldproglen) {
25263- image = module_alloc(max_t(unsigned int,
25264- proglen,
25265- sizeof(struct work_struct)));
25266+ image = module_alloc_exec(proglen);
25267 if (!image)
25268- goto out;
25269+ goto error;
25270 }
25271 oldproglen = proglen;
25272 }
25273@@ -633,7 +640,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25274 bpf_flush_icache(image, image + proglen);
25275
25276 fp->bpf_func = (void *)image;
25277- }
25278+ } else
25279+error:
25280+ kfree(fp->work);
25281+
25282 out:
25283 kfree(addrs);
25284 return;
25285@@ -641,18 +651,20 @@ out:
25286
25287 static void jit_free_defer(struct work_struct *arg)
25288 {
25289- module_free(NULL, arg);
25290+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
25291+ kfree(arg);
25292 }
25293
25294 /* run from softirq, we must use a work_struct to call
25295- * module_free() from process context
25296+ * module_free_exec() from process context
25297 */
25298 void bpf_jit_free(struct sk_filter *fp)
25299 {
25300 if (fp->bpf_func != sk_run_filter) {
25301- struct work_struct *work = (struct work_struct *)fp->bpf_func;
25302+ struct work_struct *work = &fp->work->work;
25303
25304 INIT_WORK(work, jit_free_defer);
25305+ fp->work->image = fp->bpf_func;
25306 schedule_work(work);
25307 }
25308 }
25309diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
25310index bff89df..377758a 100644
25311--- a/arch/x86/oprofile/backtrace.c
25312+++ b/arch/x86/oprofile/backtrace.c
25313@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
25314 struct stack_frame_ia32 *fp;
25315 unsigned long bytes;
25316
25317- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25318+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25319 if (bytes != sizeof(bufhead))
25320 return NULL;
25321
25322- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
25323+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
25324
25325 oprofile_add_trace(bufhead[0].return_address);
25326
25327@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
25328 struct stack_frame bufhead[2];
25329 unsigned long bytes;
25330
25331- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25332+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25333 if (bytes != sizeof(bufhead))
25334 return NULL;
25335
25336@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
25337 {
25338 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
25339
25340- if (!user_mode_vm(regs)) {
25341+ if (!user_mode(regs)) {
25342 unsigned long stack = kernel_stack_pointer(regs);
25343 if (depth)
25344 dump_trace(NULL, regs, (unsigned long *)stack, 0,
25345diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
25346index cb29191..036766d 100644
25347--- a/arch/x86/pci/mrst.c
25348+++ b/arch/x86/pci/mrst.c
25349@@ -234,7 +234,9 @@ int __init pci_mrst_init(void)
25350 printk(KERN_INFO "Moorestown platform detected, using MRST PCI ops\n");
25351 pci_mmcfg_late_init();
25352 pcibios_enable_irq = mrst_pci_irq_enable;
25353- pci_root_ops = pci_mrst_ops;
25354+ pax_open_kernel();
25355+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
25356+ pax_close_kernel();
25357 /* Continue with standard init */
25358 return 1;
25359 }
25360diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
25361index da8fe05..7ee6704 100644
25362--- a/arch/x86/pci/pcbios.c
25363+++ b/arch/x86/pci/pcbios.c
25364@@ -79,50 +79,93 @@ union bios32 {
25365 static struct {
25366 unsigned long address;
25367 unsigned short segment;
25368-} bios32_indirect = { 0, __KERNEL_CS };
25369+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
25370
25371 /*
25372 * Returns the entry point for the given service, NULL on error
25373 */
25374
25375-static unsigned long bios32_service(unsigned long service)
25376+static unsigned long __devinit bios32_service(unsigned long service)
25377 {
25378 unsigned char return_code; /* %al */
25379 unsigned long address; /* %ebx */
25380 unsigned long length; /* %ecx */
25381 unsigned long entry; /* %edx */
25382 unsigned long flags;
25383+ struct desc_struct d, *gdt;
25384
25385 local_irq_save(flags);
25386- __asm__("lcall *(%%edi); cld"
25387+
25388+ gdt = get_cpu_gdt_table(smp_processor_id());
25389+
25390+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
25391+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25392+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
25393+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25394+
25395+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
25396 : "=a" (return_code),
25397 "=b" (address),
25398 "=c" (length),
25399 "=d" (entry)
25400 : "0" (service),
25401 "1" (0),
25402- "D" (&bios32_indirect));
25403+ "D" (&bios32_indirect),
25404+ "r"(__PCIBIOS_DS)
25405+ : "memory");
25406+
25407+ pax_open_kernel();
25408+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
25409+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
25410+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
25411+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
25412+ pax_close_kernel();
25413+
25414 local_irq_restore(flags);
25415
25416 switch (return_code) {
25417- case 0:
25418- return address + entry;
25419- case 0x80: /* Not present */
25420- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
25421- return 0;
25422- default: /* Shouldn't happen */
25423- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
25424- service, return_code);
25425+ case 0: {
25426+ int cpu;
25427+ unsigned char flags;
25428+
25429+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
25430+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
25431+ printk(KERN_WARNING "bios32_service: not valid\n");
25432 return 0;
25433+ }
25434+ address = address + PAGE_OFFSET;
25435+ length += 16UL; /* some BIOSs underreport this... */
25436+ flags = 4;
25437+ if (length >= 64*1024*1024) {
25438+ length >>= PAGE_SHIFT;
25439+ flags |= 8;
25440+ }
25441+
25442+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
25443+ gdt = get_cpu_gdt_table(cpu);
25444+ pack_descriptor(&d, address, length, 0x9b, flags);
25445+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25446+ pack_descriptor(&d, address, length, 0x93, flags);
25447+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25448+ }
25449+ return entry;
25450+ }
25451+ case 0x80: /* Not present */
25452+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
25453+ return 0;
25454+ default: /* Shouldn't happen */
25455+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
25456+ service, return_code);
25457+ return 0;
25458 }
25459 }
25460
25461 static struct {
25462 unsigned long address;
25463 unsigned short segment;
25464-} pci_indirect = { 0, __KERNEL_CS };
25465+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
25466
25467-static int pci_bios_present;
25468+static int pci_bios_present __read_only;
25469
25470 static int __devinit check_pcibios(void)
25471 {
25472@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
25473 unsigned long flags, pcibios_entry;
25474
25475 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
25476- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
25477+ pci_indirect.address = pcibios_entry;
25478
25479 local_irq_save(flags);
25480- __asm__(
25481- "lcall *(%%edi); cld\n\t"
25482+ __asm__("movw %w6, %%ds\n\t"
25483+ "lcall *%%ss:(%%edi); cld\n\t"
25484+ "push %%ss\n\t"
25485+ "pop %%ds\n\t"
25486 "jc 1f\n\t"
25487 "xor %%ah, %%ah\n"
25488 "1:"
25489@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
25490 "=b" (ebx),
25491 "=c" (ecx)
25492 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
25493- "D" (&pci_indirect)
25494+ "D" (&pci_indirect),
25495+ "r" (__PCIBIOS_DS)
25496 : "memory");
25497 local_irq_restore(flags);
25498
25499@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25500
25501 switch (len) {
25502 case 1:
25503- __asm__("lcall *(%%esi); cld\n\t"
25504+ __asm__("movw %w6, %%ds\n\t"
25505+ "lcall *%%ss:(%%esi); cld\n\t"
25506+ "push %%ss\n\t"
25507+ "pop %%ds\n\t"
25508 "jc 1f\n\t"
25509 "xor %%ah, %%ah\n"
25510 "1:"
25511@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25512 : "1" (PCIBIOS_READ_CONFIG_BYTE),
25513 "b" (bx),
25514 "D" ((long)reg),
25515- "S" (&pci_indirect));
25516+ "S" (&pci_indirect),
25517+ "r" (__PCIBIOS_DS));
25518 /*
25519 * Zero-extend the result beyond 8 bits, do not trust the
25520 * BIOS having done it:
25521@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25522 *value &= 0xff;
25523 break;
25524 case 2:
25525- __asm__("lcall *(%%esi); cld\n\t"
25526+ __asm__("movw %w6, %%ds\n\t"
25527+ "lcall *%%ss:(%%esi); cld\n\t"
25528+ "push %%ss\n\t"
25529+ "pop %%ds\n\t"
25530 "jc 1f\n\t"
25531 "xor %%ah, %%ah\n"
25532 "1:"
25533@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25534 : "1" (PCIBIOS_READ_CONFIG_WORD),
25535 "b" (bx),
25536 "D" ((long)reg),
25537- "S" (&pci_indirect));
25538+ "S" (&pci_indirect),
25539+ "r" (__PCIBIOS_DS));
25540 /*
25541 * Zero-extend the result beyond 16 bits, do not trust the
25542 * BIOS having done it:
25543@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25544 *value &= 0xffff;
25545 break;
25546 case 4:
25547- __asm__("lcall *(%%esi); cld\n\t"
25548+ __asm__("movw %w6, %%ds\n\t"
25549+ "lcall *%%ss:(%%esi); cld\n\t"
25550+ "push %%ss\n\t"
25551+ "pop %%ds\n\t"
25552 "jc 1f\n\t"
25553 "xor %%ah, %%ah\n"
25554 "1:"
25555@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
25556 : "1" (PCIBIOS_READ_CONFIG_DWORD),
25557 "b" (bx),
25558 "D" ((long)reg),
25559- "S" (&pci_indirect));
25560+ "S" (&pci_indirect),
25561+ "r" (__PCIBIOS_DS));
25562 break;
25563 }
25564
25565@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
25566
25567 switch (len) {
25568 case 1:
25569- __asm__("lcall *(%%esi); cld\n\t"
25570+ __asm__("movw %w6, %%ds\n\t"
25571+ "lcall *%%ss:(%%esi); cld\n\t"
25572+ "push %%ss\n\t"
25573+ "pop %%ds\n\t"
25574 "jc 1f\n\t"
25575 "xor %%ah, %%ah\n"
25576 "1:"
25577@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
25578 "c" (value),
25579 "b" (bx),
25580 "D" ((long)reg),
25581- "S" (&pci_indirect));
25582+ "S" (&pci_indirect),
25583+ "r" (__PCIBIOS_DS));
25584 break;
25585 case 2:
25586- __asm__("lcall *(%%esi); cld\n\t"
25587+ __asm__("movw %w6, %%ds\n\t"
25588+ "lcall *%%ss:(%%esi); cld\n\t"
25589+ "push %%ss\n\t"
25590+ "pop %%ds\n\t"
25591 "jc 1f\n\t"
25592 "xor %%ah, %%ah\n"
25593 "1:"
25594@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
25595 "c" (value),
25596 "b" (bx),
25597 "D" ((long)reg),
25598- "S" (&pci_indirect));
25599+ "S" (&pci_indirect),
25600+ "r" (__PCIBIOS_DS));
25601 break;
25602 case 4:
25603- __asm__("lcall *(%%esi); cld\n\t"
25604+ __asm__("movw %w6, %%ds\n\t"
25605+ "lcall *%%ss:(%%esi); cld\n\t"
25606+ "push %%ss\n\t"
25607+ "pop %%ds\n\t"
25608 "jc 1f\n\t"
25609 "xor %%ah, %%ah\n"
25610 "1:"
25611@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
25612 "c" (value),
25613 "b" (bx),
25614 "D" ((long)reg),
25615- "S" (&pci_indirect));
25616+ "S" (&pci_indirect),
25617+ "r" (__PCIBIOS_DS));
25618 break;
25619 }
25620
25621@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
25622
25623 DBG("PCI: Fetching IRQ routing table... ");
25624 __asm__("push %%es\n\t"
25625+ "movw %w8, %%ds\n\t"
25626 "push %%ds\n\t"
25627 "pop %%es\n\t"
25628- "lcall *(%%esi); cld\n\t"
25629+ "lcall *%%ss:(%%esi); cld\n\t"
25630 "pop %%es\n\t"
25631+ "push %%ss\n\t"
25632+ "pop %%ds\n"
25633 "jc 1f\n\t"
25634 "xor %%ah, %%ah\n"
25635 "1:"
25636@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
25637 "1" (0),
25638 "D" ((long) &opt),
25639 "S" (&pci_indirect),
25640- "m" (opt)
25641+ "m" (opt),
25642+ "r" (__PCIBIOS_DS)
25643 : "memory");
25644 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
25645 if (ret & 0xff00)
25646@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
25647 {
25648 int ret;
25649
25650- __asm__("lcall *(%%esi); cld\n\t"
25651+ __asm__("movw %w5, %%ds\n\t"
25652+ "lcall *%%ss:(%%esi); cld\n\t"
25653+ "push %%ss\n\t"
25654+ "pop %%ds\n"
25655 "jc 1f\n\t"
25656 "xor %%ah, %%ah\n"
25657 "1:"
25658@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
25659 : "0" (PCIBIOS_SET_PCI_HW_INT),
25660 "b" ((dev->bus->number << 8) | dev->devfn),
25661 "c" ((irq << 8) | (pin + 10)),
25662- "S" (&pci_indirect));
25663+ "S" (&pci_indirect),
25664+ "r" (__PCIBIOS_DS));
25665 return !(ret & 0xff00);
25666 }
25667 EXPORT_SYMBOL(pcibios_set_irq_routing);
25668diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
25669index 40e4469..1ab536e 100644
25670--- a/arch/x86/platform/efi/efi_32.c
25671+++ b/arch/x86/platform/efi/efi_32.c
25672@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
25673 {
25674 struct desc_ptr gdt_descr;
25675
25676+#ifdef CONFIG_PAX_KERNEXEC
25677+ struct desc_struct d;
25678+#endif
25679+
25680 local_irq_save(efi_rt_eflags);
25681
25682 load_cr3(initial_page_table);
25683 __flush_tlb_all();
25684
25685+#ifdef CONFIG_PAX_KERNEXEC
25686+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
25687+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
25688+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
25689+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
25690+#endif
25691+
25692 gdt_descr.address = __pa(get_cpu_gdt_table(0));
25693 gdt_descr.size = GDT_SIZE - 1;
25694 load_gdt(&gdt_descr);
25695@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
25696 {
25697 struct desc_ptr gdt_descr;
25698
25699+#ifdef CONFIG_PAX_KERNEXEC
25700+ struct desc_struct d;
25701+
25702+ memset(&d, 0, sizeof d);
25703+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
25704+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
25705+#endif
25706+
25707 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
25708 gdt_descr.size = GDT_SIZE - 1;
25709 load_gdt(&gdt_descr);
25710diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
25711index fbe66e6..c5c0dd2 100644
25712--- a/arch/x86/platform/efi/efi_stub_32.S
25713+++ b/arch/x86/platform/efi/efi_stub_32.S
25714@@ -6,7 +6,9 @@
25715 */
25716
25717 #include <linux/linkage.h>
25718+#include <linux/init.h>
25719 #include <asm/page_types.h>
25720+#include <asm/segment.h>
25721
25722 /*
25723 * efi_call_phys(void *, ...) is a function with variable parameters.
25724@@ -20,7 +22,7 @@
25725 * service functions will comply with gcc calling convention, too.
25726 */
25727
25728-.text
25729+__INIT
25730 ENTRY(efi_call_phys)
25731 /*
25732 * 0. The function can only be called in Linux kernel. So CS has been
25733@@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
25734 * The mapping of lower virtual memory has been created in prelog and
25735 * epilog.
25736 */
25737- movl $1f, %edx
25738- subl $__PAGE_OFFSET, %edx
25739- jmp *%edx
25740+ movl $(__KERNEXEC_EFI_DS), %edx
25741+ mov %edx, %ds
25742+ mov %edx, %es
25743+ mov %edx, %ss
25744+ ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
25745 1:
25746
25747 /*
25748@@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
25749 * parameter 2, ..., param n. To make things easy, we save the return
25750 * address of efi_call_phys in a global variable.
25751 */
25752- popl %edx
25753- movl %edx, saved_return_addr
25754- /* get the function pointer into ECX*/
25755- popl %ecx
25756- movl %ecx, efi_rt_function_ptr
25757- movl $2f, %edx
25758- subl $__PAGE_OFFSET, %edx
25759- pushl %edx
25760+ popl (saved_return_addr)
25761+ popl (efi_rt_function_ptr)
25762
25763 /*
25764 * 3. Clear PG bit in %CR0.
25765@@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
25766 /*
25767 * 5. Call the physical function.
25768 */
25769- jmp *%ecx
25770+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
25771
25772-2:
25773 /*
25774 * 6. After EFI runtime service returns, control will return to
25775 * following instruction. We'd better readjust stack pointer first.
25776@@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
25777 movl %cr0, %edx
25778 orl $0x80000000, %edx
25779 movl %edx, %cr0
25780- jmp 1f
25781-1:
25782+
25783 /*
25784 * 8. Now restore the virtual mode from flat mode by
25785 * adding EIP with PAGE_OFFSET.
25786 */
25787- movl $1f, %edx
25788- jmp *%edx
25789+ ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
25790 1:
25791+ movl $(__KERNEL_DS), %edx
25792+ mov %edx, %ds
25793+ mov %edx, %es
25794+ mov %edx, %ss
25795
25796 /*
25797 * 9. Balance the stack. And because EAX contain the return value,
25798 * we'd better not clobber it.
25799 */
25800- leal efi_rt_function_ptr, %edx
25801- movl (%edx), %ecx
25802- pushl %ecx
25803+ pushl (efi_rt_function_ptr)
25804
25805 /*
25806- * 10. Push the saved return address onto the stack and return.
25807+ * 10. Return to the saved return address.
25808 */
25809- leal saved_return_addr, %edx
25810- movl (%edx), %ecx
25811- pushl %ecx
25812- ret
25813+ jmpl *(saved_return_addr)
25814 ENDPROC(efi_call_phys)
25815 .previous
25816
25817-.data
25818+__INITDATA
25819 saved_return_addr:
25820 .long 0
25821 efi_rt_function_ptr:
25822diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
25823index 4c07cca..2c8427d 100644
25824--- a/arch/x86/platform/efi/efi_stub_64.S
25825+++ b/arch/x86/platform/efi/efi_stub_64.S
25826@@ -7,6 +7,7 @@
25827 */
25828
25829 #include <linux/linkage.h>
25830+#include <asm/alternative-asm.h>
25831
25832 #define SAVE_XMM \
25833 mov %rsp, %rax; \
25834@@ -40,6 +41,7 @@ ENTRY(efi_call0)
25835 call *%rdi
25836 addq $32, %rsp
25837 RESTORE_XMM
25838+ pax_force_retaddr 0, 1
25839 ret
25840 ENDPROC(efi_call0)
25841
25842@@ -50,6 +52,7 @@ ENTRY(efi_call1)
25843 call *%rdi
25844 addq $32, %rsp
25845 RESTORE_XMM
25846+ pax_force_retaddr 0, 1
25847 ret
25848 ENDPROC(efi_call1)
25849
25850@@ -60,6 +63,7 @@ ENTRY(efi_call2)
25851 call *%rdi
25852 addq $32, %rsp
25853 RESTORE_XMM
25854+ pax_force_retaddr 0, 1
25855 ret
25856 ENDPROC(efi_call2)
25857
25858@@ -71,6 +75,7 @@ ENTRY(efi_call3)
25859 call *%rdi
25860 addq $32, %rsp
25861 RESTORE_XMM
25862+ pax_force_retaddr 0, 1
25863 ret
25864 ENDPROC(efi_call3)
25865
25866@@ -83,6 +88,7 @@ ENTRY(efi_call4)
25867 call *%rdi
25868 addq $32, %rsp
25869 RESTORE_XMM
25870+ pax_force_retaddr 0, 1
25871 ret
25872 ENDPROC(efi_call4)
25873
25874@@ -96,6 +102,7 @@ ENTRY(efi_call5)
25875 call *%rdi
25876 addq $48, %rsp
25877 RESTORE_XMM
25878+ pax_force_retaddr 0, 1
25879 ret
25880 ENDPROC(efi_call5)
25881
25882@@ -112,5 +119,6 @@ ENTRY(efi_call6)
25883 call *%rdi
25884 addq $48, %rsp
25885 RESTORE_XMM
25886+ pax_force_retaddr 0, 1
25887 ret
25888 ENDPROC(efi_call6)
25889diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
25890index 475e2cd..1b8e708 100644
25891--- a/arch/x86/platform/mrst/mrst.c
25892+++ b/arch/x86/platform/mrst/mrst.c
25893@@ -76,18 +76,20 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
25894 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
25895 int sfi_mrtc_num;
25896
25897-static void mrst_power_off(void)
25898+static __noreturn void mrst_power_off(void)
25899 {
25900 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
25901 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 1);
25902+ BUG();
25903 }
25904
25905-static void mrst_reboot(void)
25906+static __noreturn void mrst_reboot(void)
25907 {
25908 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
25909 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 0);
25910 else
25911 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
25912+ BUG();
25913 }
25914
25915 /* parse all the mtimer info to a static mtimer array */
25916diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
25917index f10c0af..3ec1f95 100644
25918--- a/arch/x86/power/cpu.c
25919+++ b/arch/x86/power/cpu.c
25920@@ -131,7 +131,7 @@ static void do_fpu_end(void)
25921 static void fix_processor_context(void)
25922 {
25923 int cpu = smp_processor_id();
25924- struct tss_struct *t = &per_cpu(init_tss, cpu);
25925+ struct tss_struct *t = init_tss + cpu;
25926
25927 set_tss_desc(cpu, t); /*
25928 * This just modifies memory; should not be
25929@@ -141,7 +141,9 @@ static void fix_processor_context(void)
25930 */
25931
25932 #ifdef CONFIG_X86_64
25933+ pax_open_kernel();
25934 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
25935+ pax_close_kernel();
25936
25937 syscall_init(); /* This sets MSR_*STAR and related */
25938 #endif
25939diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
25940index 5d17950..2253fc9 100644
25941--- a/arch/x86/vdso/Makefile
25942+++ b/arch/x86/vdso/Makefile
25943@@ -137,7 +137,7 @@ quiet_cmd_vdso = VDSO $@
25944 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
25945 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
25946
25947-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
25948+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
25949 GCOV_PROFILE := n
25950
25951 #
25952diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
25953index 468d591..8e80a0a 100644
25954--- a/arch/x86/vdso/vdso32-setup.c
25955+++ b/arch/x86/vdso/vdso32-setup.c
25956@@ -25,6 +25,7 @@
25957 #include <asm/tlbflush.h>
25958 #include <asm/vdso.h>
25959 #include <asm/proto.h>
25960+#include <asm/mman.h>
25961
25962 enum {
25963 VDSO_DISABLED = 0,
25964@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
25965 void enable_sep_cpu(void)
25966 {
25967 int cpu = get_cpu();
25968- struct tss_struct *tss = &per_cpu(init_tss, cpu);
25969+ struct tss_struct *tss = init_tss + cpu;
25970
25971 if (!boot_cpu_has(X86_FEATURE_SEP)) {
25972 put_cpu();
25973@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
25974 gate_vma.vm_start = FIXADDR_USER_START;
25975 gate_vma.vm_end = FIXADDR_USER_END;
25976 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
25977- gate_vma.vm_page_prot = __P101;
25978+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
25979 /*
25980 * Make sure the vDSO gets into every core dump.
25981 * Dumping its contents makes post-mortem fully interpretable later
25982@@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
25983 if (compat)
25984 addr = VDSO_HIGH_BASE;
25985 else {
25986- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
25987+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
25988 if (IS_ERR_VALUE(addr)) {
25989 ret = addr;
25990 goto up_fail;
25991 }
25992 }
25993
25994- current->mm->context.vdso = (void *)addr;
25995+ current->mm->context.vdso = addr;
25996
25997 if (compat_uses_vma || !compat) {
25998 /*
25999@@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26000 }
26001
26002 current_thread_info()->sysenter_return =
26003- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26004+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26005
26006 up_fail:
26007 if (ret)
26008- current->mm->context.vdso = NULL;
26009+ current->mm->context.vdso = 0;
26010
26011 up_write(&mm->mmap_sem);
26012
26013@@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
26014
26015 const char *arch_vma_name(struct vm_area_struct *vma)
26016 {
26017- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26018+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26019 return "[vdso]";
26020+
26021+#ifdef CONFIG_PAX_SEGMEXEC
26022+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26023+ return "[vdso]";
26024+#endif
26025+
26026 return NULL;
26027 }
26028
26029@@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26030 * Check to see if the corresponding task was created in compat vdso
26031 * mode.
26032 */
26033- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26034+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26035 return &gate_vma;
26036 return NULL;
26037 }
26038diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26039index 153407c..611cba9 100644
26040--- a/arch/x86/vdso/vma.c
26041+++ b/arch/x86/vdso/vma.c
26042@@ -16,8 +16,6 @@
26043 #include <asm/vdso.h>
26044 #include <asm/page.h>
26045
26046-unsigned int __read_mostly vdso_enabled = 1;
26047-
26048 extern char vdso_start[], vdso_end[];
26049 extern unsigned short vdso_sync_cpuid;
26050
26051@@ -96,7 +94,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26052 * unaligned here as a result of stack start randomization.
26053 */
26054 addr = PAGE_ALIGN(addr);
26055- addr = align_addr(addr, NULL, ALIGN_VDSO);
26056
26057 return addr;
26058 }
26059@@ -106,40 +103,35 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26060 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26061 {
26062 struct mm_struct *mm = current->mm;
26063- unsigned long addr;
26064+ unsigned long addr = 0;
26065 int ret;
26066
26067- if (!vdso_enabled)
26068- return 0;
26069-
26070 down_write(&mm->mmap_sem);
26071+
26072+#ifdef CONFIG_PAX_RANDMMAP
26073+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26074+#endif
26075+
26076 addr = vdso_addr(mm->start_stack, vdso_size);
26077+ addr = align_addr(addr, NULL, ALIGN_VDSO);
26078 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
26079 if (IS_ERR_VALUE(addr)) {
26080 ret = addr;
26081 goto up_fail;
26082 }
26083
26084- current->mm->context.vdso = (void *)addr;
26085+ mm->context.vdso = addr;
26086
26087 ret = install_special_mapping(mm, addr, vdso_size,
26088 VM_READ|VM_EXEC|
26089 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
26090 VM_ALWAYSDUMP,
26091 vdso_pages);
26092- if (ret) {
26093- current->mm->context.vdso = NULL;
26094- goto up_fail;
26095- }
26096+
26097+ if (ret)
26098+ mm->context.vdso = 0;
26099
26100 up_fail:
26101 up_write(&mm->mmap_sem);
26102 return ret;
26103 }
26104-
26105-static __init int vdso_setup(char *s)
26106-{
26107- vdso_enabled = simple_strtoul(s, NULL, 0);
26108- return 0;
26109-}
26110-__setup("vdso=", vdso_setup);
26111diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
26112index 4172af8..2c8ed7f 100644
26113--- a/arch/x86/xen/enlighten.c
26114+++ b/arch/x86/xen/enlighten.c
26115@@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
26116
26117 struct shared_info xen_dummy_shared_info;
26118
26119-void *xen_initial_gdt;
26120-
26121 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
26122 __read_mostly int xen_have_vector_callback;
26123 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
26124@@ -1029,30 +1027,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
26125 #endif
26126 };
26127
26128-static void xen_reboot(int reason)
26129+static __noreturn void xen_reboot(int reason)
26130 {
26131 struct sched_shutdown r = { .reason = reason };
26132
26133- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
26134- BUG();
26135+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
26136+ BUG();
26137 }
26138
26139-static void xen_restart(char *msg)
26140+static __noreturn void xen_restart(char *msg)
26141 {
26142 xen_reboot(SHUTDOWN_reboot);
26143 }
26144
26145-static void xen_emergency_restart(void)
26146+static __noreturn void xen_emergency_restart(void)
26147 {
26148 xen_reboot(SHUTDOWN_reboot);
26149 }
26150
26151-static void xen_machine_halt(void)
26152+static __noreturn void xen_machine_halt(void)
26153 {
26154 xen_reboot(SHUTDOWN_poweroff);
26155 }
26156
26157-static void xen_machine_power_off(void)
26158+static __noreturn void xen_machine_power_off(void)
26159 {
26160 if (pm_power_off)
26161 pm_power_off();
26162@@ -1155,7 +1153,17 @@ asmlinkage void __init xen_start_kernel(void)
26163 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
26164
26165 /* Work out if we support NX */
26166- x86_configure_nx();
26167+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26168+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
26169+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
26170+ unsigned l, h;
26171+
26172+ __supported_pte_mask |= _PAGE_NX;
26173+ rdmsr(MSR_EFER, l, h);
26174+ l |= EFER_NX;
26175+ wrmsr(MSR_EFER, l, h);
26176+ }
26177+#endif
26178
26179 xen_setup_features();
26180
26181@@ -1186,13 +1194,6 @@ asmlinkage void __init xen_start_kernel(void)
26182
26183 machine_ops = xen_machine_ops;
26184
26185- /*
26186- * The only reliable way to retain the initial address of the
26187- * percpu gdt_page is to remember it here, so we can go and
26188- * mark it RW later, when the initial percpu area is freed.
26189- */
26190- xen_initial_gdt = &per_cpu(gdt_page, 0);
26191-
26192 xen_smp_init();
26193
26194 #ifdef CONFIG_ACPI_NUMA
26195diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
26196index 95c1cf6..4bfa5be 100644
26197--- a/arch/x86/xen/mmu.c
26198+++ b/arch/x86/xen/mmu.c
26199@@ -1733,6 +1733,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
26200 convert_pfn_mfn(init_level4_pgt);
26201 convert_pfn_mfn(level3_ident_pgt);
26202 convert_pfn_mfn(level3_kernel_pgt);
26203+ convert_pfn_mfn(level3_vmalloc_start_pgt);
26204+ convert_pfn_mfn(level3_vmalloc_end_pgt);
26205+ convert_pfn_mfn(level3_vmemmap_pgt);
26206
26207 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
26208 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
26209@@ -1751,7 +1754,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
26210 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
26211 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
26212 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
26213+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
26214+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
26215+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
26216 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
26217+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
26218 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
26219 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
26220
26221@@ -1958,6 +1965,7 @@ static void __init xen_post_allocator_init(void)
26222 pv_mmu_ops.set_pud = xen_set_pud;
26223 #if PAGETABLE_LEVELS == 4
26224 pv_mmu_ops.set_pgd = xen_set_pgd;
26225+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
26226 #endif
26227
26228 /* This will work as long as patching hasn't happened yet
26229@@ -2039,6 +2047,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
26230 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
26231 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
26232 .set_pgd = xen_set_pgd_hyper,
26233+ .set_pgd_batched = xen_set_pgd_hyper,
26234
26235 .alloc_pud = xen_alloc_pmd_init,
26236 .release_pud = xen_release_pmd_init,
26237diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
26238index 501d4e0..e877605 100644
26239--- a/arch/x86/xen/smp.c
26240+++ b/arch/x86/xen/smp.c
26241@@ -194,11 +194,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
26242 {
26243 BUG_ON(smp_processor_id() != 0);
26244 native_smp_prepare_boot_cpu();
26245-
26246- /* We've switched to the "real" per-cpu gdt, so make sure the
26247- old memory can be recycled */
26248- make_lowmem_page_readwrite(xen_initial_gdt);
26249-
26250 xen_filter_cpu_maps();
26251 xen_setup_vcpu_info_placement();
26252 }
26253@@ -275,12 +270,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
26254 gdt = get_cpu_gdt_table(cpu);
26255
26256 ctxt->flags = VGCF_IN_KERNEL;
26257- ctxt->user_regs.ds = __USER_DS;
26258- ctxt->user_regs.es = __USER_DS;
26259+ ctxt->user_regs.ds = __KERNEL_DS;
26260+ ctxt->user_regs.es = __KERNEL_DS;
26261 ctxt->user_regs.ss = __KERNEL_DS;
26262 #ifdef CONFIG_X86_32
26263 ctxt->user_regs.fs = __KERNEL_PERCPU;
26264- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
26265+ savesegment(gs, ctxt->user_regs.gs);
26266 #else
26267 ctxt->gs_base_kernel = per_cpu_offset(cpu);
26268 #endif
26269@@ -331,13 +326,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
26270 int rc;
26271
26272 per_cpu(current_task, cpu) = idle;
26273+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
26274 #ifdef CONFIG_X86_32
26275 irq_ctx_init(cpu);
26276 #else
26277 clear_tsk_thread_flag(idle, TIF_FORK);
26278- per_cpu(kernel_stack, cpu) =
26279- (unsigned long)task_stack_page(idle) -
26280- KERNEL_STACK_OFFSET + THREAD_SIZE;
26281+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26282 #endif
26283 xen_setup_runstate_info(cpu);
26284 xen_setup_timer(cpu);
26285diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
26286index b040b0e..8cc4fe0 100644
26287--- a/arch/x86/xen/xen-asm_32.S
26288+++ b/arch/x86/xen/xen-asm_32.S
26289@@ -83,14 +83,14 @@ ENTRY(xen_iret)
26290 ESP_OFFSET=4 # bytes pushed onto stack
26291
26292 /*
26293- * Store vcpu_info pointer for easy access. Do it this way to
26294- * avoid having to reload %fs
26295+ * Store vcpu_info pointer for easy access.
26296 */
26297 #ifdef CONFIG_SMP
26298- GET_THREAD_INFO(%eax)
26299- movl TI_cpu(%eax), %eax
26300- movl __per_cpu_offset(,%eax,4), %eax
26301- mov xen_vcpu(%eax), %eax
26302+ push %fs
26303+ mov $(__KERNEL_PERCPU), %eax
26304+ mov %eax, %fs
26305+ mov PER_CPU_VAR(xen_vcpu), %eax
26306+ pop %fs
26307 #else
26308 movl xen_vcpu, %eax
26309 #endif
26310diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
26311index aaa7291..3f77960 100644
26312--- a/arch/x86/xen/xen-head.S
26313+++ b/arch/x86/xen/xen-head.S
26314@@ -19,6 +19,17 @@ ENTRY(startup_xen)
26315 #ifdef CONFIG_X86_32
26316 mov %esi,xen_start_info
26317 mov $init_thread_union+THREAD_SIZE,%esp
26318+#ifdef CONFIG_SMP
26319+ movl $cpu_gdt_table,%edi
26320+ movl $__per_cpu_load,%eax
26321+ movw %ax,__KERNEL_PERCPU + 2(%edi)
26322+ rorl $16,%eax
26323+ movb %al,__KERNEL_PERCPU + 4(%edi)
26324+ movb %ah,__KERNEL_PERCPU + 7(%edi)
26325+ movl $__per_cpu_end - 1,%eax
26326+ subl $__per_cpu_start,%eax
26327+ movw %ax,__KERNEL_PERCPU + 0(%edi)
26328+#endif
26329 #else
26330 mov %rsi,xen_start_info
26331 mov $init_thread_union+THREAD_SIZE,%rsp
26332diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
26333index b095739..8c17bcd 100644
26334--- a/arch/x86/xen/xen-ops.h
26335+++ b/arch/x86/xen/xen-ops.h
26336@@ -10,8 +10,6 @@
26337 extern const char xen_hypervisor_callback[];
26338 extern const char xen_failsafe_callback[];
26339
26340-extern void *xen_initial_gdt;
26341-
26342 struct trap_info;
26343 void xen_copy_trap_info(struct trap_info *traps);
26344
26345diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
26346index 525bd3d..ef888b1 100644
26347--- a/arch/xtensa/variants/dc232b/include/variant/core.h
26348+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
26349@@ -119,9 +119,9 @@
26350 ----------------------------------------------------------------------*/
26351
26352 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
26353-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
26354 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
26355 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
26356+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26357
26358 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
26359 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
26360diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
26361index 2f33760..835e50a 100644
26362--- a/arch/xtensa/variants/fsf/include/variant/core.h
26363+++ b/arch/xtensa/variants/fsf/include/variant/core.h
26364@@ -11,6 +11,7 @@
26365 #ifndef _XTENSA_CORE_H
26366 #define _XTENSA_CORE_H
26367
26368+#include <linux/const.h>
26369
26370 /****************************************************************************
26371 Parameters Useful for Any Code, USER or PRIVILEGED
26372@@ -112,9 +113,9 @@
26373 ----------------------------------------------------------------------*/
26374
26375 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
26376-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
26377 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
26378 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
26379+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26380
26381 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
26382 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
26383diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
26384index af00795..2bb8105 100644
26385--- a/arch/xtensa/variants/s6000/include/variant/core.h
26386+++ b/arch/xtensa/variants/s6000/include/variant/core.h
26387@@ -11,6 +11,7 @@
26388 #ifndef _XTENSA_CORE_CONFIGURATION_H
26389 #define _XTENSA_CORE_CONFIGURATION_H
26390
26391+#include <linux/const.h>
26392
26393 /****************************************************************************
26394 Parameters Useful for Any Code, USER or PRIVILEGED
26395@@ -118,9 +119,9 @@
26396 ----------------------------------------------------------------------*/
26397
26398 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
26399-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
26400 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
26401 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
26402+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
26403
26404 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
26405 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
26406diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
26407index 58916af..9cb880b 100644
26408--- a/block/blk-iopoll.c
26409+++ b/block/blk-iopoll.c
26410@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
26411 }
26412 EXPORT_SYMBOL(blk_iopoll_complete);
26413
26414-static void blk_iopoll_softirq(struct softirq_action *h)
26415+static void blk_iopoll_softirq(void)
26416 {
26417 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
26418 int rearm = 0, budget = blk_iopoll_budget;
26419diff --git a/block/blk-map.c b/block/blk-map.c
26420index 623e1cd..ca1e109 100644
26421--- a/block/blk-map.c
26422+++ b/block/blk-map.c
26423@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
26424 if (!len || !kbuf)
26425 return -EINVAL;
26426
26427- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
26428+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
26429 if (do_copy)
26430 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
26431 else
26432diff --git a/block/blk-softirq.c b/block/blk-softirq.c
26433index 1366a89..e17f54b 100644
26434--- a/block/blk-softirq.c
26435+++ b/block/blk-softirq.c
26436@@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
26437 * Softirq action handler - move entries to local list and loop over them
26438 * while passing them to the queue registered handler.
26439 */
26440-static void blk_done_softirq(struct softirq_action *h)
26441+static void blk_done_softirq(void)
26442 {
26443 struct list_head *cpu_list, local_list;
26444
26445diff --git a/block/bsg.c b/block/bsg.c
26446index ff64ae3..593560c 100644
26447--- a/block/bsg.c
26448+++ b/block/bsg.c
26449@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
26450 struct sg_io_v4 *hdr, struct bsg_device *bd,
26451 fmode_t has_write_perm)
26452 {
26453+ unsigned char tmpcmd[sizeof(rq->__cmd)];
26454+ unsigned char *cmdptr;
26455+
26456 if (hdr->request_len > BLK_MAX_CDB) {
26457 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
26458 if (!rq->cmd)
26459 return -ENOMEM;
26460- }
26461+ cmdptr = rq->cmd;
26462+ } else
26463+ cmdptr = tmpcmd;
26464
26465- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
26466+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
26467 hdr->request_len))
26468 return -EFAULT;
26469
26470+ if (cmdptr != rq->cmd)
26471+ memcpy(rq->cmd, cmdptr, hdr->request_len);
26472+
26473 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
26474 if (blk_verify_command(rq->cmd, has_write_perm))
26475 return -EPERM;
26476diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
26477index 7c668c8..db3521c 100644
26478--- a/block/compat_ioctl.c
26479+++ b/block/compat_ioctl.c
26480@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
26481 err |= __get_user(f->spec1, &uf->spec1);
26482 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
26483 err |= __get_user(name, &uf->name);
26484- f->name = compat_ptr(name);
26485+ f->name = (void __force_kernel *)compat_ptr(name);
26486 if (err) {
26487 err = -EFAULT;
26488 goto out;
26489diff --git a/block/partitions/efi.c b/block/partitions/efi.c
26490index 6296b40..417c00f 100644
26491--- a/block/partitions/efi.c
26492+++ b/block/partitions/efi.c
26493@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
26494 if (!gpt)
26495 return NULL;
26496
26497+ if (!le32_to_cpu(gpt->num_partition_entries))
26498+ return NULL;
26499+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
26500+ if (!pte)
26501+ return NULL;
26502+
26503 count = le32_to_cpu(gpt->num_partition_entries) *
26504 le32_to_cpu(gpt->sizeof_partition_entry);
26505- if (!count)
26506- return NULL;
26507- pte = kzalloc(count, GFP_KERNEL);
26508- if (!pte)
26509- return NULL;
26510-
26511 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
26512 (u8 *) pte,
26513 count) < count) {
26514diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
26515index 260fa80..e8f3caf 100644
26516--- a/block/scsi_ioctl.c
26517+++ b/block/scsi_ioctl.c
26518@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
26519 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
26520 struct sg_io_hdr *hdr, fmode_t mode)
26521 {
26522- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
26523+ unsigned char tmpcmd[sizeof(rq->__cmd)];
26524+ unsigned char *cmdptr;
26525+
26526+ if (rq->cmd != rq->__cmd)
26527+ cmdptr = rq->cmd;
26528+ else
26529+ cmdptr = tmpcmd;
26530+
26531+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
26532 return -EFAULT;
26533+
26534+ if (cmdptr != rq->cmd)
26535+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
26536+
26537 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
26538 return -EPERM;
26539
26540@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
26541 int err;
26542 unsigned int in_len, out_len, bytes, opcode, cmdlen;
26543 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
26544+ unsigned char tmpcmd[sizeof(rq->__cmd)];
26545+ unsigned char *cmdptr;
26546
26547 if (!sic)
26548 return -EINVAL;
26549@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
26550 */
26551 err = -EFAULT;
26552 rq->cmd_len = cmdlen;
26553- if (copy_from_user(rq->cmd, sic->data, cmdlen))
26554+
26555+ if (rq->cmd != rq->__cmd)
26556+ cmdptr = rq->cmd;
26557+ else
26558+ cmdptr = tmpcmd;
26559+
26560+ if (copy_from_user(cmdptr, sic->data, cmdlen))
26561 goto error;
26562
26563+ if (rq->cmd != cmdptr)
26564+ memcpy(rq->cmd, cmdptr, cmdlen);
26565+
26566 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
26567 goto error;
26568
26569diff --git a/crypto/cryptd.c b/crypto/cryptd.c
26570index 671d4d6..5f24030 100644
26571--- a/crypto/cryptd.c
26572+++ b/crypto/cryptd.c
26573@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
26574
26575 struct cryptd_blkcipher_request_ctx {
26576 crypto_completion_t complete;
26577-};
26578+} __no_const;
26579
26580 struct cryptd_hash_ctx {
26581 struct crypto_shash *child;
26582@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
26583
26584 struct cryptd_aead_request_ctx {
26585 crypto_completion_t complete;
26586-};
26587+} __no_const;
26588
26589 static void cryptd_queue_worker(struct work_struct *work);
26590
26591diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
26592index 5d41894..22021e4 100644
26593--- a/drivers/acpi/apei/cper.c
26594+++ b/drivers/acpi/apei/cper.c
26595@@ -38,12 +38,12 @@
26596 */
26597 u64 cper_next_record_id(void)
26598 {
26599- static atomic64_t seq;
26600+ static atomic64_unchecked_t seq;
26601
26602- if (!atomic64_read(&seq))
26603- atomic64_set(&seq, ((u64)get_seconds()) << 32);
26604+ if (!atomic64_read_unchecked(&seq))
26605+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
26606
26607- return atomic64_inc_return(&seq);
26608+ return atomic64_inc_return_unchecked(&seq);
26609 }
26610 EXPORT_SYMBOL_GPL(cper_next_record_id);
26611
26612diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
26613index b258cab..3fb7da7 100644
26614--- a/drivers/acpi/ec_sys.c
26615+++ b/drivers/acpi/ec_sys.c
26616@@ -12,6 +12,7 @@
26617 #include <linux/acpi.h>
26618 #include <linux/debugfs.h>
26619 #include <linux/module.h>
26620+#include <linux/uaccess.h>
26621 #include "internal.h"
26622
26623 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
26624@@ -40,7 +41,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
26625 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
26626 */
26627 unsigned int size = EC_SPACE_SIZE;
26628- u8 *data = (u8 *) buf;
26629+ u8 data;
26630 loff_t init_off = *off;
26631 int err = 0;
26632
26633@@ -53,9 +54,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
26634 size = count;
26635
26636 while (size) {
26637- err = ec_read(*off, &data[*off - init_off]);
26638+ err = ec_read(*off, &data);
26639 if (err)
26640 return err;
26641+ if (put_user(data, &buf[*off - init_off]))
26642+ return -EFAULT;
26643 *off += 1;
26644 size--;
26645 }
26646@@ -71,7 +74,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
26647
26648 unsigned int size = count;
26649 loff_t init_off = *off;
26650- u8 *data = (u8 *) buf;
26651 int err = 0;
26652
26653 if (*off >= EC_SPACE_SIZE)
26654@@ -82,7 +84,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
26655 }
26656
26657 while (size) {
26658- u8 byte_write = data[*off - init_off];
26659+ u8 byte_write;
26660+ if (get_user(byte_write, &buf[*off - init_off]))
26661+ return -EFAULT;
26662 err = ec_write(*off, byte_write);
26663 if (err)
26664 return err;
26665diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
26666index 251c7b62..000462d 100644
26667--- a/drivers/acpi/proc.c
26668+++ b/drivers/acpi/proc.c
26669@@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
26670 size_t count, loff_t * ppos)
26671 {
26672 struct list_head *node, *next;
26673- char strbuf[5];
26674- char str[5] = "";
26675- unsigned int len = count;
26676+ char strbuf[5] = {0};
26677
26678- if (len > 4)
26679- len = 4;
26680- if (len < 0)
26681+ if (count > 4)
26682+ count = 4;
26683+ if (copy_from_user(strbuf, buffer, count))
26684 return -EFAULT;
26685-
26686- if (copy_from_user(strbuf, buffer, len))
26687- return -EFAULT;
26688- strbuf[len] = '\0';
26689- sscanf(strbuf, "%s", str);
26690+ strbuf[count] = '\0';
26691
26692 mutex_lock(&acpi_device_lock);
26693 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
26694@@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
26695 if (!dev->wakeup.flags.valid)
26696 continue;
26697
26698- if (!strncmp(dev->pnp.bus_id, str, 4)) {
26699+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
26700 if (device_can_wakeup(&dev->dev)) {
26701 bool enable = !device_may_wakeup(&dev->dev);
26702 device_set_wakeup_enable(&dev->dev, enable);
26703diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
26704index 8ae05ce..7dbbed9 100644
26705--- a/drivers/acpi/processor_driver.c
26706+++ b/drivers/acpi/processor_driver.c
26707@@ -555,7 +555,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
26708 return 0;
26709 #endif
26710
26711- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
26712+ BUG_ON(pr->id >= nr_cpu_ids);
26713
26714 /*
26715 * Buggy BIOS check
26716diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
26717index c06e0ec..a2c06ba 100644
26718--- a/drivers/ata/libata-core.c
26719+++ b/drivers/ata/libata-core.c
26720@@ -4736,7 +4736,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
26721 struct ata_port *ap;
26722 unsigned int tag;
26723
26724- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
26725+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
26726 ap = qc->ap;
26727
26728 qc->flags = 0;
26729@@ -4752,7 +4752,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
26730 struct ata_port *ap;
26731 struct ata_link *link;
26732
26733- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
26734+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
26735 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
26736 ap = qc->ap;
26737 link = qc->dev->link;
26738@@ -5816,6 +5816,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
26739 return;
26740
26741 spin_lock(&lock);
26742+ pax_open_kernel();
26743
26744 for (cur = ops->inherits; cur; cur = cur->inherits) {
26745 void **inherit = (void **)cur;
26746@@ -5829,8 +5830,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
26747 if (IS_ERR(*pp))
26748 *pp = NULL;
26749
26750- ops->inherits = NULL;
26751+ *(struct ata_port_operations **)&ops->inherits = NULL;
26752
26753+ pax_close_kernel();
26754 spin_unlock(&lock);
26755 }
26756
26757diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
26758index 048589f..4002b98 100644
26759--- a/drivers/ata/pata_arasan_cf.c
26760+++ b/drivers/ata/pata_arasan_cf.c
26761@@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
26762 /* Handle platform specific quirks */
26763 if (pdata->quirk) {
26764 if (pdata->quirk & CF_BROKEN_PIO) {
26765- ap->ops->set_piomode = NULL;
26766+ pax_open_kernel();
26767+ *(void **)&ap->ops->set_piomode = NULL;
26768+ pax_close_kernel();
26769 ap->pio_mask = 0;
26770 }
26771 if (pdata->quirk & CF_BROKEN_MWDMA)
26772diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
26773index f9b983a..887b9d8 100644
26774--- a/drivers/atm/adummy.c
26775+++ b/drivers/atm/adummy.c
26776@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
26777 vcc->pop(vcc, skb);
26778 else
26779 dev_kfree_skb_any(skb);
26780- atomic_inc(&vcc->stats->tx);
26781+ atomic_inc_unchecked(&vcc->stats->tx);
26782
26783 return 0;
26784 }
26785diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
26786index f8f41e0..1f987dd 100644
26787--- a/drivers/atm/ambassador.c
26788+++ b/drivers/atm/ambassador.c
26789@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
26790 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
26791
26792 // VC layer stats
26793- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26794+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26795
26796 // free the descriptor
26797 kfree (tx_descr);
26798@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
26799 dump_skb ("<<<", vc, skb);
26800
26801 // VC layer stats
26802- atomic_inc(&atm_vcc->stats->rx);
26803+ atomic_inc_unchecked(&atm_vcc->stats->rx);
26804 __net_timestamp(skb);
26805 // end of our responsibility
26806 atm_vcc->push (atm_vcc, skb);
26807@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
26808 } else {
26809 PRINTK (KERN_INFO, "dropped over-size frame");
26810 // should we count this?
26811- atomic_inc(&atm_vcc->stats->rx_drop);
26812+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26813 }
26814
26815 } else {
26816@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
26817 }
26818
26819 if (check_area (skb->data, skb->len)) {
26820- atomic_inc(&atm_vcc->stats->tx_err);
26821+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
26822 return -ENOMEM; // ?
26823 }
26824
26825diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
26826index b22d71c..d6e1049 100644
26827--- a/drivers/atm/atmtcp.c
26828+++ b/drivers/atm/atmtcp.c
26829@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
26830 if (vcc->pop) vcc->pop(vcc,skb);
26831 else dev_kfree_skb(skb);
26832 if (dev_data) return 0;
26833- atomic_inc(&vcc->stats->tx_err);
26834+ atomic_inc_unchecked(&vcc->stats->tx_err);
26835 return -ENOLINK;
26836 }
26837 size = skb->len+sizeof(struct atmtcp_hdr);
26838@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
26839 if (!new_skb) {
26840 if (vcc->pop) vcc->pop(vcc,skb);
26841 else dev_kfree_skb(skb);
26842- atomic_inc(&vcc->stats->tx_err);
26843+ atomic_inc_unchecked(&vcc->stats->tx_err);
26844 return -ENOBUFS;
26845 }
26846 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
26847@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
26848 if (vcc->pop) vcc->pop(vcc,skb);
26849 else dev_kfree_skb(skb);
26850 out_vcc->push(out_vcc,new_skb);
26851- atomic_inc(&vcc->stats->tx);
26852- atomic_inc(&out_vcc->stats->rx);
26853+ atomic_inc_unchecked(&vcc->stats->tx);
26854+ atomic_inc_unchecked(&out_vcc->stats->rx);
26855 return 0;
26856 }
26857
26858@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
26859 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
26860 read_unlock(&vcc_sklist_lock);
26861 if (!out_vcc) {
26862- atomic_inc(&vcc->stats->tx_err);
26863+ atomic_inc_unchecked(&vcc->stats->tx_err);
26864 goto done;
26865 }
26866 skb_pull(skb,sizeof(struct atmtcp_hdr));
26867@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
26868 __net_timestamp(new_skb);
26869 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
26870 out_vcc->push(out_vcc,new_skb);
26871- atomic_inc(&vcc->stats->tx);
26872- atomic_inc(&out_vcc->stats->rx);
26873+ atomic_inc_unchecked(&vcc->stats->tx);
26874+ atomic_inc_unchecked(&out_vcc->stats->rx);
26875 done:
26876 if (vcc->pop) vcc->pop(vcc,skb);
26877 else dev_kfree_skb(skb);
26878diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
26879index 956e9ac..133516d 100644
26880--- a/drivers/atm/eni.c
26881+++ b/drivers/atm/eni.c
26882@@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
26883 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
26884 vcc->dev->number);
26885 length = 0;
26886- atomic_inc(&vcc->stats->rx_err);
26887+ atomic_inc_unchecked(&vcc->stats->rx_err);
26888 }
26889 else {
26890 length = ATM_CELL_SIZE-1; /* no HEC */
26891@@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26892 size);
26893 }
26894 eff = length = 0;
26895- atomic_inc(&vcc->stats->rx_err);
26896+ atomic_inc_unchecked(&vcc->stats->rx_err);
26897 }
26898 else {
26899 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
26900@@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26901 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
26902 vcc->dev->number,vcc->vci,length,size << 2,descr);
26903 length = eff = 0;
26904- atomic_inc(&vcc->stats->rx_err);
26905+ atomic_inc_unchecked(&vcc->stats->rx_err);
26906 }
26907 }
26908 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
26909@@ -771,7 +771,7 @@ rx_dequeued++;
26910 vcc->push(vcc,skb);
26911 pushed++;
26912 }
26913- atomic_inc(&vcc->stats->rx);
26914+ atomic_inc_unchecked(&vcc->stats->rx);
26915 }
26916 wake_up(&eni_dev->rx_wait);
26917 }
26918@@ -1229,7 +1229,7 @@ static void dequeue_tx(struct atm_dev *dev)
26919 PCI_DMA_TODEVICE);
26920 if (vcc->pop) vcc->pop(vcc,skb);
26921 else dev_kfree_skb_irq(skb);
26922- atomic_inc(&vcc->stats->tx);
26923+ atomic_inc_unchecked(&vcc->stats->tx);
26924 wake_up(&eni_dev->tx_wait);
26925 dma_complete++;
26926 }
26927@@ -1569,7 +1569,7 @@ tx_complete++;
26928 /*--------------------------------- entries ---------------------------------*/
26929
26930
26931-static const char *media_name[] __devinitdata = {
26932+static const char *media_name[] __devinitconst = {
26933 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
26934 "UTP", "05?", "06?", "07?", /* 4- 7 */
26935 "TAXI","09?", "10?", "11?", /* 8-11 */
26936diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
26937index 5072f8a..fa52520d 100644
26938--- a/drivers/atm/firestream.c
26939+++ b/drivers/atm/firestream.c
26940@@ -750,7 +750,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
26941 }
26942 }
26943
26944- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26945+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26946
26947 fs_dprintk (FS_DEBUG_TXMEM, "i");
26948 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
26949@@ -817,7 +817,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
26950 #endif
26951 skb_put (skb, qe->p1 & 0xffff);
26952 ATM_SKB(skb)->vcc = atm_vcc;
26953- atomic_inc(&atm_vcc->stats->rx);
26954+ atomic_inc_unchecked(&atm_vcc->stats->rx);
26955 __net_timestamp(skb);
26956 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
26957 atm_vcc->push (atm_vcc, skb);
26958@@ -838,12 +838,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
26959 kfree (pe);
26960 }
26961 if (atm_vcc)
26962- atomic_inc(&atm_vcc->stats->rx_drop);
26963+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26964 break;
26965 case 0x1f: /* Reassembly abort: no buffers. */
26966 /* Silently increment error counter. */
26967 if (atm_vcc)
26968- atomic_inc(&atm_vcc->stats->rx_drop);
26969+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26970 break;
26971 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
26972 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
26973diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
26974index 361f5ae..7fc552d 100644
26975--- a/drivers/atm/fore200e.c
26976+++ b/drivers/atm/fore200e.c
26977@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
26978 #endif
26979 /* check error condition */
26980 if (*entry->status & STATUS_ERROR)
26981- atomic_inc(&vcc->stats->tx_err);
26982+ atomic_inc_unchecked(&vcc->stats->tx_err);
26983 else
26984- atomic_inc(&vcc->stats->tx);
26985+ atomic_inc_unchecked(&vcc->stats->tx);
26986 }
26987 }
26988
26989@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
26990 if (skb == NULL) {
26991 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
26992
26993- atomic_inc(&vcc->stats->rx_drop);
26994+ atomic_inc_unchecked(&vcc->stats->rx_drop);
26995 return -ENOMEM;
26996 }
26997
26998@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
26999
27000 dev_kfree_skb_any(skb);
27001
27002- atomic_inc(&vcc->stats->rx_drop);
27003+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27004 return -ENOMEM;
27005 }
27006
27007 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27008
27009 vcc->push(vcc, skb);
27010- atomic_inc(&vcc->stats->rx);
27011+ atomic_inc_unchecked(&vcc->stats->rx);
27012
27013 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27014
27015@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
27016 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27017 fore200e->atm_dev->number,
27018 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27019- atomic_inc(&vcc->stats->rx_err);
27020+ atomic_inc_unchecked(&vcc->stats->rx_err);
27021 }
27022 }
27023
27024@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
27025 goto retry_here;
27026 }
27027
27028- atomic_inc(&vcc->stats->tx_err);
27029+ atomic_inc_unchecked(&vcc->stats->tx_err);
27030
27031 fore200e->tx_sat++;
27032 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
27033diff --git a/drivers/atm/he.c b/drivers/atm/he.c
27034index b182c2f..1c6fa8a 100644
27035--- a/drivers/atm/he.c
27036+++ b/drivers/atm/he.c
27037@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27038
27039 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
27040 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
27041- atomic_inc(&vcc->stats->rx_drop);
27042+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27043 goto return_host_buffers;
27044 }
27045
27046@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27047 RBRQ_LEN_ERR(he_dev->rbrq_head)
27048 ? "LEN_ERR" : "",
27049 vcc->vpi, vcc->vci);
27050- atomic_inc(&vcc->stats->rx_err);
27051+ atomic_inc_unchecked(&vcc->stats->rx_err);
27052 goto return_host_buffers;
27053 }
27054
27055@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27056 vcc->push(vcc, skb);
27057 spin_lock(&he_dev->global_lock);
27058
27059- atomic_inc(&vcc->stats->rx);
27060+ atomic_inc_unchecked(&vcc->stats->rx);
27061
27062 return_host_buffers:
27063 ++pdus_assembled;
27064@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
27065 tpd->vcc->pop(tpd->vcc, tpd->skb);
27066 else
27067 dev_kfree_skb_any(tpd->skb);
27068- atomic_inc(&tpd->vcc->stats->tx_err);
27069+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
27070 }
27071 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
27072 return;
27073@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27074 vcc->pop(vcc, skb);
27075 else
27076 dev_kfree_skb_any(skb);
27077- atomic_inc(&vcc->stats->tx_err);
27078+ atomic_inc_unchecked(&vcc->stats->tx_err);
27079 return -EINVAL;
27080 }
27081
27082@@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27083 vcc->pop(vcc, skb);
27084 else
27085 dev_kfree_skb_any(skb);
27086- atomic_inc(&vcc->stats->tx_err);
27087+ atomic_inc_unchecked(&vcc->stats->tx_err);
27088 return -EINVAL;
27089 }
27090 #endif
27091@@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27092 vcc->pop(vcc, skb);
27093 else
27094 dev_kfree_skb_any(skb);
27095- atomic_inc(&vcc->stats->tx_err);
27096+ atomic_inc_unchecked(&vcc->stats->tx_err);
27097 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27098 return -ENOMEM;
27099 }
27100@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27101 vcc->pop(vcc, skb);
27102 else
27103 dev_kfree_skb_any(skb);
27104- atomic_inc(&vcc->stats->tx_err);
27105+ atomic_inc_unchecked(&vcc->stats->tx_err);
27106 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27107 return -ENOMEM;
27108 }
27109@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27110 __enqueue_tpd(he_dev, tpd, cid);
27111 spin_unlock_irqrestore(&he_dev->global_lock, flags);
27112
27113- atomic_inc(&vcc->stats->tx);
27114+ atomic_inc_unchecked(&vcc->stats->tx);
27115
27116 return 0;
27117 }
27118diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
27119index b812103..e391a49 100644
27120--- a/drivers/atm/horizon.c
27121+++ b/drivers/atm/horizon.c
27122@@ -1035,7 +1035,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
27123 {
27124 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
27125 // VC layer stats
27126- atomic_inc(&vcc->stats->rx);
27127+ atomic_inc_unchecked(&vcc->stats->rx);
27128 __net_timestamp(skb);
27129 // end of our responsibility
27130 vcc->push (vcc, skb);
27131@@ -1187,7 +1187,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
27132 dev->tx_iovec = NULL;
27133
27134 // VC layer stats
27135- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27136+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27137
27138 // free the skb
27139 hrz_kfree_skb (skb);
27140diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
27141index 1c05212..c28e200 100644
27142--- a/drivers/atm/idt77252.c
27143+++ b/drivers/atm/idt77252.c
27144@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
27145 else
27146 dev_kfree_skb(skb);
27147
27148- atomic_inc(&vcc->stats->tx);
27149+ atomic_inc_unchecked(&vcc->stats->tx);
27150 }
27151
27152 atomic_dec(&scq->used);
27153@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27154 if ((sb = dev_alloc_skb(64)) == NULL) {
27155 printk("%s: Can't allocate buffers for aal0.\n",
27156 card->name);
27157- atomic_add(i, &vcc->stats->rx_drop);
27158+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
27159 break;
27160 }
27161 if (!atm_charge(vcc, sb->truesize)) {
27162 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
27163 card->name);
27164- atomic_add(i - 1, &vcc->stats->rx_drop);
27165+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
27166 dev_kfree_skb(sb);
27167 break;
27168 }
27169@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27170 ATM_SKB(sb)->vcc = vcc;
27171 __net_timestamp(sb);
27172 vcc->push(vcc, sb);
27173- atomic_inc(&vcc->stats->rx);
27174+ atomic_inc_unchecked(&vcc->stats->rx);
27175
27176 cell += ATM_CELL_PAYLOAD;
27177 }
27178@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27179 "(CDC: %08x)\n",
27180 card->name, len, rpp->len, readl(SAR_REG_CDC));
27181 recycle_rx_pool_skb(card, rpp);
27182- atomic_inc(&vcc->stats->rx_err);
27183+ atomic_inc_unchecked(&vcc->stats->rx_err);
27184 return;
27185 }
27186 if (stat & SAR_RSQE_CRC) {
27187 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
27188 recycle_rx_pool_skb(card, rpp);
27189- atomic_inc(&vcc->stats->rx_err);
27190+ atomic_inc_unchecked(&vcc->stats->rx_err);
27191 return;
27192 }
27193 if (skb_queue_len(&rpp->queue) > 1) {
27194@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27195 RXPRINTK("%s: Can't alloc RX skb.\n",
27196 card->name);
27197 recycle_rx_pool_skb(card, rpp);
27198- atomic_inc(&vcc->stats->rx_err);
27199+ atomic_inc_unchecked(&vcc->stats->rx_err);
27200 return;
27201 }
27202 if (!atm_charge(vcc, skb->truesize)) {
27203@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27204 __net_timestamp(skb);
27205
27206 vcc->push(vcc, skb);
27207- atomic_inc(&vcc->stats->rx);
27208+ atomic_inc_unchecked(&vcc->stats->rx);
27209
27210 return;
27211 }
27212@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
27213 __net_timestamp(skb);
27214
27215 vcc->push(vcc, skb);
27216- atomic_inc(&vcc->stats->rx);
27217+ atomic_inc_unchecked(&vcc->stats->rx);
27218
27219 if (skb->truesize > SAR_FB_SIZE_3)
27220 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
27221@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
27222 if (vcc->qos.aal != ATM_AAL0) {
27223 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
27224 card->name, vpi, vci);
27225- atomic_inc(&vcc->stats->rx_drop);
27226+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27227 goto drop;
27228 }
27229
27230 if ((sb = dev_alloc_skb(64)) == NULL) {
27231 printk("%s: Can't allocate buffers for AAL0.\n",
27232 card->name);
27233- atomic_inc(&vcc->stats->rx_err);
27234+ atomic_inc_unchecked(&vcc->stats->rx_err);
27235 goto drop;
27236 }
27237
27238@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
27239 ATM_SKB(sb)->vcc = vcc;
27240 __net_timestamp(sb);
27241 vcc->push(vcc, sb);
27242- atomic_inc(&vcc->stats->rx);
27243+ atomic_inc_unchecked(&vcc->stats->rx);
27244
27245 drop:
27246 skb_pull(queue, 64);
27247@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27248
27249 if (vc == NULL) {
27250 printk("%s: NULL connection in send().\n", card->name);
27251- atomic_inc(&vcc->stats->tx_err);
27252+ atomic_inc_unchecked(&vcc->stats->tx_err);
27253 dev_kfree_skb(skb);
27254 return -EINVAL;
27255 }
27256 if (!test_bit(VCF_TX, &vc->flags)) {
27257 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
27258- atomic_inc(&vcc->stats->tx_err);
27259+ atomic_inc_unchecked(&vcc->stats->tx_err);
27260 dev_kfree_skb(skb);
27261 return -EINVAL;
27262 }
27263@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27264 break;
27265 default:
27266 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
27267- atomic_inc(&vcc->stats->tx_err);
27268+ atomic_inc_unchecked(&vcc->stats->tx_err);
27269 dev_kfree_skb(skb);
27270 return -EINVAL;
27271 }
27272
27273 if (skb_shinfo(skb)->nr_frags != 0) {
27274 printk("%s: No scatter-gather yet.\n", card->name);
27275- atomic_inc(&vcc->stats->tx_err);
27276+ atomic_inc_unchecked(&vcc->stats->tx_err);
27277 dev_kfree_skb(skb);
27278 return -EINVAL;
27279 }
27280@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
27281
27282 err = queue_skb(card, vc, skb, oam);
27283 if (err) {
27284- atomic_inc(&vcc->stats->tx_err);
27285+ atomic_inc_unchecked(&vcc->stats->tx_err);
27286 dev_kfree_skb(skb);
27287 return err;
27288 }
27289@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
27290 skb = dev_alloc_skb(64);
27291 if (!skb) {
27292 printk("%s: Out of memory in send_oam().\n", card->name);
27293- atomic_inc(&vcc->stats->tx_err);
27294+ atomic_inc_unchecked(&vcc->stats->tx_err);
27295 return -ENOMEM;
27296 }
27297 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
27298diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
27299index 9e373ba..cf93727 100644
27300--- a/drivers/atm/iphase.c
27301+++ b/drivers/atm/iphase.c
27302@@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
27303 status = (u_short) (buf_desc_ptr->desc_mode);
27304 if (status & (RX_CER | RX_PTE | RX_OFL))
27305 {
27306- atomic_inc(&vcc->stats->rx_err);
27307+ atomic_inc_unchecked(&vcc->stats->rx_err);
27308 IF_ERR(printk("IA: bad packet, dropping it");)
27309 if (status & RX_CER) {
27310 IF_ERR(printk(" cause: packet CRC error\n");)
27311@@ -1169,7 +1169,7 @@ static int rx_pkt(struct atm_dev *dev)
27312 len = dma_addr - buf_addr;
27313 if (len > iadev->rx_buf_sz) {
27314 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
27315- atomic_inc(&vcc->stats->rx_err);
27316+ atomic_inc_unchecked(&vcc->stats->rx_err);
27317 goto out_free_desc;
27318 }
27319
27320@@ -1319,7 +1319,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27321 ia_vcc = INPH_IA_VCC(vcc);
27322 if (ia_vcc == NULL)
27323 {
27324- atomic_inc(&vcc->stats->rx_err);
27325+ atomic_inc_unchecked(&vcc->stats->rx_err);
27326 atm_return(vcc, skb->truesize);
27327 dev_kfree_skb_any(skb);
27328 goto INCR_DLE;
27329@@ -1331,7 +1331,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27330 if ((length > iadev->rx_buf_sz) || (length >
27331 (skb->len - sizeof(struct cpcs_trailer))))
27332 {
27333- atomic_inc(&vcc->stats->rx_err);
27334+ atomic_inc_unchecked(&vcc->stats->rx_err);
27335 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
27336 length, skb->len);)
27337 atm_return(vcc, skb->truesize);
27338@@ -1347,7 +1347,7 @@ static void rx_dle_intr(struct atm_dev *dev)
27339
27340 IF_RX(printk("rx_dle_intr: skb push");)
27341 vcc->push(vcc,skb);
27342- atomic_inc(&vcc->stats->rx);
27343+ atomic_inc_unchecked(&vcc->stats->rx);
27344 iadev->rx_pkt_cnt++;
27345 }
27346 INCR_DLE:
27347@@ -2827,15 +2827,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
27348 {
27349 struct k_sonet_stats *stats;
27350 stats = &PRIV(_ia_dev[board])->sonet_stats;
27351- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
27352- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
27353- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
27354- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
27355- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
27356- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
27357- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
27358- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
27359- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
27360+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
27361+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
27362+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
27363+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
27364+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
27365+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
27366+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
27367+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
27368+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
27369 }
27370 ia_cmds.status = 0;
27371 break;
27372@@ -2940,7 +2940,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
27373 if ((desc == 0) || (desc > iadev->num_tx_desc))
27374 {
27375 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
27376- atomic_inc(&vcc->stats->tx);
27377+ atomic_inc_unchecked(&vcc->stats->tx);
27378 if (vcc->pop)
27379 vcc->pop(vcc, skb);
27380 else
27381@@ -3045,14 +3045,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
27382 ATM_DESC(skb) = vcc->vci;
27383 skb_queue_tail(&iadev->tx_dma_q, skb);
27384
27385- atomic_inc(&vcc->stats->tx);
27386+ atomic_inc_unchecked(&vcc->stats->tx);
27387 iadev->tx_pkt_cnt++;
27388 /* Increment transaction counter */
27389 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
27390
27391 #if 0
27392 /* add flow control logic */
27393- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
27394+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
27395 if (iavcc->vc_desc_cnt > 10) {
27396 vcc->tx_quota = vcc->tx_quota * 3 / 4;
27397 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
27398diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
27399index f556969..0da15eb 100644
27400--- a/drivers/atm/lanai.c
27401+++ b/drivers/atm/lanai.c
27402@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
27403 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
27404 lanai_endtx(lanai, lvcc);
27405 lanai_free_skb(lvcc->tx.atmvcc, skb);
27406- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
27407+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
27408 }
27409
27410 /* Try to fill the buffer - don't call unless there is backlog */
27411@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
27412 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
27413 __net_timestamp(skb);
27414 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
27415- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
27416+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
27417 out:
27418 lvcc->rx.buf.ptr = end;
27419 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
27420@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
27421 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
27422 "vcc %d\n", lanai->number, (unsigned int) s, vci);
27423 lanai->stats.service_rxnotaal5++;
27424- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27425+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27426 return 0;
27427 }
27428 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
27429@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
27430 int bytes;
27431 read_unlock(&vcc_sklist_lock);
27432 DPRINTK("got trashed rx pdu on vci %d\n", vci);
27433- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27434+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27435 lvcc->stats.x.aal5.service_trash++;
27436 bytes = (SERVICE_GET_END(s) * 16) -
27437 (((unsigned long) lvcc->rx.buf.ptr) -
27438@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
27439 }
27440 if (s & SERVICE_STREAM) {
27441 read_unlock(&vcc_sklist_lock);
27442- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27443+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27444 lvcc->stats.x.aal5.service_stream++;
27445 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
27446 "PDU on VCI %d!\n", lanai->number, vci);
27447@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
27448 return 0;
27449 }
27450 DPRINTK("got rx crc error on vci %d\n", vci);
27451- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27452+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27453 lvcc->stats.x.aal5.service_rxcrc++;
27454 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
27455 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
27456diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
27457index 1c70c45..300718d 100644
27458--- a/drivers/atm/nicstar.c
27459+++ b/drivers/atm/nicstar.c
27460@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
27461 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
27462 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
27463 card->index);
27464- atomic_inc(&vcc->stats->tx_err);
27465+ atomic_inc_unchecked(&vcc->stats->tx_err);
27466 dev_kfree_skb_any(skb);
27467 return -EINVAL;
27468 }
27469@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
27470 if (!vc->tx) {
27471 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
27472 card->index);
27473- atomic_inc(&vcc->stats->tx_err);
27474+ atomic_inc_unchecked(&vcc->stats->tx_err);
27475 dev_kfree_skb_any(skb);
27476 return -EINVAL;
27477 }
27478@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
27479 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
27480 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
27481 card->index);
27482- atomic_inc(&vcc->stats->tx_err);
27483+ atomic_inc_unchecked(&vcc->stats->tx_err);
27484 dev_kfree_skb_any(skb);
27485 return -EINVAL;
27486 }
27487
27488 if (skb_shinfo(skb)->nr_frags != 0) {
27489 printk("nicstar%d: No scatter-gather yet.\n", card->index);
27490- atomic_inc(&vcc->stats->tx_err);
27491+ atomic_inc_unchecked(&vcc->stats->tx_err);
27492 dev_kfree_skb_any(skb);
27493 return -EINVAL;
27494 }
27495@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
27496 }
27497
27498 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
27499- atomic_inc(&vcc->stats->tx_err);
27500+ atomic_inc_unchecked(&vcc->stats->tx_err);
27501 dev_kfree_skb_any(skb);
27502 return -EIO;
27503 }
27504- atomic_inc(&vcc->stats->tx);
27505+ atomic_inc_unchecked(&vcc->stats->tx);
27506
27507 return 0;
27508 }
27509@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27510 printk
27511 ("nicstar%d: Can't allocate buffers for aal0.\n",
27512 card->index);
27513- atomic_add(i, &vcc->stats->rx_drop);
27514+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
27515 break;
27516 }
27517 if (!atm_charge(vcc, sb->truesize)) {
27518 RXPRINTK
27519 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
27520 card->index);
27521- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
27522+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
27523 dev_kfree_skb_any(sb);
27524 break;
27525 }
27526@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27527 ATM_SKB(sb)->vcc = vcc;
27528 __net_timestamp(sb);
27529 vcc->push(vcc, sb);
27530- atomic_inc(&vcc->stats->rx);
27531+ atomic_inc_unchecked(&vcc->stats->rx);
27532 cell += ATM_CELL_PAYLOAD;
27533 }
27534
27535@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27536 if (iovb == NULL) {
27537 printk("nicstar%d: Out of iovec buffers.\n",
27538 card->index);
27539- atomic_inc(&vcc->stats->rx_drop);
27540+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27541 recycle_rx_buf(card, skb);
27542 return;
27543 }
27544@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27545 small or large buffer itself. */
27546 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
27547 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
27548- atomic_inc(&vcc->stats->rx_err);
27549+ atomic_inc_unchecked(&vcc->stats->rx_err);
27550 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27551 NS_MAX_IOVECS);
27552 NS_PRV_IOVCNT(iovb) = 0;
27553@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27554 ("nicstar%d: Expected a small buffer, and this is not one.\n",
27555 card->index);
27556 which_list(card, skb);
27557- atomic_inc(&vcc->stats->rx_err);
27558+ atomic_inc_unchecked(&vcc->stats->rx_err);
27559 recycle_rx_buf(card, skb);
27560 vc->rx_iov = NULL;
27561 recycle_iov_buf(card, iovb);
27562@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27563 ("nicstar%d: Expected a large buffer, and this is not one.\n",
27564 card->index);
27565 which_list(card, skb);
27566- atomic_inc(&vcc->stats->rx_err);
27567+ atomic_inc_unchecked(&vcc->stats->rx_err);
27568 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27569 NS_PRV_IOVCNT(iovb));
27570 vc->rx_iov = NULL;
27571@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27572 printk(" - PDU size mismatch.\n");
27573 else
27574 printk(".\n");
27575- atomic_inc(&vcc->stats->rx_err);
27576+ atomic_inc_unchecked(&vcc->stats->rx_err);
27577 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27578 NS_PRV_IOVCNT(iovb));
27579 vc->rx_iov = NULL;
27580@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27581 /* skb points to a small buffer */
27582 if (!atm_charge(vcc, skb->truesize)) {
27583 push_rxbufs(card, skb);
27584- atomic_inc(&vcc->stats->rx_drop);
27585+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27586 } else {
27587 skb_put(skb, len);
27588 dequeue_sm_buf(card, skb);
27589@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27590 ATM_SKB(skb)->vcc = vcc;
27591 __net_timestamp(skb);
27592 vcc->push(vcc, skb);
27593- atomic_inc(&vcc->stats->rx);
27594+ atomic_inc_unchecked(&vcc->stats->rx);
27595 }
27596 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
27597 struct sk_buff *sb;
27598@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27599 if (len <= NS_SMBUFSIZE) {
27600 if (!atm_charge(vcc, sb->truesize)) {
27601 push_rxbufs(card, sb);
27602- atomic_inc(&vcc->stats->rx_drop);
27603+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27604 } else {
27605 skb_put(sb, len);
27606 dequeue_sm_buf(card, sb);
27607@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27608 ATM_SKB(sb)->vcc = vcc;
27609 __net_timestamp(sb);
27610 vcc->push(vcc, sb);
27611- atomic_inc(&vcc->stats->rx);
27612+ atomic_inc_unchecked(&vcc->stats->rx);
27613 }
27614
27615 push_rxbufs(card, skb);
27616@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27617
27618 if (!atm_charge(vcc, skb->truesize)) {
27619 push_rxbufs(card, skb);
27620- atomic_inc(&vcc->stats->rx_drop);
27621+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27622 } else {
27623 dequeue_lg_buf(card, skb);
27624 #ifdef NS_USE_DESTRUCTORS
27625@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27626 ATM_SKB(skb)->vcc = vcc;
27627 __net_timestamp(skb);
27628 vcc->push(vcc, skb);
27629- atomic_inc(&vcc->stats->rx);
27630+ atomic_inc_unchecked(&vcc->stats->rx);
27631 }
27632
27633 push_rxbufs(card, sb);
27634@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27635 printk
27636 ("nicstar%d: Out of huge buffers.\n",
27637 card->index);
27638- atomic_inc(&vcc->stats->rx_drop);
27639+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27640 recycle_iovec_rx_bufs(card,
27641 (struct iovec *)
27642 iovb->data,
27643@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27644 card->hbpool.count++;
27645 } else
27646 dev_kfree_skb_any(hb);
27647- atomic_inc(&vcc->stats->rx_drop);
27648+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27649 } else {
27650 /* Copy the small buffer to the huge buffer */
27651 sb = (struct sk_buff *)iov->iov_base;
27652@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
27653 #endif /* NS_USE_DESTRUCTORS */
27654 __net_timestamp(hb);
27655 vcc->push(vcc, hb);
27656- atomic_inc(&vcc->stats->rx);
27657+ atomic_inc_unchecked(&vcc->stats->rx);
27658 }
27659 }
27660
27661diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
27662index e8cd652..bbbd1fc 100644
27663--- a/drivers/atm/solos-pci.c
27664+++ b/drivers/atm/solos-pci.c
27665@@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
27666 }
27667 atm_charge(vcc, skb->truesize);
27668 vcc->push(vcc, skb);
27669- atomic_inc(&vcc->stats->rx);
27670+ atomic_inc_unchecked(&vcc->stats->rx);
27671 break;
27672
27673 case PKT_STATUS:
27674@@ -1008,7 +1008,7 @@ static uint32_t fpga_tx(struct solos_card *card)
27675 vcc = SKB_CB(oldskb)->vcc;
27676
27677 if (vcc) {
27678- atomic_inc(&vcc->stats->tx);
27679+ atomic_inc_unchecked(&vcc->stats->tx);
27680 solos_pop(vcc, oldskb);
27681 } else
27682 dev_kfree_skb_irq(oldskb);
27683diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
27684index 90f1ccc..04c4a1e 100644
27685--- a/drivers/atm/suni.c
27686+++ b/drivers/atm/suni.c
27687@@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
27688
27689
27690 #define ADD_LIMITED(s,v) \
27691- atomic_add((v),&stats->s); \
27692- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
27693+ atomic_add_unchecked((v),&stats->s); \
27694+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
27695
27696
27697 static void suni_hz(unsigned long from_timer)
27698diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
27699index 5120a96..e2572bd 100644
27700--- a/drivers/atm/uPD98402.c
27701+++ b/drivers/atm/uPD98402.c
27702@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
27703 struct sonet_stats tmp;
27704 int error = 0;
27705
27706- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
27707+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
27708 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
27709 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
27710 if (zero && !error) {
27711@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
27712
27713
27714 #define ADD_LIMITED(s,v) \
27715- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
27716- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
27717- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
27718+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
27719+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
27720+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
27721
27722
27723 static void stat_event(struct atm_dev *dev)
27724@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
27725 if (reason & uPD98402_INT_PFM) stat_event(dev);
27726 if (reason & uPD98402_INT_PCO) {
27727 (void) GET(PCOCR); /* clear interrupt cause */
27728- atomic_add(GET(HECCT),
27729+ atomic_add_unchecked(GET(HECCT),
27730 &PRIV(dev)->sonet_stats.uncorr_hcs);
27731 }
27732 if ((reason & uPD98402_INT_RFO) &&
27733@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
27734 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
27735 uPD98402_INT_LOS),PIMR); /* enable them */
27736 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
27737- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
27738- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
27739- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
27740+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
27741+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
27742+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
27743 return 0;
27744 }
27745
27746diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
27747index d889f56..17eb71e 100644
27748--- a/drivers/atm/zatm.c
27749+++ b/drivers/atm/zatm.c
27750@@ -460,7 +460,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
27751 }
27752 if (!size) {
27753 dev_kfree_skb_irq(skb);
27754- if (vcc) atomic_inc(&vcc->stats->rx_err);
27755+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
27756 continue;
27757 }
27758 if (!atm_charge(vcc,skb->truesize)) {
27759@@ -470,7 +470,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
27760 skb->len = size;
27761 ATM_SKB(skb)->vcc = vcc;
27762 vcc->push(vcc,skb);
27763- atomic_inc(&vcc->stats->rx);
27764+ atomic_inc_unchecked(&vcc->stats->rx);
27765 }
27766 zout(pos & 0xffff,MTA(mbx));
27767 #if 0 /* probably a stupid idea */
27768@@ -734,7 +734,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
27769 skb_queue_head(&zatm_vcc->backlog,skb);
27770 break;
27771 }
27772- atomic_inc(&vcc->stats->tx);
27773+ atomic_inc_unchecked(&vcc->stats->tx);
27774 wake_up(&zatm_vcc->tx_wait);
27775 }
27776
27777diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
27778index 8493536..31adee0 100644
27779--- a/drivers/base/devtmpfs.c
27780+++ b/drivers/base/devtmpfs.c
27781@@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
27782 if (!thread)
27783 return 0;
27784
27785- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
27786+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
27787 if (err)
27788 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
27789 else
27790diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
27791index caf995f..6f76697 100644
27792--- a/drivers/base/power/wakeup.c
27793+++ b/drivers/base/power/wakeup.c
27794@@ -30,14 +30,14 @@ bool events_check_enabled;
27795 * They need to be modified together atomically, so it's better to use one
27796 * atomic variable to hold them both.
27797 */
27798-static atomic_t combined_event_count = ATOMIC_INIT(0);
27799+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
27800
27801 #define IN_PROGRESS_BITS (sizeof(int) * 4)
27802 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
27803
27804 static void split_counters(unsigned int *cnt, unsigned int *inpr)
27805 {
27806- unsigned int comb = atomic_read(&combined_event_count);
27807+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
27808
27809 *cnt = (comb >> IN_PROGRESS_BITS);
27810 *inpr = comb & MAX_IN_PROGRESS;
27811@@ -353,7 +353,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
27812 ws->last_time = ktime_get();
27813
27814 /* Increment the counter of events in progress. */
27815- atomic_inc(&combined_event_count);
27816+ atomic_inc_unchecked(&combined_event_count);
27817 }
27818
27819 /**
27820@@ -443,7 +443,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
27821 * Increment the counter of registered wakeup events and decrement the
27822 * couter of wakeup events in progress simultaneously.
27823 */
27824- atomic_add(MAX_IN_PROGRESS, &combined_event_count);
27825+ atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
27826 }
27827
27828 /**
27829diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
27830index b0f553b..77b928b 100644
27831--- a/drivers/block/cciss.c
27832+++ b/drivers/block/cciss.c
27833@@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
27834 int err;
27835 u32 cp;
27836
27837+ memset(&arg64, 0, sizeof(arg64));
27838+
27839 err = 0;
27840 err |=
27841 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
27842@@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
27843 while (!list_empty(&h->reqQ)) {
27844 c = list_entry(h->reqQ.next, CommandList_struct, list);
27845 /* can't do anything if fifo is full */
27846- if ((h->access.fifo_full(h))) {
27847+ if ((h->access->fifo_full(h))) {
27848 dev_warn(&h->pdev->dev, "fifo full\n");
27849 break;
27850 }
27851@@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
27852 h->Qdepth--;
27853
27854 /* Tell the controller execute command */
27855- h->access.submit_command(h, c);
27856+ h->access->submit_command(h, c);
27857
27858 /* Put job onto the completed Q */
27859 addQ(&h->cmpQ, c);
27860@@ -3443,17 +3445,17 @@ startio:
27861
27862 static inline unsigned long get_next_completion(ctlr_info_t *h)
27863 {
27864- return h->access.command_completed(h);
27865+ return h->access->command_completed(h);
27866 }
27867
27868 static inline int interrupt_pending(ctlr_info_t *h)
27869 {
27870- return h->access.intr_pending(h);
27871+ return h->access->intr_pending(h);
27872 }
27873
27874 static inline long interrupt_not_for_us(ctlr_info_t *h)
27875 {
27876- return ((h->access.intr_pending(h) == 0) ||
27877+ return ((h->access->intr_pending(h) == 0) ||
27878 (h->interrupts_enabled == 0));
27879 }
27880
27881@@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
27882 u32 a;
27883
27884 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
27885- return h->access.command_completed(h);
27886+ return h->access->command_completed(h);
27887
27888 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
27889 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
27890@@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
27891 trans_support & CFGTBL_Trans_use_short_tags);
27892
27893 /* Change the access methods to the performant access methods */
27894- h->access = SA5_performant_access;
27895+ h->access = &SA5_performant_access;
27896 h->transMethod = CFGTBL_Trans_Performant;
27897
27898 return;
27899@@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
27900 if (prod_index < 0)
27901 return -ENODEV;
27902 h->product_name = products[prod_index].product_name;
27903- h->access = *(products[prod_index].access);
27904+ h->access = products[prod_index].access;
27905
27906 if (cciss_board_disabled(h)) {
27907 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
27908@@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
27909 }
27910
27911 /* make sure the board interrupts are off */
27912- h->access.set_intr_mask(h, CCISS_INTR_OFF);
27913+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
27914 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
27915 if (rc)
27916 goto clean2;
27917@@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
27918 * fake ones to scoop up any residual completions.
27919 */
27920 spin_lock_irqsave(&h->lock, flags);
27921- h->access.set_intr_mask(h, CCISS_INTR_OFF);
27922+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
27923 spin_unlock_irqrestore(&h->lock, flags);
27924 free_irq(h->intr[h->intr_mode], h);
27925 rc = cciss_request_irq(h, cciss_msix_discard_completions,
27926@@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
27927 dev_info(&h->pdev->dev, "Board READY.\n");
27928 dev_info(&h->pdev->dev,
27929 "Waiting for stale completions to drain.\n");
27930- h->access.set_intr_mask(h, CCISS_INTR_ON);
27931+ h->access->set_intr_mask(h, CCISS_INTR_ON);
27932 msleep(10000);
27933- h->access.set_intr_mask(h, CCISS_INTR_OFF);
27934+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
27935
27936 rc = controller_reset_failed(h->cfgtable);
27937 if (rc)
27938@@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
27939 cciss_scsi_setup(h);
27940
27941 /* Turn the interrupts on so we can service requests */
27942- h->access.set_intr_mask(h, CCISS_INTR_ON);
27943+ h->access->set_intr_mask(h, CCISS_INTR_ON);
27944
27945 /* Get the firmware version */
27946 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
27947@@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
27948 kfree(flush_buf);
27949 if (return_code != IO_OK)
27950 dev_warn(&h->pdev->dev, "Error flushing cache\n");
27951- h->access.set_intr_mask(h, CCISS_INTR_OFF);
27952+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
27953 free_irq(h->intr[h->intr_mode], h);
27954 }
27955
27956diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
27957index 7fda30e..eb5dfe0 100644
27958--- a/drivers/block/cciss.h
27959+++ b/drivers/block/cciss.h
27960@@ -101,7 +101,7 @@ struct ctlr_info
27961 /* information about each logical volume */
27962 drive_info_struct *drv[CISS_MAX_LUN];
27963
27964- struct access_method access;
27965+ struct access_method *access;
27966
27967 /* queue and queue Info */
27968 struct list_head reqQ;
27969diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
27970index 9125bbe..eede5c8 100644
27971--- a/drivers/block/cpqarray.c
27972+++ b/drivers/block/cpqarray.c
27973@@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
27974 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
27975 goto Enomem4;
27976 }
27977- hba[i]->access.set_intr_mask(hba[i], 0);
27978+ hba[i]->access->set_intr_mask(hba[i], 0);
27979 if (request_irq(hba[i]->intr, do_ida_intr,
27980 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
27981 {
27982@@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
27983 add_timer(&hba[i]->timer);
27984
27985 /* Enable IRQ now that spinlock and rate limit timer are set up */
27986- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
27987+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
27988
27989 for(j=0; j<NWD; j++) {
27990 struct gendisk *disk = ida_gendisk[i][j];
27991@@ -694,7 +694,7 @@ DBGINFO(
27992 for(i=0; i<NR_PRODUCTS; i++) {
27993 if (board_id == products[i].board_id) {
27994 c->product_name = products[i].product_name;
27995- c->access = *(products[i].access);
27996+ c->access = products[i].access;
27997 break;
27998 }
27999 }
28000@@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28001 hba[ctlr]->intr = intr;
28002 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28003 hba[ctlr]->product_name = products[j].product_name;
28004- hba[ctlr]->access = *(products[j].access);
28005+ hba[ctlr]->access = products[j].access;
28006 hba[ctlr]->ctlr = ctlr;
28007 hba[ctlr]->board_id = board_id;
28008 hba[ctlr]->pci_dev = NULL; /* not PCI */
28009@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
28010
28011 while((c = h->reqQ) != NULL) {
28012 /* Can't do anything if we're busy */
28013- if (h->access.fifo_full(h) == 0)
28014+ if (h->access->fifo_full(h) == 0)
28015 return;
28016
28017 /* Get the first entry from the request Q */
28018@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
28019 h->Qdepth--;
28020
28021 /* Tell the controller to do our bidding */
28022- h->access.submit_command(h, c);
28023+ h->access->submit_command(h, c);
28024
28025 /* Get onto the completion Q */
28026 addQ(&h->cmpQ, c);
28027@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28028 unsigned long flags;
28029 __u32 a,a1;
28030
28031- istat = h->access.intr_pending(h);
28032+ istat = h->access->intr_pending(h);
28033 /* Is this interrupt for us? */
28034 if (istat == 0)
28035 return IRQ_NONE;
28036@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28037 */
28038 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
28039 if (istat & FIFO_NOT_EMPTY) {
28040- while((a = h->access.command_completed(h))) {
28041+ while((a = h->access->command_completed(h))) {
28042 a1 = a; a &= ~3;
28043 if ((c = h->cmpQ) == NULL)
28044 {
28045@@ -1449,11 +1449,11 @@ static int sendcmd(
28046 /*
28047 * Disable interrupt
28048 */
28049- info_p->access.set_intr_mask(info_p, 0);
28050+ info_p->access->set_intr_mask(info_p, 0);
28051 /* Make sure there is room in the command FIFO */
28052 /* Actually it should be completely empty at this time. */
28053 for (i = 200000; i > 0; i--) {
28054- temp = info_p->access.fifo_full(info_p);
28055+ temp = info_p->access->fifo_full(info_p);
28056 if (temp != 0) {
28057 break;
28058 }
28059@@ -1466,7 +1466,7 @@ DBG(
28060 /*
28061 * Send the cmd
28062 */
28063- info_p->access.submit_command(info_p, c);
28064+ info_p->access->submit_command(info_p, c);
28065 complete = pollcomplete(ctlr);
28066
28067 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
28068@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
28069 * we check the new geometry. Then turn interrupts back on when
28070 * we're done.
28071 */
28072- host->access.set_intr_mask(host, 0);
28073+ host->access->set_intr_mask(host, 0);
28074 getgeometry(ctlr);
28075- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
28076+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
28077
28078 for(i=0; i<NWD; i++) {
28079 struct gendisk *disk = ida_gendisk[ctlr][i];
28080@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
28081 /* Wait (up to 2 seconds) for a command to complete */
28082
28083 for (i = 200000; i > 0; i--) {
28084- done = hba[ctlr]->access.command_completed(hba[ctlr]);
28085+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
28086 if (done == 0) {
28087 udelay(10); /* a short fixed delay */
28088 } else
28089diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
28090index be73e9d..7fbf140 100644
28091--- a/drivers/block/cpqarray.h
28092+++ b/drivers/block/cpqarray.h
28093@@ -99,7 +99,7 @@ struct ctlr_info {
28094 drv_info_t drv[NWD];
28095 struct proc_dir_entry *proc;
28096
28097- struct access_method access;
28098+ struct access_method *access;
28099
28100 cmdlist_t *reqQ;
28101 cmdlist_t *cmpQ;
28102diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
28103index 8d68056..e67050f 100644
28104--- a/drivers/block/drbd/drbd_int.h
28105+++ b/drivers/block/drbd/drbd_int.h
28106@@ -736,7 +736,7 @@ struct drbd_request;
28107 struct drbd_epoch {
28108 struct list_head list;
28109 unsigned int barrier_nr;
28110- atomic_t epoch_size; /* increased on every request added. */
28111+ atomic_unchecked_t epoch_size; /* increased on every request added. */
28112 atomic_t active; /* increased on every req. added, and dec on every finished. */
28113 unsigned long flags;
28114 };
28115@@ -1108,7 +1108,7 @@ struct drbd_conf {
28116 void *int_dig_in;
28117 void *int_dig_vv;
28118 wait_queue_head_t seq_wait;
28119- atomic_t packet_seq;
28120+ atomic_unchecked_t packet_seq;
28121 unsigned int peer_seq;
28122 spinlock_t peer_seq_lock;
28123 unsigned int minor;
28124@@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
28125
28126 static inline void drbd_tcp_cork(struct socket *sock)
28127 {
28128- int __user val = 1;
28129+ int val = 1;
28130 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
28131- (char __user *)&val, sizeof(val));
28132+ (char __force_user *)&val, sizeof(val));
28133 }
28134
28135 static inline void drbd_tcp_uncork(struct socket *sock)
28136 {
28137- int __user val = 0;
28138+ int val = 0;
28139 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
28140- (char __user *)&val, sizeof(val));
28141+ (char __force_user *)&val, sizeof(val));
28142 }
28143
28144 static inline void drbd_tcp_nodelay(struct socket *sock)
28145 {
28146- int __user val = 1;
28147+ int val = 1;
28148 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
28149- (char __user *)&val, sizeof(val));
28150+ (char __force_user *)&val, sizeof(val));
28151 }
28152
28153 static inline void drbd_tcp_quickack(struct socket *sock)
28154 {
28155- int __user val = 2;
28156+ int val = 2;
28157 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
28158- (char __user *)&val, sizeof(val));
28159+ (char __force_user *)&val, sizeof(val));
28160 }
28161
28162 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
28163diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
28164index 211fc44..c5116f1 100644
28165--- a/drivers/block/drbd/drbd_main.c
28166+++ b/drivers/block/drbd/drbd_main.c
28167@@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
28168 p.sector = sector;
28169 p.block_id = block_id;
28170 p.blksize = blksize;
28171- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
28172+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
28173
28174 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
28175 return false;
28176@@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
28177 p.sector = cpu_to_be64(req->sector);
28178 p.block_id = (unsigned long)req;
28179 p.seq_num = cpu_to_be32(req->seq_num =
28180- atomic_add_return(1, &mdev->packet_seq));
28181+ atomic_add_return_unchecked(1, &mdev->packet_seq));
28182
28183 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
28184
28185@@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
28186 atomic_set(&mdev->unacked_cnt, 0);
28187 atomic_set(&mdev->local_cnt, 0);
28188 atomic_set(&mdev->net_cnt, 0);
28189- atomic_set(&mdev->packet_seq, 0);
28190+ atomic_set_unchecked(&mdev->packet_seq, 0);
28191 atomic_set(&mdev->pp_in_use, 0);
28192 atomic_set(&mdev->pp_in_use_by_net, 0);
28193 atomic_set(&mdev->rs_sect_in, 0);
28194@@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
28195 mdev->receiver.t_state);
28196
28197 /* no need to lock it, I'm the only thread alive */
28198- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
28199- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
28200+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
28201+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
28202 mdev->al_writ_cnt =
28203 mdev->bm_writ_cnt =
28204 mdev->read_cnt =
28205diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
28206index af2a250..219c74b 100644
28207--- a/drivers/block/drbd/drbd_nl.c
28208+++ b/drivers/block/drbd/drbd_nl.c
28209@@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
28210 module_put(THIS_MODULE);
28211 }
28212
28213-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
28214+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
28215
28216 static unsigned short *
28217 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
28218@@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
28219 cn_reply->id.idx = CN_IDX_DRBD;
28220 cn_reply->id.val = CN_VAL_DRBD;
28221
28222- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
28223+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
28224 cn_reply->ack = 0; /* not used here. */
28225 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28226 (int)((char *)tl - (char *)reply->tag_list);
28227@@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
28228 cn_reply->id.idx = CN_IDX_DRBD;
28229 cn_reply->id.val = CN_VAL_DRBD;
28230
28231- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
28232+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
28233 cn_reply->ack = 0; /* not used here. */
28234 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28235 (int)((char *)tl - (char *)reply->tag_list);
28236@@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
28237 cn_reply->id.idx = CN_IDX_DRBD;
28238 cn_reply->id.val = CN_VAL_DRBD;
28239
28240- cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
28241+ cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
28242 cn_reply->ack = 0; // not used here.
28243 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28244 (int)((char*)tl - (char*)reply->tag_list);
28245@@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
28246 cn_reply->id.idx = CN_IDX_DRBD;
28247 cn_reply->id.val = CN_VAL_DRBD;
28248
28249- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
28250+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
28251 cn_reply->ack = 0; /* not used here. */
28252 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
28253 (int)((char *)tl - (char *)reply->tag_list);
28254diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
28255index 43beaca..4a5b1dd 100644
28256--- a/drivers/block/drbd/drbd_receiver.c
28257+++ b/drivers/block/drbd/drbd_receiver.c
28258@@ -894,7 +894,7 @@ retry:
28259 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
28260 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
28261
28262- atomic_set(&mdev->packet_seq, 0);
28263+ atomic_set_unchecked(&mdev->packet_seq, 0);
28264 mdev->peer_seq = 0;
28265
28266 drbd_thread_start(&mdev->asender);
28267@@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
28268 do {
28269 next_epoch = NULL;
28270
28271- epoch_size = atomic_read(&epoch->epoch_size);
28272+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
28273
28274 switch (ev & ~EV_CLEANUP) {
28275 case EV_PUT:
28276@@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
28277 rv = FE_DESTROYED;
28278 } else {
28279 epoch->flags = 0;
28280- atomic_set(&epoch->epoch_size, 0);
28281+ atomic_set_unchecked(&epoch->epoch_size, 0);
28282 /* atomic_set(&epoch->active, 0); is already zero */
28283 if (rv == FE_STILL_LIVE)
28284 rv = FE_RECYCLED;
28285@@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
28286 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
28287 drbd_flush(mdev);
28288
28289- if (atomic_read(&mdev->current_epoch->epoch_size)) {
28290+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
28291 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
28292 if (epoch)
28293 break;
28294 }
28295
28296 epoch = mdev->current_epoch;
28297- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
28298+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
28299
28300 D_ASSERT(atomic_read(&epoch->active) == 0);
28301 D_ASSERT(epoch->flags == 0);
28302@@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
28303 }
28304
28305 epoch->flags = 0;
28306- atomic_set(&epoch->epoch_size, 0);
28307+ atomic_set_unchecked(&epoch->epoch_size, 0);
28308 atomic_set(&epoch->active, 0);
28309
28310 spin_lock(&mdev->epoch_lock);
28311- if (atomic_read(&mdev->current_epoch->epoch_size)) {
28312+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
28313 list_add(&epoch->list, &mdev->current_epoch->list);
28314 mdev->current_epoch = epoch;
28315 mdev->epochs++;
28316@@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
28317 spin_unlock(&mdev->peer_seq_lock);
28318
28319 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
28320- atomic_inc(&mdev->current_epoch->epoch_size);
28321+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
28322 return drbd_drain_block(mdev, data_size);
28323 }
28324
28325@@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
28326
28327 spin_lock(&mdev->epoch_lock);
28328 e->epoch = mdev->current_epoch;
28329- atomic_inc(&e->epoch->epoch_size);
28330+ atomic_inc_unchecked(&e->epoch->epoch_size);
28331 atomic_inc(&e->epoch->active);
28332 spin_unlock(&mdev->epoch_lock);
28333
28334@@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
28335 D_ASSERT(list_empty(&mdev->done_ee));
28336
28337 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
28338- atomic_set(&mdev->current_epoch->epoch_size, 0);
28339+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
28340 D_ASSERT(list_empty(&mdev->current_epoch->list));
28341 }
28342
28343diff --git a/drivers/block/loop.c b/drivers/block/loop.c
28344index cd50435..ba1ffb5 100644
28345--- a/drivers/block/loop.c
28346+++ b/drivers/block/loop.c
28347@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
28348 mm_segment_t old_fs = get_fs();
28349
28350 set_fs(get_ds());
28351- bw = file->f_op->write(file, buf, len, &pos);
28352+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
28353 set_fs(old_fs);
28354 if (likely(bw == len))
28355 return 0;
28356diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
28357index 4364303..9adf4ee 100644
28358--- a/drivers/char/Kconfig
28359+++ b/drivers/char/Kconfig
28360@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
28361
28362 config DEVKMEM
28363 bool "/dev/kmem virtual device support"
28364- default y
28365+ default n
28366+ depends on !GRKERNSEC_KMEM
28367 help
28368 Say Y here if you want to support the /dev/kmem device. The
28369 /dev/kmem device is rarely used, but can be used for certain
28370@@ -596,6 +597,7 @@ config DEVPORT
28371 bool
28372 depends on !M68K
28373 depends on ISA || PCI
28374+ depends on !GRKERNSEC_KMEM
28375 default y
28376
28377 source "drivers/s390/char/Kconfig"
28378diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
28379index 2e04433..22afc64 100644
28380--- a/drivers/char/agp/frontend.c
28381+++ b/drivers/char/agp/frontend.c
28382@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
28383 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
28384 return -EFAULT;
28385
28386- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
28387+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
28388 return -EFAULT;
28389
28390 client = agp_find_client_by_pid(reserve.pid);
28391diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
28392index 095ab90..afad0a4 100644
28393--- a/drivers/char/briq_panel.c
28394+++ b/drivers/char/briq_panel.c
28395@@ -9,6 +9,7 @@
28396 #include <linux/types.h>
28397 #include <linux/errno.h>
28398 #include <linux/tty.h>
28399+#include <linux/mutex.h>
28400 #include <linux/timer.h>
28401 #include <linux/kernel.h>
28402 #include <linux/wait.h>
28403@@ -34,6 +35,7 @@ static int vfd_is_open;
28404 static unsigned char vfd[40];
28405 static int vfd_cursor;
28406 static unsigned char ledpb, led;
28407+static DEFINE_MUTEX(vfd_mutex);
28408
28409 static void update_vfd(void)
28410 {
28411@@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
28412 if (!vfd_is_open)
28413 return -EBUSY;
28414
28415+ mutex_lock(&vfd_mutex);
28416 for (;;) {
28417 char c;
28418 if (!indx)
28419 break;
28420- if (get_user(c, buf))
28421+ if (get_user(c, buf)) {
28422+ mutex_unlock(&vfd_mutex);
28423 return -EFAULT;
28424+ }
28425 if (esc) {
28426 set_led(c);
28427 esc = 0;
28428@@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
28429 buf++;
28430 }
28431 update_vfd();
28432+ mutex_unlock(&vfd_mutex);
28433
28434 return len;
28435 }
28436diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
28437index f773a9d..65cd683 100644
28438--- a/drivers/char/genrtc.c
28439+++ b/drivers/char/genrtc.c
28440@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
28441 switch (cmd) {
28442
28443 case RTC_PLL_GET:
28444+ memset(&pll, 0, sizeof(pll));
28445 if (get_rtc_pll(&pll))
28446 return -EINVAL;
28447 else
28448diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
28449index 0833896..cccce52 100644
28450--- a/drivers/char/hpet.c
28451+++ b/drivers/char/hpet.c
28452@@ -572,7 +572,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
28453 }
28454
28455 static int
28456-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
28457+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
28458 struct hpet_info *info)
28459 {
28460 struct hpet_timer __iomem *timer;
28461diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
28462index 58c0e63..46c16bf 100644
28463--- a/drivers/char/ipmi/ipmi_msghandler.c
28464+++ b/drivers/char/ipmi/ipmi_msghandler.c
28465@@ -415,7 +415,7 @@ struct ipmi_smi {
28466 struct proc_dir_entry *proc_dir;
28467 char proc_dir_name[10];
28468
28469- atomic_t stats[IPMI_NUM_STATS];
28470+ atomic_unchecked_t stats[IPMI_NUM_STATS];
28471
28472 /*
28473 * run_to_completion duplicate of smb_info, smi_info
28474@@ -448,9 +448,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
28475
28476
28477 #define ipmi_inc_stat(intf, stat) \
28478- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
28479+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
28480 #define ipmi_get_stat(intf, stat) \
28481- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
28482+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
28483
28484 static int is_lan_addr(struct ipmi_addr *addr)
28485 {
28486@@ -2868,7 +2868,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
28487 INIT_LIST_HEAD(&intf->cmd_rcvrs);
28488 init_waitqueue_head(&intf->waitq);
28489 for (i = 0; i < IPMI_NUM_STATS; i++)
28490- atomic_set(&intf->stats[i], 0);
28491+ atomic_set_unchecked(&intf->stats[i], 0);
28492
28493 intf->proc_dir = NULL;
28494
28495diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
28496index 50fcf9c..91b5528 100644
28497--- a/drivers/char/ipmi/ipmi_si_intf.c
28498+++ b/drivers/char/ipmi/ipmi_si_intf.c
28499@@ -277,7 +277,7 @@ struct smi_info {
28500 unsigned char slave_addr;
28501
28502 /* Counters and things for the proc filesystem. */
28503- atomic_t stats[SI_NUM_STATS];
28504+ atomic_unchecked_t stats[SI_NUM_STATS];
28505
28506 struct task_struct *thread;
28507
28508@@ -286,9 +286,9 @@ struct smi_info {
28509 };
28510
28511 #define smi_inc_stat(smi, stat) \
28512- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
28513+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
28514 #define smi_get_stat(smi, stat) \
28515- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
28516+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
28517
28518 #define SI_MAX_PARMS 4
28519
28520@@ -3230,7 +3230,7 @@ static int try_smi_init(struct smi_info *new_smi)
28521 atomic_set(&new_smi->req_events, 0);
28522 new_smi->run_to_completion = 0;
28523 for (i = 0; i < SI_NUM_STATS; i++)
28524- atomic_set(&new_smi->stats[i], 0);
28525+ atomic_set_unchecked(&new_smi->stats[i], 0);
28526
28527 new_smi->interrupt_disabled = 1;
28528 atomic_set(&new_smi->stop_operation, 0);
28529diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
28530index 1aeaaba..e018570 100644
28531--- a/drivers/char/mbcs.c
28532+++ b/drivers/char/mbcs.c
28533@@ -800,7 +800,7 @@ static int mbcs_remove(struct cx_dev *dev)
28534 return 0;
28535 }
28536
28537-static const struct cx_device_id __devinitdata mbcs_id_table[] = {
28538+static const struct cx_device_id __devinitconst mbcs_id_table[] = {
28539 {
28540 .part_num = MBCS_PART_NUM,
28541 .mfg_num = MBCS_MFG_NUM,
28542diff --git a/drivers/char/mem.c b/drivers/char/mem.c
28543index d6e9d08..4493e89 100644
28544--- a/drivers/char/mem.c
28545+++ b/drivers/char/mem.c
28546@@ -18,6 +18,7 @@
28547 #include <linux/raw.h>
28548 #include <linux/tty.h>
28549 #include <linux/capability.h>
28550+#include <linux/security.h>
28551 #include <linux/ptrace.h>
28552 #include <linux/device.h>
28553 #include <linux/highmem.h>
28554@@ -35,6 +36,10 @@
28555 # include <linux/efi.h>
28556 #endif
28557
28558+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
28559+extern const struct file_operations grsec_fops;
28560+#endif
28561+
28562 static inline unsigned long size_inside_page(unsigned long start,
28563 unsigned long size)
28564 {
28565@@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28566
28567 while (cursor < to) {
28568 if (!devmem_is_allowed(pfn)) {
28569+#ifdef CONFIG_GRKERNSEC_KMEM
28570+ gr_handle_mem_readwrite(from, to);
28571+#else
28572 printk(KERN_INFO
28573 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
28574 current->comm, from, to);
28575+#endif
28576 return 0;
28577 }
28578 cursor += PAGE_SIZE;
28579@@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28580 }
28581 return 1;
28582 }
28583+#elif defined(CONFIG_GRKERNSEC_KMEM)
28584+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28585+{
28586+ return 0;
28587+}
28588 #else
28589 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28590 {
28591@@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
28592
28593 while (count > 0) {
28594 unsigned long remaining;
28595+ char *temp;
28596
28597 sz = size_inside_page(p, count);
28598
28599@@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
28600 if (!ptr)
28601 return -EFAULT;
28602
28603- remaining = copy_to_user(buf, ptr, sz);
28604+#ifdef CONFIG_PAX_USERCOPY
28605+ temp = kmalloc(sz, GFP_KERNEL);
28606+ if (!temp) {
28607+ unxlate_dev_mem_ptr(p, ptr);
28608+ return -ENOMEM;
28609+ }
28610+ memcpy(temp, ptr, sz);
28611+#else
28612+ temp = ptr;
28613+#endif
28614+
28615+ remaining = copy_to_user(buf, temp, sz);
28616+
28617+#ifdef CONFIG_PAX_USERCOPY
28618+ kfree(temp);
28619+#endif
28620+
28621 unxlate_dev_mem_ptr(p, ptr);
28622 if (remaining)
28623 return -EFAULT;
28624@@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
28625 size_t count, loff_t *ppos)
28626 {
28627 unsigned long p = *ppos;
28628- ssize_t low_count, read, sz;
28629+ ssize_t low_count, read, sz, err = 0;
28630 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
28631- int err = 0;
28632
28633 read = 0;
28634 if (p < (unsigned long) high_memory) {
28635@@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
28636 }
28637 #endif
28638 while (low_count > 0) {
28639+ char *temp;
28640+
28641 sz = size_inside_page(p, low_count);
28642
28643 /*
28644@@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
28645 */
28646 kbuf = xlate_dev_kmem_ptr((char *)p);
28647
28648- if (copy_to_user(buf, kbuf, sz))
28649+#ifdef CONFIG_PAX_USERCOPY
28650+ temp = kmalloc(sz, GFP_KERNEL);
28651+ if (!temp)
28652+ return -ENOMEM;
28653+ memcpy(temp, kbuf, sz);
28654+#else
28655+ temp = kbuf;
28656+#endif
28657+
28658+ err = copy_to_user(buf, temp, sz);
28659+
28660+#ifdef CONFIG_PAX_USERCOPY
28661+ kfree(temp);
28662+#endif
28663+
28664+ if (err)
28665 return -EFAULT;
28666 buf += sz;
28667 p += sz;
28668@@ -867,6 +914,9 @@ static const struct memdev {
28669 #ifdef CONFIG_CRASH_DUMP
28670 [12] = { "oldmem", 0, &oldmem_fops, NULL },
28671 #endif
28672+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
28673+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
28674+#endif
28675 };
28676
28677 static int memory_open(struct inode *inode, struct file *filp)
28678diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
28679index da3cfee..a5a6606 100644
28680--- a/drivers/char/nvram.c
28681+++ b/drivers/char/nvram.c
28682@@ -248,7 +248,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
28683
28684 spin_unlock_irq(&rtc_lock);
28685
28686- if (copy_to_user(buf, contents, tmp - contents))
28687+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
28688 return -EFAULT;
28689
28690 *ppos = i;
28691diff --git a/drivers/char/random.c b/drivers/char/random.c
28692index 54ca8b2..d58cb51 100644
28693--- a/drivers/char/random.c
28694+++ b/drivers/char/random.c
28695@@ -261,8 +261,13 @@
28696 /*
28697 * Configuration information
28698 */
28699+#ifdef CONFIG_GRKERNSEC_RANDNET
28700+#define INPUT_POOL_WORDS 512
28701+#define OUTPUT_POOL_WORDS 128
28702+#else
28703 #define INPUT_POOL_WORDS 128
28704 #define OUTPUT_POOL_WORDS 32
28705+#endif
28706 #define SEC_XFER_SIZE 512
28707 #define EXTRACT_SIZE 10
28708
28709@@ -300,10 +305,17 @@ static struct poolinfo {
28710 int poolwords;
28711 int tap1, tap2, tap3, tap4, tap5;
28712 } poolinfo_table[] = {
28713+#ifdef CONFIG_GRKERNSEC_RANDNET
28714+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
28715+ { 512, 411, 308, 208, 104, 1 },
28716+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
28717+ { 128, 103, 76, 51, 25, 1 },
28718+#else
28719 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
28720 { 128, 103, 76, 51, 25, 1 },
28721 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
28722 { 32, 26, 20, 14, 7, 1 },
28723+#endif
28724 #if 0
28725 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
28726 { 2048, 1638, 1231, 819, 411, 1 },
28727@@ -913,7 +925,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
28728
28729 extract_buf(r, tmp);
28730 i = min_t(int, nbytes, EXTRACT_SIZE);
28731- if (copy_to_user(buf, tmp, i)) {
28732+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
28733 ret = -EFAULT;
28734 break;
28735 }
28736@@ -1238,7 +1250,7 @@ EXPORT_SYMBOL(generate_random_uuid);
28737 #include <linux/sysctl.h>
28738
28739 static int min_read_thresh = 8, min_write_thresh;
28740-static int max_read_thresh = INPUT_POOL_WORDS * 32;
28741+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
28742 static int max_write_thresh = INPUT_POOL_WORDS * 32;
28743 static char sysctl_bootid[16];
28744
28745diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
28746index 1ee8ce7..b778bef 100644
28747--- a/drivers/char/sonypi.c
28748+++ b/drivers/char/sonypi.c
28749@@ -55,6 +55,7 @@
28750 #include <asm/uaccess.h>
28751 #include <asm/io.h>
28752 #include <asm/system.h>
28753+#include <asm/local.h>
28754
28755 #include <linux/sonypi.h>
28756
28757@@ -491,7 +492,7 @@ static struct sonypi_device {
28758 spinlock_t fifo_lock;
28759 wait_queue_head_t fifo_proc_list;
28760 struct fasync_struct *fifo_async;
28761- int open_count;
28762+ local_t open_count;
28763 int model;
28764 struct input_dev *input_jog_dev;
28765 struct input_dev *input_key_dev;
28766@@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
28767 static int sonypi_misc_release(struct inode *inode, struct file *file)
28768 {
28769 mutex_lock(&sonypi_device.lock);
28770- sonypi_device.open_count--;
28771+ local_dec(&sonypi_device.open_count);
28772 mutex_unlock(&sonypi_device.lock);
28773 return 0;
28774 }
28775@@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
28776 {
28777 mutex_lock(&sonypi_device.lock);
28778 /* Flush input queue on first open */
28779- if (!sonypi_device.open_count)
28780+ if (!local_read(&sonypi_device.open_count))
28781 kfifo_reset(&sonypi_device.fifo);
28782- sonypi_device.open_count++;
28783+ local_inc(&sonypi_device.open_count);
28784 mutex_unlock(&sonypi_device.lock);
28785
28786 return 0;
28787diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
28788index ad7c732..5aa8054 100644
28789--- a/drivers/char/tpm/tpm.c
28790+++ b/drivers/char/tpm/tpm.c
28791@@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
28792 chip->vendor.req_complete_val)
28793 goto out_recv;
28794
28795- if ((status == chip->vendor.req_canceled)) {
28796+ if (status == chip->vendor.req_canceled) {
28797 dev_err(chip->dev, "Operation Canceled\n");
28798 rc = -ECANCELED;
28799 goto out;
28800diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
28801index 0636520..169c1d0 100644
28802--- a/drivers/char/tpm/tpm_bios.c
28803+++ b/drivers/char/tpm/tpm_bios.c
28804@@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
28805 event = addr;
28806
28807 if ((event->event_type == 0 && event->event_size == 0) ||
28808- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
28809+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
28810 return NULL;
28811
28812 return addr;
28813@@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
28814 return NULL;
28815
28816 if ((event->event_type == 0 && event->event_size == 0) ||
28817- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
28818+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
28819 return NULL;
28820
28821 (*pos)++;
28822@@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
28823 int i;
28824
28825 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
28826- seq_putc(m, data[i]);
28827+ if (!seq_putc(m, data[i]))
28828+ return -EFAULT;
28829
28830 return 0;
28831 }
28832@@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
28833 log->bios_event_log_end = log->bios_event_log + len;
28834
28835 virt = acpi_os_map_memory(start, len);
28836+ if (!virt) {
28837+ kfree(log->bios_event_log);
28838+ log->bios_event_log = NULL;
28839+ return -EFAULT;
28840+ }
28841
28842- memcpy(log->bios_event_log, virt, len);
28843+ memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
28844
28845 acpi_os_unmap_memory(virt, len);
28846 return 0;
28847diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
28848index b58b561..c9088c8 100644
28849--- a/drivers/char/virtio_console.c
28850+++ b/drivers/char/virtio_console.c
28851@@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
28852 if (to_user) {
28853 ssize_t ret;
28854
28855- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
28856+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
28857 if (ret)
28858 return -EFAULT;
28859 } else {
28860@@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
28861 if (!port_has_data(port) && !port->host_connected)
28862 return 0;
28863
28864- return fill_readbuf(port, ubuf, count, true);
28865+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
28866 }
28867
28868 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
28869diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
28870index c9eee6d..f9d5280 100644
28871--- a/drivers/edac/amd64_edac.c
28872+++ b/drivers/edac/amd64_edac.c
28873@@ -2685,7 +2685,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
28874 * PCI core identifies what devices are on a system during boot, and then
28875 * inquiry this table to see if this driver is for a given device found.
28876 */
28877-static const struct pci_device_id amd64_pci_table[] __devinitdata = {
28878+static const struct pci_device_id amd64_pci_table[] __devinitconst = {
28879 {
28880 .vendor = PCI_VENDOR_ID_AMD,
28881 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
28882diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
28883index e47e73b..348e0bd 100644
28884--- a/drivers/edac/amd76x_edac.c
28885+++ b/drivers/edac/amd76x_edac.c
28886@@ -321,7 +321,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
28887 edac_mc_free(mci);
28888 }
28889
28890-static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
28891+static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
28892 {
28893 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
28894 AMD762},
28895diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
28896index 1af531a..3a8ff27 100644
28897--- a/drivers/edac/e752x_edac.c
28898+++ b/drivers/edac/e752x_edac.c
28899@@ -1380,7 +1380,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
28900 edac_mc_free(mci);
28901 }
28902
28903-static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
28904+static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
28905 {
28906 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
28907 E7520},
28908diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
28909index 6ffb6d2..383d8d7 100644
28910--- a/drivers/edac/e7xxx_edac.c
28911+++ b/drivers/edac/e7xxx_edac.c
28912@@ -525,7 +525,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
28913 edac_mc_free(mci);
28914 }
28915
28916-static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
28917+static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
28918 {
28919 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
28920 E7205},
28921diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
28922index 97f5064..202b6e6 100644
28923--- a/drivers/edac/edac_pci_sysfs.c
28924+++ b/drivers/edac/edac_pci_sysfs.c
28925@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
28926 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
28927 static int edac_pci_poll_msec = 1000; /* one second workq period */
28928
28929-static atomic_t pci_parity_count = ATOMIC_INIT(0);
28930-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
28931+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
28932+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
28933
28934 static struct kobject *edac_pci_top_main_kobj;
28935 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
28936@@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28937 edac_printk(KERN_CRIT, EDAC_PCI,
28938 "Signaled System Error on %s\n",
28939 pci_name(dev));
28940- atomic_inc(&pci_nonparity_count);
28941+ atomic_inc_unchecked(&pci_nonparity_count);
28942 }
28943
28944 if (status & (PCI_STATUS_PARITY)) {
28945@@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28946 "Master Data Parity Error on %s\n",
28947 pci_name(dev));
28948
28949- atomic_inc(&pci_parity_count);
28950+ atomic_inc_unchecked(&pci_parity_count);
28951 }
28952
28953 if (status & (PCI_STATUS_DETECTED_PARITY)) {
28954@@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28955 "Detected Parity Error on %s\n",
28956 pci_name(dev));
28957
28958- atomic_inc(&pci_parity_count);
28959+ atomic_inc_unchecked(&pci_parity_count);
28960 }
28961 }
28962
28963@@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28964 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
28965 "Signaled System Error on %s\n",
28966 pci_name(dev));
28967- atomic_inc(&pci_nonparity_count);
28968+ atomic_inc_unchecked(&pci_nonparity_count);
28969 }
28970
28971 if (status & (PCI_STATUS_PARITY)) {
28972@@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28973 "Master Data Parity Error on "
28974 "%s\n", pci_name(dev));
28975
28976- atomic_inc(&pci_parity_count);
28977+ atomic_inc_unchecked(&pci_parity_count);
28978 }
28979
28980 if (status & (PCI_STATUS_DETECTED_PARITY)) {
28981@@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
28982 "Detected Parity Error on %s\n",
28983 pci_name(dev));
28984
28985- atomic_inc(&pci_parity_count);
28986+ atomic_inc_unchecked(&pci_parity_count);
28987 }
28988 }
28989 }
28990@@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
28991 if (!check_pci_errors)
28992 return;
28993
28994- before_count = atomic_read(&pci_parity_count);
28995+ before_count = atomic_read_unchecked(&pci_parity_count);
28996
28997 /* scan all PCI devices looking for a Parity Error on devices and
28998 * bridges.
28999@@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29000 /* Only if operator has selected panic on PCI Error */
29001 if (edac_pci_get_panic_on_pe()) {
29002 /* If the count is different 'after' from 'before' */
29003- if (before_count != atomic_read(&pci_parity_count))
29004+ if (before_count != atomic_read_unchecked(&pci_parity_count))
29005 panic("EDAC: PCI Parity Error");
29006 }
29007 }
29008diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
29009index c0510b3..6e2a954 100644
29010--- a/drivers/edac/i3000_edac.c
29011+++ b/drivers/edac/i3000_edac.c
29012@@ -470,7 +470,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
29013 edac_mc_free(mci);
29014 }
29015
29016-static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
29017+static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
29018 {
29019 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29020 I3000},
29021diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
29022index 73f55e200..5faaf59 100644
29023--- a/drivers/edac/i3200_edac.c
29024+++ b/drivers/edac/i3200_edac.c
29025@@ -445,7 +445,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
29026 edac_mc_free(mci);
29027 }
29028
29029-static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
29030+static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
29031 {
29032 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29033 I3200},
29034diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
29035index 4dc3ac2..67d05a6 100644
29036--- a/drivers/edac/i5000_edac.c
29037+++ b/drivers/edac/i5000_edac.c
29038@@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
29039 *
29040 * The "E500P" device is the first device supported.
29041 */
29042-static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
29043+static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
29044 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
29045 .driver_data = I5000P},
29046
29047diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
29048index bcbdeec..9886d16 100644
29049--- a/drivers/edac/i5100_edac.c
29050+++ b/drivers/edac/i5100_edac.c
29051@@ -1051,7 +1051,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
29052 edac_mc_free(mci);
29053 }
29054
29055-static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
29056+static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
29057 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
29058 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
29059 { 0, }
29060diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
29061index 74d6ec34..baff517 100644
29062--- a/drivers/edac/i5400_edac.c
29063+++ b/drivers/edac/i5400_edac.c
29064@@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
29065 *
29066 * The "E500P" device is the first device supported.
29067 */
29068-static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
29069+static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
29070 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
29071 {0,} /* 0 terminated list. */
29072 };
29073diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
29074index 6104dba..e7ea8e1 100644
29075--- a/drivers/edac/i7300_edac.c
29076+++ b/drivers/edac/i7300_edac.c
29077@@ -1192,7 +1192,7 @@ static void __devexit i7300_remove_one(struct pci_dev *pdev)
29078 *
29079 * Has only 8086:360c PCI ID
29080 */
29081-static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
29082+static const struct pci_device_id i7300_pci_tbl[] __devinitconst = {
29083 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
29084 {0,} /* 0 terminated list. */
29085 };
29086diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
29087index 8568d9b..42b2fa8 100644
29088--- a/drivers/edac/i7core_edac.c
29089+++ b/drivers/edac/i7core_edac.c
29090@@ -391,7 +391,7 @@ static const struct pci_id_table pci_dev_table[] = {
29091 /*
29092 * pci_device_id table for which devices we are looking for
29093 */
29094-static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
29095+static const struct pci_device_id i7core_pci_tbl[] __devinitconst = {
29096 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
29097 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)},
29098 {0,} /* 0 terminated list. */
29099diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
29100index 4329d39..f3022ef 100644
29101--- a/drivers/edac/i82443bxgx_edac.c
29102+++ b/drivers/edac/i82443bxgx_edac.c
29103@@ -380,7 +380,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
29104
29105 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
29106
29107-static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
29108+static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
29109 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
29110 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
29111 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
29112diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
29113index 931a057..fd28340 100644
29114--- a/drivers/edac/i82860_edac.c
29115+++ b/drivers/edac/i82860_edac.c
29116@@ -270,7 +270,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
29117 edac_mc_free(mci);
29118 }
29119
29120-static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
29121+static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
29122 {
29123 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29124 I82860},
29125diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
29126index 33864c6..01edc61 100644
29127--- a/drivers/edac/i82875p_edac.c
29128+++ b/drivers/edac/i82875p_edac.c
29129@@ -511,7 +511,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
29130 edac_mc_free(mci);
29131 }
29132
29133-static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
29134+static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
29135 {
29136 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29137 I82875P},
29138diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
29139index 4184e01..dcb2cd3 100644
29140--- a/drivers/edac/i82975x_edac.c
29141+++ b/drivers/edac/i82975x_edac.c
29142@@ -612,7 +612,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
29143 edac_mc_free(mci);
29144 }
29145
29146-static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
29147+static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
29148 {
29149 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29150 I82975X
29151diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29152index 0106747..0b40417 100644
29153--- a/drivers/edac/mce_amd.h
29154+++ b/drivers/edac/mce_amd.h
29155@@ -83,7 +83,7 @@ struct amd_decoder_ops {
29156 bool (*dc_mce)(u16, u8);
29157 bool (*ic_mce)(u16, u8);
29158 bool (*nb_mce)(u16, u8);
29159-};
29160+} __no_const;
29161
29162 void amd_report_gart_errors(bool);
29163 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
29164diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
29165index e294e1b..a41b05b 100644
29166--- a/drivers/edac/r82600_edac.c
29167+++ b/drivers/edac/r82600_edac.c
29168@@ -373,7 +373,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
29169 edac_mc_free(mci);
29170 }
29171
29172-static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
29173+static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
29174 {
29175 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
29176 },
29177diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
29178index 1dc118d..8c68af9 100644
29179--- a/drivers/edac/sb_edac.c
29180+++ b/drivers/edac/sb_edac.c
29181@@ -367,7 +367,7 @@ static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
29182 /*
29183 * pci_device_id table for which devices we are looking for
29184 */
29185-static const struct pci_device_id sbridge_pci_tbl[] __devinitdata = {
29186+static const struct pci_device_id sbridge_pci_tbl[] __devinitconst = {
29187 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)},
29188 {0,} /* 0 terminated list. */
29189 };
29190diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
29191index b6f47de..c5acf3a 100644
29192--- a/drivers/edac/x38_edac.c
29193+++ b/drivers/edac/x38_edac.c
29194@@ -440,7 +440,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
29195 edac_mc_free(mci);
29196 }
29197
29198-static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
29199+static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
29200 {
29201 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29202 X38},
29203diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
29204index 85661b0..c784559a 100644
29205--- a/drivers/firewire/core-card.c
29206+++ b/drivers/firewire/core-card.c
29207@@ -657,7 +657,7 @@ void fw_card_release(struct kref *kref)
29208
29209 void fw_core_remove_card(struct fw_card *card)
29210 {
29211- struct fw_card_driver dummy_driver = dummy_driver_template;
29212+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
29213
29214 card->driver->update_phy_reg(card, 4,
29215 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
29216diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
29217index 4799393..37bd3ab 100644
29218--- a/drivers/firewire/core-cdev.c
29219+++ b/drivers/firewire/core-cdev.c
29220@@ -1331,8 +1331,7 @@ static int init_iso_resource(struct client *client,
29221 int ret;
29222
29223 if ((request->channels == 0 && request->bandwidth == 0) ||
29224- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
29225- request->bandwidth < 0)
29226+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
29227 return -EINVAL;
29228
29229 r = kmalloc(sizeof(*r), GFP_KERNEL);
29230diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
29231index 855ab3f..11f4bbd 100644
29232--- a/drivers/firewire/core-transaction.c
29233+++ b/drivers/firewire/core-transaction.c
29234@@ -37,6 +37,7 @@
29235 #include <linux/timer.h>
29236 #include <linux/types.h>
29237 #include <linux/workqueue.h>
29238+#include <linux/sched.h>
29239
29240 #include <asm/byteorder.h>
29241
29242diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
29243index b45be57..5fad18b 100644
29244--- a/drivers/firewire/core.h
29245+++ b/drivers/firewire/core.h
29246@@ -101,6 +101,7 @@ struct fw_card_driver {
29247
29248 int (*stop_iso)(struct fw_iso_context *ctx);
29249 };
29250+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
29251
29252 void fw_card_initialize(struct fw_card *card,
29253 const struct fw_card_driver *driver, struct device *device);
29254diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
29255index 153980b..4b4d046 100644
29256--- a/drivers/firmware/dmi_scan.c
29257+++ b/drivers/firmware/dmi_scan.c
29258@@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
29259 }
29260 }
29261 else {
29262- /*
29263- * no iounmap() for that ioremap(); it would be a no-op, but
29264- * it's so early in setup that sucker gets confused into doing
29265- * what it shouldn't if we actually call it.
29266- */
29267 p = dmi_ioremap(0xF0000, 0x10000);
29268 if (p == NULL)
29269 goto error;
29270@@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
29271 if (buf == NULL)
29272 return -1;
29273
29274- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
29275+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
29276
29277 iounmap(buf);
29278 return 0;
29279diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
29280index 82d5c20..44a7177 100644
29281--- a/drivers/gpio/gpio-vr41xx.c
29282+++ b/drivers/gpio/gpio-vr41xx.c
29283@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
29284 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
29285 maskl, pendl, maskh, pendh);
29286
29287- atomic_inc(&irq_err_count);
29288+ atomic_inc_unchecked(&irq_err_count);
29289
29290 return -EINVAL;
29291 }
29292diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
29293index 84a4a80..ce0306e 100644
29294--- a/drivers/gpu/drm/drm_crtc_helper.c
29295+++ b/drivers/gpu/drm/drm_crtc_helper.c
29296@@ -280,7 +280,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
29297 struct drm_crtc *tmp;
29298 int crtc_mask = 1;
29299
29300- WARN(!crtc, "checking null crtc?\n");
29301+ BUG_ON(!crtc);
29302
29303 dev = crtc->dev;
29304
29305diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
29306index ebf7d3f..d64c436 100644
29307--- a/drivers/gpu/drm/drm_drv.c
29308+++ b/drivers/gpu/drm/drm_drv.c
29309@@ -312,7 +312,7 @@ module_exit(drm_core_exit);
29310 /**
29311 * Copy and IOCTL return string to user space
29312 */
29313-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
29314+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
29315 {
29316 int len;
29317
29318@@ -391,7 +391,7 @@ long drm_ioctl(struct file *filp,
29319
29320 dev = file_priv->minor->dev;
29321 atomic_inc(&dev->ioctl_count);
29322- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
29323+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
29324 ++file_priv->ioctl_count;
29325
29326 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
29327diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
29328index 6263b01..7987f55 100644
29329--- a/drivers/gpu/drm/drm_fops.c
29330+++ b/drivers/gpu/drm/drm_fops.c
29331@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
29332 }
29333
29334 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
29335- atomic_set(&dev->counts[i], 0);
29336+ atomic_set_unchecked(&dev->counts[i], 0);
29337
29338 dev->sigdata.lock = NULL;
29339
29340@@ -135,8 +135,8 @@ int drm_open(struct inode *inode, struct file *filp)
29341
29342 retcode = drm_open_helper(inode, filp, dev);
29343 if (!retcode) {
29344- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
29345- if (!dev->open_count++)
29346+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
29347+ if (local_inc_return(&dev->open_count) == 1)
29348 retcode = drm_setup(dev);
29349 }
29350 if (!retcode) {
29351@@ -473,7 +473,7 @@ int drm_release(struct inode *inode, struct file *filp)
29352
29353 mutex_lock(&drm_global_mutex);
29354
29355- DRM_DEBUG("open_count = %d\n", dev->open_count);
29356+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
29357
29358 if (dev->driver->preclose)
29359 dev->driver->preclose(dev, file_priv);
29360@@ -482,10 +482,10 @@ int drm_release(struct inode *inode, struct file *filp)
29361 * Begin inline drm_release
29362 */
29363
29364- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
29365+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
29366 task_pid_nr(current),
29367 (long)old_encode_dev(file_priv->minor->device),
29368- dev->open_count);
29369+ local_read(&dev->open_count));
29370
29371 /* Release any auth tokens that might point to this file_priv,
29372 (do that under the drm_global_mutex) */
29373@@ -571,8 +571,8 @@ int drm_release(struct inode *inode, struct file *filp)
29374 * End inline drm_release
29375 */
29376
29377- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
29378- if (!--dev->open_count) {
29379+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
29380+ if (local_dec_and_test(&dev->open_count)) {
29381 if (atomic_read(&dev->ioctl_count)) {
29382 DRM_ERROR("Device busy: %d\n",
29383 atomic_read(&dev->ioctl_count));
29384diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
29385index c87dc96..326055d 100644
29386--- a/drivers/gpu/drm/drm_global.c
29387+++ b/drivers/gpu/drm/drm_global.c
29388@@ -36,7 +36,7 @@
29389 struct drm_global_item {
29390 struct mutex mutex;
29391 void *object;
29392- int refcount;
29393+ atomic_t refcount;
29394 };
29395
29396 static struct drm_global_item glob[DRM_GLOBAL_NUM];
29397@@ -49,7 +49,7 @@ void drm_global_init(void)
29398 struct drm_global_item *item = &glob[i];
29399 mutex_init(&item->mutex);
29400 item->object = NULL;
29401- item->refcount = 0;
29402+ atomic_set(&item->refcount, 0);
29403 }
29404 }
29405
29406@@ -59,7 +59,7 @@ void drm_global_release(void)
29407 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
29408 struct drm_global_item *item = &glob[i];
29409 BUG_ON(item->object != NULL);
29410- BUG_ON(item->refcount != 0);
29411+ BUG_ON(atomic_read(&item->refcount) != 0);
29412 }
29413 }
29414
29415@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
29416 void *object;
29417
29418 mutex_lock(&item->mutex);
29419- if (item->refcount == 0) {
29420+ if (atomic_read(&item->refcount) == 0) {
29421 item->object = kzalloc(ref->size, GFP_KERNEL);
29422 if (unlikely(item->object == NULL)) {
29423 ret = -ENOMEM;
29424@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
29425 goto out_err;
29426
29427 }
29428- ++item->refcount;
29429+ atomic_inc(&item->refcount);
29430 ref->object = item->object;
29431 object = item->object;
29432 mutex_unlock(&item->mutex);
29433@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
29434 struct drm_global_item *item = &glob[ref->global_type];
29435
29436 mutex_lock(&item->mutex);
29437- BUG_ON(item->refcount == 0);
29438+ BUG_ON(atomic_read(&item->refcount) == 0);
29439 BUG_ON(ref->object != item->object);
29440- if (--item->refcount == 0) {
29441+ if (atomic_dec_and_test(&item->refcount)) {
29442 ref->release(ref);
29443 item->object = NULL;
29444 }
29445diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
29446index ab1162d..42587b2 100644
29447--- a/drivers/gpu/drm/drm_info.c
29448+++ b/drivers/gpu/drm/drm_info.c
29449@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
29450 struct drm_local_map *map;
29451 struct drm_map_list *r_list;
29452
29453- /* Hardcoded from _DRM_FRAME_BUFFER,
29454- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
29455- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
29456- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
29457+ static const char * const types[] = {
29458+ [_DRM_FRAME_BUFFER] = "FB",
29459+ [_DRM_REGISTERS] = "REG",
29460+ [_DRM_SHM] = "SHM",
29461+ [_DRM_AGP] = "AGP",
29462+ [_DRM_SCATTER_GATHER] = "SG",
29463+ [_DRM_CONSISTENT] = "PCI",
29464+ [_DRM_GEM] = "GEM" };
29465 const char *type;
29466 int i;
29467
29468@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
29469 map = r_list->map;
29470 if (!map)
29471 continue;
29472- if (map->type < 0 || map->type > 5)
29473+ if (map->type >= ARRAY_SIZE(types))
29474 type = "??";
29475 else
29476 type = types[map->type];
29477@@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
29478 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
29479 vma->vm_flags & VM_LOCKED ? 'l' : '-',
29480 vma->vm_flags & VM_IO ? 'i' : '-',
29481+#ifdef CONFIG_GRKERNSEC_HIDESYM
29482+ 0);
29483+#else
29484 vma->vm_pgoff);
29485+#endif
29486
29487 #if defined(__i386__)
29488 pgprot = pgprot_val(vma->vm_page_prot);
29489diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
29490index 637fcc3..e890b33 100644
29491--- a/drivers/gpu/drm/drm_ioc32.c
29492+++ b/drivers/gpu/drm/drm_ioc32.c
29493@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
29494 request = compat_alloc_user_space(nbytes);
29495 if (!access_ok(VERIFY_WRITE, request, nbytes))
29496 return -EFAULT;
29497- list = (struct drm_buf_desc *) (request + 1);
29498+ list = (struct drm_buf_desc __user *) (request + 1);
29499
29500 if (__put_user(count, &request->count)
29501 || __put_user(list, &request->list))
29502@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
29503 request = compat_alloc_user_space(nbytes);
29504 if (!access_ok(VERIFY_WRITE, request, nbytes))
29505 return -EFAULT;
29506- list = (struct drm_buf_pub *) (request + 1);
29507+ list = (struct drm_buf_pub __user *) (request + 1);
29508
29509 if (__put_user(count, &request->count)
29510 || __put_user(list, &request->list))
29511diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
29512index 956fd38..e52167a 100644
29513--- a/drivers/gpu/drm/drm_ioctl.c
29514+++ b/drivers/gpu/drm/drm_ioctl.c
29515@@ -251,7 +251,7 @@ int drm_getstats(struct drm_device *dev, void *data,
29516 stats->data[i].value =
29517 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
29518 else
29519- stats->data[i].value = atomic_read(&dev->counts[i]);
29520+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
29521 stats->data[i].type = dev->types[i];
29522 }
29523
29524diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
29525index c79c713..2048588 100644
29526--- a/drivers/gpu/drm/drm_lock.c
29527+++ b/drivers/gpu/drm/drm_lock.c
29528@@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
29529 if (drm_lock_take(&master->lock, lock->context)) {
29530 master->lock.file_priv = file_priv;
29531 master->lock.lock_time = jiffies;
29532- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
29533+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
29534 break; /* Got lock */
29535 }
29536
29537@@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
29538 return -EINVAL;
29539 }
29540
29541- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
29542+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
29543
29544 if (drm_lock_free(&master->lock, lock->context)) {
29545 /* FIXME: Should really bail out here. */
29546diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
29547index 7f4b4e1..bf4def2 100644
29548--- a/drivers/gpu/drm/i810/i810_dma.c
29549+++ b/drivers/gpu/drm/i810/i810_dma.c
29550@@ -948,8 +948,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
29551 dma->buflist[vertex->idx],
29552 vertex->discard, vertex->used);
29553
29554- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
29555- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
29556+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
29557+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
29558 sarea_priv->last_enqueue = dev_priv->counter - 1;
29559 sarea_priv->last_dispatch = (int)hw_status[5];
29560
29561@@ -1109,8 +1109,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
29562 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
29563 mc->last_render);
29564
29565- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
29566- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
29567+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
29568+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
29569 sarea_priv->last_enqueue = dev_priv->counter - 1;
29570 sarea_priv->last_dispatch = (int)hw_status[5];
29571
29572diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
29573index c9339f4..f5e1b9d 100644
29574--- a/drivers/gpu/drm/i810/i810_drv.h
29575+++ b/drivers/gpu/drm/i810/i810_drv.h
29576@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
29577 int page_flipping;
29578
29579 wait_queue_head_t irq_queue;
29580- atomic_t irq_received;
29581- atomic_t irq_emitted;
29582+ atomic_unchecked_t irq_received;
29583+ atomic_unchecked_t irq_emitted;
29584
29585 int front_offset;
29586 } drm_i810_private_t;
29587diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
29588index deaa657..e0fd296 100644
29589--- a/drivers/gpu/drm/i915/i915_debugfs.c
29590+++ b/drivers/gpu/drm/i915/i915_debugfs.c
29591@@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
29592 I915_READ(GTIMR));
29593 }
29594 seq_printf(m, "Interrupts received: %d\n",
29595- atomic_read(&dev_priv->irq_received));
29596+ atomic_read_unchecked(&dev_priv->irq_received));
29597 for (i = 0; i < I915_NUM_RINGS; i++) {
29598 if (IS_GEN6(dev) || IS_GEN7(dev)) {
29599 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
29600@@ -1321,7 +1321,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
29601 return ret;
29602
29603 if (opregion->header)
29604- seq_write(m, opregion->header, OPREGION_SIZE);
29605+ seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
29606
29607 mutex_unlock(&dev->struct_mutex);
29608
29609diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
29610index ddfe3d9..f6e6b21 100644
29611--- a/drivers/gpu/drm/i915/i915_dma.c
29612+++ b/drivers/gpu/drm/i915/i915_dma.c
29613@@ -1175,7 +1175,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
29614 bool can_switch;
29615
29616 spin_lock(&dev->count_lock);
29617- can_switch = (dev->open_count == 0);
29618+ can_switch = (local_read(&dev->open_count) == 0);
29619 spin_unlock(&dev->count_lock);
29620 return can_switch;
29621 }
29622diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
29623index 9689ca3..294f9c1 100644
29624--- a/drivers/gpu/drm/i915/i915_drv.h
29625+++ b/drivers/gpu/drm/i915/i915_drv.h
29626@@ -231,7 +231,7 @@ struct drm_i915_display_funcs {
29627 /* render clock increase/decrease */
29628 /* display clock increase/decrease */
29629 /* pll clock increase/decrease */
29630-};
29631+} __no_const;
29632
29633 struct intel_device_info {
29634 u8 gen;
29635@@ -320,7 +320,7 @@ typedef struct drm_i915_private {
29636 int current_page;
29637 int page_flipping;
29638
29639- atomic_t irq_received;
29640+ atomic_unchecked_t irq_received;
29641
29642 /* protects the irq masks */
29643 spinlock_t irq_lock;
29644@@ -896,7 +896,7 @@ struct drm_i915_gem_object {
29645 * will be page flipped away on the next vblank. When it
29646 * reaches 0, dev_priv->pending_flip_queue will be woken up.
29647 */
29648- atomic_t pending_flip;
29649+ atomic_unchecked_t pending_flip;
29650 };
29651
29652 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
29653@@ -1276,7 +1276,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
29654 extern void intel_teardown_gmbus(struct drm_device *dev);
29655 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
29656 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
29657-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
29658+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
29659 {
29660 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
29661 }
29662diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
29663index 65e1f00..a30ef00 100644
29664--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
29665+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
29666@@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
29667 i915_gem_clflush_object(obj);
29668
29669 if (obj->base.pending_write_domain)
29670- cd->flips |= atomic_read(&obj->pending_flip);
29671+ cd->flips |= atomic_read_unchecked(&obj->pending_flip);
29672
29673 /* The actual obj->write_domain will be updated with
29674 * pending_write_domain after we emit the accumulated flush for all
29675@@ -882,9 +882,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
29676
29677 static int
29678 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
29679- int count)
29680+ unsigned int count)
29681 {
29682- int i;
29683+ unsigned int i;
29684
29685 for (i = 0; i < count; i++) {
29686 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
29687diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
29688index 5bd4361..0241a42 100644
29689--- a/drivers/gpu/drm/i915/i915_irq.c
29690+++ b/drivers/gpu/drm/i915/i915_irq.c
29691@@ -475,7 +475,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
29692 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
29693 struct drm_i915_master_private *master_priv;
29694
29695- atomic_inc(&dev_priv->irq_received);
29696+ atomic_inc_unchecked(&dev_priv->irq_received);
29697
29698 /* disable master interrupt before clearing iir */
29699 de_ier = I915_READ(DEIER);
29700@@ -566,7 +566,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
29701 struct drm_i915_master_private *master_priv;
29702 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
29703
29704- atomic_inc(&dev_priv->irq_received);
29705+ atomic_inc_unchecked(&dev_priv->irq_received);
29706
29707 if (IS_GEN6(dev))
29708 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
29709@@ -1231,7 +1231,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
29710 int ret = IRQ_NONE, pipe;
29711 bool blc_event = false;
29712
29713- atomic_inc(&dev_priv->irq_received);
29714+ atomic_inc_unchecked(&dev_priv->irq_received);
29715
29716 iir = I915_READ(IIR);
29717
29718@@ -1743,7 +1743,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
29719 {
29720 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
29721
29722- atomic_set(&dev_priv->irq_received, 0);
29723+ atomic_set_unchecked(&dev_priv->irq_received, 0);
29724
29725 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
29726 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
29727@@ -1932,7 +1932,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
29728 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
29729 int pipe;
29730
29731- atomic_set(&dev_priv->irq_received, 0);
29732+ atomic_set_unchecked(&dev_priv->irq_received, 0);
29733
29734 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
29735 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
29736diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
29737index 397087c..9178d0d 100644
29738--- a/drivers/gpu/drm/i915/intel_display.c
29739+++ b/drivers/gpu/drm/i915/intel_display.c
29740@@ -2238,7 +2238,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
29741
29742 wait_event(dev_priv->pending_flip_queue,
29743 atomic_read(&dev_priv->mm.wedged) ||
29744- atomic_read(&obj->pending_flip) == 0);
29745+ atomic_read_unchecked(&obj->pending_flip) == 0);
29746
29747 /* Big Hammer, we also need to ensure that any pending
29748 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
29749@@ -2859,7 +2859,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
29750 obj = to_intel_framebuffer(crtc->fb)->obj;
29751 dev_priv = crtc->dev->dev_private;
29752 wait_event(dev_priv->pending_flip_queue,
29753- atomic_read(&obj->pending_flip) == 0);
29754+ atomic_read_unchecked(&obj->pending_flip) == 0);
29755 }
29756
29757 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
29758@@ -7171,7 +7171,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
29759
29760 atomic_clear_mask(1 << intel_crtc->plane,
29761 &obj->pending_flip.counter);
29762- if (atomic_read(&obj->pending_flip) == 0)
29763+ if (atomic_read_unchecked(&obj->pending_flip) == 0)
29764 wake_up(&dev_priv->pending_flip_queue);
29765
29766 schedule_work(&work->work);
29767@@ -7461,7 +7461,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
29768 /* Block clients from rendering to the new back buffer until
29769 * the flip occurs and the object is no longer visible.
29770 */
29771- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29772+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29773
29774 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
29775 if (ret)
29776@@ -7475,7 +7475,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
29777 return 0;
29778
29779 cleanup_pending:
29780- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29781+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29782 drm_gem_object_unreference(&work->old_fb_obj->base);
29783 drm_gem_object_unreference(&obj->base);
29784 mutex_unlock(&dev->struct_mutex);
29785diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
29786index 54558a0..2d97005 100644
29787--- a/drivers/gpu/drm/mga/mga_drv.h
29788+++ b/drivers/gpu/drm/mga/mga_drv.h
29789@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
29790 u32 clear_cmd;
29791 u32 maccess;
29792
29793- atomic_t vbl_received; /**< Number of vblanks received. */
29794+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
29795 wait_queue_head_t fence_queue;
29796- atomic_t last_fence_retired;
29797+ atomic_unchecked_t last_fence_retired;
29798 u32 next_fence_to_post;
29799
29800 unsigned int fb_cpp;
29801diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
29802index 2581202..f230a8d9 100644
29803--- a/drivers/gpu/drm/mga/mga_irq.c
29804+++ b/drivers/gpu/drm/mga/mga_irq.c
29805@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
29806 if (crtc != 0)
29807 return 0;
29808
29809- return atomic_read(&dev_priv->vbl_received);
29810+ return atomic_read_unchecked(&dev_priv->vbl_received);
29811 }
29812
29813
29814@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
29815 /* VBLANK interrupt */
29816 if (status & MGA_VLINEPEN) {
29817 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
29818- atomic_inc(&dev_priv->vbl_received);
29819+ atomic_inc_unchecked(&dev_priv->vbl_received);
29820 drm_handle_vblank(dev, 0);
29821 handled = 1;
29822 }
29823@@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
29824 if ((prim_start & ~0x03) != (prim_end & ~0x03))
29825 MGA_WRITE(MGA_PRIMEND, prim_end);
29826
29827- atomic_inc(&dev_priv->last_fence_retired);
29828+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
29829 DRM_WAKEUP(&dev_priv->fence_queue);
29830 handled = 1;
29831 }
29832@@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
29833 * using fences.
29834 */
29835 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
29836- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
29837+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
29838 - *sequence) <= (1 << 23)));
29839
29840 *sequence = cur_fence;
29841diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
29842index e5cbead..6c354a3 100644
29843--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
29844+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
29845@@ -199,7 +199,7 @@ struct methods {
29846 const char desc[8];
29847 void (*loadbios)(struct drm_device *, uint8_t *);
29848 const bool rw;
29849-};
29850+} __do_const;
29851
29852 static struct methods shadow_methods[] = {
29853 { "PRAMIN", load_vbios_pramin, true },
29854@@ -5290,7 +5290,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
29855 struct bit_table {
29856 const char id;
29857 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
29858-};
29859+} __no_const;
29860
29861 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
29862
29863diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
29864index b827098..c31a797 100644
29865--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
29866+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
29867@@ -242,7 +242,7 @@ struct nouveau_channel {
29868 struct list_head pending;
29869 uint32_t sequence;
29870 uint32_t sequence_ack;
29871- atomic_t last_sequence_irq;
29872+ atomic_unchecked_t last_sequence_irq;
29873 struct nouveau_vma vma;
29874 } fence;
29875
29876@@ -323,7 +323,7 @@ struct nouveau_exec_engine {
29877 u32 handle, u16 class);
29878 void (*set_tile_region)(struct drm_device *dev, int i);
29879 void (*tlb_flush)(struct drm_device *, int engine);
29880-};
29881+} __no_const;
29882
29883 struct nouveau_instmem_engine {
29884 void *priv;
29885@@ -345,13 +345,13 @@ struct nouveau_instmem_engine {
29886 struct nouveau_mc_engine {
29887 int (*init)(struct drm_device *dev);
29888 void (*takedown)(struct drm_device *dev);
29889-};
29890+} __no_const;
29891
29892 struct nouveau_timer_engine {
29893 int (*init)(struct drm_device *dev);
29894 void (*takedown)(struct drm_device *dev);
29895 uint64_t (*read)(struct drm_device *dev);
29896-};
29897+} __no_const;
29898
29899 struct nouveau_fb_engine {
29900 int num_tiles;
29901@@ -566,7 +566,7 @@ struct nouveau_vram_engine {
29902 void (*put)(struct drm_device *, struct nouveau_mem **);
29903
29904 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
29905-};
29906+} __no_const;
29907
29908 struct nouveau_engine {
29909 struct nouveau_instmem_engine instmem;
29910@@ -714,7 +714,7 @@ struct drm_nouveau_private {
29911 struct drm_global_reference mem_global_ref;
29912 struct ttm_bo_global_ref bo_global_ref;
29913 struct ttm_bo_device bdev;
29914- atomic_t validate_sequence;
29915+ atomic_unchecked_t validate_sequence;
29916 } ttm;
29917
29918 struct {
29919diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
29920index 2f6daae..c9d7b9e 100644
29921--- a/drivers/gpu/drm/nouveau/nouveau_fence.c
29922+++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
29923@@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
29924 if (USE_REFCNT(dev))
29925 sequence = nvchan_rd32(chan, 0x48);
29926 else
29927- sequence = atomic_read(&chan->fence.last_sequence_irq);
29928+ sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
29929
29930 if (chan->fence.sequence_ack == sequence)
29931 goto out;
29932@@ -539,7 +539,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
29933 return ret;
29934 }
29935
29936- atomic_set(&chan->fence.last_sequence_irq, 0);
29937+ atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
29938 return 0;
29939 }
29940
29941diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
29942index 7ce3fde..cb3ea04 100644
29943--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
29944+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
29945@@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
29946 int trycnt = 0;
29947 int ret, i;
29948
29949- sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
29950+ sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
29951 retry:
29952 if (++trycnt > 100000) {
29953 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
29954diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
29955index f80c5e0..936baa7 100644
29956--- a/drivers/gpu/drm/nouveau/nouveau_state.c
29957+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
29958@@ -543,7 +543,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
29959 bool can_switch;
29960
29961 spin_lock(&dev->count_lock);
29962- can_switch = (dev->open_count == 0);
29963+ can_switch = (local_read(&dev->open_count) == 0);
29964 spin_unlock(&dev->count_lock);
29965 return can_switch;
29966 }
29967diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
29968index dbdea8e..cd6eeeb 100644
29969--- a/drivers/gpu/drm/nouveau/nv04_graph.c
29970+++ b/drivers/gpu/drm/nouveau/nv04_graph.c
29971@@ -554,7 +554,7 @@ static int
29972 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
29973 u32 class, u32 mthd, u32 data)
29974 {
29975- atomic_set(&chan->fence.last_sequence_irq, data);
29976+ atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
29977 return 0;
29978 }
29979
29980diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
29981index bcac90b..53bfc76 100644
29982--- a/drivers/gpu/drm/r128/r128_cce.c
29983+++ b/drivers/gpu/drm/r128/r128_cce.c
29984@@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
29985
29986 /* GH: Simple idle check.
29987 */
29988- atomic_set(&dev_priv->idle_count, 0);
29989+ atomic_set_unchecked(&dev_priv->idle_count, 0);
29990
29991 /* We don't support anything other than bus-mastering ring mode,
29992 * but the ring can be in either AGP or PCI space for the ring
29993diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
29994index 930c71b..499aded 100644
29995--- a/drivers/gpu/drm/r128/r128_drv.h
29996+++ b/drivers/gpu/drm/r128/r128_drv.h
29997@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
29998 int is_pci;
29999 unsigned long cce_buffers_offset;
30000
30001- atomic_t idle_count;
30002+ atomic_unchecked_t idle_count;
30003
30004 int page_flipping;
30005 int current_page;
30006 u32 crtc_offset;
30007 u32 crtc_offset_cntl;
30008
30009- atomic_t vbl_received;
30010+ atomic_unchecked_t vbl_received;
30011
30012 u32 color_fmt;
30013 unsigned int front_offset;
30014diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30015index 429d5a0..7e899ed 100644
30016--- a/drivers/gpu/drm/r128/r128_irq.c
30017+++ b/drivers/gpu/drm/r128/r128_irq.c
30018@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30019 if (crtc != 0)
30020 return 0;
30021
30022- return atomic_read(&dev_priv->vbl_received);
30023+ return atomic_read_unchecked(&dev_priv->vbl_received);
30024 }
30025
30026 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30027@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30028 /* VBLANK interrupt */
30029 if (status & R128_CRTC_VBLANK_INT) {
30030 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30031- atomic_inc(&dev_priv->vbl_received);
30032+ atomic_inc_unchecked(&dev_priv->vbl_received);
30033 drm_handle_vblank(dev, 0);
30034 return IRQ_HANDLED;
30035 }
30036diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30037index a9e33ce..09edd4b 100644
30038--- a/drivers/gpu/drm/r128/r128_state.c
30039+++ b/drivers/gpu/drm/r128/r128_state.c
30040@@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30041
30042 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30043 {
30044- if (atomic_read(&dev_priv->idle_count) == 0)
30045+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30046 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30047 else
30048- atomic_set(&dev_priv->idle_count, 0);
30049+ atomic_set_unchecked(&dev_priv->idle_count, 0);
30050 }
30051
30052 #endif
30053diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30054index 5a82b6b..9e69c73 100644
30055--- a/drivers/gpu/drm/radeon/mkregtable.c
30056+++ b/drivers/gpu/drm/radeon/mkregtable.c
30057@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30058 regex_t mask_rex;
30059 regmatch_t match[4];
30060 char buf[1024];
30061- size_t end;
30062+ long end;
30063 int len;
30064 int done = 0;
30065 int r;
30066 unsigned o;
30067 struct offset *offset;
30068 char last_reg_s[10];
30069- int last_reg;
30070+ unsigned long last_reg;
30071
30072 if (regcomp
30073 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30074diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30075index 1668ec1..30ebdab 100644
30076--- a/drivers/gpu/drm/radeon/radeon.h
30077+++ b/drivers/gpu/drm/radeon/radeon.h
30078@@ -250,7 +250,7 @@ struct radeon_fence_driver {
30079 uint32_t scratch_reg;
30080 uint64_t gpu_addr;
30081 volatile uint32_t *cpu_addr;
30082- atomic_t seq;
30083+ atomic_unchecked_t seq;
30084 uint32_t last_seq;
30085 unsigned long last_jiffies;
30086 unsigned long last_timeout;
30087@@ -752,7 +752,7 @@ struct r600_blit_cp_primitives {
30088 int x2, int y2);
30089 void (*draw_auto)(struct radeon_device *rdev);
30090 void (*set_default_state)(struct radeon_device *rdev);
30091-};
30092+} __no_const;
30093
30094 struct r600_blit {
30095 struct mutex mutex;
30096@@ -1201,7 +1201,7 @@ struct radeon_asic {
30097 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
30098 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30099 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30100-};
30101+} __no_const;
30102
30103 /*
30104 * Asic structures
30105diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30106index 49f7cb7..2fcb48f 100644
30107--- a/drivers/gpu/drm/radeon/radeon_device.c
30108+++ b/drivers/gpu/drm/radeon/radeon_device.c
30109@@ -687,7 +687,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30110 bool can_switch;
30111
30112 spin_lock(&dev->count_lock);
30113- can_switch = (dev->open_count == 0);
30114+ can_switch = (local_read(&dev->open_count) == 0);
30115 spin_unlock(&dev->count_lock);
30116 return can_switch;
30117 }
30118diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30119index a1b59ca..86f2d44 100644
30120--- a/drivers/gpu/drm/radeon/radeon_drv.h
30121+++ b/drivers/gpu/drm/radeon/radeon_drv.h
30122@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30123
30124 /* SW interrupt */
30125 wait_queue_head_t swi_queue;
30126- atomic_t swi_emitted;
30127+ atomic_unchecked_t swi_emitted;
30128 int vblank_crtc;
30129 uint32_t irq_enable_reg;
30130 uint32_t r500_disp_irq_reg;
30131diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
30132index 4bd36a3..e66fe9c 100644
30133--- a/drivers/gpu/drm/radeon/radeon_fence.c
30134+++ b/drivers/gpu/drm/radeon/radeon_fence.c
30135@@ -70,7 +70,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
30136 write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
30137 return 0;
30138 }
30139- fence->seq = atomic_add_return(1, &rdev->fence_drv[fence->ring].seq);
30140+ fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv[fence->ring].seq);
30141 if (!rdev->ring[fence->ring].ready)
30142 /* FIXME: cp is not running assume everythings is done right
30143 * away
30144@@ -405,7 +405,7 @@ int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
30145 }
30146 rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
30147 rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
30148- radeon_fence_write(rdev, atomic_read(&rdev->fence_drv[ring].seq), ring);
30149+ radeon_fence_write(rdev, atomic_read_unchecked(&rdev->fence_drv[ring].seq), ring);
30150 rdev->fence_drv[ring].initialized = true;
30151 DRM_INFO("fence driver on ring %d use gpu addr 0x%08Lx and cpu addr 0x%p\n",
30152 ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
30153@@ -418,7 +418,7 @@ static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
30154 rdev->fence_drv[ring].scratch_reg = -1;
30155 rdev->fence_drv[ring].cpu_addr = NULL;
30156 rdev->fence_drv[ring].gpu_addr = 0;
30157- atomic_set(&rdev->fence_drv[ring].seq, 0);
30158+ atomic_set_unchecked(&rdev->fence_drv[ring].seq, 0);
30159 INIT_LIST_HEAD(&rdev->fence_drv[ring].created);
30160 INIT_LIST_HEAD(&rdev->fence_drv[ring].emitted);
30161 INIT_LIST_HEAD(&rdev->fence_drv[ring].signaled);
30162diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30163index 48b7cea..342236f 100644
30164--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30165+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30166@@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30167 request = compat_alloc_user_space(sizeof(*request));
30168 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30169 || __put_user(req32.param, &request->param)
30170- || __put_user((void __user *)(unsigned long)req32.value,
30171+ || __put_user((unsigned long)req32.value,
30172 &request->value))
30173 return -EFAULT;
30174
30175diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30176index 00da384..32f972d 100644
30177--- a/drivers/gpu/drm/radeon/radeon_irq.c
30178+++ b/drivers/gpu/drm/radeon/radeon_irq.c
30179@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30180 unsigned int ret;
30181 RING_LOCALS;
30182
30183- atomic_inc(&dev_priv->swi_emitted);
30184- ret = atomic_read(&dev_priv->swi_emitted);
30185+ atomic_inc_unchecked(&dev_priv->swi_emitted);
30186+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30187
30188 BEGIN_RING(4);
30189 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30190@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30191 drm_radeon_private_t *dev_priv =
30192 (drm_radeon_private_t *) dev->dev_private;
30193
30194- atomic_set(&dev_priv->swi_emitted, 0);
30195+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30196 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30197
30198 dev->max_vblank_count = 0x001fffff;
30199diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30200index e8422ae..d22d4a8 100644
30201--- a/drivers/gpu/drm/radeon/radeon_state.c
30202+++ b/drivers/gpu/drm/radeon/radeon_state.c
30203@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30204 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30205 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30206
30207- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30208+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30209 sarea_priv->nbox * sizeof(depth_boxes[0])))
30210 return -EFAULT;
30211
30212@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30213 {
30214 drm_radeon_private_t *dev_priv = dev->dev_private;
30215 drm_radeon_getparam_t *param = data;
30216- int value;
30217+ int value = 0;
30218
30219 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30220
30221diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
30222index c421e77..e6bf2e8 100644
30223--- a/drivers/gpu/drm/radeon/radeon_ttm.c
30224+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
30225@@ -842,8 +842,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
30226 }
30227 if (unlikely(ttm_vm_ops == NULL)) {
30228 ttm_vm_ops = vma->vm_ops;
30229- radeon_ttm_vm_ops = *ttm_vm_ops;
30230- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30231+ pax_open_kernel();
30232+ memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
30233+ *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30234+ pax_close_kernel();
30235 }
30236 vma->vm_ops = &radeon_ttm_vm_ops;
30237 return 0;
30238diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
30239index f68dff2..8df955c 100644
30240--- a/drivers/gpu/drm/radeon/rs690.c
30241+++ b/drivers/gpu/drm/radeon/rs690.c
30242@@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
30243 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
30244 rdev->pm.sideport_bandwidth.full)
30245 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
30246- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
30247+ read_delay_latency.full = dfixed_const(800 * 1000);
30248 read_delay_latency.full = dfixed_div(read_delay_latency,
30249 rdev->pm.igp_sideport_mclk);
30250+ a.full = dfixed_const(370);
30251+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
30252 } else {
30253 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
30254 rdev->pm.k8_bandwidth.full)
30255diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30256index 499debd..66fce72 100644
30257--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
30258+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30259@@ -398,9 +398,9 @@ static int ttm_pool_get_num_unused_pages(void)
30260 static int ttm_pool_mm_shrink(struct shrinker *shrink,
30261 struct shrink_control *sc)
30262 {
30263- static atomic_t start_pool = ATOMIC_INIT(0);
30264+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
30265 unsigned i;
30266- unsigned pool_offset = atomic_add_return(1, &start_pool);
30267+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
30268 struct ttm_page_pool *pool;
30269 int shrink_pages = sc->nr_to_scan;
30270
30271diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
30272index 88edacc..1e5412b 100644
30273--- a/drivers/gpu/drm/via/via_drv.h
30274+++ b/drivers/gpu/drm/via/via_drv.h
30275@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
30276 typedef uint32_t maskarray_t[5];
30277
30278 typedef struct drm_via_irq {
30279- atomic_t irq_received;
30280+ atomic_unchecked_t irq_received;
30281 uint32_t pending_mask;
30282 uint32_t enable_mask;
30283 wait_queue_head_t irq_queue;
30284@@ -75,7 +75,7 @@ typedef struct drm_via_private {
30285 struct timeval last_vblank;
30286 int last_vblank_valid;
30287 unsigned usec_per_vblank;
30288- atomic_t vbl_received;
30289+ atomic_unchecked_t vbl_received;
30290 drm_via_state_t hc_state;
30291 char pci_buf[VIA_PCI_BUF_SIZE];
30292 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
30293diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
30294index d391f48..10c8ca3 100644
30295--- a/drivers/gpu/drm/via/via_irq.c
30296+++ b/drivers/gpu/drm/via/via_irq.c
30297@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
30298 if (crtc != 0)
30299 return 0;
30300
30301- return atomic_read(&dev_priv->vbl_received);
30302+ return atomic_read_unchecked(&dev_priv->vbl_received);
30303 }
30304
30305 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30306@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30307
30308 status = VIA_READ(VIA_REG_INTERRUPT);
30309 if (status & VIA_IRQ_VBLANK_PENDING) {
30310- atomic_inc(&dev_priv->vbl_received);
30311- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
30312+ atomic_inc_unchecked(&dev_priv->vbl_received);
30313+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
30314 do_gettimeofday(&cur_vblank);
30315 if (dev_priv->last_vblank_valid) {
30316 dev_priv->usec_per_vblank =
30317@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30318 dev_priv->last_vblank = cur_vblank;
30319 dev_priv->last_vblank_valid = 1;
30320 }
30321- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
30322+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
30323 DRM_DEBUG("US per vblank is: %u\n",
30324 dev_priv->usec_per_vblank);
30325 }
30326@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
30327
30328 for (i = 0; i < dev_priv->num_irqs; ++i) {
30329 if (status & cur_irq->pending_mask) {
30330- atomic_inc(&cur_irq->irq_received);
30331+ atomic_inc_unchecked(&cur_irq->irq_received);
30332 DRM_WAKEUP(&cur_irq->irq_queue);
30333 handled = 1;
30334 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
30335@@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
30336 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
30337 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
30338 masks[irq][4]));
30339- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
30340+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
30341 } else {
30342 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
30343 (((cur_irq_sequence =
30344- atomic_read(&cur_irq->irq_received)) -
30345+ atomic_read_unchecked(&cur_irq->irq_received)) -
30346 *sequence) <= (1 << 23)));
30347 }
30348 *sequence = cur_irq_sequence;
30349@@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
30350 }
30351
30352 for (i = 0; i < dev_priv->num_irqs; ++i) {
30353- atomic_set(&cur_irq->irq_received, 0);
30354+ atomic_set_unchecked(&cur_irq->irq_received, 0);
30355 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
30356 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
30357 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
30358@@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
30359 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
30360 case VIA_IRQ_RELATIVE:
30361 irqwait->request.sequence +=
30362- atomic_read(&cur_irq->irq_received);
30363+ atomic_read_unchecked(&cur_irq->irq_received);
30364 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
30365 case VIA_IRQ_ABSOLUTE:
30366 break;
30367diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
30368index dc27970..f18b008 100644
30369--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
30370+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
30371@@ -260,7 +260,7 @@ struct vmw_private {
30372 * Fencing and IRQs.
30373 */
30374
30375- atomic_t marker_seq;
30376+ atomic_unchecked_t marker_seq;
30377 wait_queue_head_t fence_queue;
30378 wait_queue_head_t fifo_queue;
30379 int fence_queue_waiters; /* Protected by hw_mutex */
30380diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
30381index a0c2f12..68ae6cb 100644
30382--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
30383+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
30384@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
30385 (unsigned int) min,
30386 (unsigned int) fifo->capabilities);
30387
30388- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
30389+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
30390 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
30391 vmw_marker_queue_init(&fifo->marker_queue);
30392 return vmw_fifo_send_fence(dev_priv, &dummy);
30393@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
30394 if (reserveable)
30395 iowrite32(bytes, fifo_mem +
30396 SVGA_FIFO_RESERVED);
30397- return fifo_mem + (next_cmd >> 2);
30398+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
30399 } else {
30400 need_bounce = true;
30401 }
30402@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
30403
30404 fm = vmw_fifo_reserve(dev_priv, bytes);
30405 if (unlikely(fm == NULL)) {
30406- *seqno = atomic_read(&dev_priv->marker_seq);
30407+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
30408 ret = -ENOMEM;
30409 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
30410 false, 3*HZ);
30411@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
30412 }
30413
30414 do {
30415- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
30416+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
30417 } while (*seqno == 0);
30418
30419 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
30420diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
30421index cabc95f..14b3d77 100644
30422--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
30423+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
30424@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
30425 * emitted. Then the fence is stale and signaled.
30426 */
30427
30428- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
30429+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
30430 > VMW_FENCE_WRAP);
30431
30432 return ret;
30433@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
30434
30435 if (fifo_idle)
30436 down_read(&fifo_state->rwsem);
30437- signal_seq = atomic_read(&dev_priv->marker_seq);
30438+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
30439 ret = 0;
30440
30441 for (;;) {
30442diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
30443index 8a8725c..afed796 100644
30444--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
30445+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
30446@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
30447 while (!vmw_lag_lt(queue, us)) {
30448 spin_lock(&queue->lock);
30449 if (list_empty(&queue->head))
30450- seqno = atomic_read(&dev_priv->marker_seq);
30451+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
30452 else {
30453 marker = list_first_entry(&queue->head,
30454 struct vmw_marker, head);
30455diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
30456index 75dbe34..f9204a8 100644
30457--- a/drivers/hid/hid-core.c
30458+++ b/drivers/hid/hid-core.c
30459@@ -2021,7 +2021,7 @@ static bool hid_ignore(struct hid_device *hdev)
30460
30461 int hid_add_device(struct hid_device *hdev)
30462 {
30463- static atomic_t id = ATOMIC_INIT(0);
30464+ static atomic_unchecked_t id = ATOMIC_INIT(0);
30465 int ret;
30466
30467 if (WARN_ON(hdev->status & HID_STAT_ADDED))
30468@@ -2036,7 +2036,7 @@ int hid_add_device(struct hid_device *hdev)
30469 /* XXX hack, any other cleaner solution after the driver core
30470 * is converted to allow more than 20 bytes as the device name? */
30471 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
30472- hdev->vendor, hdev->product, atomic_inc_return(&id));
30473+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
30474
30475 hid_debug_register(hdev, dev_name(&hdev->dev));
30476 ret = device_add(&hdev->dev);
30477diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
30478index b1ec0e2..c295a61 100644
30479--- a/drivers/hid/usbhid/hiddev.c
30480+++ b/drivers/hid/usbhid/hiddev.c
30481@@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
30482 break;
30483
30484 case HIDIOCAPPLICATION:
30485- if (arg < 0 || arg >= hid->maxapplication)
30486+ if (arg >= hid->maxapplication)
30487 break;
30488
30489 for (i = 0; i < hid->maxcollection; i++)
30490diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
30491index 4065374..10ed7dc 100644
30492--- a/drivers/hv/channel.c
30493+++ b/drivers/hv/channel.c
30494@@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
30495 int ret = 0;
30496 int t;
30497
30498- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
30499- atomic_inc(&vmbus_connection.next_gpadl_handle);
30500+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
30501+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
30502
30503 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
30504 if (ret)
30505diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
30506index 12aa97f..c0679f7 100644
30507--- a/drivers/hv/hv.c
30508+++ b/drivers/hv/hv.c
30509@@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
30510 u64 output_address = (output) ? virt_to_phys(output) : 0;
30511 u32 output_address_hi = output_address >> 32;
30512 u32 output_address_lo = output_address & 0xFFFFFFFF;
30513- void *hypercall_page = hv_context.hypercall_page;
30514+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
30515
30516 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
30517 "=a"(hv_status_lo) : "d" (control_hi),
30518diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
30519index 6d7d286..92b0873 100644
30520--- a/drivers/hv/hyperv_vmbus.h
30521+++ b/drivers/hv/hyperv_vmbus.h
30522@@ -556,7 +556,7 @@ enum vmbus_connect_state {
30523 struct vmbus_connection {
30524 enum vmbus_connect_state conn_state;
30525
30526- atomic_t next_gpadl_handle;
30527+ atomic_unchecked_t next_gpadl_handle;
30528
30529 /*
30530 * Represents channel interrupts. Each bit position represents a
30531diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
30532index a220e57..428f54d 100644
30533--- a/drivers/hv/vmbus_drv.c
30534+++ b/drivers/hv/vmbus_drv.c
30535@@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
30536 {
30537 int ret = 0;
30538
30539- static atomic_t device_num = ATOMIC_INIT(0);
30540+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
30541
30542 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
30543- atomic_inc_return(&device_num));
30544+ atomic_inc_return_unchecked(&device_num));
30545
30546 child_device_obj->device.bus = &hv_bus;
30547 child_device_obj->device.parent = &hv_acpi_dev->dev;
30548diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
30549index 554f046..f8b4729 100644
30550--- a/drivers/hwmon/acpi_power_meter.c
30551+++ b/drivers/hwmon/acpi_power_meter.c
30552@@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
30553 return res;
30554
30555 temp /= 1000;
30556- if (temp < 0)
30557- return -EINVAL;
30558
30559 mutex_lock(&resource->lock);
30560 resource->trip[attr->index - 7] = temp;
30561diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
30562index 91fdd1f..b66a686 100644
30563--- a/drivers/hwmon/sht15.c
30564+++ b/drivers/hwmon/sht15.c
30565@@ -166,7 +166,7 @@ struct sht15_data {
30566 int supply_uV;
30567 bool supply_uV_valid;
30568 struct work_struct update_supply_work;
30569- atomic_t interrupt_handled;
30570+ atomic_unchecked_t interrupt_handled;
30571 };
30572
30573 /**
30574@@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
30575 return ret;
30576
30577 gpio_direction_input(data->pdata->gpio_data);
30578- atomic_set(&data->interrupt_handled, 0);
30579+ atomic_set_unchecked(&data->interrupt_handled, 0);
30580
30581 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30582 if (gpio_get_value(data->pdata->gpio_data) == 0) {
30583 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
30584 /* Only relevant if the interrupt hasn't occurred. */
30585- if (!atomic_read(&data->interrupt_handled))
30586+ if (!atomic_read_unchecked(&data->interrupt_handled))
30587 schedule_work(&data->read_work);
30588 }
30589 ret = wait_event_timeout(data->wait_queue,
30590@@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
30591
30592 /* First disable the interrupt */
30593 disable_irq_nosync(irq);
30594- atomic_inc(&data->interrupt_handled);
30595+ atomic_inc_unchecked(&data->interrupt_handled);
30596 /* Then schedule a reading work struct */
30597 if (data->state != SHT15_READING_NOTHING)
30598 schedule_work(&data->read_work);
30599@@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
30600 * If not, then start the interrupt again - care here as could
30601 * have gone low in meantime so verify it hasn't!
30602 */
30603- atomic_set(&data->interrupt_handled, 0);
30604+ atomic_set_unchecked(&data->interrupt_handled, 0);
30605 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30606 /* If still not occurred or another handler has been scheduled */
30607 if (gpio_get_value(data->pdata->gpio_data)
30608- || atomic_read(&data->interrupt_handled))
30609+ || atomic_read_unchecked(&data->interrupt_handled))
30610 return;
30611 }
30612
30613diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
30614index 378fcb5..5e91fa8 100644
30615--- a/drivers/i2c/busses/i2c-amd756-s4882.c
30616+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
30617@@ -43,7 +43,7 @@
30618 extern struct i2c_adapter amd756_smbus;
30619
30620 static struct i2c_adapter *s4882_adapter;
30621-static struct i2c_algorithm *s4882_algo;
30622+static i2c_algorithm_no_const *s4882_algo;
30623
30624 /* Wrapper access functions for multiplexed SMBus */
30625 static DEFINE_MUTEX(amd756_lock);
30626diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
30627index 29015eb..af2d8e9 100644
30628--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
30629+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
30630@@ -41,7 +41,7 @@
30631 extern struct i2c_adapter *nforce2_smbus;
30632
30633 static struct i2c_adapter *s4985_adapter;
30634-static struct i2c_algorithm *s4985_algo;
30635+static i2c_algorithm_no_const *s4985_algo;
30636
30637 /* Wrapper access functions for multiplexed SMBus */
30638 static DEFINE_MUTEX(nforce2_lock);
30639diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
30640index d7a4833..7fae376 100644
30641--- a/drivers/i2c/i2c-mux.c
30642+++ b/drivers/i2c/i2c-mux.c
30643@@ -28,7 +28,7 @@
30644 /* multiplexer per channel data */
30645 struct i2c_mux_priv {
30646 struct i2c_adapter adap;
30647- struct i2c_algorithm algo;
30648+ i2c_algorithm_no_const algo;
30649
30650 struct i2c_adapter *parent;
30651 void *mux_dev; /* the mux chip/device */
30652diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
30653index 57d00ca..0145194 100644
30654--- a/drivers/ide/aec62xx.c
30655+++ b/drivers/ide/aec62xx.c
30656@@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
30657 .cable_detect = atp86x_cable_detect,
30658 };
30659
30660-static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
30661+static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
30662 { /* 0: AEC6210 */
30663 .name = DRV_NAME,
30664 .init_chipset = init_chipset_aec62xx,
30665diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
30666index 2c8016a..911a27c 100644
30667--- a/drivers/ide/alim15x3.c
30668+++ b/drivers/ide/alim15x3.c
30669@@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
30670 .dma_sff_read_status = ide_dma_sff_read_status,
30671 };
30672
30673-static const struct ide_port_info ali15x3_chipset __devinitdata = {
30674+static const struct ide_port_info ali15x3_chipset __devinitconst = {
30675 .name = DRV_NAME,
30676 .init_chipset = init_chipset_ali15x3,
30677 .init_hwif = init_hwif_ali15x3,
30678diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
30679index 3747b25..56fc995 100644
30680--- a/drivers/ide/amd74xx.c
30681+++ b/drivers/ide/amd74xx.c
30682@@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
30683 .udma_mask = udma, \
30684 }
30685
30686-static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
30687+static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
30688 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
30689 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
30690 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
30691diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
30692index 15f0ead..cb43480 100644
30693--- a/drivers/ide/atiixp.c
30694+++ b/drivers/ide/atiixp.c
30695@@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
30696 .cable_detect = atiixp_cable_detect,
30697 };
30698
30699-static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
30700+static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
30701 { /* 0: IXP200/300/400/700 */
30702 .name = DRV_NAME,
30703 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
30704diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
30705index 5f80312..d1fc438 100644
30706--- a/drivers/ide/cmd64x.c
30707+++ b/drivers/ide/cmd64x.c
30708@@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
30709 .dma_sff_read_status = ide_dma_sff_read_status,
30710 };
30711
30712-static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
30713+static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
30714 { /* 0: CMD643 */
30715 .name = DRV_NAME,
30716 .init_chipset = init_chipset_cmd64x,
30717diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
30718index 2c1e5f7..1444762 100644
30719--- a/drivers/ide/cs5520.c
30720+++ b/drivers/ide/cs5520.c
30721@@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
30722 .set_dma_mode = cs5520_set_dma_mode,
30723 };
30724
30725-static const struct ide_port_info cyrix_chipset __devinitdata = {
30726+static const struct ide_port_info cyrix_chipset __devinitconst = {
30727 .name = DRV_NAME,
30728 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
30729 .port_ops = &cs5520_port_ops,
30730diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
30731index 4dc4eb9..49b40ad 100644
30732--- a/drivers/ide/cs5530.c
30733+++ b/drivers/ide/cs5530.c
30734@@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
30735 .udma_filter = cs5530_udma_filter,
30736 };
30737
30738-static const struct ide_port_info cs5530_chipset __devinitdata = {
30739+static const struct ide_port_info cs5530_chipset __devinitconst = {
30740 .name = DRV_NAME,
30741 .init_chipset = init_chipset_cs5530,
30742 .init_hwif = init_hwif_cs5530,
30743diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
30744index 5059faf..18d4c85 100644
30745--- a/drivers/ide/cs5535.c
30746+++ b/drivers/ide/cs5535.c
30747@@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
30748 .cable_detect = cs5535_cable_detect,
30749 };
30750
30751-static const struct ide_port_info cs5535_chipset __devinitdata = {
30752+static const struct ide_port_info cs5535_chipset __devinitconst = {
30753 .name = DRV_NAME,
30754 .port_ops = &cs5535_port_ops,
30755 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
30756diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
30757index 847553f..3ffb49d 100644
30758--- a/drivers/ide/cy82c693.c
30759+++ b/drivers/ide/cy82c693.c
30760@@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
30761 .set_dma_mode = cy82c693_set_dma_mode,
30762 };
30763
30764-static const struct ide_port_info cy82c693_chipset __devinitdata = {
30765+static const struct ide_port_info cy82c693_chipset __devinitconst = {
30766 .name = DRV_NAME,
30767 .init_iops = init_iops_cy82c693,
30768 .port_ops = &cy82c693_port_ops,
30769diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
30770index 58c51cd..4aec3b8 100644
30771--- a/drivers/ide/hpt366.c
30772+++ b/drivers/ide/hpt366.c
30773@@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
30774 }
30775 };
30776
30777-static const struct hpt_info hpt36x __devinitdata = {
30778+static const struct hpt_info hpt36x __devinitconst = {
30779 .chip_name = "HPT36x",
30780 .chip_type = HPT36x,
30781 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
30782@@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
30783 .timings = &hpt36x_timings
30784 };
30785
30786-static const struct hpt_info hpt370 __devinitdata = {
30787+static const struct hpt_info hpt370 __devinitconst = {
30788 .chip_name = "HPT370",
30789 .chip_type = HPT370,
30790 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
30791@@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
30792 .timings = &hpt37x_timings
30793 };
30794
30795-static const struct hpt_info hpt370a __devinitdata = {
30796+static const struct hpt_info hpt370a __devinitconst = {
30797 .chip_name = "HPT370A",
30798 .chip_type = HPT370A,
30799 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
30800@@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
30801 .timings = &hpt37x_timings
30802 };
30803
30804-static const struct hpt_info hpt374 __devinitdata = {
30805+static const struct hpt_info hpt374 __devinitconst = {
30806 .chip_name = "HPT374",
30807 .chip_type = HPT374,
30808 .udma_mask = ATA_UDMA5,
30809@@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
30810 .timings = &hpt37x_timings
30811 };
30812
30813-static const struct hpt_info hpt372 __devinitdata = {
30814+static const struct hpt_info hpt372 __devinitconst = {
30815 .chip_name = "HPT372",
30816 .chip_type = HPT372,
30817 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30818@@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
30819 .timings = &hpt37x_timings
30820 };
30821
30822-static const struct hpt_info hpt372a __devinitdata = {
30823+static const struct hpt_info hpt372a __devinitconst = {
30824 .chip_name = "HPT372A",
30825 .chip_type = HPT372A,
30826 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30827@@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
30828 .timings = &hpt37x_timings
30829 };
30830
30831-static const struct hpt_info hpt302 __devinitdata = {
30832+static const struct hpt_info hpt302 __devinitconst = {
30833 .chip_name = "HPT302",
30834 .chip_type = HPT302,
30835 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30836@@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
30837 .timings = &hpt37x_timings
30838 };
30839
30840-static const struct hpt_info hpt371 __devinitdata = {
30841+static const struct hpt_info hpt371 __devinitconst = {
30842 .chip_name = "HPT371",
30843 .chip_type = HPT371,
30844 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30845@@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
30846 .timings = &hpt37x_timings
30847 };
30848
30849-static const struct hpt_info hpt372n __devinitdata = {
30850+static const struct hpt_info hpt372n __devinitconst = {
30851 .chip_name = "HPT372N",
30852 .chip_type = HPT372N,
30853 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30854@@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
30855 .timings = &hpt37x_timings
30856 };
30857
30858-static const struct hpt_info hpt302n __devinitdata = {
30859+static const struct hpt_info hpt302n __devinitconst = {
30860 .chip_name = "HPT302N",
30861 .chip_type = HPT302N,
30862 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30863@@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
30864 .timings = &hpt37x_timings
30865 };
30866
30867-static const struct hpt_info hpt371n __devinitdata = {
30868+static const struct hpt_info hpt371n __devinitconst = {
30869 .chip_name = "HPT371N",
30870 .chip_type = HPT371N,
30871 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
30872@@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
30873 .dma_sff_read_status = ide_dma_sff_read_status,
30874 };
30875
30876-static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
30877+static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
30878 { /* 0: HPT36x */
30879 .name = DRV_NAME,
30880 .init_chipset = init_chipset_hpt366,
30881diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
30882index 8126824..55a2798 100644
30883--- a/drivers/ide/ide-cd.c
30884+++ b/drivers/ide/ide-cd.c
30885@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
30886 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
30887 if ((unsigned long)buf & alignment
30888 || blk_rq_bytes(rq) & q->dma_pad_mask
30889- || object_is_on_stack(buf))
30890+ || object_starts_on_stack(buf))
30891 drive->dma = 0;
30892 }
30893 }
30894diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
30895index 7f56b73..dab5b67 100644
30896--- a/drivers/ide/ide-pci-generic.c
30897+++ b/drivers/ide/ide-pci-generic.c
30898@@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
30899 .udma_mask = ATA_UDMA6, \
30900 }
30901
30902-static const struct ide_port_info generic_chipsets[] __devinitdata = {
30903+static const struct ide_port_info generic_chipsets[] __devinitconst = {
30904 /* 0: Unknown */
30905 DECLARE_GENERIC_PCI_DEV(0),
30906
30907diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
30908index 560e66d..d5dd180 100644
30909--- a/drivers/ide/it8172.c
30910+++ b/drivers/ide/it8172.c
30911@@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
30912 .set_dma_mode = it8172_set_dma_mode,
30913 };
30914
30915-static const struct ide_port_info it8172_port_info __devinitdata = {
30916+static const struct ide_port_info it8172_port_info __devinitconst = {
30917 .name = DRV_NAME,
30918 .port_ops = &it8172_port_ops,
30919 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
30920diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
30921index 46816ba..1847aeb 100644
30922--- a/drivers/ide/it8213.c
30923+++ b/drivers/ide/it8213.c
30924@@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
30925 .cable_detect = it8213_cable_detect,
30926 };
30927
30928-static const struct ide_port_info it8213_chipset __devinitdata = {
30929+static const struct ide_port_info it8213_chipset __devinitconst = {
30930 .name = DRV_NAME,
30931 .enablebits = { {0x41, 0x80, 0x80} },
30932 .port_ops = &it8213_port_ops,
30933diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
30934index 2e3169f..c5611db 100644
30935--- a/drivers/ide/it821x.c
30936+++ b/drivers/ide/it821x.c
30937@@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
30938 .cable_detect = it821x_cable_detect,
30939 };
30940
30941-static const struct ide_port_info it821x_chipset __devinitdata = {
30942+static const struct ide_port_info it821x_chipset __devinitconst = {
30943 .name = DRV_NAME,
30944 .init_chipset = init_chipset_it821x,
30945 .init_hwif = init_hwif_it821x,
30946diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
30947index 74c2c4a..efddd7d 100644
30948--- a/drivers/ide/jmicron.c
30949+++ b/drivers/ide/jmicron.c
30950@@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
30951 .cable_detect = jmicron_cable_detect,
30952 };
30953
30954-static const struct ide_port_info jmicron_chipset __devinitdata = {
30955+static const struct ide_port_info jmicron_chipset __devinitconst = {
30956 .name = DRV_NAME,
30957 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
30958 .port_ops = &jmicron_port_ops,
30959diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
30960index 95327a2..73f78d8 100644
30961--- a/drivers/ide/ns87415.c
30962+++ b/drivers/ide/ns87415.c
30963@@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
30964 .dma_sff_read_status = superio_dma_sff_read_status,
30965 };
30966
30967-static const struct ide_port_info ns87415_chipset __devinitdata = {
30968+static const struct ide_port_info ns87415_chipset __devinitconst = {
30969 .name = DRV_NAME,
30970 .init_hwif = init_hwif_ns87415,
30971 .tp_ops = &ns87415_tp_ops,
30972diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
30973index 1a53a4c..39edc66 100644
30974--- a/drivers/ide/opti621.c
30975+++ b/drivers/ide/opti621.c
30976@@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
30977 .set_pio_mode = opti621_set_pio_mode,
30978 };
30979
30980-static const struct ide_port_info opti621_chipset __devinitdata = {
30981+static const struct ide_port_info opti621_chipset __devinitconst = {
30982 .name = DRV_NAME,
30983 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
30984 .port_ops = &opti621_port_ops,
30985diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
30986index 9546fe2..2e5ceb6 100644
30987--- a/drivers/ide/pdc202xx_new.c
30988+++ b/drivers/ide/pdc202xx_new.c
30989@@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
30990 .udma_mask = udma, \
30991 }
30992
30993-static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
30994+static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
30995 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
30996 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
30997 };
30998diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
30999index 3a35ec6..5634510 100644
31000--- a/drivers/ide/pdc202xx_old.c
31001+++ b/drivers/ide/pdc202xx_old.c
31002@@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31003 .max_sectors = sectors, \
31004 }
31005
31006-static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31007+static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31008 { /* 0: PDC20246 */
31009 .name = DRV_NAME,
31010 .init_chipset = init_chipset_pdc202xx,
31011diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31012index 1892e81..fe0fd60 100644
31013--- a/drivers/ide/piix.c
31014+++ b/drivers/ide/piix.c
31015@@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31016 .udma_mask = udma, \
31017 }
31018
31019-static const struct ide_port_info piix_pci_info[] __devinitdata = {
31020+static const struct ide_port_info piix_pci_info[] __devinitconst = {
31021 /* 0: MPIIX */
31022 { /*
31023 * MPIIX actually has only a single IDE channel mapped to
31024diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31025index a6414a8..c04173e 100644
31026--- a/drivers/ide/rz1000.c
31027+++ b/drivers/ide/rz1000.c
31028@@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31029 }
31030 }
31031
31032-static const struct ide_port_info rz1000_chipset __devinitdata = {
31033+static const struct ide_port_info rz1000_chipset __devinitconst = {
31034 .name = DRV_NAME,
31035 .host_flags = IDE_HFLAG_NO_DMA,
31036 };
31037diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31038index 356b9b5..d4758eb 100644
31039--- a/drivers/ide/sc1200.c
31040+++ b/drivers/ide/sc1200.c
31041@@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31042 .dma_sff_read_status = ide_dma_sff_read_status,
31043 };
31044
31045-static const struct ide_port_info sc1200_chipset __devinitdata = {
31046+static const struct ide_port_info sc1200_chipset __devinitconst = {
31047 .name = DRV_NAME,
31048 .port_ops = &sc1200_port_ops,
31049 .dma_ops = &sc1200_dma_ops,
31050diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31051index b7f5b0c..9701038 100644
31052--- a/drivers/ide/scc_pata.c
31053+++ b/drivers/ide/scc_pata.c
31054@@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31055 .dma_sff_read_status = scc_dma_sff_read_status,
31056 };
31057
31058-static const struct ide_port_info scc_chipset __devinitdata = {
31059+static const struct ide_port_info scc_chipset __devinitconst = {
31060 .name = "sccIDE",
31061 .init_iops = init_iops_scc,
31062 .init_dma = scc_init_dma,
31063diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31064index 35fb8da..24d72ef 100644
31065--- a/drivers/ide/serverworks.c
31066+++ b/drivers/ide/serverworks.c
31067@@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31068 .cable_detect = svwks_cable_detect,
31069 };
31070
31071-static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31072+static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31073 { /* 0: OSB4 */
31074 .name = DRV_NAME,
31075 .init_chipset = init_chipset_svwks,
31076diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31077index ddeda44..46f7e30 100644
31078--- a/drivers/ide/siimage.c
31079+++ b/drivers/ide/siimage.c
31080@@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31081 .udma_mask = ATA_UDMA6, \
31082 }
31083
31084-static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31085+static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31086 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31087 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31088 };
31089diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31090index 4a00225..09e61b4 100644
31091--- a/drivers/ide/sis5513.c
31092+++ b/drivers/ide/sis5513.c
31093@@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31094 .cable_detect = sis_cable_detect,
31095 };
31096
31097-static const struct ide_port_info sis5513_chipset __devinitdata = {
31098+static const struct ide_port_info sis5513_chipset __devinitconst = {
31099 .name = DRV_NAME,
31100 .init_chipset = init_chipset_sis5513,
31101 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31102diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31103index f21dc2a..d051cd2 100644
31104--- a/drivers/ide/sl82c105.c
31105+++ b/drivers/ide/sl82c105.c
31106@@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31107 .dma_sff_read_status = ide_dma_sff_read_status,
31108 };
31109
31110-static const struct ide_port_info sl82c105_chipset __devinitdata = {
31111+static const struct ide_port_info sl82c105_chipset __devinitconst = {
31112 .name = DRV_NAME,
31113 .init_chipset = init_chipset_sl82c105,
31114 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31115diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31116index 864ffe0..863a5e9 100644
31117--- a/drivers/ide/slc90e66.c
31118+++ b/drivers/ide/slc90e66.c
31119@@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31120 .cable_detect = slc90e66_cable_detect,
31121 };
31122
31123-static const struct ide_port_info slc90e66_chipset __devinitdata = {
31124+static const struct ide_port_info slc90e66_chipset __devinitconst = {
31125 .name = DRV_NAME,
31126 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31127 .port_ops = &slc90e66_port_ops,
31128diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31129index 4799d5c..1794678 100644
31130--- a/drivers/ide/tc86c001.c
31131+++ b/drivers/ide/tc86c001.c
31132@@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31133 .dma_sff_read_status = ide_dma_sff_read_status,
31134 };
31135
31136-static const struct ide_port_info tc86c001_chipset __devinitdata = {
31137+static const struct ide_port_info tc86c001_chipset __devinitconst = {
31138 .name = DRV_NAME,
31139 .init_hwif = init_hwif_tc86c001,
31140 .port_ops = &tc86c001_port_ops,
31141diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31142index 281c914..55ce1b8 100644
31143--- a/drivers/ide/triflex.c
31144+++ b/drivers/ide/triflex.c
31145@@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31146 .set_dma_mode = triflex_set_mode,
31147 };
31148
31149-static const struct ide_port_info triflex_device __devinitdata = {
31150+static const struct ide_port_info triflex_device __devinitconst = {
31151 .name = DRV_NAME,
31152 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31153 .port_ops = &triflex_port_ops,
31154diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31155index 4b42ca0..e494a98 100644
31156--- a/drivers/ide/trm290.c
31157+++ b/drivers/ide/trm290.c
31158@@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31159 .dma_check = trm290_dma_check,
31160 };
31161
31162-static const struct ide_port_info trm290_chipset __devinitdata = {
31163+static const struct ide_port_info trm290_chipset __devinitconst = {
31164 .name = DRV_NAME,
31165 .init_hwif = init_hwif_trm290,
31166 .tp_ops = &trm290_tp_ops,
31167diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31168index f46f49c..eb77678 100644
31169--- a/drivers/ide/via82cxxx.c
31170+++ b/drivers/ide/via82cxxx.c
31171@@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31172 .cable_detect = via82cxxx_cable_detect,
31173 };
31174
31175-static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31176+static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31177 .name = DRV_NAME,
31178 .init_chipset = init_chipset_via82cxxx,
31179 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31180diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31181index 73d4531..c90cd2d 100644
31182--- a/drivers/ieee802154/fakehard.c
31183+++ b/drivers/ieee802154/fakehard.c
31184@@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31185 phy->transmit_power = 0xbf;
31186
31187 dev->netdev_ops = &fake_ops;
31188- dev->ml_priv = &fake_mlme;
31189+ dev->ml_priv = (void *)&fake_mlme;
31190
31191 priv = netdev_priv(dev);
31192 priv->phy = phy;
31193diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31194index c889aae..6cf5aa7 100644
31195--- a/drivers/infiniband/core/cm.c
31196+++ b/drivers/infiniband/core/cm.c
31197@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31198
31199 struct cm_counter_group {
31200 struct kobject obj;
31201- atomic_long_t counter[CM_ATTR_COUNT];
31202+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31203 };
31204
31205 struct cm_counter_attribute {
31206@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
31207 struct ib_mad_send_buf *msg = NULL;
31208 int ret;
31209
31210- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31211+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31212 counter[CM_REQ_COUNTER]);
31213
31214 /* Quick state check to discard duplicate REQs. */
31215@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
31216 if (!cm_id_priv)
31217 return;
31218
31219- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31220+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31221 counter[CM_REP_COUNTER]);
31222 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
31223 if (ret)
31224@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
31225 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
31226 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
31227 spin_unlock_irq(&cm_id_priv->lock);
31228- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31229+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31230 counter[CM_RTU_COUNTER]);
31231 goto out;
31232 }
31233@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
31234 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
31235 dreq_msg->local_comm_id);
31236 if (!cm_id_priv) {
31237- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31238+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31239 counter[CM_DREQ_COUNTER]);
31240 cm_issue_drep(work->port, work->mad_recv_wc);
31241 return -EINVAL;
31242@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
31243 case IB_CM_MRA_REP_RCVD:
31244 break;
31245 case IB_CM_TIMEWAIT:
31246- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31247+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31248 counter[CM_DREQ_COUNTER]);
31249 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31250 goto unlock;
31251@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
31252 cm_free_msg(msg);
31253 goto deref;
31254 case IB_CM_DREQ_RCVD:
31255- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31256+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31257 counter[CM_DREQ_COUNTER]);
31258 goto unlock;
31259 default:
31260@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
31261 ib_modify_mad(cm_id_priv->av.port->mad_agent,
31262 cm_id_priv->msg, timeout)) {
31263 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
31264- atomic_long_inc(&work->port->
31265+ atomic_long_inc_unchecked(&work->port->
31266 counter_group[CM_RECV_DUPLICATES].
31267 counter[CM_MRA_COUNTER]);
31268 goto out;
31269@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
31270 break;
31271 case IB_CM_MRA_REQ_RCVD:
31272 case IB_CM_MRA_REP_RCVD:
31273- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31274+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31275 counter[CM_MRA_COUNTER]);
31276 /* fall through */
31277 default:
31278@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
31279 case IB_CM_LAP_IDLE:
31280 break;
31281 case IB_CM_MRA_LAP_SENT:
31282- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31283+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31284 counter[CM_LAP_COUNTER]);
31285 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31286 goto unlock;
31287@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
31288 cm_free_msg(msg);
31289 goto deref;
31290 case IB_CM_LAP_RCVD:
31291- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31292+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31293 counter[CM_LAP_COUNTER]);
31294 goto unlock;
31295 default:
31296@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
31297 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
31298 if (cur_cm_id_priv) {
31299 spin_unlock_irq(&cm.lock);
31300- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31301+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31302 counter[CM_SIDR_REQ_COUNTER]);
31303 goto out; /* Duplicate message. */
31304 }
31305@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
31306 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
31307 msg->retries = 1;
31308
31309- atomic_long_add(1 + msg->retries,
31310+ atomic_long_add_unchecked(1 + msg->retries,
31311 &port->counter_group[CM_XMIT].counter[attr_index]);
31312 if (msg->retries)
31313- atomic_long_add(msg->retries,
31314+ atomic_long_add_unchecked(msg->retries,
31315 &port->counter_group[CM_XMIT_RETRIES].
31316 counter[attr_index]);
31317
31318@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
31319 }
31320
31321 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
31322- atomic_long_inc(&port->counter_group[CM_RECV].
31323+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
31324 counter[attr_id - CM_ATTR_ID_OFFSET]);
31325
31326 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
31327@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
31328 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
31329
31330 return sprintf(buf, "%ld\n",
31331- atomic_long_read(&group->counter[cm_attr->index]));
31332+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
31333 }
31334
31335 static const struct sysfs_ops cm_counter_ops = {
31336diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
31337index 176c8f9..2627b62 100644
31338--- a/drivers/infiniband/core/fmr_pool.c
31339+++ b/drivers/infiniband/core/fmr_pool.c
31340@@ -98,8 +98,8 @@ struct ib_fmr_pool {
31341
31342 struct task_struct *thread;
31343
31344- atomic_t req_ser;
31345- atomic_t flush_ser;
31346+ atomic_unchecked_t req_ser;
31347+ atomic_unchecked_t flush_ser;
31348
31349 wait_queue_head_t force_wait;
31350 };
31351@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
31352 struct ib_fmr_pool *pool = pool_ptr;
31353
31354 do {
31355- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
31356+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
31357 ib_fmr_batch_release(pool);
31358
31359- atomic_inc(&pool->flush_ser);
31360+ atomic_inc_unchecked(&pool->flush_ser);
31361 wake_up_interruptible(&pool->force_wait);
31362
31363 if (pool->flush_function)
31364@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
31365 }
31366
31367 set_current_state(TASK_INTERRUPTIBLE);
31368- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
31369+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
31370 !kthread_should_stop())
31371 schedule();
31372 __set_current_state(TASK_RUNNING);
31373@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
31374 pool->dirty_watermark = params->dirty_watermark;
31375 pool->dirty_len = 0;
31376 spin_lock_init(&pool->pool_lock);
31377- atomic_set(&pool->req_ser, 0);
31378- atomic_set(&pool->flush_ser, 0);
31379+ atomic_set_unchecked(&pool->req_ser, 0);
31380+ atomic_set_unchecked(&pool->flush_ser, 0);
31381 init_waitqueue_head(&pool->force_wait);
31382
31383 pool->thread = kthread_run(ib_fmr_cleanup_thread,
31384@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
31385 }
31386 spin_unlock_irq(&pool->pool_lock);
31387
31388- serial = atomic_inc_return(&pool->req_ser);
31389+ serial = atomic_inc_return_unchecked(&pool->req_ser);
31390 wake_up_process(pool->thread);
31391
31392 if (wait_event_interruptible(pool->force_wait,
31393- atomic_read(&pool->flush_ser) - serial >= 0))
31394+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
31395 return -EINTR;
31396
31397 return 0;
31398@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
31399 } else {
31400 list_add_tail(&fmr->list, &pool->dirty_list);
31401 if (++pool->dirty_len >= pool->dirty_watermark) {
31402- atomic_inc(&pool->req_ser);
31403+ atomic_inc_unchecked(&pool->req_ser);
31404 wake_up_process(pool->thread);
31405 }
31406 }
31407diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
31408index 40c8353..946b0e4 100644
31409--- a/drivers/infiniband/hw/cxgb4/mem.c
31410+++ b/drivers/infiniband/hw/cxgb4/mem.c
31411@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
31412 int err;
31413 struct fw_ri_tpte tpt;
31414 u32 stag_idx;
31415- static atomic_t key;
31416+ static atomic_unchecked_t key;
31417
31418 if (c4iw_fatal_error(rdev))
31419 return -EIO;
31420@@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
31421 &rdev->resource.tpt_fifo_lock);
31422 if (!stag_idx)
31423 return -ENOMEM;
31424- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
31425+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
31426 }
31427 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
31428 __func__, stag_state, type, pdid, stag_idx);
31429diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
31430index 79b3dbc..96e5fcc 100644
31431--- a/drivers/infiniband/hw/ipath/ipath_rc.c
31432+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
31433@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
31434 struct ib_atomic_eth *ateth;
31435 struct ipath_ack_entry *e;
31436 u64 vaddr;
31437- atomic64_t *maddr;
31438+ atomic64_unchecked_t *maddr;
31439 u64 sdata;
31440 u32 rkey;
31441 u8 next;
31442@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
31443 IB_ACCESS_REMOTE_ATOMIC)))
31444 goto nack_acc_unlck;
31445 /* Perform atomic OP and save result. */
31446- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
31447+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
31448 sdata = be64_to_cpu(ateth->swap_data);
31449 e = &qp->s_ack_queue[qp->r_head_ack_queue];
31450 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
31451- (u64) atomic64_add_return(sdata, maddr) - sdata :
31452+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
31453 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
31454 be64_to_cpu(ateth->compare_data),
31455 sdata);
31456diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
31457index 1f95bba..9530f87 100644
31458--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
31459+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
31460@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
31461 unsigned long flags;
31462 struct ib_wc wc;
31463 u64 sdata;
31464- atomic64_t *maddr;
31465+ atomic64_unchecked_t *maddr;
31466 enum ib_wc_status send_status;
31467
31468 /*
31469@@ -382,11 +382,11 @@ again:
31470 IB_ACCESS_REMOTE_ATOMIC)))
31471 goto acc_err;
31472 /* Perform atomic OP and save result. */
31473- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
31474+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
31475 sdata = wqe->wr.wr.atomic.compare_add;
31476 *(u64 *) sqp->s_sge.sge.vaddr =
31477 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
31478- (u64) atomic64_add_return(sdata, maddr) - sdata :
31479+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
31480 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
31481 sdata, wqe->wr.wr.atomic.swap);
31482 goto send_comp;
31483diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
31484index 7140199..da60063 100644
31485--- a/drivers/infiniband/hw/nes/nes.c
31486+++ b/drivers/infiniband/hw/nes/nes.c
31487@@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
31488 LIST_HEAD(nes_adapter_list);
31489 static LIST_HEAD(nes_dev_list);
31490
31491-atomic_t qps_destroyed;
31492+atomic_unchecked_t qps_destroyed;
31493
31494 static unsigned int ee_flsh_adapter;
31495 static unsigned int sysfs_nonidx_addr;
31496@@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
31497 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
31498 struct nes_adapter *nesadapter = nesdev->nesadapter;
31499
31500- atomic_inc(&qps_destroyed);
31501+ atomic_inc_unchecked(&qps_destroyed);
31502
31503 /* Free the control structures */
31504
31505diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
31506index c438e46..ca30356 100644
31507--- a/drivers/infiniband/hw/nes/nes.h
31508+++ b/drivers/infiniband/hw/nes/nes.h
31509@@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
31510 extern unsigned int wqm_quanta;
31511 extern struct list_head nes_adapter_list;
31512
31513-extern atomic_t cm_connects;
31514-extern atomic_t cm_accepts;
31515-extern atomic_t cm_disconnects;
31516-extern atomic_t cm_closes;
31517-extern atomic_t cm_connecteds;
31518-extern atomic_t cm_connect_reqs;
31519-extern atomic_t cm_rejects;
31520-extern atomic_t mod_qp_timouts;
31521-extern atomic_t qps_created;
31522-extern atomic_t qps_destroyed;
31523-extern atomic_t sw_qps_destroyed;
31524+extern atomic_unchecked_t cm_connects;
31525+extern atomic_unchecked_t cm_accepts;
31526+extern atomic_unchecked_t cm_disconnects;
31527+extern atomic_unchecked_t cm_closes;
31528+extern atomic_unchecked_t cm_connecteds;
31529+extern atomic_unchecked_t cm_connect_reqs;
31530+extern atomic_unchecked_t cm_rejects;
31531+extern atomic_unchecked_t mod_qp_timouts;
31532+extern atomic_unchecked_t qps_created;
31533+extern atomic_unchecked_t qps_destroyed;
31534+extern atomic_unchecked_t sw_qps_destroyed;
31535 extern u32 mh_detected;
31536 extern u32 mh_pauses_sent;
31537 extern u32 cm_packets_sent;
31538@@ -197,16 +197,16 @@ extern u32 cm_packets_created;
31539 extern u32 cm_packets_received;
31540 extern u32 cm_packets_dropped;
31541 extern u32 cm_packets_retrans;
31542-extern atomic_t cm_listens_created;
31543-extern atomic_t cm_listens_destroyed;
31544+extern atomic_unchecked_t cm_listens_created;
31545+extern atomic_unchecked_t cm_listens_destroyed;
31546 extern u32 cm_backlog_drops;
31547-extern atomic_t cm_loopbacks;
31548-extern atomic_t cm_nodes_created;
31549-extern atomic_t cm_nodes_destroyed;
31550-extern atomic_t cm_accel_dropped_pkts;
31551-extern atomic_t cm_resets_recvd;
31552-extern atomic_t pau_qps_created;
31553-extern atomic_t pau_qps_destroyed;
31554+extern atomic_unchecked_t cm_loopbacks;
31555+extern atomic_unchecked_t cm_nodes_created;
31556+extern atomic_unchecked_t cm_nodes_destroyed;
31557+extern atomic_unchecked_t cm_accel_dropped_pkts;
31558+extern atomic_unchecked_t cm_resets_recvd;
31559+extern atomic_unchecked_t pau_qps_created;
31560+extern atomic_unchecked_t pau_qps_destroyed;
31561
31562 extern u32 int_mod_timer_init;
31563 extern u32 int_mod_cq_depth_256;
31564diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
31565index a4972ab..1bcfc31 100644
31566--- a/drivers/infiniband/hw/nes/nes_cm.c
31567+++ b/drivers/infiniband/hw/nes/nes_cm.c
31568@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
31569 u32 cm_packets_retrans;
31570 u32 cm_packets_created;
31571 u32 cm_packets_received;
31572-atomic_t cm_listens_created;
31573-atomic_t cm_listens_destroyed;
31574+atomic_unchecked_t cm_listens_created;
31575+atomic_unchecked_t cm_listens_destroyed;
31576 u32 cm_backlog_drops;
31577-atomic_t cm_loopbacks;
31578-atomic_t cm_nodes_created;
31579-atomic_t cm_nodes_destroyed;
31580-atomic_t cm_accel_dropped_pkts;
31581-atomic_t cm_resets_recvd;
31582+atomic_unchecked_t cm_loopbacks;
31583+atomic_unchecked_t cm_nodes_created;
31584+atomic_unchecked_t cm_nodes_destroyed;
31585+atomic_unchecked_t cm_accel_dropped_pkts;
31586+atomic_unchecked_t cm_resets_recvd;
31587
31588 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
31589 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
31590@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
31591
31592 static struct nes_cm_core *g_cm_core;
31593
31594-atomic_t cm_connects;
31595-atomic_t cm_accepts;
31596-atomic_t cm_disconnects;
31597-atomic_t cm_closes;
31598-atomic_t cm_connecteds;
31599-atomic_t cm_connect_reqs;
31600-atomic_t cm_rejects;
31601+atomic_unchecked_t cm_connects;
31602+atomic_unchecked_t cm_accepts;
31603+atomic_unchecked_t cm_disconnects;
31604+atomic_unchecked_t cm_closes;
31605+atomic_unchecked_t cm_connecteds;
31606+atomic_unchecked_t cm_connect_reqs;
31607+atomic_unchecked_t cm_rejects;
31608
31609 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
31610 {
31611@@ -1274,7 +1274,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
31612 kfree(listener);
31613 listener = NULL;
31614 ret = 0;
31615- atomic_inc(&cm_listens_destroyed);
31616+ atomic_inc_unchecked(&cm_listens_destroyed);
31617 } else {
31618 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
31619 }
31620@@ -1473,7 +1473,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
31621 cm_node->rem_mac);
31622
31623 add_hte_node(cm_core, cm_node);
31624- atomic_inc(&cm_nodes_created);
31625+ atomic_inc_unchecked(&cm_nodes_created);
31626
31627 return cm_node;
31628 }
31629@@ -1531,7 +1531,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
31630 }
31631
31632 atomic_dec(&cm_core->node_cnt);
31633- atomic_inc(&cm_nodes_destroyed);
31634+ atomic_inc_unchecked(&cm_nodes_destroyed);
31635 nesqp = cm_node->nesqp;
31636 if (nesqp) {
31637 nesqp->cm_node = NULL;
31638@@ -1595,7 +1595,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
31639
31640 static void drop_packet(struct sk_buff *skb)
31641 {
31642- atomic_inc(&cm_accel_dropped_pkts);
31643+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
31644 dev_kfree_skb_any(skb);
31645 }
31646
31647@@ -1658,7 +1658,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
31648 {
31649
31650 int reset = 0; /* whether to send reset in case of err.. */
31651- atomic_inc(&cm_resets_recvd);
31652+ atomic_inc_unchecked(&cm_resets_recvd);
31653 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
31654 " refcnt=%d\n", cm_node, cm_node->state,
31655 atomic_read(&cm_node->ref_count));
31656@@ -2299,7 +2299,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
31657 rem_ref_cm_node(cm_node->cm_core, cm_node);
31658 return NULL;
31659 }
31660- atomic_inc(&cm_loopbacks);
31661+ atomic_inc_unchecked(&cm_loopbacks);
31662 loopbackremotenode->loopbackpartner = cm_node;
31663 loopbackremotenode->tcp_cntxt.rcv_wscale =
31664 NES_CM_DEFAULT_RCV_WND_SCALE;
31665@@ -2574,7 +2574,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
31666 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
31667 else {
31668 rem_ref_cm_node(cm_core, cm_node);
31669- atomic_inc(&cm_accel_dropped_pkts);
31670+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
31671 dev_kfree_skb_any(skb);
31672 }
31673 break;
31674@@ -2881,7 +2881,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
31675
31676 if ((cm_id) && (cm_id->event_handler)) {
31677 if (issue_disconn) {
31678- atomic_inc(&cm_disconnects);
31679+ atomic_inc_unchecked(&cm_disconnects);
31680 cm_event.event = IW_CM_EVENT_DISCONNECT;
31681 cm_event.status = disconn_status;
31682 cm_event.local_addr = cm_id->local_addr;
31683@@ -2903,7 +2903,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
31684 }
31685
31686 if (issue_close) {
31687- atomic_inc(&cm_closes);
31688+ atomic_inc_unchecked(&cm_closes);
31689 nes_disconnect(nesqp, 1);
31690
31691 cm_id->provider_data = nesqp;
31692@@ -3039,7 +3039,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
31693
31694 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
31695 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
31696- atomic_inc(&cm_accepts);
31697+ atomic_inc_unchecked(&cm_accepts);
31698
31699 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
31700 netdev_refcnt_read(nesvnic->netdev));
31701@@ -3241,7 +3241,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
31702 struct nes_cm_core *cm_core;
31703 u8 *start_buff;
31704
31705- atomic_inc(&cm_rejects);
31706+ atomic_inc_unchecked(&cm_rejects);
31707 cm_node = (struct nes_cm_node *)cm_id->provider_data;
31708 loopback = cm_node->loopbackpartner;
31709 cm_core = cm_node->cm_core;
31710@@ -3301,7 +3301,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
31711 ntohl(cm_id->local_addr.sin_addr.s_addr),
31712 ntohs(cm_id->local_addr.sin_port));
31713
31714- atomic_inc(&cm_connects);
31715+ atomic_inc_unchecked(&cm_connects);
31716 nesqp->active_conn = 1;
31717
31718 /* cache the cm_id in the qp */
31719@@ -3407,7 +3407,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
31720 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
31721 return err;
31722 }
31723- atomic_inc(&cm_listens_created);
31724+ atomic_inc_unchecked(&cm_listens_created);
31725 }
31726
31727 cm_id->add_ref(cm_id);
31728@@ -3508,7 +3508,7 @@ static void cm_event_connected(struct nes_cm_event *event)
31729
31730 if (nesqp->destroyed)
31731 return;
31732- atomic_inc(&cm_connecteds);
31733+ atomic_inc_unchecked(&cm_connecteds);
31734 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
31735 " local port 0x%04X. jiffies = %lu.\n",
31736 nesqp->hwqp.qp_id,
31737@@ -3695,7 +3695,7 @@ static void cm_event_reset(struct nes_cm_event *event)
31738
31739 cm_id->add_ref(cm_id);
31740 ret = cm_id->event_handler(cm_id, &cm_event);
31741- atomic_inc(&cm_closes);
31742+ atomic_inc_unchecked(&cm_closes);
31743 cm_event.event = IW_CM_EVENT_CLOSE;
31744 cm_event.status = 0;
31745 cm_event.provider_data = cm_id->provider_data;
31746@@ -3731,7 +3731,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
31747 return;
31748 cm_id = cm_node->cm_id;
31749
31750- atomic_inc(&cm_connect_reqs);
31751+ atomic_inc_unchecked(&cm_connect_reqs);
31752 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
31753 cm_node, cm_id, jiffies);
31754
31755@@ -3771,7 +3771,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
31756 return;
31757 cm_id = cm_node->cm_id;
31758
31759- atomic_inc(&cm_connect_reqs);
31760+ atomic_inc_unchecked(&cm_connect_reqs);
31761 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
31762 cm_node, cm_id, jiffies);
31763
31764diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
31765index 3ba7be3..c81f6ff 100644
31766--- a/drivers/infiniband/hw/nes/nes_mgt.c
31767+++ b/drivers/infiniband/hw/nes/nes_mgt.c
31768@@ -40,8 +40,8 @@
31769 #include "nes.h"
31770 #include "nes_mgt.h"
31771
31772-atomic_t pau_qps_created;
31773-atomic_t pau_qps_destroyed;
31774+atomic_unchecked_t pau_qps_created;
31775+atomic_unchecked_t pau_qps_destroyed;
31776
31777 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
31778 {
31779@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
31780 {
31781 struct sk_buff *skb;
31782 unsigned long flags;
31783- atomic_inc(&pau_qps_destroyed);
31784+ atomic_inc_unchecked(&pau_qps_destroyed);
31785
31786 /* Free packets that have not yet been forwarded */
31787 /* Lock is acquired by skb_dequeue when removing the skb */
31788@@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
31789 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
31790 skb_queue_head_init(&nesqp->pau_list);
31791 spin_lock_init(&nesqp->pau_lock);
31792- atomic_inc(&pau_qps_created);
31793+ atomic_inc_unchecked(&pau_qps_created);
31794 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
31795 }
31796
31797diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
31798index f3a3ecf..57d311d 100644
31799--- a/drivers/infiniband/hw/nes/nes_nic.c
31800+++ b/drivers/infiniband/hw/nes/nes_nic.c
31801@@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
31802 target_stat_values[++index] = mh_detected;
31803 target_stat_values[++index] = mh_pauses_sent;
31804 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
31805- target_stat_values[++index] = atomic_read(&cm_connects);
31806- target_stat_values[++index] = atomic_read(&cm_accepts);
31807- target_stat_values[++index] = atomic_read(&cm_disconnects);
31808- target_stat_values[++index] = atomic_read(&cm_connecteds);
31809- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
31810- target_stat_values[++index] = atomic_read(&cm_rejects);
31811- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
31812- target_stat_values[++index] = atomic_read(&qps_created);
31813- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
31814- target_stat_values[++index] = atomic_read(&qps_destroyed);
31815- target_stat_values[++index] = atomic_read(&cm_closes);
31816+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
31817+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
31818+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
31819+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
31820+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
31821+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
31822+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
31823+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
31824+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
31825+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
31826+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
31827 target_stat_values[++index] = cm_packets_sent;
31828 target_stat_values[++index] = cm_packets_bounced;
31829 target_stat_values[++index] = cm_packets_created;
31830 target_stat_values[++index] = cm_packets_received;
31831 target_stat_values[++index] = cm_packets_dropped;
31832 target_stat_values[++index] = cm_packets_retrans;
31833- target_stat_values[++index] = atomic_read(&cm_listens_created);
31834- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
31835+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
31836+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
31837 target_stat_values[++index] = cm_backlog_drops;
31838- target_stat_values[++index] = atomic_read(&cm_loopbacks);
31839- target_stat_values[++index] = atomic_read(&cm_nodes_created);
31840- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
31841- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
31842- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
31843+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
31844+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
31845+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
31846+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
31847+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
31848 target_stat_values[++index] = nesadapter->free_4kpbl;
31849 target_stat_values[++index] = nesadapter->free_256pbl;
31850 target_stat_values[++index] = int_mod_timer_init;
31851 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
31852 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
31853 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
31854- target_stat_values[++index] = atomic_read(&pau_qps_created);
31855- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
31856+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
31857+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
31858 }
31859
31860 /**
31861diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
31862index 0927b5c..ed67986 100644
31863--- a/drivers/infiniband/hw/nes/nes_verbs.c
31864+++ b/drivers/infiniband/hw/nes/nes_verbs.c
31865@@ -46,9 +46,9 @@
31866
31867 #include <rdma/ib_umem.h>
31868
31869-atomic_t mod_qp_timouts;
31870-atomic_t qps_created;
31871-atomic_t sw_qps_destroyed;
31872+atomic_unchecked_t mod_qp_timouts;
31873+atomic_unchecked_t qps_created;
31874+atomic_unchecked_t sw_qps_destroyed;
31875
31876 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
31877
31878@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
31879 if (init_attr->create_flags)
31880 return ERR_PTR(-EINVAL);
31881
31882- atomic_inc(&qps_created);
31883+ atomic_inc_unchecked(&qps_created);
31884 switch (init_attr->qp_type) {
31885 case IB_QPT_RC:
31886 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
31887@@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
31888 struct iw_cm_event cm_event;
31889 int ret = 0;
31890
31891- atomic_inc(&sw_qps_destroyed);
31892+ atomic_inc_unchecked(&sw_qps_destroyed);
31893 nesqp->destroyed = 1;
31894
31895 /* Blow away the connection if it exists. */
31896diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
31897index b881bdc..c2e360c 100644
31898--- a/drivers/infiniband/hw/qib/qib.h
31899+++ b/drivers/infiniband/hw/qib/qib.h
31900@@ -51,6 +51,7 @@
31901 #include <linux/completion.h>
31902 #include <linux/kref.h>
31903 #include <linux/sched.h>
31904+#include <linux/slab.h>
31905
31906 #include "qib_common.h"
31907 #include "qib_verbs.h"
31908diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
31909index c351aa4..e6967c2 100644
31910--- a/drivers/input/gameport/gameport.c
31911+++ b/drivers/input/gameport/gameport.c
31912@@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
31913 */
31914 static void gameport_init_port(struct gameport *gameport)
31915 {
31916- static atomic_t gameport_no = ATOMIC_INIT(0);
31917+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
31918
31919 __module_get(THIS_MODULE);
31920
31921 mutex_init(&gameport->drv_mutex);
31922 device_initialize(&gameport->dev);
31923 dev_set_name(&gameport->dev, "gameport%lu",
31924- (unsigned long)atomic_inc_return(&gameport_no) - 1);
31925+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
31926 gameport->dev.bus = &gameport_bus;
31927 gameport->dev.release = gameport_release_port;
31928 if (gameport->parent)
31929diff --git a/drivers/input/input.c b/drivers/input/input.c
31930index 1f78c95..3cddc6c 100644
31931--- a/drivers/input/input.c
31932+++ b/drivers/input/input.c
31933@@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
31934 */
31935 int input_register_device(struct input_dev *dev)
31936 {
31937- static atomic_t input_no = ATOMIC_INIT(0);
31938+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
31939 struct input_handler *handler;
31940 const char *path;
31941 int error;
31942@@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
31943 dev->setkeycode = input_default_setkeycode;
31944
31945 dev_set_name(&dev->dev, "input%ld",
31946- (unsigned long) atomic_inc_return(&input_no) - 1);
31947+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
31948
31949 error = device_add(&dev->dev);
31950 if (error)
31951diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
31952index b8d8611..7a4a04b 100644
31953--- a/drivers/input/joystick/sidewinder.c
31954+++ b/drivers/input/joystick/sidewinder.c
31955@@ -30,6 +30,7 @@
31956 #include <linux/kernel.h>
31957 #include <linux/module.h>
31958 #include <linux/slab.h>
31959+#include <linux/sched.h>
31960 #include <linux/init.h>
31961 #include <linux/input.h>
31962 #include <linux/gameport.h>
31963diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
31964index fd7a0d5..a4af10c 100644
31965--- a/drivers/input/joystick/xpad.c
31966+++ b/drivers/input/joystick/xpad.c
31967@@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
31968
31969 static int xpad_led_probe(struct usb_xpad *xpad)
31970 {
31971- static atomic_t led_seq = ATOMIC_INIT(0);
31972+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
31973 long led_no;
31974 struct xpad_led *led;
31975 struct led_classdev *led_cdev;
31976@@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
31977 if (!led)
31978 return -ENOMEM;
31979
31980- led_no = (long)atomic_inc_return(&led_seq) - 1;
31981+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
31982
31983 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
31984 led->xpad = xpad;
31985diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
31986index 0110b5a..d3ad144 100644
31987--- a/drivers/input/mousedev.c
31988+++ b/drivers/input/mousedev.c
31989@@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
31990
31991 spin_unlock_irq(&client->packet_lock);
31992
31993- if (copy_to_user(buffer, data, count))
31994+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
31995 return -EFAULT;
31996
31997 return count;
31998diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
31999index ba70058..571d25d 100644
32000--- a/drivers/input/serio/serio.c
32001+++ b/drivers/input/serio/serio.c
32002@@ -497,7 +497,7 @@ static void serio_release_port(struct device *dev)
32003 */
32004 static void serio_init_port(struct serio *serio)
32005 {
32006- static atomic_t serio_no = ATOMIC_INIT(0);
32007+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32008
32009 __module_get(THIS_MODULE);
32010
32011@@ -508,7 +508,7 @@ static void serio_init_port(struct serio *serio)
32012 mutex_init(&serio->drv_mutex);
32013 device_initialize(&serio->dev);
32014 dev_set_name(&serio->dev, "serio%ld",
32015- (long)atomic_inc_return(&serio_no) - 1);
32016+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
32017 serio->dev.bus = &serio_bus;
32018 serio->dev.release = serio_release_port;
32019 serio->dev.groups = serio_device_attr_groups;
32020diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32021index e44933d..9ba484a 100644
32022--- a/drivers/isdn/capi/capi.c
32023+++ b/drivers/isdn/capi/capi.c
32024@@ -83,8 +83,8 @@ struct capiminor {
32025
32026 struct capi20_appl *ap;
32027 u32 ncci;
32028- atomic_t datahandle;
32029- atomic_t msgid;
32030+ atomic_unchecked_t datahandle;
32031+ atomic_unchecked_t msgid;
32032
32033 struct tty_port port;
32034 int ttyinstop;
32035@@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32036 capimsg_setu16(s, 2, mp->ap->applid);
32037 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32038 capimsg_setu8 (s, 5, CAPI_RESP);
32039- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32040+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32041 capimsg_setu32(s, 8, mp->ncci);
32042 capimsg_setu16(s, 12, datahandle);
32043 }
32044@@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
32045 mp->outbytes -= len;
32046 spin_unlock_bh(&mp->outlock);
32047
32048- datahandle = atomic_inc_return(&mp->datahandle);
32049+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32050 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32051 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32052 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32053 capimsg_setu16(skb->data, 2, mp->ap->applid);
32054 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32055 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32056- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32057+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32058 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32059 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32060 capimsg_setu16(skb->data, 16, len); /* Data length */
32061diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
32062index db621db..825ea1a 100644
32063--- a/drivers/isdn/gigaset/common.c
32064+++ b/drivers/isdn/gigaset/common.c
32065@@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
32066 cs->commands_pending = 0;
32067 cs->cur_at_seq = 0;
32068 cs->gotfwver = -1;
32069- cs->open_count = 0;
32070+ local_set(&cs->open_count, 0);
32071 cs->dev = NULL;
32072 cs->tty = NULL;
32073 cs->tty_dev = NULL;
32074diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
32075index 212efaf..f187c6b 100644
32076--- a/drivers/isdn/gigaset/gigaset.h
32077+++ b/drivers/isdn/gigaset/gigaset.h
32078@@ -35,6 +35,7 @@
32079 #include <linux/tty_driver.h>
32080 #include <linux/list.h>
32081 #include <linux/atomic.h>
32082+#include <asm/local.h>
32083
32084 #define GIG_VERSION {0, 5, 0, 0}
32085 #define GIG_COMPAT {0, 4, 0, 0}
32086@@ -433,7 +434,7 @@ struct cardstate {
32087 spinlock_t cmdlock;
32088 unsigned curlen, cmdbytes;
32089
32090- unsigned open_count;
32091+ local_t open_count;
32092 struct tty_struct *tty;
32093 struct tasklet_struct if_wake_tasklet;
32094 unsigned control_state;
32095diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
32096index ee0a549..a7c9798 100644
32097--- a/drivers/isdn/gigaset/interface.c
32098+++ b/drivers/isdn/gigaset/interface.c
32099@@ -163,9 +163,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
32100 }
32101 tty->driver_data = cs;
32102
32103- ++cs->open_count;
32104-
32105- if (cs->open_count == 1) {
32106+ if (local_inc_return(&cs->open_count) == 1) {
32107 spin_lock_irqsave(&cs->lock, flags);
32108 cs->tty = tty;
32109 spin_unlock_irqrestore(&cs->lock, flags);
32110@@ -193,10 +191,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
32111
32112 if (!cs->connected)
32113 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32114- else if (!cs->open_count)
32115+ else if (!local_read(&cs->open_count))
32116 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32117 else {
32118- if (!--cs->open_count) {
32119+ if (!local_dec_return(&cs->open_count)) {
32120 spin_lock_irqsave(&cs->lock, flags);
32121 cs->tty = NULL;
32122 spin_unlock_irqrestore(&cs->lock, flags);
32123@@ -231,7 +229,7 @@ static int if_ioctl(struct tty_struct *tty,
32124 if (!cs->connected) {
32125 gig_dbg(DEBUG_IF, "not connected");
32126 retval = -ENODEV;
32127- } else if (!cs->open_count)
32128+ } else if (!local_read(&cs->open_count))
32129 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32130 else {
32131 retval = 0;
32132@@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
32133 retval = -ENODEV;
32134 goto done;
32135 }
32136- if (!cs->open_count) {
32137+ if (!local_read(&cs->open_count)) {
32138 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32139 retval = -ENODEV;
32140 goto done;
32141@@ -414,7 +412,7 @@ static int if_write_room(struct tty_struct *tty)
32142 if (!cs->connected) {
32143 gig_dbg(DEBUG_IF, "not connected");
32144 retval = -ENODEV;
32145- } else if (!cs->open_count)
32146+ } else if (!local_read(&cs->open_count))
32147 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32148 else if (cs->mstate != MS_LOCKED) {
32149 dev_warn(cs->dev, "can't write to unlocked device\n");
32150@@ -444,7 +442,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
32151
32152 if (!cs->connected)
32153 gig_dbg(DEBUG_IF, "not connected");
32154- else if (!cs->open_count)
32155+ else if (!local_read(&cs->open_count))
32156 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32157 else if (cs->mstate != MS_LOCKED)
32158 dev_warn(cs->dev, "can't write to unlocked device\n");
32159@@ -472,7 +470,7 @@ static void if_throttle(struct tty_struct *tty)
32160
32161 if (!cs->connected)
32162 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32163- else if (!cs->open_count)
32164+ else if (!local_read(&cs->open_count))
32165 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32166 else
32167 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
32168@@ -496,7 +494,7 @@ static void if_unthrottle(struct tty_struct *tty)
32169
32170 if (!cs->connected)
32171 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32172- else if (!cs->open_count)
32173+ else if (!local_read(&cs->open_count))
32174 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32175 else
32176 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
32177@@ -527,7 +525,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
32178 goto out;
32179 }
32180
32181- if (!cs->open_count) {
32182+ if (!local_read(&cs->open_count)) {
32183 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32184 goto out;
32185 }
32186diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32187index 2a57da59..e7a12ed 100644
32188--- a/drivers/isdn/hardware/avm/b1.c
32189+++ b/drivers/isdn/hardware/avm/b1.c
32190@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
32191 }
32192 if (left) {
32193 if (t4file->user) {
32194- if (copy_from_user(buf, dp, left))
32195+ if (left > sizeof buf || copy_from_user(buf, dp, left))
32196 return -EFAULT;
32197 } else {
32198 memcpy(buf, dp, left);
32199@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
32200 }
32201 if (left) {
32202 if (config->user) {
32203- if (copy_from_user(buf, dp, left))
32204+ if (left > sizeof buf || copy_from_user(buf, dp, left))
32205 return -EFAULT;
32206 } else {
32207 memcpy(buf, dp, left);
32208diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32209index 85784a7..a19ca98 100644
32210--- a/drivers/isdn/hardware/eicon/divasync.h
32211+++ b/drivers/isdn/hardware/eicon/divasync.h
32212@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32213 } diva_didd_add_adapter_t;
32214 typedef struct _diva_didd_remove_adapter {
32215 IDI_CALL p_request;
32216-} diva_didd_remove_adapter_t;
32217+} __no_const diva_didd_remove_adapter_t;
32218 typedef struct _diva_didd_read_adapter_array {
32219 void * buffer;
32220 dword length;
32221diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32222index a3bd163..8956575 100644
32223--- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32224+++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32225@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32226 typedef struct _diva_os_idi_adapter_interface {
32227 diva_init_card_proc_t cleanup_adapter_proc;
32228 diva_cmd_card_proc_t cmd_proc;
32229-} diva_os_idi_adapter_interface_t;
32230+} __no_const diva_os_idi_adapter_interface_t;
32231
32232 typedef struct _diva_os_xdi_adapter {
32233 struct list_head link;
32234diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32235index 1f355bb..43f1fea 100644
32236--- a/drivers/isdn/icn/icn.c
32237+++ b/drivers/isdn/icn/icn.c
32238@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
32239 if (count > len)
32240 count = len;
32241 if (user) {
32242- if (copy_from_user(msg, buf, count))
32243+ if (count > sizeof msg || copy_from_user(msg, buf, count))
32244 return -EFAULT;
32245 } else
32246 memcpy(msg, buf, count);
32247diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
32248index b5fdcb7..5b6c59f 100644
32249--- a/drivers/lguest/core.c
32250+++ b/drivers/lguest/core.c
32251@@ -92,9 +92,17 @@ static __init int map_switcher(void)
32252 * it's worked so far. The end address needs +1 because __get_vm_area
32253 * allocates an extra guard page, so we need space for that.
32254 */
32255+
32256+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32257+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32258+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
32259+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32260+#else
32261 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32262 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
32263 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32264+#endif
32265+
32266 if (!switcher_vma) {
32267 err = -ENOMEM;
32268 printk("lguest: could not map switcher pages high\n");
32269@@ -119,7 +127,7 @@ static __init int map_switcher(void)
32270 * Now the Switcher is mapped at the right address, we can't fail!
32271 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
32272 */
32273- memcpy(switcher_vma->addr, start_switcher_text,
32274+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
32275 end_switcher_text - start_switcher_text);
32276
32277 printk(KERN_INFO "lguest: mapped switcher at %p\n",
32278diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
32279index 3980903..ce25c5e 100644
32280--- a/drivers/lguest/x86/core.c
32281+++ b/drivers/lguest/x86/core.c
32282@@ -59,7 +59,7 @@ static struct {
32283 /* Offset from where switcher.S was compiled to where we've copied it */
32284 static unsigned long switcher_offset(void)
32285 {
32286- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
32287+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
32288 }
32289
32290 /* This cpu's struct lguest_pages. */
32291@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
32292 * These copies are pretty cheap, so we do them unconditionally: */
32293 /* Save the current Host top-level page directory.
32294 */
32295+
32296+#ifdef CONFIG_PAX_PER_CPU_PGD
32297+ pages->state.host_cr3 = read_cr3();
32298+#else
32299 pages->state.host_cr3 = __pa(current->mm->pgd);
32300+#endif
32301+
32302 /*
32303 * Set up the Guest's page tables to see this CPU's pages (and no
32304 * other CPU's pages).
32305@@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
32306 * compiled-in switcher code and the high-mapped copy we just made.
32307 */
32308 for (i = 0; i < IDT_ENTRIES; i++)
32309- default_idt_entries[i] += switcher_offset();
32310+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
32311
32312 /*
32313 * Set up the Switcher's per-cpu areas.
32314@@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
32315 * it will be undisturbed when we switch. To change %cs and jump we
32316 * need this structure to feed to Intel's "lcall" instruction.
32317 */
32318- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
32319+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
32320 lguest_entry.segment = LGUEST_CS;
32321
32322 /*
32323diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
32324index 40634b0..4f5855e 100644
32325--- a/drivers/lguest/x86/switcher_32.S
32326+++ b/drivers/lguest/x86/switcher_32.S
32327@@ -87,6 +87,7 @@
32328 #include <asm/page.h>
32329 #include <asm/segment.h>
32330 #include <asm/lguest.h>
32331+#include <asm/processor-flags.h>
32332
32333 // We mark the start of the code to copy
32334 // It's placed in .text tho it's never run here
32335@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
32336 // Changes type when we load it: damn Intel!
32337 // For after we switch over our page tables
32338 // That entry will be read-only: we'd crash.
32339+
32340+#ifdef CONFIG_PAX_KERNEXEC
32341+ mov %cr0, %edx
32342+ xor $X86_CR0_WP, %edx
32343+ mov %edx, %cr0
32344+#endif
32345+
32346 movl $(GDT_ENTRY_TSS*8), %edx
32347 ltr %dx
32348
32349@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
32350 // Let's clear it again for our return.
32351 // The GDT descriptor of the Host
32352 // Points to the table after two "size" bytes
32353- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
32354+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
32355 // Clear "used" from type field (byte 5, bit 2)
32356- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
32357+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
32358+
32359+#ifdef CONFIG_PAX_KERNEXEC
32360+ mov %cr0, %eax
32361+ xor $X86_CR0_WP, %eax
32362+ mov %eax, %cr0
32363+#endif
32364
32365 // Once our page table's switched, the Guest is live!
32366 // The Host fades as we run this final step.
32367@@ -295,13 +309,12 @@ deliver_to_host:
32368 // I consulted gcc, and it gave
32369 // These instructions, which I gladly credit:
32370 leal (%edx,%ebx,8), %eax
32371- movzwl (%eax),%edx
32372- movl 4(%eax), %eax
32373- xorw %ax, %ax
32374- orl %eax, %edx
32375+ movl 4(%eax), %edx
32376+ movw (%eax), %dx
32377 // Now the address of the handler's in %edx
32378 // We call it now: its "iret" drops us home.
32379- jmp *%edx
32380+ ljmp $__KERNEL_CS, $1f
32381+1: jmp *%edx
32382
32383 // Every interrupt can come to us here
32384 // But we must truly tell each apart.
32385diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
32386index 4daf9e5..b8d1d0f 100644
32387--- a/drivers/macintosh/macio_asic.c
32388+++ b/drivers/macintosh/macio_asic.c
32389@@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
32390 * MacIO is matched against any Apple ID, it's probe() function
32391 * will then decide wether it applies or not
32392 */
32393-static const struct pci_device_id __devinitdata pci_ids [] = { {
32394+static const struct pci_device_id __devinitconst pci_ids [] = { {
32395 .vendor = PCI_VENDOR_ID_APPLE,
32396 .device = PCI_ANY_ID,
32397 .subvendor = PCI_ANY_ID,
32398diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
32399index 1ce84ed..0fdd40a 100644
32400--- a/drivers/md/dm-ioctl.c
32401+++ b/drivers/md/dm-ioctl.c
32402@@ -1589,7 +1589,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
32403 cmd == DM_LIST_VERSIONS_CMD)
32404 return 0;
32405
32406- if ((cmd == DM_DEV_CREATE_CMD)) {
32407+ if (cmd == DM_DEV_CREATE_CMD) {
32408 if (!*param->name) {
32409 DMWARN("name not supplied when creating device");
32410 return -EINVAL;
32411diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
32412index 9bfd057..01180bc 100644
32413--- a/drivers/md/dm-raid1.c
32414+++ b/drivers/md/dm-raid1.c
32415@@ -40,7 +40,7 @@ enum dm_raid1_error {
32416
32417 struct mirror {
32418 struct mirror_set *ms;
32419- atomic_t error_count;
32420+ atomic_unchecked_t error_count;
32421 unsigned long error_type;
32422 struct dm_dev *dev;
32423 sector_t offset;
32424@@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
32425 struct mirror *m;
32426
32427 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
32428- if (!atomic_read(&m->error_count))
32429+ if (!atomic_read_unchecked(&m->error_count))
32430 return m;
32431
32432 return NULL;
32433@@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
32434 * simple way to tell if a device has encountered
32435 * errors.
32436 */
32437- atomic_inc(&m->error_count);
32438+ atomic_inc_unchecked(&m->error_count);
32439
32440 if (test_and_set_bit(error_type, &m->error_type))
32441 return;
32442@@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
32443 struct mirror *m = get_default_mirror(ms);
32444
32445 do {
32446- if (likely(!atomic_read(&m->error_count)))
32447+ if (likely(!atomic_read_unchecked(&m->error_count)))
32448 return m;
32449
32450 if (m-- == ms->mirror)
32451@@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
32452 {
32453 struct mirror *default_mirror = get_default_mirror(m->ms);
32454
32455- return !atomic_read(&default_mirror->error_count);
32456+ return !atomic_read_unchecked(&default_mirror->error_count);
32457 }
32458
32459 static int mirror_available(struct mirror_set *ms, struct bio *bio)
32460@@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
32461 */
32462 if (likely(region_in_sync(ms, region, 1)))
32463 m = choose_mirror(ms, bio->bi_sector);
32464- else if (m && atomic_read(&m->error_count))
32465+ else if (m && atomic_read_unchecked(&m->error_count))
32466 m = NULL;
32467
32468 if (likely(m))
32469@@ -937,7 +937,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
32470 }
32471
32472 ms->mirror[mirror].ms = ms;
32473- atomic_set(&(ms->mirror[mirror].error_count), 0);
32474+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
32475 ms->mirror[mirror].error_type = 0;
32476 ms->mirror[mirror].offset = offset;
32477
32478@@ -1347,7 +1347,7 @@ static void mirror_resume(struct dm_target *ti)
32479 */
32480 static char device_status_char(struct mirror *m)
32481 {
32482- if (!atomic_read(&(m->error_count)))
32483+ if (!atomic_read_unchecked(&(m->error_count)))
32484 return 'A';
32485
32486 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
32487diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
32488index 3d80cf0..b77cc47 100644
32489--- a/drivers/md/dm-stripe.c
32490+++ b/drivers/md/dm-stripe.c
32491@@ -20,7 +20,7 @@ struct stripe {
32492 struct dm_dev *dev;
32493 sector_t physical_start;
32494
32495- atomic_t error_count;
32496+ atomic_unchecked_t error_count;
32497 };
32498
32499 struct stripe_c {
32500@@ -192,7 +192,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
32501 kfree(sc);
32502 return r;
32503 }
32504- atomic_set(&(sc->stripe[i].error_count), 0);
32505+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
32506 }
32507
32508 ti->private = sc;
32509@@ -314,7 +314,7 @@ static int stripe_status(struct dm_target *ti,
32510 DMEMIT("%d ", sc->stripes);
32511 for (i = 0; i < sc->stripes; i++) {
32512 DMEMIT("%s ", sc->stripe[i].dev->name);
32513- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
32514+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
32515 'D' : 'A';
32516 }
32517 buffer[i] = '\0';
32518@@ -361,8 +361,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
32519 */
32520 for (i = 0; i < sc->stripes; i++)
32521 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
32522- atomic_inc(&(sc->stripe[i].error_count));
32523- if (atomic_read(&(sc->stripe[i].error_count)) <
32524+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
32525+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
32526 DM_IO_ERROR_THRESHOLD)
32527 schedule_work(&sc->trigger_event);
32528 }
32529diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
32530index 63cc542..8d45caf3 100644
32531--- a/drivers/md/dm-table.c
32532+++ b/drivers/md/dm-table.c
32533@@ -391,7 +391,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
32534 if (!dev_size)
32535 return 0;
32536
32537- if ((start >= dev_size) || (start + len > dev_size)) {
32538+ if ((start >= dev_size) || (len > dev_size - start)) {
32539 DMWARN("%s: %s too small for target: "
32540 "start=%llu, len=%llu, dev_size=%llu",
32541 dm_device_name(ti->table->md), bdevname(bdev, b),
32542diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
32543index 237571a..fb6d19b 100644
32544--- a/drivers/md/dm-thin-metadata.c
32545+++ b/drivers/md/dm-thin-metadata.c
32546@@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
32547
32548 pmd->info.tm = tm;
32549 pmd->info.levels = 2;
32550- pmd->info.value_type.context = pmd->data_sm;
32551+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
32552 pmd->info.value_type.size = sizeof(__le64);
32553 pmd->info.value_type.inc = data_block_inc;
32554 pmd->info.value_type.dec = data_block_dec;
32555@@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
32556
32557 pmd->bl_info.tm = tm;
32558 pmd->bl_info.levels = 1;
32559- pmd->bl_info.value_type.context = pmd->data_sm;
32560+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
32561 pmd->bl_info.value_type.size = sizeof(__le64);
32562 pmd->bl_info.value_type.inc = data_block_inc;
32563 pmd->bl_info.value_type.dec = data_block_dec;
32564diff --git a/drivers/md/dm.c b/drivers/md/dm.c
32565index b89c548..2af3ce4 100644
32566--- a/drivers/md/dm.c
32567+++ b/drivers/md/dm.c
32568@@ -176,9 +176,9 @@ struct mapped_device {
32569 /*
32570 * Event handling.
32571 */
32572- atomic_t event_nr;
32573+ atomic_unchecked_t event_nr;
32574 wait_queue_head_t eventq;
32575- atomic_t uevent_seq;
32576+ atomic_unchecked_t uevent_seq;
32577 struct list_head uevent_list;
32578 spinlock_t uevent_lock; /* Protect access to uevent_list */
32579
32580@@ -1844,8 +1844,8 @@ static struct mapped_device *alloc_dev(int minor)
32581 rwlock_init(&md->map_lock);
32582 atomic_set(&md->holders, 1);
32583 atomic_set(&md->open_count, 0);
32584- atomic_set(&md->event_nr, 0);
32585- atomic_set(&md->uevent_seq, 0);
32586+ atomic_set_unchecked(&md->event_nr, 0);
32587+ atomic_set_unchecked(&md->uevent_seq, 0);
32588 INIT_LIST_HEAD(&md->uevent_list);
32589 spin_lock_init(&md->uevent_lock);
32590
32591@@ -1979,7 +1979,7 @@ static void event_callback(void *context)
32592
32593 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
32594
32595- atomic_inc(&md->event_nr);
32596+ atomic_inc_unchecked(&md->event_nr);
32597 wake_up(&md->eventq);
32598 }
32599
32600@@ -2621,18 +2621,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
32601
32602 uint32_t dm_next_uevent_seq(struct mapped_device *md)
32603 {
32604- return atomic_add_return(1, &md->uevent_seq);
32605+ return atomic_add_return_unchecked(1, &md->uevent_seq);
32606 }
32607
32608 uint32_t dm_get_event_nr(struct mapped_device *md)
32609 {
32610- return atomic_read(&md->event_nr);
32611+ return atomic_read_unchecked(&md->event_nr);
32612 }
32613
32614 int dm_wait_event(struct mapped_device *md, int event_nr)
32615 {
32616 return wait_event_interruptible(md->eventq,
32617- (event_nr != atomic_read(&md->event_nr)));
32618+ (event_nr != atomic_read_unchecked(&md->event_nr)));
32619 }
32620
32621 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
32622diff --git a/drivers/md/md.c b/drivers/md/md.c
32623index 6acc846..80a6b96 100644
32624--- a/drivers/md/md.c
32625+++ b/drivers/md/md.c
32626@@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
32627 * start build, activate spare
32628 */
32629 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
32630-static atomic_t md_event_count;
32631+static atomic_unchecked_t md_event_count;
32632 void md_new_event(struct mddev *mddev)
32633 {
32634- atomic_inc(&md_event_count);
32635+ atomic_inc_unchecked(&md_event_count);
32636 wake_up(&md_event_waiters);
32637 }
32638 EXPORT_SYMBOL_GPL(md_new_event);
32639@@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
32640 */
32641 static void md_new_event_inintr(struct mddev *mddev)
32642 {
32643- atomic_inc(&md_event_count);
32644+ atomic_inc_unchecked(&md_event_count);
32645 wake_up(&md_event_waiters);
32646 }
32647
32648@@ -1524,7 +1524,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
32649
32650 rdev->preferred_minor = 0xffff;
32651 rdev->data_offset = le64_to_cpu(sb->data_offset);
32652- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
32653+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
32654
32655 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
32656 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
32657@@ -1743,7 +1743,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
32658 else
32659 sb->resync_offset = cpu_to_le64(0);
32660
32661- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
32662+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
32663
32664 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
32665 sb->size = cpu_to_le64(mddev->dev_sectors);
32666@@ -2689,7 +2689,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
32667 static ssize_t
32668 errors_show(struct md_rdev *rdev, char *page)
32669 {
32670- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
32671+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
32672 }
32673
32674 static ssize_t
32675@@ -2698,7 +2698,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
32676 char *e;
32677 unsigned long n = simple_strtoul(buf, &e, 10);
32678 if (*buf && (*e == 0 || *e == '\n')) {
32679- atomic_set(&rdev->corrected_errors, n);
32680+ atomic_set_unchecked(&rdev->corrected_errors, n);
32681 return len;
32682 }
32683 return -EINVAL;
32684@@ -3084,8 +3084,8 @@ int md_rdev_init(struct md_rdev *rdev)
32685 rdev->sb_loaded = 0;
32686 rdev->bb_page = NULL;
32687 atomic_set(&rdev->nr_pending, 0);
32688- atomic_set(&rdev->read_errors, 0);
32689- atomic_set(&rdev->corrected_errors, 0);
32690+ atomic_set_unchecked(&rdev->read_errors, 0);
32691+ atomic_set_unchecked(&rdev->corrected_errors, 0);
32692
32693 INIT_LIST_HEAD(&rdev->same_set);
32694 init_waitqueue_head(&rdev->blocked_wait);
32695@@ -6736,7 +6736,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
32696
32697 spin_unlock(&pers_lock);
32698 seq_printf(seq, "\n");
32699- seq->poll_event = atomic_read(&md_event_count);
32700+ seq->poll_event = atomic_read_unchecked(&md_event_count);
32701 return 0;
32702 }
32703 if (v == (void*)2) {
32704@@ -6828,7 +6828,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
32705 chunk_kb ? "KB" : "B");
32706 if (bitmap->file) {
32707 seq_printf(seq, ", file: ");
32708- seq_path(seq, &bitmap->file->f_path, " \t\n");
32709+ seq_path(seq, &bitmap->file->f_path, " \t\n\\");
32710 }
32711
32712 seq_printf(seq, "\n");
32713@@ -6859,7 +6859,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
32714 return error;
32715
32716 seq = file->private_data;
32717- seq->poll_event = atomic_read(&md_event_count);
32718+ seq->poll_event = atomic_read_unchecked(&md_event_count);
32719 return error;
32720 }
32721
32722@@ -6873,7 +6873,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
32723 /* always allow read */
32724 mask = POLLIN | POLLRDNORM;
32725
32726- if (seq->poll_event != atomic_read(&md_event_count))
32727+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
32728 mask |= POLLERR | POLLPRI;
32729 return mask;
32730 }
32731@@ -6917,7 +6917,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
32732 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
32733 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
32734 (int)part_stat_read(&disk->part0, sectors[1]) -
32735- atomic_read(&disk->sync_io);
32736+ atomic_read_unchecked(&disk->sync_io);
32737 /* sync IO will cause sync_io to increase before the disk_stats
32738 * as sync_io is counted when a request starts, and
32739 * disk_stats is counted when it completes.
32740diff --git a/drivers/md/md.h b/drivers/md/md.h
32741index 44c63df..b795d1a 100644
32742--- a/drivers/md/md.h
32743+++ b/drivers/md/md.h
32744@@ -93,13 +93,13 @@ struct md_rdev {
32745 * only maintained for arrays that
32746 * support hot removal
32747 */
32748- atomic_t read_errors; /* number of consecutive read errors that
32749+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
32750 * we have tried to ignore.
32751 */
32752 struct timespec last_read_error; /* monotonic time since our
32753 * last read error
32754 */
32755- atomic_t corrected_errors; /* number of corrected read errors,
32756+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
32757 * for reporting to userspace and storing
32758 * in superblock.
32759 */
32760@@ -421,7 +421,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
32761
32762 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
32763 {
32764- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
32765+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
32766 }
32767
32768 struct md_personality
32769diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
32770index 50ed53b..4f29d7d 100644
32771--- a/drivers/md/persistent-data/dm-space-map-checker.c
32772+++ b/drivers/md/persistent-data/dm-space-map-checker.c
32773@@ -159,7 +159,7 @@ static void ca_destroy(struct count_array *ca)
32774 /*----------------------------------------------------------------*/
32775
32776 struct sm_checker {
32777- struct dm_space_map sm;
32778+ dm_space_map_no_const sm;
32779
32780 struct count_array old_counts;
32781 struct count_array counts;
32782diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
32783index fc469ba..2d91555 100644
32784--- a/drivers/md/persistent-data/dm-space-map-disk.c
32785+++ b/drivers/md/persistent-data/dm-space-map-disk.c
32786@@ -23,7 +23,7 @@
32787 * Space map interface.
32788 */
32789 struct sm_disk {
32790- struct dm_space_map sm;
32791+ dm_space_map_no_const sm;
32792
32793 struct ll_disk ll;
32794 struct ll_disk old_ll;
32795diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
32796index e89ae5e..062e4c2 100644
32797--- a/drivers/md/persistent-data/dm-space-map-metadata.c
32798+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
32799@@ -43,7 +43,7 @@ struct block_op {
32800 };
32801
32802 struct sm_metadata {
32803- struct dm_space_map sm;
32804+ dm_space_map_no_const sm;
32805
32806 struct ll_disk ll;
32807 struct ll_disk old_ll;
32808diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
32809index 1cbfc6b..56e1dbb 100644
32810--- a/drivers/md/persistent-data/dm-space-map.h
32811+++ b/drivers/md/persistent-data/dm-space-map.h
32812@@ -60,6 +60,7 @@ struct dm_space_map {
32813 int (*root_size)(struct dm_space_map *sm, size_t *result);
32814 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
32815 };
32816+typedef struct dm_space_map __no_const dm_space_map_no_const;
32817
32818 /*----------------------------------------------------------------*/
32819
32820diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
32821index 118e0f6..210c4d7 100644
32822--- a/drivers/md/raid1.c
32823+++ b/drivers/md/raid1.c
32824@@ -1645,7 +1645,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
32825 if (r1_sync_page_io(rdev, sect, s,
32826 bio->bi_io_vec[idx].bv_page,
32827 READ) != 0)
32828- atomic_add(s, &rdev->corrected_errors);
32829+ atomic_add_unchecked(s, &rdev->corrected_errors);
32830 }
32831 sectors -= s;
32832 sect += s;
32833@@ -1858,7 +1858,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
32834 test_bit(In_sync, &rdev->flags)) {
32835 if (r1_sync_page_io(rdev, sect, s,
32836 conf->tmppage, READ)) {
32837- atomic_add(s, &rdev->corrected_errors);
32838+ atomic_add_unchecked(s, &rdev->corrected_errors);
32839 printk(KERN_INFO
32840 "md/raid1:%s: read error corrected "
32841 "(%d sectors at %llu on %s)\n",
32842diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
32843index be7101d..f23ba30 100644
32844--- a/drivers/md/raid10.c
32845+++ b/drivers/md/raid10.c
32846@@ -1636,7 +1636,7 @@ static void end_sync_read(struct bio *bio, int error)
32847 /* The write handler will notice the lack of
32848 * R10BIO_Uptodate and record any errors etc
32849 */
32850- atomic_add(r10_bio->sectors,
32851+ atomic_add_unchecked(r10_bio->sectors,
32852 &conf->mirrors[d].rdev->corrected_errors);
32853
32854 /* for reconstruct, we always reschedule after a read.
32855@@ -1987,7 +1987,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
32856 {
32857 struct timespec cur_time_mon;
32858 unsigned long hours_since_last;
32859- unsigned int read_errors = atomic_read(&rdev->read_errors);
32860+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
32861
32862 ktime_get_ts(&cur_time_mon);
32863
32864@@ -2009,9 +2009,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
32865 * overflowing the shift of read_errors by hours_since_last.
32866 */
32867 if (hours_since_last >= 8 * sizeof(read_errors))
32868- atomic_set(&rdev->read_errors, 0);
32869+ atomic_set_unchecked(&rdev->read_errors, 0);
32870 else
32871- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
32872+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
32873 }
32874
32875 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
32876@@ -2065,8 +2065,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
32877 return;
32878
32879 check_decay_read_errors(mddev, rdev);
32880- atomic_inc(&rdev->read_errors);
32881- if (atomic_read(&rdev->read_errors) > max_read_errors) {
32882+ atomic_inc_unchecked(&rdev->read_errors);
32883+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
32884 char b[BDEVNAME_SIZE];
32885 bdevname(rdev->bdev, b);
32886
32887@@ -2074,7 +2074,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
32888 "md/raid10:%s: %s: Raid device exceeded "
32889 "read_error threshold [cur %d:max %d]\n",
32890 mdname(mddev), b,
32891- atomic_read(&rdev->read_errors), max_read_errors);
32892+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
32893 printk(KERN_NOTICE
32894 "md/raid10:%s: %s: Failing raid device\n",
32895 mdname(mddev), b);
32896@@ -2223,7 +2223,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
32897 (unsigned long long)(
32898 sect + rdev->data_offset),
32899 bdevname(rdev->bdev, b));
32900- atomic_add(s, &rdev->corrected_errors);
32901+ atomic_add_unchecked(s, &rdev->corrected_errors);
32902 }
32903
32904 rdev_dec_pending(rdev, mddev);
32905diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
32906index 360f2b9..08b5382 100644
32907--- a/drivers/md/raid5.c
32908+++ b/drivers/md/raid5.c
32909@@ -1687,18 +1687,18 @@ static void raid5_end_read_request(struct bio * bi, int error)
32910 (unsigned long long)(sh->sector
32911 + rdev->data_offset),
32912 bdevname(rdev->bdev, b));
32913- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
32914+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
32915 clear_bit(R5_ReadError, &sh->dev[i].flags);
32916 clear_bit(R5_ReWrite, &sh->dev[i].flags);
32917 }
32918- if (atomic_read(&rdev->read_errors))
32919- atomic_set(&rdev->read_errors, 0);
32920+ if (atomic_read_unchecked(&rdev->read_errors))
32921+ atomic_set_unchecked(&rdev->read_errors, 0);
32922 } else {
32923 const char *bdn = bdevname(rdev->bdev, b);
32924 int retry = 0;
32925
32926 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
32927- atomic_inc(&rdev->read_errors);
32928+ atomic_inc_unchecked(&rdev->read_errors);
32929 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
32930 printk_ratelimited(
32931 KERN_WARNING
32932@@ -1727,7 +1727,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
32933 (unsigned long long)(sh->sector
32934 + rdev->data_offset),
32935 bdn);
32936- else if (atomic_read(&rdev->read_errors)
32937+ else if (atomic_read_unchecked(&rdev->read_errors)
32938 > conf->max_nr_stripes)
32939 printk(KERN_WARNING
32940 "md/raid:%s: Too many read errors, failing device %s.\n",
32941diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
32942index ce4f858..7bcfb46 100644
32943--- a/drivers/media/dvb/ddbridge/ddbridge-core.c
32944+++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
32945@@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
32946 .subvendor = _subvend, .subdevice = _subdev, \
32947 .driver_data = (unsigned long)&_driverdata }
32948
32949-static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
32950+static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
32951 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
32952 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
32953 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
32954diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
32955index a7d876f..8c21b61 100644
32956--- a/drivers/media/dvb/dvb-core/dvb_demux.h
32957+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
32958@@ -73,7 +73,7 @@ struct dvb_demux_feed {
32959 union {
32960 dmx_ts_cb ts;
32961 dmx_section_cb sec;
32962- } cb;
32963+ } __no_const cb;
32964
32965 struct dvb_demux *demux;
32966 void *priv;
32967diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
32968index 00a6732..70a682e 100644
32969--- a/drivers/media/dvb/dvb-core/dvbdev.c
32970+++ b/drivers/media/dvb/dvb-core/dvbdev.c
32971@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
32972 const struct dvb_device *template, void *priv, int type)
32973 {
32974 struct dvb_device *dvbdev;
32975- struct file_operations *dvbdevfops;
32976+ file_operations_no_const *dvbdevfops;
32977 struct device *clsdev;
32978 int minor;
32979 int id;
32980diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
32981index 3940bb0..fb3952a 100644
32982--- a/drivers/media/dvb/dvb-usb/cxusb.c
32983+++ b/drivers/media/dvb/dvb-usb/cxusb.c
32984@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
32985
32986 struct dib0700_adapter_state {
32987 int (*set_param_save) (struct dvb_frontend *);
32988-};
32989+} __no_const;
32990
32991 static int dib7070_set_param_override(struct dvb_frontend *fe)
32992 {
32993diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
32994index 451c5a7..649f711 100644
32995--- a/drivers/media/dvb/dvb-usb/dw2102.c
32996+++ b/drivers/media/dvb/dvb-usb/dw2102.c
32997@@ -95,7 +95,7 @@ struct su3000_state {
32998
32999 struct s6x0_state {
33000 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33001-};
33002+} __no_const;
33003
33004 /* debug */
33005 static int dvb_usb_dw2102_debug;
33006diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33007index 404f63a..4796533 100644
33008--- a/drivers/media/dvb/frontends/dib3000.h
33009+++ b/drivers/media/dvb/frontends/dib3000.h
33010@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33011 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33012 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33013 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33014-};
33015+} __no_const;
33016
33017 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33018 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33019diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33020index 8418c02..8555013 100644
33021--- a/drivers/media/dvb/ngene/ngene-cards.c
33022+++ b/drivers/media/dvb/ngene/ngene-cards.c
33023@@ -477,7 +477,7 @@ static struct ngene_info ngene_info_m780 = {
33024
33025 /****************************************************************************/
33026
33027-static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33028+static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33029 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33030 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33031 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33032diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33033index 16a089f..ab1667d 100644
33034--- a/drivers/media/radio/radio-cadet.c
33035+++ b/drivers/media/radio/radio-cadet.c
33036@@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33037 unsigned char readbuf[RDS_BUFFER];
33038 int i = 0;
33039
33040+ if (count > RDS_BUFFER)
33041+ return -EFAULT;
33042 mutex_lock(&dev->lock);
33043 if (dev->rdsstat == 0) {
33044 dev->rdsstat = 1;
33045diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33046index 9cde353..8c6a1c3 100644
33047--- a/drivers/media/video/au0828/au0828.h
33048+++ b/drivers/media/video/au0828/au0828.h
33049@@ -191,7 +191,7 @@ struct au0828_dev {
33050
33051 /* I2C */
33052 struct i2c_adapter i2c_adap;
33053- struct i2c_algorithm i2c_algo;
33054+ i2c_algorithm_no_const i2c_algo;
33055 struct i2c_client i2c_client;
33056 u32 i2c_rc;
33057
33058diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33059index 04bf662..e0ac026 100644
33060--- a/drivers/media/video/cx88/cx88-alsa.c
33061+++ b/drivers/media/video/cx88/cx88-alsa.c
33062@@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33063 * Only boards with eeprom and byte 1 at eeprom=1 have it
33064 */
33065
33066-static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33067+static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33068 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33069 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33070 {0, }
33071diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33072index 1fb7d5b..3901e77 100644
33073--- a/drivers/media/video/omap/omap_vout.c
33074+++ b/drivers/media/video/omap/omap_vout.c
33075@@ -64,7 +64,6 @@ enum omap_vout_channels {
33076 OMAP_VIDEO2,
33077 };
33078
33079-static struct videobuf_queue_ops video_vbq_ops;
33080 /* Variables configurable through module params*/
33081 static u32 video1_numbuffers = 3;
33082 static u32 video2_numbuffers = 3;
33083@@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33084 {
33085 struct videobuf_queue *q;
33086 struct omap_vout_device *vout = NULL;
33087+ static struct videobuf_queue_ops video_vbq_ops = {
33088+ .buf_setup = omap_vout_buffer_setup,
33089+ .buf_prepare = omap_vout_buffer_prepare,
33090+ .buf_release = omap_vout_buffer_release,
33091+ .buf_queue = omap_vout_buffer_queue,
33092+ };
33093
33094 vout = video_drvdata(file);
33095 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33096@@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33097 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33098
33099 q = &vout->vbq;
33100- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33101- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33102- video_vbq_ops.buf_release = omap_vout_buffer_release;
33103- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33104 spin_lock_init(&vout->vbq_lock);
33105
33106 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33107diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33108index 305e6aa..0143317 100644
33109--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33110+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33111@@ -196,7 +196,7 @@ struct pvr2_hdw {
33112
33113 /* I2C stuff */
33114 struct i2c_adapter i2c_adap;
33115- struct i2c_algorithm i2c_algo;
33116+ i2c_algorithm_no_const i2c_algo;
33117 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33118 int i2c_cx25840_hack_state;
33119 int i2c_linked;
33120diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33121index 4ed1c7c2..8f15e13 100644
33122--- a/drivers/media/video/timblogiw.c
33123+++ b/drivers/media/video/timblogiw.c
33124@@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33125
33126 /* Platform device functions */
33127
33128-static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33129+static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33130 .vidioc_querycap = timblogiw_querycap,
33131 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33132 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33133@@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33134 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33135 };
33136
33137-static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33138+static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33139 .owner = THIS_MODULE,
33140 .open = timblogiw_open,
33141 .release = timblogiw_close,
33142diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33143index a7dc467..a55c423 100644
33144--- a/drivers/message/fusion/mptbase.c
33145+++ b/drivers/message/fusion/mptbase.c
33146@@ -6754,8 +6754,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33147 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33148 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33149
33150+#ifdef CONFIG_GRKERNSEC_HIDESYM
33151+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33152+#else
33153 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33154 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33155+#endif
33156+
33157 /*
33158 * Rounding UP to nearest 4-kB boundary here...
33159 */
33160diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33161index 551262e..7551198 100644
33162--- a/drivers/message/fusion/mptsas.c
33163+++ b/drivers/message/fusion/mptsas.c
33164@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33165 return 0;
33166 }
33167
33168+static inline void
33169+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33170+{
33171+ if (phy_info->port_details) {
33172+ phy_info->port_details->rphy = rphy;
33173+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33174+ ioc->name, rphy));
33175+ }
33176+
33177+ if (rphy) {
33178+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33179+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33180+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33181+ ioc->name, rphy, rphy->dev.release));
33182+ }
33183+}
33184+
33185 /* no mutex */
33186 static void
33187 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33188@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
33189 return NULL;
33190 }
33191
33192-static inline void
33193-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33194-{
33195- if (phy_info->port_details) {
33196- phy_info->port_details->rphy = rphy;
33197- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33198- ioc->name, rphy));
33199- }
33200-
33201- if (rphy) {
33202- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33203- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33204- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33205- ioc->name, rphy, rphy->dev.release));
33206- }
33207-}
33208-
33209 static inline struct sas_port *
33210 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33211 {
33212diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
33213index 0c3ced7..1fe34ec 100644
33214--- a/drivers/message/fusion/mptscsih.c
33215+++ b/drivers/message/fusion/mptscsih.c
33216@@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
33217
33218 h = shost_priv(SChost);
33219
33220- if (h) {
33221- if (h->info_kbuf == NULL)
33222- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33223- return h->info_kbuf;
33224- h->info_kbuf[0] = '\0';
33225+ if (!h)
33226+ return NULL;
33227
33228- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33229- h->info_kbuf[size-1] = '\0';
33230- }
33231+ if (h->info_kbuf == NULL)
33232+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33233+ return h->info_kbuf;
33234+ h->info_kbuf[0] = '\0';
33235+
33236+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33237+ h->info_kbuf[size-1] = '\0';
33238
33239 return h->info_kbuf;
33240 }
33241diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
33242index 6d115c7..58ff7fd 100644
33243--- a/drivers/message/i2o/i2o_proc.c
33244+++ b/drivers/message/i2o/i2o_proc.c
33245@@ -255,13 +255,6 @@ static char *scsi_devices[] = {
33246 "Array Controller Device"
33247 };
33248
33249-static char *chtostr(u8 * chars, int n)
33250-{
33251- char tmp[256];
33252- tmp[0] = 0;
33253- return strncat(tmp, (char *)chars, n);
33254-}
33255-
33256 static int i2o_report_query_status(struct seq_file *seq, int block_status,
33257 char *group)
33258 {
33259@@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
33260
33261 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
33262 seq_printf(seq, "%-#8x", ddm_table.module_id);
33263- seq_printf(seq, "%-29s",
33264- chtostr(ddm_table.module_name_version, 28));
33265+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
33266 seq_printf(seq, "%9d ", ddm_table.data_size);
33267 seq_printf(seq, "%8d", ddm_table.code_size);
33268
33269@@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
33270
33271 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
33272 seq_printf(seq, "%-#8x", dst->module_id);
33273- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
33274- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
33275+ seq_printf(seq, "%-.28s", dst->module_name_version);
33276+ seq_printf(seq, "%-.8s", dst->date);
33277 seq_printf(seq, "%8d ", dst->module_size);
33278 seq_printf(seq, "%8d ", dst->mpb_size);
33279 seq_printf(seq, "0x%04x", dst->module_flags);
33280@@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
33281 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
33282 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
33283 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
33284- seq_printf(seq, "Vendor info : %s\n",
33285- chtostr((u8 *) (work32 + 2), 16));
33286- seq_printf(seq, "Product info : %s\n",
33287- chtostr((u8 *) (work32 + 6), 16));
33288- seq_printf(seq, "Description : %s\n",
33289- chtostr((u8 *) (work32 + 10), 16));
33290- seq_printf(seq, "Product rev. : %s\n",
33291- chtostr((u8 *) (work32 + 14), 8));
33292+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
33293+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
33294+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
33295+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
33296
33297 seq_printf(seq, "Serial number : ");
33298 print_serial_number(seq, (u8 *) (work32 + 16),
33299@@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
33300 }
33301
33302 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
33303- seq_printf(seq, "Module name : %s\n",
33304- chtostr(result.module_name, 24));
33305- seq_printf(seq, "Module revision : %s\n",
33306- chtostr(result.module_rev, 8));
33307+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
33308+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
33309
33310 seq_printf(seq, "Serial number : ");
33311 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
33312@@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
33313 return 0;
33314 }
33315
33316- seq_printf(seq, "Device name : %s\n",
33317- chtostr(result.device_name, 64));
33318- seq_printf(seq, "Service name : %s\n",
33319- chtostr(result.service_name, 64));
33320- seq_printf(seq, "Physical name : %s\n",
33321- chtostr(result.physical_location, 64));
33322- seq_printf(seq, "Instance number : %s\n",
33323- chtostr(result.instance_number, 4));
33324+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
33325+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
33326+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
33327+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
33328
33329 return 0;
33330 }
33331diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
33332index a8c08f3..155fe3d 100644
33333--- a/drivers/message/i2o/iop.c
33334+++ b/drivers/message/i2o/iop.c
33335@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
33336
33337 spin_lock_irqsave(&c->context_list_lock, flags);
33338
33339- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
33340- atomic_inc(&c->context_list_counter);
33341+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
33342+ atomic_inc_unchecked(&c->context_list_counter);
33343
33344- entry->context = atomic_read(&c->context_list_counter);
33345+ entry->context = atomic_read_unchecked(&c->context_list_counter);
33346
33347 list_add(&entry->list, &c->context_list);
33348
33349@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
33350
33351 #if BITS_PER_LONG == 64
33352 spin_lock_init(&c->context_list_lock);
33353- atomic_set(&c->context_list_counter, 0);
33354+ atomic_set_unchecked(&c->context_list_counter, 0);
33355 INIT_LIST_HEAD(&c->context_list);
33356 #endif
33357
33358diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
33359index 7ce65f4..e66e9bc 100644
33360--- a/drivers/mfd/abx500-core.c
33361+++ b/drivers/mfd/abx500-core.c
33362@@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
33363
33364 struct abx500_device_entry {
33365 struct list_head list;
33366- struct abx500_ops ops;
33367+ abx500_ops_no_const ops;
33368 struct device *dev;
33369 };
33370
33371diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
33372index a9223ed..4127b13 100644
33373--- a/drivers/mfd/janz-cmodio.c
33374+++ b/drivers/mfd/janz-cmodio.c
33375@@ -13,6 +13,7 @@
33376
33377 #include <linux/kernel.h>
33378 #include <linux/module.h>
33379+#include <linux/slab.h>
33380 #include <linux/init.h>
33381 #include <linux/pci.h>
33382 #include <linux/interrupt.h>
33383diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
33384index a981e2a..5ca0c8b 100644
33385--- a/drivers/misc/lis3lv02d/lis3lv02d.c
33386+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
33387@@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
33388 * the lid is closed. This leads to interrupts as soon as a little move
33389 * is done.
33390 */
33391- atomic_inc(&lis3->count);
33392+ atomic_inc_unchecked(&lis3->count);
33393
33394 wake_up_interruptible(&lis3->misc_wait);
33395 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
33396@@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
33397 if (lis3->pm_dev)
33398 pm_runtime_get_sync(lis3->pm_dev);
33399
33400- atomic_set(&lis3->count, 0);
33401+ atomic_set_unchecked(&lis3->count, 0);
33402 return 0;
33403 }
33404
33405@@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
33406 add_wait_queue(&lis3->misc_wait, &wait);
33407 while (true) {
33408 set_current_state(TASK_INTERRUPTIBLE);
33409- data = atomic_xchg(&lis3->count, 0);
33410+ data = atomic_xchg_unchecked(&lis3->count, 0);
33411 if (data)
33412 break;
33413
33414@@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
33415 struct lis3lv02d, miscdev);
33416
33417 poll_wait(file, &lis3->misc_wait, wait);
33418- if (atomic_read(&lis3->count))
33419+ if (atomic_read_unchecked(&lis3->count))
33420 return POLLIN | POLLRDNORM;
33421 return 0;
33422 }
33423diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
33424index 2b1482a..5d33616 100644
33425--- a/drivers/misc/lis3lv02d/lis3lv02d.h
33426+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
33427@@ -266,7 +266,7 @@ struct lis3lv02d {
33428 struct input_polled_dev *idev; /* input device */
33429 struct platform_device *pdev; /* platform device */
33430 struct regulator_bulk_data regulators[2];
33431- atomic_t count; /* interrupt count after last read */
33432+ atomic_unchecked_t count; /* interrupt count after last read */
33433 union axis_conversion ac; /* hw -> logical axis */
33434 int mapped_btns[3];
33435
33436diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
33437index 2f30bad..c4c13d0 100644
33438--- a/drivers/misc/sgi-gru/gruhandles.c
33439+++ b/drivers/misc/sgi-gru/gruhandles.c
33440@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
33441 unsigned long nsec;
33442
33443 nsec = CLKS2NSEC(clks);
33444- atomic_long_inc(&mcs_op_statistics[op].count);
33445- atomic_long_add(nsec, &mcs_op_statistics[op].total);
33446+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
33447+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
33448 if (mcs_op_statistics[op].max < nsec)
33449 mcs_op_statistics[op].max = nsec;
33450 }
33451diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
33452index 950dbe9..eeef0f8 100644
33453--- a/drivers/misc/sgi-gru/gruprocfs.c
33454+++ b/drivers/misc/sgi-gru/gruprocfs.c
33455@@ -32,9 +32,9 @@
33456
33457 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
33458
33459-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
33460+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
33461 {
33462- unsigned long val = atomic_long_read(v);
33463+ unsigned long val = atomic_long_read_unchecked(v);
33464
33465 seq_printf(s, "%16lu %s\n", val, id);
33466 }
33467@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
33468
33469 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
33470 for (op = 0; op < mcsop_last; op++) {
33471- count = atomic_long_read(&mcs_op_statistics[op].count);
33472- total = atomic_long_read(&mcs_op_statistics[op].total);
33473+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
33474+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
33475 max = mcs_op_statistics[op].max;
33476 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
33477 count ? total / count : 0, max);
33478diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
33479index 5c3ce24..4915ccb 100644
33480--- a/drivers/misc/sgi-gru/grutables.h
33481+++ b/drivers/misc/sgi-gru/grutables.h
33482@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
33483 * GRU statistics.
33484 */
33485 struct gru_stats_s {
33486- atomic_long_t vdata_alloc;
33487- atomic_long_t vdata_free;
33488- atomic_long_t gts_alloc;
33489- atomic_long_t gts_free;
33490- atomic_long_t gms_alloc;
33491- atomic_long_t gms_free;
33492- atomic_long_t gts_double_allocate;
33493- atomic_long_t assign_context;
33494- atomic_long_t assign_context_failed;
33495- atomic_long_t free_context;
33496- atomic_long_t load_user_context;
33497- atomic_long_t load_kernel_context;
33498- atomic_long_t lock_kernel_context;
33499- atomic_long_t unlock_kernel_context;
33500- atomic_long_t steal_user_context;
33501- atomic_long_t steal_kernel_context;
33502- atomic_long_t steal_context_failed;
33503- atomic_long_t nopfn;
33504- atomic_long_t asid_new;
33505- atomic_long_t asid_next;
33506- atomic_long_t asid_wrap;
33507- atomic_long_t asid_reuse;
33508- atomic_long_t intr;
33509- atomic_long_t intr_cbr;
33510- atomic_long_t intr_tfh;
33511- atomic_long_t intr_spurious;
33512- atomic_long_t intr_mm_lock_failed;
33513- atomic_long_t call_os;
33514- atomic_long_t call_os_wait_queue;
33515- atomic_long_t user_flush_tlb;
33516- atomic_long_t user_unload_context;
33517- atomic_long_t user_exception;
33518- atomic_long_t set_context_option;
33519- atomic_long_t check_context_retarget_intr;
33520- atomic_long_t check_context_unload;
33521- atomic_long_t tlb_dropin;
33522- atomic_long_t tlb_preload_page;
33523- atomic_long_t tlb_dropin_fail_no_asid;
33524- atomic_long_t tlb_dropin_fail_upm;
33525- atomic_long_t tlb_dropin_fail_invalid;
33526- atomic_long_t tlb_dropin_fail_range_active;
33527- atomic_long_t tlb_dropin_fail_idle;
33528- atomic_long_t tlb_dropin_fail_fmm;
33529- atomic_long_t tlb_dropin_fail_no_exception;
33530- atomic_long_t tfh_stale_on_fault;
33531- atomic_long_t mmu_invalidate_range;
33532- atomic_long_t mmu_invalidate_page;
33533- atomic_long_t flush_tlb;
33534- atomic_long_t flush_tlb_gru;
33535- atomic_long_t flush_tlb_gru_tgh;
33536- atomic_long_t flush_tlb_gru_zero_asid;
33537+ atomic_long_unchecked_t vdata_alloc;
33538+ atomic_long_unchecked_t vdata_free;
33539+ atomic_long_unchecked_t gts_alloc;
33540+ atomic_long_unchecked_t gts_free;
33541+ atomic_long_unchecked_t gms_alloc;
33542+ atomic_long_unchecked_t gms_free;
33543+ atomic_long_unchecked_t gts_double_allocate;
33544+ atomic_long_unchecked_t assign_context;
33545+ atomic_long_unchecked_t assign_context_failed;
33546+ atomic_long_unchecked_t free_context;
33547+ atomic_long_unchecked_t load_user_context;
33548+ atomic_long_unchecked_t load_kernel_context;
33549+ atomic_long_unchecked_t lock_kernel_context;
33550+ atomic_long_unchecked_t unlock_kernel_context;
33551+ atomic_long_unchecked_t steal_user_context;
33552+ atomic_long_unchecked_t steal_kernel_context;
33553+ atomic_long_unchecked_t steal_context_failed;
33554+ atomic_long_unchecked_t nopfn;
33555+ atomic_long_unchecked_t asid_new;
33556+ atomic_long_unchecked_t asid_next;
33557+ atomic_long_unchecked_t asid_wrap;
33558+ atomic_long_unchecked_t asid_reuse;
33559+ atomic_long_unchecked_t intr;
33560+ atomic_long_unchecked_t intr_cbr;
33561+ atomic_long_unchecked_t intr_tfh;
33562+ atomic_long_unchecked_t intr_spurious;
33563+ atomic_long_unchecked_t intr_mm_lock_failed;
33564+ atomic_long_unchecked_t call_os;
33565+ atomic_long_unchecked_t call_os_wait_queue;
33566+ atomic_long_unchecked_t user_flush_tlb;
33567+ atomic_long_unchecked_t user_unload_context;
33568+ atomic_long_unchecked_t user_exception;
33569+ atomic_long_unchecked_t set_context_option;
33570+ atomic_long_unchecked_t check_context_retarget_intr;
33571+ atomic_long_unchecked_t check_context_unload;
33572+ atomic_long_unchecked_t tlb_dropin;
33573+ atomic_long_unchecked_t tlb_preload_page;
33574+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
33575+ atomic_long_unchecked_t tlb_dropin_fail_upm;
33576+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
33577+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
33578+ atomic_long_unchecked_t tlb_dropin_fail_idle;
33579+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
33580+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
33581+ atomic_long_unchecked_t tfh_stale_on_fault;
33582+ atomic_long_unchecked_t mmu_invalidate_range;
33583+ atomic_long_unchecked_t mmu_invalidate_page;
33584+ atomic_long_unchecked_t flush_tlb;
33585+ atomic_long_unchecked_t flush_tlb_gru;
33586+ atomic_long_unchecked_t flush_tlb_gru_tgh;
33587+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
33588
33589- atomic_long_t copy_gpa;
33590- atomic_long_t read_gpa;
33591+ atomic_long_unchecked_t copy_gpa;
33592+ atomic_long_unchecked_t read_gpa;
33593
33594- atomic_long_t mesq_receive;
33595- atomic_long_t mesq_receive_none;
33596- atomic_long_t mesq_send;
33597- atomic_long_t mesq_send_failed;
33598- atomic_long_t mesq_noop;
33599- atomic_long_t mesq_send_unexpected_error;
33600- atomic_long_t mesq_send_lb_overflow;
33601- atomic_long_t mesq_send_qlimit_reached;
33602- atomic_long_t mesq_send_amo_nacked;
33603- atomic_long_t mesq_send_put_nacked;
33604- atomic_long_t mesq_page_overflow;
33605- atomic_long_t mesq_qf_locked;
33606- atomic_long_t mesq_qf_noop_not_full;
33607- atomic_long_t mesq_qf_switch_head_failed;
33608- atomic_long_t mesq_qf_unexpected_error;
33609- atomic_long_t mesq_noop_unexpected_error;
33610- atomic_long_t mesq_noop_lb_overflow;
33611- atomic_long_t mesq_noop_qlimit_reached;
33612- atomic_long_t mesq_noop_amo_nacked;
33613- atomic_long_t mesq_noop_put_nacked;
33614- atomic_long_t mesq_noop_page_overflow;
33615+ atomic_long_unchecked_t mesq_receive;
33616+ atomic_long_unchecked_t mesq_receive_none;
33617+ atomic_long_unchecked_t mesq_send;
33618+ atomic_long_unchecked_t mesq_send_failed;
33619+ atomic_long_unchecked_t mesq_noop;
33620+ atomic_long_unchecked_t mesq_send_unexpected_error;
33621+ atomic_long_unchecked_t mesq_send_lb_overflow;
33622+ atomic_long_unchecked_t mesq_send_qlimit_reached;
33623+ atomic_long_unchecked_t mesq_send_amo_nacked;
33624+ atomic_long_unchecked_t mesq_send_put_nacked;
33625+ atomic_long_unchecked_t mesq_page_overflow;
33626+ atomic_long_unchecked_t mesq_qf_locked;
33627+ atomic_long_unchecked_t mesq_qf_noop_not_full;
33628+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
33629+ atomic_long_unchecked_t mesq_qf_unexpected_error;
33630+ atomic_long_unchecked_t mesq_noop_unexpected_error;
33631+ atomic_long_unchecked_t mesq_noop_lb_overflow;
33632+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
33633+ atomic_long_unchecked_t mesq_noop_amo_nacked;
33634+ atomic_long_unchecked_t mesq_noop_put_nacked;
33635+ atomic_long_unchecked_t mesq_noop_page_overflow;
33636
33637 };
33638
33639@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
33640 tghop_invalidate, mcsop_last};
33641
33642 struct mcs_op_statistic {
33643- atomic_long_t count;
33644- atomic_long_t total;
33645+ atomic_long_unchecked_t count;
33646+ atomic_long_unchecked_t total;
33647 unsigned long max;
33648 };
33649
33650@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
33651
33652 #define STAT(id) do { \
33653 if (gru_options & OPT_STATS) \
33654- atomic_long_inc(&gru_stats.id); \
33655+ atomic_long_inc_unchecked(&gru_stats.id); \
33656 } while (0)
33657
33658 #ifdef CONFIG_SGI_GRU_DEBUG
33659diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
33660index 851b2f2..a4ec097 100644
33661--- a/drivers/misc/sgi-xp/xp.h
33662+++ b/drivers/misc/sgi-xp/xp.h
33663@@ -289,7 +289,7 @@ struct xpc_interface {
33664 xpc_notify_func, void *);
33665 void (*received) (short, int, void *);
33666 enum xp_retval (*partid_to_nasids) (short, void *);
33667-};
33668+} __no_const;
33669
33670 extern struct xpc_interface xpc_interface;
33671
33672diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
33673index b94d5f7..7f494c5 100644
33674--- a/drivers/misc/sgi-xp/xpc.h
33675+++ b/drivers/misc/sgi-xp/xpc.h
33676@@ -835,6 +835,7 @@ struct xpc_arch_operations {
33677 void (*received_payload) (struct xpc_channel *, void *);
33678 void (*notify_senders_of_disconnect) (struct xpc_channel *);
33679 };
33680+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
33681
33682 /* struct xpc_partition act_state values (for XPC HB) */
33683
33684@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
33685 /* found in xpc_main.c */
33686 extern struct device *xpc_part;
33687 extern struct device *xpc_chan;
33688-extern struct xpc_arch_operations xpc_arch_ops;
33689+extern xpc_arch_operations_no_const xpc_arch_ops;
33690 extern int xpc_disengage_timelimit;
33691 extern int xpc_disengage_timedout;
33692 extern int xpc_activate_IRQ_rcvd;
33693diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
33694index 8d082b4..aa749ae 100644
33695--- a/drivers/misc/sgi-xp/xpc_main.c
33696+++ b/drivers/misc/sgi-xp/xpc_main.c
33697@@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
33698 .notifier_call = xpc_system_die,
33699 };
33700
33701-struct xpc_arch_operations xpc_arch_ops;
33702+xpc_arch_operations_no_const xpc_arch_ops;
33703
33704 /*
33705 * Timer function to enforce the timelimit on the partition disengage.
33706diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
33707index 6ebdc40..9edf5d8 100644
33708--- a/drivers/mmc/host/sdhci-pci.c
33709+++ b/drivers/mmc/host/sdhci-pci.c
33710@@ -631,7 +631,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
33711 .probe = via_probe,
33712 };
33713
33714-static const struct pci_device_id pci_ids[] __devinitdata = {
33715+static const struct pci_device_id pci_ids[] __devinitconst = {
33716 {
33717 .vendor = PCI_VENDOR_ID_RICOH,
33718 .device = PCI_DEVICE_ID_RICOH_R5C822,
33719diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
33720index b1cdf64..ce6e438 100644
33721--- a/drivers/mtd/devices/doc2000.c
33722+++ b/drivers/mtd/devices/doc2000.c
33723@@ -764,7 +764,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
33724
33725 /* The ECC will not be calculated correctly if less than 512 is written */
33726 /* DBB-
33727- if (len != 0x200 && eccbuf)
33728+ if (len != 0x200)
33729 printk(KERN_WARNING
33730 "ECC needs a full sector write (adr: %lx size %lx)\n",
33731 (long) to, (long) len);
33732diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
33733index 7543b98..7069947 100644
33734--- a/drivers/mtd/devices/doc2001.c
33735+++ b/drivers/mtd/devices/doc2001.c
33736@@ -384,7 +384,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
33737 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
33738
33739 /* Don't allow read past end of device */
33740- if (from >= this->totlen)
33741+ if (from >= this->totlen || !len)
33742 return -EINVAL;
33743
33744 /* Don't allow a single read to cross a 512-byte block boundary */
33745diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
33746index 3984d48..28aa897 100644
33747--- a/drivers/mtd/nand/denali.c
33748+++ b/drivers/mtd/nand/denali.c
33749@@ -26,6 +26,7 @@
33750 #include <linux/pci.h>
33751 #include <linux/mtd/mtd.h>
33752 #include <linux/module.h>
33753+#include <linux/slab.h>
33754
33755 #include "denali.h"
33756
33757diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
33758index 51b9d6a..52af9a7 100644
33759--- a/drivers/mtd/nftlmount.c
33760+++ b/drivers/mtd/nftlmount.c
33761@@ -24,6 +24,7 @@
33762 #include <asm/errno.h>
33763 #include <linux/delay.h>
33764 #include <linux/slab.h>
33765+#include <linux/sched.h>
33766 #include <linux/mtd/mtd.h>
33767 #include <linux/mtd/nand.h>
33768 #include <linux/mtd/nftl.h>
33769diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
33770index 115749f..3021f01 100644
33771--- a/drivers/mtd/ubi/build.c
33772+++ b/drivers/mtd/ubi/build.c
33773@@ -1311,7 +1311,7 @@ module_exit(ubi_exit);
33774 static int __init bytes_str_to_int(const char *str)
33775 {
33776 char *endp;
33777- unsigned long result;
33778+ unsigned long result, scale = 1;
33779
33780 result = simple_strtoul(str, &endp, 0);
33781 if (str == endp || result >= INT_MAX) {
33782@@ -1322,11 +1322,11 @@ static int __init bytes_str_to_int(const char *str)
33783
33784 switch (*endp) {
33785 case 'G':
33786- result *= 1024;
33787+ scale *= 1024;
33788 case 'M':
33789- result *= 1024;
33790+ scale *= 1024;
33791 case 'K':
33792- result *= 1024;
33793+ scale *= 1024;
33794 if (endp[1] == 'i' && endp[2] == 'B')
33795 endp += 2;
33796 case '\0':
33797@@ -1337,7 +1337,13 @@ static int __init bytes_str_to_int(const char *str)
33798 return -EINVAL;
33799 }
33800
33801- return result;
33802+ if ((intoverflow_t)result*scale >= INT_MAX) {
33803+ printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
33804+ str);
33805+ return -EINVAL;
33806+ }
33807+
33808+ return result*scale;
33809 }
33810
33811 /**
33812diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
33813index 071f4c8..440862e 100644
33814--- a/drivers/net/ethernet/atheros/atlx/atl2.c
33815+++ b/drivers/net/ethernet/atheros/atlx/atl2.c
33816@@ -2862,7 +2862,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
33817 */
33818
33819 #define ATL2_PARAM(X, desc) \
33820- static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
33821+ static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
33822 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
33823 MODULE_PARM_DESC(X, desc);
33824 #else
33825diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
33826index 66da39f..5dc436d 100644
33827--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
33828+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
33829@@ -473,7 +473,7 @@ struct bnx2x_rx_mode_obj {
33830
33831 int (*wait_comp)(struct bnx2x *bp,
33832 struct bnx2x_rx_mode_ramrod_params *p);
33833-};
33834+} __no_const;
33835
33836 /********************** Set multicast group ***********************************/
33837
33838diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
33839index aea8f72..fcebf75 100644
33840--- a/drivers/net/ethernet/broadcom/tg3.h
33841+++ b/drivers/net/ethernet/broadcom/tg3.h
33842@@ -140,6 +140,7 @@
33843 #define CHIPREV_ID_5750_A0 0x4000
33844 #define CHIPREV_ID_5750_A1 0x4001
33845 #define CHIPREV_ID_5750_A3 0x4003
33846+#define CHIPREV_ID_5750_C1 0x4201
33847 #define CHIPREV_ID_5750_C2 0x4202
33848 #define CHIPREV_ID_5752_A0_HW 0x5000
33849 #define CHIPREV_ID_5752_A0 0x6000
33850diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
33851index c4e8643..0979484 100644
33852--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
33853+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
33854@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
33855 */
33856 struct l2t_skb_cb {
33857 arp_failure_handler_func arp_failure_handler;
33858-};
33859+} __no_const;
33860
33861 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
33862
33863diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
33864index 4d71f5a..8004440 100644
33865--- a/drivers/net/ethernet/dec/tulip/de4x5.c
33866+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
33867@@ -5392,7 +5392,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
33868 for (i=0; i<ETH_ALEN; i++) {
33869 tmp.addr[i] = dev->dev_addr[i];
33870 }
33871- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
33872+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
33873 break;
33874
33875 case DE4X5_SET_HWADDR: /* Set the hardware address */
33876@@ -5432,7 +5432,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
33877 spin_lock_irqsave(&lp->lock, flags);
33878 memcpy(&statbuf, &lp->pktStats, ioc->len);
33879 spin_unlock_irqrestore(&lp->lock, flags);
33880- if (copy_to_user(ioc->data, &statbuf, ioc->len))
33881+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
33882 return -EFAULT;
33883 break;
33884 }
33885diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
33886index 14d5b61..1398636 100644
33887--- a/drivers/net/ethernet/dec/tulip/eeprom.c
33888+++ b/drivers/net/ethernet/dec/tulip/eeprom.c
33889@@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
33890 {NULL}};
33891
33892
33893-static const char *block_name[] __devinitdata = {
33894+static const char *block_name[] __devinitconst = {
33895 "21140 non-MII",
33896 "21140 MII PHY",
33897 "21142 Serial PHY",
33898diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
33899index 52da7b2..4ddfe1c 100644
33900--- a/drivers/net/ethernet/dec/tulip/winbond-840.c
33901+++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
33902@@ -236,7 +236,7 @@ struct pci_id_info {
33903 int drv_flags; /* Driver use, intended as capability flags. */
33904 };
33905
33906-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
33907+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
33908 { /* Sometime a Level-One switch card. */
33909 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
33910 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
33911diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
33912index 28a3a9b..d96cb63 100644
33913--- a/drivers/net/ethernet/dlink/sundance.c
33914+++ b/drivers/net/ethernet/dlink/sundance.c
33915@@ -218,7 +218,7 @@ enum {
33916 struct pci_id_info {
33917 const char *name;
33918 };
33919-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
33920+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
33921 {"D-Link DFE-550TX FAST Ethernet Adapter"},
33922 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
33923 {"D-Link DFE-580TX 4 port Server Adapter"},
33924diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
33925index e703d64..d62ecf9 100644
33926--- a/drivers/net/ethernet/emulex/benet/be_main.c
33927+++ b/drivers/net/ethernet/emulex/benet/be_main.c
33928@@ -402,7 +402,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
33929
33930 if (wrapped)
33931 newacc += 65536;
33932- ACCESS_ONCE(*acc) = newacc;
33933+ ACCESS_ONCE_RW(*acc) = newacc;
33934 }
33935
33936 void be_parse_stats(struct be_adapter *adapter)
33937diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
33938index 47f85c3..82ab6c4 100644
33939--- a/drivers/net/ethernet/faraday/ftgmac100.c
33940+++ b/drivers/net/ethernet/faraday/ftgmac100.c
33941@@ -31,6 +31,8 @@
33942 #include <linux/netdevice.h>
33943 #include <linux/phy.h>
33944 #include <linux/platform_device.h>
33945+#include <linux/interrupt.h>
33946+#include <linux/irqreturn.h>
33947 #include <net/ip.h>
33948
33949 #include "ftgmac100.h"
33950diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
33951index bb336a0..4b472da 100644
33952--- a/drivers/net/ethernet/faraday/ftmac100.c
33953+++ b/drivers/net/ethernet/faraday/ftmac100.c
33954@@ -31,6 +31,8 @@
33955 #include <linux/module.h>
33956 #include <linux/netdevice.h>
33957 #include <linux/platform_device.h>
33958+#include <linux/interrupt.h>
33959+#include <linux/irqreturn.h>
33960
33961 #include "ftmac100.h"
33962
33963diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
33964index c82d444..0007fb4 100644
33965--- a/drivers/net/ethernet/fealnx.c
33966+++ b/drivers/net/ethernet/fealnx.c
33967@@ -150,7 +150,7 @@ struct chip_info {
33968 int flags;
33969 };
33970
33971-static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
33972+static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
33973 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
33974 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
33975 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
33976diff --git a/drivers/net/ethernet/intel/e1000e/80003es2lan.c b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
33977index e1159e5..e18684d 100644
33978--- a/drivers/net/ethernet/intel/e1000e/80003es2lan.c
33979+++ b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
33980@@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
33981 {
33982 struct e1000_hw *hw = &adapter->hw;
33983 struct e1000_mac_info *mac = &hw->mac;
33984- struct e1000_mac_operations *func = &mac->ops;
33985+ e1000_mac_operations_no_const *func = &mac->ops;
33986
33987 /* Set media type */
33988 switch (adapter->pdev->device) {
33989diff --git a/drivers/net/ethernet/intel/e1000e/82571.c b/drivers/net/ethernet/intel/e1000e/82571.c
33990index a3e65fd..f451444 100644
33991--- a/drivers/net/ethernet/intel/e1000e/82571.c
33992+++ b/drivers/net/ethernet/intel/e1000e/82571.c
33993@@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
33994 {
33995 struct e1000_hw *hw = &adapter->hw;
33996 struct e1000_mac_info *mac = &hw->mac;
33997- struct e1000_mac_operations *func = &mac->ops;
33998+ e1000_mac_operations_no_const *func = &mac->ops;
33999 u32 swsm = 0;
34000 u32 swsm2 = 0;
34001 bool force_clear_smbi = false;
34002diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34003index 2967039..ca8c40c 100644
34004--- a/drivers/net/ethernet/intel/e1000e/hw.h
34005+++ b/drivers/net/ethernet/intel/e1000e/hw.h
34006@@ -778,6 +778,7 @@ struct e1000_mac_operations {
34007 void (*write_vfta)(struct e1000_hw *, u32, u32);
34008 s32 (*read_mac_addr)(struct e1000_hw *);
34009 };
34010+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34011
34012 /*
34013 * When to use various PHY register access functions:
34014@@ -818,6 +819,7 @@ struct e1000_phy_operations {
34015 void (*power_up)(struct e1000_hw *);
34016 void (*power_down)(struct e1000_hw *);
34017 };
34018+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34019
34020 /* Function pointers for the NVM. */
34021 struct e1000_nvm_operations {
34022@@ -829,9 +831,10 @@ struct e1000_nvm_operations {
34023 s32 (*validate)(struct e1000_hw *);
34024 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34025 };
34026+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34027
34028 struct e1000_mac_info {
34029- struct e1000_mac_operations ops;
34030+ e1000_mac_operations_no_const ops;
34031 u8 addr[ETH_ALEN];
34032 u8 perm_addr[ETH_ALEN];
34033
34034@@ -872,7 +875,7 @@ struct e1000_mac_info {
34035 };
34036
34037 struct e1000_phy_info {
34038- struct e1000_phy_operations ops;
34039+ e1000_phy_operations_no_const ops;
34040
34041 enum e1000_phy_type type;
34042
34043@@ -906,7 +909,7 @@ struct e1000_phy_info {
34044 };
34045
34046 struct e1000_nvm_info {
34047- struct e1000_nvm_operations ops;
34048+ e1000_nvm_operations_no_const ops;
34049
34050 enum e1000_nvm_type type;
34051 enum e1000_nvm_override override;
34052diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34053index f67cbd3..cef9e3d 100644
34054--- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34055+++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34056@@ -314,6 +314,7 @@ struct e1000_mac_operations {
34057 s32 (*read_mac_addr)(struct e1000_hw *);
34058 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
34059 };
34060+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34061
34062 struct e1000_phy_operations {
34063 s32 (*acquire)(struct e1000_hw *);
34064@@ -330,6 +331,7 @@ struct e1000_phy_operations {
34065 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34066 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34067 };
34068+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34069
34070 struct e1000_nvm_operations {
34071 s32 (*acquire)(struct e1000_hw *);
34072@@ -339,6 +341,7 @@ struct e1000_nvm_operations {
34073 s32 (*update)(struct e1000_hw *);
34074 s32 (*validate)(struct e1000_hw *);
34075 };
34076+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34077
34078 struct e1000_info {
34079 s32 (*get_invariants)(struct e1000_hw *);
34080@@ -350,7 +353,7 @@ struct e1000_info {
34081 extern const struct e1000_info e1000_82575_info;
34082
34083 struct e1000_mac_info {
34084- struct e1000_mac_operations ops;
34085+ e1000_mac_operations_no_const ops;
34086
34087 u8 addr[6];
34088 u8 perm_addr[6];
34089@@ -388,7 +391,7 @@ struct e1000_mac_info {
34090 };
34091
34092 struct e1000_phy_info {
34093- struct e1000_phy_operations ops;
34094+ e1000_phy_operations_no_const ops;
34095
34096 enum e1000_phy_type type;
34097
34098@@ -423,7 +426,7 @@ struct e1000_phy_info {
34099 };
34100
34101 struct e1000_nvm_info {
34102- struct e1000_nvm_operations ops;
34103+ e1000_nvm_operations_no_const ops;
34104 enum e1000_nvm_type type;
34105 enum e1000_nvm_override override;
34106
34107@@ -468,6 +471,7 @@ struct e1000_mbx_operations {
34108 s32 (*check_for_ack)(struct e1000_hw *, u16);
34109 s32 (*check_for_rst)(struct e1000_hw *, u16);
34110 };
34111+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34112
34113 struct e1000_mbx_stats {
34114 u32 msgs_tx;
34115@@ -479,7 +483,7 @@ struct e1000_mbx_stats {
34116 };
34117
34118 struct e1000_mbx_info {
34119- struct e1000_mbx_operations ops;
34120+ e1000_mbx_operations_no_const ops;
34121 struct e1000_mbx_stats stats;
34122 u32 timeout;
34123 u32 usec_delay;
34124diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34125index 57db3c6..aa825fc 100644
34126--- a/drivers/net/ethernet/intel/igbvf/vf.h
34127+++ b/drivers/net/ethernet/intel/igbvf/vf.h
34128@@ -189,9 +189,10 @@ struct e1000_mac_operations {
34129 s32 (*read_mac_addr)(struct e1000_hw *);
34130 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34131 };
34132+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34133
34134 struct e1000_mac_info {
34135- struct e1000_mac_operations ops;
34136+ e1000_mac_operations_no_const ops;
34137 u8 addr[6];
34138 u8 perm_addr[6];
34139
34140@@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34141 s32 (*check_for_ack)(struct e1000_hw *);
34142 s32 (*check_for_rst)(struct e1000_hw *);
34143 };
34144+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34145
34146 struct e1000_mbx_stats {
34147 u32 msgs_tx;
34148@@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34149 };
34150
34151 struct e1000_mbx_info {
34152- struct e1000_mbx_operations ops;
34153+ e1000_mbx_operations_no_const ops;
34154 struct e1000_mbx_stats stats;
34155 u32 timeout;
34156 u32 usec_delay;
34157diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34158index 9b95bef..7e254ee 100644
34159--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34160+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34161@@ -2708,6 +2708,7 @@ struct ixgbe_eeprom_operations {
34162 s32 (*update_checksum)(struct ixgbe_hw *);
34163 u16 (*calc_checksum)(struct ixgbe_hw *);
34164 };
34165+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
34166
34167 struct ixgbe_mac_operations {
34168 s32 (*init_hw)(struct ixgbe_hw *);
34169@@ -2769,6 +2770,7 @@ struct ixgbe_mac_operations {
34170 /* Manageability interface */
34171 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
34172 };
34173+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34174
34175 struct ixgbe_phy_operations {
34176 s32 (*identify)(struct ixgbe_hw *);
34177@@ -2788,9 +2790,10 @@ struct ixgbe_phy_operations {
34178 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34179 s32 (*check_overtemp)(struct ixgbe_hw *);
34180 };
34181+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34182
34183 struct ixgbe_eeprom_info {
34184- struct ixgbe_eeprom_operations ops;
34185+ ixgbe_eeprom_operations_no_const ops;
34186 enum ixgbe_eeprom_type type;
34187 u32 semaphore_delay;
34188 u16 word_size;
34189@@ -2800,7 +2803,7 @@ struct ixgbe_eeprom_info {
34190
34191 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34192 struct ixgbe_mac_info {
34193- struct ixgbe_mac_operations ops;
34194+ ixgbe_mac_operations_no_const ops;
34195 enum ixgbe_mac_type type;
34196 u8 addr[ETH_ALEN];
34197 u8 perm_addr[ETH_ALEN];
34198@@ -2828,7 +2831,7 @@ struct ixgbe_mac_info {
34199 };
34200
34201 struct ixgbe_phy_info {
34202- struct ixgbe_phy_operations ops;
34203+ ixgbe_phy_operations_no_const ops;
34204 struct mdio_if_info mdio;
34205 enum ixgbe_phy_type type;
34206 u32 id;
34207@@ -2856,6 +2859,7 @@ struct ixgbe_mbx_operations {
34208 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
34209 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
34210 };
34211+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34212
34213 struct ixgbe_mbx_stats {
34214 u32 msgs_tx;
34215@@ -2867,7 +2871,7 @@ struct ixgbe_mbx_stats {
34216 };
34217
34218 struct ixgbe_mbx_info {
34219- struct ixgbe_mbx_operations ops;
34220+ ixgbe_mbx_operations_no_const ops;
34221 struct ixgbe_mbx_stats stats;
34222 u32 timeout;
34223 u32 usec_delay;
34224diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
34225index 25c951d..cc7cf33 100644
34226--- a/drivers/net/ethernet/intel/ixgbevf/vf.h
34227+++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
34228@@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
34229 s32 (*clear_vfta)(struct ixgbe_hw *);
34230 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
34231 };
34232+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34233
34234 enum ixgbe_mac_type {
34235 ixgbe_mac_unknown = 0,
34236@@ -79,7 +80,7 @@ enum ixgbe_mac_type {
34237 };
34238
34239 struct ixgbe_mac_info {
34240- struct ixgbe_mac_operations ops;
34241+ ixgbe_mac_operations_no_const ops;
34242 u8 addr[6];
34243 u8 perm_addr[6];
34244
34245@@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
34246 s32 (*check_for_ack)(struct ixgbe_hw *);
34247 s32 (*check_for_rst)(struct ixgbe_hw *);
34248 };
34249+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34250
34251 struct ixgbe_mbx_stats {
34252 u32 msgs_tx;
34253@@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
34254 };
34255
34256 struct ixgbe_mbx_info {
34257- struct ixgbe_mbx_operations ops;
34258+ ixgbe_mbx_operations_no_const ops;
34259 struct ixgbe_mbx_stats stats;
34260 u32 timeout;
34261 u32 udelay;
34262diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
34263index 8bf22b6..7f5baaa 100644
34264--- a/drivers/net/ethernet/mellanox/mlx4/main.c
34265+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
34266@@ -41,6 +41,7 @@
34267 #include <linux/slab.h>
34268 #include <linux/io-mapping.h>
34269 #include <linux/delay.h>
34270+#include <linux/sched.h>
34271
34272 #include <linux/mlx4/device.h>
34273 #include <linux/mlx4/doorbell.h>
34274diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34275index 5046a64..71ca936 100644
34276--- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
34277+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34278@@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
34279 void (*link_down)(struct __vxge_hw_device *devh);
34280 void (*crit_err)(struct __vxge_hw_device *devh,
34281 enum vxge_hw_event type, u64 ext_data);
34282-};
34283+} __no_const;
34284
34285 /*
34286 * struct __vxge_hw_blockpool_entry - Block private data structure
34287diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34288index 4a518a3..936b334 100644
34289--- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34290+++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34291@@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
34292 struct vxge_hw_mempool_dma *dma_object,
34293 u32 index,
34294 u32 is_last);
34295-};
34296+} __no_const;
34297
34298 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
34299 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
34300diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
34301index bbacb37..d60887d 100644
34302--- a/drivers/net/ethernet/realtek/r8169.c
34303+++ b/drivers/net/ethernet/realtek/r8169.c
34304@@ -695,17 +695,17 @@ struct rtl8169_private {
34305 struct mdio_ops {
34306 void (*write)(void __iomem *, int, int);
34307 int (*read)(void __iomem *, int);
34308- } mdio_ops;
34309+ } __no_const mdio_ops;
34310
34311 struct pll_power_ops {
34312 void (*down)(struct rtl8169_private *);
34313 void (*up)(struct rtl8169_private *);
34314- } pll_power_ops;
34315+ } __no_const pll_power_ops;
34316
34317 struct jumbo_ops {
34318 void (*enable)(struct rtl8169_private *);
34319 void (*disable)(struct rtl8169_private *);
34320- } jumbo_ops;
34321+ } __no_const jumbo_ops;
34322
34323 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
34324 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
34325diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
34326index 5b118cd..858b523 100644
34327--- a/drivers/net/ethernet/sis/sis190.c
34328+++ b/drivers/net/ethernet/sis/sis190.c
34329@@ -1622,7 +1622,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
34330 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
34331 struct net_device *dev)
34332 {
34333- static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
34334+ static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
34335 struct sis190_private *tp = netdev_priv(dev);
34336 struct pci_dev *isa_bridge;
34337 u8 reg, tmp8;
34338diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
34339index c07cfe9..81cbf7e 100644
34340--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
34341+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
34342@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
34343
34344 writel(value, ioaddr + MMC_CNTRL);
34345
34346- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
34347- MMC_CNTRL, value);
34348+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
34349+// MMC_CNTRL, value);
34350 }
34351
34352 /* To mask all all interrupts.*/
34353diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
34354index dec5836..6d4db7d 100644
34355--- a/drivers/net/hyperv/hyperv_net.h
34356+++ b/drivers/net/hyperv/hyperv_net.h
34357@@ -97,7 +97,7 @@ struct rndis_device {
34358
34359 enum rndis_device_state state;
34360 bool link_state;
34361- atomic_t new_req_id;
34362+ atomic_unchecked_t new_req_id;
34363
34364 spinlock_t request_lock;
34365 struct list_head req_list;
34366diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
34367index 133b7fb..d58c559 100644
34368--- a/drivers/net/hyperv/rndis_filter.c
34369+++ b/drivers/net/hyperv/rndis_filter.c
34370@@ -96,7 +96,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
34371 * template
34372 */
34373 set = &rndis_msg->msg.set_req;
34374- set->req_id = atomic_inc_return(&dev->new_req_id);
34375+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
34376
34377 /* Add to the request list */
34378 spin_lock_irqsave(&dev->request_lock, flags);
34379@@ -627,7 +627,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
34380
34381 /* Setup the rndis set */
34382 halt = &request->request_msg.msg.halt_req;
34383- halt->req_id = atomic_inc_return(&dev->new_req_id);
34384+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
34385
34386 /* Ignore return since this msg is optional. */
34387 rndis_filter_send_request(dev, request);
34388diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
34389index 486b404..0d6677d 100644
34390--- a/drivers/net/ppp/ppp_generic.c
34391+++ b/drivers/net/ppp/ppp_generic.c
34392@@ -987,7 +987,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34393 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
34394 struct ppp_stats stats;
34395 struct ppp_comp_stats cstats;
34396- char *vers;
34397
34398 switch (cmd) {
34399 case SIOCGPPPSTATS:
34400@@ -1009,8 +1008,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34401 break;
34402
34403 case SIOCGPPPVER:
34404- vers = PPP_VERSION;
34405- if (copy_to_user(addr, vers, strlen(vers) + 1))
34406+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
34407 break;
34408 err = 0;
34409 break;
34410diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
34411index 515f122..41dd273 100644
34412--- a/drivers/net/tokenring/abyss.c
34413+++ b/drivers/net/tokenring/abyss.c
34414@@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
34415
34416 static int __init abyss_init (void)
34417 {
34418- abyss_netdev_ops = tms380tr_netdev_ops;
34419+ pax_open_kernel();
34420+ memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34421
34422- abyss_netdev_ops.ndo_open = abyss_open;
34423- abyss_netdev_ops.ndo_stop = abyss_close;
34424+ *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
34425+ *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
34426+ pax_close_kernel();
34427
34428 return pci_register_driver(&abyss_driver);
34429 }
34430diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
34431index 6153cfd..cf69c1c 100644
34432--- a/drivers/net/tokenring/madgemc.c
34433+++ b/drivers/net/tokenring/madgemc.c
34434@@ -744,9 +744,11 @@ static struct mca_driver madgemc_driver = {
34435
34436 static int __init madgemc_init (void)
34437 {
34438- madgemc_netdev_ops = tms380tr_netdev_ops;
34439- madgemc_netdev_ops.ndo_open = madgemc_open;
34440- madgemc_netdev_ops.ndo_stop = madgemc_close;
34441+ pax_open_kernel();
34442+ memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34443+ *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
34444+ *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
34445+ pax_close_kernel();
34446
34447 return mca_register_driver (&madgemc_driver);
34448 }
34449diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
34450index 8d362e6..f91cc52 100644
34451--- a/drivers/net/tokenring/proteon.c
34452+++ b/drivers/net/tokenring/proteon.c
34453@@ -353,9 +353,11 @@ static int __init proteon_init(void)
34454 struct platform_device *pdev;
34455 int i, num = 0, err = 0;
34456
34457- proteon_netdev_ops = tms380tr_netdev_ops;
34458- proteon_netdev_ops.ndo_open = proteon_open;
34459- proteon_netdev_ops.ndo_stop = tms380tr_close;
34460+ pax_open_kernel();
34461+ memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34462+ *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
34463+ *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
34464+ pax_close_kernel();
34465
34466 err = platform_driver_register(&proteon_driver);
34467 if (err)
34468diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
34469index 46db5c5..37c1536 100644
34470--- a/drivers/net/tokenring/skisa.c
34471+++ b/drivers/net/tokenring/skisa.c
34472@@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
34473 struct platform_device *pdev;
34474 int i, num = 0, err = 0;
34475
34476- sk_isa_netdev_ops = tms380tr_netdev_ops;
34477- sk_isa_netdev_ops.ndo_open = sk_isa_open;
34478- sk_isa_netdev_ops.ndo_stop = tms380tr_close;
34479+ pax_open_kernel();
34480+ memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
34481+ *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
34482+ *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
34483+ pax_close_kernel();
34484
34485 err = platform_driver_register(&sk_isa_driver);
34486 if (err)
34487diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
34488index e1324b4..e1b0041 100644
34489--- a/drivers/net/usb/hso.c
34490+++ b/drivers/net/usb/hso.c
34491@@ -71,7 +71,7 @@
34492 #include <asm/byteorder.h>
34493 #include <linux/serial_core.h>
34494 #include <linux/serial.h>
34495-
34496+#include <asm/local.h>
34497
34498 #define MOD_AUTHOR "Option Wireless"
34499 #define MOD_DESCRIPTION "USB High Speed Option driver"
34500@@ -257,7 +257,7 @@ struct hso_serial {
34501
34502 /* from usb_serial_port */
34503 struct tty_struct *tty;
34504- int open_count;
34505+ local_t open_count;
34506 spinlock_t serial_lock;
34507
34508 int (*write_data) (struct hso_serial *serial);
34509@@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
34510 struct urb *urb;
34511
34512 urb = serial->rx_urb[0];
34513- if (serial->open_count > 0) {
34514+ if (local_read(&serial->open_count) > 0) {
34515 count = put_rxbuf_data(urb, serial);
34516 if (count == -1)
34517 return;
34518@@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
34519 DUMP1(urb->transfer_buffer, urb->actual_length);
34520
34521 /* Anyone listening? */
34522- if (serial->open_count == 0)
34523+ if (local_read(&serial->open_count) == 0)
34524 return;
34525
34526 if (status == 0) {
34527@@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
34528 spin_unlock_irq(&serial->serial_lock);
34529
34530 /* check for port already opened, if not set the termios */
34531- serial->open_count++;
34532- if (serial->open_count == 1) {
34533+ if (local_inc_return(&serial->open_count) == 1) {
34534 serial->rx_state = RX_IDLE;
34535 /* Force default termio settings */
34536 _hso_serial_set_termios(tty, NULL);
34537@@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
34538 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
34539 if (result) {
34540 hso_stop_serial_device(serial->parent);
34541- serial->open_count--;
34542+ local_dec(&serial->open_count);
34543 kref_put(&serial->parent->ref, hso_serial_ref_free);
34544 }
34545 } else {
34546@@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
34547
34548 /* reset the rts and dtr */
34549 /* do the actual close */
34550- serial->open_count--;
34551+ local_dec(&serial->open_count);
34552
34553- if (serial->open_count <= 0) {
34554- serial->open_count = 0;
34555+ if (local_read(&serial->open_count) <= 0) {
34556+ local_set(&serial->open_count, 0);
34557 spin_lock_irq(&serial->serial_lock);
34558 if (serial->tty == tty) {
34559 serial->tty->driver_data = NULL;
34560@@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
34561
34562 /* the actual setup */
34563 spin_lock_irqsave(&serial->serial_lock, flags);
34564- if (serial->open_count)
34565+ if (local_read(&serial->open_count))
34566 _hso_serial_set_termios(tty, old);
34567 else
34568 tty->termios = old;
34569@@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
34570 D1("Pending read interrupt on port %d\n", i);
34571 spin_lock(&serial->serial_lock);
34572 if (serial->rx_state == RX_IDLE &&
34573- serial->open_count > 0) {
34574+ local_read(&serial->open_count) > 0) {
34575 /* Setup and send a ctrl req read on
34576 * port i */
34577 if (!serial->rx_urb_filled[0]) {
34578@@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
34579 /* Start all serial ports */
34580 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
34581 if (serial_table[i] && (serial_table[i]->interface == iface)) {
34582- if (dev2ser(serial_table[i])->open_count) {
34583+ if (local_read(&dev2ser(serial_table[i])->open_count)) {
34584 result =
34585 hso_start_serial_device(serial_table[i], GFP_NOIO);
34586 hso_kick_transmit(dev2ser(serial_table[i]));
34587diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
34588index efc0111..79c8f5b 100644
34589--- a/drivers/net/wireless/ath/ath.h
34590+++ b/drivers/net/wireless/ath/ath.h
34591@@ -119,6 +119,7 @@ struct ath_ops {
34592 void (*write_flush) (void *);
34593 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
34594 };
34595+typedef struct ath_ops __no_const ath_ops_no_const;
34596
34597 struct ath_common;
34598 struct ath_bus_ops;
34599diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
34600index 7b6417b..ab5db98 100644
34601--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
34602+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
34603@@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34604 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
34605 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
34606
34607- ACCESS_ONCE(ads->ds_link) = i->link;
34608- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
34609+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
34610+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
34611
34612 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
34613 ctl6 = SM(i->keytype, AR_EncrType);
34614@@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34615
34616 if ((i->is_first || i->is_last) &&
34617 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
34618- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
34619+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
34620 | set11nTries(i->rates, 1)
34621 | set11nTries(i->rates, 2)
34622 | set11nTries(i->rates, 3)
34623 | (i->dur_update ? AR_DurUpdateEna : 0)
34624 | SM(0, AR_BurstDur);
34625
34626- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
34627+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
34628 | set11nRate(i->rates, 1)
34629 | set11nRate(i->rates, 2)
34630 | set11nRate(i->rates, 3);
34631 } else {
34632- ACCESS_ONCE(ads->ds_ctl2) = 0;
34633- ACCESS_ONCE(ads->ds_ctl3) = 0;
34634+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
34635+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
34636 }
34637
34638 if (!i->is_first) {
34639- ACCESS_ONCE(ads->ds_ctl0) = 0;
34640- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
34641- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
34642+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
34643+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
34644+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
34645 return;
34646 }
34647
34648@@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34649 break;
34650 }
34651
34652- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
34653+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
34654 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
34655 | SM(i->txpower, AR_XmitPower)
34656 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
34657@@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34658 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
34659 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
34660
34661- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
34662- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
34663+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
34664+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
34665
34666 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
34667 return;
34668
34669- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
34670+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
34671 | set11nPktDurRTSCTS(i->rates, 1);
34672
34673- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
34674+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
34675 | set11nPktDurRTSCTS(i->rates, 3);
34676
34677- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
34678+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
34679 | set11nRateFlags(i->rates, 1)
34680 | set11nRateFlags(i->rates, 2)
34681 | set11nRateFlags(i->rates, 3)
34682diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
34683index 09b8c9d..905339e 100644
34684--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
34685+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
34686@@ -35,47 +35,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34687 (i->qcu << AR_TxQcuNum_S) | 0x17;
34688
34689 checksum += val;
34690- ACCESS_ONCE(ads->info) = val;
34691+ ACCESS_ONCE_RW(ads->info) = val;
34692
34693 checksum += i->link;
34694- ACCESS_ONCE(ads->link) = i->link;
34695+ ACCESS_ONCE_RW(ads->link) = i->link;
34696
34697 checksum += i->buf_addr[0];
34698- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
34699+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
34700 checksum += i->buf_addr[1];
34701- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
34702+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
34703 checksum += i->buf_addr[2];
34704- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
34705+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
34706 checksum += i->buf_addr[3];
34707- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
34708+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
34709
34710 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
34711- ACCESS_ONCE(ads->ctl3) = val;
34712+ ACCESS_ONCE_RW(ads->ctl3) = val;
34713 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
34714- ACCESS_ONCE(ads->ctl5) = val;
34715+ ACCESS_ONCE_RW(ads->ctl5) = val;
34716 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
34717- ACCESS_ONCE(ads->ctl7) = val;
34718+ ACCESS_ONCE_RW(ads->ctl7) = val;
34719 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
34720- ACCESS_ONCE(ads->ctl9) = val;
34721+ ACCESS_ONCE_RW(ads->ctl9) = val;
34722
34723 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
34724- ACCESS_ONCE(ads->ctl10) = checksum;
34725+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
34726
34727 if (i->is_first || i->is_last) {
34728- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
34729+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
34730 | set11nTries(i->rates, 1)
34731 | set11nTries(i->rates, 2)
34732 | set11nTries(i->rates, 3)
34733 | (i->dur_update ? AR_DurUpdateEna : 0)
34734 | SM(0, AR_BurstDur);
34735
34736- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
34737+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
34738 | set11nRate(i->rates, 1)
34739 | set11nRate(i->rates, 2)
34740 | set11nRate(i->rates, 3);
34741 } else {
34742- ACCESS_ONCE(ads->ctl13) = 0;
34743- ACCESS_ONCE(ads->ctl14) = 0;
34744+ ACCESS_ONCE_RW(ads->ctl13) = 0;
34745+ ACCESS_ONCE_RW(ads->ctl14) = 0;
34746 }
34747
34748 ads->ctl20 = 0;
34749@@ -84,17 +84,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34750
34751 ctl17 = SM(i->keytype, AR_EncrType);
34752 if (!i->is_first) {
34753- ACCESS_ONCE(ads->ctl11) = 0;
34754- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
34755- ACCESS_ONCE(ads->ctl15) = 0;
34756- ACCESS_ONCE(ads->ctl16) = 0;
34757- ACCESS_ONCE(ads->ctl17) = ctl17;
34758- ACCESS_ONCE(ads->ctl18) = 0;
34759- ACCESS_ONCE(ads->ctl19) = 0;
34760+ ACCESS_ONCE_RW(ads->ctl11) = 0;
34761+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
34762+ ACCESS_ONCE_RW(ads->ctl15) = 0;
34763+ ACCESS_ONCE_RW(ads->ctl16) = 0;
34764+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
34765+ ACCESS_ONCE_RW(ads->ctl18) = 0;
34766+ ACCESS_ONCE_RW(ads->ctl19) = 0;
34767 return;
34768 }
34769
34770- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
34771+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
34772 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
34773 | SM(i->txpower, AR_XmitPower)
34774 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
34775@@ -130,22 +130,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
34776 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
34777 ctl12 |= SM(val, AR_PAPRDChainMask);
34778
34779- ACCESS_ONCE(ads->ctl12) = ctl12;
34780- ACCESS_ONCE(ads->ctl17) = ctl17;
34781+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
34782+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
34783
34784- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
34785+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
34786 | set11nPktDurRTSCTS(i->rates, 1);
34787
34788- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
34789+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
34790 | set11nPktDurRTSCTS(i->rates, 3);
34791
34792- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
34793+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
34794 | set11nRateFlags(i->rates, 1)
34795 | set11nRateFlags(i->rates, 2)
34796 | set11nRateFlags(i->rates, 3)
34797 | SM(i->rtscts_rate, AR_RTSCTSRate);
34798
34799- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
34800+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
34801 }
34802
34803 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
34804diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
34805index c8261d4..8d88929 100644
34806--- a/drivers/net/wireless/ath/ath9k/hw.h
34807+++ b/drivers/net/wireless/ath/ath9k/hw.h
34808@@ -773,7 +773,7 @@ struct ath_hw_private_ops {
34809
34810 /* ANI */
34811 void (*ani_cache_ini_regs)(struct ath_hw *ah);
34812-};
34813+} __no_const;
34814
34815 /**
34816 * struct ath_hw_ops - callbacks used by hardware code and driver code
34817@@ -803,7 +803,7 @@ struct ath_hw_ops {
34818 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
34819 struct ath_hw_antcomb_conf *antconf);
34820
34821-};
34822+} __no_const;
34823
34824 struct ath_nf_limits {
34825 s16 max;
34826@@ -823,7 +823,7 @@ enum ath_cal_list {
34827 #define AH_FASTCC 0x4
34828
34829 struct ath_hw {
34830- struct ath_ops reg_ops;
34831+ ath_ops_no_const reg_ops;
34832
34833 struct ieee80211_hw *hw;
34834 struct ath_common common;
34835diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
34836index af00e2c..ab04d34 100644
34837--- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
34838+++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
34839@@ -545,7 +545,7 @@ struct phy_func_ptr {
34840 void (*carrsuppr)(struct brcms_phy *);
34841 s32 (*rxsigpwr)(struct brcms_phy *, s32);
34842 void (*detach)(struct brcms_phy *);
34843-};
34844+} __no_const;
34845
34846 struct brcms_phy {
34847 struct brcms_phy_pub pubpi_ro;
34848diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
34849index a7dfba8..e28eacd 100644
34850--- a/drivers/net/wireless/iwlegacy/3945-mac.c
34851+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
34852@@ -3647,7 +3647,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
34853 */
34854 if (il3945_mod_params.disable_hw_scan) {
34855 D_INFO("Disabling hw_scan\n");
34856- il3945_hw_ops.hw_scan = NULL;
34857+ pax_open_kernel();
34858+ *(void **)&il3945_hw_ops.hw_scan = NULL;
34859+ pax_close_kernel();
34860 }
34861
34862 D_INFO("*** LOAD DRIVER ***\n");
34863diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
34864index f8fc239..8cade22 100644
34865--- a/drivers/net/wireless/iwlwifi/iwl-debug.h
34866+++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
34867@@ -86,8 +86,8 @@ do { \
34868 } while (0)
34869
34870 #else
34871-#define IWL_DEBUG(m, level, fmt, args...)
34872-#define IWL_DEBUG_LIMIT(m, level, fmt, args...)
34873+#define IWL_DEBUG(m, level, fmt, args...) do {} while (0)
34874+#define IWL_DEBUG_LIMIT(m, level, fmt, args...) do {} while (0)
34875 #define iwl_print_hex_dump(m, level, p, len)
34876 #define IWL_DEBUG_QUIET_RFKILL(p, fmt, args...) \
34877 do { \
34878diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
34879index 4b9e730..7603659 100644
34880--- a/drivers/net/wireless/mac80211_hwsim.c
34881+++ b/drivers/net/wireless/mac80211_hwsim.c
34882@@ -1677,9 +1677,11 @@ static int __init init_mac80211_hwsim(void)
34883 return -EINVAL;
34884
34885 if (fake_hw_scan) {
34886- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
34887- mac80211_hwsim_ops.sw_scan_start = NULL;
34888- mac80211_hwsim_ops.sw_scan_complete = NULL;
34889+ pax_open_kernel();
34890+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
34891+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
34892+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
34893+ pax_close_kernel();
34894 }
34895
34896 spin_lock_init(&hwsim_radio_lock);
34897diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
34898index 3186aa4..b35b09f 100644
34899--- a/drivers/net/wireless/mwifiex/main.h
34900+++ b/drivers/net/wireless/mwifiex/main.h
34901@@ -536,7 +536,7 @@ struct mwifiex_if_ops {
34902 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
34903 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
34904 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
34905-};
34906+} __no_const;
34907
34908 struct mwifiex_adapter {
34909 u8 iface_type;
34910diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
34911index a330c69..a81540f 100644
34912--- a/drivers/net/wireless/rndis_wlan.c
34913+++ b/drivers/net/wireless/rndis_wlan.c
34914@@ -1278,7 +1278,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
34915
34916 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
34917
34918- if (rts_threshold < 0 || rts_threshold > 2347)
34919+ if (rts_threshold > 2347)
34920 rts_threshold = 2347;
34921
34922 tmp = cpu_to_le32(rts_threshold);
34923diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
34924index a77f1bb..c608b2b 100644
34925--- a/drivers/net/wireless/wl1251/wl1251.h
34926+++ b/drivers/net/wireless/wl1251/wl1251.h
34927@@ -266,7 +266,7 @@ struct wl1251_if_operations {
34928 void (*reset)(struct wl1251 *wl);
34929 void (*enable_irq)(struct wl1251 *wl);
34930 void (*disable_irq)(struct wl1251 *wl);
34931-};
34932+} __no_const;
34933
34934 struct wl1251 {
34935 struct ieee80211_hw *hw;
34936diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
34937index f34b5b2..b5abb9f 100644
34938--- a/drivers/oprofile/buffer_sync.c
34939+++ b/drivers/oprofile/buffer_sync.c
34940@@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
34941 if (cookie == NO_COOKIE)
34942 offset = pc;
34943 if (cookie == INVALID_COOKIE) {
34944- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
34945+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
34946 offset = pc;
34947 }
34948 if (cookie != last_cookie) {
34949@@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
34950 /* add userspace sample */
34951
34952 if (!mm) {
34953- atomic_inc(&oprofile_stats.sample_lost_no_mm);
34954+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
34955 return 0;
34956 }
34957
34958 cookie = lookup_dcookie(mm, s->eip, &offset);
34959
34960 if (cookie == INVALID_COOKIE) {
34961- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
34962+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
34963 return 0;
34964 }
34965
34966@@ -563,7 +563,7 @@ void sync_buffer(int cpu)
34967 /* ignore backtraces if failed to add a sample */
34968 if (state == sb_bt_start) {
34969 state = sb_bt_ignore;
34970- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
34971+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
34972 }
34973 }
34974 release_mm(mm);
34975diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
34976index c0cc4e7..44d4e54 100644
34977--- a/drivers/oprofile/event_buffer.c
34978+++ b/drivers/oprofile/event_buffer.c
34979@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
34980 }
34981
34982 if (buffer_pos == buffer_size) {
34983- atomic_inc(&oprofile_stats.event_lost_overflow);
34984+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
34985 return;
34986 }
34987
34988diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
34989index ed2c3ec..deda85a 100644
34990--- a/drivers/oprofile/oprof.c
34991+++ b/drivers/oprofile/oprof.c
34992@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
34993 if (oprofile_ops.switch_events())
34994 return;
34995
34996- atomic_inc(&oprofile_stats.multiplex_counter);
34997+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
34998 start_switch_worker();
34999 }
35000
35001diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35002index 917d28e..d62d981 100644
35003--- a/drivers/oprofile/oprofile_stats.c
35004+++ b/drivers/oprofile/oprofile_stats.c
35005@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35006 cpu_buf->sample_invalid_eip = 0;
35007 }
35008
35009- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35010- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35011- atomic_set(&oprofile_stats.event_lost_overflow, 0);
35012- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35013- atomic_set(&oprofile_stats.multiplex_counter, 0);
35014+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35015+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35016+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35017+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35018+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35019 }
35020
35021
35022diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35023index 38b6fc0..b5cbfce 100644
35024--- a/drivers/oprofile/oprofile_stats.h
35025+++ b/drivers/oprofile/oprofile_stats.h
35026@@ -13,11 +13,11 @@
35027 #include <linux/atomic.h>
35028
35029 struct oprofile_stat_struct {
35030- atomic_t sample_lost_no_mm;
35031- atomic_t sample_lost_no_mapping;
35032- atomic_t bt_lost_no_mapping;
35033- atomic_t event_lost_overflow;
35034- atomic_t multiplex_counter;
35035+ atomic_unchecked_t sample_lost_no_mm;
35036+ atomic_unchecked_t sample_lost_no_mapping;
35037+ atomic_unchecked_t bt_lost_no_mapping;
35038+ atomic_unchecked_t event_lost_overflow;
35039+ atomic_unchecked_t multiplex_counter;
35040 };
35041
35042 extern struct oprofile_stat_struct oprofile_stats;
35043diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35044index 2f0aa0f..90fab02 100644
35045--- a/drivers/oprofile/oprofilefs.c
35046+++ b/drivers/oprofile/oprofilefs.c
35047@@ -193,7 +193,7 @@ static const struct file_operations atomic_ro_fops = {
35048
35049
35050 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35051- char const *name, atomic_t *val)
35052+ char const *name, atomic_unchecked_t *val)
35053 {
35054 return __oprofilefs_create_file(sb, root, name,
35055 &atomic_ro_fops, 0444, val);
35056diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35057index 3f56bc0..707d642 100644
35058--- a/drivers/parport/procfs.c
35059+++ b/drivers/parport/procfs.c
35060@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35061
35062 *ppos += len;
35063
35064- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35065+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35066 }
35067
35068 #ifdef CONFIG_PARPORT_1284
35069@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35070
35071 *ppos += len;
35072
35073- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35074+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35075 }
35076 #endif /* IEEE1284.3 support. */
35077
35078diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35079index 9fff878..ad0ad53 100644
35080--- a/drivers/pci/hotplug/cpci_hotplug.h
35081+++ b/drivers/pci/hotplug/cpci_hotplug.h
35082@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35083 int (*hardware_test) (struct slot* slot, u32 value);
35084 u8 (*get_power) (struct slot* slot);
35085 int (*set_power) (struct slot* slot, int value);
35086-};
35087+} __no_const;
35088
35089 struct cpci_hp_controller {
35090 unsigned int irq;
35091diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35092index 76ba8a1..20ca857 100644
35093--- a/drivers/pci/hotplug/cpqphp_nvram.c
35094+++ b/drivers/pci/hotplug/cpqphp_nvram.c
35095@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35096
35097 void compaq_nvram_init (void __iomem *rom_start)
35098 {
35099+
35100+#ifndef CONFIG_PAX_KERNEXEC
35101 if (rom_start) {
35102 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35103 }
35104+#endif
35105+
35106 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35107
35108 /* initialize our int15 lock */
35109diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35110index 2275162..95f1a92 100644
35111--- a/drivers/pci/pcie/aspm.c
35112+++ b/drivers/pci/pcie/aspm.c
35113@@ -27,9 +27,9 @@
35114 #define MODULE_PARAM_PREFIX "pcie_aspm."
35115
35116 /* Note: those are not register definitions */
35117-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35118-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35119-#define ASPM_STATE_L1 (4) /* L1 state */
35120+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35121+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35122+#define ASPM_STATE_L1 (4U) /* L1 state */
35123 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35124 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35125
35126diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
35127index 71eac9c..2de27ef 100644
35128--- a/drivers/pci/probe.c
35129+++ b/drivers/pci/probe.c
35130@@ -136,7 +136,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
35131 u32 l, sz, mask;
35132 u16 orig_cmd;
35133
35134- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
35135+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
35136
35137 if (!dev->mmio_always_on) {
35138 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
35139diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
35140index 27911b5..5b6db88 100644
35141--- a/drivers/pci/proc.c
35142+++ b/drivers/pci/proc.c
35143@@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
35144 static int __init pci_proc_init(void)
35145 {
35146 struct pci_dev *dev = NULL;
35147+
35148+#ifdef CONFIG_GRKERNSEC_PROC_ADD
35149+#ifdef CONFIG_GRKERNSEC_PROC_USER
35150+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35151+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35152+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35153+#endif
35154+#else
35155 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35156+#endif
35157 proc_create("devices", 0, proc_bus_pci_dir,
35158 &proc_bus_pci_dev_operations);
35159 proc_initialized = 1;
35160diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
35161index ea0c607..58c4628 100644
35162--- a/drivers/platform/x86/thinkpad_acpi.c
35163+++ b/drivers/platform/x86/thinkpad_acpi.c
35164@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
35165 return 0;
35166 }
35167
35168-void static hotkey_mask_warn_incomplete_mask(void)
35169+static void hotkey_mask_warn_incomplete_mask(void)
35170 {
35171 /* log only what the user can fix... */
35172 const u32 wantedmask = hotkey_driver_mask &
35173@@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
35174 }
35175 }
35176
35177-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35178- struct tp_nvram_state *newn,
35179- const u32 event_mask)
35180-{
35181-
35182 #define TPACPI_COMPARE_KEY(__scancode, __member) \
35183 do { \
35184 if ((event_mask & (1 << __scancode)) && \
35185@@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35186 tpacpi_hotkey_send_key(__scancode); \
35187 } while (0)
35188
35189- void issue_volchange(const unsigned int oldvol,
35190- const unsigned int newvol)
35191- {
35192- unsigned int i = oldvol;
35193+static void issue_volchange(const unsigned int oldvol,
35194+ const unsigned int newvol,
35195+ const u32 event_mask)
35196+{
35197+ unsigned int i = oldvol;
35198
35199- while (i > newvol) {
35200- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35201- i--;
35202- }
35203- while (i < newvol) {
35204- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35205- i++;
35206- }
35207+ while (i > newvol) {
35208+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35209+ i--;
35210 }
35211+ while (i < newvol) {
35212+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35213+ i++;
35214+ }
35215+}
35216
35217- void issue_brightnesschange(const unsigned int oldbrt,
35218- const unsigned int newbrt)
35219- {
35220- unsigned int i = oldbrt;
35221+static void issue_brightnesschange(const unsigned int oldbrt,
35222+ const unsigned int newbrt,
35223+ const u32 event_mask)
35224+{
35225+ unsigned int i = oldbrt;
35226
35227- while (i > newbrt) {
35228- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35229- i--;
35230- }
35231- while (i < newbrt) {
35232- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35233- i++;
35234- }
35235+ while (i > newbrt) {
35236+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35237+ i--;
35238+ }
35239+ while (i < newbrt) {
35240+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35241+ i++;
35242 }
35243+}
35244
35245+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35246+ struct tp_nvram_state *newn,
35247+ const u32 event_mask)
35248+{
35249 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
35250 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
35251 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
35252@@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35253 oldn->volume_level != newn->volume_level) {
35254 /* recently muted, or repeated mute keypress, or
35255 * multiple presses ending in mute */
35256- issue_volchange(oldn->volume_level, newn->volume_level);
35257+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35258 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
35259 }
35260 } else {
35261@@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35262 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35263 }
35264 if (oldn->volume_level != newn->volume_level) {
35265- issue_volchange(oldn->volume_level, newn->volume_level);
35266+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35267 } else if (oldn->volume_toggle != newn->volume_toggle) {
35268 /* repeated vol up/down keypress at end of scale ? */
35269 if (newn->volume_level == 0)
35270@@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35271 /* handle brightness */
35272 if (oldn->brightness_level != newn->brightness_level) {
35273 issue_brightnesschange(oldn->brightness_level,
35274- newn->brightness_level);
35275+ newn->brightness_level,
35276+ event_mask);
35277 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
35278 /* repeated key presses that didn't change state */
35279 if (newn->brightness_level == 0)
35280@@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35281 && !tp_features.bright_unkfw)
35282 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35283 }
35284+}
35285
35286 #undef TPACPI_COMPARE_KEY
35287 #undef TPACPI_MAY_SEND_KEY
35288-}
35289
35290 /*
35291 * Polling driver
35292diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
35293index b859d16..5cc6b1a 100644
35294--- a/drivers/pnp/pnpbios/bioscalls.c
35295+++ b/drivers/pnp/pnpbios/bioscalls.c
35296@@ -59,7 +59,7 @@ do { \
35297 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
35298 } while(0)
35299
35300-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
35301+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
35302 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
35303
35304 /*
35305@@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35306
35307 cpu = get_cpu();
35308 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
35309+
35310+ pax_open_kernel();
35311 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
35312+ pax_close_kernel();
35313
35314 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
35315 spin_lock_irqsave(&pnp_bios_lock, flags);
35316@@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35317 :"memory");
35318 spin_unlock_irqrestore(&pnp_bios_lock, flags);
35319
35320+ pax_open_kernel();
35321 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
35322+ pax_close_kernel();
35323+
35324 put_cpu();
35325
35326 /* If we get here and this is set then the PnP BIOS faulted on us. */
35327@@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
35328 return status;
35329 }
35330
35331-void pnpbios_calls_init(union pnp_bios_install_struct *header)
35332+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
35333 {
35334 int i;
35335
35336@@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35337 pnp_bios_callpoint.offset = header->fields.pm16offset;
35338 pnp_bios_callpoint.segment = PNP_CS16;
35339
35340+ pax_open_kernel();
35341+
35342 for_each_possible_cpu(i) {
35343 struct desc_struct *gdt = get_cpu_gdt_table(i);
35344 if (!gdt)
35345@@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35346 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
35347 (unsigned long)__va(header->fields.pm16dseg));
35348 }
35349+
35350+ pax_close_kernel();
35351 }
35352diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
35353index b0ecacb..7c9da2e 100644
35354--- a/drivers/pnp/resource.c
35355+++ b/drivers/pnp/resource.c
35356@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
35357 return 1;
35358
35359 /* check if the resource is valid */
35360- if (*irq < 0 || *irq > 15)
35361+ if (*irq > 15)
35362 return 0;
35363
35364 /* check if the resource is reserved */
35365@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
35366 return 1;
35367
35368 /* check if the resource is valid */
35369- if (*dma < 0 || *dma == 4 || *dma > 7)
35370+ if (*dma == 4 || *dma > 7)
35371 return 0;
35372
35373 /* check if the resource is reserved */
35374diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
35375index 1ed6ea0..77c0bd2 100644
35376--- a/drivers/power/bq27x00_battery.c
35377+++ b/drivers/power/bq27x00_battery.c
35378@@ -72,7 +72,7 @@
35379 struct bq27x00_device_info;
35380 struct bq27x00_access_methods {
35381 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
35382-};
35383+} __no_const;
35384
35385 enum bq27x00_chip { BQ27000, BQ27500 };
35386
35387diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
35388index a838e66..a9e1665 100644
35389--- a/drivers/regulator/max8660.c
35390+++ b/drivers/regulator/max8660.c
35391@@ -383,8 +383,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
35392 max8660->shadow_regs[MAX8660_OVER1] = 5;
35393 } else {
35394 /* Otherwise devices can be toggled via software */
35395- max8660_dcdc_ops.enable = max8660_dcdc_enable;
35396- max8660_dcdc_ops.disable = max8660_dcdc_disable;
35397+ pax_open_kernel();
35398+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
35399+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
35400+ pax_close_kernel();
35401 }
35402
35403 /*
35404diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
35405index e8cfc99..072aee2 100644
35406--- a/drivers/regulator/mc13892-regulator.c
35407+++ b/drivers/regulator/mc13892-regulator.c
35408@@ -574,10 +574,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
35409 }
35410 mc13xxx_unlock(mc13892);
35411
35412- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
35413+ pax_open_kernel();
35414+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
35415 = mc13892_vcam_set_mode;
35416- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
35417+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
35418 = mc13892_vcam_get_mode;
35419+ pax_close_kernel();
35420
35421 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
35422 ARRAY_SIZE(mc13892_regulators));
35423diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
35424index cace6d3..f623fda 100644
35425--- a/drivers/rtc/rtc-dev.c
35426+++ b/drivers/rtc/rtc-dev.c
35427@@ -14,6 +14,7 @@
35428 #include <linux/module.h>
35429 #include <linux/rtc.h>
35430 #include <linux/sched.h>
35431+#include <linux/grsecurity.h>
35432 #include "rtc-core.h"
35433
35434 static dev_t rtc_devt;
35435@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
35436 if (copy_from_user(&tm, uarg, sizeof(tm)))
35437 return -EFAULT;
35438
35439+ gr_log_timechange();
35440+
35441 return rtc_set_time(rtc, &tm);
35442
35443 case RTC_PIE_ON:
35444diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
35445index ffb5878..e6d785c 100644
35446--- a/drivers/scsi/aacraid/aacraid.h
35447+++ b/drivers/scsi/aacraid/aacraid.h
35448@@ -492,7 +492,7 @@ struct adapter_ops
35449 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
35450 /* Administrative operations */
35451 int (*adapter_comm)(struct aac_dev * dev, int comm);
35452-};
35453+} __no_const;
35454
35455 /*
35456 * Define which interrupt handler needs to be installed
35457diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
35458index 705e13e..91c873c 100644
35459--- a/drivers/scsi/aacraid/linit.c
35460+++ b/drivers/scsi/aacraid/linit.c
35461@@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
35462 #elif defined(__devinitconst)
35463 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
35464 #else
35465-static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
35466+static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
35467 #endif
35468 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
35469 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
35470diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
35471index d5ff142..49c0ebb 100644
35472--- a/drivers/scsi/aic94xx/aic94xx_init.c
35473+++ b/drivers/scsi/aic94xx/aic94xx_init.c
35474@@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
35475 .lldd_control_phy = asd_control_phy,
35476 };
35477
35478-static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
35479+static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
35480 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
35481 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
35482 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
35483diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
35484index a796de9..1ef20e1 100644
35485--- a/drivers/scsi/bfa/bfa.h
35486+++ b/drivers/scsi/bfa/bfa.h
35487@@ -196,7 +196,7 @@ struct bfa_hwif_s {
35488 u32 *end);
35489 int cpe_vec_q0;
35490 int rme_vec_q0;
35491-};
35492+} __no_const;
35493 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
35494
35495 struct bfa_faa_cbfn_s {
35496diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
35497index f0f80e2..8ec946b 100644
35498--- a/drivers/scsi/bfa/bfa_fcpim.c
35499+++ b/drivers/scsi/bfa/bfa_fcpim.c
35500@@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
35501
35502 bfa_iotag_attach(fcp);
35503
35504- fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
35505+ fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
35506 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
35507 (fcp->num_itns * sizeof(struct bfa_itn_s));
35508 memset(fcp->itn_arr, 0,
35509@@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
35510 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
35511 {
35512 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
35513- struct bfa_itn_s *itn;
35514+ bfa_itn_s_no_const *itn;
35515
35516 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
35517 itn->isr = isr;
35518diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
35519index 36f26da..38a34a8 100644
35520--- a/drivers/scsi/bfa/bfa_fcpim.h
35521+++ b/drivers/scsi/bfa/bfa_fcpim.h
35522@@ -37,6 +37,7 @@ struct bfa_iotag_s {
35523 struct bfa_itn_s {
35524 bfa_isr_func_t isr;
35525 };
35526+typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
35527
35528 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
35529 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
35530@@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
35531 struct list_head iotag_tio_free_q; /* free IO resources */
35532 struct list_head iotag_unused_q; /* unused IO resources*/
35533 struct bfa_iotag_s *iotag_arr;
35534- struct bfa_itn_s *itn_arr;
35535+ bfa_itn_s_no_const *itn_arr;
35536 int num_ioim_reqs;
35537 int num_fwtio_reqs;
35538 int num_itns;
35539diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
35540index 546d46b..642fa5b 100644
35541--- a/drivers/scsi/bfa/bfa_ioc.h
35542+++ b/drivers/scsi/bfa/bfa_ioc.h
35543@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
35544 bfa_ioc_disable_cbfn_t disable_cbfn;
35545 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
35546 bfa_ioc_reset_cbfn_t reset_cbfn;
35547-};
35548+} __no_const;
35549
35550 /*
35551 * IOC event notification mechanism.
35552@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
35553 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
35554 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
35555 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
35556-};
35557+} __no_const;
35558
35559 /*
35560 * Queue element to wait for room in request queue. FIFO order is
35561diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
35562index 351dc0b..951dc32 100644
35563--- a/drivers/scsi/hosts.c
35564+++ b/drivers/scsi/hosts.c
35565@@ -42,7 +42,7 @@
35566 #include "scsi_logging.h"
35567
35568
35569-static atomic_t scsi_host_next_hn; /* host_no for next new host */
35570+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
35571
35572
35573 static void scsi_host_cls_release(struct device *dev)
35574@@ -357,7 +357,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
35575 * subtract one because we increment first then return, but we need to
35576 * know what the next host number was before increment
35577 */
35578- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
35579+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
35580 shost->dma_channel = 0xff;
35581
35582 /* These three are default values which can be overridden */
35583diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
35584index b96962c..0c82ec2 100644
35585--- a/drivers/scsi/hpsa.c
35586+++ b/drivers/scsi/hpsa.c
35587@@ -507,7 +507,7 @@ static inline u32 next_command(struct ctlr_info *h)
35588 u32 a;
35589
35590 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
35591- return h->access.command_completed(h);
35592+ return h->access->command_completed(h);
35593
35594 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
35595 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
35596@@ -2991,7 +2991,7 @@ static void start_io(struct ctlr_info *h)
35597 while (!list_empty(&h->reqQ)) {
35598 c = list_entry(h->reqQ.next, struct CommandList, list);
35599 /* can't do anything if fifo is full */
35600- if ((h->access.fifo_full(h))) {
35601+ if ((h->access->fifo_full(h))) {
35602 dev_warn(&h->pdev->dev, "fifo full\n");
35603 break;
35604 }
35605@@ -3001,7 +3001,7 @@ static void start_io(struct ctlr_info *h)
35606 h->Qdepth--;
35607
35608 /* Tell the controller execute command */
35609- h->access.submit_command(h, c);
35610+ h->access->submit_command(h, c);
35611
35612 /* Put job onto the completed Q */
35613 addQ(&h->cmpQ, c);
35614@@ -3010,17 +3010,17 @@ static void start_io(struct ctlr_info *h)
35615
35616 static inline unsigned long get_next_completion(struct ctlr_info *h)
35617 {
35618- return h->access.command_completed(h);
35619+ return h->access->command_completed(h);
35620 }
35621
35622 static inline bool interrupt_pending(struct ctlr_info *h)
35623 {
35624- return h->access.intr_pending(h);
35625+ return h->access->intr_pending(h);
35626 }
35627
35628 static inline long interrupt_not_for_us(struct ctlr_info *h)
35629 {
35630- return (h->access.intr_pending(h) == 0) ||
35631+ return (h->access->intr_pending(h) == 0) ||
35632 (h->interrupts_enabled == 0);
35633 }
35634
35635@@ -3919,7 +3919,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
35636 if (prod_index < 0)
35637 return -ENODEV;
35638 h->product_name = products[prod_index].product_name;
35639- h->access = *(products[prod_index].access);
35640+ h->access = products[prod_index].access;
35641
35642 if (hpsa_board_disabled(h->pdev)) {
35643 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
35644@@ -4164,7 +4164,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
35645
35646 assert_spin_locked(&lockup_detector_lock);
35647 remove_ctlr_from_lockup_detector_list(h);
35648- h->access.set_intr_mask(h, HPSA_INTR_OFF);
35649+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
35650 spin_lock_irqsave(&h->lock, flags);
35651 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
35652 spin_unlock_irqrestore(&h->lock, flags);
35653@@ -4344,7 +4344,7 @@ reinit_after_soft_reset:
35654 }
35655
35656 /* make sure the board interrupts are off */
35657- h->access.set_intr_mask(h, HPSA_INTR_OFF);
35658+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
35659
35660 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
35661 goto clean2;
35662@@ -4378,7 +4378,7 @@ reinit_after_soft_reset:
35663 * fake ones to scoop up any residual completions.
35664 */
35665 spin_lock_irqsave(&h->lock, flags);
35666- h->access.set_intr_mask(h, HPSA_INTR_OFF);
35667+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
35668 spin_unlock_irqrestore(&h->lock, flags);
35669 free_irq(h->intr[h->intr_mode], h);
35670 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
35671@@ -4397,9 +4397,9 @@ reinit_after_soft_reset:
35672 dev_info(&h->pdev->dev, "Board READY.\n");
35673 dev_info(&h->pdev->dev,
35674 "Waiting for stale completions to drain.\n");
35675- h->access.set_intr_mask(h, HPSA_INTR_ON);
35676+ h->access->set_intr_mask(h, HPSA_INTR_ON);
35677 msleep(10000);
35678- h->access.set_intr_mask(h, HPSA_INTR_OFF);
35679+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
35680
35681 rc = controller_reset_failed(h->cfgtable);
35682 if (rc)
35683@@ -4420,7 +4420,7 @@ reinit_after_soft_reset:
35684 }
35685
35686 /* Turn the interrupts on so we can service requests */
35687- h->access.set_intr_mask(h, HPSA_INTR_ON);
35688+ h->access->set_intr_mask(h, HPSA_INTR_ON);
35689
35690 hpsa_hba_inquiry(h);
35691 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
35692@@ -4472,7 +4472,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
35693 * To write all data in the battery backed cache to disks
35694 */
35695 hpsa_flush_cache(h);
35696- h->access.set_intr_mask(h, HPSA_INTR_OFF);
35697+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
35698 free_irq(h->intr[h->intr_mode], h);
35699 #ifdef CONFIG_PCI_MSI
35700 if (h->msix_vector)
35701@@ -4636,7 +4636,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
35702 return;
35703 }
35704 /* Change the access methods to the performant access methods */
35705- h->access = SA5_performant_access;
35706+ h->access = &SA5_performant_access;
35707 h->transMethod = CFGTBL_Trans_Performant;
35708 }
35709
35710diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
35711index 91edafb..a9b88ec 100644
35712--- a/drivers/scsi/hpsa.h
35713+++ b/drivers/scsi/hpsa.h
35714@@ -73,7 +73,7 @@ struct ctlr_info {
35715 unsigned int msix_vector;
35716 unsigned int msi_vector;
35717 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
35718- struct access_method access;
35719+ struct access_method *access;
35720
35721 /* queue and queue Info */
35722 struct list_head reqQ;
35723diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
35724index f2df059..a3a9930 100644
35725--- a/drivers/scsi/ips.h
35726+++ b/drivers/scsi/ips.h
35727@@ -1027,7 +1027,7 @@ typedef struct {
35728 int (*intr)(struct ips_ha *);
35729 void (*enableint)(struct ips_ha *);
35730 uint32_t (*statupd)(struct ips_ha *);
35731-} ips_hw_func_t;
35732+} __no_const ips_hw_func_t;
35733
35734 typedef struct ips_ha {
35735 uint8_t ha_id[IPS_MAX_CHANNELS+1];
35736diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
35737index 4d70d96..84d0573 100644
35738--- a/drivers/scsi/libfc/fc_exch.c
35739+++ b/drivers/scsi/libfc/fc_exch.c
35740@@ -105,12 +105,12 @@ struct fc_exch_mgr {
35741 * all together if not used XXX
35742 */
35743 struct {
35744- atomic_t no_free_exch;
35745- atomic_t no_free_exch_xid;
35746- atomic_t xid_not_found;
35747- atomic_t xid_busy;
35748- atomic_t seq_not_found;
35749- atomic_t non_bls_resp;
35750+ atomic_unchecked_t no_free_exch;
35751+ atomic_unchecked_t no_free_exch_xid;
35752+ atomic_unchecked_t xid_not_found;
35753+ atomic_unchecked_t xid_busy;
35754+ atomic_unchecked_t seq_not_found;
35755+ atomic_unchecked_t non_bls_resp;
35756 } stats;
35757 };
35758
35759@@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
35760 /* allocate memory for exchange */
35761 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
35762 if (!ep) {
35763- atomic_inc(&mp->stats.no_free_exch);
35764+ atomic_inc_unchecked(&mp->stats.no_free_exch);
35765 goto out;
35766 }
35767 memset(ep, 0, sizeof(*ep));
35768@@ -780,7 +780,7 @@ out:
35769 return ep;
35770 err:
35771 spin_unlock_bh(&pool->lock);
35772- atomic_inc(&mp->stats.no_free_exch_xid);
35773+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
35774 mempool_free(ep, mp->ep_pool);
35775 return NULL;
35776 }
35777@@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
35778 xid = ntohs(fh->fh_ox_id); /* we originated exch */
35779 ep = fc_exch_find(mp, xid);
35780 if (!ep) {
35781- atomic_inc(&mp->stats.xid_not_found);
35782+ atomic_inc_unchecked(&mp->stats.xid_not_found);
35783 reject = FC_RJT_OX_ID;
35784 goto out;
35785 }
35786@@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
35787 ep = fc_exch_find(mp, xid);
35788 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
35789 if (ep) {
35790- atomic_inc(&mp->stats.xid_busy);
35791+ atomic_inc_unchecked(&mp->stats.xid_busy);
35792 reject = FC_RJT_RX_ID;
35793 goto rel;
35794 }
35795@@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
35796 }
35797 xid = ep->xid; /* get our XID */
35798 } else if (!ep) {
35799- atomic_inc(&mp->stats.xid_not_found);
35800+ atomic_inc_unchecked(&mp->stats.xid_not_found);
35801 reject = FC_RJT_RX_ID; /* XID not found */
35802 goto out;
35803 }
35804@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
35805 } else {
35806 sp = &ep->seq;
35807 if (sp->id != fh->fh_seq_id) {
35808- atomic_inc(&mp->stats.seq_not_found);
35809+ atomic_inc_unchecked(&mp->stats.seq_not_found);
35810 if (f_ctl & FC_FC_END_SEQ) {
35811 /*
35812 * Update sequence_id based on incoming last
35813@@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
35814
35815 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
35816 if (!ep) {
35817- atomic_inc(&mp->stats.xid_not_found);
35818+ atomic_inc_unchecked(&mp->stats.xid_not_found);
35819 goto out;
35820 }
35821 if (ep->esb_stat & ESB_ST_COMPLETE) {
35822- atomic_inc(&mp->stats.xid_not_found);
35823+ atomic_inc_unchecked(&mp->stats.xid_not_found);
35824 goto rel;
35825 }
35826 if (ep->rxid == FC_XID_UNKNOWN)
35827 ep->rxid = ntohs(fh->fh_rx_id);
35828 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
35829- atomic_inc(&mp->stats.xid_not_found);
35830+ atomic_inc_unchecked(&mp->stats.xid_not_found);
35831 goto rel;
35832 }
35833 if (ep->did != ntoh24(fh->fh_s_id) &&
35834 ep->did != FC_FID_FLOGI) {
35835- atomic_inc(&mp->stats.xid_not_found);
35836+ atomic_inc_unchecked(&mp->stats.xid_not_found);
35837 goto rel;
35838 }
35839 sof = fr_sof(fp);
35840@@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
35841 sp->ssb_stat |= SSB_ST_RESP;
35842 sp->id = fh->fh_seq_id;
35843 } else if (sp->id != fh->fh_seq_id) {
35844- atomic_inc(&mp->stats.seq_not_found);
35845+ atomic_inc_unchecked(&mp->stats.seq_not_found);
35846 goto rel;
35847 }
35848
35849@@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
35850 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
35851
35852 if (!sp)
35853- atomic_inc(&mp->stats.xid_not_found);
35854+ atomic_inc_unchecked(&mp->stats.xid_not_found);
35855 else
35856- atomic_inc(&mp->stats.non_bls_resp);
35857+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
35858
35859 fc_frame_free(fp);
35860 }
35861diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
35862index db9238f..4378ed2 100644
35863--- a/drivers/scsi/libsas/sas_ata.c
35864+++ b/drivers/scsi/libsas/sas_ata.c
35865@@ -368,7 +368,7 @@ static struct ata_port_operations sas_sata_ops = {
35866 .postreset = ata_std_postreset,
35867 .error_handler = ata_std_error_handler,
35868 .post_internal_cmd = sas_ata_post_internal,
35869- .qc_defer = ata_std_qc_defer,
35870+ .qc_defer = ata_std_qc_defer,
35871 .qc_prep = ata_noop_qc_prep,
35872 .qc_issue = sas_ata_qc_issue,
35873 .qc_fill_rtf = sas_ata_qc_fill_rtf,
35874diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
35875index 825f930..ce42672 100644
35876--- a/drivers/scsi/lpfc/lpfc.h
35877+++ b/drivers/scsi/lpfc/lpfc.h
35878@@ -413,7 +413,7 @@ struct lpfc_vport {
35879 struct dentry *debug_nodelist;
35880 struct dentry *vport_debugfs_root;
35881 struct lpfc_debugfs_trc *disc_trc;
35882- atomic_t disc_trc_cnt;
35883+ atomic_unchecked_t disc_trc_cnt;
35884 #endif
35885 uint8_t stat_data_enabled;
35886 uint8_t stat_data_blocked;
35887@@ -821,8 +821,8 @@ struct lpfc_hba {
35888 struct timer_list fabric_block_timer;
35889 unsigned long bit_flags;
35890 #define FABRIC_COMANDS_BLOCKED 0
35891- atomic_t num_rsrc_err;
35892- atomic_t num_cmd_success;
35893+ atomic_unchecked_t num_rsrc_err;
35894+ atomic_unchecked_t num_cmd_success;
35895 unsigned long last_rsrc_error_time;
35896 unsigned long last_ramp_down_time;
35897 unsigned long last_ramp_up_time;
35898@@ -852,7 +852,7 @@ struct lpfc_hba {
35899
35900 struct dentry *debug_slow_ring_trc;
35901 struct lpfc_debugfs_trc *slow_ring_trc;
35902- atomic_t slow_ring_trc_cnt;
35903+ atomic_unchecked_t slow_ring_trc_cnt;
35904 /* iDiag debugfs sub-directory */
35905 struct dentry *idiag_root;
35906 struct dentry *idiag_pci_cfg;
35907diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
35908index 3587a3f..d45b81b 100644
35909--- a/drivers/scsi/lpfc/lpfc_debugfs.c
35910+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
35911@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
35912
35913 #include <linux/debugfs.h>
35914
35915-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
35916+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
35917 static unsigned long lpfc_debugfs_start_time = 0L;
35918
35919 /* iDiag */
35920@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
35921 lpfc_debugfs_enable = 0;
35922
35923 len = 0;
35924- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
35925+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
35926 (lpfc_debugfs_max_disc_trc - 1);
35927 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
35928 dtp = vport->disc_trc + i;
35929@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
35930 lpfc_debugfs_enable = 0;
35931
35932 len = 0;
35933- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
35934+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
35935 (lpfc_debugfs_max_slow_ring_trc - 1);
35936 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
35937 dtp = phba->slow_ring_trc + i;
35938@@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
35939 !vport || !vport->disc_trc)
35940 return;
35941
35942- index = atomic_inc_return(&vport->disc_trc_cnt) &
35943+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
35944 (lpfc_debugfs_max_disc_trc - 1);
35945 dtp = vport->disc_trc + index;
35946 dtp->fmt = fmt;
35947 dtp->data1 = data1;
35948 dtp->data2 = data2;
35949 dtp->data3 = data3;
35950- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
35951+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
35952 dtp->jif = jiffies;
35953 #endif
35954 return;
35955@@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
35956 !phba || !phba->slow_ring_trc)
35957 return;
35958
35959- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
35960+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
35961 (lpfc_debugfs_max_slow_ring_trc - 1);
35962 dtp = phba->slow_ring_trc + index;
35963 dtp->fmt = fmt;
35964 dtp->data1 = data1;
35965 dtp->data2 = data2;
35966 dtp->data3 = data3;
35967- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
35968+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
35969 dtp->jif = jiffies;
35970 #endif
35971 return;
35972@@ -4040,7 +4040,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
35973 "slow_ring buffer\n");
35974 goto debug_failed;
35975 }
35976- atomic_set(&phba->slow_ring_trc_cnt, 0);
35977+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
35978 memset(phba->slow_ring_trc, 0,
35979 (sizeof(struct lpfc_debugfs_trc) *
35980 lpfc_debugfs_max_slow_ring_trc));
35981@@ -4086,7 +4086,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
35982 "buffer\n");
35983 goto debug_failed;
35984 }
35985- atomic_set(&vport->disc_trc_cnt, 0);
35986+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
35987
35988 snprintf(name, sizeof(name), "discovery_trace");
35989 vport->debug_disc_trc =
35990diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
35991index dfea2da..8e17227 100644
35992--- a/drivers/scsi/lpfc/lpfc_init.c
35993+++ b/drivers/scsi/lpfc/lpfc_init.c
35994@@ -10145,8 +10145,10 @@ lpfc_init(void)
35995 printk(LPFC_COPYRIGHT "\n");
35996
35997 if (lpfc_enable_npiv) {
35998- lpfc_transport_functions.vport_create = lpfc_vport_create;
35999- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36000+ pax_open_kernel();
36001+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36002+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36003+ pax_close_kernel();
36004 }
36005 lpfc_transport_template =
36006 fc_attach_transport(&lpfc_transport_functions);
36007diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36008index c60f5d0..751535c 100644
36009--- a/drivers/scsi/lpfc/lpfc_scsi.c
36010+++ b/drivers/scsi/lpfc/lpfc_scsi.c
36011@@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36012 uint32_t evt_posted;
36013
36014 spin_lock_irqsave(&phba->hbalock, flags);
36015- atomic_inc(&phba->num_rsrc_err);
36016+ atomic_inc_unchecked(&phba->num_rsrc_err);
36017 phba->last_rsrc_error_time = jiffies;
36018
36019 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36020@@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36021 unsigned long flags;
36022 struct lpfc_hba *phba = vport->phba;
36023 uint32_t evt_posted;
36024- atomic_inc(&phba->num_cmd_success);
36025+ atomic_inc_unchecked(&phba->num_cmd_success);
36026
36027 if (vport->cfg_lun_queue_depth <= queue_depth)
36028 return;
36029@@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36030 unsigned long num_rsrc_err, num_cmd_success;
36031 int i;
36032
36033- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36034- num_cmd_success = atomic_read(&phba->num_cmd_success);
36035+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36036+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36037
36038 vports = lpfc_create_vport_work_array(phba);
36039 if (vports != NULL)
36040@@ -411,8 +411,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36041 }
36042 }
36043 lpfc_destroy_vport_work_array(phba, vports);
36044- atomic_set(&phba->num_rsrc_err, 0);
36045- atomic_set(&phba->num_cmd_success, 0);
36046+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
36047+ atomic_set_unchecked(&phba->num_cmd_success, 0);
36048 }
36049
36050 /**
36051@@ -446,8 +446,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36052 }
36053 }
36054 lpfc_destroy_vport_work_array(phba, vports);
36055- atomic_set(&phba->num_rsrc_err, 0);
36056- atomic_set(&phba->num_cmd_success, 0);
36057+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
36058+ atomic_set_unchecked(&phba->num_cmd_success, 0);
36059 }
36060
36061 /**
36062diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36063index ea8a0b4..812a124 100644
36064--- a/drivers/scsi/pmcraid.c
36065+++ b/drivers/scsi/pmcraid.c
36066@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36067 res->scsi_dev = scsi_dev;
36068 scsi_dev->hostdata = res;
36069 res->change_detected = 0;
36070- atomic_set(&res->read_failures, 0);
36071- atomic_set(&res->write_failures, 0);
36072+ atomic_set_unchecked(&res->read_failures, 0);
36073+ atomic_set_unchecked(&res->write_failures, 0);
36074 rc = 0;
36075 }
36076 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36077@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36078
36079 /* If this was a SCSI read/write command keep count of errors */
36080 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36081- atomic_inc(&res->read_failures);
36082+ atomic_inc_unchecked(&res->read_failures);
36083 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36084- atomic_inc(&res->write_failures);
36085+ atomic_inc_unchecked(&res->write_failures);
36086
36087 if (!RES_IS_GSCSI(res->cfg_entry) &&
36088 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36089@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
36090 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36091 * hrrq_id assigned here in queuecommand
36092 */
36093- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36094+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36095 pinstance->num_hrrq;
36096 cmd->cmd_done = pmcraid_io_done;
36097
36098@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
36099 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36100 * hrrq_id assigned here in queuecommand
36101 */
36102- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36103+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36104 pinstance->num_hrrq;
36105
36106 if (request_size) {
36107@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36108
36109 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36110 /* add resources only after host is added into system */
36111- if (!atomic_read(&pinstance->expose_resources))
36112+ if (!atomic_read_unchecked(&pinstance->expose_resources))
36113 return;
36114
36115 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36116@@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
36117 init_waitqueue_head(&pinstance->reset_wait_q);
36118
36119 atomic_set(&pinstance->outstanding_cmds, 0);
36120- atomic_set(&pinstance->last_message_id, 0);
36121- atomic_set(&pinstance->expose_resources, 0);
36122+ atomic_set_unchecked(&pinstance->last_message_id, 0);
36123+ atomic_set_unchecked(&pinstance->expose_resources, 0);
36124
36125 INIT_LIST_HEAD(&pinstance->free_res_q);
36126 INIT_LIST_HEAD(&pinstance->used_res_q);
36127@@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
36128 /* Schedule worker thread to handle CCN and take care of adding and
36129 * removing devices to OS
36130 */
36131- atomic_set(&pinstance->expose_resources, 1);
36132+ atomic_set_unchecked(&pinstance->expose_resources, 1);
36133 schedule_work(&pinstance->worker_q);
36134 return rc;
36135
36136diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
36137index ca496c7..9c791d5 100644
36138--- a/drivers/scsi/pmcraid.h
36139+++ b/drivers/scsi/pmcraid.h
36140@@ -748,7 +748,7 @@ struct pmcraid_instance {
36141 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
36142
36143 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
36144- atomic_t last_message_id;
36145+ atomic_unchecked_t last_message_id;
36146
36147 /* configuration table */
36148 struct pmcraid_config_table *cfg_table;
36149@@ -777,7 +777,7 @@ struct pmcraid_instance {
36150 atomic_t outstanding_cmds;
36151
36152 /* should add/delete resources to mid-layer now ?*/
36153- atomic_t expose_resources;
36154+ atomic_unchecked_t expose_resources;
36155
36156
36157
36158@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
36159 struct pmcraid_config_table_entry_ext cfg_entry_ext;
36160 };
36161 struct scsi_device *scsi_dev; /* Link scsi_device structure */
36162- atomic_t read_failures; /* count of failed READ commands */
36163- atomic_t write_failures; /* count of failed WRITE commands */
36164+ atomic_unchecked_t read_failures; /* count of failed READ commands */
36165+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
36166
36167 /* To indicate add/delete/modify during CCN */
36168 u8 change_detected;
36169diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
36170index af1003f..be55a75 100644
36171--- a/drivers/scsi/qla2xxx/qla_def.h
36172+++ b/drivers/scsi/qla2xxx/qla_def.h
36173@@ -2247,7 +2247,7 @@ struct isp_operations {
36174 int (*start_scsi) (srb_t *);
36175 int (*abort_isp) (struct scsi_qla_host *);
36176 int (*iospace_config)(struct qla_hw_data*);
36177-};
36178+} __no_const;
36179
36180 /* MSI-X Support *************************************************************/
36181
36182diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
36183index bfe6854..ceac088 100644
36184--- a/drivers/scsi/qla4xxx/ql4_def.h
36185+++ b/drivers/scsi/qla4xxx/ql4_def.h
36186@@ -261,7 +261,7 @@ struct ddb_entry {
36187 * (4000 only) */
36188 atomic_t relogin_timer; /* Max Time to wait for
36189 * relogin to complete */
36190- atomic_t relogin_retry_count; /* Num of times relogin has been
36191+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
36192 * retried */
36193 uint32_t default_time2wait; /* Default Min time between
36194 * relogins (+aens) */
36195diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
36196index ce6d3b7..73fac54 100644
36197--- a/drivers/scsi/qla4xxx/ql4_os.c
36198+++ b/drivers/scsi/qla4xxx/ql4_os.c
36199@@ -2178,12 +2178,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
36200 */
36201 if (!iscsi_is_session_online(cls_sess)) {
36202 /* Reset retry relogin timer */
36203- atomic_inc(&ddb_entry->relogin_retry_count);
36204+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
36205 DEBUG2(ql4_printk(KERN_INFO, ha,
36206 "%s: index[%d] relogin timed out-retrying"
36207 " relogin (%d), retry (%d)\n", __func__,
36208 ddb_entry->fw_ddb_index,
36209- atomic_read(&ddb_entry->relogin_retry_count),
36210+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
36211 ddb_entry->default_time2wait + 4));
36212 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
36213 atomic_set(&ddb_entry->retry_relogin_timer,
36214@@ -3953,7 +3953,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
36215
36216 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
36217 atomic_set(&ddb_entry->relogin_timer, 0);
36218- atomic_set(&ddb_entry->relogin_retry_count, 0);
36219+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
36220 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
36221 ddb_entry->default_relogin_timeout =
36222 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
36223diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
36224index 2aeb2e9..46e3925 100644
36225--- a/drivers/scsi/scsi.c
36226+++ b/drivers/scsi/scsi.c
36227@@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
36228 unsigned long timeout;
36229 int rtn = 0;
36230
36231- atomic_inc(&cmd->device->iorequest_cnt);
36232+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36233
36234 /* check if the device is still usable */
36235 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
36236diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
36237index b2c95db..227d74e 100644
36238--- a/drivers/scsi/scsi_lib.c
36239+++ b/drivers/scsi/scsi_lib.c
36240@@ -1411,7 +1411,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
36241 shost = sdev->host;
36242 scsi_init_cmd_errh(cmd);
36243 cmd->result = DID_NO_CONNECT << 16;
36244- atomic_inc(&cmd->device->iorequest_cnt);
36245+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36246
36247 /*
36248 * SCSI request completion path will do scsi_device_unbusy(),
36249@@ -1437,9 +1437,9 @@ static void scsi_softirq_done(struct request *rq)
36250
36251 INIT_LIST_HEAD(&cmd->eh_entry);
36252
36253- atomic_inc(&cmd->device->iodone_cnt);
36254+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
36255 if (cmd->result)
36256- atomic_inc(&cmd->device->ioerr_cnt);
36257+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
36258
36259 disposition = scsi_decide_disposition(cmd);
36260 if (disposition != SUCCESS &&
36261diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
36262index 04c2a27..9d8bd66 100644
36263--- a/drivers/scsi/scsi_sysfs.c
36264+++ b/drivers/scsi/scsi_sysfs.c
36265@@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
36266 char *buf) \
36267 { \
36268 struct scsi_device *sdev = to_scsi_device(dev); \
36269- unsigned long long count = atomic_read(&sdev->field); \
36270+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
36271 return snprintf(buf, 20, "0x%llx\n", count); \
36272 } \
36273 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
36274diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
36275index 84a1fdf..693b0d6 100644
36276--- a/drivers/scsi/scsi_tgt_lib.c
36277+++ b/drivers/scsi/scsi_tgt_lib.c
36278@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
36279 int err;
36280
36281 dprintk("%lx %u\n", uaddr, len);
36282- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
36283+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
36284 if (err) {
36285 /*
36286 * TODO: need to fixup sg_tablesize, max_segment_size,
36287diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
36288index f59d4a0..1d89407 100644
36289--- a/drivers/scsi/scsi_transport_fc.c
36290+++ b/drivers/scsi/scsi_transport_fc.c
36291@@ -484,7 +484,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
36292 * Netlink Infrastructure
36293 */
36294
36295-static atomic_t fc_event_seq;
36296+static atomic_unchecked_t fc_event_seq;
36297
36298 /**
36299 * fc_get_event_number - Obtain the next sequential FC event number
36300@@ -497,7 +497,7 @@ static atomic_t fc_event_seq;
36301 u32
36302 fc_get_event_number(void)
36303 {
36304- return atomic_add_return(1, &fc_event_seq);
36305+ return atomic_add_return_unchecked(1, &fc_event_seq);
36306 }
36307 EXPORT_SYMBOL(fc_get_event_number);
36308
36309@@ -645,7 +645,7 @@ static __init int fc_transport_init(void)
36310 {
36311 int error;
36312
36313- atomic_set(&fc_event_seq, 0);
36314+ atomic_set_unchecked(&fc_event_seq, 0);
36315
36316 error = transport_class_register(&fc_host_class);
36317 if (error)
36318@@ -835,7 +835,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
36319 char *cp;
36320
36321 *val = simple_strtoul(buf, &cp, 0);
36322- if ((*cp && (*cp != '\n')) || (*val < 0))
36323+ if (*cp && (*cp != '\n'))
36324 return -EINVAL;
36325 /*
36326 * Check for overflow; dev_loss_tmo is u32
36327diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
36328index e3e3c7d..ebdab62 100644
36329--- a/drivers/scsi/scsi_transport_iscsi.c
36330+++ b/drivers/scsi/scsi_transport_iscsi.c
36331@@ -79,7 +79,7 @@ struct iscsi_internal {
36332 struct transport_container session_cont;
36333 };
36334
36335-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
36336+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
36337 static struct workqueue_struct *iscsi_eh_timer_workq;
36338
36339 static DEFINE_IDA(iscsi_sess_ida);
36340@@ -1063,7 +1063,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
36341 int err;
36342
36343 ihost = shost->shost_data;
36344- session->sid = atomic_add_return(1, &iscsi_session_nr);
36345+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
36346
36347 if (target_id == ISCSI_MAX_TARGET) {
36348 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
36349@@ -2680,7 +2680,7 @@ static __init int iscsi_transport_init(void)
36350 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
36351 ISCSI_TRANSPORT_VERSION);
36352
36353- atomic_set(&iscsi_session_nr, 0);
36354+ atomic_set_unchecked(&iscsi_session_nr, 0);
36355
36356 err = class_register(&iscsi_transport_class);
36357 if (err)
36358diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
36359index 21a045e..ec89e03 100644
36360--- a/drivers/scsi/scsi_transport_srp.c
36361+++ b/drivers/scsi/scsi_transport_srp.c
36362@@ -33,7 +33,7 @@
36363 #include "scsi_transport_srp_internal.h"
36364
36365 struct srp_host_attrs {
36366- atomic_t next_port_id;
36367+ atomic_unchecked_t next_port_id;
36368 };
36369 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
36370
36371@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
36372 struct Scsi_Host *shost = dev_to_shost(dev);
36373 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
36374
36375- atomic_set(&srp_host->next_port_id, 0);
36376+ atomic_set_unchecked(&srp_host->next_port_id, 0);
36377 return 0;
36378 }
36379
36380@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
36381 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
36382 rport->roles = ids->roles;
36383
36384- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
36385+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
36386 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
36387
36388 transport_setup_device(&rport->dev);
36389diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
36390index eacd46b..e3f4d62 100644
36391--- a/drivers/scsi/sg.c
36392+++ b/drivers/scsi/sg.c
36393@@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
36394 sdp->disk->disk_name,
36395 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
36396 NULL,
36397- (char *)arg);
36398+ (char __user *)arg);
36399 case BLKTRACESTART:
36400 return blk_trace_startstop(sdp->device->request_queue, 1);
36401 case BLKTRACESTOP:
36402@@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
36403 const struct file_operations * fops;
36404 };
36405
36406-static struct sg_proc_leaf sg_proc_leaf_arr[] = {
36407+static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
36408 {"allow_dio", &adio_fops},
36409 {"debug", &debug_fops},
36410 {"def_reserved_size", &dressz_fops},
36411@@ -2332,7 +2332,7 @@ sg_proc_init(void)
36412 if (!sg_proc_sgp)
36413 return 1;
36414 for (k = 0; k < num_leaves; ++k) {
36415- struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
36416+ const struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
36417 umode_t mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO;
36418 proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops);
36419 }
36420diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
36421index f64250e..1ee3049 100644
36422--- a/drivers/spi/spi-dw-pci.c
36423+++ b/drivers/spi/spi-dw-pci.c
36424@@ -149,7 +149,7 @@ static int spi_resume(struct pci_dev *pdev)
36425 #define spi_resume NULL
36426 #endif
36427
36428-static const struct pci_device_id pci_ids[] __devinitdata = {
36429+static const struct pci_device_id pci_ids[] __devinitconst = {
36430 /* Intel MID platform SPI controller 0 */
36431 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
36432 {},
36433diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
36434index b2ccdea..84cde75 100644
36435--- a/drivers/spi/spi.c
36436+++ b/drivers/spi/spi.c
36437@@ -1024,7 +1024,7 @@ int spi_bus_unlock(struct spi_master *master)
36438 EXPORT_SYMBOL_GPL(spi_bus_unlock);
36439
36440 /* portable code must never pass more than 32 bytes */
36441-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
36442+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
36443
36444 static u8 *buf;
36445
36446diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
36447index 400df8c..065d4f4 100644
36448--- a/drivers/staging/octeon/ethernet-rx.c
36449+++ b/drivers/staging/octeon/ethernet-rx.c
36450@@ -420,11 +420,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
36451 /* Increment RX stats for virtual ports */
36452 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
36453 #ifdef CONFIG_64BIT
36454- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
36455- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
36456+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
36457+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
36458 #else
36459- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
36460- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
36461+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
36462+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
36463 #endif
36464 }
36465 netif_receive_skb(skb);
36466@@ -436,9 +436,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
36467 dev->name);
36468 */
36469 #ifdef CONFIG_64BIT
36470- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
36471+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
36472 #else
36473- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
36474+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
36475 #endif
36476 dev_kfree_skb_irq(skb);
36477 }
36478diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
36479index 9112cd8..92f8d51 100644
36480--- a/drivers/staging/octeon/ethernet.c
36481+++ b/drivers/staging/octeon/ethernet.c
36482@@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
36483 * since the RX tasklet also increments it.
36484 */
36485 #ifdef CONFIG_64BIT
36486- atomic64_add(rx_status.dropped_packets,
36487- (atomic64_t *)&priv->stats.rx_dropped);
36488+ atomic64_add_unchecked(rx_status.dropped_packets,
36489+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
36490 #else
36491- atomic_add(rx_status.dropped_packets,
36492- (atomic_t *)&priv->stats.rx_dropped);
36493+ atomic_add_unchecked(rx_status.dropped_packets,
36494+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
36495 #endif
36496 }
36497
36498diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
36499index 86308a0..feaa925 100644
36500--- a/drivers/staging/rtl8712/rtl871x_io.h
36501+++ b/drivers/staging/rtl8712/rtl871x_io.h
36502@@ -108,7 +108,7 @@ struct _io_ops {
36503 u8 *pmem);
36504 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
36505 u8 *pmem);
36506-};
36507+} __no_const;
36508
36509 struct io_req {
36510 struct list_head list;
36511diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
36512index c7b5e8b..783d6cb 100644
36513--- a/drivers/staging/sbe-2t3e3/netdev.c
36514+++ b/drivers/staging/sbe-2t3e3/netdev.c
36515@@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36516 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
36517
36518 if (rlen)
36519- if (copy_to_user(data, &resp, rlen))
36520+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
36521 return -EFAULT;
36522
36523 return 0;
36524diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
36525index 42cdafe..2769103 100644
36526--- a/drivers/staging/speakup/speakup_soft.c
36527+++ b/drivers/staging/speakup/speakup_soft.c
36528@@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
36529 break;
36530 } else if (!initialized) {
36531 if (*init) {
36532- ch = *init;
36533 init++;
36534 } else {
36535 initialized = 1;
36536 }
36537+ ch = *init;
36538 } else {
36539 ch = synth_buffer_getc();
36540 }
36541diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
36542index b8f8c48..1fc5025 100644
36543--- a/drivers/staging/usbip/usbip_common.h
36544+++ b/drivers/staging/usbip/usbip_common.h
36545@@ -289,7 +289,7 @@ struct usbip_device {
36546 void (*shutdown)(struct usbip_device *);
36547 void (*reset)(struct usbip_device *);
36548 void (*unusable)(struct usbip_device *);
36549- } eh_ops;
36550+ } __no_const eh_ops;
36551 };
36552
36553 /* usbip_common.c */
36554diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
36555index 88b3298..3783eee 100644
36556--- a/drivers/staging/usbip/vhci.h
36557+++ b/drivers/staging/usbip/vhci.h
36558@@ -88,7 +88,7 @@ struct vhci_hcd {
36559 unsigned resuming:1;
36560 unsigned long re_timeout;
36561
36562- atomic_t seqnum;
36563+ atomic_unchecked_t seqnum;
36564
36565 /*
36566 * NOTE:
36567diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
36568index 2ee97e2..0420b86 100644
36569--- a/drivers/staging/usbip/vhci_hcd.c
36570+++ b/drivers/staging/usbip/vhci_hcd.c
36571@@ -527,7 +527,7 @@ static void vhci_tx_urb(struct urb *urb)
36572 return;
36573 }
36574
36575- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
36576+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
36577 if (priv->seqnum == 0xffff)
36578 dev_info(&urb->dev->dev, "seqnum max\n");
36579
36580@@ -779,7 +779,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
36581 return -ENOMEM;
36582 }
36583
36584- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
36585+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
36586 if (unlink->seqnum == 0xffff)
36587 pr_info("seqnum max\n");
36588
36589@@ -969,7 +969,7 @@ static int vhci_start(struct usb_hcd *hcd)
36590 vdev->rhport = rhport;
36591 }
36592
36593- atomic_set(&vhci->seqnum, 0);
36594+ atomic_set_unchecked(&vhci->seqnum, 0);
36595 spin_lock_init(&vhci->lock);
36596
36597 hcd->power_budget = 0; /* no limit */
36598diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
36599index 3f511b4..d3dbc1e 100644
36600--- a/drivers/staging/usbip/vhci_rx.c
36601+++ b/drivers/staging/usbip/vhci_rx.c
36602@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
36603 if (!urb) {
36604 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
36605 pr_info("max seqnum %d\n",
36606- atomic_read(&the_controller->seqnum));
36607+ atomic_read_unchecked(&the_controller->seqnum));
36608 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
36609 return;
36610 }
36611diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
36612index 7735027..30eed13 100644
36613--- a/drivers/staging/vt6655/hostap.c
36614+++ b/drivers/staging/vt6655/hostap.c
36615@@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
36616 *
36617 */
36618
36619+static net_device_ops_no_const apdev_netdev_ops;
36620+
36621 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
36622 {
36623 PSDevice apdev_priv;
36624 struct net_device *dev = pDevice->dev;
36625 int ret;
36626- const struct net_device_ops apdev_netdev_ops = {
36627- .ndo_start_xmit = pDevice->tx_80211,
36628- };
36629
36630 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
36631
36632@@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
36633 *apdev_priv = *pDevice;
36634 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
36635
36636+ /* only half broken now */
36637+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
36638 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
36639
36640 pDevice->apdev->type = ARPHRD_IEEE80211;
36641diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
36642index 51b5adf..098e320 100644
36643--- a/drivers/staging/vt6656/hostap.c
36644+++ b/drivers/staging/vt6656/hostap.c
36645@@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
36646 *
36647 */
36648
36649+static net_device_ops_no_const apdev_netdev_ops;
36650+
36651 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
36652 {
36653 PSDevice apdev_priv;
36654 struct net_device *dev = pDevice->dev;
36655 int ret;
36656- const struct net_device_ops apdev_netdev_ops = {
36657- .ndo_start_xmit = pDevice->tx_80211,
36658- };
36659
36660 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
36661
36662@@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
36663 *apdev_priv = *pDevice;
36664 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
36665
36666+ /* only half broken now */
36667+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
36668 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
36669
36670 pDevice->apdev->type = ARPHRD_IEEE80211;
36671diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
36672index 7843dfd..3db105f 100644
36673--- a/drivers/staging/wlan-ng/hfa384x_usb.c
36674+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
36675@@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
36676
36677 struct usbctlx_completor {
36678 int (*complete) (struct usbctlx_completor *);
36679-};
36680+} __no_const;
36681
36682 static int
36683 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
36684diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
36685index 1ca66ea..76f1343 100644
36686--- a/drivers/staging/zcache/tmem.c
36687+++ b/drivers/staging/zcache/tmem.c
36688@@ -39,7 +39,7 @@
36689 * A tmem host implementation must use this function to register callbacks
36690 * for memory allocation.
36691 */
36692-static struct tmem_hostops tmem_hostops;
36693+static tmem_hostops_no_const tmem_hostops;
36694
36695 static void tmem_objnode_tree_init(void);
36696
36697@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
36698 * A tmem host implementation must use this function to register
36699 * callbacks for a page-accessible memory (PAM) implementation
36700 */
36701-static struct tmem_pamops tmem_pamops;
36702+static tmem_pamops_no_const tmem_pamops;
36703
36704 void tmem_register_pamops(struct tmem_pamops *m)
36705 {
36706diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
36707index ed147c4..94fc3c6 100644
36708--- a/drivers/staging/zcache/tmem.h
36709+++ b/drivers/staging/zcache/tmem.h
36710@@ -180,6 +180,7 @@ struct tmem_pamops {
36711 void (*new_obj)(struct tmem_obj *);
36712 int (*replace_in_obj)(void *, struct tmem_obj *);
36713 };
36714+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
36715 extern void tmem_register_pamops(struct tmem_pamops *m);
36716
36717 /* memory allocation methods provided by the host implementation */
36718@@ -189,6 +190,7 @@ struct tmem_hostops {
36719 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
36720 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
36721 };
36722+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
36723 extern void tmem_register_hostops(struct tmem_hostops *m);
36724
36725 /* core tmem accessor functions */
36726diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
36727index 97c74ee..7f6d77d 100644
36728--- a/drivers/target/iscsi/iscsi_target.c
36729+++ b/drivers/target/iscsi/iscsi_target.c
36730@@ -1361,7 +1361,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
36731 * outstanding_r2ts reaches zero, go ahead and send the delayed
36732 * TASK_ABORTED status.
36733 */
36734- if (atomic_read(&se_cmd->t_transport_aborted) != 0) {
36735+ if (atomic_read_unchecked(&se_cmd->t_transport_aborted) != 0) {
36736 if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
36737 if (--cmd->outstanding_r2ts < 1) {
36738 iscsit_stop_dataout_timer(cmd);
36739diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
36740index dcb0618..97e3d85 100644
36741--- a/drivers/target/target_core_tmr.c
36742+++ b/drivers/target/target_core_tmr.c
36743@@ -260,7 +260,7 @@ static void core_tmr_drain_task_list(
36744 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
36745 cmd->t_task_list_num,
36746 atomic_read(&cmd->t_task_cdbs_left),
36747- atomic_read(&cmd->t_task_cdbs_sent),
36748+ atomic_read_unchecked(&cmd->t_task_cdbs_sent),
36749 atomic_read(&cmd->t_transport_active),
36750 atomic_read(&cmd->t_transport_stop),
36751 atomic_read(&cmd->t_transport_sent));
36752@@ -291,7 +291,7 @@ static void core_tmr_drain_task_list(
36753 pr_debug("LUN_RESET: got t_transport_active = 1 for"
36754 " task: %p, t_fe_count: %d dev: %p\n", task,
36755 fe_count, dev);
36756- atomic_set(&cmd->t_transport_aborted, 1);
36757+ atomic_set_unchecked(&cmd->t_transport_aborted, 1);
36758 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
36759
36760 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
36761@@ -299,7 +299,7 @@ static void core_tmr_drain_task_list(
36762 }
36763 pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p,"
36764 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
36765- atomic_set(&cmd->t_transport_aborted, 1);
36766+ atomic_set_unchecked(&cmd->t_transport_aborted, 1);
36767 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
36768
36769 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
36770diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
36771index cd5cd95..5249d30 100644
36772--- a/drivers/target/target_core_transport.c
36773+++ b/drivers/target/target_core_transport.c
36774@@ -1330,7 +1330,7 @@ struct se_device *transport_add_device_to_core_hba(
36775 spin_lock_init(&dev->se_port_lock);
36776 spin_lock_init(&dev->se_tmr_lock);
36777 spin_lock_init(&dev->qf_cmd_lock);
36778- atomic_set(&dev->dev_ordered_id, 0);
36779+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
36780
36781 se_dev_set_default_attribs(dev, dev_limits);
36782
36783@@ -1517,7 +1517,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
36784 * Used to determine when ORDERED commands should go from
36785 * Dormant to Active status.
36786 */
36787- cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
36788+ cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
36789 smp_mb__after_atomic_inc();
36790 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
36791 cmd->se_ordered_id, cmd->sam_task_attr,
36792@@ -1862,7 +1862,7 @@ static void transport_generic_request_failure(struct se_cmd *cmd)
36793 " t_transport_active: %d t_transport_stop: %d"
36794 " t_transport_sent: %d\n", cmd->t_task_list_num,
36795 atomic_read(&cmd->t_task_cdbs_left),
36796- atomic_read(&cmd->t_task_cdbs_sent),
36797+ atomic_read_unchecked(&cmd->t_task_cdbs_sent),
36798 atomic_read(&cmd->t_task_cdbs_ex_left),
36799 atomic_read(&cmd->t_transport_active),
36800 atomic_read(&cmd->t_transport_stop),
36801@@ -2121,9 +2121,9 @@ check_depth:
36802 cmd = task->task_se_cmd;
36803 spin_lock_irqsave(&cmd->t_state_lock, flags);
36804 task->task_flags |= (TF_ACTIVE | TF_SENT);
36805- atomic_inc(&cmd->t_task_cdbs_sent);
36806+ atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
36807
36808- if (atomic_read(&cmd->t_task_cdbs_sent) ==
36809+ if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
36810 cmd->t_task_list_num)
36811 atomic_set(&cmd->t_transport_sent, 1);
36812
36813@@ -4348,7 +4348,7 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
36814 atomic_set(&cmd->transport_lun_stop, 0);
36815 }
36816 if (!atomic_read(&cmd->t_transport_active) ||
36817- atomic_read(&cmd->t_transport_aborted)) {
36818+ atomic_read_unchecked(&cmd->t_transport_aborted)) {
36819 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
36820 return false;
36821 }
36822@@ -4597,7 +4597,7 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
36823 {
36824 int ret = 0;
36825
36826- if (atomic_read(&cmd->t_transport_aborted) != 0) {
36827+ if (atomic_read_unchecked(&cmd->t_transport_aborted) != 0) {
36828 if (!send_status ||
36829 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
36830 return 1;
36831@@ -4634,7 +4634,7 @@ void transport_send_task_abort(struct se_cmd *cmd)
36832 */
36833 if (cmd->data_direction == DMA_TO_DEVICE) {
36834 if (cmd->se_tfo->write_pending_status(cmd) != 0) {
36835- atomic_inc(&cmd->t_transport_aborted);
36836+ atomic_inc_unchecked(&cmd->t_transport_aborted);
36837 smp_mb__after_atomic_inc();
36838 }
36839 }
36840diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
36841index b9040be..e3f5aab 100644
36842--- a/drivers/tty/hvc/hvcs.c
36843+++ b/drivers/tty/hvc/hvcs.c
36844@@ -83,6 +83,7 @@
36845 #include <asm/hvcserver.h>
36846 #include <asm/uaccess.h>
36847 #include <asm/vio.h>
36848+#include <asm/local.h>
36849
36850 /*
36851 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
36852@@ -270,7 +271,7 @@ struct hvcs_struct {
36853 unsigned int index;
36854
36855 struct tty_struct *tty;
36856- int open_count;
36857+ local_t open_count;
36858
36859 /*
36860 * Used to tell the driver kernel_thread what operations need to take
36861@@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
36862
36863 spin_lock_irqsave(&hvcsd->lock, flags);
36864
36865- if (hvcsd->open_count > 0) {
36866+ if (local_read(&hvcsd->open_count) > 0) {
36867 spin_unlock_irqrestore(&hvcsd->lock, flags);
36868 printk(KERN_INFO "HVCS: vterm state unchanged. "
36869 "The hvcs device node is still in use.\n");
36870@@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
36871 if ((retval = hvcs_partner_connect(hvcsd)))
36872 goto error_release;
36873
36874- hvcsd->open_count = 1;
36875+ local_set(&hvcsd->open_count, 1);
36876 hvcsd->tty = tty;
36877 tty->driver_data = hvcsd;
36878
36879@@ -1179,7 +1180,7 @@ fast_open:
36880
36881 spin_lock_irqsave(&hvcsd->lock, flags);
36882 kref_get(&hvcsd->kref);
36883- hvcsd->open_count++;
36884+ local_inc(&hvcsd->open_count);
36885 hvcsd->todo_mask |= HVCS_SCHED_READ;
36886 spin_unlock_irqrestore(&hvcsd->lock, flags);
36887
36888@@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
36889 hvcsd = tty->driver_data;
36890
36891 spin_lock_irqsave(&hvcsd->lock, flags);
36892- if (--hvcsd->open_count == 0) {
36893+ if (local_dec_and_test(&hvcsd->open_count)) {
36894
36895 vio_disable_interrupts(hvcsd->vdev);
36896
36897@@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
36898 free_irq(irq, hvcsd);
36899 kref_put(&hvcsd->kref, destroy_hvcs_struct);
36900 return;
36901- } else if (hvcsd->open_count < 0) {
36902+ } else if (local_read(&hvcsd->open_count) < 0) {
36903 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
36904 " is missmanaged.\n",
36905- hvcsd->vdev->unit_address, hvcsd->open_count);
36906+ hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
36907 }
36908
36909 spin_unlock_irqrestore(&hvcsd->lock, flags);
36910@@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struct * tty)
36911
36912 spin_lock_irqsave(&hvcsd->lock, flags);
36913 /* Preserve this so that we know how many kref refs to put */
36914- temp_open_count = hvcsd->open_count;
36915+ temp_open_count = local_read(&hvcsd->open_count);
36916
36917 /*
36918 * Don't kref put inside the spinlock because the destruction
36919@@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struct * tty)
36920 hvcsd->tty->driver_data = NULL;
36921 hvcsd->tty = NULL;
36922
36923- hvcsd->open_count = 0;
36924+ local_set(&hvcsd->open_count, 0);
36925
36926 /* This will drop any buffered data on the floor which is OK in a hangup
36927 * scenario. */
36928@@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct *tty,
36929 * the middle of a write operation? This is a crummy place to do this
36930 * but we want to keep it all in the spinlock.
36931 */
36932- if (hvcsd->open_count <= 0) {
36933+ if (local_read(&hvcsd->open_count) <= 0) {
36934 spin_unlock_irqrestore(&hvcsd->lock, flags);
36935 return -ENODEV;
36936 }
36937@@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_struct *tty)
36938 {
36939 struct hvcs_struct *hvcsd = tty->driver_data;
36940
36941- if (!hvcsd || hvcsd->open_count <= 0)
36942+ if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
36943 return 0;
36944
36945 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
36946diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
36947index ef92869..f4ebd88 100644
36948--- a/drivers/tty/ipwireless/tty.c
36949+++ b/drivers/tty/ipwireless/tty.c
36950@@ -29,6 +29,7 @@
36951 #include <linux/tty_driver.h>
36952 #include <linux/tty_flip.h>
36953 #include <linux/uaccess.h>
36954+#include <asm/local.h>
36955
36956 #include "tty.h"
36957 #include "network.h"
36958@@ -51,7 +52,7 @@ struct ipw_tty {
36959 int tty_type;
36960 struct ipw_network *network;
36961 struct tty_struct *linux_tty;
36962- int open_count;
36963+ local_t open_count;
36964 unsigned int control_lines;
36965 struct mutex ipw_tty_mutex;
36966 int tx_bytes_queued;
36967@@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
36968 mutex_unlock(&tty->ipw_tty_mutex);
36969 return -ENODEV;
36970 }
36971- if (tty->open_count == 0)
36972+ if (local_read(&tty->open_count) == 0)
36973 tty->tx_bytes_queued = 0;
36974
36975- tty->open_count++;
36976+ local_inc(&tty->open_count);
36977
36978 tty->linux_tty = linux_tty;
36979 linux_tty->driver_data = tty;
36980@@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
36981
36982 static void do_ipw_close(struct ipw_tty *tty)
36983 {
36984- tty->open_count--;
36985-
36986- if (tty->open_count == 0) {
36987+ if (local_dec_return(&tty->open_count) == 0) {
36988 struct tty_struct *linux_tty = tty->linux_tty;
36989
36990 if (linux_tty != NULL) {
36991@@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
36992 return;
36993
36994 mutex_lock(&tty->ipw_tty_mutex);
36995- if (tty->open_count == 0) {
36996+ if (local_read(&tty->open_count) == 0) {
36997 mutex_unlock(&tty->ipw_tty_mutex);
36998 return;
36999 }
37000@@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37001 return;
37002 }
37003
37004- if (!tty->open_count) {
37005+ if (!local_read(&tty->open_count)) {
37006 mutex_unlock(&tty->ipw_tty_mutex);
37007 return;
37008 }
37009@@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37010 return -ENODEV;
37011
37012 mutex_lock(&tty->ipw_tty_mutex);
37013- if (!tty->open_count) {
37014+ if (!local_read(&tty->open_count)) {
37015 mutex_unlock(&tty->ipw_tty_mutex);
37016 return -EINVAL;
37017 }
37018@@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
37019 if (!tty)
37020 return -ENODEV;
37021
37022- if (!tty->open_count)
37023+ if (!local_read(&tty->open_count))
37024 return -EINVAL;
37025
37026 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
37027@@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
37028 if (!tty)
37029 return 0;
37030
37031- if (!tty->open_count)
37032+ if (!local_read(&tty->open_count))
37033 return 0;
37034
37035 return tty->tx_bytes_queued;
37036@@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
37037 if (!tty)
37038 return -ENODEV;
37039
37040- if (!tty->open_count)
37041+ if (!local_read(&tty->open_count))
37042 return -EINVAL;
37043
37044 return get_control_lines(tty);
37045@@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
37046 if (!tty)
37047 return -ENODEV;
37048
37049- if (!tty->open_count)
37050+ if (!local_read(&tty->open_count))
37051 return -EINVAL;
37052
37053 return set_control_lines(tty, set, clear);
37054@@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
37055 if (!tty)
37056 return -ENODEV;
37057
37058- if (!tty->open_count)
37059+ if (!local_read(&tty->open_count))
37060 return -EINVAL;
37061
37062 /* FIXME: Exactly how is the tty object locked here .. */
37063@@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
37064 against a parallel ioctl etc */
37065 mutex_lock(&ttyj->ipw_tty_mutex);
37066 }
37067- while (ttyj->open_count)
37068+ while (local_read(&ttyj->open_count))
37069 do_ipw_close(ttyj);
37070 ipwireless_disassociate_network_ttys(network,
37071 ttyj->channel_idx);
37072diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
37073index fc7bbba..9527e93 100644
37074--- a/drivers/tty/n_gsm.c
37075+++ b/drivers/tty/n_gsm.c
37076@@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
37077 kref_init(&dlci->ref);
37078 mutex_init(&dlci->mutex);
37079 dlci->fifo = &dlci->_fifo;
37080- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
37081+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
37082 kfree(dlci);
37083 return NULL;
37084 }
37085diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
37086index d2256d0..97476fa 100644
37087--- a/drivers/tty/n_tty.c
37088+++ b/drivers/tty/n_tty.c
37089@@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
37090 {
37091 *ops = tty_ldisc_N_TTY;
37092 ops->owner = NULL;
37093- ops->refcount = ops->flags = 0;
37094+ atomic_set(&ops->refcount, 0);
37095+ ops->flags = 0;
37096 }
37097 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
37098diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
37099index d8653ab..f8afd9d 100644
37100--- a/drivers/tty/pty.c
37101+++ b/drivers/tty/pty.c
37102@@ -765,8 +765,10 @@ static void __init unix98_pty_init(void)
37103 register_sysctl_table(pty_root_table);
37104
37105 /* Now create the /dev/ptmx special device */
37106+ pax_open_kernel();
37107 tty_default_fops(&ptmx_fops);
37108- ptmx_fops.open = ptmx_open;
37109+ *(void **)&ptmx_fops.open = ptmx_open;
37110+ pax_close_kernel();
37111
37112 cdev_init(&ptmx_cdev, &ptmx_fops);
37113 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
37114diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
37115index 2b42a01..32a2ed3 100644
37116--- a/drivers/tty/serial/kgdboc.c
37117+++ b/drivers/tty/serial/kgdboc.c
37118@@ -24,8 +24,9 @@
37119 #define MAX_CONFIG_LEN 40
37120
37121 static struct kgdb_io kgdboc_io_ops;
37122+static struct kgdb_io kgdboc_io_ops_console;
37123
37124-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37125+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
37126 static int configured = -1;
37127
37128 static char config[MAX_CONFIG_LEN];
37129@@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
37130 kgdboc_unregister_kbd();
37131 if (configured == 1)
37132 kgdb_unregister_io_module(&kgdboc_io_ops);
37133+ else if (configured == 2)
37134+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
37135 }
37136
37137 static int configure_kgdboc(void)
37138@@ -157,13 +160,13 @@ static int configure_kgdboc(void)
37139 int err;
37140 char *cptr = config;
37141 struct console *cons;
37142+ int is_console = 0;
37143
37144 err = kgdboc_option_setup(config);
37145 if (err || !strlen(config) || isspace(config[0]))
37146 goto noconfig;
37147
37148 err = -ENODEV;
37149- kgdboc_io_ops.is_console = 0;
37150 kgdb_tty_driver = NULL;
37151
37152 kgdboc_use_kms = 0;
37153@@ -184,7 +187,7 @@ static int configure_kgdboc(void)
37154 int idx;
37155 if (cons->device && cons->device(cons, &idx) == p &&
37156 idx == tty_line) {
37157- kgdboc_io_ops.is_console = 1;
37158+ is_console = 1;
37159 break;
37160 }
37161 cons = cons->next;
37162@@ -194,12 +197,16 @@ static int configure_kgdboc(void)
37163 kgdb_tty_line = tty_line;
37164
37165 do_register:
37166- err = kgdb_register_io_module(&kgdboc_io_ops);
37167+ if (is_console) {
37168+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
37169+ configured = 2;
37170+ } else {
37171+ err = kgdb_register_io_module(&kgdboc_io_ops);
37172+ configured = 1;
37173+ }
37174 if (err)
37175 goto noconfig;
37176
37177- configured = 1;
37178-
37179 return 0;
37180
37181 noconfig:
37182@@ -213,7 +220,7 @@ noconfig:
37183 static int __init init_kgdboc(void)
37184 {
37185 /* Already configured? */
37186- if (configured == 1)
37187+ if (configured >= 1)
37188 return 0;
37189
37190 return configure_kgdboc();
37191@@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
37192 if (config[len - 1] == '\n')
37193 config[len - 1] = '\0';
37194
37195- if (configured == 1)
37196+ if (configured >= 1)
37197 cleanup_kgdboc();
37198
37199 /* Go and configure with the new params. */
37200@@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
37201 .post_exception = kgdboc_post_exp_handler,
37202 };
37203
37204+static struct kgdb_io kgdboc_io_ops_console = {
37205+ .name = "kgdboc",
37206+ .read_char = kgdboc_get_char,
37207+ .write_char = kgdboc_put_char,
37208+ .pre_exception = kgdboc_pre_exp_handler,
37209+ .post_exception = kgdboc_post_exp_handler,
37210+ .is_console = 1
37211+};
37212+
37213 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
37214 /* This is only available if kgdboc is a built in for early debugging */
37215 static int __init kgdboc_early_init(char *opt)
37216diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
37217index e41b9bb..84002fb 100644
37218--- a/drivers/tty/tty_io.c
37219+++ b/drivers/tty/tty_io.c
37220@@ -3291,7 +3291,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
37221
37222 void tty_default_fops(struct file_operations *fops)
37223 {
37224- *fops = tty_fops;
37225+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
37226 }
37227
37228 /*
37229diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
37230index 24b95db..9c078d0 100644
37231--- a/drivers/tty/tty_ldisc.c
37232+++ b/drivers/tty/tty_ldisc.c
37233@@ -57,7 +57,7 @@ static void put_ldisc(struct tty_ldisc *ld)
37234 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
37235 struct tty_ldisc_ops *ldo = ld->ops;
37236
37237- ldo->refcount--;
37238+ atomic_dec(&ldo->refcount);
37239 module_put(ldo->owner);
37240 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37241
37242@@ -92,7 +92,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
37243 spin_lock_irqsave(&tty_ldisc_lock, flags);
37244 tty_ldiscs[disc] = new_ldisc;
37245 new_ldisc->num = disc;
37246- new_ldisc->refcount = 0;
37247+ atomic_set(&new_ldisc->refcount, 0);
37248 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37249
37250 return ret;
37251@@ -120,7 +120,7 @@ int tty_unregister_ldisc(int disc)
37252 return -EINVAL;
37253
37254 spin_lock_irqsave(&tty_ldisc_lock, flags);
37255- if (tty_ldiscs[disc]->refcount)
37256+ if (atomic_read(&tty_ldiscs[disc]->refcount))
37257 ret = -EBUSY;
37258 else
37259 tty_ldiscs[disc] = NULL;
37260@@ -141,7 +141,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
37261 if (ldops) {
37262 ret = ERR_PTR(-EAGAIN);
37263 if (try_module_get(ldops->owner)) {
37264- ldops->refcount++;
37265+ atomic_inc(&ldops->refcount);
37266 ret = ldops;
37267 }
37268 }
37269@@ -154,7 +154,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
37270 unsigned long flags;
37271
37272 spin_lock_irqsave(&tty_ldisc_lock, flags);
37273- ldops->refcount--;
37274+ atomic_dec(&ldops->refcount);
37275 module_put(ldops->owner);
37276 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37277 }
37278diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
37279index a605549..6bd3c96 100644
37280--- a/drivers/tty/vt/keyboard.c
37281+++ b/drivers/tty/vt/keyboard.c
37282@@ -657,6 +657,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
37283 kbd->kbdmode == VC_OFF) &&
37284 value != KVAL(K_SAK))
37285 return; /* SAK is allowed even in raw mode */
37286+
37287+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
37288+ {
37289+ void *func = fn_handler[value];
37290+ if (func == fn_show_state || func == fn_show_ptregs ||
37291+ func == fn_show_mem)
37292+ return;
37293+ }
37294+#endif
37295+
37296 fn_handler[value](vc);
37297 }
37298
37299diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
37300index 65447c5..0526f0a 100644
37301--- a/drivers/tty/vt/vt_ioctl.c
37302+++ b/drivers/tty/vt/vt_ioctl.c
37303@@ -207,9 +207,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
37304 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
37305 return -EFAULT;
37306
37307- if (!capable(CAP_SYS_TTY_CONFIG))
37308- perm = 0;
37309-
37310 switch (cmd) {
37311 case KDGKBENT:
37312 key_map = key_maps[s];
37313@@ -221,6 +218,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
37314 val = (i ? K_HOLE : K_NOSUCHMAP);
37315 return put_user(val, &user_kbe->kb_value);
37316 case KDSKBENT:
37317+ if (!capable(CAP_SYS_TTY_CONFIG))
37318+ perm = 0;
37319+
37320 if (!perm)
37321 return -EPERM;
37322 if (!i && v == K_NOSUCHMAP) {
37323@@ -322,9 +322,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
37324 int i, j, k;
37325 int ret;
37326
37327- if (!capable(CAP_SYS_TTY_CONFIG))
37328- perm = 0;
37329-
37330 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
37331 if (!kbs) {
37332 ret = -ENOMEM;
37333@@ -358,6 +355,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
37334 kfree(kbs);
37335 return ((p && *p) ? -EOVERFLOW : 0);
37336 case KDSKBSENT:
37337+ if (!capable(CAP_SYS_TTY_CONFIG))
37338+ perm = 0;
37339+
37340 if (!perm) {
37341 ret = -EPERM;
37342 goto reterr;
37343diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
37344index a783d53..cb30d94 100644
37345--- a/drivers/uio/uio.c
37346+++ b/drivers/uio/uio.c
37347@@ -25,6 +25,7 @@
37348 #include <linux/kobject.h>
37349 #include <linux/cdev.h>
37350 #include <linux/uio_driver.h>
37351+#include <asm/local.h>
37352
37353 #define UIO_MAX_DEVICES (1U << MINORBITS)
37354
37355@@ -32,10 +33,10 @@ struct uio_device {
37356 struct module *owner;
37357 struct device *dev;
37358 int minor;
37359- atomic_t event;
37360+ atomic_unchecked_t event;
37361 struct fasync_struct *async_queue;
37362 wait_queue_head_t wait;
37363- int vma_count;
37364+ local_t vma_count;
37365 struct uio_info *info;
37366 struct kobject *map_dir;
37367 struct kobject *portio_dir;
37368@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
37369 struct device_attribute *attr, char *buf)
37370 {
37371 struct uio_device *idev = dev_get_drvdata(dev);
37372- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
37373+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
37374 }
37375
37376 static struct device_attribute uio_class_attributes[] = {
37377@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
37378 {
37379 struct uio_device *idev = info->uio_dev;
37380
37381- atomic_inc(&idev->event);
37382+ atomic_inc_unchecked(&idev->event);
37383 wake_up_interruptible(&idev->wait);
37384 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
37385 }
37386@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
37387 }
37388
37389 listener->dev = idev;
37390- listener->event_count = atomic_read(&idev->event);
37391+ listener->event_count = atomic_read_unchecked(&idev->event);
37392 filep->private_data = listener;
37393
37394 if (idev->info->open) {
37395@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
37396 return -EIO;
37397
37398 poll_wait(filep, &idev->wait, wait);
37399- if (listener->event_count != atomic_read(&idev->event))
37400+ if (listener->event_count != atomic_read_unchecked(&idev->event))
37401 return POLLIN | POLLRDNORM;
37402 return 0;
37403 }
37404@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
37405 do {
37406 set_current_state(TASK_INTERRUPTIBLE);
37407
37408- event_count = atomic_read(&idev->event);
37409+ event_count = atomic_read_unchecked(&idev->event);
37410 if (event_count != listener->event_count) {
37411 if (copy_to_user(buf, &event_count, count))
37412 retval = -EFAULT;
37413@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
37414 static void uio_vma_open(struct vm_area_struct *vma)
37415 {
37416 struct uio_device *idev = vma->vm_private_data;
37417- idev->vma_count++;
37418+ local_inc(&idev->vma_count);
37419 }
37420
37421 static void uio_vma_close(struct vm_area_struct *vma)
37422 {
37423 struct uio_device *idev = vma->vm_private_data;
37424- idev->vma_count--;
37425+ local_dec(&idev->vma_count);
37426 }
37427
37428 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
37429@@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
37430 idev->owner = owner;
37431 idev->info = info;
37432 init_waitqueue_head(&idev->wait);
37433- atomic_set(&idev->event, 0);
37434+ atomic_set_unchecked(&idev->event, 0);
37435
37436 ret = uio_get_minor(idev);
37437 if (ret)
37438diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
37439index 98b89fe..aff824e 100644
37440--- a/drivers/usb/atm/cxacru.c
37441+++ b/drivers/usb/atm/cxacru.c
37442@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
37443 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
37444 if (ret < 2)
37445 return -EINVAL;
37446- if (index < 0 || index > 0x7f)
37447+ if (index > 0x7f)
37448 return -EINVAL;
37449 pos += tmp;
37450
37451diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
37452index d3448ca..d2864ca 100644
37453--- a/drivers/usb/atm/usbatm.c
37454+++ b/drivers/usb/atm/usbatm.c
37455@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
37456 if (printk_ratelimit())
37457 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
37458 __func__, vpi, vci);
37459- atomic_inc(&vcc->stats->rx_err);
37460+ atomic_inc_unchecked(&vcc->stats->rx_err);
37461 return;
37462 }
37463
37464@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
37465 if (length > ATM_MAX_AAL5_PDU) {
37466 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
37467 __func__, length, vcc);
37468- atomic_inc(&vcc->stats->rx_err);
37469+ atomic_inc_unchecked(&vcc->stats->rx_err);
37470 goto out;
37471 }
37472
37473@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
37474 if (sarb->len < pdu_length) {
37475 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
37476 __func__, pdu_length, sarb->len, vcc);
37477- atomic_inc(&vcc->stats->rx_err);
37478+ atomic_inc_unchecked(&vcc->stats->rx_err);
37479 goto out;
37480 }
37481
37482 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
37483 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
37484 __func__, vcc);
37485- atomic_inc(&vcc->stats->rx_err);
37486+ atomic_inc_unchecked(&vcc->stats->rx_err);
37487 goto out;
37488 }
37489
37490@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
37491 if (printk_ratelimit())
37492 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
37493 __func__, length);
37494- atomic_inc(&vcc->stats->rx_drop);
37495+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37496 goto out;
37497 }
37498
37499@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
37500
37501 vcc->push(vcc, skb);
37502
37503- atomic_inc(&vcc->stats->rx);
37504+ atomic_inc_unchecked(&vcc->stats->rx);
37505 out:
37506 skb_trim(sarb, 0);
37507 }
37508@@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
37509 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
37510
37511 usbatm_pop(vcc, skb);
37512- atomic_inc(&vcc->stats->tx);
37513+ atomic_inc_unchecked(&vcc->stats->tx);
37514
37515 skb = skb_dequeue(&instance->sndqueue);
37516 }
37517@@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
37518 if (!left--)
37519 return sprintf(page,
37520 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
37521- atomic_read(&atm_dev->stats.aal5.tx),
37522- atomic_read(&atm_dev->stats.aal5.tx_err),
37523- atomic_read(&atm_dev->stats.aal5.rx),
37524- atomic_read(&atm_dev->stats.aal5.rx_err),
37525- atomic_read(&atm_dev->stats.aal5.rx_drop));
37526+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
37527+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
37528+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
37529+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
37530+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
37531
37532 if (!left--) {
37533 if (instance->disconnected)
37534diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
37535index d956965..4179a77 100644
37536--- a/drivers/usb/core/devices.c
37537+++ b/drivers/usb/core/devices.c
37538@@ -126,7 +126,7 @@ static const char format_endpt[] =
37539 * time it gets called.
37540 */
37541 static struct device_connect_event {
37542- atomic_t count;
37543+ atomic_unchecked_t count;
37544 wait_queue_head_t wait;
37545 } device_event = {
37546 .count = ATOMIC_INIT(1),
37547@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
37548
37549 void usbfs_conn_disc_event(void)
37550 {
37551- atomic_add(2, &device_event.count);
37552+ atomic_add_unchecked(2, &device_event.count);
37553 wake_up(&device_event.wait);
37554 }
37555
37556@@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
37557
37558 poll_wait(file, &device_event.wait, wait);
37559
37560- event_count = atomic_read(&device_event.count);
37561+ event_count = atomic_read_unchecked(&device_event.count);
37562 if (file->f_version != event_count) {
37563 file->f_version = event_count;
37564 return POLLIN | POLLRDNORM;
37565diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
37566index b3bdfed..a9460e0 100644
37567--- a/drivers/usb/core/message.c
37568+++ b/drivers/usb/core/message.c
37569@@ -869,8 +869,8 @@ char *usb_cache_string(struct usb_device *udev, int index)
37570 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
37571 if (buf) {
37572 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
37573- if (len > 0) {
37574- smallbuf = kmalloc(++len, GFP_NOIO);
37575+ if (len++ > 0) {
37576+ smallbuf = kmalloc(len, GFP_NOIO);
37577 if (!smallbuf)
37578 return buf;
37579 memcpy(smallbuf, buf, len);
37580diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
37581index 1fc8f12..20647c1 100644
37582--- a/drivers/usb/early/ehci-dbgp.c
37583+++ b/drivers/usb/early/ehci-dbgp.c
37584@@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
37585
37586 #ifdef CONFIG_KGDB
37587 static struct kgdb_io kgdbdbgp_io_ops;
37588-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
37589+static struct kgdb_io kgdbdbgp_io_ops_console;
37590+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
37591 #else
37592 #define dbgp_kgdb_mode (0)
37593 #endif
37594@@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
37595 .write_char = kgdbdbgp_write_char,
37596 };
37597
37598+static struct kgdb_io kgdbdbgp_io_ops_console = {
37599+ .name = "kgdbdbgp",
37600+ .read_char = kgdbdbgp_read_char,
37601+ .write_char = kgdbdbgp_write_char,
37602+ .is_console = 1
37603+};
37604+
37605 static int kgdbdbgp_wait_time;
37606
37607 static int __init kgdbdbgp_parse_config(char *str)
37608@@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
37609 ptr++;
37610 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
37611 }
37612- kgdb_register_io_module(&kgdbdbgp_io_ops);
37613- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
37614+ if (early_dbgp_console.index != -1)
37615+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
37616+ else
37617+ kgdb_register_io_module(&kgdbdbgp_io_ops);
37618
37619 return 0;
37620 }
37621diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
37622index d6bea3e..60b250e 100644
37623--- a/drivers/usb/wusbcore/wa-hc.h
37624+++ b/drivers/usb/wusbcore/wa-hc.h
37625@@ -192,7 +192,7 @@ struct wahc {
37626 struct list_head xfer_delayed_list;
37627 spinlock_t xfer_list_lock;
37628 struct work_struct xfer_work;
37629- atomic_t xfer_id_count;
37630+ atomic_unchecked_t xfer_id_count;
37631 };
37632
37633
37634@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
37635 INIT_LIST_HEAD(&wa->xfer_delayed_list);
37636 spin_lock_init(&wa->xfer_list_lock);
37637 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
37638- atomic_set(&wa->xfer_id_count, 1);
37639+ atomic_set_unchecked(&wa->xfer_id_count, 1);
37640 }
37641
37642 /**
37643diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
37644index 57c01ab..8a05959 100644
37645--- a/drivers/usb/wusbcore/wa-xfer.c
37646+++ b/drivers/usb/wusbcore/wa-xfer.c
37647@@ -296,7 +296,7 @@ out:
37648 */
37649 static void wa_xfer_id_init(struct wa_xfer *xfer)
37650 {
37651- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
37652+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
37653 }
37654
37655 /*
37656diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
37657index c14c42b..f955cc2 100644
37658--- a/drivers/vhost/vhost.c
37659+++ b/drivers/vhost/vhost.c
37660@@ -629,7 +629,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
37661 return 0;
37662 }
37663
37664-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
37665+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
37666 {
37667 struct file *eventfp, *filep = NULL,
37668 *pollstart = NULL, *pollstop = NULL;
37669diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
37670index b0b2ac3..89a4399 100644
37671--- a/drivers/video/aty/aty128fb.c
37672+++ b/drivers/video/aty/aty128fb.c
37673@@ -148,7 +148,7 @@ enum {
37674 };
37675
37676 /* Must match above enum */
37677-static const char *r128_family[] __devinitdata = {
37678+static const char *r128_family[] __devinitconst = {
37679 "AGP",
37680 "PCI",
37681 "PRO AGP",
37682diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
37683index 5c3960d..15cf8fc 100644
37684--- a/drivers/video/fbcmap.c
37685+++ b/drivers/video/fbcmap.c
37686@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
37687 rc = -ENODEV;
37688 goto out;
37689 }
37690- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
37691- !info->fbops->fb_setcmap)) {
37692+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
37693 rc = -EINVAL;
37694 goto out1;
37695 }
37696diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
37697index c6ce416..3b9b642 100644
37698--- a/drivers/video/fbmem.c
37699+++ b/drivers/video/fbmem.c
37700@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
37701 image->dx += image->width + 8;
37702 }
37703 } else if (rotate == FB_ROTATE_UD) {
37704- for (x = 0; x < num && image->dx >= 0; x++) {
37705+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
37706 info->fbops->fb_imageblit(info, image);
37707 image->dx -= image->width + 8;
37708 }
37709@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
37710 image->dy += image->height + 8;
37711 }
37712 } else if (rotate == FB_ROTATE_CCW) {
37713- for (x = 0; x < num && image->dy >= 0; x++) {
37714+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
37715 info->fbops->fb_imageblit(info, image);
37716 image->dy -= image->height + 8;
37717 }
37718@@ -1157,7 +1157,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
37719 return -EFAULT;
37720 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
37721 return -EINVAL;
37722- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
37723+ if (con2fb.framebuffer >= FB_MAX)
37724 return -EINVAL;
37725 if (!registered_fb[con2fb.framebuffer])
37726 request_module("fb%d", con2fb.framebuffer);
37727diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
37728index 5a5d092..265c5ed 100644
37729--- a/drivers/video/geode/gx1fb_core.c
37730+++ b/drivers/video/geode/gx1fb_core.c
37731@@ -29,7 +29,7 @@ static int crt_option = 1;
37732 static char panel_option[32] = "";
37733
37734 /* Modes relevant to the GX1 (taken from modedb.c) */
37735-static const struct fb_videomode __devinitdata gx1_modedb[] = {
37736+static const struct fb_videomode __devinitconst gx1_modedb[] = {
37737 /* 640x480-60 VESA */
37738 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
37739 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
37740diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
37741index 0fad23f..0e9afa4 100644
37742--- a/drivers/video/gxt4500.c
37743+++ b/drivers/video/gxt4500.c
37744@@ -156,7 +156,7 @@ struct gxt4500_par {
37745 static char *mode_option;
37746
37747 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
37748-static const struct fb_videomode defaultmode __devinitdata = {
37749+static const struct fb_videomode defaultmode __devinitconst = {
37750 .refresh = 60,
37751 .xres = 1280,
37752 .yres = 1024,
37753@@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
37754 return 0;
37755 }
37756
37757-static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
37758+static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
37759 .id = "IBM GXT4500P",
37760 .type = FB_TYPE_PACKED_PIXELS,
37761 .visual = FB_VISUAL_PSEUDOCOLOR,
37762diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
37763index 7672d2e..b56437f 100644
37764--- a/drivers/video/i810/i810_accel.c
37765+++ b/drivers/video/i810/i810_accel.c
37766@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
37767 }
37768 }
37769 printk("ringbuffer lockup!!!\n");
37770+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
37771 i810_report_error(mmio);
37772 par->dev_flags |= LOCKUP;
37773 info->pixmap.scan_align = 1;
37774diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
37775index b83f361..2b05a91 100644
37776--- a/drivers/video/i810/i810_main.c
37777+++ b/drivers/video/i810/i810_main.c
37778@@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
37779 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
37780
37781 /* PCI */
37782-static const char *i810_pci_list[] __devinitdata = {
37783+static const char *i810_pci_list[] __devinitconst = {
37784 "Intel(R) 810 Framebuffer Device" ,
37785 "Intel(R) 810-DC100 Framebuffer Device" ,
37786 "Intel(R) 810E Framebuffer Device" ,
37787diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
37788index de36693..3c63fc2 100644
37789--- a/drivers/video/jz4740_fb.c
37790+++ b/drivers/video/jz4740_fb.c
37791@@ -136,7 +136,7 @@ struct jzfb {
37792 uint32_t pseudo_palette[16];
37793 };
37794
37795-static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
37796+static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
37797 .id = "JZ4740 FB",
37798 .type = FB_TYPE_PACKED_PIXELS,
37799 .visual = FB_VISUAL_TRUECOLOR,
37800diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
37801index 3c14e43..eafa544 100644
37802--- a/drivers/video/logo/logo_linux_clut224.ppm
37803+++ b/drivers/video/logo/logo_linux_clut224.ppm
37804@@ -1,1604 +1,1123 @@
37805 P3
37806-# Standard 224-color Linux logo
37807 80 80
37808 255
37809- 0 0 0 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 0 0 0 0 0 0
37813- 0 0 0 0 0 0 0 0 0 0 0 0
37814- 0 0 0 0 0 0 0 0 0 0 0 0
37815- 0 0 0 0 0 0 0 0 0 0 0 0
37816- 0 0 0 0 0 0 0 0 0 0 0 0
37817- 0 0 0 0 0 0 0 0 0 0 0 0
37818- 6 6 6 6 6 6 10 10 10 10 10 10
37819- 10 10 10 6 6 6 6 6 6 6 6 6
37820- 0 0 0 0 0 0 0 0 0 0 0 0
37821- 0 0 0 0 0 0 0 0 0 0 0 0
37822- 0 0 0 0 0 0 0 0 0 0 0 0
37823- 0 0 0 0 0 0 0 0 0 0 0 0
37824- 0 0 0 0 0 0 0 0 0 0 0 0
37825- 0 0 0 0 0 0 0 0 0 0 0 0
37826- 0 0 0 0 0 0 0 0 0 0 0 0
37827- 0 0 0 0 0 0 0 0 0 0 0 0
37828- 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0
37833- 0 0 0 0 0 0 0 0 0 0 0 0
37834- 0 0 0 0 0 0 0 0 0 0 0 0
37835- 0 0 0 0 0 0 0 0 0 0 0 0
37836- 0 0 0 0 0 0 0 0 0 0 0 0
37837- 0 0 0 6 6 6 10 10 10 14 14 14
37838- 22 22 22 26 26 26 30 30 30 34 34 34
37839- 30 30 30 30 30 30 26 26 26 18 18 18
37840- 14 14 14 10 10 10 6 6 6 0 0 0
37841- 0 0 0 0 0 0 0 0 0 0 0 0
37842- 0 0 0 0 0 0 0 0 0 0 0 0
37843- 0 0 0 0 0 0 0 0 0 0 0 0
37844- 0 0 0 0 0 0 0 0 0 0 0 0
37845- 0 0 0 0 0 0 0 0 0 0 0 0
37846- 0 0 0 0 0 0 0 0 0 0 0 0
37847- 0 0 0 0 0 0 0 0 0 0 0 0
37848- 0 0 0 0 0 0 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 1 0 0 1 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 0 0 0
37853- 0 0 0 0 0 0 0 0 0 0 0 0
37854- 0 0 0 0 0 0 0 0 0 0 0 0
37855- 0 0 0 0 0 0 0 0 0 0 0 0
37856- 0 0 0 0 0 0 0 0 0 0 0 0
37857- 6 6 6 14 14 14 26 26 26 42 42 42
37858- 54 54 54 66 66 66 78 78 78 78 78 78
37859- 78 78 78 74 74 74 66 66 66 54 54 54
37860- 42 42 42 26 26 26 18 18 18 10 10 10
37861- 6 6 6 0 0 0 0 0 0 0 0 0
37862- 0 0 0 0 0 0 0 0 0 0 0 0
37863- 0 0 0 0 0 0 0 0 0 0 0 0
37864- 0 0 0 0 0 0 0 0 0 0 0 0
37865- 0 0 0 0 0 0 0 0 0 0 0 0
37866- 0 0 0 0 0 0 0 0 0 0 0 0
37867- 0 0 0 0 0 0 0 0 0 0 0 0
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 1 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- 0 0 0 0 0 0 0 0 0 0 0 0
37874- 0 0 0 0 0 0 0 0 0 0 0 0
37875- 0 0 0 0 0 0 0 0 0 0 0 0
37876- 0 0 0 0 0 0 0 0 0 10 10 10
37877- 22 22 22 42 42 42 66 66 66 86 86 86
37878- 66 66 66 38 38 38 38 38 38 22 22 22
37879- 26 26 26 34 34 34 54 54 54 66 66 66
37880- 86 86 86 70 70 70 46 46 46 26 26 26
37881- 14 14 14 6 6 6 0 0 0 0 0 0
37882- 0 0 0 0 0 0 0 0 0 0 0 0
37883- 0 0 0 0 0 0 0 0 0 0 0 0
37884- 0 0 0 0 0 0 0 0 0 0 0 0
37885- 0 0 0 0 0 0 0 0 0 0 0 0
37886- 0 0 0 0 0 0 0 0 0 0 0 0
37887- 0 0 0 0 0 0 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 1 0 0 1 0 0 1 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 0 0 0 0 0 0
37894- 0 0 0 0 0 0 0 0 0 0 0 0
37895- 0 0 0 0 0 0 0 0 0 0 0 0
37896- 0 0 0 0 0 0 10 10 10 26 26 26
37897- 50 50 50 82 82 82 58 58 58 6 6 6
37898- 2 2 6 2 2 6 2 2 6 2 2 6
37899- 2 2 6 2 2 6 2 2 6 2 2 6
37900- 6 6 6 54 54 54 86 86 86 66 66 66
37901- 38 38 38 18 18 18 6 6 6 0 0 0
37902- 0 0 0 0 0 0 0 0 0 0 0 0
37903- 0 0 0 0 0 0 0 0 0 0 0 0
37904- 0 0 0 0 0 0 0 0 0 0 0 0
37905- 0 0 0 0 0 0 0 0 0 0 0 0
37906- 0 0 0 0 0 0 0 0 0 0 0 0
37907- 0 0 0 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 0 0 0 0 0 0 0 0 0
37915- 0 0 0 0 0 0 0 0 0 0 0 0
37916- 0 0 0 6 6 6 22 22 22 50 50 50
37917- 78 78 78 34 34 34 2 2 6 2 2 6
37918- 2 2 6 2 2 6 2 2 6 2 2 6
37919- 2 2 6 2 2 6 2 2 6 2 2 6
37920- 2 2 6 2 2 6 6 6 6 70 70 70
37921- 78 78 78 46 46 46 22 22 22 6 6 6
37922- 0 0 0 0 0 0 0 0 0 0 0 0
37923- 0 0 0 0 0 0 0 0 0 0 0 0
37924- 0 0 0 0 0 0 0 0 0 0 0 0
37925- 0 0 0 0 0 0 0 0 0 0 0 0
37926- 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1 0 0 1 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 0 0 0 0 0 0 0 0 0
37936- 6 6 6 18 18 18 42 42 42 82 82 82
37937- 26 26 26 2 2 6 2 2 6 2 2 6
37938- 2 2 6 2 2 6 2 2 6 2 2 6
37939- 2 2 6 2 2 6 2 2 6 14 14 14
37940- 46 46 46 34 34 34 6 6 6 2 2 6
37941- 42 42 42 78 78 78 42 42 42 18 18 18
37942- 6 6 6 0 0 0 0 0 0 0 0 0
37943- 0 0 0 0 0 0 0 0 0 0 0 0
37944- 0 0 0 0 0 0 0 0 0 0 0 0
37945- 0 0 0 0 0 0 0 0 0 0 0 0
37946- 0 0 0 0 0 0 0 0 0 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 1 0 0 0 0 0 1 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- 10 10 10 30 30 30 66 66 66 58 58 58
37957- 2 2 6 2 2 6 2 2 6 2 2 6
37958- 2 2 6 2 2 6 2 2 6 2 2 6
37959- 2 2 6 2 2 6 2 2 6 26 26 26
37960- 86 86 86 101 101 101 46 46 46 10 10 10
37961- 2 2 6 58 58 58 70 70 70 34 34 34
37962- 10 10 10 0 0 0 0 0 0 0 0 0
37963- 0 0 0 0 0 0 0 0 0 0 0 0
37964- 0 0 0 0 0 0 0 0 0 0 0 0
37965- 0 0 0 0 0 0 0 0 0 0 0 0
37966- 0 0 0 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 1 0 0 1 0 0 1 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- 14 14 14 42 42 42 86 86 86 10 10 10
37977- 2 2 6 2 2 6 2 2 6 2 2 6
37978- 2 2 6 2 2 6 2 2 6 2 2 6
37979- 2 2 6 2 2 6 2 2 6 30 30 30
37980- 94 94 94 94 94 94 58 58 58 26 26 26
37981- 2 2 6 6 6 6 78 78 78 54 54 54
37982- 22 22 22 6 6 6 0 0 0 0 0 0
37983- 0 0 0 0 0 0 0 0 0 0 0 0
37984- 0 0 0 0 0 0 0 0 0 0 0 0
37985- 0 0 0 0 0 0 0 0 0 0 0 0
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- 0 0 0 0 0 0 0 0 0 0 0 0
37992- 0 0 0 0 0 0 0 0 0 0 0 0
37993- 0 0 0 0 0 0 0 0 0 0 0 0
37994- 0 0 0 0 0 0 0 0 0 0 0 0
37995- 0 0 0 0 0 0 0 0 0 6 6 6
37996- 22 22 22 62 62 62 62 62 62 2 2 6
37997- 2 2 6 2 2 6 2 2 6 2 2 6
37998- 2 2 6 2 2 6 2 2 6 2 2 6
37999- 2 2 6 2 2 6 2 2 6 26 26 26
38000- 54 54 54 38 38 38 18 18 18 10 10 10
38001- 2 2 6 2 2 6 34 34 34 82 82 82
38002- 38 38 38 14 14 14 0 0 0 0 0 0
38003- 0 0 0 0 0 0 0 0 0 0 0 0
38004- 0 0 0 0 0 0 0 0 0 0 0 0
38005- 0 0 0 0 0 0 0 0 0 0 0 0
38006- 0 0 0 0 0 0 0 0 0 0 0 0
38007- 0 0 0 0 0 0 0 0 0 0 0 0
38008- 0 0 0 0 0 0 0 0 0 0 0 0
38009- 0 0 0 0 0 0 0 0 0 0 0 0
38010- 0 0 0 0 0 1 0 0 1 0 0 0
38011- 0 0 0 0 0 0 0 0 0 0 0 0
38012- 0 0 0 0 0 0 0 0 0 0 0 0
38013- 0 0 0 0 0 0 0 0 0 0 0 0
38014- 0 0 0 0 0 0 0 0 0 0 0 0
38015- 0 0 0 0 0 0 0 0 0 6 6 6
38016- 30 30 30 78 78 78 30 30 30 2 2 6
38017- 2 2 6 2 2 6 2 2 6 2 2 6
38018- 2 2 6 2 2 6 2 2 6 2 2 6
38019- 2 2 6 2 2 6 2 2 6 10 10 10
38020- 10 10 10 2 2 6 2 2 6 2 2 6
38021- 2 2 6 2 2 6 2 2 6 78 78 78
38022- 50 50 50 18 18 18 6 6 6 0 0 0
38023- 0 0 0 0 0 0 0 0 0 0 0 0
38024- 0 0 0 0 0 0 0 0 0 0 0 0
38025- 0 0 0 0 0 0 0 0 0 0 0 0
38026- 0 0 0 0 0 0 0 0 0 0 0 0
38027- 0 0 0 0 0 0 0 0 0 0 0 0
38028- 0 0 0 0 0 0 0 0 0 0 0 0
38029- 0 0 0 0 0 0 0 0 0 0 0 0
38030- 0 0 1 0 0 0 0 0 0 0 0 0
38031- 0 0 0 0 0 0 0 0 0 0 0 0
38032- 0 0 0 0 0 0 0 0 0 0 0 0
38033- 0 0 0 0 0 0 0 0 0 0 0 0
38034- 0 0 0 0 0 0 0 0 0 0 0 0
38035- 0 0 0 0 0 0 0 0 0 10 10 10
38036- 38 38 38 86 86 86 14 14 14 2 2 6
38037- 2 2 6 2 2 6 2 2 6 2 2 6
38038- 2 2 6 2 2 6 2 2 6 2 2 6
38039- 2 2 6 2 2 6 2 2 6 2 2 6
38040- 2 2 6 2 2 6 2 2 6 2 2 6
38041- 2 2 6 2 2 6 2 2 6 54 54 54
38042- 66 66 66 26 26 26 6 6 6 0 0 0
38043- 0 0 0 0 0 0 0 0 0 0 0 0
38044- 0 0 0 0 0 0 0 0 0 0 0 0
38045- 0 0 0 0 0 0 0 0 0 0 0 0
38046- 0 0 0 0 0 0 0 0 0 0 0 0
38047- 0 0 0 0 0 0 0 0 0 0 0 0
38048- 0 0 0 0 0 0 0 0 0 0 0 0
38049- 0 0 0 0 0 0 0 0 0 0 0 0
38050- 0 0 0 0 0 1 0 0 1 0 0 0
38051- 0 0 0 0 0 0 0 0 0 0 0 0
38052- 0 0 0 0 0 0 0 0 0 0 0 0
38053- 0 0 0 0 0 0 0 0 0 0 0 0
38054- 0 0 0 0 0 0 0 0 0 0 0 0
38055- 0 0 0 0 0 0 0 0 0 14 14 14
38056- 42 42 42 82 82 82 2 2 6 2 2 6
38057- 2 2 6 6 6 6 10 10 10 2 2 6
38058- 2 2 6 2 2 6 2 2 6 2 2 6
38059- 2 2 6 2 2 6 2 2 6 6 6 6
38060- 14 14 14 10 10 10 2 2 6 2 2 6
38061- 2 2 6 2 2 6 2 2 6 18 18 18
38062- 82 82 82 34 34 34 10 10 10 0 0 0
38063- 0 0 0 0 0 0 0 0 0 0 0 0
38064- 0 0 0 0 0 0 0 0 0 0 0 0
38065- 0 0 0 0 0 0 0 0 0 0 0 0
38066- 0 0 0 0 0 0 0 0 0 0 0 0
38067- 0 0 0 0 0 0 0 0 0 0 0 0
38068- 0 0 0 0 0 0 0 0 0 0 0 0
38069- 0 0 0 0 0 0 0 0 0 0 0 0
38070- 0 0 1 0 0 0 0 0 0 0 0 0
38071- 0 0 0 0 0 0 0 0 0 0 0 0
38072- 0 0 0 0 0 0 0 0 0 0 0 0
38073- 0 0 0 0 0 0 0 0 0 0 0 0
38074- 0 0 0 0 0 0 0 0 0 0 0 0
38075- 0 0 0 0 0 0 0 0 0 14 14 14
38076- 46 46 46 86 86 86 2 2 6 2 2 6
38077- 6 6 6 6 6 6 22 22 22 34 34 34
38078- 6 6 6 2 2 6 2 2 6 2 2 6
38079- 2 2 6 2 2 6 18 18 18 34 34 34
38080- 10 10 10 50 50 50 22 22 22 2 2 6
38081- 2 2 6 2 2 6 2 2 6 10 10 10
38082- 86 86 86 42 42 42 14 14 14 0 0 0
38083- 0 0 0 0 0 0 0 0 0 0 0 0
38084- 0 0 0 0 0 0 0 0 0 0 0 0
38085- 0 0 0 0 0 0 0 0 0 0 0 0
38086- 0 0 0 0 0 0 0 0 0 0 0 0
38087- 0 0 0 0 0 0 0 0 0 0 0 0
38088- 0 0 0 0 0 0 0 0 0 0 0 0
38089- 0 0 0 0 0 0 0 0 0 0 0 0
38090- 0 0 1 0 0 1 0 0 1 0 0 0
38091- 0 0 0 0 0 0 0 0 0 0 0 0
38092- 0 0 0 0 0 0 0 0 0 0 0 0
38093- 0 0 0 0 0 0 0 0 0 0 0 0
38094- 0 0 0 0 0 0 0 0 0 0 0 0
38095- 0 0 0 0 0 0 0 0 0 14 14 14
38096- 46 46 46 86 86 86 2 2 6 2 2 6
38097- 38 38 38 116 116 116 94 94 94 22 22 22
38098- 22 22 22 2 2 6 2 2 6 2 2 6
38099- 14 14 14 86 86 86 138 138 138 162 162 162
38100-154 154 154 38 38 38 26 26 26 6 6 6
38101- 2 2 6 2 2 6 2 2 6 2 2 6
38102- 86 86 86 46 46 46 14 14 14 0 0 0
38103- 0 0 0 0 0 0 0 0 0 0 0 0
38104- 0 0 0 0 0 0 0 0 0 0 0 0
38105- 0 0 0 0 0 0 0 0 0 0 0 0
38106- 0 0 0 0 0 0 0 0 0 0 0 0
38107- 0 0 0 0 0 0 0 0 0 0 0 0
38108- 0 0 0 0 0 0 0 0 0 0 0 0
38109- 0 0 0 0 0 0 0 0 0 0 0 0
38110- 0 0 0 0 0 0 0 0 0 0 0 0
38111- 0 0 0 0 0 0 0 0 0 0 0 0
38112- 0 0 0 0 0 0 0 0 0 0 0 0
38113- 0 0 0 0 0 0 0 0 0 0 0 0
38114- 0 0 0 0 0 0 0 0 0 0 0 0
38115- 0 0 0 0 0 0 0 0 0 14 14 14
38116- 46 46 46 86 86 86 2 2 6 14 14 14
38117-134 134 134 198 198 198 195 195 195 116 116 116
38118- 10 10 10 2 2 6 2 2 6 6 6 6
38119-101 98 89 187 187 187 210 210 210 218 218 218
38120-214 214 214 134 134 134 14 14 14 6 6 6
38121- 2 2 6 2 2 6 2 2 6 2 2 6
38122- 86 86 86 50 50 50 18 18 18 6 6 6
38123- 0 0 0 0 0 0 0 0 0 0 0 0
38124- 0 0 0 0 0 0 0 0 0 0 0 0
38125- 0 0 0 0 0 0 0 0 0 0 0 0
38126- 0 0 0 0 0 0 0 0 0 0 0 0
38127- 0 0 0 0 0 0 0 0 0 0 0 0
38128- 0 0 0 0 0 0 0 0 0 0 0 0
38129- 0 0 0 0 0 0 0 0 1 0 0 0
38130- 0 0 1 0 0 1 0 0 1 0 0 0
38131- 0 0 0 0 0 0 0 0 0 0 0 0
38132- 0 0 0 0 0 0 0 0 0 0 0 0
38133- 0 0 0 0 0 0 0 0 0 0 0 0
38134- 0 0 0 0 0 0 0 0 0 0 0 0
38135- 0 0 0 0 0 0 0 0 0 14 14 14
38136- 46 46 46 86 86 86 2 2 6 54 54 54
38137-218 218 218 195 195 195 226 226 226 246 246 246
38138- 58 58 58 2 2 6 2 2 6 30 30 30
38139-210 210 210 253 253 253 174 174 174 123 123 123
38140-221 221 221 234 234 234 74 74 74 2 2 6
38141- 2 2 6 2 2 6 2 2 6 2 2 6
38142- 70 70 70 58 58 58 22 22 22 6 6 6
38143- 0 0 0 0 0 0 0 0 0 0 0 0
38144- 0 0 0 0 0 0 0 0 0 0 0 0
38145- 0 0 0 0 0 0 0 0 0 0 0 0
38146- 0 0 0 0 0 0 0 0 0 0 0 0
38147- 0 0 0 0 0 0 0 0 0 0 0 0
38148- 0 0 0 0 0 0 0 0 0 0 0 0
38149- 0 0 0 0 0 0 0 0 0 0 0 0
38150- 0 0 0 0 0 0 0 0 0 0 0 0
38151- 0 0 0 0 0 0 0 0 0 0 0 0
38152- 0 0 0 0 0 0 0 0 0 0 0 0
38153- 0 0 0 0 0 0 0 0 0 0 0 0
38154- 0 0 0 0 0 0 0 0 0 0 0 0
38155- 0 0 0 0 0 0 0 0 0 14 14 14
38156- 46 46 46 82 82 82 2 2 6 106 106 106
38157-170 170 170 26 26 26 86 86 86 226 226 226
38158-123 123 123 10 10 10 14 14 14 46 46 46
38159-231 231 231 190 190 190 6 6 6 70 70 70
38160- 90 90 90 238 238 238 158 158 158 2 2 6
38161- 2 2 6 2 2 6 2 2 6 2 2 6
38162- 70 70 70 58 58 58 22 22 22 6 6 6
38163- 0 0 0 0 0 0 0 0 0 0 0 0
38164- 0 0 0 0 0 0 0 0 0 0 0 0
38165- 0 0 0 0 0 0 0 0 0 0 0 0
38166- 0 0 0 0 0 0 0 0 0 0 0 0
38167- 0 0 0 0 0 0 0 0 0 0 0 0
38168- 0 0 0 0 0 0 0 0 0 0 0 0
38169- 0 0 0 0 0 0 0 0 1 0 0 0
38170- 0 0 1 0 0 1 0 0 1 0 0 0
38171- 0 0 0 0 0 0 0 0 0 0 0 0
38172- 0 0 0 0 0 0 0 0 0 0 0 0
38173- 0 0 0 0 0 0 0 0 0 0 0 0
38174- 0 0 0 0 0 0 0 0 0 0 0 0
38175- 0 0 0 0 0 0 0 0 0 14 14 14
38176- 42 42 42 86 86 86 6 6 6 116 116 116
38177-106 106 106 6 6 6 70 70 70 149 149 149
38178-128 128 128 18 18 18 38 38 38 54 54 54
38179-221 221 221 106 106 106 2 2 6 14 14 14
38180- 46 46 46 190 190 190 198 198 198 2 2 6
38181- 2 2 6 2 2 6 2 2 6 2 2 6
38182- 74 74 74 62 62 62 22 22 22 6 6 6
38183- 0 0 0 0 0 0 0 0 0 0 0 0
38184- 0 0 0 0 0 0 0 0 0 0 0 0
38185- 0 0 0 0 0 0 0 0 0 0 0 0
38186- 0 0 0 0 0 0 0 0 0 0 0 0
38187- 0 0 0 0 0 0 0 0 0 0 0 0
38188- 0 0 0 0 0 0 0 0 0 0 0 0
38189- 0 0 0 0 0 0 0 0 1 0 0 0
38190- 0 0 1 0 0 0 0 0 1 0 0 0
38191- 0 0 0 0 0 0 0 0 0 0 0 0
38192- 0 0 0 0 0 0 0 0 0 0 0 0
38193- 0 0 0 0 0 0 0 0 0 0 0 0
38194- 0 0 0 0 0 0 0 0 0 0 0 0
38195- 0 0 0 0 0 0 0 0 0 14 14 14
38196- 42 42 42 94 94 94 14 14 14 101 101 101
38197-128 128 128 2 2 6 18 18 18 116 116 116
38198-118 98 46 121 92 8 121 92 8 98 78 10
38199-162 162 162 106 106 106 2 2 6 2 2 6
38200- 2 2 6 195 195 195 195 195 195 6 6 6
38201- 2 2 6 2 2 6 2 2 6 2 2 6
38202- 74 74 74 62 62 62 22 22 22 6 6 6
38203- 0 0 0 0 0 0 0 0 0 0 0 0
38204- 0 0 0 0 0 0 0 0 0 0 0 0
38205- 0 0 0 0 0 0 0 0 0 0 0 0
38206- 0 0 0 0 0 0 0 0 0 0 0 0
38207- 0 0 0 0 0 0 0 0 0 0 0 0
38208- 0 0 0 0 0 0 0 0 0 0 0 0
38209- 0 0 0 0 0 0 0 0 1 0 0 1
38210- 0 0 1 0 0 0 0 0 1 0 0 0
38211- 0 0 0 0 0 0 0 0 0 0 0 0
38212- 0 0 0 0 0 0 0 0 0 0 0 0
38213- 0 0 0 0 0 0 0 0 0 0 0 0
38214- 0 0 0 0 0 0 0 0 0 0 0 0
38215- 0 0 0 0 0 0 0 0 0 10 10 10
38216- 38 38 38 90 90 90 14 14 14 58 58 58
38217-210 210 210 26 26 26 54 38 6 154 114 10
38218-226 170 11 236 186 11 225 175 15 184 144 12
38219-215 174 15 175 146 61 37 26 9 2 2 6
38220- 70 70 70 246 246 246 138 138 138 2 2 6
38221- 2 2 6 2 2 6 2 2 6 2 2 6
38222- 70 70 70 66 66 66 26 26 26 6 6 6
38223- 0 0 0 0 0 0 0 0 0 0 0 0
38224- 0 0 0 0 0 0 0 0 0 0 0 0
38225- 0 0 0 0 0 0 0 0 0 0 0 0
38226- 0 0 0 0 0 0 0 0 0 0 0 0
38227- 0 0 0 0 0 0 0 0 0 0 0 0
38228- 0 0 0 0 0 0 0 0 0 0 0 0
38229- 0 0 0 0 0 0 0 0 0 0 0 0
38230- 0 0 0 0 0 0 0 0 0 0 0 0
38231- 0 0 0 0 0 0 0 0 0 0 0 0
38232- 0 0 0 0 0 0 0 0 0 0 0 0
38233- 0 0 0 0 0 0 0 0 0 0 0 0
38234- 0 0 0 0 0 0 0 0 0 0 0 0
38235- 0 0 0 0 0 0 0 0 0 10 10 10
38236- 38 38 38 86 86 86 14 14 14 10 10 10
38237-195 195 195 188 164 115 192 133 9 225 175 15
38238-239 182 13 234 190 10 232 195 16 232 200 30
38239-245 207 45 241 208 19 232 195 16 184 144 12
38240-218 194 134 211 206 186 42 42 42 2 2 6
38241- 2 2 6 2 2 6 2 2 6 2 2 6
38242- 50 50 50 74 74 74 30 30 30 6 6 6
38243- 0 0 0 0 0 0 0 0 0 0 0 0
38244- 0 0 0 0 0 0 0 0 0 0 0 0
38245- 0 0 0 0 0 0 0 0 0 0 0 0
38246- 0 0 0 0 0 0 0 0 0 0 0 0
38247- 0 0 0 0 0 0 0 0 0 0 0 0
38248- 0 0 0 0 0 0 0 0 0 0 0 0
38249- 0 0 0 0 0 0 0 0 0 0 0 0
38250- 0 0 0 0 0 0 0 0 0 0 0 0
38251- 0 0 0 0 0 0 0 0 0 0 0 0
38252- 0 0 0 0 0 0 0 0 0 0 0 0
38253- 0 0 0 0 0 0 0 0 0 0 0 0
38254- 0 0 0 0 0 0 0 0 0 0 0 0
38255- 0 0 0 0 0 0 0 0 0 10 10 10
38256- 34 34 34 86 86 86 14 14 14 2 2 6
38257-121 87 25 192 133 9 219 162 10 239 182 13
38258-236 186 11 232 195 16 241 208 19 244 214 54
38259-246 218 60 246 218 38 246 215 20 241 208 19
38260-241 208 19 226 184 13 121 87 25 2 2 6
38261- 2 2 6 2 2 6 2 2 6 2 2 6
38262- 50 50 50 82 82 82 34 34 34 10 10 10
38263- 0 0 0 0 0 0 0 0 0 0 0 0
38264- 0 0 0 0 0 0 0 0 0 0 0 0
38265- 0 0 0 0 0 0 0 0 0 0 0 0
38266- 0 0 0 0 0 0 0 0 0 0 0 0
38267- 0 0 0 0 0 0 0 0 0 0 0 0
38268- 0 0 0 0 0 0 0 0 0 0 0 0
38269- 0 0 0 0 0 0 0 0 0 0 0 0
38270- 0 0 0 0 0 0 0 0 0 0 0 0
38271- 0 0 0 0 0 0 0 0 0 0 0 0
38272- 0 0 0 0 0 0 0 0 0 0 0 0
38273- 0 0 0 0 0 0 0 0 0 0 0 0
38274- 0 0 0 0 0 0 0 0 0 0 0 0
38275- 0 0 0 0 0 0 0 0 0 10 10 10
38276- 34 34 34 82 82 82 30 30 30 61 42 6
38277-180 123 7 206 145 10 230 174 11 239 182 13
38278-234 190 10 238 202 15 241 208 19 246 218 74
38279-246 218 38 246 215 20 246 215 20 246 215 20
38280-226 184 13 215 174 15 184 144 12 6 6 6
38281- 2 2 6 2 2 6 2 2 6 2 2 6
38282- 26 26 26 94 94 94 42 42 42 14 14 14
38283- 0 0 0 0 0 0 0 0 0 0 0 0
38284- 0 0 0 0 0 0 0 0 0 0 0 0
38285- 0 0 0 0 0 0 0 0 0 0 0 0
38286- 0 0 0 0 0 0 0 0 0 0 0 0
38287- 0 0 0 0 0 0 0 0 0 0 0 0
38288- 0 0 0 0 0 0 0 0 0 0 0 0
38289- 0 0 0 0 0 0 0 0 0 0 0 0
38290- 0 0 0 0 0 0 0 0 0 0 0 0
38291- 0 0 0 0 0 0 0 0 0 0 0 0
38292- 0 0 0 0 0 0 0 0 0 0 0 0
38293- 0 0 0 0 0 0 0 0 0 0 0 0
38294- 0 0 0 0 0 0 0 0 0 0 0 0
38295- 0 0 0 0 0 0 0 0 0 10 10 10
38296- 30 30 30 78 78 78 50 50 50 104 69 6
38297-192 133 9 216 158 10 236 178 12 236 186 11
38298-232 195 16 241 208 19 244 214 54 245 215 43
38299-246 215 20 246 215 20 241 208 19 198 155 10
38300-200 144 11 216 158 10 156 118 10 2 2 6
38301- 2 2 6 2 2 6 2 2 6 2 2 6
38302- 6 6 6 90 90 90 54 54 54 18 18 18
38303- 6 6 6 0 0 0 0 0 0 0 0 0
38304- 0 0 0 0 0 0 0 0 0 0 0 0
38305- 0 0 0 0 0 0 0 0 0 0 0 0
38306- 0 0 0 0 0 0 0 0 0 0 0 0
38307- 0 0 0 0 0 0 0 0 0 0 0 0
38308- 0 0 0 0 0 0 0 0 0 0 0 0
38309- 0 0 0 0 0 0 0 0 0 0 0 0
38310- 0 0 0 0 0 0 0 0 0 0 0 0
38311- 0 0 0 0 0 0 0 0 0 0 0 0
38312- 0 0 0 0 0 0 0 0 0 0 0 0
38313- 0 0 0 0 0 0 0 0 0 0 0 0
38314- 0 0 0 0 0 0 0 0 0 0 0 0
38315- 0 0 0 0 0 0 0 0 0 10 10 10
38316- 30 30 30 78 78 78 46 46 46 22 22 22
38317-137 92 6 210 162 10 239 182 13 238 190 10
38318-238 202 15 241 208 19 246 215 20 246 215 20
38319-241 208 19 203 166 17 185 133 11 210 150 10
38320-216 158 10 210 150 10 102 78 10 2 2 6
38321- 6 6 6 54 54 54 14 14 14 2 2 6
38322- 2 2 6 62 62 62 74 74 74 30 30 30
38323- 10 10 10 0 0 0 0 0 0 0 0 0
38324- 0 0 0 0 0 0 0 0 0 0 0 0
38325- 0 0 0 0 0 0 0 0 0 0 0 0
38326- 0 0 0 0 0 0 0 0 0 0 0 0
38327- 0 0 0 0 0 0 0 0 0 0 0 0
38328- 0 0 0 0 0 0 0 0 0 0 0 0
38329- 0 0 0 0 0 0 0 0 0 0 0 0
38330- 0 0 0 0 0 0 0 0 0 0 0 0
38331- 0 0 0 0 0 0 0 0 0 0 0 0
38332- 0 0 0 0 0 0 0 0 0 0 0 0
38333- 0 0 0 0 0 0 0 0 0 0 0 0
38334- 0 0 0 0 0 0 0 0 0 0 0 0
38335- 0 0 0 0 0 0 0 0 0 10 10 10
38336- 34 34 34 78 78 78 50 50 50 6 6 6
38337- 94 70 30 139 102 15 190 146 13 226 184 13
38338-232 200 30 232 195 16 215 174 15 190 146 13
38339-168 122 10 192 133 9 210 150 10 213 154 11
38340-202 150 34 182 157 106 101 98 89 2 2 6
38341- 2 2 6 78 78 78 116 116 116 58 58 58
38342- 2 2 6 22 22 22 90 90 90 46 46 46
38343- 18 18 18 6 6 6 0 0 0 0 0 0
38344- 0 0 0 0 0 0 0 0 0 0 0 0
38345- 0 0 0 0 0 0 0 0 0 0 0 0
38346- 0 0 0 0 0 0 0 0 0 0 0 0
38347- 0 0 0 0 0 0 0 0 0 0 0 0
38348- 0 0 0 0 0 0 0 0 0 0 0 0
38349- 0 0 0 0 0 0 0 0 0 0 0 0
38350- 0 0 0 0 0 0 0 0 0 0 0 0
38351- 0 0 0 0 0 0 0 0 0 0 0 0
38352- 0 0 0 0 0 0 0 0 0 0 0 0
38353- 0 0 0 0 0 0 0 0 0 0 0 0
38354- 0 0 0 0 0 0 0 0 0 0 0 0
38355- 0 0 0 0 0 0 0 0 0 10 10 10
38356- 38 38 38 86 86 86 50 50 50 6 6 6
38357-128 128 128 174 154 114 156 107 11 168 122 10
38358-198 155 10 184 144 12 197 138 11 200 144 11
38359-206 145 10 206 145 10 197 138 11 188 164 115
38360-195 195 195 198 198 198 174 174 174 14 14 14
38361- 2 2 6 22 22 22 116 116 116 116 116 116
38362- 22 22 22 2 2 6 74 74 74 70 70 70
38363- 30 30 30 10 10 10 0 0 0 0 0 0
38364- 0 0 0 0 0 0 0 0 0 0 0 0
38365- 0 0 0 0 0 0 0 0 0 0 0 0
38366- 0 0 0 0 0 0 0 0 0 0 0 0
38367- 0 0 0 0 0 0 0 0 0 0 0 0
38368- 0 0 0 0 0 0 0 0 0 0 0 0
38369- 0 0 0 0 0 0 0 0 0 0 0 0
38370- 0 0 0 0 0 0 0 0 0 0 0 0
38371- 0 0 0 0 0 0 0 0 0 0 0 0
38372- 0 0 0 0 0 0 0 0 0 0 0 0
38373- 0 0 0 0 0 0 0 0 0 0 0 0
38374- 0 0 0 0 0 0 0 0 0 0 0 0
38375- 0 0 0 0 0 0 6 6 6 18 18 18
38376- 50 50 50 101 101 101 26 26 26 10 10 10
38377-138 138 138 190 190 190 174 154 114 156 107 11
38378-197 138 11 200 144 11 197 138 11 192 133 9
38379-180 123 7 190 142 34 190 178 144 187 187 187
38380-202 202 202 221 221 221 214 214 214 66 66 66
38381- 2 2 6 2 2 6 50 50 50 62 62 62
38382- 6 6 6 2 2 6 10 10 10 90 90 90
38383- 50 50 50 18 18 18 6 6 6 0 0 0
38384- 0 0 0 0 0 0 0 0 0 0 0 0
38385- 0 0 0 0 0 0 0 0 0 0 0 0
38386- 0 0 0 0 0 0 0 0 0 0 0 0
38387- 0 0 0 0 0 0 0 0 0 0 0 0
38388- 0 0 0 0 0 0 0 0 0 0 0 0
38389- 0 0 0 0 0 0 0 0 0 0 0 0
38390- 0 0 0 0 0 0 0 0 0 0 0 0
38391- 0 0 0 0 0 0 0 0 0 0 0 0
38392- 0 0 0 0 0 0 0 0 0 0 0 0
38393- 0 0 0 0 0 0 0 0 0 0 0 0
38394- 0 0 0 0 0 0 0 0 0 0 0 0
38395- 0 0 0 0 0 0 10 10 10 34 34 34
38396- 74 74 74 74 74 74 2 2 6 6 6 6
38397-144 144 144 198 198 198 190 190 190 178 166 146
38398-154 121 60 156 107 11 156 107 11 168 124 44
38399-174 154 114 187 187 187 190 190 190 210 210 210
38400-246 246 246 253 253 253 253 253 253 182 182 182
38401- 6 6 6 2 2 6 2 2 6 2 2 6
38402- 2 2 6 2 2 6 2 2 6 62 62 62
38403- 74 74 74 34 34 34 14 14 14 0 0 0
38404- 0 0 0 0 0 0 0 0 0 0 0 0
38405- 0 0 0 0 0 0 0 0 0 0 0 0
38406- 0 0 0 0 0 0 0 0 0 0 0 0
38407- 0 0 0 0 0 0 0 0 0 0 0 0
38408- 0 0 0 0 0 0 0 0 0 0 0 0
38409- 0 0 0 0 0 0 0 0 0 0 0 0
38410- 0 0 0 0 0 0 0 0 0 0 0 0
38411- 0 0 0 0 0 0 0 0 0 0 0 0
38412- 0 0 0 0 0 0 0 0 0 0 0 0
38413- 0 0 0 0 0 0 0 0 0 0 0 0
38414- 0 0 0 0 0 0 0 0 0 0 0 0
38415- 0 0 0 10 10 10 22 22 22 54 54 54
38416- 94 94 94 18 18 18 2 2 6 46 46 46
38417-234 234 234 221 221 221 190 190 190 190 190 190
38418-190 190 190 187 187 187 187 187 187 190 190 190
38419-190 190 190 195 195 195 214 214 214 242 242 242
38420-253 253 253 253 253 253 253 253 253 253 253 253
38421- 82 82 82 2 2 6 2 2 6 2 2 6
38422- 2 2 6 2 2 6 2 2 6 14 14 14
38423- 86 86 86 54 54 54 22 22 22 6 6 6
38424- 0 0 0 0 0 0 0 0 0 0 0 0
38425- 0 0 0 0 0 0 0 0 0 0 0 0
38426- 0 0 0 0 0 0 0 0 0 0 0 0
38427- 0 0 0 0 0 0 0 0 0 0 0 0
38428- 0 0 0 0 0 0 0 0 0 0 0 0
38429- 0 0 0 0 0 0 0 0 0 0 0 0
38430- 0 0 0 0 0 0 0 0 0 0 0 0
38431- 0 0 0 0 0 0 0 0 0 0 0 0
38432- 0 0 0 0 0 0 0 0 0 0 0 0
38433- 0 0 0 0 0 0 0 0 0 0 0 0
38434- 0 0 0 0 0 0 0 0 0 0 0 0
38435- 6 6 6 18 18 18 46 46 46 90 90 90
38436- 46 46 46 18 18 18 6 6 6 182 182 182
38437-253 253 253 246 246 246 206 206 206 190 190 190
38438-190 190 190 190 190 190 190 190 190 190 190 190
38439-206 206 206 231 231 231 250 250 250 253 253 253
38440-253 253 253 253 253 253 253 253 253 253 253 253
38441-202 202 202 14 14 14 2 2 6 2 2 6
38442- 2 2 6 2 2 6 2 2 6 2 2 6
38443- 42 42 42 86 86 86 42 42 42 18 18 18
38444- 6 6 6 0 0 0 0 0 0 0 0 0
38445- 0 0 0 0 0 0 0 0 0 0 0 0
38446- 0 0 0 0 0 0 0 0 0 0 0 0
38447- 0 0 0 0 0 0 0 0 0 0 0 0
38448- 0 0 0 0 0 0 0 0 0 0 0 0
38449- 0 0 0 0 0 0 0 0 0 0 0 0
38450- 0 0 0 0 0 0 0 0 0 0 0 0
38451- 0 0 0 0 0 0 0 0 0 0 0 0
38452- 0 0 0 0 0 0 0 0 0 0 0 0
38453- 0 0 0 0 0 0 0 0 0 0 0 0
38454- 0 0 0 0 0 0 0 0 0 6 6 6
38455- 14 14 14 38 38 38 74 74 74 66 66 66
38456- 2 2 6 6 6 6 90 90 90 250 250 250
38457-253 253 253 253 253 253 238 238 238 198 198 198
38458-190 190 190 190 190 190 195 195 195 221 221 221
38459-246 246 246 253 253 253 253 253 253 253 253 253
38460-253 253 253 253 253 253 253 253 253 253 253 253
38461-253 253 253 82 82 82 2 2 6 2 2 6
38462- 2 2 6 2 2 6 2 2 6 2 2 6
38463- 2 2 6 78 78 78 70 70 70 34 34 34
38464- 14 14 14 6 6 6 0 0 0 0 0 0
38465- 0 0 0 0 0 0 0 0 0 0 0 0
38466- 0 0 0 0 0 0 0 0 0 0 0 0
38467- 0 0 0 0 0 0 0 0 0 0 0 0
38468- 0 0 0 0 0 0 0 0 0 0 0 0
38469- 0 0 0 0 0 0 0 0 0 0 0 0
38470- 0 0 0 0 0 0 0 0 0 0 0 0
38471- 0 0 0 0 0 0 0 0 0 0 0 0
38472- 0 0 0 0 0 0 0 0 0 0 0 0
38473- 0 0 0 0 0 0 0 0 0 0 0 0
38474- 0 0 0 0 0 0 0 0 0 14 14 14
38475- 34 34 34 66 66 66 78 78 78 6 6 6
38476- 2 2 6 18 18 18 218 218 218 253 253 253
38477-253 253 253 253 253 253 253 253 253 246 246 246
38478-226 226 226 231 231 231 246 246 246 253 253 253
38479-253 253 253 253 253 253 253 253 253 253 253 253
38480-253 253 253 253 253 253 253 253 253 253 253 253
38481-253 253 253 178 178 178 2 2 6 2 2 6
38482- 2 2 6 2 2 6 2 2 6 2 2 6
38483- 2 2 6 18 18 18 90 90 90 62 62 62
38484- 30 30 30 10 10 10 0 0 0 0 0 0
38485- 0 0 0 0 0 0 0 0 0 0 0 0
38486- 0 0 0 0 0 0 0 0 0 0 0 0
38487- 0 0 0 0 0 0 0 0 0 0 0 0
38488- 0 0 0 0 0 0 0 0 0 0 0 0
38489- 0 0 0 0 0 0 0 0 0 0 0 0
38490- 0 0 0 0 0 0 0 0 0 0 0 0
38491- 0 0 0 0 0 0 0 0 0 0 0 0
38492- 0 0 0 0 0 0 0 0 0 0 0 0
38493- 0 0 0 0 0 0 0 0 0 0 0 0
38494- 0 0 0 0 0 0 10 10 10 26 26 26
38495- 58 58 58 90 90 90 18 18 18 2 2 6
38496- 2 2 6 110 110 110 253 253 253 253 253 253
38497-253 253 253 253 253 253 253 253 253 253 253 253
38498-250 250 250 253 253 253 253 253 253 253 253 253
38499-253 253 253 253 253 253 253 253 253 253 253 253
38500-253 253 253 253 253 253 253 253 253 253 253 253
38501-253 253 253 231 231 231 18 18 18 2 2 6
38502- 2 2 6 2 2 6 2 2 6 2 2 6
38503- 2 2 6 2 2 6 18 18 18 94 94 94
38504- 54 54 54 26 26 26 10 10 10 0 0 0
38505- 0 0 0 0 0 0 0 0 0 0 0 0
38506- 0 0 0 0 0 0 0 0 0 0 0 0
38507- 0 0 0 0 0 0 0 0 0 0 0 0
38508- 0 0 0 0 0 0 0 0 0 0 0 0
38509- 0 0 0 0 0 0 0 0 0 0 0 0
38510- 0 0 0 0 0 0 0 0 0 0 0 0
38511- 0 0 0 0 0 0 0 0 0 0 0 0
38512- 0 0 0 0 0 0 0 0 0 0 0 0
38513- 0 0 0 0 0 0 0 0 0 0 0 0
38514- 0 0 0 6 6 6 22 22 22 50 50 50
38515- 90 90 90 26 26 26 2 2 6 2 2 6
38516- 14 14 14 195 195 195 250 250 250 253 253 253
38517-253 253 253 253 253 253 253 253 253 253 253 253
38518-253 253 253 253 253 253 253 253 253 253 253 253
38519-253 253 253 253 253 253 253 253 253 253 253 253
38520-253 253 253 253 253 253 253 253 253 253 253 253
38521-250 250 250 242 242 242 54 54 54 2 2 6
38522- 2 2 6 2 2 6 2 2 6 2 2 6
38523- 2 2 6 2 2 6 2 2 6 38 38 38
38524- 86 86 86 50 50 50 22 22 22 6 6 6
38525- 0 0 0 0 0 0 0 0 0 0 0 0
38526- 0 0 0 0 0 0 0 0 0 0 0 0
38527- 0 0 0 0 0 0 0 0 0 0 0 0
38528- 0 0 0 0 0 0 0 0 0 0 0 0
38529- 0 0 0 0 0 0 0 0 0 0 0 0
38530- 0 0 0 0 0 0 0 0 0 0 0 0
38531- 0 0 0 0 0 0 0 0 0 0 0 0
38532- 0 0 0 0 0 0 0 0 0 0 0 0
38533- 0 0 0 0 0 0 0 0 0 0 0 0
38534- 6 6 6 14 14 14 38 38 38 82 82 82
38535- 34 34 34 2 2 6 2 2 6 2 2 6
38536- 42 42 42 195 195 195 246 246 246 253 253 253
38537-253 253 253 253 253 253 253 253 253 250 250 250
38538-242 242 242 242 242 242 250 250 250 253 253 253
38539-253 253 253 253 253 253 253 253 253 253 253 253
38540-253 253 253 250 250 250 246 246 246 238 238 238
38541-226 226 226 231 231 231 101 101 101 6 6 6
38542- 2 2 6 2 2 6 2 2 6 2 2 6
38543- 2 2 6 2 2 6 2 2 6 2 2 6
38544- 38 38 38 82 82 82 42 42 42 14 14 14
38545- 6 6 6 0 0 0 0 0 0 0 0 0
38546- 0 0 0 0 0 0 0 0 0 0 0 0
38547- 0 0 0 0 0 0 0 0 0 0 0 0
38548- 0 0 0 0 0 0 0 0 0 0 0 0
38549- 0 0 0 0 0 0 0 0 0 0 0 0
38550- 0 0 0 0 0 0 0 0 0 0 0 0
38551- 0 0 0 0 0 0 0 0 0 0 0 0
38552- 0 0 0 0 0 0 0 0 0 0 0 0
38553- 0 0 0 0 0 0 0 0 0 0 0 0
38554- 10 10 10 26 26 26 62 62 62 66 66 66
38555- 2 2 6 2 2 6 2 2 6 6 6 6
38556- 70 70 70 170 170 170 206 206 206 234 234 234
38557-246 246 246 250 250 250 250 250 250 238 238 238
38558-226 226 226 231 231 231 238 238 238 250 250 250
38559-250 250 250 250 250 250 246 246 246 231 231 231
38560-214 214 214 206 206 206 202 202 202 202 202 202
38561-198 198 198 202 202 202 182 182 182 18 18 18
38562- 2 2 6 2 2 6 2 2 6 2 2 6
38563- 2 2 6 2 2 6 2 2 6 2 2 6
38564- 2 2 6 62 62 62 66 66 66 30 30 30
38565- 10 10 10 0 0 0 0 0 0 0 0 0
38566- 0 0 0 0 0 0 0 0 0 0 0 0
38567- 0 0 0 0 0 0 0 0 0 0 0 0
38568- 0 0 0 0 0 0 0 0 0 0 0 0
38569- 0 0 0 0 0 0 0 0 0 0 0 0
38570- 0 0 0 0 0 0 0 0 0 0 0 0
38571- 0 0 0 0 0 0 0 0 0 0 0 0
38572- 0 0 0 0 0 0 0 0 0 0 0 0
38573- 0 0 0 0 0 0 0 0 0 0 0 0
38574- 14 14 14 42 42 42 82 82 82 18 18 18
38575- 2 2 6 2 2 6 2 2 6 10 10 10
38576- 94 94 94 182 182 182 218 218 218 242 242 242
38577-250 250 250 253 253 253 253 253 253 250 250 250
38578-234 234 234 253 253 253 253 253 253 253 253 253
38579-253 253 253 253 253 253 253 253 253 246 246 246
38580-238 238 238 226 226 226 210 210 210 202 202 202
38581-195 195 195 195 195 195 210 210 210 158 158 158
38582- 6 6 6 14 14 14 50 50 50 14 14 14
38583- 2 2 6 2 2 6 2 2 6 2 2 6
38584- 2 2 6 6 6 6 86 86 86 46 46 46
38585- 18 18 18 6 6 6 0 0 0 0 0 0
38586- 0 0 0 0 0 0 0 0 0 0 0 0
38587- 0 0 0 0 0 0 0 0 0 0 0 0
38588- 0 0 0 0 0 0 0 0 0 0 0 0
38589- 0 0 0 0 0 0 0 0 0 0 0 0
38590- 0 0 0 0 0 0 0 0 0 0 0 0
38591- 0 0 0 0 0 0 0 0 0 0 0 0
38592- 0 0 0 0 0 0 0 0 0 0 0 0
38593- 0 0 0 0 0 0 0 0 0 6 6 6
38594- 22 22 22 54 54 54 70 70 70 2 2 6
38595- 2 2 6 10 10 10 2 2 6 22 22 22
38596-166 166 166 231 231 231 250 250 250 253 253 253
38597-253 253 253 253 253 253 253 253 253 250 250 250
38598-242 242 242 253 253 253 253 253 253 253 253 253
38599-253 253 253 253 253 253 253 253 253 253 253 253
38600-253 253 253 253 253 253 253 253 253 246 246 246
38601-231 231 231 206 206 206 198 198 198 226 226 226
38602- 94 94 94 2 2 6 6 6 6 38 38 38
38603- 30 30 30 2 2 6 2 2 6 2 2 6
38604- 2 2 6 2 2 6 62 62 62 66 66 66
38605- 26 26 26 10 10 10 0 0 0 0 0 0
38606- 0 0 0 0 0 0 0 0 0 0 0 0
38607- 0 0 0 0 0 0 0 0 0 0 0 0
38608- 0 0 0 0 0 0 0 0 0 0 0 0
38609- 0 0 0 0 0 0 0 0 0 0 0 0
38610- 0 0 0 0 0 0 0 0 0 0 0 0
38611- 0 0 0 0 0 0 0 0 0 0 0 0
38612- 0 0 0 0 0 0 0 0 0 0 0 0
38613- 0 0 0 0 0 0 0 0 0 10 10 10
38614- 30 30 30 74 74 74 50 50 50 2 2 6
38615- 26 26 26 26 26 26 2 2 6 106 106 106
38616-238 238 238 253 253 253 253 253 253 253 253 253
38617-253 253 253 253 253 253 253 253 253 253 253 253
38618-253 253 253 253 253 253 253 253 253 253 253 253
38619-253 253 253 253 253 253 253 253 253 253 253 253
38620-253 253 253 253 253 253 253 253 253 253 253 253
38621-253 253 253 246 246 246 218 218 218 202 202 202
38622-210 210 210 14 14 14 2 2 6 2 2 6
38623- 30 30 30 22 22 22 2 2 6 2 2 6
38624- 2 2 6 2 2 6 18 18 18 86 86 86
38625- 42 42 42 14 14 14 0 0 0 0 0 0
38626- 0 0 0 0 0 0 0 0 0 0 0 0
38627- 0 0 0 0 0 0 0 0 0 0 0 0
38628- 0 0 0 0 0 0 0 0 0 0 0 0
38629- 0 0 0 0 0 0 0 0 0 0 0 0
38630- 0 0 0 0 0 0 0 0 0 0 0 0
38631- 0 0 0 0 0 0 0 0 0 0 0 0
38632- 0 0 0 0 0 0 0 0 0 0 0 0
38633- 0 0 0 0 0 0 0 0 0 14 14 14
38634- 42 42 42 90 90 90 22 22 22 2 2 6
38635- 42 42 42 2 2 6 18 18 18 218 218 218
38636-253 253 253 253 253 253 253 253 253 253 253 253
38637-253 253 253 253 253 253 253 253 253 253 253 253
38638-253 253 253 253 253 253 253 253 253 253 253 253
38639-253 253 253 253 253 253 253 253 253 253 253 253
38640-253 253 253 253 253 253 253 253 253 253 253 253
38641-253 253 253 253 253 253 250 250 250 221 221 221
38642-218 218 218 101 101 101 2 2 6 14 14 14
38643- 18 18 18 38 38 38 10 10 10 2 2 6
38644- 2 2 6 2 2 6 2 2 6 78 78 78
38645- 58 58 58 22 22 22 6 6 6 0 0 0
38646- 0 0 0 0 0 0 0 0 0 0 0 0
38647- 0 0 0 0 0 0 0 0 0 0 0 0
38648- 0 0 0 0 0 0 0 0 0 0 0 0
38649- 0 0 0 0 0 0 0 0 0 0 0 0
38650- 0 0 0 0 0 0 0 0 0 0 0 0
38651- 0 0 0 0 0 0 0 0 0 0 0 0
38652- 0 0 0 0 0 0 0 0 0 0 0 0
38653- 0 0 0 0 0 0 6 6 6 18 18 18
38654- 54 54 54 82 82 82 2 2 6 26 26 26
38655- 22 22 22 2 2 6 123 123 123 253 253 253
38656-253 253 253 253 253 253 253 253 253 253 253 253
38657-253 253 253 253 253 253 253 253 253 253 253 253
38658-253 253 253 253 253 253 253 253 253 253 253 253
38659-253 253 253 253 253 253 253 253 253 253 253 253
38660-253 253 253 253 253 253 253 253 253 253 253 253
38661-253 253 253 253 253 253 253 253 253 250 250 250
38662-238 238 238 198 198 198 6 6 6 38 38 38
38663- 58 58 58 26 26 26 38 38 38 2 2 6
38664- 2 2 6 2 2 6 2 2 6 46 46 46
38665- 78 78 78 30 30 30 10 10 10 0 0 0
38666- 0 0 0 0 0 0 0 0 0 0 0 0
38667- 0 0 0 0 0 0 0 0 0 0 0 0
38668- 0 0 0 0 0 0 0 0 0 0 0 0
38669- 0 0 0 0 0 0 0 0 0 0 0 0
38670- 0 0 0 0 0 0 0 0 0 0 0 0
38671- 0 0 0 0 0 0 0 0 0 0 0 0
38672- 0 0 0 0 0 0 0 0 0 0 0 0
38673- 0 0 0 0 0 0 10 10 10 30 30 30
38674- 74 74 74 58 58 58 2 2 6 42 42 42
38675- 2 2 6 22 22 22 231 231 231 253 253 253
38676-253 253 253 253 253 253 253 253 253 253 253 253
38677-253 253 253 253 253 253 253 253 253 250 250 250
38678-253 253 253 253 253 253 253 253 253 253 253 253
38679-253 253 253 253 253 253 253 253 253 253 253 253
38680-253 253 253 253 253 253 253 253 253 253 253 253
38681-253 253 253 253 253 253 253 253 253 253 253 253
38682-253 253 253 246 246 246 46 46 46 38 38 38
38683- 42 42 42 14 14 14 38 38 38 14 14 14
38684- 2 2 6 2 2 6 2 2 6 6 6 6
38685- 86 86 86 46 46 46 14 14 14 0 0 0
38686- 0 0 0 0 0 0 0 0 0 0 0 0
38687- 0 0 0 0 0 0 0 0 0 0 0 0
38688- 0 0 0 0 0 0 0 0 0 0 0 0
38689- 0 0 0 0 0 0 0 0 0 0 0 0
38690- 0 0 0 0 0 0 0 0 0 0 0 0
38691- 0 0 0 0 0 0 0 0 0 0 0 0
38692- 0 0 0 0 0 0 0 0 0 0 0 0
38693- 0 0 0 6 6 6 14 14 14 42 42 42
38694- 90 90 90 18 18 18 18 18 18 26 26 26
38695- 2 2 6 116 116 116 253 253 253 253 253 253
38696-253 253 253 253 253 253 253 253 253 253 253 253
38697-253 253 253 253 253 253 250 250 250 238 238 238
38698-253 253 253 253 253 253 253 253 253 253 253 253
38699-253 253 253 253 253 253 253 253 253 253 253 253
38700-253 253 253 253 253 253 253 253 253 253 253 253
38701-253 253 253 253 253 253 253 253 253 253 253 253
38702-253 253 253 253 253 253 94 94 94 6 6 6
38703- 2 2 6 2 2 6 10 10 10 34 34 34
38704- 2 2 6 2 2 6 2 2 6 2 2 6
38705- 74 74 74 58 58 58 22 22 22 6 6 6
38706- 0 0 0 0 0 0 0 0 0 0 0 0
38707- 0 0 0 0 0 0 0 0 0 0 0 0
38708- 0 0 0 0 0 0 0 0 0 0 0 0
38709- 0 0 0 0 0 0 0 0 0 0 0 0
38710- 0 0 0 0 0 0 0 0 0 0 0 0
38711- 0 0 0 0 0 0 0 0 0 0 0 0
38712- 0 0 0 0 0 0 0 0 0 0 0 0
38713- 0 0 0 10 10 10 26 26 26 66 66 66
38714- 82 82 82 2 2 6 38 38 38 6 6 6
38715- 14 14 14 210 210 210 253 253 253 253 253 253
38716-253 253 253 253 253 253 253 253 253 253 253 253
38717-253 253 253 253 253 253 246 246 246 242 242 242
38718-253 253 253 253 253 253 253 253 253 253 253 253
38719-253 253 253 253 253 253 253 253 253 253 253 253
38720-253 253 253 253 253 253 253 253 253 253 253 253
38721-253 253 253 253 253 253 253 253 253 253 253 253
38722-253 253 253 253 253 253 144 144 144 2 2 6
38723- 2 2 6 2 2 6 2 2 6 46 46 46
38724- 2 2 6 2 2 6 2 2 6 2 2 6
38725- 42 42 42 74 74 74 30 30 30 10 10 10
38726- 0 0 0 0 0 0 0 0 0 0 0 0
38727- 0 0 0 0 0 0 0 0 0 0 0 0
38728- 0 0 0 0 0 0 0 0 0 0 0 0
38729- 0 0 0 0 0 0 0 0 0 0 0 0
38730- 0 0 0 0 0 0 0 0 0 0 0 0
38731- 0 0 0 0 0 0 0 0 0 0 0 0
38732- 0 0 0 0 0 0 0 0 0 0 0 0
38733- 6 6 6 14 14 14 42 42 42 90 90 90
38734- 26 26 26 6 6 6 42 42 42 2 2 6
38735- 74 74 74 250 250 250 253 253 253 253 253 253
38736-253 253 253 253 253 253 253 253 253 253 253 253
38737-253 253 253 253 253 253 242 242 242 242 242 242
38738-253 253 253 253 253 253 253 253 253 253 253 253
38739-253 253 253 253 253 253 253 253 253 253 253 253
38740-253 253 253 253 253 253 253 253 253 253 253 253
38741-253 253 253 253 253 253 253 253 253 253 253 253
38742-253 253 253 253 253 253 182 182 182 2 2 6
38743- 2 2 6 2 2 6 2 2 6 46 46 46
38744- 2 2 6 2 2 6 2 2 6 2 2 6
38745- 10 10 10 86 86 86 38 38 38 10 10 10
38746- 0 0 0 0 0 0 0 0 0 0 0 0
38747- 0 0 0 0 0 0 0 0 0 0 0 0
38748- 0 0 0 0 0 0 0 0 0 0 0 0
38749- 0 0 0 0 0 0 0 0 0 0 0 0
38750- 0 0 0 0 0 0 0 0 0 0 0 0
38751- 0 0 0 0 0 0 0 0 0 0 0 0
38752- 0 0 0 0 0 0 0 0 0 0 0 0
38753- 10 10 10 26 26 26 66 66 66 82 82 82
38754- 2 2 6 22 22 22 18 18 18 2 2 6
38755-149 149 149 253 253 253 253 253 253 253 253 253
38756-253 253 253 253 253 253 253 253 253 253 253 253
38757-253 253 253 253 253 253 234 234 234 242 242 242
38758-253 253 253 253 253 253 253 253 253 253 253 253
38759-253 253 253 253 253 253 253 253 253 253 253 253
38760-253 253 253 253 253 253 253 253 253 253 253 253
38761-253 253 253 253 253 253 253 253 253 253 253 253
38762-253 253 253 253 253 253 206 206 206 2 2 6
38763- 2 2 6 2 2 6 2 2 6 38 38 38
38764- 2 2 6 2 2 6 2 2 6 2 2 6
38765- 6 6 6 86 86 86 46 46 46 14 14 14
38766- 0 0 0 0 0 0 0 0 0 0 0 0
38767- 0 0 0 0 0 0 0 0 0 0 0 0
38768- 0 0 0 0 0 0 0 0 0 0 0 0
38769- 0 0 0 0 0 0 0 0 0 0 0 0
38770- 0 0 0 0 0 0 0 0 0 0 0 0
38771- 0 0 0 0 0 0 0 0 0 0 0 0
38772- 0 0 0 0 0 0 0 0 0 6 6 6
38773- 18 18 18 46 46 46 86 86 86 18 18 18
38774- 2 2 6 34 34 34 10 10 10 6 6 6
38775-210 210 210 253 253 253 253 253 253 253 253 253
38776-253 253 253 253 253 253 253 253 253 253 253 253
38777-253 253 253 253 253 253 234 234 234 242 242 242
38778-253 253 253 253 253 253 253 253 253 253 253 253
38779-253 253 253 253 253 253 253 253 253 253 253 253
38780-253 253 253 253 253 253 253 253 253 253 253 253
38781-253 253 253 253 253 253 253 253 253 253 253 253
38782-253 253 253 253 253 253 221 221 221 6 6 6
38783- 2 2 6 2 2 6 6 6 6 30 30 30
38784- 2 2 6 2 2 6 2 2 6 2 2 6
38785- 2 2 6 82 82 82 54 54 54 18 18 18
38786- 6 6 6 0 0 0 0 0 0 0 0 0
38787- 0 0 0 0 0 0 0 0 0 0 0 0
38788- 0 0 0 0 0 0 0 0 0 0 0 0
38789- 0 0 0 0 0 0 0 0 0 0 0 0
38790- 0 0 0 0 0 0 0 0 0 0 0 0
38791- 0 0 0 0 0 0 0 0 0 0 0 0
38792- 0 0 0 0 0 0 0 0 0 10 10 10
38793- 26 26 26 66 66 66 62 62 62 2 2 6
38794- 2 2 6 38 38 38 10 10 10 26 26 26
38795-238 238 238 253 253 253 253 253 253 253 253 253
38796-253 253 253 253 253 253 253 253 253 253 253 253
38797-253 253 253 253 253 253 231 231 231 238 238 238
38798-253 253 253 253 253 253 253 253 253 253 253 253
38799-253 253 253 253 253 253 253 253 253 253 253 253
38800-253 253 253 253 253 253 253 253 253 253 253 253
38801-253 253 253 253 253 253 253 253 253 253 253 253
38802-253 253 253 253 253 253 231 231 231 6 6 6
38803- 2 2 6 2 2 6 10 10 10 30 30 30
38804- 2 2 6 2 2 6 2 2 6 2 2 6
38805- 2 2 6 66 66 66 58 58 58 22 22 22
38806- 6 6 6 0 0 0 0 0 0 0 0 0
38807- 0 0 0 0 0 0 0 0 0 0 0 0
38808- 0 0 0 0 0 0 0 0 0 0 0 0
38809- 0 0 0 0 0 0 0 0 0 0 0 0
38810- 0 0 0 0 0 0 0 0 0 0 0 0
38811- 0 0 0 0 0 0 0 0 0 0 0 0
38812- 0 0 0 0 0 0 0 0 0 10 10 10
38813- 38 38 38 78 78 78 6 6 6 2 2 6
38814- 2 2 6 46 46 46 14 14 14 42 42 42
38815-246 246 246 253 253 253 253 253 253 253 253 253
38816-253 253 253 253 253 253 253 253 253 253 253 253
38817-253 253 253 253 253 253 231 231 231 242 242 242
38818-253 253 253 253 253 253 253 253 253 253 253 253
38819-253 253 253 253 253 253 253 253 253 253 253 253
38820-253 253 253 253 253 253 253 253 253 253 253 253
38821-253 253 253 253 253 253 253 253 253 253 253 253
38822-253 253 253 253 253 253 234 234 234 10 10 10
38823- 2 2 6 2 2 6 22 22 22 14 14 14
38824- 2 2 6 2 2 6 2 2 6 2 2 6
38825- 2 2 6 66 66 66 62 62 62 22 22 22
38826- 6 6 6 0 0 0 0 0 0 0 0 0
38827- 0 0 0 0 0 0 0 0 0 0 0 0
38828- 0 0 0 0 0 0 0 0 0 0 0 0
38829- 0 0 0 0 0 0 0 0 0 0 0 0
38830- 0 0 0 0 0 0 0 0 0 0 0 0
38831- 0 0 0 0 0 0 0 0 0 0 0 0
38832- 0 0 0 0 0 0 6 6 6 18 18 18
38833- 50 50 50 74 74 74 2 2 6 2 2 6
38834- 14 14 14 70 70 70 34 34 34 62 62 62
38835-250 250 250 253 253 253 253 253 253 253 253 253
38836-253 253 253 253 253 253 253 253 253 253 253 253
38837-253 253 253 253 253 253 231 231 231 246 246 246
38838-253 253 253 253 253 253 253 253 253 253 253 253
38839-253 253 253 253 253 253 253 253 253 253 253 253
38840-253 253 253 253 253 253 253 253 253 253 253 253
38841-253 253 253 253 253 253 253 253 253 253 253 253
38842-253 253 253 253 253 253 234 234 234 14 14 14
38843- 2 2 6 2 2 6 30 30 30 2 2 6
38844- 2 2 6 2 2 6 2 2 6 2 2 6
38845- 2 2 6 66 66 66 62 62 62 22 22 22
38846- 6 6 6 0 0 0 0 0 0 0 0 0
38847- 0 0 0 0 0 0 0 0 0 0 0 0
38848- 0 0 0 0 0 0 0 0 0 0 0 0
38849- 0 0 0 0 0 0 0 0 0 0 0 0
38850- 0 0 0 0 0 0 0 0 0 0 0 0
38851- 0 0 0 0 0 0 0 0 0 0 0 0
38852- 0 0 0 0 0 0 6 6 6 18 18 18
38853- 54 54 54 62 62 62 2 2 6 2 2 6
38854- 2 2 6 30 30 30 46 46 46 70 70 70
38855-250 250 250 253 253 253 253 253 253 253 253 253
38856-253 253 253 253 253 253 253 253 253 253 253 253
38857-253 253 253 253 253 253 231 231 231 246 246 246
38858-253 253 253 253 253 253 253 253 253 253 253 253
38859-253 253 253 253 253 253 253 253 253 253 253 253
38860-253 253 253 253 253 253 253 253 253 253 253 253
38861-253 253 253 253 253 253 253 253 253 253 253 253
38862-253 253 253 253 253 253 226 226 226 10 10 10
38863- 2 2 6 6 6 6 30 30 30 2 2 6
38864- 2 2 6 2 2 6 2 2 6 2 2 6
38865- 2 2 6 66 66 66 58 58 58 22 22 22
38866- 6 6 6 0 0 0 0 0 0 0 0 0
38867- 0 0 0 0 0 0 0 0 0 0 0 0
38868- 0 0 0 0 0 0 0 0 0 0 0 0
38869- 0 0 0 0 0 0 0 0 0 0 0 0
38870- 0 0 0 0 0 0 0 0 0 0 0 0
38871- 0 0 0 0 0 0 0 0 0 0 0 0
38872- 0 0 0 0 0 0 6 6 6 22 22 22
38873- 58 58 58 62 62 62 2 2 6 2 2 6
38874- 2 2 6 2 2 6 30 30 30 78 78 78
38875-250 250 250 253 253 253 253 253 253 253 253 253
38876-253 253 253 253 253 253 253 253 253 253 253 253
38877-253 253 253 253 253 253 231 231 231 246 246 246
38878-253 253 253 253 253 253 253 253 253 253 253 253
38879-253 253 253 253 253 253 253 253 253 253 253 253
38880-253 253 253 253 253 253 253 253 253 253 253 253
38881-253 253 253 253 253 253 253 253 253 253 253 253
38882-253 253 253 253 253 253 206 206 206 2 2 6
38883- 22 22 22 34 34 34 18 14 6 22 22 22
38884- 26 26 26 18 18 18 6 6 6 2 2 6
38885- 2 2 6 82 82 82 54 54 54 18 18 18
38886- 6 6 6 0 0 0 0 0 0 0 0 0
38887- 0 0 0 0 0 0 0 0 0 0 0 0
38888- 0 0 0 0 0 0 0 0 0 0 0 0
38889- 0 0 0 0 0 0 0 0 0 0 0 0
38890- 0 0 0 0 0 0 0 0 0 0 0 0
38891- 0 0 0 0 0 0 0 0 0 0 0 0
38892- 0 0 0 0 0 0 6 6 6 26 26 26
38893- 62 62 62 106 106 106 74 54 14 185 133 11
38894-210 162 10 121 92 8 6 6 6 62 62 62
38895-238 238 238 253 253 253 253 253 253 253 253 253
38896-253 253 253 253 253 253 253 253 253 253 253 253
38897-253 253 253 253 253 253 231 231 231 246 246 246
38898-253 253 253 253 253 253 253 253 253 253 253 253
38899-253 253 253 253 253 253 253 253 253 253 253 253
38900-253 253 253 253 253 253 253 253 253 253 253 253
38901-253 253 253 253 253 253 253 253 253 253 253 253
38902-253 253 253 253 253 253 158 158 158 18 18 18
38903- 14 14 14 2 2 6 2 2 6 2 2 6
38904- 6 6 6 18 18 18 66 66 66 38 38 38
38905- 6 6 6 94 94 94 50 50 50 18 18 18
38906- 6 6 6 0 0 0 0 0 0 0 0 0
38907- 0 0 0 0 0 0 0 0 0 0 0 0
38908- 0 0 0 0 0 0 0 0 0 0 0 0
38909- 0 0 0 0 0 0 0 0 0 0 0 0
38910- 0 0 0 0 0 0 0 0 0 0 0 0
38911- 0 0 0 0 0 0 0 0 0 6 6 6
38912- 10 10 10 10 10 10 18 18 18 38 38 38
38913- 78 78 78 142 134 106 216 158 10 242 186 14
38914-246 190 14 246 190 14 156 118 10 10 10 10
38915- 90 90 90 238 238 238 253 253 253 253 253 253
38916-253 253 253 253 253 253 253 253 253 253 253 253
38917-253 253 253 253 253 253 231 231 231 250 250 250
38918-253 253 253 253 253 253 253 253 253 253 253 253
38919-253 253 253 253 253 253 253 253 253 253 253 253
38920-253 253 253 253 253 253 253 253 253 253 253 253
38921-253 253 253 253 253 253 253 253 253 246 230 190
38922-238 204 91 238 204 91 181 142 44 37 26 9
38923- 2 2 6 2 2 6 2 2 6 2 2 6
38924- 2 2 6 2 2 6 38 38 38 46 46 46
38925- 26 26 26 106 106 106 54 54 54 18 18 18
38926- 6 6 6 0 0 0 0 0 0 0 0 0
38927- 0 0 0 0 0 0 0 0 0 0 0 0
38928- 0 0 0 0 0 0 0 0 0 0 0 0
38929- 0 0 0 0 0 0 0 0 0 0 0 0
38930- 0 0 0 0 0 0 0 0 0 0 0 0
38931- 0 0 0 6 6 6 14 14 14 22 22 22
38932- 30 30 30 38 38 38 50 50 50 70 70 70
38933-106 106 106 190 142 34 226 170 11 242 186 14
38934-246 190 14 246 190 14 246 190 14 154 114 10
38935- 6 6 6 74 74 74 226 226 226 253 253 253
38936-253 253 253 253 253 253 253 253 253 253 253 253
38937-253 253 253 253 253 253 231 231 231 250 250 250
38938-253 253 253 253 253 253 253 253 253 253 253 253
38939-253 253 253 253 253 253 253 253 253 253 253 253
38940-253 253 253 253 253 253 253 253 253 253 253 253
38941-253 253 253 253 253 253 253 253 253 228 184 62
38942-241 196 14 241 208 19 232 195 16 38 30 10
38943- 2 2 6 2 2 6 2 2 6 2 2 6
38944- 2 2 6 6 6 6 30 30 30 26 26 26
38945-203 166 17 154 142 90 66 66 66 26 26 26
38946- 6 6 6 0 0 0 0 0 0 0 0 0
38947- 0 0 0 0 0 0 0 0 0 0 0 0
38948- 0 0 0 0 0 0 0 0 0 0 0 0
38949- 0 0 0 0 0 0 0 0 0 0 0 0
38950- 0 0 0 0 0 0 0 0 0 0 0 0
38951- 6 6 6 18 18 18 38 38 38 58 58 58
38952- 78 78 78 86 86 86 101 101 101 123 123 123
38953-175 146 61 210 150 10 234 174 13 246 186 14
38954-246 190 14 246 190 14 246 190 14 238 190 10
38955-102 78 10 2 2 6 46 46 46 198 198 198
38956-253 253 253 253 253 253 253 253 253 253 253 253
38957-253 253 253 253 253 253 234 234 234 242 242 242
38958-253 253 253 253 253 253 253 253 253 253 253 253
38959-253 253 253 253 253 253 253 253 253 253 253 253
38960-253 253 253 253 253 253 253 253 253 253 253 253
38961-253 253 253 253 253 253 253 253 253 224 178 62
38962-242 186 14 241 196 14 210 166 10 22 18 6
38963- 2 2 6 2 2 6 2 2 6 2 2 6
38964- 2 2 6 2 2 6 6 6 6 121 92 8
38965-238 202 15 232 195 16 82 82 82 34 34 34
38966- 10 10 10 0 0 0 0 0 0 0 0 0
38967- 0 0 0 0 0 0 0 0 0 0 0 0
38968- 0 0 0 0 0 0 0 0 0 0 0 0
38969- 0 0 0 0 0 0 0 0 0 0 0 0
38970- 0 0 0 0 0 0 0 0 0 0 0 0
38971- 14 14 14 38 38 38 70 70 70 154 122 46
38972-190 142 34 200 144 11 197 138 11 197 138 11
38973-213 154 11 226 170 11 242 186 14 246 190 14
38974-246 190 14 246 190 14 246 190 14 246 190 14
38975-225 175 15 46 32 6 2 2 6 22 22 22
38976-158 158 158 250 250 250 253 253 253 253 253 253
38977-253 253 253 253 253 253 253 253 253 253 253 253
38978-253 253 253 253 253 253 253 253 253 253 253 253
38979-253 253 253 253 253 253 253 253 253 253 253 253
38980-253 253 253 253 253 253 253 253 253 253 253 253
38981-253 253 253 250 250 250 242 242 242 224 178 62
38982-239 182 13 236 186 11 213 154 11 46 32 6
38983- 2 2 6 2 2 6 2 2 6 2 2 6
38984- 2 2 6 2 2 6 61 42 6 225 175 15
38985-238 190 10 236 186 11 112 100 78 42 42 42
38986- 14 14 14 0 0 0 0 0 0 0 0 0
38987- 0 0 0 0 0 0 0 0 0 0 0 0
38988- 0 0 0 0 0 0 0 0 0 0 0 0
38989- 0 0 0 0 0 0 0 0 0 0 0 0
38990- 0 0 0 0 0 0 0 0 0 6 6 6
38991- 22 22 22 54 54 54 154 122 46 213 154 11
38992-226 170 11 230 174 11 226 170 11 226 170 11
38993-236 178 12 242 186 14 246 190 14 246 190 14
38994-246 190 14 246 190 14 246 190 14 246 190 14
38995-241 196 14 184 144 12 10 10 10 2 2 6
38996- 6 6 6 116 116 116 242 242 242 253 253 253
38997-253 253 253 253 253 253 253 253 253 253 253 253
38998-253 253 253 253 253 253 253 253 253 253 253 253
38999-253 253 253 253 253 253 253 253 253 253 253 253
39000-253 253 253 253 253 253 253 253 253 253 253 253
39001-253 253 253 231 231 231 198 198 198 214 170 54
39002-236 178 12 236 178 12 210 150 10 137 92 6
39003- 18 14 6 2 2 6 2 2 6 2 2 6
39004- 6 6 6 70 47 6 200 144 11 236 178 12
39005-239 182 13 239 182 13 124 112 88 58 58 58
39006- 22 22 22 6 6 6 0 0 0 0 0 0
39007- 0 0 0 0 0 0 0 0 0 0 0 0
39008- 0 0 0 0 0 0 0 0 0 0 0 0
39009- 0 0 0 0 0 0 0 0 0 0 0 0
39010- 0 0 0 0 0 0 0 0 0 10 10 10
39011- 30 30 30 70 70 70 180 133 36 226 170 11
39012-239 182 13 242 186 14 242 186 14 246 186 14
39013-246 190 14 246 190 14 246 190 14 246 190 14
39014-246 190 14 246 190 14 246 190 14 246 190 14
39015-246 190 14 232 195 16 98 70 6 2 2 6
39016- 2 2 6 2 2 6 66 66 66 221 221 221
39017-253 253 253 253 253 253 253 253 253 253 253 253
39018-253 253 253 253 253 253 253 253 253 253 253 253
39019-253 253 253 253 253 253 253 253 253 253 253 253
39020-253 253 253 253 253 253 253 253 253 253 253 253
39021-253 253 253 206 206 206 198 198 198 214 166 58
39022-230 174 11 230 174 11 216 158 10 192 133 9
39023-163 110 8 116 81 8 102 78 10 116 81 8
39024-167 114 7 197 138 11 226 170 11 239 182 13
39025-242 186 14 242 186 14 162 146 94 78 78 78
39026- 34 34 34 14 14 14 6 6 6 0 0 0
39027- 0 0 0 0 0 0 0 0 0 0 0 0
39028- 0 0 0 0 0 0 0 0 0 0 0 0
39029- 0 0 0 0 0 0 0 0 0 0 0 0
39030- 0 0 0 0 0 0 0 0 0 6 6 6
39031- 30 30 30 78 78 78 190 142 34 226 170 11
39032-239 182 13 246 190 14 246 190 14 246 190 14
39033-246 190 14 246 190 14 246 190 14 246 190 14
39034-246 190 14 246 190 14 246 190 14 246 190 14
39035-246 190 14 241 196 14 203 166 17 22 18 6
39036- 2 2 6 2 2 6 2 2 6 38 38 38
39037-218 218 218 253 253 253 253 253 253 253 253 253
39038-253 253 253 253 253 253 253 253 253 253 253 253
39039-253 253 253 253 253 253 253 253 253 253 253 253
39040-253 253 253 253 253 253 253 253 253 253 253 253
39041-250 250 250 206 206 206 198 198 198 202 162 69
39042-226 170 11 236 178 12 224 166 10 210 150 10
39043-200 144 11 197 138 11 192 133 9 197 138 11
39044-210 150 10 226 170 11 242 186 14 246 190 14
39045-246 190 14 246 186 14 225 175 15 124 112 88
39046- 62 62 62 30 30 30 14 14 14 6 6 6
39047- 0 0 0 0 0 0 0 0 0 0 0 0
39048- 0 0 0 0 0 0 0 0 0 0 0 0
39049- 0 0 0 0 0 0 0 0 0 0 0 0
39050- 0 0 0 0 0 0 0 0 0 10 10 10
39051- 30 30 30 78 78 78 174 135 50 224 166 10
39052-239 182 13 246 190 14 246 190 14 246 190 14
39053-246 190 14 246 190 14 246 190 14 246 190 14
39054-246 190 14 246 190 14 246 190 14 246 190 14
39055-246 190 14 246 190 14 241 196 14 139 102 15
39056- 2 2 6 2 2 6 2 2 6 2 2 6
39057- 78 78 78 250 250 250 253 253 253 253 253 253
39058-253 253 253 253 253 253 253 253 253 253 253 253
39059-253 253 253 253 253 253 253 253 253 253 253 253
39060-253 253 253 253 253 253 253 253 253 253 253 253
39061-250 250 250 214 214 214 198 198 198 190 150 46
39062-219 162 10 236 178 12 234 174 13 224 166 10
39063-216 158 10 213 154 11 213 154 11 216 158 10
39064-226 170 11 239 182 13 246 190 14 246 190 14
39065-246 190 14 246 190 14 242 186 14 206 162 42
39066-101 101 101 58 58 58 30 30 30 14 14 14
39067- 6 6 6 0 0 0 0 0 0 0 0 0
39068- 0 0 0 0 0 0 0 0 0 0 0 0
39069- 0 0 0 0 0 0 0 0 0 0 0 0
39070- 0 0 0 0 0 0 0 0 0 10 10 10
39071- 30 30 30 74 74 74 174 135 50 216 158 10
39072-236 178 12 246 190 14 246 190 14 246 190 14
39073-246 190 14 246 190 14 246 190 14 246 190 14
39074-246 190 14 246 190 14 246 190 14 246 190 14
39075-246 190 14 246 190 14 241 196 14 226 184 13
39076- 61 42 6 2 2 6 2 2 6 2 2 6
39077- 22 22 22 238 238 238 253 253 253 253 253 253
39078-253 253 253 253 253 253 253 253 253 253 253 253
39079-253 253 253 253 253 253 253 253 253 253 253 253
39080-253 253 253 253 253 253 253 253 253 253 253 253
39081-253 253 253 226 226 226 187 187 187 180 133 36
39082-216 158 10 236 178 12 239 182 13 236 178 12
39083-230 174 11 226 170 11 226 170 11 230 174 11
39084-236 178 12 242 186 14 246 190 14 246 190 14
39085-246 190 14 246 190 14 246 186 14 239 182 13
39086-206 162 42 106 106 106 66 66 66 34 34 34
39087- 14 14 14 6 6 6 0 0 0 0 0 0
39088- 0 0 0 0 0 0 0 0 0 0 0 0
39089- 0 0 0 0 0 0 0 0 0 0 0 0
39090- 0 0 0 0 0 0 0 0 0 6 6 6
39091- 26 26 26 70 70 70 163 133 67 213 154 11
39092-236 178 12 246 190 14 246 190 14 246 190 14
39093-246 190 14 246 190 14 246 190 14 246 190 14
39094-246 190 14 246 190 14 246 190 14 246 190 14
39095-246 190 14 246 190 14 246 190 14 241 196 14
39096-190 146 13 18 14 6 2 2 6 2 2 6
39097- 46 46 46 246 246 246 253 253 253 253 253 253
39098-253 253 253 253 253 253 253 253 253 253 253 253
39099-253 253 253 253 253 253 253 253 253 253 253 253
39100-253 253 253 253 253 253 253 253 253 253 253 253
39101-253 253 253 221 221 221 86 86 86 156 107 11
39102-216 158 10 236 178 12 242 186 14 246 186 14
39103-242 186 14 239 182 13 239 182 13 242 186 14
39104-242 186 14 246 186 14 246 190 14 246 190 14
39105-246 190 14 246 190 14 246 190 14 246 190 14
39106-242 186 14 225 175 15 142 122 72 66 66 66
39107- 30 30 30 10 10 10 0 0 0 0 0 0
39108- 0 0 0 0 0 0 0 0 0 0 0 0
39109- 0 0 0 0 0 0 0 0 0 0 0 0
39110- 0 0 0 0 0 0 0 0 0 6 6 6
39111- 26 26 26 70 70 70 163 133 67 210 150 10
39112-236 178 12 246 190 14 246 190 14 246 190 14
39113-246 190 14 246 190 14 246 190 14 246 190 14
39114-246 190 14 246 190 14 246 190 14 246 190 14
39115-246 190 14 246 190 14 246 190 14 246 190 14
39116-232 195 16 121 92 8 34 34 34 106 106 106
39117-221 221 221 253 253 253 253 253 253 253 253 253
39118-253 253 253 253 253 253 253 253 253 253 253 253
39119-253 253 253 253 253 253 253 253 253 253 253 253
39120-253 253 253 253 253 253 253 253 253 253 253 253
39121-242 242 242 82 82 82 18 14 6 163 110 8
39122-216 158 10 236 178 12 242 186 14 246 190 14
39123-246 190 14 246 190 14 246 190 14 246 190 14
39124-246 190 14 246 190 14 246 190 14 246 190 14
39125-246 190 14 246 190 14 246 190 14 246 190 14
39126-246 190 14 246 190 14 242 186 14 163 133 67
39127- 46 46 46 18 18 18 6 6 6 0 0 0
39128- 0 0 0 0 0 0 0 0 0 0 0 0
39129- 0 0 0 0 0 0 0 0 0 0 0 0
39130- 0 0 0 0 0 0 0 0 0 10 10 10
39131- 30 30 30 78 78 78 163 133 67 210 150 10
39132-236 178 12 246 186 14 246 190 14 246 190 14
39133-246 190 14 246 190 14 246 190 14 246 190 14
39134-246 190 14 246 190 14 246 190 14 246 190 14
39135-246 190 14 246 190 14 246 190 14 246 190 14
39136-241 196 14 215 174 15 190 178 144 253 253 253
39137-253 253 253 253 253 253 253 253 253 253 253 253
39138-253 253 253 253 253 253 253 253 253 253 253 253
39139-253 253 253 253 253 253 253 253 253 253 253 253
39140-253 253 253 253 253 253 253 253 253 218 218 218
39141- 58 58 58 2 2 6 22 18 6 167 114 7
39142-216 158 10 236 178 12 246 186 14 246 190 14
39143-246 190 14 246 190 14 246 190 14 246 190 14
39144-246 190 14 246 190 14 246 190 14 246 190 14
39145-246 190 14 246 190 14 246 190 14 246 190 14
39146-246 190 14 246 186 14 242 186 14 190 150 46
39147- 54 54 54 22 22 22 6 6 6 0 0 0
39148- 0 0 0 0 0 0 0 0 0 0 0 0
39149- 0 0 0 0 0 0 0 0 0 0 0 0
39150- 0 0 0 0 0 0 0 0 0 14 14 14
39151- 38 38 38 86 86 86 180 133 36 213 154 11
39152-236 178 12 246 186 14 246 190 14 246 190 14
39153-246 190 14 246 190 14 246 190 14 246 190 14
39154-246 190 14 246 190 14 246 190 14 246 190 14
39155-246 190 14 246 190 14 246 190 14 246 190 14
39156-246 190 14 232 195 16 190 146 13 214 214 214
39157-253 253 253 253 253 253 253 253 253 253 253 253
39158-253 253 253 253 253 253 253 253 253 253 253 253
39159-253 253 253 253 253 253 253 253 253 253 253 253
39160-253 253 253 250 250 250 170 170 170 26 26 26
39161- 2 2 6 2 2 6 37 26 9 163 110 8
39162-219 162 10 239 182 13 246 186 14 246 190 14
39163-246 190 14 246 190 14 246 190 14 246 190 14
39164-246 190 14 246 190 14 246 190 14 246 190 14
39165-246 190 14 246 190 14 246 190 14 246 190 14
39166-246 186 14 236 178 12 224 166 10 142 122 72
39167- 46 46 46 18 18 18 6 6 6 0 0 0
39168- 0 0 0 0 0 0 0 0 0 0 0 0
39169- 0 0 0 0 0 0 0 0 0 0 0 0
39170- 0 0 0 0 0 0 6 6 6 18 18 18
39171- 50 50 50 109 106 95 192 133 9 224 166 10
39172-242 186 14 246 190 14 246 190 14 246 190 14
39173-246 190 14 246 190 14 246 190 14 246 190 14
39174-246 190 14 246 190 14 246 190 14 246 190 14
39175-246 190 14 246 190 14 246 190 14 246 190 14
39176-242 186 14 226 184 13 210 162 10 142 110 46
39177-226 226 226 253 253 253 253 253 253 253 253 253
39178-253 253 253 253 253 253 253 253 253 253 253 253
39179-253 253 253 253 253 253 253 253 253 253 253 253
39180-198 198 198 66 66 66 2 2 6 2 2 6
39181- 2 2 6 2 2 6 50 34 6 156 107 11
39182-219 162 10 239 182 13 246 186 14 246 190 14
39183-246 190 14 246 190 14 246 190 14 246 190 14
39184-246 190 14 246 190 14 246 190 14 246 190 14
39185-246 190 14 246 190 14 246 190 14 242 186 14
39186-234 174 13 213 154 11 154 122 46 66 66 66
39187- 30 30 30 10 10 10 0 0 0 0 0 0
39188- 0 0 0 0 0 0 0 0 0 0 0 0
39189- 0 0 0 0 0 0 0 0 0 0 0 0
39190- 0 0 0 0 0 0 6 6 6 22 22 22
39191- 58 58 58 154 121 60 206 145 10 234 174 13
39192-242 186 14 246 186 14 246 190 14 246 190 14
39193-246 190 14 246 190 14 246 190 14 246 190 14
39194-246 190 14 246 190 14 246 190 14 246 190 14
39195-246 190 14 246 190 14 246 190 14 246 190 14
39196-246 186 14 236 178 12 210 162 10 163 110 8
39197- 61 42 6 138 138 138 218 218 218 250 250 250
39198-253 253 253 253 253 253 253 253 253 250 250 250
39199-242 242 242 210 210 210 144 144 144 66 66 66
39200- 6 6 6 2 2 6 2 2 6 2 2 6
39201- 2 2 6 2 2 6 61 42 6 163 110 8
39202-216 158 10 236 178 12 246 190 14 246 190 14
39203-246 190 14 246 190 14 246 190 14 246 190 14
39204-246 190 14 246 190 14 246 190 14 246 190 14
39205-246 190 14 239 182 13 230 174 11 216 158 10
39206-190 142 34 124 112 88 70 70 70 38 38 38
39207- 18 18 18 6 6 6 0 0 0 0 0 0
39208- 0 0 0 0 0 0 0 0 0 0 0 0
39209- 0 0 0 0 0 0 0 0 0 0 0 0
39210- 0 0 0 0 0 0 6 6 6 22 22 22
39211- 62 62 62 168 124 44 206 145 10 224 166 10
39212-236 178 12 239 182 13 242 186 14 242 186 14
39213-246 186 14 246 190 14 246 190 14 246 190 14
39214-246 190 14 246 190 14 246 190 14 246 190 14
39215-246 190 14 246 190 14 246 190 14 246 190 14
39216-246 190 14 236 178 12 216 158 10 175 118 6
39217- 80 54 7 2 2 6 6 6 6 30 30 30
39218- 54 54 54 62 62 62 50 50 50 38 38 38
39219- 14 14 14 2 2 6 2 2 6 2 2 6
39220- 2 2 6 2 2 6 2 2 6 2 2 6
39221- 2 2 6 6 6 6 80 54 7 167 114 7
39222-213 154 11 236 178 12 246 190 14 246 190 14
39223-246 190 14 246 190 14 246 190 14 246 190 14
39224-246 190 14 242 186 14 239 182 13 239 182 13
39225-230 174 11 210 150 10 174 135 50 124 112 88
39226- 82 82 82 54 54 54 34 34 34 18 18 18
39227- 6 6 6 0 0 0 0 0 0 0 0 0
39228- 0 0 0 0 0 0 0 0 0 0 0 0
39229- 0 0 0 0 0 0 0 0 0 0 0 0
39230- 0 0 0 0 0 0 6 6 6 18 18 18
39231- 50 50 50 158 118 36 192 133 9 200 144 11
39232-216 158 10 219 162 10 224 166 10 226 170 11
39233-230 174 11 236 178 12 239 182 13 239 182 13
39234-242 186 14 246 186 14 246 190 14 246 190 14
39235-246 190 14 246 190 14 246 190 14 246 190 14
39236-246 186 14 230 174 11 210 150 10 163 110 8
39237-104 69 6 10 10 10 2 2 6 2 2 6
39238- 2 2 6 2 2 6 2 2 6 2 2 6
39239- 2 2 6 2 2 6 2 2 6 2 2 6
39240- 2 2 6 2 2 6 2 2 6 2 2 6
39241- 2 2 6 6 6 6 91 60 6 167 114 7
39242-206 145 10 230 174 11 242 186 14 246 190 14
39243-246 190 14 246 190 14 246 186 14 242 186 14
39244-239 182 13 230 174 11 224 166 10 213 154 11
39245-180 133 36 124 112 88 86 86 86 58 58 58
39246- 38 38 38 22 22 22 10 10 10 6 6 6
39247- 0 0 0 0 0 0 0 0 0 0 0 0
39248- 0 0 0 0 0 0 0 0 0 0 0 0
39249- 0 0 0 0 0 0 0 0 0 0 0 0
39250- 0 0 0 0 0 0 0 0 0 14 14 14
39251- 34 34 34 70 70 70 138 110 50 158 118 36
39252-167 114 7 180 123 7 192 133 9 197 138 11
39253-200 144 11 206 145 10 213 154 11 219 162 10
39254-224 166 10 230 174 11 239 182 13 242 186 14
39255-246 186 14 246 186 14 246 186 14 246 186 14
39256-239 182 13 216 158 10 185 133 11 152 99 6
39257-104 69 6 18 14 6 2 2 6 2 2 6
39258- 2 2 6 2 2 6 2 2 6 2 2 6
39259- 2 2 6 2 2 6 2 2 6 2 2 6
39260- 2 2 6 2 2 6 2 2 6 2 2 6
39261- 2 2 6 6 6 6 80 54 7 152 99 6
39262-192 133 9 219 162 10 236 178 12 239 182 13
39263-246 186 14 242 186 14 239 182 13 236 178 12
39264-224 166 10 206 145 10 192 133 9 154 121 60
39265- 94 94 94 62 62 62 42 42 42 22 22 22
39266- 14 14 14 6 6 6 0 0 0 0 0 0
39267- 0 0 0 0 0 0 0 0 0 0 0 0
39268- 0 0 0 0 0 0 0 0 0 0 0 0
39269- 0 0 0 0 0 0 0 0 0 0 0 0
39270- 0 0 0 0 0 0 0 0 0 6 6 6
39271- 18 18 18 34 34 34 58 58 58 78 78 78
39272-101 98 89 124 112 88 142 110 46 156 107 11
39273-163 110 8 167 114 7 175 118 6 180 123 7
39274-185 133 11 197 138 11 210 150 10 219 162 10
39275-226 170 11 236 178 12 236 178 12 234 174 13
39276-219 162 10 197 138 11 163 110 8 130 83 6
39277- 91 60 6 10 10 10 2 2 6 2 2 6
39278- 18 18 18 38 38 38 38 38 38 38 38 38
39279- 38 38 38 38 38 38 38 38 38 38 38 38
39280- 38 38 38 38 38 38 26 26 26 2 2 6
39281- 2 2 6 6 6 6 70 47 6 137 92 6
39282-175 118 6 200 144 11 219 162 10 230 174 11
39283-234 174 13 230 174 11 219 162 10 210 150 10
39284-192 133 9 163 110 8 124 112 88 82 82 82
39285- 50 50 50 30 30 30 14 14 14 6 6 6
39286- 0 0 0 0 0 0 0 0 0 0 0 0
39287- 0 0 0 0 0 0 0 0 0 0 0 0
39288- 0 0 0 0 0 0 0 0 0 0 0 0
39289- 0 0 0 0 0 0 0 0 0 0 0 0
39290- 0 0 0 0 0 0 0 0 0 0 0 0
39291- 6 6 6 14 14 14 22 22 22 34 34 34
39292- 42 42 42 58 58 58 74 74 74 86 86 86
39293-101 98 89 122 102 70 130 98 46 121 87 25
39294-137 92 6 152 99 6 163 110 8 180 123 7
39295-185 133 11 197 138 11 206 145 10 200 144 11
39296-180 123 7 156 107 11 130 83 6 104 69 6
39297- 50 34 6 54 54 54 110 110 110 101 98 89
39298- 86 86 86 82 82 82 78 78 78 78 78 78
39299- 78 78 78 78 78 78 78 78 78 78 78 78
39300- 78 78 78 82 82 82 86 86 86 94 94 94
39301-106 106 106 101 101 101 86 66 34 124 80 6
39302-156 107 11 180 123 7 192 133 9 200 144 11
39303-206 145 10 200 144 11 192 133 9 175 118 6
39304-139 102 15 109 106 95 70 70 70 42 42 42
39305- 22 22 22 10 10 10 0 0 0 0 0 0
39306- 0 0 0 0 0 0 0 0 0 0 0 0
39307- 0 0 0 0 0 0 0 0 0 0 0 0
39308- 0 0 0 0 0 0 0 0 0 0 0 0
39309- 0 0 0 0 0 0 0 0 0 0 0 0
39310- 0 0 0 0 0 0 0 0 0 0 0 0
39311- 0 0 0 0 0 0 6 6 6 10 10 10
39312- 14 14 14 22 22 22 30 30 30 38 38 38
39313- 50 50 50 62 62 62 74 74 74 90 90 90
39314-101 98 89 112 100 78 121 87 25 124 80 6
39315-137 92 6 152 99 6 152 99 6 152 99 6
39316-138 86 6 124 80 6 98 70 6 86 66 30
39317-101 98 89 82 82 82 58 58 58 46 46 46
39318- 38 38 38 34 34 34 34 34 34 34 34 34
39319- 34 34 34 34 34 34 34 34 34 34 34 34
39320- 34 34 34 34 34 34 38 38 38 42 42 42
39321- 54 54 54 82 82 82 94 86 76 91 60 6
39322-134 86 6 156 107 11 167 114 7 175 118 6
39323-175 118 6 167 114 7 152 99 6 121 87 25
39324-101 98 89 62 62 62 34 34 34 18 18 18
39325- 6 6 6 0 0 0 0 0 0 0 0 0
39326- 0 0 0 0 0 0 0 0 0 0 0 0
39327- 0 0 0 0 0 0 0 0 0 0 0 0
39328- 0 0 0 0 0 0 0 0 0 0 0 0
39329- 0 0 0 0 0 0 0 0 0 0 0 0
39330- 0 0 0 0 0 0 0 0 0 0 0 0
39331- 0 0 0 0 0 0 0 0 0 0 0 0
39332- 0 0 0 6 6 6 6 6 6 10 10 10
39333- 18 18 18 22 22 22 30 30 30 42 42 42
39334- 50 50 50 66 66 66 86 86 86 101 98 89
39335-106 86 58 98 70 6 104 69 6 104 69 6
39336-104 69 6 91 60 6 82 62 34 90 90 90
39337- 62 62 62 38 38 38 22 22 22 14 14 14
39338- 10 10 10 10 10 10 10 10 10 10 10 10
39339- 10 10 10 10 10 10 6 6 6 10 10 10
39340- 10 10 10 10 10 10 10 10 10 14 14 14
39341- 22 22 22 42 42 42 70 70 70 89 81 66
39342- 80 54 7 104 69 6 124 80 6 137 92 6
39343-134 86 6 116 81 8 100 82 52 86 86 86
39344- 58 58 58 30 30 30 14 14 14 6 6 6
39345- 0 0 0 0 0 0 0 0 0 0 0 0
39346- 0 0 0 0 0 0 0 0 0 0 0 0
39347- 0 0 0 0 0 0 0 0 0 0 0 0
39348- 0 0 0 0 0 0 0 0 0 0 0 0
39349- 0 0 0 0 0 0 0 0 0 0 0 0
39350- 0 0 0 0 0 0 0 0 0 0 0 0
39351- 0 0 0 0 0 0 0 0 0 0 0 0
39352- 0 0 0 0 0 0 0 0 0 0 0 0
39353- 0 0 0 6 6 6 10 10 10 14 14 14
39354- 18 18 18 26 26 26 38 38 38 54 54 54
39355- 70 70 70 86 86 86 94 86 76 89 81 66
39356- 89 81 66 86 86 86 74 74 74 50 50 50
39357- 30 30 30 14 14 14 6 6 6 0 0 0
39358- 0 0 0 0 0 0 0 0 0 0 0 0
39359- 0 0 0 0 0 0 0 0 0 0 0 0
39360- 0 0 0 0 0 0 0 0 0 0 0 0
39361- 6 6 6 18 18 18 34 34 34 58 58 58
39362- 82 82 82 89 81 66 89 81 66 89 81 66
39363- 94 86 66 94 86 76 74 74 74 50 50 50
39364- 26 26 26 14 14 14 6 6 6 0 0 0
39365- 0 0 0 0 0 0 0 0 0 0 0 0
39366- 0 0 0 0 0 0 0 0 0 0 0 0
39367- 0 0 0 0 0 0 0 0 0 0 0 0
39368- 0 0 0 0 0 0 0 0 0 0 0 0
39369- 0 0 0 0 0 0 0 0 0 0 0 0
39370- 0 0 0 0 0 0 0 0 0 0 0 0
39371- 0 0 0 0 0 0 0 0 0 0 0 0
39372- 0 0 0 0 0 0 0 0 0 0 0 0
39373- 0 0 0 0 0 0 0 0 0 0 0 0
39374- 6 6 6 6 6 6 14 14 14 18 18 18
39375- 30 30 30 38 38 38 46 46 46 54 54 54
39376- 50 50 50 42 42 42 30 30 30 18 18 18
39377- 10 10 10 0 0 0 0 0 0 0 0 0
39378- 0 0 0 0 0 0 0 0 0 0 0 0
39379- 0 0 0 0 0 0 0 0 0 0 0 0
39380- 0 0 0 0 0 0 0 0 0 0 0 0
39381- 0 0 0 6 6 6 14 14 14 26 26 26
39382- 38 38 38 50 50 50 58 58 58 58 58 58
39383- 54 54 54 42 42 42 30 30 30 18 18 18
39384- 10 10 10 0 0 0 0 0 0 0 0 0
39385- 0 0 0 0 0 0 0 0 0 0 0 0
39386- 0 0 0 0 0 0 0 0 0 0 0 0
39387- 0 0 0 0 0 0 0 0 0 0 0 0
39388- 0 0 0 0 0 0 0 0 0 0 0 0
39389- 0 0 0 0 0 0 0 0 0 0 0 0
39390- 0 0 0 0 0 0 0 0 0 0 0 0
39391- 0 0 0 0 0 0 0 0 0 0 0 0
39392- 0 0 0 0 0 0 0 0 0 0 0 0
39393- 0 0 0 0 0 0 0 0 0 0 0 0
39394- 0 0 0 0 0 0 0 0 0 6 6 6
39395- 6 6 6 10 10 10 14 14 14 18 18 18
39396- 18 18 18 14 14 14 10 10 10 6 6 6
39397- 0 0 0 0 0 0 0 0 0 0 0 0
39398- 0 0 0 0 0 0 0 0 0 0 0 0
39399- 0 0 0 0 0 0 0 0 0 0 0 0
39400- 0 0 0 0 0 0 0 0 0 0 0 0
39401- 0 0 0 0 0 0 0 0 0 6 6 6
39402- 14 14 14 18 18 18 22 22 22 22 22 22
39403- 18 18 18 14 14 14 10 10 10 6 6 6
39404- 0 0 0 0 0 0 0 0 0 0 0 0
39405- 0 0 0 0 0 0 0 0 0 0 0 0
39406- 0 0 0 0 0 0 0 0 0 0 0 0
39407- 0 0 0 0 0 0 0 0 0 0 0 0
39408- 0 0 0 0 0 0 0 0 0 0 0 0
39409+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39410+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39411+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39412+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39415+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39416+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39417+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39419+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39420+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39421+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39422+4 4 4 4 4 4
39423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39424+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39425+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39426+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39428+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39429+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39430+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39433+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39434+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39435+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39436+4 4 4 4 4 4
39437+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39438+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39439+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39442+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39443+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39444+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39447+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39448+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39450+4 4 4 4 4 4
39451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39452+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39453+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39454+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39455+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39456+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39457+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39458+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39459+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39461+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39462+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39463+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39464+4 4 4 4 4 4
39465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39466+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39467+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39468+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39469+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39470+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39471+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39472+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39475+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39476+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39477+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39478+4 4 4 4 4 4
39479+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39480+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39481+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39482+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39483+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39484+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39485+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39486+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39489+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39490+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39491+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39492+4 4 4 4 4 4
39493+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39494+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39495+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39496+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39497+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
39498+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
39499+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39502+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
39503+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
39504+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
39505+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39506+4 4 4 4 4 4
39507+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39508+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39509+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39510+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39511+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
39512+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
39513+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39516+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
39517+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
39518+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
39519+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39520+4 4 4 4 4 4
39521+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39522+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39523+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39524+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39525+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
39526+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
39527+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
39528+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39530+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
39531+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
39532+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
39533+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
39534+4 4 4 4 4 4
39535+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39536+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39537+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39538+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
39539+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
39540+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
39541+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
39542+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39543+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
39544+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
39545+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
39546+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
39547+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
39548+4 4 4 4 4 4
39549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39550+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39551+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39552+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
39553+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
39554+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
39555+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
39556+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
39557+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
39558+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
39559+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
39560+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
39561+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
39562+4 4 4 4 4 4
39563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39564+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39565+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
39566+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
39567+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
39568+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
39569+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
39570+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
39571+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
39572+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
39573+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
39574+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
39575+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
39576+4 4 4 4 4 4
39577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39578+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39579+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
39580+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
39581+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
39582+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
39583+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
39584+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
39585+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
39586+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
39587+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
39588+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
39589+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
39590+4 4 4 4 4 4
39591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39592+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39593+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
39594+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
39595+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
39596+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
39597+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
39598+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
39599+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
39600+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
39601+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
39602+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
39603+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
39604+4 4 4 4 4 4
39605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39607+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
39608+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
39609+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
39610+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
39611+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
39612+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
39613+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
39614+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
39615+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
39616+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
39617+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
39618+4 4 4 4 4 4
39619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39621+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
39622+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
39623+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
39624+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
39625+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
39626+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
39627+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
39628+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
39629+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
39630+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
39631+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
39632+4 4 4 4 4 4
39633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39634+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
39635+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
39636+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
39637+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
39638+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
39639+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
39640+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
39641+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
39642+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
39643+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
39644+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
39645+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
39646+4 4 4 4 4 4
39647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39648+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
39649+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
39650+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
39651+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
39652+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
39653+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
39654+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
39655+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
39656+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
39657+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
39658+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
39659+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
39660+0 0 0 4 4 4
39661+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
39662+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
39663+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
39664+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
39665+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
39666+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
39667+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
39668+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
39669+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
39670+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
39671+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
39672+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
39673+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
39674+2 0 0 0 0 0
39675+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
39676+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
39677+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
39678+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
39679+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
39680+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
39681+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
39682+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
39683+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
39684+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
39685+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
39686+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
39687+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
39688+37 38 37 0 0 0
39689+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
39690+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
39691+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
39692+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
39693+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
39694+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
39695+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
39696+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
39697+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
39698+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
39699+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
39700+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
39701+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
39702+85 115 134 4 0 0
39703+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
39704+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
39705+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
39706+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
39707+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
39708+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
39709+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
39710+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
39711+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
39712+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
39713+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
39714+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
39715+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
39716+60 73 81 4 0 0
39717+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
39718+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
39719+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
39720+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
39721+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
39722+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
39723+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
39724+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
39725+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
39726+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
39727+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
39728+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
39729+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
39730+16 19 21 4 0 0
39731+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
39732+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
39733+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
39734+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
39735+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
39736+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
39737+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
39738+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
39739+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
39740+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
39741+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
39742+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
39743+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
39744+4 0 0 4 3 3
39745+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
39746+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
39747+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
39748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
39749+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
39750+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
39751+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
39752+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
39753+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
39754+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
39755+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
39756+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
39757+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
39758+3 2 2 4 4 4
39759+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
39760+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
39761+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
39762+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
39763+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
39764+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
39765+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
39766+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
39767+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
39768+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
39769+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
39770+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
39771+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
39772+4 4 4 4 4 4
39773+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
39774+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
39775+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
39776+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
39777+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
39778+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
39779+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
39780+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
39781+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
39782+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
39783+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
39784+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
39785+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
39786+4 4 4 4 4 4
39787+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
39788+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
39789+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
39790+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
39791+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
39792+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
39793+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
39794+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
39795+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
39796+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
39797+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
39798+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
39799+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
39800+5 5 5 5 5 5
39801+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
39802+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
39803+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
39804+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
39805+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
39806+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
39807+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
39808+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
39809+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
39810+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
39811+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
39812+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
39813+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
39814+5 5 5 4 4 4
39815+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
39816+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
39817+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
39818+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
39819+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
39820+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
39821+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
39822+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
39823+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
39824+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
39825+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
39826+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
39827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39828+4 4 4 4 4 4
39829+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
39830+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
39831+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
39832+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
39833+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
39834+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
39835+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
39836+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
39837+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
39838+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
39839+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
39840+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
39841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39842+4 4 4 4 4 4
39843+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
39844+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
39845+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
39846+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
39847+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
39848+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
39849+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
39850+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
39851+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
39852+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
39853+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
39854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39856+4 4 4 4 4 4
39857+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
39858+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
39859+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
39860+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
39861+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
39862+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
39863+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
39864+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
39865+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
39866+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
39867+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
39868+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39870+4 4 4 4 4 4
39871+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
39872+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
39873+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
39874+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
39875+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
39876+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
39877+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
39878+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
39879+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
39880+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
39881+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39882+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39884+4 4 4 4 4 4
39885+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
39886+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
39887+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
39888+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
39889+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
39890+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
39891+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
39892+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
39893+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
39894+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
39895+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
39896+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39897+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39898+4 4 4 4 4 4
39899+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
39900+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
39901+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
39902+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
39903+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
39904+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
39905+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
39906+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
39907+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
39908+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
39909+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
39910+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39911+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39912+4 4 4 4 4 4
39913+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
39914+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
39915+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
39916+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
39917+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
39918+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
39919+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
39920+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
39921+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
39922+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
39923+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39924+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39925+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39926+4 4 4 4 4 4
39927+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
39928+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
39929+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
39930+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
39931+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
39932+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
39933+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
39934+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
39935+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
39936+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
39937+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39938+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39939+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39940+4 4 4 4 4 4
39941+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
39942+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
39943+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
39944+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
39945+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
39946+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
39947+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
39948+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
39949+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
39950+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
39951+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39952+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39953+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39954+4 4 4 4 4 4
39955+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
39956+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
39957+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
39958+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
39959+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
39960+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
39961+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
39962+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
39963+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
39964+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
39965+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39966+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39967+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39968+4 4 4 4 4 4
39969+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
39970+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
39971+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
39972+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
39973+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
39974+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
39975+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
39976+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
39977+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
39978+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
39979+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39980+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39981+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39982+4 4 4 4 4 4
39983+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
39984+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
39985+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
39986+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
39987+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
39988+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
39989+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
39990+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
39991+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
39992+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
39993+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39994+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39995+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39996+4 4 4 4 4 4
39997+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
39998+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
39999+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40000+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
40001+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
40002+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
40003+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
40004+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
40005+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40006+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40007+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40008+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40009+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40010+4 4 4 4 4 4
40011+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
40012+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
40013+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40014+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
40015+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
40016+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
40017+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
40018+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
40019+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40020+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40021+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40022+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40023+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40024+4 4 4 4 4 4
40025+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
40026+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
40027+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40028+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
40029+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
40030+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
40031+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
40032+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
40033+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40034+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40035+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40036+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40037+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40038+4 4 4 4 4 4
40039+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
40040+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
40041+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40042+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
40043+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
40044+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
40045+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
40046+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
40047+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
40048+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40049+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40050+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40051+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40052+4 4 4 4 4 4
40053+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
40054+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
40055+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
40056+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
40057+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
40058+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
40059+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
40060+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
40061+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40062+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40063+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40064+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40065+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40066+4 4 4 4 4 4
40067+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40068+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
40069+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40070+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
40071+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
40072+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
40073+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
40074+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
40075+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40076+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40077+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40078+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40079+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40080+4 4 4 4 4 4
40081+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
40082+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
40083+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
40084+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
40085+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
40086+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
40087+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40088+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
40089+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40090+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40091+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40092+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40093+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40094+4 4 4 4 4 4
40095+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40096+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
40097+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
40098+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
40099+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
40100+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
40101+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40102+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
40103+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40104+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40105+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40106+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40108+4 4 4 4 4 4
40109+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
40110+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
40111+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
40112+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
40113+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
40114+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
40115+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
40116+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
40117+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
40118+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40119+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40120+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40122+4 4 4 4 4 4
40123+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40124+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
40125+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
40126+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
40127+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
40128+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
40129+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
40130+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
40131+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
40132+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40133+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40134+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40136+4 4 4 4 4 4
40137+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
40138+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
40139+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
40140+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
40141+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
40142+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
40143+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
40144+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
40145+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
40146+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40147+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40148+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40150+4 4 4 4 4 4
40151+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40152+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
40153+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
40154+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
40155+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
40156+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
40157+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
40158+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
40159+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
40160+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40161+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40162+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40164+4 4 4 4 4 4
40165+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
40166+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
40167+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
40168+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
40169+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
40170+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
40171+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
40172+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
40173+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
40174+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
40175+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40178+4 4 4 4 4 4
40179+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
40180+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
40181+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
40182+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
40183+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
40184+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
40185+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
40186+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
40187+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
40188+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
40189+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40192+4 4 4 4 4 4
40193+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
40194+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
40195+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
40196+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
40197+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
40198+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
40199+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40200+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
40201+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
40202+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
40203+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40206+4 4 4 4 4 4
40207+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
40208+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
40209+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
40210+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
40211+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
40212+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
40213+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
40214+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
40215+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
40216+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
40217+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40220+4 4 4 4 4 4
40221+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
40222+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
40223+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
40224+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
40225+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
40226+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
40227+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
40228+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
40229+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
40230+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
40231+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40232+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40234+4 4 4 4 4 4
40235+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40236+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
40237+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
40238+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
40239+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
40240+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
40241+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
40242+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
40243+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
40244+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
40245+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40246+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40248+4 4 4 4 4 4
40249+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
40250+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
40251+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
40252+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
40253+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
40254+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
40255+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
40256+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
40257+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
40258+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
40259+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40260+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40261+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40262+4 4 4 4 4 4
40263+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
40264+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
40265+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
40266+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
40267+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
40268+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
40269+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
40270+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
40271+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40272+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40274+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40276+4 4 4 4 4 4
40277+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
40278+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40279+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
40280+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
40281+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
40282+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
40283+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
40284+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
40285+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
40286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40288+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40290+4 4 4 4 4 4
40291+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
40292+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
40293+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
40294+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
40295+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
40296+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
40297+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
40298+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
40299+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
40300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40302+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40304+4 4 4 4 4 4
40305+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
40306+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
40307+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
40308+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
40309+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
40310+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
40311+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
40312+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
40313+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40316+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40318+4 4 4 4 4 4
40319+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
40320+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
40321+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
40322+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
40323+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
40324+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
40325+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
40326+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
40327+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40329+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40330+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40332+4 4 4 4 4 4
40333+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
40334+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
40335+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
40336+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
40337+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
40338+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
40339+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
40340+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
40341+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40346+4 4 4 4 4 4
40347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40348+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
40349+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
40350+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
40351+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
40352+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
40353+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
40354+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
40355+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40357+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40358+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40359+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40360+4 4 4 4 4 4
40361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40362+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
40363+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
40364+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
40365+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
40366+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
40367+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
40368+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
40369+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40372+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40373+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40374+4 4 4 4 4 4
40375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40376+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40377+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
40378+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
40379+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
40380+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
40381+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
40382+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40383+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40386+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40387+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40388+4 4 4 4 4 4
40389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40391+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
40392+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
40393+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
40394+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
40395+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
40396+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40397+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40400+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40401+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40402+4 4 4 4 4 4
40403+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40404+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40405+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40406+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
40407+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
40408+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
40409+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
40410+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40411+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40412+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40415+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40416+4 4 4 4 4 4
40417+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40419+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40420+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
40421+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
40422+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
40423+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
40424+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40425+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40426+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40428+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40429+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40430+4 4 4 4 4 4
40431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40433+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40434+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
40435+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40436+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
40437+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
40438+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40439+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40442+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40443+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40444+4 4 4 4 4 4
40445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40447+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40448+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
40449+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
40450+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
40451+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
40452+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40453+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40454+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40455+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40456+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40457+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40458+4 4 4 4 4 4
40459+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40461+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40462+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40463+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
40464+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
40465+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40466+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40467+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40468+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40469+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40470+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40471+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40472+4 4 4 4 4 4
40473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40475+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40476+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40477+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
40478+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
40479+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40480+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40481+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40482+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40483+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40484+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40485+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40486+4 4 4 4 4 4
40487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40489+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40490+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40491+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
40492+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
40493+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40494+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40495+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40496+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40497+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40498+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40499+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40500+4 4 4 4 4 4
40501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40502+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40503+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40504+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40505+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
40506+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
40507+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40508+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40509+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40510+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40511+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40512+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40513+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40514+4 4 4 4 4 4
40515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40516+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40517+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40518+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40519+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
40520+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
40521+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40522+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40523+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40524+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40525+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40526+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40527+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40528+4 4 4 4 4 4
40529diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
40530index a40c05e..785c583 100644
40531--- a/drivers/video/udlfb.c
40532+++ b/drivers/video/udlfb.c
40533@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
40534 dlfb_urb_completion(urb);
40535
40536 error:
40537- atomic_add(bytes_sent, &dev->bytes_sent);
40538- atomic_add(bytes_identical, &dev->bytes_identical);
40539- atomic_add(width*height*2, &dev->bytes_rendered);
40540+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
40541+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
40542+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
40543 end_cycles = get_cycles();
40544- atomic_add(((unsigned int) ((end_cycles - start_cycles)
40545+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
40546 >> 10)), /* Kcycles */
40547 &dev->cpu_kcycles_used);
40548
40549@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
40550 dlfb_urb_completion(urb);
40551
40552 error:
40553- atomic_add(bytes_sent, &dev->bytes_sent);
40554- atomic_add(bytes_identical, &dev->bytes_identical);
40555- atomic_add(bytes_rendered, &dev->bytes_rendered);
40556+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
40557+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
40558+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
40559 end_cycles = get_cycles();
40560- atomic_add(((unsigned int) ((end_cycles - start_cycles)
40561+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
40562 >> 10)), /* Kcycles */
40563 &dev->cpu_kcycles_used);
40564 }
40565@@ -1368,7 +1368,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
40566 struct fb_info *fb_info = dev_get_drvdata(fbdev);
40567 struct dlfb_data *dev = fb_info->par;
40568 return snprintf(buf, PAGE_SIZE, "%u\n",
40569- atomic_read(&dev->bytes_rendered));
40570+ atomic_read_unchecked(&dev->bytes_rendered));
40571 }
40572
40573 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
40574@@ -1376,7 +1376,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
40575 struct fb_info *fb_info = dev_get_drvdata(fbdev);
40576 struct dlfb_data *dev = fb_info->par;
40577 return snprintf(buf, PAGE_SIZE, "%u\n",
40578- atomic_read(&dev->bytes_identical));
40579+ atomic_read_unchecked(&dev->bytes_identical));
40580 }
40581
40582 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
40583@@ -1384,7 +1384,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
40584 struct fb_info *fb_info = dev_get_drvdata(fbdev);
40585 struct dlfb_data *dev = fb_info->par;
40586 return snprintf(buf, PAGE_SIZE, "%u\n",
40587- atomic_read(&dev->bytes_sent));
40588+ atomic_read_unchecked(&dev->bytes_sent));
40589 }
40590
40591 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
40592@@ -1392,7 +1392,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
40593 struct fb_info *fb_info = dev_get_drvdata(fbdev);
40594 struct dlfb_data *dev = fb_info->par;
40595 return snprintf(buf, PAGE_SIZE, "%u\n",
40596- atomic_read(&dev->cpu_kcycles_used));
40597+ atomic_read_unchecked(&dev->cpu_kcycles_used));
40598 }
40599
40600 static ssize_t edid_show(
40601@@ -1449,10 +1449,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
40602 struct fb_info *fb_info = dev_get_drvdata(fbdev);
40603 struct dlfb_data *dev = fb_info->par;
40604
40605- atomic_set(&dev->bytes_rendered, 0);
40606- atomic_set(&dev->bytes_identical, 0);
40607- atomic_set(&dev->bytes_sent, 0);
40608- atomic_set(&dev->cpu_kcycles_used, 0);
40609+ atomic_set_unchecked(&dev->bytes_rendered, 0);
40610+ atomic_set_unchecked(&dev->bytes_identical, 0);
40611+ atomic_set_unchecked(&dev->bytes_sent, 0);
40612+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
40613
40614 return count;
40615 }
40616diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
40617index e7f69ef..83af4fd 100644
40618--- a/drivers/video/uvesafb.c
40619+++ b/drivers/video/uvesafb.c
40620@@ -19,6 +19,7 @@
40621 #include <linux/io.h>
40622 #include <linux/mutex.h>
40623 #include <linux/slab.h>
40624+#include <linux/moduleloader.h>
40625 #include <video/edid.h>
40626 #include <video/uvesafb.h>
40627 #ifdef CONFIG_X86
40628@@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
40629 NULL,
40630 };
40631
40632- return call_usermodehelper(v86d_path, argv, envp, 1);
40633+ return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
40634 }
40635
40636 /*
40637@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
40638 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
40639 par->pmi_setpal = par->ypan = 0;
40640 } else {
40641+
40642+#ifdef CONFIG_PAX_KERNEXEC
40643+#ifdef CONFIG_MODULES
40644+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
40645+#endif
40646+ if (!par->pmi_code) {
40647+ par->pmi_setpal = par->ypan = 0;
40648+ return 0;
40649+ }
40650+#endif
40651+
40652 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
40653 + task->t.regs.edi);
40654+
40655+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40656+ pax_open_kernel();
40657+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
40658+ pax_close_kernel();
40659+
40660+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
40661+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
40662+#else
40663 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
40664 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
40665+#endif
40666+
40667 printk(KERN_INFO "uvesafb: protected mode interface info at "
40668 "%04x:%04x\n",
40669 (u16)task->t.regs.es, (u16)task->t.regs.edi);
40670@@ -1821,6 +1844,11 @@ out:
40671 if (par->vbe_modes)
40672 kfree(par->vbe_modes);
40673
40674+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40675+ if (par->pmi_code)
40676+ module_free_exec(NULL, par->pmi_code);
40677+#endif
40678+
40679 framebuffer_release(info);
40680 return err;
40681 }
40682@@ -1847,6 +1875,12 @@ static int uvesafb_remove(struct platform_device *dev)
40683 kfree(par->vbe_state_orig);
40684 if (par->vbe_state_saved)
40685 kfree(par->vbe_state_saved);
40686+
40687+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40688+ if (par->pmi_code)
40689+ module_free_exec(NULL, par->pmi_code);
40690+#endif
40691+
40692 }
40693
40694 framebuffer_release(info);
40695diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
40696index 501b340..86bd4cf 100644
40697--- a/drivers/video/vesafb.c
40698+++ b/drivers/video/vesafb.c
40699@@ -9,6 +9,7 @@
40700 */
40701
40702 #include <linux/module.h>
40703+#include <linux/moduleloader.h>
40704 #include <linux/kernel.h>
40705 #include <linux/errno.h>
40706 #include <linux/string.h>
40707@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
40708 static int vram_total __initdata; /* Set total amount of memory */
40709 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
40710 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
40711-static void (*pmi_start)(void) __read_mostly;
40712-static void (*pmi_pal) (void) __read_mostly;
40713+static void (*pmi_start)(void) __read_only;
40714+static void (*pmi_pal) (void) __read_only;
40715 static int depth __read_mostly;
40716 static int vga_compat __read_mostly;
40717 /* --------------------------------------------------------------------- */
40718@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
40719 unsigned int size_vmode;
40720 unsigned int size_remap;
40721 unsigned int size_total;
40722+ void *pmi_code = NULL;
40723
40724 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
40725 return -ENODEV;
40726@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
40727 size_remap = size_total;
40728 vesafb_fix.smem_len = size_remap;
40729
40730-#ifndef __i386__
40731- screen_info.vesapm_seg = 0;
40732-#endif
40733-
40734 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
40735 printk(KERN_WARNING
40736 "vesafb: cannot reserve video memory at 0x%lx\n",
40737@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
40738 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
40739 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
40740
40741+#ifdef __i386__
40742+
40743+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40744+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
40745+ if (!pmi_code)
40746+#elif !defined(CONFIG_PAX_KERNEXEC)
40747+ if (0)
40748+#endif
40749+
40750+#endif
40751+ screen_info.vesapm_seg = 0;
40752+
40753 if (screen_info.vesapm_seg) {
40754- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
40755- screen_info.vesapm_seg,screen_info.vesapm_off);
40756+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
40757+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
40758 }
40759
40760 if (screen_info.vesapm_seg < 0xc000)
40761@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
40762
40763 if (ypan || pmi_setpal) {
40764 unsigned short *pmi_base;
40765+
40766 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
40767- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
40768- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
40769+
40770+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40771+ pax_open_kernel();
40772+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
40773+#else
40774+ pmi_code = pmi_base;
40775+#endif
40776+
40777+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
40778+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
40779+
40780+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40781+ pmi_start = ktva_ktla(pmi_start);
40782+ pmi_pal = ktva_ktla(pmi_pal);
40783+ pax_close_kernel();
40784+#endif
40785+
40786 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
40787 if (pmi_base[3]) {
40788 printk(KERN_INFO "vesafb: pmi: ports = ");
40789@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
40790 info->node, info->fix.id);
40791 return 0;
40792 err:
40793+
40794+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
40795+ module_free_exec(NULL, pmi_code);
40796+#endif
40797+
40798 if (info->screen_base)
40799 iounmap(info->screen_base);
40800 framebuffer_release(info);
40801diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
40802index 88714ae..16c2e11 100644
40803--- a/drivers/video/via/via_clock.h
40804+++ b/drivers/video/via/via_clock.h
40805@@ -56,7 +56,7 @@ struct via_clock {
40806
40807 void (*set_engine_pll_state)(u8 state);
40808 void (*set_engine_pll)(struct via_pll_config config);
40809-};
40810+} __no_const;
40811
40812
40813 static inline u32 get_pll_internal_frequency(u32 ref_freq,
40814diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
40815index e56c934..fc22f4b 100644
40816--- a/drivers/xen/xen-pciback/conf_space.h
40817+++ b/drivers/xen/xen-pciback/conf_space.h
40818@@ -44,15 +44,15 @@ struct config_field {
40819 struct {
40820 conf_dword_write write;
40821 conf_dword_read read;
40822- } dw;
40823+ } __no_const dw;
40824 struct {
40825 conf_word_write write;
40826 conf_word_read read;
40827- } w;
40828+ } __no_const w;
40829 struct {
40830 conf_byte_write write;
40831 conf_byte_read read;
40832- } b;
40833+ } __no_const b;
40834 } u;
40835 struct list_head list;
40836 };
40837diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
40838index 014c8dd..6f3dfe6 100644
40839--- a/fs/9p/vfs_inode.c
40840+++ b/fs/9p/vfs_inode.c
40841@@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
40842 void
40843 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
40844 {
40845- char *s = nd_get_link(nd);
40846+ const char *s = nd_get_link(nd);
40847
40848 p9_debug(P9_DEBUG_VFS, " %s %s\n",
40849 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
40850diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
40851index e95d1b6..3454244 100644
40852--- a/fs/Kconfig.binfmt
40853+++ b/fs/Kconfig.binfmt
40854@@ -89,7 +89,7 @@ config HAVE_AOUT
40855
40856 config BINFMT_AOUT
40857 tristate "Kernel support for a.out and ECOFF binaries"
40858- depends on HAVE_AOUT
40859+ depends on HAVE_AOUT && BROKEN
40860 ---help---
40861 A.out (Assembler.OUTput) is a set of formats for libraries and
40862 executables used in the earliest versions of UNIX. Linux used
40863diff --git a/fs/aio.c b/fs/aio.c
40864index b9d64d8..86cb1d5 100644
40865--- a/fs/aio.c
40866+++ b/fs/aio.c
40867@@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx *ctx)
40868 size += sizeof(struct io_event) * nr_events;
40869 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
40870
40871- if (nr_pages < 0)
40872+ if (nr_pages <= 0)
40873 return -EINVAL;
40874
40875 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
40876@@ -1461,22 +1461,27 @@ static ssize_t aio_fsync(struct kiocb *iocb)
40877 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
40878 {
40879 ssize_t ret;
40880+ struct iovec iovstack;
40881
40882 #ifdef CONFIG_COMPAT
40883 if (compat)
40884 ret = compat_rw_copy_check_uvector(type,
40885 (struct compat_iovec __user *)kiocb->ki_buf,
40886- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
40887+ kiocb->ki_nbytes, 1, &iovstack,
40888 &kiocb->ki_iovec, 1);
40889 else
40890 #endif
40891 ret = rw_copy_check_uvector(type,
40892 (struct iovec __user *)kiocb->ki_buf,
40893- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
40894+ kiocb->ki_nbytes, 1, &iovstack,
40895 &kiocb->ki_iovec, 1);
40896 if (ret < 0)
40897 goto out;
40898
40899+ if (kiocb->ki_iovec == &iovstack) {
40900+ kiocb->ki_inline_vec = iovstack;
40901+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
40902+ }
40903 kiocb->ki_nr_segs = kiocb->ki_nbytes;
40904 kiocb->ki_cur_seg = 0;
40905 /* ki_nbytes/left now reflect bytes instead of segs */
40906diff --git a/fs/attr.c b/fs/attr.c
40907index 95053ad..2cc93ca 100644
40908--- a/fs/attr.c
40909+++ b/fs/attr.c
40910@@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
40911 unsigned long limit;
40912
40913 limit = rlimit(RLIMIT_FSIZE);
40914+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
40915 if (limit != RLIM_INFINITY && offset > limit)
40916 goto out_sig;
40917 if (offset > inode->i_sb->s_maxbytes)
40918diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
40919index 9c098db..c755da5 100644
40920--- a/fs/autofs4/waitq.c
40921+++ b/fs/autofs4/waitq.c
40922@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
40923 {
40924 unsigned long sigpipe, flags;
40925 mm_segment_t fs;
40926- const char *data = (const char *)addr;
40927+ const char __user *data = (const char __force_user *)addr;
40928 ssize_t wr = 0;
40929
40930 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
40931diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
40932index 6e6d536..457113a 100644
40933--- a/fs/befs/linuxvfs.c
40934+++ b/fs/befs/linuxvfs.c
40935@@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
40936 {
40937 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
40938 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
40939- char *link = nd_get_link(nd);
40940+ const char *link = nd_get_link(nd);
40941 if (!IS_ERR(link))
40942 kfree(link);
40943 }
40944diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
40945index 1ff9405..f1e376a 100644
40946--- a/fs/binfmt_aout.c
40947+++ b/fs/binfmt_aout.c
40948@@ -16,6 +16,7 @@
40949 #include <linux/string.h>
40950 #include <linux/fs.h>
40951 #include <linux/file.h>
40952+#include <linux/security.h>
40953 #include <linux/stat.h>
40954 #include <linux/fcntl.h>
40955 #include <linux/ptrace.h>
40956@@ -86,6 +87,8 @@ static int aout_core_dump(struct coredump_params *cprm)
40957 #endif
40958 # define START_STACK(u) ((void __user *)u.start_stack)
40959
40960+ memset(&dump, 0, sizeof(dump));
40961+
40962 fs = get_fs();
40963 set_fs(KERNEL_DS);
40964 has_dumped = 1;
40965@@ -97,10 +100,12 @@ static int aout_core_dump(struct coredump_params *cprm)
40966
40967 /* If the size of the dump file exceeds the rlimit, then see what would happen
40968 if we wrote the stack, but not the data area. */
40969+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
40970 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
40971 dump.u_dsize = 0;
40972
40973 /* Make sure we have enough room to write the stack and data areas. */
40974+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
40975 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
40976 dump.u_ssize = 0;
40977
40978@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
40979 rlim = rlimit(RLIMIT_DATA);
40980 if (rlim >= RLIM_INFINITY)
40981 rlim = ~0;
40982+
40983+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
40984 if (ex.a_data + ex.a_bss > rlim)
40985 return -ENOMEM;
40986
40987@@ -269,6 +276,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
40988 install_exec_creds(bprm);
40989 current->flags &= ~PF_FORKNOEXEC;
40990
40991+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
40992+ current->mm->pax_flags = 0UL;
40993+#endif
40994+
40995+#ifdef CONFIG_PAX_PAGEEXEC
40996+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
40997+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
40998+
40999+#ifdef CONFIG_PAX_EMUTRAMP
41000+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
41001+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
41002+#endif
41003+
41004+#ifdef CONFIG_PAX_MPROTECT
41005+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
41006+ current->mm->pax_flags |= MF_PAX_MPROTECT;
41007+#endif
41008+
41009+ }
41010+#endif
41011+
41012 if (N_MAGIC(ex) == OMAGIC) {
41013 unsigned long text_addr, map_size;
41014 loff_t pos;
41015@@ -341,7 +369,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41016
41017 down_write(&current->mm->mmap_sem);
41018 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
41019- PROT_READ | PROT_WRITE | PROT_EXEC,
41020+ PROT_READ | PROT_WRITE,
41021 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
41022 fd_offset + ex.a_text);
41023 up_write(&current->mm->mmap_sem);
41024diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
41025index 07d096c..1f08d39 100644
41026--- a/fs/binfmt_elf.c
41027+++ b/fs/binfmt_elf.c
41028@@ -32,6 +32,7 @@
41029 #include <linux/elf.h>
41030 #include <linux/utsname.h>
41031 #include <linux/coredump.h>
41032+#include <linux/xattr.h>
41033 #include <asm/uaccess.h>
41034 #include <asm/param.h>
41035 #include <asm/page.h>
41036@@ -51,6 +52,10 @@ static int elf_core_dump(struct coredump_params *cprm);
41037 #define elf_core_dump NULL
41038 #endif
41039
41040+#ifdef CONFIG_PAX_MPROTECT
41041+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
41042+#endif
41043+
41044 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
41045 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
41046 #else
41047@@ -70,6 +75,11 @@ static struct linux_binfmt elf_format = {
41048 .load_binary = load_elf_binary,
41049 .load_shlib = load_elf_library,
41050 .core_dump = elf_core_dump,
41051+
41052+#ifdef CONFIG_PAX_MPROTECT
41053+ .handle_mprotect= elf_handle_mprotect,
41054+#endif
41055+
41056 .min_coredump = ELF_EXEC_PAGESIZE,
41057 };
41058
41059@@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
41060
41061 static int set_brk(unsigned long start, unsigned long end)
41062 {
41063+ unsigned long e = end;
41064+
41065 start = ELF_PAGEALIGN(start);
41066 end = ELF_PAGEALIGN(end);
41067 if (end > start) {
41068@@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
41069 if (BAD_ADDR(addr))
41070 return addr;
41071 }
41072- current->mm->start_brk = current->mm->brk = end;
41073+ current->mm->start_brk = current->mm->brk = e;
41074 return 0;
41075 }
41076
41077@@ -148,12 +160,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41078 elf_addr_t __user *u_rand_bytes;
41079 const char *k_platform = ELF_PLATFORM;
41080 const char *k_base_platform = ELF_BASE_PLATFORM;
41081- unsigned char k_rand_bytes[16];
41082+ u32 k_rand_bytes[4];
41083 int items;
41084 elf_addr_t *elf_info;
41085 int ei_index = 0;
41086 const struct cred *cred = current_cred();
41087 struct vm_area_struct *vma;
41088+ unsigned long saved_auxv[AT_VECTOR_SIZE];
41089
41090 /*
41091 * In some cases (e.g. Hyper-Threading), we want to avoid L1
41092@@ -195,8 +208,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41093 * Generate 16 random bytes for userspace PRNG seeding.
41094 */
41095 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
41096- u_rand_bytes = (elf_addr_t __user *)
41097- STACK_ALLOC(p, sizeof(k_rand_bytes));
41098+ srandom32(k_rand_bytes[0] ^ random32());
41099+ srandom32(k_rand_bytes[1] ^ random32());
41100+ srandom32(k_rand_bytes[2] ^ random32());
41101+ srandom32(k_rand_bytes[3] ^ random32());
41102+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
41103+ u_rand_bytes = (elf_addr_t __user *) p;
41104 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
41105 return -EFAULT;
41106
41107@@ -308,9 +325,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41108 return -EFAULT;
41109 current->mm->env_end = p;
41110
41111+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
41112+
41113 /* Put the elf_info on the stack in the right place. */
41114 sp = (elf_addr_t __user *)envp + 1;
41115- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
41116+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
41117 return -EFAULT;
41118 return 0;
41119 }
41120@@ -381,10 +400,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41121 {
41122 struct elf_phdr *elf_phdata;
41123 struct elf_phdr *eppnt;
41124- unsigned long load_addr = 0;
41125+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
41126 int load_addr_set = 0;
41127 unsigned long last_bss = 0, elf_bss = 0;
41128- unsigned long error = ~0UL;
41129+ unsigned long error = -EINVAL;
41130 unsigned long total_size;
41131 int retval, i, size;
41132
41133@@ -430,6 +449,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41134 goto out_close;
41135 }
41136
41137+#ifdef CONFIG_PAX_SEGMEXEC
41138+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
41139+ pax_task_size = SEGMEXEC_TASK_SIZE;
41140+#endif
41141+
41142 eppnt = elf_phdata;
41143 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
41144 if (eppnt->p_type == PT_LOAD) {
41145@@ -473,8 +497,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41146 k = load_addr + eppnt->p_vaddr;
41147 if (BAD_ADDR(k) ||
41148 eppnt->p_filesz > eppnt->p_memsz ||
41149- eppnt->p_memsz > TASK_SIZE ||
41150- TASK_SIZE - eppnt->p_memsz < k) {
41151+ eppnt->p_memsz > pax_task_size ||
41152+ pax_task_size - eppnt->p_memsz < k) {
41153 error = -ENOMEM;
41154 goto out_close;
41155 }
41156@@ -528,6 +552,351 @@ out:
41157 return error;
41158 }
41159
41160+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
41161+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
41162+{
41163+ unsigned long pax_flags = 0UL;
41164+
41165+#ifdef CONFIG_PAX_PT_PAX_FLAGS
41166+
41167+#ifdef CONFIG_PAX_PAGEEXEC
41168+ if (elf_phdata->p_flags & PF_PAGEEXEC)
41169+ pax_flags |= MF_PAX_PAGEEXEC;
41170+#endif
41171+
41172+#ifdef CONFIG_PAX_SEGMEXEC
41173+ if (elf_phdata->p_flags & PF_SEGMEXEC)
41174+ pax_flags |= MF_PAX_SEGMEXEC;
41175+#endif
41176+
41177+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41178+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41179+ if ((__supported_pte_mask & _PAGE_NX))
41180+ pax_flags &= ~MF_PAX_SEGMEXEC;
41181+ else
41182+ pax_flags &= ~MF_PAX_PAGEEXEC;
41183+ }
41184+#endif
41185+
41186+#ifdef CONFIG_PAX_EMUTRAMP
41187+ if (elf_phdata->p_flags & PF_EMUTRAMP)
41188+ pax_flags |= MF_PAX_EMUTRAMP;
41189+#endif
41190+
41191+#ifdef CONFIG_PAX_MPROTECT
41192+ if (elf_phdata->p_flags & PF_MPROTECT)
41193+ pax_flags |= MF_PAX_MPROTECT;
41194+#endif
41195+
41196+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41197+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
41198+ pax_flags |= MF_PAX_RANDMMAP;
41199+#endif
41200+
41201+#endif
41202+
41203+ return pax_flags;
41204+}
41205+
41206+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
41207+{
41208+ unsigned long pax_flags = 0UL;
41209+
41210+#ifdef CONFIG_PAX_PT_PAX_FLAGS
41211+
41212+#ifdef CONFIG_PAX_PAGEEXEC
41213+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
41214+ pax_flags |= MF_PAX_PAGEEXEC;
41215+#endif
41216+
41217+#ifdef CONFIG_PAX_SEGMEXEC
41218+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
41219+ pax_flags |= MF_PAX_SEGMEXEC;
41220+#endif
41221+
41222+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41223+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41224+ if ((__supported_pte_mask & _PAGE_NX))
41225+ pax_flags &= ~MF_PAX_SEGMEXEC;
41226+ else
41227+ pax_flags &= ~MF_PAX_PAGEEXEC;
41228+ }
41229+#endif
41230+
41231+#ifdef CONFIG_PAX_EMUTRAMP
41232+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
41233+ pax_flags |= MF_PAX_EMUTRAMP;
41234+#endif
41235+
41236+#ifdef CONFIG_PAX_MPROTECT
41237+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
41238+ pax_flags |= MF_PAX_MPROTECT;
41239+#endif
41240+
41241+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41242+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
41243+ pax_flags |= MF_PAX_RANDMMAP;
41244+#endif
41245+
41246+#endif
41247+
41248+ return pax_flags;
41249+}
41250+
41251+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
41252+{
41253+ unsigned long pax_flags = 0UL;
41254+
41255+#ifdef CONFIG_PAX_EI_PAX
41256+
41257+#ifdef CONFIG_PAX_PAGEEXEC
41258+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
41259+ pax_flags |= MF_PAX_PAGEEXEC;
41260+#endif
41261+
41262+#ifdef CONFIG_PAX_SEGMEXEC
41263+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
41264+ pax_flags |= MF_PAX_SEGMEXEC;
41265+#endif
41266+
41267+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41268+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41269+ if ((__supported_pte_mask & _PAGE_NX))
41270+ pax_flags &= ~MF_PAX_SEGMEXEC;
41271+ else
41272+ pax_flags &= ~MF_PAX_PAGEEXEC;
41273+ }
41274+#endif
41275+
41276+#ifdef CONFIG_PAX_EMUTRAMP
41277+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
41278+ pax_flags |= MF_PAX_EMUTRAMP;
41279+#endif
41280+
41281+#ifdef CONFIG_PAX_MPROTECT
41282+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
41283+ pax_flags |= MF_PAX_MPROTECT;
41284+#endif
41285+
41286+#ifdef CONFIG_PAX_ASLR
41287+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
41288+ pax_flags |= MF_PAX_RANDMMAP;
41289+#endif
41290+
41291+#else
41292+
41293+#ifdef CONFIG_PAX_PAGEEXEC
41294+ pax_flags |= MF_PAX_PAGEEXEC;
41295+#endif
41296+
41297+#ifdef CONFIG_PAX_MPROTECT
41298+ pax_flags |= MF_PAX_MPROTECT;
41299+#endif
41300+
41301+#ifdef CONFIG_PAX_RANDMMAP
41302+ pax_flags |= MF_PAX_RANDMMAP;
41303+#endif
41304+
41305+#ifdef CONFIG_PAX_SEGMEXEC
41306+ if (!(pax_flags & MF_PAX_PAGEEXEC) || !(__supported_pte_mask & _PAGE_NX)) {
41307+ pax_flags &= ~MF_PAX_PAGEEXEC;
41308+ pax_flags |= MF_PAX_SEGMEXEC;
41309+ }
41310+#endif
41311+
41312+#endif
41313+
41314+ return pax_flags;
41315+}
41316+
41317+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
41318+{
41319+
41320+#ifdef CONFIG_PAX_PT_PAX_FLAGS
41321+ unsigned long i;
41322+
41323+ for (i = 0UL; i < elf_ex->e_phnum; i++)
41324+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
41325+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
41326+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
41327+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
41328+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
41329+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
41330+ return ~0UL;
41331+
41332+#ifdef CONFIG_PAX_SOFTMODE
41333+ if (pax_softmode)
41334+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
41335+ else
41336+#endif
41337+
41338+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
41339+ break;
41340+ }
41341+#endif
41342+
41343+ return ~0UL;
41344+}
41345+
41346+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
41347+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
41348+{
41349+ unsigned long pax_flags = 0UL;
41350+
41351+#ifdef CONFIG_PAX_PAGEEXEC
41352+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
41353+ pax_flags |= MF_PAX_PAGEEXEC;
41354+#endif
41355+
41356+#ifdef CONFIG_PAX_SEGMEXEC
41357+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
41358+ pax_flags |= MF_PAX_SEGMEXEC;
41359+#endif
41360+
41361+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41362+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41363+ if ((__supported_pte_mask & _PAGE_NX))
41364+ pax_flags &= ~MF_PAX_SEGMEXEC;
41365+ else
41366+ pax_flags &= ~MF_PAX_PAGEEXEC;
41367+ }
41368+#endif
41369+
41370+#ifdef CONFIG_PAX_EMUTRAMP
41371+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
41372+ pax_flags |= MF_PAX_EMUTRAMP;
41373+#endif
41374+
41375+#ifdef CONFIG_PAX_MPROTECT
41376+ if (pax_flags_softmode & MF_PAX_MPROTECT)
41377+ pax_flags |= MF_PAX_MPROTECT;
41378+#endif
41379+
41380+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41381+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
41382+ pax_flags |= MF_PAX_RANDMMAP;
41383+#endif
41384+
41385+ return pax_flags;
41386+}
41387+
41388+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
41389+{
41390+ unsigned long pax_flags = 0UL;
41391+
41392+#ifdef CONFIG_PAX_PAGEEXEC
41393+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
41394+ pax_flags |= MF_PAX_PAGEEXEC;
41395+#endif
41396+
41397+#ifdef CONFIG_PAX_SEGMEXEC
41398+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
41399+ pax_flags |= MF_PAX_SEGMEXEC;
41400+#endif
41401+
41402+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41403+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41404+ if ((__supported_pte_mask & _PAGE_NX))
41405+ pax_flags &= ~MF_PAX_SEGMEXEC;
41406+ else
41407+ pax_flags &= ~MF_PAX_PAGEEXEC;
41408+ }
41409+#endif
41410+
41411+#ifdef CONFIG_PAX_EMUTRAMP
41412+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
41413+ pax_flags |= MF_PAX_EMUTRAMP;
41414+#endif
41415+
41416+#ifdef CONFIG_PAX_MPROTECT
41417+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
41418+ pax_flags |= MF_PAX_MPROTECT;
41419+#endif
41420+
41421+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41422+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
41423+ pax_flags |= MF_PAX_RANDMMAP;
41424+#endif
41425+
41426+ return pax_flags;
41427+}
41428+#endif
41429+
41430+static unsigned long pax_parse_xattr_pax(struct file * const file)
41431+{
41432+
41433+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
41434+ ssize_t xattr_size, i;
41435+ unsigned char xattr_value[5];
41436+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
41437+
41438+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
41439+ if (xattr_size <= 0)
41440+ return ~0UL;
41441+
41442+ for (i = 0; i < xattr_size; i++)
41443+ switch (xattr_value[i]) {
41444+ default:
41445+ return ~0UL;
41446+
41447+#define parse_flag(option1, option2, flag) \
41448+ case option1: \
41449+ pax_flags_hardmode |= MF_PAX_##flag; \
41450+ break; \
41451+ case option2: \
41452+ pax_flags_softmode |= MF_PAX_##flag; \
41453+ break;
41454+
41455+ parse_flag('p', 'P', PAGEEXEC);
41456+ parse_flag('e', 'E', EMUTRAMP);
41457+ parse_flag('m', 'M', MPROTECT);
41458+ parse_flag('r', 'R', RANDMMAP);
41459+ parse_flag('s', 'S', SEGMEXEC);
41460+
41461+#undef parse_flag
41462+ }
41463+
41464+ if (pax_flags_hardmode & pax_flags_softmode)
41465+ return ~0UL;
41466+
41467+#ifdef CONFIG_PAX_SOFTMODE
41468+ if (pax_softmode)
41469+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
41470+ else
41471+#endif
41472+
41473+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
41474+#else
41475+ return ~0UL;
41476+#endif
41477+
41478+}
41479+
41480+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
41481+{
41482+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
41483+
41484+ pax_flags = pax_parse_ei_pax(elf_ex);
41485+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
41486+ xattr_pax_flags = pax_parse_xattr_pax(file);
41487+
41488+ if (pt_pax_flags == ~0UL)
41489+ pt_pax_flags = xattr_pax_flags;
41490+ else if (xattr_pax_flags == ~0UL)
41491+ xattr_pax_flags = pt_pax_flags;
41492+ if (pt_pax_flags != xattr_pax_flags)
41493+ return -EINVAL;
41494+ if (pt_pax_flags != ~0UL)
41495+ pax_flags = pt_pax_flags;
41496+
41497+ if (0 > pax_check_flags(&pax_flags))
41498+ return -EINVAL;
41499+
41500+ current->mm->pax_flags = pax_flags;
41501+ return 0;
41502+}
41503+#endif
41504+
41505 /*
41506 * These are the functions used to load ELF style executables and shared
41507 * libraries. There is no binary dependent code anywhere else.
41508@@ -544,6 +913,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
41509 {
41510 unsigned int random_variable = 0;
41511
41512+#ifdef CONFIG_PAX_RANDUSTACK
41513+ if (randomize_va_space)
41514+ return stack_top - current->mm->delta_stack;
41515+#endif
41516+
41517 if ((current->flags & PF_RANDOMIZE) &&
41518 !(current->personality & ADDR_NO_RANDOMIZE)) {
41519 random_variable = get_random_int() & STACK_RND_MASK;
41520@@ -562,7 +936,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41521 unsigned long load_addr = 0, load_bias = 0;
41522 int load_addr_set = 0;
41523 char * elf_interpreter = NULL;
41524- unsigned long error;
41525+ unsigned long error = 0;
41526 struct elf_phdr *elf_ppnt, *elf_phdata;
41527 unsigned long elf_bss, elf_brk;
41528 int retval, i;
41529@@ -572,11 +946,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41530 unsigned long start_code, end_code, start_data, end_data;
41531 unsigned long reloc_func_desc __maybe_unused = 0;
41532 int executable_stack = EXSTACK_DEFAULT;
41533- unsigned long def_flags = 0;
41534 struct {
41535 struct elfhdr elf_ex;
41536 struct elfhdr interp_elf_ex;
41537 } *loc;
41538+ unsigned long pax_task_size = TASK_SIZE;
41539
41540 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
41541 if (!loc) {
41542@@ -713,11 +1087,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41543
41544 /* OK, This is the point of no return */
41545 current->flags &= ~PF_FORKNOEXEC;
41546- current->mm->def_flags = def_flags;
41547+
41548+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
41549+ current->mm->pax_flags = 0UL;
41550+#endif
41551+
41552+#ifdef CONFIG_PAX_DLRESOLVE
41553+ current->mm->call_dl_resolve = 0UL;
41554+#endif
41555+
41556+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
41557+ current->mm->call_syscall = 0UL;
41558+#endif
41559+
41560+#ifdef CONFIG_PAX_ASLR
41561+ current->mm->delta_mmap = 0UL;
41562+ current->mm->delta_stack = 0UL;
41563+#endif
41564+
41565+ current->mm->def_flags = 0;
41566+
41567+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
41568+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
41569+ send_sig(SIGKILL, current, 0);
41570+ goto out_free_dentry;
41571+ }
41572+#endif
41573+
41574+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
41575+ pax_set_initial_flags(bprm);
41576+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
41577+ if (pax_set_initial_flags_func)
41578+ (pax_set_initial_flags_func)(bprm);
41579+#endif
41580+
41581+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
41582+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
41583+ current->mm->context.user_cs_limit = PAGE_SIZE;
41584+ current->mm->def_flags |= VM_PAGEEXEC;
41585+ }
41586+#endif
41587+
41588+#ifdef CONFIG_PAX_SEGMEXEC
41589+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
41590+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
41591+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
41592+ pax_task_size = SEGMEXEC_TASK_SIZE;
41593+ current->mm->def_flags |= VM_NOHUGEPAGE;
41594+ }
41595+#endif
41596+
41597+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
41598+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41599+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
41600+ put_cpu();
41601+ }
41602+#endif
41603
41604 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
41605 may depend on the personality. */
41606 SET_PERSONALITY(loc->elf_ex);
41607+
41608+#ifdef CONFIG_PAX_ASLR
41609+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
41610+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
41611+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
41612+ }
41613+#endif
41614+
41615+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
41616+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41617+ executable_stack = EXSTACK_DISABLE_X;
41618+ current->personality &= ~READ_IMPLIES_EXEC;
41619+ } else
41620+#endif
41621+
41622 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
41623 current->personality |= READ_IMPLIES_EXEC;
41624
41625@@ -808,6 +1252,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41626 #else
41627 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
41628 #endif
41629+
41630+#ifdef CONFIG_PAX_RANDMMAP
41631+ /* PaX: randomize base address at the default exe base if requested */
41632+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
41633+#ifdef CONFIG_SPARC64
41634+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
41635+#else
41636+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
41637+#endif
41638+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
41639+ elf_flags |= MAP_FIXED;
41640+ }
41641+#endif
41642+
41643 }
41644
41645 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
41646@@ -840,9 +1298,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41647 * allowed task size. Note that p_filesz must always be
41648 * <= p_memsz so it is only necessary to check p_memsz.
41649 */
41650- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
41651- elf_ppnt->p_memsz > TASK_SIZE ||
41652- TASK_SIZE - elf_ppnt->p_memsz < k) {
41653+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
41654+ elf_ppnt->p_memsz > pax_task_size ||
41655+ pax_task_size - elf_ppnt->p_memsz < k) {
41656 /* set_brk can never work. Avoid overflows. */
41657 send_sig(SIGKILL, current, 0);
41658 retval = -EINVAL;
41659@@ -881,11 +1339,37 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
41660 goto out_free_dentry;
41661 }
41662 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
41663- send_sig(SIGSEGV, current, 0);
41664- retval = -EFAULT; /* Nobody gets to see this, but.. */
41665- goto out_free_dentry;
41666+ /*
41667+ * This bss-zeroing can fail if the ELF
41668+ * file specifies odd protections. So
41669+ * we don't check the return value
41670+ */
41671 }
41672
41673+#ifdef CONFIG_PAX_RANDMMAP
41674+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
41675+ unsigned long start, size;
41676+
41677+ current->mm->end_data = end_data = elf_brk;
41678+ start = ELF_PAGEALIGN(elf_brk);
41679+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
41680+ current->mm->start_brk = start + size;
41681+ down_write(&current->mm->mmap_sem);
41682+ retval = -ENOMEM;
41683+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
41684+ start = do_mmap(NULL, start, size, PROT_NONE, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
41685+ retval = IS_ERR_VALUE(start) ? start : 0;
41686+ }
41687+ up_write(&current->mm->mmap_sem);
41688+ if (retval == 0)
41689+ retval = set_brk(start + size, start + size + PAGE_SIZE);
41690+ if (retval < 0) {
41691+ send_sig(SIGKILL, current, 0);
41692+ goto out_free_dentry;
41693+ }
41694+ }
41695+#endif
41696+
41697 if (elf_interpreter) {
41698 unsigned long uninitialized_var(interp_map_addr);
41699
41700@@ -1098,7 +1582,7 @@ out:
41701 * Decide what to dump of a segment, part, all or none.
41702 */
41703 static unsigned long vma_dump_size(struct vm_area_struct *vma,
41704- unsigned long mm_flags)
41705+ unsigned long mm_flags, long signr)
41706 {
41707 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
41708
41709@@ -1132,7 +1616,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
41710 if (vma->vm_file == NULL)
41711 return 0;
41712
41713- if (FILTER(MAPPED_PRIVATE))
41714+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
41715 goto whole;
41716
41717 /*
41718@@ -1354,9 +1838,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
41719 {
41720 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
41721 int i = 0;
41722- do
41723+ do {
41724 i += 2;
41725- while (auxv[i - 2] != AT_NULL);
41726+ } while (auxv[i - 2] != AT_NULL);
41727 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
41728 }
41729
41730@@ -1862,14 +2346,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
41731 }
41732
41733 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
41734- unsigned long mm_flags)
41735+ struct coredump_params *cprm)
41736 {
41737 struct vm_area_struct *vma;
41738 size_t size = 0;
41739
41740 for (vma = first_vma(current, gate_vma); vma != NULL;
41741 vma = next_vma(vma, gate_vma))
41742- size += vma_dump_size(vma, mm_flags);
41743+ size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
41744 return size;
41745 }
41746
41747@@ -1963,7 +2447,7 @@ static int elf_core_dump(struct coredump_params *cprm)
41748
41749 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
41750
41751- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
41752+ offset += elf_core_vma_data_size(gate_vma, cprm);
41753 offset += elf_core_extra_data_size();
41754 e_shoff = offset;
41755
41756@@ -1977,10 +2461,12 @@ static int elf_core_dump(struct coredump_params *cprm)
41757 offset = dataoff;
41758
41759 size += sizeof(*elf);
41760+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
41761 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
41762 goto end_coredump;
41763
41764 size += sizeof(*phdr4note);
41765+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
41766 if (size > cprm->limit
41767 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
41768 goto end_coredump;
41769@@ -1994,7 +2480,7 @@ static int elf_core_dump(struct coredump_params *cprm)
41770 phdr.p_offset = offset;
41771 phdr.p_vaddr = vma->vm_start;
41772 phdr.p_paddr = 0;
41773- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
41774+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
41775 phdr.p_memsz = vma->vm_end - vma->vm_start;
41776 offset += phdr.p_filesz;
41777 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
41778@@ -2005,6 +2491,7 @@ static int elf_core_dump(struct coredump_params *cprm)
41779 phdr.p_align = ELF_EXEC_PAGESIZE;
41780
41781 size += sizeof(phdr);
41782+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
41783 if (size > cprm->limit
41784 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
41785 goto end_coredump;
41786@@ -2029,7 +2516,7 @@ static int elf_core_dump(struct coredump_params *cprm)
41787 unsigned long addr;
41788 unsigned long end;
41789
41790- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
41791+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
41792
41793 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
41794 struct page *page;
41795@@ -2038,6 +2525,7 @@ static int elf_core_dump(struct coredump_params *cprm)
41796 page = get_dump_page(addr);
41797 if (page) {
41798 void *kaddr = kmap(page);
41799+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
41800 stop = ((size += PAGE_SIZE) > cprm->limit) ||
41801 !dump_write(cprm->file, kaddr,
41802 PAGE_SIZE);
41803@@ -2055,6 +2543,7 @@ static int elf_core_dump(struct coredump_params *cprm)
41804
41805 if (e_phnum == PN_XNUM) {
41806 size += sizeof(*shdr4extnum);
41807+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
41808 if (size > cprm->limit
41809 || !dump_write(cprm->file, shdr4extnum,
41810 sizeof(*shdr4extnum)))
41811@@ -2075,6 +2564,97 @@ out:
41812
41813 #endif /* CONFIG_ELF_CORE */
41814
41815+#ifdef CONFIG_PAX_MPROTECT
41816+/* PaX: non-PIC ELF libraries need relocations on their executable segments
41817+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
41818+ * we'll remove VM_MAYWRITE for good on RELRO segments.
41819+ *
41820+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
41821+ * basis because we want to allow the common case and not the special ones.
41822+ */
41823+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
41824+{
41825+ struct elfhdr elf_h;
41826+ struct elf_phdr elf_p;
41827+ unsigned long i;
41828+ unsigned long oldflags;
41829+ bool is_textrel_rw, is_textrel_rx, is_relro;
41830+
41831+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
41832+ return;
41833+
41834+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
41835+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
41836+
41837+#ifdef CONFIG_PAX_ELFRELOCS
41838+ /* possible TEXTREL */
41839+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
41840+ 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);
41841+#else
41842+ is_textrel_rw = false;
41843+ is_textrel_rx = false;
41844+#endif
41845+
41846+ /* possible RELRO */
41847+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
41848+
41849+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
41850+ return;
41851+
41852+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
41853+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
41854+
41855+#ifdef CONFIG_PAX_ETEXECRELOCS
41856+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
41857+#else
41858+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
41859+#endif
41860+
41861+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
41862+ !elf_check_arch(&elf_h) ||
41863+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
41864+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
41865+ return;
41866+
41867+ for (i = 0UL; i < elf_h.e_phnum; i++) {
41868+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
41869+ return;
41870+ switch (elf_p.p_type) {
41871+ case PT_DYNAMIC:
41872+ if (!is_textrel_rw && !is_textrel_rx)
41873+ continue;
41874+ i = 0UL;
41875+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
41876+ elf_dyn dyn;
41877+
41878+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
41879+ return;
41880+ if (dyn.d_tag == DT_NULL)
41881+ return;
41882+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
41883+ gr_log_textrel(vma);
41884+ if (is_textrel_rw)
41885+ vma->vm_flags |= VM_MAYWRITE;
41886+ else
41887+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
41888+ vma->vm_flags &= ~VM_MAYWRITE;
41889+ return;
41890+ }
41891+ i++;
41892+ }
41893+ return;
41894+
41895+ case PT_GNU_RELRO:
41896+ if (!is_relro)
41897+ continue;
41898+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
41899+ vma->vm_flags &= ~VM_MAYWRITE;
41900+ return;
41901+ }
41902+ }
41903+}
41904+#endif
41905+
41906 static int __init init_elf_binfmt(void)
41907 {
41908 return register_binfmt(&elf_format);
41909diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
41910index 1bffbe0..c8c283e 100644
41911--- a/fs/binfmt_flat.c
41912+++ b/fs/binfmt_flat.c
41913@@ -567,7 +567,9 @@ static int load_flat_file(struct linux_binprm * bprm,
41914 realdatastart = (unsigned long) -ENOMEM;
41915 printk("Unable to allocate RAM for process data, errno %d\n",
41916 (int)-realdatastart);
41917+ down_write(&current->mm->mmap_sem);
41918 do_munmap(current->mm, textpos, text_len);
41919+ up_write(&current->mm->mmap_sem);
41920 ret = realdatastart;
41921 goto err;
41922 }
41923@@ -591,8 +593,10 @@ static int load_flat_file(struct linux_binprm * bprm,
41924 }
41925 if (IS_ERR_VALUE(result)) {
41926 printk("Unable to read data+bss, errno %d\n", (int)-result);
41927+ down_write(&current->mm->mmap_sem);
41928 do_munmap(current->mm, textpos, text_len);
41929 do_munmap(current->mm, realdatastart, len);
41930+ up_write(&current->mm->mmap_sem);
41931 ret = result;
41932 goto err;
41933 }
41934@@ -661,8 +665,10 @@ static int load_flat_file(struct linux_binprm * bprm,
41935 }
41936 if (IS_ERR_VALUE(result)) {
41937 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
41938+ down_write(&current->mm->mmap_sem);
41939 do_munmap(current->mm, textpos, text_len + data_len + extra +
41940 MAX_SHARED_LIBS * sizeof(unsigned long));
41941+ up_write(&current->mm->mmap_sem);
41942 ret = result;
41943 goto err;
41944 }
41945diff --git a/fs/bio.c b/fs/bio.c
41946index b980ecd..74800bf 100644
41947--- a/fs/bio.c
41948+++ b/fs/bio.c
41949@@ -833,7 +833,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
41950 /*
41951 * Overflow, abort
41952 */
41953- if (end < start)
41954+ if (end < start || end - start > INT_MAX - nr_pages)
41955 return ERR_PTR(-EINVAL);
41956
41957 nr_pages += end - start;
41958@@ -1229,7 +1229,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
41959 const int read = bio_data_dir(bio) == READ;
41960 struct bio_map_data *bmd = bio->bi_private;
41961 int i;
41962- char *p = bmd->sgvecs[0].iov_base;
41963+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
41964
41965 __bio_for_each_segment(bvec, bio, i, 0) {
41966 char *addr = page_address(bvec->bv_page);
41967diff --git a/fs/block_dev.c b/fs/block_dev.c
41968index 5e9f198..6bf9b1c 100644
41969--- a/fs/block_dev.c
41970+++ b/fs/block_dev.c
41971@@ -703,7 +703,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
41972 else if (bdev->bd_contains == bdev)
41973 return true; /* is a whole device which isn't held */
41974
41975- else if (whole->bd_holder == bd_may_claim)
41976+ else if (whole->bd_holder == (void *)bd_may_claim)
41977 return true; /* is a partition of a device that is being partitioned */
41978 else if (whole->bd_holder != NULL)
41979 return false; /* is a partition of a held device */
41980diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
41981index d986824..af1befd 100644
41982--- a/fs/btrfs/check-integrity.c
41983+++ b/fs/btrfs/check-integrity.c
41984@@ -157,7 +157,7 @@ struct btrfsic_block {
41985 union {
41986 bio_end_io_t *bio;
41987 bh_end_io_t *bh;
41988- } orig_bio_bh_end_io;
41989+ } __no_const orig_bio_bh_end_io;
41990 int submit_bio_bh_rw;
41991 u64 flush_gen; /* only valid if !never_written */
41992 };
41993diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
41994index 0639a55..7d9e07f 100644
41995--- a/fs/btrfs/ctree.c
41996+++ b/fs/btrfs/ctree.c
41997@@ -488,9 +488,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
41998 free_extent_buffer(buf);
41999 add_root_to_dirty_list(root);
42000 } else {
42001- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
42002- parent_start = parent->start;
42003- else
42004+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
42005+ if (parent)
42006+ parent_start = parent->start;
42007+ else
42008+ parent_start = 0;
42009+ } else
42010 parent_start = 0;
42011
42012 WARN_ON(trans->transid != btrfs_header_generation(parent));
42013diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
42014index 892b347..b3db246 100644
42015--- a/fs/btrfs/inode.c
42016+++ b/fs/btrfs/inode.c
42017@@ -6930,7 +6930,7 @@ fail:
42018 return -ENOMEM;
42019 }
42020
42021-static int btrfs_getattr(struct vfsmount *mnt,
42022+int btrfs_getattr(struct vfsmount *mnt,
42023 struct dentry *dentry, struct kstat *stat)
42024 {
42025 struct inode *inode = dentry->d_inode;
42026@@ -6944,6 +6944,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
42027 return 0;
42028 }
42029
42030+EXPORT_SYMBOL(btrfs_getattr);
42031+
42032+dev_t get_btrfs_dev_from_inode(struct inode *inode)
42033+{
42034+ return BTRFS_I(inode)->root->anon_dev;
42035+}
42036+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
42037+
42038 /*
42039 * If a file is moved, it will inherit the cow and compression flags of the new
42040 * directory.
42041diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
42042index d8b5471..e5463d7 100644
42043--- a/fs/btrfs/ioctl.c
42044+++ b/fs/btrfs/ioctl.c
42045@@ -2783,9 +2783,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
42046 for (i = 0; i < num_types; i++) {
42047 struct btrfs_space_info *tmp;
42048
42049+ /* Don't copy in more than we allocated */
42050 if (!slot_count)
42051 break;
42052
42053+ slot_count--;
42054+
42055 info = NULL;
42056 rcu_read_lock();
42057 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
42058@@ -2807,15 +2810,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
42059 memcpy(dest, &space, sizeof(space));
42060 dest++;
42061 space_args.total_spaces++;
42062- slot_count--;
42063 }
42064- if (!slot_count)
42065- break;
42066 }
42067 up_read(&info->groups_sem);
42068 }
42069
42070- user_dest = (struct btrfs_ioctl_space_info *)
42071+ user_dest = (struct btrfs_ioctl_space_info __user *)
42072 (arg + sizeof(struct btrfs_ioctl_space_args));
42073
42074 if (copy_to_user(user_dest, dest_orig, alloc_size))
42075diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
42076index 8c1aae2..1e46446 100644
42077--- a/fs/btrfs/relocation.c
42078+++ b/fs/btrfs/relocation.c
42079@@ -1244,7 +1244,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
42080 }
42081 spin_unlock(&rc->reloc_root_tree.lock);
42082
42083- BUG_ON((struct btrfs_root *)node->data != root);
42084+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
42085
42086 if (!del) {
42087 spin_lock(&rc->reloc_root_tree.lock);
42088diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
42089index 622f469..e8d2d55 100644
42090--- a/fs/cachefiles/bind.c
42091+++ b/fs/cachefiles/bind.c
42092@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
42093 args);
42094
42095 /* start by checking things over */
42096- ASSERT(cache->fstop_percent >= 0 &&
42097- cache->fstop_percent < cache->fcull_percent &&
42098+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
42099 cache->fcull_percent < cache->frun_percent &&
42100 cache->frun_percent < 100);
42101
42102- ASSERT(cache->bstop_percent >= 0 &&
42103- cache->bstop_percent < cache->bcull_percent &&
42104+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
42105 cache->bcull_percent < cache->brun_percent &&
42106 cache->brun_percent < 100);
42107
42108diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
42109index 0a1467b..6a53245 100644
42110--- a/fs/cachefiles/daemon.c
42111+++ b/fs/cachefiles/daemon.c
42112@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
42113 if (n > buflen)
42114 return -EMSGSIZE;
42115
42116- if (copy_to_user(_buffer, buffer, n) != 0)
42117+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
42118 return -EFAULT;
42119
42120 return n;
42121@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
42122 if (test_bit(CACHEFILES_DEAD, &cache->flags))
42123 return -EIO;
42124
42125- if (datalen < 0 || datalen > PAGE_SIZE - 1)
42126+ if (datalen > PAGE_SIZE - 1)
42127 return -EOPNOTSUPP;
42128
42129 /* drag the command string into the kernel so we can parse it */
42130@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
42131 if (args[0] != '%' || args[1] != '\0')
42132 return -EINVAL;
42133
42134- if (fstop < 0 || fstop >= cache->fcull_percent)
42135+ if (fstop >= cache->fcull_percent)
42136 return cachefiles_daemon_range_error(cache, args);
42137
42138 cache->fstop_percent = fstop;
42139@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
42140 if (args[0] != '%' || args[1] != '\0')
42141 return -EINVAL;
42142
42143- if (bstop < 0 || bstop >= cache->bcull_percent)
42144+ if (bstop >= cache->bcull_percent)
42145 return cachefiles_daemon_range_error(cache, args);
42146
42147 cache->bstop_percent = bstop;
42148diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
42149index bd6bc1b..b627b53 100644
42150--- a/fs/cachefiles/internal.h
42151+++ b/fs/cachefiles/internal.h
42152@@ -57,7 +57,7 @@ struct cachefiles_cache {
42153 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
42154 struct rb_root active_nodes; /* active nodes (can't be culled) */
42155 rwlock_t active_lock; /* lock for active_nodes */
42156- atomic_t gravecounter; /* graveyard uniquifier */
42157+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
42158 unsigned frun_percent; /* when to stop culling (% files) */
42159 unsigned fcull_percent; /* when to start culling (% files) */
42160 unsigned fstop_percent; /* when to stop allocating (% files) */
42161@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
42162 * proc.c
42163 */
42164 #ifdef CONFIG_CACHEFILES_HISTOGRAM
42165-extern atomic_t cachefiles_lookup_histogram[HZ];
42166-extern atomic_t cachefiles_mkdir_histogram[HZ];
42167-extern atomic_t cachefiles_create_histogram[HZ];
42168+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
42169+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
42170+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
42171
42172 extern int __init cachefiles_proc_init(void);
42173 extern void cachefiles_proc_cleanup(void);
42174 static inline
42175-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
42176+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
42177 {
42178 unsigned long jif = jiffies - start_jif;
42179 if (jif >= HZ)
42180 jif = HZ - 1;
42181- atomic_inc(&histogram[jif]);
42182+ atomic_inc_unchecked(&histogram[jif]);
42183 }
42184
42185 #else
42186diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
42187index a0358c2..d6137f2 100644
42188--- a/fs/cachefiles/namei.c
42189+++ b/fs/cachefiles/namei.c
42190@@ -318,7 +318,7 @@ try_again:
42191 /* first step is to make up a grave dentry in the graveyard */
42192 sprintf(nbuffer, "%08x%08x",
42193 (uint32_t) get_seconds(),
42194- (uint32_t) atomic_inc_return(&cache->gravecounter));
42195+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
42196
42197 /* do the multiway lock magic */
42198 trap = lock_rename(cache->graveyard, dir);
42199diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
42200index eccd339..4c1d995 100644
42201--- a/fs/cachefiles/proc.c
42202+++ b/fs/cachefiles/proc.c
42203@@ -14,9 +14,9 @@
42204 #include <linux/seq_file.h>
42205 #include "internal.h"
42206
42207-atomic_t cachefiles_lookup_histogram[HZ];
42208-atomic_t cachefiles_mkdir_histogram[HZ];
42209-atomic_t cachefiles_create_histogram[HZ];
42210+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
42211+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
42212+atomic_unchecked_t cachefiles_create_histogram[HZ];
42213
42214 /*
42215 * display the latency histogram
42216@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
42217 return 0;
42218 default:
42219 index = (unsigned long) v - 3;
42220- x = atomic_read(&cachefiles_lookup_histogram[index]);
42221- y = atomic_read(&cachefiles_mkdir_histogram[index]);
42222- z = atomic_read(&cachefiles_create_histogram[index]);
42223+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
42224+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
42225+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
42226 if (x == 0 && y == 0 && z == 0)
42227 return 0;
42228
42229diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
42230index 0e3c092..818480e 100644
42231--- a/fs/cachefiles/rdwr.c
42232+++ b/fs/cachefiles/rdwr.c
42233@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
42234 old_fs = get_fs();
42235 set_fs(KERNEL_DS);
42236 ret = file->f_op->write(
42237- file, (const void __user *) data, len, &pos);
42238+ file, (const void __force_user *) data, len, &pos);
42239 set_fs(old_fs);
42240 kunmap(page);
42241 if (ret != len)
42242diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
42243index 3e8094b..cb3ff3d 100644
42244--- a/fs/ceph/dir.c
42245+++ b/fs/ceph/dir.c
42246@@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
42247 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
42248 struct ceph_mds_client *mdsc = fsc->mdsc;
42249 unsigned frag = fpos_frag(filp->f_pos);
42250- int off = fpos_off(filp->f_pos);
42251+ unsigned int off = fpos_off(filp->f_pos);
42252 int err;
42253 u32 ftype;
42254 struct ceph_mds_reply_info_parsed *rinfo;
42255@@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
42256 if (nd &&
42257 (nd->flags & LOOKUP_OPEN) &&
42258 !(nd->intent.open.flags & O_CREAT)) {
42259- int mode = nd->intent.open.create_mode & ~current->fs->umask;
42260+ int mode = nd->intent.open.create_mode & ~current_umask();
42261 return ceph_lookup_open(dir, dentry, nd, mode, 1);
42262 }
42263
42264diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
42265index 24b3dfc..3cd5454 100644
42266--- a/fs/cifs/cifs_debug.c
42267+++ b/fs/cifs/cifs_debug.c
42268@@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
42269
42270 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
42271 #ifdef CONFIG_CIFS_STATS2
42272- atomic_set(&totBufAllocCount, 0);
42273- atomic_set(&totSmBufAllocCount, 0);
42274+ atomic_set_unchecked(&totBufAllocCount, 0);
42275+ atomic_set_unchecked(&totSmBufAllocCount, 0);
42276 #endif /* CONFIG_CIFS_STATS2 */
42277 spin_lock(&cifs_tcp_ses_lock);
42278 list_for_each(tmp1, &cifs_tcp_ses_list) {
42279@@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
42280 tcon = list_entry(tmp3,
42281 struct cifs_tcon,
42282 tcon_list);
42283- atomic_set(&tcon->num_smbs_sent, 0);
42284- atomic_set(&tcon->num_writes, 0);
42285- atomic_set(&tcon->num_reads, 0);
42286- atomic_set(&tcon->num_oplock_brks, 0);
42287- atomic_set(&tcon->num_opens, 0);
42288- atomic_set(&tcon->num_posixopens, 0);
42289- atomic_set(&tcon->num_posixmkdirs, 0);
42290- atomic_set(&tcon->num_closes, 0);
42291- atomic_set(&tcon->num_deletes, 0);
42292- atomic_set(&tcon->num_mkdirs, 0);
42293- atomic_set(&tcon->num_rmdirs, 0);
42294- atomic_set(&tcon->num_renames, 0);
42295- atomic_set(&tcon->num_t2renames, 0);
42296- atomic_set(&tcon->num_ffirst, 0);
42297- atomic_set(&tcon->num_fnext, 0);
42298- atomic_set(&tcon->num_fclose, 0);
42299- atomic_set(&tcon->num_hardlinks, 0);
42300- atomic_set(&tcon->num_symlinks, 0);
42301- atomic_set(&tcon->num_locks, 0);
42302+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
42303+ atomic_set_unchecked(&tcon->num_writes, 0);
42304+ atomic_set_unchecked(&tcon->num_reads, 0);
42305+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
42306+ atomic_set_unchecked(&tcon->num_opens, 0);
42307+ atomic_set_unchecked(&tcon->num_posixopens, 0);
42308+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
42309+ atomic_set_unchecked(&tcon->num_closes, 0);
42310+ atomic_set_unchecked(&tcon->num_deletes, 0);
42311+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
42312+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
42313+ atomic_set_unchecked(&tcon->num_renames, 0);
42314+ atomic_set_unchecked(&tcon->num_t2renames, 0);
42315+ atomic_set_unchecked(&tcon->num_ffirst, 0);
42316+ atomic_set_unchecked(&tcon->num_fnext, 0);
42317+ atomic_set_unchecked(&tcon->num_fclose, 0);
42318+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
42319+ atomic_set_unchecked(&tcon->num_symlinks, 0);
42320+ atomic_set_unchecked(&tcon->num_locks, 0);
42321 }
42322 }
42323 }
42324@@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
42325 smBufAllocCount.counter, cifs_min_small);
42326 #ifdef CONFIG_CIFS_STATS2
42327 seq_printf(m, "Total Large %d Small %d Allocations\n",
42328- atomic_read(&totBufAllocCount),
42329- atomic_read(&totSmBufAllocCount));
42330+ atomic_read_unchecked(&totBufAllocCount),
42331+ atomic_read_unchecked(&totSmBufAllocCount));
42332 #endif /* CONFIG_CIFS_STATS2 */
42333
42334 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
42335@@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
42336 if (tcon->need_reconnect)
42337 seq_puts(m, "\tDISCONNECTED ");
42338 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
42339- atomic_read(&tcon->num_smbs_sent),
42340- atomic_read(&tcon->num_oplock_brks));
42341+ atomic_read_unchecked(&tcon->num_smbs_sent),
42342+ atomic_read_unchecked(&tcon->num_oplock_brks));
42343 seq_printf(m, "\nReads: %d Bytes: %lld",
42344- atomic_read(&tcon->num_reads),
42345+ atomic_read_unchecked(&tcon->num_reads),
42346 (long long)(tcon->bytes_read));
42347 seq_printf(m, "\nWrites: %d Bytes: %lld",
42348- atomic_read(&tcon->num_writes),
42349+ atomic_read_unchecked(&tcon->num_writes),
42350 (long long)(tcon->bytes_written));
42351 seq_printf(m, "\nFlushes: %d",
42352- atomic_read(&tcon->num_flushes));
42353+ atomic_read_unchecked(&tcon->num_flushes));
42354 seq_printf(m, "\nLocks: %d HardLinks: %d "
42355 "Symlinks: %d",
42356- atomic_read(&tcon->num_locks),
42357- atomic_read(&tcon->num_hardlinks),
42358- atomic_read(&tcon->num_symlinks));
42359+ atomic_read_unchecked(&tcon->num_locks),
42360+ atomic_read_unchecked(&tcon->num_hardlinks),
42361+ atomic_read_unchecked(&tcon->num_symlinks));
42362 seq_printf(m, "\nOpens: %d Closes: %d "
42363 "Deletes: %d",
42364- atomic_read(&tcon->num_opens),
42365- atomic_read(&tcon->num_closes),
42366- atomic_read(&tcon->num_deletes));
42367+ atomic_read_unchecked(&tcon->num_opens),
42368+ atomic_read_unchecked(&tcon->num_closes),
42369+ atomic_read_unchecked(&tcon->num_deletes));
42370 seq_printf(m, "\nPosix Opens: %d "
42371 "Posix Mkdirs: %d",
42372- atomic_read(&tcon->num_posixopens),
42373- atomic_read(&tcon->num_posixmkdirs));
42374+ atomic_read_unchecked(&tcon->num_posixopens),
42375+ atomic_read_unchecked(&tcon->num_posixmkdirs));
42376 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
42377- atomic_read(&tcon->num_mkdirs),
42378- atomic_read(&tcon->num_rmdirs));
42379+ atomic_read_unchecked(&tcon->num_mkdirs),
42380+ atomic_read_unchecked(&tcon->num_rmdirs));
42381 seq_printf(m, "\nRenames: %d T2 Renames %d",
42382- atomic_read(&tcon->num_renames),
42383- atomic_read(&tcon->num_t2renames));
42384+ atomic_read_unchecked(&tcon->num_renames),
42385+ atomic_read_unchecked(&tcon->num_t2renames));
42386 seq_printf(m, "\nFindFirst: %d FNext %d "
42387 "FClose %d",
42388- atomic_read(&tcon->num_ffirst),
42389- atomic_read(&tcon->num_fnext),
42390- atomic_read(&tcon->num_fclose));
42391+ atomic_read_unchecked(&tcon->num_ffirst),
42392+ atomic_read_unchecked(&tcon->num_fnext),
42393+ atomic_read_unchecked(&tcon->num_fclose));
42394 }
42395 }
42396 }
42397diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
42398index 6ee1cb4..8443157 100644
42399--- a/fs/cifs/cifsfs.c
42400+++ b/fs/cifs/cifsfs.c
42401@@ -989,7 +989,7 @@ cifs_init_request_bufs(void)
42402 cifs_req_cachep = kmem_cache_create("cifs_request",
42403 CIFSMaxBufSize +
42404 MAX_CIFS_HDR_SIZE, 0,
42405- SLAB_HWCACHE_ALIGN, NULL);
42406+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
42407 if (cifs_req_cachep == NULL)
42408 return -ENOMEM;
42409
42410@@ -1016,7 +1016,7 @@ cifs_init_request_bufs(void)
42411 efficient to alloc 1 per page off the slab compared to 17K (5page)
42412 alloc of large cifs buffers even when page debugging is on */
42413 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
42414- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
42415+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
42416 NULL);
42417 if (cifs_sm_req_cachep == NULL) {
42418 mempool_destroy(cifs_req_poolp);
42419@@ -1101,8 +1101,8 @@ init_cifs(void)
42420 atomic_set(&bufAllocCount, 0);
42421 atomic_set(&smBufAllocCount, 0);
42422 #ifdef CONFIG_CIFS_STATS2
42423- atomic_set(&totBufAllocCount, 0);
42424- atomic_set(&totSmBufAllocCount, 0);
42425+ atomic_set_unchecked(&totBufAllocCount, 0);
42426+ atomic_set_unchecked(&totSmBufAllocCount, 0);
42427 #endif /* CONFIG_CIFS_STATS2 */
42428
42429 atomic_set(&midCount, 0);
42430diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
42431index d47d20a..77e8b33 100644
42432--- a/fs/cifs/cifsglob.h
42433+++ b/fs/cifs/cifsglob.h
42434@@ -388,28 +388,28 @@ struct cifs_tcon {
42435 __u16 Flags; /* optional support bits */
42436 enum statusEnum tidStatus;
42437 #ifdef CONFIG_CIFS_STATS
42438- atomic_t num_smbs_sent;
42439- atomic_t num_writes;
42440- atomic_t num_reads;
42441- atomic_t num_flushes;
42442- atomic_t num_oplock_brks;
42443- atomic_t num_opens;
42444- atomic_t num_closes;
42445- atomic_t num_deletes;
42446- atomic_t num_mkdirs;
42447- atomic_t num_posixopens;
42448- atomic_t num_posixmkdirs;
42449- atomic_t num_rmdirs;
42450- atomic_t num_renames;
42451- atomic_t num_t2renames;
42452- atomic_t num_ffirst;
42453- atomic_t num_fnext;
42454- atomic_t num_fclose;
42455- atomic_t num_hardlinks;
42456- atomic_t num_symlinks;
42457- atomic_t num_locks;
42458- atomic_t num_acl_get;
42459- atomic_t num_acl_set;
42460+ atomic_unchecked_t num_smbs_sent;
42461+ atomic_unchecked_t num_writes;
42462+ atomic_unchecked_t num_reads;
42463+ atomic_unchecked_t num_flushes;
42464+ atomic_unchecked_t num_oplock_brks;
42465+ atomic_unchecked_t num_opens;
42466+ atomic_unchecked_t num_closes;
42467+ atomic_unchecked_t num_deletes;
42468+ atomic_unchecked_t num_mkdirs;
42469+ atomic_unchecked_t num_posixopens;
42470+ atomic_unchecked_t num_posixmkdirs;
42471+ atomic_unchecked_t num_rmdirs;
42472+ atomic_unchecked_t num_renames;
42473+ atomic_unchecked_t num_t2renames;
42474+ atomic_unchecked_t num_ffirst;
42475+ atomic_unchecked_t num_fnext;
42476+ atomic_unchecked_t num_fclose;
42477+ atomic_unchecked_t num_hardlinks;
42478+ atomic_unchecked_t num_symlinks;
42479+ atomic_unchecked_t num_locks;
42480+ atomic_unchecked_t num_acl_get;
42481+ atomic_unchecked_t num_acl_set;
42482 #ifdef CONFIG_CIFS_STATS2
42483 unsigned long long time_writes;
42484 unsigned long long time_reads;
42485@@ -624,7 +624,7 @@ convert_delimiter(char *path, char delim)
42486 }
42487
42488 #ifdef CONFIG_CIFS_STATS
42489-#define cifs_stats_inc atomic_inc
42490+#define cifs_stats_inc atomic_inc_unchecked
42491
42492 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
42493 unsigned int bytes)
42494@@ -983,8 +983,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
42495 /* Various Debug counters */
42496 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
42497 #ifdef CONFIG_CIFS_STATS2
42498-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
42499-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
42500+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
42501+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
42502 #endif
42503 GLOBAL_EXTERN atomic_t smBufAllocCount;
42504 GLOBAL_EXTERN atomic_t midCount;
42505diff --git a/fs/cifs/link.c b/fs/cifs/link.c
42506index 6b0e064..94e6c3c 100644
42507--- a/fs/cifs/link.c
42508+++ b/fs/cifs/link.c
42509@@ -600,7 +600,7 @@ symlink_exit:
42510
42511 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
42512 {
42513- char *p = nd_get_link(nd);
42514+ const char *p = nd_get_link(nd);
42515 if (!IS_ERR(p))
42516 kfree(p);
42517 }
42518diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
42519index 703ef5c..2a44ed5 100644
42520--- a/fs/cifs/misc.c
42521+++ b/fs/cifs/misc.c
42522@@ -156,7 +156,7 @@ cifs_buf_get(void)
42523 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
42524 atomic_inc(&bufAllocCount);
42525 #ifdef CONFIG_CIFS_STATS2
42526- atomic_inc(&totBufAllocCount);
42527+ atomic_inc_unchecked(&totBufAllocCount);
42528 #endif /* CONFIG_CIFS_STATS2 */
42529 }
42530
42531@@ -191,7 +191,7 @@ cifs_small_buf_get(void)
42532 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
42533 atomic_inc(&smBufAllocCount);
42534 #ifdef CONFIG_CIFS_STATS2
42535- atomic_inc(&totSmBufAllocCount);
42536+ atomic_inc_unchecked(&totSmBufAllocCount);
42537 #endif /* CONFIG_CIFS_STATS2 */
42538
42539 }
42540diff --git a/fs/coda/cache.c b/fs/coda/cache.c
42541index 6901578..d402eb5 100644
42542--- a/fs/coda/cache.c
42543+++ b/fs/coda/cache.c
42544@@ -24,7 +24,7 @@
42545 #include "coda_linux.h"
42546 #include "coda_cache.h"
42547
42548-static atomic_t permission_epoch = ATOMIC_INIT(0);
42549+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
42550
42551 /* replace or extend an acl cache hit */
42552 void coda_cache_enter(struct inode *inode, int mask)
42553@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
42554 struct coda_inode_info *cii = ITOC(inode);
42555
42556 spin_lock(&cii->c_lock);
42557- cii->c_cached_epoch = atomic_read(&permission_epoch);
42558+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
42559 if (cii->c_uid != current_fsuid()) {
42560 cii->c_uid = current_fsuid();
42561 cii->c_cached_perm = mask;
42562@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
42563 {
42564 struct coda_inode_info *cii = ITOC(inode);
42565 spin_lock(&cii->c_lock);
42566- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
42567+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
42568 spin_unlock(&cii->c_lock);
42569 }
42570
42571 /* remove all acl caches */
42572 void coda_cache_clear_all(struct super_block *sb)
42573 {
42574- atomic_inc(&permission_epoch);
42575+ atomic_inc_unchecked(&permission_epoch);
42576 }
42577
42578
42579@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
42580 spin_lock(&cii->c_lock);
42581 hit = (mask & cii->c_cached_perm) == mask &&
42582 cii->c_uid == current_fsuid() &&
42583- cii->c_cached_epoch == atomic_read(&permission_epoch);
42584+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
42585 spin_unlock(&cii->c_lock);
42586
42587 return hit;
42588diff --git a/fs/compat.c b/fs/compat.c
42589index 07880ba..3fb2862 100644
42590--- a/fs/compat.c
42591+++ b/fs/compat.c
42592@@ -491,7 +491,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
42593
42594 set_fs(KERNEL_DS);
42595 /* The __user pointer cast is valid because of the set_fs() */
42596- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
42597+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
42598 set_fs(oldfs);
42599 /* truncating is ok because it's a user address */
42600 if (!ret)
42601@@ -549,7 +549,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
42602 goto out;
42603
42604 ret = -EINVAL;
42605- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
42606+ if (nr_segs > UIO_MAXIOV)
42607 goto out;
42608 if (nr_segs > fast_segs) {
42609 ret = -ENOMEM;
42610@@ -832,6 +832,7 @@ struct compat_old_linux_dirent {
42611
42612 struct compat_readdir_callback {
42613 struct compat_old_linux_dirent __user *dirent;
42614+ struct file * file;
42615 int result;
42616 };
42617
42618@@ -849,6 +850,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
42619 buf->result = -EOVERFLOW;
42620 return -EOVERFLOW;
42621 }
42622+
42623+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
42624+ return 0;
42625+
42626 buf->result++;
42627 dirent = buf->dirent;
42628 if (!access_ok(VERIFY_WRITE, dirent,
42629@@ -881,6 +886,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
42630
42631 buf.result = 0;
42632 buf.dirent = dirent;
42633+ buf.file = file;
42634
42635 error = vfs_readdir(file, compat_fillonedir, &buf);
42636 if (buf.result)
42637@@ -901,6 +907,7 @@ struct compat_linux_dirent {
42638 struct compat_getdents_callback {
42639 struct compat_linux_dirent __user *current_dir;
42640 struct compat_linux_dirent __user *previous;
42641+ struct file * file;
42642 int count;
42643 int error;
42644 };
42645@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
42646 buf->error = -EOVERFLOW;
42647 return -EOVERFLOW;
42648 }
42649+
42650+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
42651+ return 0;
42652+
42653 dirent = buf->previous;
42654 if (dirent) {
42655 if (__put_user(offset, &dirent->d_off))
42656@@ -969,6 +980,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
42657 buf.previous = NULL;
42658 buf.count = count;
42659 buf.error = 0;
42660+ buf.file = file;
42661
42662 error = vfs_readdir(file, compat_filldir, &buf);
42663 if (error >= 0)
42664@@ -990,6 +1002,7 @@ out:
42665 struct compat_getdents_callback64 {
42666 struct linux_dirent64 __user *current_dir;
42667 struct linux_dirent64 __user *previous;
42668+ struct file * file;
42669 int count;
42670 int error;
42671 };
42672@@ -1006,6 +1019,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
42673 buf->error = -EINVAL; /* only used if we fail.. */
42674 if (reclen > buf->count)
42675 return -EINVAL;
42676+
42677+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
42678+ return 0;
42679+
42680 dirent = buf->previous;
42681
42682 if (dirent) {
42683@@ -1057,13 +1074,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
42684 buf.previous = NULL;
42685 buf.count = count;
42686 buf.error = 0;
42687+ buf.file = file;
42688
42689 error = vfs_readdir(file, compat_filldir64, &buf);
42690 if (error >= 0)
42691 error = buf.error;
42692 lastdirent = buf.previous;
42693 if (lastdirent) {
42694- typeof(lastdirent->d_off) d_off = file->f_pos;
42695+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
42696 if (__put_user_unaligned(d_off, &lastdirent->d_off))
42697 error = -EFAULT;
42698 else
42699diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
42700index 112e45a..b59845b 100644
42701--- a/fs/compat_binfmt_elf.c
42702+++ b/fs/compat_binfmt_elf.c
42703@@ -30,11 +30,13 @@
42704 #undef elf_phdr
42705 #undef elf_shdr
42706 #undef elf_note
42707+#undef elf_dyn
42708 #undef elf_addr_t
42709 #define elfhdr elf32_hdr
42710 #define elf_phdr elf32_phdr
42711 #define elf_shdr elf32_shdr
42712 #define elf_note elf32_note
42713+#define elf_dyn Elf32_Dyn
42714 #define elf_addr_t Elf32_Addr
42715
42716 /*
42717diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
42718index a26bea1..ae23e72 100644
42719--- a/fs/compat_ioctl.c
42720+++ b/fs/compat_ioctl.c
42721@@ -211,6 +211,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
42722
42723 err = get_user(palp, &up->palette);
42724 err |= get_user(length, &up->length);
42725+ if (err)
42726+ return -EFAULT;
42727
42728 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
42729 err = put_user(compat_ptr(palp), &up_native->palette);
42730@@ -622,7 +624,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
42731 return -EFAULT;
42732 if (__get_user(udata, &ss32->iomem_base))
42733 return -EFAULT;
42734- ss.iomem_base = compat_ptr(udata);
42735+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
42736 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
42737 __get_user(ss.port_high, &ss32->port_high))
42738 return -EFAULT;
42739@@ -797,7 +799,7 @@ static int compat_ioctl_preallocate(struct file *file,
42740 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
42741 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
42742 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
42743- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
42744+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
42745 return -EFAULT;
42746
42747 return ioctl_preallocate(file, p);
42748@@ -1611,8 +1613,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
42749 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
42750 {
42751 unsigned int a, b;
42752- a = *(unsigned int *)p;
42753- b = *(unsigned int *)q;
42754+ a = *(const unsigned int *)p;
42755+ b = *(const unsigned int *)q;
42756 if (a > b)
42757 return 1;
42758 if (a < b)
42759diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
42760index 5ddd7eb..c18bf04 100644
42761--- a/fs/configfs/dir.c
42762+++ b/fs/configfs/dir.c
42763@@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
42764 }
42765 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
42766 struct configfs_dirent *next;
42767- const char * name;
42768+ const unsigned char * name;
42769+ char d_name[sizeof(next->s_dentry->d_iname)];
42770 int len;
42771 struct inode *inode = NULL;
42772
42773@@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
42774 continue;
42775
42776 name = configfs_get_name(next);
42777- len = strlen(name);
42778+ if (next->s_dentry && name == next->s_dentry->d_iname) {
42779+ len = next->s_dentry->d_name.len;
42780+ memcpy(d_name, name, len);
42781+ name = d_name;
42782+ } else
42783+ len = strlen(name);
42784
42785 /*
42786 * We'll have a dentry and an inode for
42787diff --git a/fs/dcache.c b/fs/dcache.c
42788index 2576d14..0cec38d 100644
42789--- a/fs/dcache.c
42790+++ b/fs/dcache.c
42791@@ -105,10 +105,10 @@ static unsigned int d_hash_shift __read_mostly;
42792 static struct hlist_bl_head *dentry_hashtable __read_mostly;
42793
42794 static inline struct hlist_bl_head *d_hash(const struct dentry *parent,
42795- unsigned long hash)
42796+ unsigned int hash)
42797 {
42798- hash += ((unsigned long) parent ^ GOLDEN_RATIO_PRIME) / L1_CACHE_BYTES;
42799- hash = hash ^ ((hash ^ GOLDEN_RATIO_PRIME) >> D_HASHBITS);
42800+ hash += (unsigned long) parent / L1_CACHE_BYTES;
42801+ hash = hash + (hash >> D_HASHBITS);
42802 return dentry_hashtable + (hash & D_HASHMASK);
42803 }
42804
42805@@ -3067,7 +3067,7 @@ void __init vfs_caches_init(unsigned long mempages)
42806 mempages -= reserve;
42807
42808 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
42809- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
42810+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
42811
42812 dcache_init();
42813 inode_init();
42814diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
42815index 956d5dd..e755e04 100644
42816--- a/fs/debugfs/inode.c
42817+++ b/fs/debugfs/inode.c
42818@@ -261,7 +261,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
42819 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
42820 {
42821 return debugfs_create_file(name,
42822+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
42823+ S_IFDIR | S_IRWXU,
42824+#else
42825 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
42826+#endif
42827 parent, NULL, NULL);
42828 }
42829 EXPORT_SYMBOL_GPL(debugfs_create_dir);
42830diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
42831index ab35b11..b30af66 100644
42832--- a/fs/ecryptfs/inode.c
42833+++ b/fs/ecryptfs/inode.c
42834@@ -672,7 +672,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
42835 old_fs = get_fs();
42836 set_fs(get_ds());
42837 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
42838- (char __user *)lower_buf,
42839+ (char __force_user *)lower_buf,
42840 lower_bufsiz);
42841 set_fs(old_fs);
42842 if (rc < 0)
42843@@ -718,7 +718,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42844 }
42845 old_fs = get_fs();
42846 set_fs(get_ds());
42847- rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
42848+ rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
42849 set_fs(old_fs);
42850 if (rc < 0) {
42851 kfree(buf);
42852@@ -733,7 +733,7 @@ out:
42853 static void
42854 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
42855 {
42856- char *buf = nd_get_link(nd);
42857+ const char *buf = nd_get_link(nd);
42858 if (!IS_ERR(buf)) {
42859 /* Free the char* */
42860 kfree(buf);
42861diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
42862index 3a06f40..f7af544 100644
42863--- a/fs/ecryptfs/miscdev.c
42864+++ b/fs/ecryptfs/miscdev.c
42865@@ -345,7 +345,7 @@ check_list:
42866 goto out_unlock_msg_ctx;
42867 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
42868 if (msg_ctx->msg) {
42869- if (copy_to_user(&buf[i], packet_length, packet_length_size))
42870+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
42871 goto out_unlock_msg_ctx;
42872 i += packet_length_size;
42873 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
42874diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
42875index b2a34a1..162fa69 100644
42876--- a/fs/ecryptfs/read_write.c
42877+++ b/fs/ecryptfs/read_write.c
42878@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
42879 return -EIO;
42880 fs_save = get_fs();
42881 set_fs(get_ds());
42882- rc = vfs_write(lower_file, data, size, &offset);
42883+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
42884 set_fs(fs_save);
42885 mark_inode_dirty_sync(ecryptfs_inode);
42886 return rc;
42887@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
42888 return -EIO;
42889 fs_save = get_fs();
42890 set_fs(get_ds());
42891- rc = vfs_read(lower_file, data, size, &offset);
42892+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
42893 set_fs(fs_save);
42894 return rc;
42895 }
42896diff --git a/fs/exec.c b/fs/exec.c
42897index 153dee1..8ee97ba 100644
42898--- a/fs/exec.c
42899+++ b/fs/exec.c
42900@@ -55,6 +55,13 @@
42901 #include <linux/pipe_fs_i.h>
42902 #include <linux/oom.h>
42903 #include <linux/compat.h>
42904+#include <linux/random.h>
42905+#include <linux/seq_file.h>
42906+
42907+#ifdef CONFIG_PAX_REFCOUNT
42908+#include <linux/kallsyms.h>
42909+#include <linux/kdebug.h>
42910+#endif
42911
42912 #include <asm/uaccess.h>
42913 #include <asm/mmu_context.h>
42914@@ -63,6 +70,15 @@
42915 #include <trace/events/task.h>
42916 #include "internal.h"
42917
42918+#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
42919+void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
42920+#endif
42921+
42922+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
42923+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
42924+EXPORT_SYMBOL(pax_set_initial_flags_func);
42925+#endif
42926+
42927 int core_uses_pid;
42928 char core_pattern[CORENAME_MAX_SIZE] = "core";
42929 unsigned int core_pipe_limit;
42930@@ -72,7 +88,7 @@ struct core_name {
42931 char *corename;
42932 int used, size;
42933 };
42934-static atomic_t call_count = ATOMIC_INIT(1);
42935+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
42936
42937 /* The maximal length of core_pattern is also specified in sysctl.c */
42938
42939@@ -190,18 +206,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
42940 int write)
42941 {
42942 struct page *page;
42943- int ret;
42944
42945-#ifdef CONFIG_STACK_GROWSUP
42946- if (write) {
42947- ret = expand_downwards(bprm->vma, pos);
42948- if (ret < 0)
42949- return NULL;
42950- }
42951-#endif
42952- ret = get_user_pages(current, bprm->mm, pos,
42953- 1, write, 1, &page, NULL);
42954- if (ret <= 0)
42955+ if (0 > expand_downwards(bprm->vma, pos))
42956+ return NULL;
42957+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
42958 return NULL;
42959
42960 if (write) {
42961@@ -217,6 +225,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
42962 if (size <= ARG_MAX)
42963 return page;
42964
42965+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42966+ // only allow 512KB for argv+env on suid/sgid binaries
42967+ // to prevent easy ASLR exhaustion
42968+ if (((bprm->cred->euid != current_euid()) ||
42969+ (bprm->cred->egid != current_egid())) &&
42970+ (size > (512 * 1024))) {
42971+ put_page(page);
42972+ return NULL;
42973+ }
42974+#endif
42975+
42976 /*
42977 * Limit to 1/4-th the stack size for the argv+env strings.
42978 * This ensures that:
42979@@ -276,6 +295,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
42980 vma->vm_end = STACK_TOP_MAX;
42981 vma->vm_start = vma->vm_end - PAGE_SIZE;
42982 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
42983+
42984+#ifdef CONFIG_PAX_SEGMEXEC
42985+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
42986+#endif
42987+
42988 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
42989 INIT_LIST_HEAD(&vma->anon_vma_chain);
42990
42991@@ -290,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
42992 mm->stack_vm = mm->total_vm = 1;
42993 up_write(&mm->mmap_sem);
42994 bprm->p = vma->vm_end - sizeof(void *);
42995+
42996+#ifdef CONFIG_PAX_RANDUSTACK
42997+ if (randomize_va_space)
42998+ bprm->p ^= random32() & ~PAGE_MASK;
42999+#endif
43000+
43001 return 0;
43002 err:
43003 up_write(&mm->mmap_sem);
43004@@ -398,19 +428,7 @@ err:
43005 return err;
43006 }
43007
43008-struct user_arg_ptr {
43009-#ifdef CONFIG_COMPAT
43010- bool is_compat;
43011-#endif
43012- union {
43013- const char __user *const __user *native;
43014-#ifdef CONFIG_COMPAT
43015- compat_uptr_t __user *compat;
43016-#endif
43017- } ptr;
43018-};
43019-
43020-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43021+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43022 {
43023 const char __user *native;
43024
43025@@ -419,14 +437,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43026 compat_uptr_t compat;
43027
43028 if (get_user(compat, argv.ptr.compat + nr))
43029- return ERR_PTR(-EFAULT);
43030+ return (const char __force_user *)ERR_PTR(-EFAULT);
43031
43032 return compat_ptr(compat);
43033 }
43034 #endif
43035
43036 if (get_user(native, argv.ptr.native + nr))
43037- return ERR_PTR(-EFAULT);
43038+ return (const char __force_user *)ERR_PTR(-EFAULT);
43039
43040 return native;
43041 }
43042@@ -445,7 +463,7 @@ static int count(struct user_arg_ptr argv, int max)
43043 if (!p)
43044 break;
43045
43046- if (IS_ERR(p))
43047+ if (IS_ERR((const char __force_kernel *)p))
43048 return -EFAULT;
43049
43050 if (i++ >= max)
43051@@ -479,7 +497,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
43052
43053 ret = -EFAULT;
43054 str = get_user_arg_ptr(argv, argc);
43055- if (IS_ERR(str))
43056+ if (IS_ERR((const char __force_kernel *)str))
43057 goto out;
43058
43059 len = strnlen_user(str, MAX_ARG_STRLEN);
43060@@ -561,7 +579,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
43061 int r;
43062 mm_segment_t oldfs = get_fs();
43063 struct user_arg_ptr argv = {
43064- .ptr.native = (const char __user *const __user *)__argv,
43065+ .ptr.native = (const char __force_user *const __force_user *)__argv,
43066 };
43067
43068 set_fs(KERNEL_DS);
43069@@ -596,7 +614,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
43070 unsigned long new_end = old_end - shift;
43071 struct mmu_gather tlb;
43072
43073- BUG_ON(new_start > new_end);
43074+ if (new_start >= new_end || new_start < mmap_min_addr)
43075+ return -ENOMEM;
43076
43077 /*
43078 * ensure there are no vmas between where we want to go
43079@@ -605,6 +624,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
43080 if (vma != find_vma(mm, new_start))
43081 return -EFAULT;
43082
43083+#ifdef CONFIG_PAX_SEGMEXEC
43084+ BUG_ON(pax_find_mirror_vma(vma));
43085+#endif
43086+
43087 /*
43088 * cover the whole range: [new_start, old_end)
43089 */
43090@@ -685,10 +708,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
43091 stack_top = arch_align_stack(stack_top);
43092 stack_top = PAGE_ALIGN(stack_top);
43093
43094- if (unlikely(stack_top < mmap_min_addr) ||
43095- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
43096- return -ENOMEM;
43097-
43098 stack_shift = vma->vm_end - stack_top;
43099
43100 bprm->p -= stack_shift;
43101@@ -700,8 +719,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
43102 bprm->exec -= stack_shift;
43103
43104 down_write(&mm->mmap_sem);
43105+
43106+ /* Move stack pages down in memory. */
43107+ if (stack_shift) {
43108+ ret = shift_arg_pages(vma, stack_shift);
43109+ if (ret)
43110+ goto out_unlock;
43111+ }
43112+
43113 vm_flags = VM_STACK_FLAGS;
43114
43115+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43116+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43117+ vm_flags &= ~VM_EXEC;
43118+
43119+#ifdef CONFIG_PAX_MPROTECT
43120+ if (mm->pax_flags & MF_PAX_MPROTECT)
43121+ vm_flags &= ~VM_MAYEXEC;
43122+#endif
43123+
43124+ }
43125+#endif
43126+
43127 /*
43128 * Adjust stack execute permissions; explicitly enable for
43129 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
43130@@ -720,13 +759,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
43131 goto out_unlock;
43132 BUG_ON(prev != vma);
43133
43134- /* Move stack pages down in memory. */
43135- if (stack_shift) {
43136- ret = shift_arg_pages(vma, stack_shift);
43137- if (ret)
43138- goto out_unlock;
43139- }
43140-
43141 /* mprotect_fixup is overkill to remove the temporary stack flags */
43142 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
43143
43144@@ -807,7 +839,7 @@ int kernel_read(struct file *file, loff_t offset,
43145 old_fs = get_fs();
43146 set_fs(get_ds());
43147 /* The cast to a user pointer is valid due to the set_fs() */
43148- result = vfs_read(file, (void __user *)addr, count, &pos);
43149+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
43150 set_fs(old_fs);
43151 return result;
43152 }
43153@@ -1252,7 +1284,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
43154 }
43155 rcu_read_unlock();
43156
43157- if (p->fs->users > n_fs) {
43158+ if (atomic_read(&p->fs->users) > n_fs) {
43159 bprm->unsafe |= LSM_UNSAFE_SHARE;
43160 } else {
43161 res = -EAGAIN;
43162@@ -1447,6 +1479,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
43163
43164 EXPORT_SYMBOL(search_binary_handler);
43165
43166+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43167+static DEFINE_PER_CPU(u64, exec_counter);
43168+static int __init init_exec_counters(void)
43169+{
43170+ unsigned int cpu;
43171+
43172+ for_each_possible_cpu(cpu) {
43173+ per_cpu(exec_counter, cpu) = (u64)cpu;
43174+ }
43175+
43176+ return 0;
43177+}
43178+early_initcall(init_exec_counters);
43179+static inline void increment_exec_counter(void)
43180+{
43181+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
43182+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
43183+}
43184+#else
43185+static inline void increment_exec_counter(void) {}
43186+#endif
43187+
43188 /*
43189 * sys_execve() executes a new program.
43190 */
43191@@ -1455,6 +1509,11 @@ static int do_execve_common(const char *filename,
43192 struct user_arg_ptr envp,
43193 struct pt_regs *regs)
43194 {
43195+#ifdef CONFIG_GRKERNSEC
43196+ struct file *old_exec_file;
43197+ struct acl_subject_label *old_acl;
43198+ struct rlimit old_rlim[RLIM_NLIMITS];
43199+#endif
43200 struct linux_binprm *bprm;
43201 struct file *file;
43202 struct files_struct *displaced;
43203@@ -1462,6 +1521,8 @@ static int do_execve_common(const char *filename,
43204 int retval;
43205 const struct cred *cred = current_cred();
43206
43207+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
43208+
43209 /*
43210 * We move the actual failure in case of RLIMIT_NPROC excess from
43211 * set*uid() to execve() because too many poorly written programs
43212@@ -1502,12 +1563,27 @@ static int do_execve_common(const char *filename,
43213 if (IS_ERR(file))
43214 goto out_unmark;
43215
43216+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
43217+ retval = -EPERM;
43218+ goto out_file;
43219+ }
43220+
43221 sched_exec();
43222
43223 bprm->file = file;
43224 bprm->filename = filename;
43225 bprm->interp = filename;
43226
43227+ if (gr_process_user_ban()) {
43228+ retval = -EPERM;
43229+ goto out_file;
43230+ }
43231+
43232+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
43233+ retval = -EACCES;
43234+ goto out_file;
43235+ }
43236+
43237 retval = bprm_mm_init(bprm);
43238 if (retval)
43239 goto out_file;
43240@@ -1524,24 +1600,65 @@ static int do_execve_common(const char *filename,
43241 if (retval < 0)
43242 goto out;
43243
43244+#ifdef CONFIG_GRKERNSEC
43245+ old_acl = current->acl;
43246+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
43247+ old_exec_file = current->exec_file;
43248+ get_file(file);
43249+ current->exec_file = file;
43250+#endif
43251+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43252+ /* limit suid stack to 8MB
43253+ we saved the old limits above and will restore them if this exec fails
43254+ */
43255+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
43256+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
43257+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
43258+#endif
43259+
43260+ if (!gr_tpe_allow(file)) {
43261+ retval = -EACCES;
43262+ goto out_fail;
43263+ }
43264+
43265+ if (gr_check_crash_exec(file)) {
43266+ retval = -EACCES;
43267+ goto out_fail;
43268+ }
43269+
43270+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
43271+ bprm->unsafe);
43272+ if (retval < 0)
43273+ goto out_fail;
43274+
43275 retval = copy_strings_kernel(1, &bprm->filename, bprm);
43276 if (retval < 0)
43277- goto out;
43278+ goto out_fail;
43279
43280 bprm->exec = bprm->p;
43281 retval = copy_strings(bprm->envc, envp, bprm);
43282 if (retval < 0)
43283- goto out;
43284+ goto out_fail;
43285
43286 retval = copy_strings(bprm->argc, argv, bprm);
43287 if (retval < 0)
43288- goto out;
43289+ goto out_fail;
43290+
43291+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
43292+
43293+ gr_handle_exec_args(bprm, argv);
43294
43295 retval = search_binary_handler(bprm,regs);
43296 if (retval < 0)
43297- goto out;
43298+ goto out_fail;
43299+#ifdef CONFIG_GRKERNSEC
43300+ if (old_exec_file)
43301+ fput(old_exec_file);
43302+#endif
43303
43304 /* execve succeeded */
43305+
43306+ increment_exec_counter();
43307 current->fs->in_exec = 0;
43308 current->in_execve = 0;
43309 acct_update_integrals(current);
43310@@ -1550,6 +1667,14 @@ static int do_execve_common(const char *filename,
43311 put_files_struct(displaced);
43312 return retval;
43313
43314+out_fail:
43315+#ifdef CONFIG_GRKERNSEC
43316+ current->acl = old_acl;
43317+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
43318+ fput(current->exec_file);
43319+ current->exec_file = old_exec_file;
43320+#endif
43321+
43322 out:
43323 if (bprm->mm) {
43324 acct_arg_size(bprm, 0);
43325@@ -1623,7 +1748,7 @@ static int expand_corename(struct core_name *cn)
43326 {
43327 char *old_corename = cn->corename;
43328
43329- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
43330+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
43331 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
43332
43333 if (!cn->corename) {
43334@@ -1720,7 +1845,7 @@ static int format_corename(struct core_name *cn, long signr)
43335 int pid_in_pattern = 0;
43336 int err = 0;
43337
43338- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
43339+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
43340 cn->corename = kmalloc(cn->size, GFP_KERNEL);
43341 cn->used = 0;
43342
43343@@ -1817,6 +1942,218 @@ out:
43344 return ispipe;
43345 }
43346
43347+int pax_check_flags(unsigned long *flags)
43348+{
43349+ int retval = 0;
43350+
43351+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
43352+ if (*flags & MF_PAX_SEGMEXEC)
43353+ {
43354+ *flags &= ~MF_PAX_SEGMEXEC;
43355+ retval = -EINVAL;
43356+ }
43357+#endif
43358+
43359+ if ((*flags & MF_PAX_PAGEEXEC)
43360+
43361+#ifdef CONFIG_PAX_PAGEEXEC
43362+ && (*flags & MF_PAX_SEGMEXEC)
43363+#endif
43364+
43365+ )
43366+ {
43367+ *flags &= ~MF_PAX_PAGEEXEC;
43368+ retval = -EINVAL;
43369+ }
43370+
43371+ if ((*flags & MF_PAX_MPROTECT)
43372+
43373+#ifdef CONFIG_PAX_MPROTECT
43374+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
43375+#endif
43376+
43377+ )
43378+ {
43379+ *flags &= ~MF_PAX_MPROTECT;
43380+ retval = -EINVAL;
43381+ }
43382+
43383+ if ((*flags & MF_PAX_EMUTRAMP)
43384+
43385+#ifdef CONFIG_PAX_EMUTRAMP
43386+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
43387+#endif
43388+
43389+ )
43390+ {
43391+ *flags &= ~MF_PAX_EMUTRAMP;
43392+ retval = -EINVAL;
43393+ }
43394+
43395+ return retval;
43396+}
43397+
43398+EXPORT_SYMBOL(pax_check_flags);
43399+
43400+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43401+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
43402+{
43403+ struct task_struct *tsk = current;
43404+ struct mm_struct *mm = current->mm;
43405+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
43406+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
43407+ char *path_exec = NULL;
43408+ char *path_fault = NULL;
43409+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
43410+
43411+ if (buffer_exec && buffer_fault) {
43412+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
43413+
43414+ down_read(&mm->mmap_sem);
43415+ vma = mm->mmap;
43416+ while (vma && (!vma_exec || !vma_fault)) {
43417+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
43418+ vma_exec = vma;
43419+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
43420+ vma_fault = vma;
43421+ vma = vma->vm_next;
43422+ }
43423+ if (vma_exec) {
43424+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
43425+ if (IS_ERR(path_exec))
43426+ path_exec = "<path too long>";
43427+ else {
43428+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
43429+ if (path_exec) {
43430+ *path_exec = 0;
43431+ path_exec = buffer_exec;
43432+ } else
43433+ path_exec = "<path too long>";
43434+ }
43435+ }
43436+ if (vma_fault) {
43437+ start = vma_fault->vm_start;
43438+ end = vma_fault->vm_end;
43439+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
43440+ if (vma_fault->vm_file) {
43441+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
43442+ if (IS_ERR(path_fault))
43443+ path_fault = "<path too long>";
43444+ else {
43445+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
43446+ if (path_fault) {
43447+ *path_fault = 0;
43448+ path_fault = buffer_fault;
43449+ } else
43450+ path_fault = "<path too long>";
43451+ }
43452+ } else
43453+ path_fault = "<anonymous mapping>";
43454+ }
43455+ up_read(&mm->mmap_sem);
43456+ }
43457+ if (tsk->signal->curr_ip)
43458+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
43459+ else
43460+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
43461+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
43462+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
43463+ task_uid(tsk), task_euid(tsk), pc, sp);
43464+ free_page((unsigned long)buffer_exec);
43465+ free_page((unsigned long)buffer_fault);
43466+ pax_report_insns(regs, pc, sp);
43467+ do_coredump(SIGKILL, SIGKILL, regs);
43468+}
43469+#endif
43470+
43471+#ifdef CONFIG_PAX_REFCOUNT
43472+void pax_report_refcount_overflow(struct pt_regs *regs)
43473+{
43474+ if (current->signal->curr_ip)
43475+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
43476+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
43477+ else
43478+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
43479+ current->comm, task_pid_nr(current), current_uid(), current_euid());
43480+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
43481+ show_regs(regs);
43482+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
43483+}
43484+#endif
43485+
43486+#ifdef CONFIG_PAX_USERCOPY
43487+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
43488+int object_is_on_stack(const void *obj, unsigned long len)
43489+{
43490+ const void * const stack = task_stack_page(current);
43491+ const void * const stackend = stack + THREAD_SIZE;
43492+
43493+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
43494+ const void *frame = NULL;
43495+ const void *oldframe;
43496+#endif
43497+
43498+ if (obj + len < obj)
43499+ return -1;
43500+
43501+ if (obj + len <= stack || stackend <= obj)
43502+ return 0;
43503+
43504+ if (obj < stack || stackend < obj + len)
43505+ return -1;
43506+
43507+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
43508+ oldframe = __builtin_frame_address(1);
43509+ if (oldframe)
43510+ frame = __builtin_frame_address(2);
43511+ /*
43512+ low ----------------------------------------------> high
43513+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
43514+ ^----------------^
43515+ allow copies only within here
43516+ */
43517+ while (stack <= frame && frame < stackend) {
43518+ /* if obj + len extends past the last frame, this
43519+ check won't pass and the next frame will be 0,
43520+ causing us to bail out and correctly report
43521+ the copy as invalid
43522+ */
43523+ if (obj + len <= frame)
43524+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
43525+ oldframe = frame;
43526+ frame = *(const void * const *)frame;
43527+ }
43528+ return -1;
43529+#else
43530+ return 1;
43531+#endif
43532+}
43533+
43534+__noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
43535+{
43536+ if (current->signal->curr_ip)
43537+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
43538+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
43539+ else
43540+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
43541+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
43542+ dump_stack();
43543+ gr_handle_kernel_exploit();
43544+ do_group_exit(SIGKILL);
43545+}
43546+#endif
43547+
43548+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
43549+void pax_track_stack(void)
43550+{
43551+ unsigned long sp = (unsigned long)&sp;
43552+ if (sp < current_thread_info()->lowest_stack &&
43553+ sp > (unsigned long)task_stack_page(current))
43554+ current_thread_info()->lowest_stack = sp;
43555+}
43556+EXPORT_SYMBOL(pax_track_stack);
43557+#endif
43558+
43559 static int zap_process(struct task_struct *start, int exit_code)
43560 {
43561 struct task_struct *t;
43562@@ -2014,17 +2351,17 @@ static void wait_for_dump_helpers(struct file *file)
43563 pipe = file->f_path.dentry->d_inode->i_pipe;
43564
43565 pipe_lock(pipe);
43566- pipe->readers++;
43567- pipe->writers--;
43568+ atomic_inc(&pipe->readers);
43569+ atomic_dec(&pipe->writers);
43570
43571- while ((pipe->readers > 1) && (!signal_pending(current))) {
43572+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
43573 wake_up_interruptible_sync(&pipe->wait);
43574 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
43575 pipe_wait(pipe);
43576 }
43577
43578- pipe->readers--;
43579- pipe->writers++;
43580+ atomic_dec(&pipe->readers);
43581+ atomic_inc(&pipe->writers);
43582 pipe_unlock(pipe);
43583
43584 }
43585@@ -2085,7 +2422,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
43586 int retval = 0;
43587 int flag = 0;
43588 int ispipe;
43589- static atomic_t core_dump_count = ATOMIC_INIT(0);
43590+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
43591 struct coredump_params cprm = {
43592 .signr = signr,
43593 .regs = regs,
43594@@ -2100,6 +2437,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
43595
43596 audit_core_dumps(signr);
43597
43598+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
43599+ gr_handle_brute_attach(current, cprm.mm_flags);
43600+
43601 binfmt = mm->binfmt;
43602 if (!binfmt || !binfmt->core_dump)
43603 goto fail;
43604@@ -2167,7 +2507,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
43605 }
43606 cprm.limit = RLIM_INFINITY;
43607
43608- dump_count = atomic_inc_return(&core_dump_count);
43609+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
43610 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
43611 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
43612 task_tgid_vnr(current), current->comm);
43613@@ -2194,6 +2534,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
43614 } else {
43615 struct inode *inode;
43616
43617+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
43618+
43619 if (cprm.limit < binfmt->min_coredump)
43620 goto fail_unlock;
43621
43622@@ -2237,7 +2579,7 @@ close_fail:
43623 filp_close(cprm.file, NULL);
43624 fail_dropcount:
43625 if (ispipe)
43626- atomic_dec(&core_dump_count);
43627+ atomic_dec_unchecked(&core_dump_count);
43628 fail_unlock:
43629 kfree(cn.corename);
43630 fail_corename:
43631@@ -2256,7 +2598,7 @@ fail:
43632 */
43633 int dump_write(struct file *file, const void *addr, int nr)
43634 {
43635- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
43636+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
43637 }
43638 EXPORT_SYMBOL(dump_write);
43639
43640diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
43641index a8cbe1b..fed04cb 100644
43642--- a/fs/ext2/balloc.c
43643+++ b/fs/ext2/balloc.c
43644@@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
43645
43646 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
43647 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
43648- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
43649+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
43650 sbi->s_resuid != current_fsuid() &&
43651 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
43652 return 0;
43653diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
43654index a203892..4e64db5 100644
43655--- a/fs/ext3/balloc.c
43656+++ b/fs/ext3/balloc.c
43657@@ -1446,9 +1446,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
43658
43659 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
43660 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
43661- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
43662+ if (free_blocks < root_blocks + 1 &&
43663 !use_reservation && sbi->s_resuid != current_fsuid() &&
43664- (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
43665+ (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
43666+ !capable_nolog(CAP_SYS_RESOURCE)) {
43667 return 0;
43668 }
43669 return 1;
43670diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
43671index f9e2cd8..bfdc476 100644
43672--- a/fs/ext4/balloc.c
43673+++ b/fs/ext4/balloc.c
43674@@ -438,8 +438,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
43675 /* Hm, nope. Are (enough) root reserved clusters available? */
43676 if (sbi->s_resuid == current_fsuid() ||
43677 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
43678- capable(CAP_SYS_RESOURCE) ||
43679- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
43680+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
43681+ capable_nolog(CAP_SYS_RESOURCE)) {
43682
43683 if (free_clusters >= (nclusters + dirty_clusters))
43684 return 1;
43685diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
43686index 3ce6a0c..0311fe5 100644
43687--- a/fs/ext4/ext4.h
43688+++ b/fs/ext4/ext4.h
43689@@ -1220,19 +1220,19 @@ struct ext4_sb_info {
43690 unsigned long s_mb_last_start;
43691
43692 /* stats for buddy allocator */
43693- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
43694- atomic_t s_bal_success; /* we found long enough chunks */
43695- atomic_t s_bal_allocated; /* in blocks */
43696- atomic_t s_bal_ex_scanned; /* total extents scanned */
43697- atomic_t s_bal_goals; /* goal hits */
43698- atomic_t s_bal_breaks; /* too long searches */
43699- atomic_t s_bal_2orders; /* 2^order hits */
43700+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
43701+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
43702+ atomic_unchecked_t s_bal_allocated; /* in blocks */
43703+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
43704+ atomic_unchecked_t s_bal_goals; /* goal hits */
43705+ atomic_unchecked_t s_bal_breaks; /* too long searches */
43706+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
43707 spinlock_t s_bal_lock;
43708 unsigned long s_mb_buddies_generated;
43709 unsigned long long s_mb_generation_time;
43710- atomic_t s_mb_lost_chunks;
43711- atomic_t s_mb_preallocated;
43712- atomic_t s_mb_discarded;
43713+ atomic_unchecked_t s_mb_lost_chunks;
43714+ atomic_unchecked_t s_mb_preallocated;
43715+ atomic_unchecked_t s_mb_discarded;
43716 atomic_t s_lock_busy;
43717
43718 /* locality groups */
43719diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
43720index cb990b2..4820141 100644
43721--- a/fs/ext4/mballoc.c
43722+++ b/fs/ext4/mballoc.c
43723@@ -1794,7 +1794,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
43724 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
43725
43726 if (EXT4_SB(sb)->s_mb_stats)
43727- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
43728+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
43729
43730 break;
43731 }
43732@@ -2088,7 +2088,7 @@ repeat:
43733 ac->ac_status = AC_STATUS_CONTINUE;
43734 ac->ac_flags |= EXT4_MB_HINT_FIRST;
43735 cr = 3;
43736- atomic_inc(&sbi->s_mb_lost_chunks);
43737+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
43738 goto repeat;
43739 }
43740 }
43741@@ -2592,25 +2592,25 @@ int ext4_mb_release(struct super_block *sb)
43742 if (sbi->s_mb_stats) {
43743 ext4_msg(sb, KERN_INFO,
43744 "mballoc: %u blocks %u reqs (%u success)",
43745- atomic_read(&sbi->s_bal_allocated),
43746- atomic_read(&sbi->s_bal_reqs),
43747- atomic_read(&sbi->s_bal_success));
43748+ atomic_read_unchecked(&sbi->s_bal_allocated),
43749+ atomic_read_unchecked(&sbi->s_bal_reqs),
43750+ atomic_read_unchecked(&sbi->s_bal_success));
43751 ext4_msg(sb, KERN_INFO,
43752 "mballoc: %u extents scanned, %u goal hits, "
43753 "%u 2^N hits, %u breaks, %u lost",
43754- atomic_read(&sbi->s_bal_ex_scanned),
43755- atomic_read(&sbi->s_bal_goals),
43756- atomic_read(&sbi->s_bal_2orders),
43757- atomic_read(&sbi->s_bal_breaks),
43758- atomic_read(&sbi->s_mb_lost_chunks));
43759+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
43760+ atomic_read_unchecked(&sbi->s_bal_goals),
43761+ atomic_read_unchecked(&sbi->s_bal_2orders),
43762+ atomic_read_unchecked(&sbi->s_bal_breaks),
43763+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
43764 ext4_msg(sb, KERN_INFO,
43765 "mballoc: %lu generated and it took %Lu",
43766 sbi->s_mb_buddies_generated,
43767 sbi->s_mb_generation_time);
43768 ext4_msg(sb, KERN_INFO,
43769 "mballoc: %u preallocated, %u discarded",
43770- atomic_read(&sbi->s_mb_preallocated),
43771- atomic_read(&sbi->s_mb_discarded));
43772+ atomic_read_unchecked(&sbi->s_mb_preallocated),
43773+ atomic_read_unchecked(&sbi->s_mb_discarded));
43774 }
43775
43776 free_percpu(sbi->s_locality_groups);
43777@@ -3096,16 +3096,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
43778 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
43779
43780 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
43781- atomic_inc(&sbi->s_bal_reqs);
43782- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
43783+ atomic_inc_unchecked(&sbi->s_bal_reqs);
43784+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
43785 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
43786- atomic_inc(&sbi->s_bal_success);
43787- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
43788+ atomic_inc_unchecked(&sbi->s_bal_success);
43789+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
43790 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
43791 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
43792- atomic_inc(&sbi->s_bal_goals);
43793+ atomic_inc_unchecked(&sbi->s_bal_goals);
43794 if (ac->ac_found > sbi->s_mb_max_to_scan)
43795- atomic_inc(&sbi->s_bal_breaks);
43796+ atomic_inc_unchecked(&sbi->s_bal_breaks);
43797 }
43798
43799 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
43800@@ -3509,7 +3509,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
43801 trace_ext4_mb_new_inode_pa(ac, pa);
43802
43803 ext4_mb_use_inode_pa(ac, pa);
43804- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
43805+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
43806
43807 ei = EXT4_I(ac->ac_inode);
43808 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
43809@@ -3569,7 +3569,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
43810 trace_ext4_mb_new_group_pa(ac, pa);
43811
43812 ext4_mb_use_group_pa(ac, pa);
43813- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
43814+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
43815
43816 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
43817 lg = ac->ac_lg;
43818@@ -3658,7 +3658,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
43819 * from the bitmap and continue.
43820 */
43821 }
43822- atomic_add(free, &sbi->s_mb_discarded);
43823+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
43824
43825 return err;
43826 }
43827@@ -3676,7 +3676,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
43828 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
43829 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
43830 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
43831- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
43832+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
43833 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
43834
43835 return 0;
43836diff --git a/fs/fcntl.c b/fs/fcntl.c
43837index 22764c7..86372c9 100644
43838--- a/fs/fcntl.c
43839+++ b/fs/fcntl.c
43840@@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
43841 if (err)
43842 return err;
43843
43844+ if (gr_handle_chroot_fowner(pid, type))
43845+ return -ENOENT;
43846+ if (gr_check_protected_task_fowner(pid, type))
43847+ return -EACCES;
43848+
43849 f_modown(filp, pid, type, force);
43850 return 0;
43851 }
43852@@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
43853
43854 static int f_setown_ex(struct file *filp, unsigned long arg)
43855 {
43856- struct f_owner_ex * __user owner_p = (void * __user)arg;
43857+ struct f_owner_ex __user *owner_p = (void __user *)arg;
43858 struct f_owner_ex owner;
43859 struct pid *pid;
43860 int type;
43861@@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
43862
43863 static int f_getown_ex(struct file *filp, unsigned long arg)
43864 {
43865- struct f_owner_ex * __user owner_p = (void * __user)arg;
43866+ struct f_owner_ex __user *owner_p = (void __user *)arg;
43867 struct f_owner_ex owner;
43868 int ret = 0;
43869
43870@@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
43871 switch (cmd) {
43872 case F_DUPFD:
43873 case F_DUPFD_CLOEXEC:
43874+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
43875 if (arg >= rlimit(RLIMIT_NOFILE))
43876 break;
43877 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
43878diff --git a/fs/fifo.c b/fs/fifo.c
43879index b1a524d..4ee270e 100644
43880--- a/fs/fifo.c
43881+++ b/fs/fifo.c
43882@@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
43883 */
43884 filp->f_op = &read_pipefifo_fops;
43885 pipe->r_counter++;
43886- if (pipe->readers++ == 0)
43887+ if (atomic_inc_return(&pipe->readers) == 1)
43888 wake_up_partner(inode);
43889
43890- if (!pipe->writers) {
43891+ if (!atomic_read(&pipe->writers)) {
43892 if ((filp->f_flags & O_NONBLOCK)) {
43893 /* suppress POLLHUP until we have
43894 * seen a writer */
43895@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
43896 * errno=ENXIO when there is no process reading the FIFO.
43897 */
43898 ret = -ENXIO;
43899- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
43900+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
43901 goto err;
43902
43903 filp->f_op = &write_pipefifo_fops;
43904 pipe->w_counter++;
43905- if (!pipe->writers++)
43906+ if (atomic_inc_return(&pipe->writers) == 1)
43907 wake_up_partner(inode);
43908
43909- if (!pipe->readers) {
43910+ if (!atomic_read(&pipe->readers)) {
43911 wait_for_partner(inode, &pipe->r_counter);
43912 if (signal_pending(current))
43913 goto err_wr;
43914@@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
43915 */
43916 filp->f_op = &rdwr_pipefifo_fops;
43917
43918- pipe->readers++;
43919- pipe->writers++;
43920+ atomic_inc(&pipe->readers);
43921+ atomic_inc(&pipe->writers);
43922 pipe->r_counter++;
43923 pipe->w_counter++;
43924- if (pipe->readers == 1 || pipe->writers == 1)
43925+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
43926 wake_up_partner(inode);
43927 break;
43928
43929@@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
43930 return 0;
43931
43932 err_rd:
43933- if (!--pipe->readers)
43934+ if (atomic_dec_and_test(&pipe->readers))
43935 wake_up_interruptible(&pipe->wait);
43936 ret = -ERESTARTSYS;
43937 goto err;
43938
43939 err_wr:
43940- if (!--pipe->writers)
43941+ if (atomic_dec_and_test(&pipe->writers))
43942 wake_up_interruptible(&pipe->wait);
43943 ret = -ERESTARTSYS;
43944 goto err;
43945
43946 err:
43947- if (!pipe->readers && !pipe->writers)
43948+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
43949 free_pipe_info(inode);
43950
43951 err_nocleanup:
43952diff --git a/fs/file.c b/fs/file.c
43953index 4c6992d..104cdea 100644
43954--- a/fs/file.c
43955+++ b/fs/file.c
43956@@ -15,6 +15,7 @@
43957 #include <linux/slab.h>
43958 #include <linux/vmalloc.h>
43959 #include <linux/file.h>
43960+#include <linux/security.h>
43961 #include <linux/fdtable.h>
43962 #include <linux/bitops.h>
43963 #include <linux/interrupt.h>
43964@@ -254,6 +255,7 @@ int expand_files(struct files_struct *files, int nr)
43965 * N.B. For clone tasks sharing a files structure, this test
43966 * will limit the total number of files that can be opened.
43967 */
43968+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
43969 if (nr >= rlimit(RLIMIT_NOFILE))
43970 return -EMFILE;
43971
43972diff --git a/fs/filesystems.c b/fs/filesystems.c
43973index 96f2428..f5eeb8e 100644
43974--- a/fs/filesystems.c
43975+++ b/fs/filesystems.c
43976@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
43977 int len = dot ? dot - name : strlen(name);
43978
43979 fs = __get_fs_type(name, len);
43980+
43981+#ifdef CONFIG_GRKERNSEC_MODHARDEN
43982+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
43983+#else
43984 if (!fs && (request_module("%.*s", len, name) == 0))
43985+#endif
43986 fs = __get_fs_type(name, len);
43987
43988 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
43989diff --git a/fs/fs_struct.c b/fs/fs_struct.c
43990index 78b519c..a8b4979 100644
43991--- a/fs/fs_struct.c
43992+++ b/fs/fs_struct.c
43993@@ -4,6 +4,7 @@
43994 #include <linux/path.h>
43995 #include <linux/slab.h>
43996 #include <linux/fs_struct.h>
43997+#include <linux/grsecurity.h>
43998 #include "internal.h"
43999
44000 static inline void path_get_longterm(struct path *path)
44001@@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
44002 old_root = fs->root;
44003 fs->root = *path;
44004 path_get_longterm(path);
44005+ gr_set_chroot_entries(current, path);
44006 write_seqcount_end(&fs->seq);
44007 spin_unlock(&fs->lock);
44008 if (old_root.dentry)
44009@@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
44010 && fs->root.mnt == old_root->mnt) {
44011 path_get_longterm(new_root);
44012 fs->root = *new_root;
44013+ gr_set_chroot_entries(p, new_root);
44014 count++;
44015 }
44016 if (fs->pwd.dentry == old_root->dentry
44017@@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
44018 spin_lock(&fs->lock);
44019 write_seqcount_begin(&fs->seq);
44020 tsk->fs = NULL;
44021- kill = !--fs->users;
44022+ gr_clear_chroot_entries(tsk);
44023+ kill = !atomic_dec_return(&fs->users);
44024 write_seqcount_end(&fs->seq);
44025 spin_unlock(&fs->lock);
44026 task_unlock(tsk);
44027@@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
44028 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
44029 /* We don't need to lock fs - think why ;-) */
44030 if (fs) {
44031- fs->users = 1;
44032+ atomic_set(&fs->users, 1);
44033 fs->in_exec = 0;
44034 spin_lock_init(&fs->lock);
44035 seqcount_init(&fs->seq);
44036@@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
44037 spin_lock(&old->lock);
44038 fs->root = old->root;
44039 path_get_longterm(&fs->root);
44040+ /* instead of calling gr_set_chroot_entries here,
44041+ we call it from every caller of this function
44042+ */
44043 fs->pwd = old->pwd;
44044 path_get_longterm(&fs->pwd);
44045 spin_unlock(&old->lock);
44046@@ -150,8 +157,9 @@ int unshare_fs_struct(void)
44047
44048 task_lock(current);
44049 spin_lock(&fs->lock);
44050- kill = !--fs->users;
44051+ kill = !atomic_dec_return(&fs->users);
44052 current->fs = new_fs;
44053+ gr_set_chroot_entries(current, &new_fs->root);
44054 spin_unlock(&fs->lock);
44055 task_unlock(current);
44056
44057@@ -164,13 +172,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
44058
44059 int current_umask(void)
44060 {
44061- return current->fs->umask;
44062+ return current->fs->umask | gr_acl_umask();
44063 }
44064 EXPORT_SYMBOL(current_umask);
44065
44066 /* to be mentioned only in INIT_TASK */
44067 struct fs_struct init_fs = {
44068- .users = 1,
44069+ .users = ATOMIC_INIT(1),
44070 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
44071 .seq = SEQCNT_ZERO,
44072 .umask = 0022,
44073@@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
44074 task_lock(current);
44075
44076 spin_lock(&init_fs.lock);
44077- init_fs.users++;
44078+ atomic_inc(&init_fs.users);
44079 spin_unlock(&init_fs.lock);
44080
44081 spin_lock(&fs->lock);
44082 current->fs = &init_fs;
44083- kill = !--fs->users;
44084+ gr_set_chroot_entries(current, &current->fs->root);
44085+ kill = !atomic_dec_return(&fs->users);
44086 spin_unlock(&fs->lock);
44087
44088 task_unlock(current);
44089diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
44090index 9905350..02eaec4 100644
44091--- a/fs/fscache/cookie.c
44092+++ b/fs/fscache/cookie.c
44093@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
44094 parent ? (char *) parent->def->name : "<no-parent>",
44095 def->name, netfs_data);
44096
44097- fscache_stat(&fscache_n_acquires);
44098+ fscache_stat_unchecked(&fscache_n_acquires);
44099
44100 /* if there's no parent cookie, then we don't create one here either */
44101 if (!parent) {
44102- fscache_stat(&fscache_n_acquires_null);
44103+ fscache_stat_unchecked(&fscache_n_acquires_null);
44104 _leave(" [no parent]");
44105 return NULL;
44106 }
44107@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
44108 /* allocate and initialise a cookie */
44109 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
44110 if (!cookie) {
44111- fscache_stat(&fscache_n_acquires_oom);
44112+ fscache_stat_unchecked(&fscache_n_acquires_oom);
44113 _leave(" [ENOMEM]");
44114 return NULL;
44115 }
44116@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44117
44118 switch (cookie->def->type) {
44119 case FSCACHE_COOKIE_TYPE_INDEX:
44120- fscache_stat(&fscache_n_cookie_index);
44121+ fscache_stat_unchecked(&fscache_n_cookie_index);
44122 break;
44123 case FSCACHE_COOKIE_TYPE_DATAFILE:
44124- fscache_stat(&fscache_n_cookie_data);
44125+ fscache_stat_unchecked(&fscache_n_cookie_data);
44126 break;
44127 default:
44128- fscache_stat(&fscache_n_cookie_special);
44129+ fscache_stat_unchecked(&fscache_n_cookie_special);
44130 break;
44131 }
44132
44133@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44134 if (fscache_acquire_non_index_cookie(cookie) < 0) {
44135 atomic_dec(&parent->n_children);
44136 __fscache_cookie_put(cookie);
44137- fscache_stat(&fscache_n_acquires_nobufs);
44138+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
44139 _leave(" = NULL");
44140 return NULL;
44141 }
44142 }
44143
44144- fscache_stat(&fscache_n_acquires_ok);
44145+ fscache_stat_unchecked(&fscache_n_acquires_ok);
44146 _leave(" = %p", cookie);
44147 return cookie;
44148 }
44149@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
44150 cache = fscache_select_cache_for_object(cookie->parent);
44151 if (!cache) {
44152 up_read(&fscache_addremove_sem);
44153- fscache_stat(&fscache_n_acquires_no_cache);
44154+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
44155 _leave(" = -ENOMEDIUM [no cache]");
44156 return -ENOMEDIUM;
44157 }
44158@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
44159 object = cache->ops->alloc_object(cache, cookie);
44160 fscache_stat_d(&fscache_n_cop_alloc_object);
44161 if (IS_ERR(object)) {
44162- fscache_stat(&fscache_n_object_no_alloc);
44163+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
44164 ret = PTR_ERR(object);
44165 goto error;
44166 }
44167
44168- fscache_stat(&fscache_n_object_alloc);
44169+ fscache_stat_unchecked(&fscache_n_object_alloc);
44170
44171 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
44172
44173@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
44174 struct fscache_object *object;
44175 struct hlist_node *_p;
44176
44177- fscache_stat(&fscache_n_updates);
44178+ fscache_stat_unchecked(&fscache_n_updates);
44179
44180 if (!cookie) {
44181- fscache_stat(&fscache_n_updates_null);
44182+ fscache_stat_unchecked(&fscache_n_updates_null);
44183 _leave(" [no cookie]");
44184 return;
44185 }
44186@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
44187 struct fscache_object *object;
44188 unsigned long event;
44189
44190- fscache_stat(&fscache_n_relinquishes);
44191+ fscache_stat_unchecked(&fscache_n_relinquishes);
44192 if (retire)
44193- fscache_stat(&fscache_n_relinquishes_retire);
44194+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
44195
44196 if (!cookie) {
44197- fscache_stat(&fscache_n_relinquishes_null);
44198+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
44199 _leave(" [no cookie]");
44200 return;
44201 }
44202@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
44203
44204 /* wait for the cookie to finish being instantiated (or to fail) */
44205 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
44206- fscache_stat(&fscache_n_relinquishes_waitcrt);
44207+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
44208 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
44209 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
44210 }
44211diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
44212index f6aad48..88dcf26 100644
44213--- a/fs/fscache/internal.h
44214+++ b/fs/fscache/internal.h
44215@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
44216 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
44217 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
44218
44219-extern atomic_t fscache_n_op_pend;
44220-extern atomic_t fscache_n_op_run;
44221-extern atomic_t fscache_n_op_enqueue;
44222-extern atomic_t fscache_n_op_deferred_release;
44223-extern atomic_t fscache_n_op_release;
44224-extern atomic_t fscache_n_op_gc;
44225-extern atomic_t fscache_n_op_cancelled;
44226-extern atomic_t fscache_n_op_rejected;
44227+extern atomic_unchecked_t fscache_n_op_pend;
44228+extern atomic_unchecked_t fscache_n_op_run;
44229+extern atomic_unchecked_t fscache_n_op_enqueue;
44230+extern atomic_unchecked_t fscache_n_op_deferred_release;
44231+extern atomic_unchecked_t fscache_n_op_release;
44232+extern atomic_unchecked_t fscache_n_op_gc;
44233+extern atomic_unchecked_t fscache_n_op_cancelled;
44234+extern atomic_unchecked_t fscache_n_op_rejected;
44235
44236-extern atomic_t fscache_n_attr_changed;
44237-extern atomic_t fscache_n_attr_changed_ok;
44238-extern atomic_t fscache_n_attr_changed_nobufs;
44239-extern atomic_t fscache_n_attr_changed_nomem;
44240-extern atomic_t fscache_n_attr_changed_calls;
44241+extern atomic_unchecked_t fscache_n_attr_changed;
44242+extern atomic_unchecked_t fscache_n_attr_changed_ok;
44243+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
44244+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
44245+extern atomic_unchecked_t fscache_n_attr_changed_calls;
44246
44247-extern atomic_t fscache_n_allocs;
44248-extern atomic_t fscache_n_allocs_ok;
44249-extern atomic_t fscache_n_allocs_wait;
44250-extern atomic_t fscache_n_allocs_nobufs;
44251-extern atomic_t fscache_n_allocs_intr;
44252-extern atomic_t fscache_n_allocs_object_dead;
44253-extern atomic_t fscache_n_alloc_ops;
44254-extern atomic_t fscache_n_alloc_op_waits;
44255+extern atomic_unchecked_t fscache_n_allocs;
44256+extern atomic_unchecked_t fscache_n_allocs_ok;
44257+extern atomic_unchecked_t fscache_n_allocs_wait;
44258+extern atomic_unchecked_t fscache_n_allocs_nobufs;
44259+extern atomic_unchecked_t fscache_n_allocs_intr;
44260+extern atomic_unchecked_t fscache_n_allocs_object_dead;
44261+extern atomic_unchecked_t fscache_n_alloc_ops;
44262+extern atomic_unchecked_t fscache_n_alloc_op_waits;
44263
44264-extern atomic_t fscache_n_retrievals;
44265-extern atomic_t fscache_n_retrievals_ok;
44266-extern atomic_t fscache_n_retrievals_wait;
44267-extern atomic_t fscache_n_retrievals_nodata;
44268-extern atomic_t fscache_n_retrievals_nobufs;
44269-extern atomic_t fscache_n_retrievals_intr;
44270-extern atomic_t fscache_n_retrievals_nomem;
44271-extern atomic_t fscache_n_retrievals_object_dead;
44272-extern atomic_t fscache_n_retrieval_ops;
44273-extern atomic_t fscache_n_retrieval_op_waits;
44274+extern atomic_unchecked_t fscache_n_retrievals;
44275+extern atomic_unchecked_t fscache_n_retrievals_ok;
44276+extern atomic_unchecked_t fscache_n_retrievals_wait;
44277+extern atomic_unchecked_t fscache_n_retrievals_nodata;
44278+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
44279+extern atomic_unchecked_t fscache_n_retrievals_intr;
44280+extern atomic_unchecked_t fscache_n_retrievals_nomem;
44281+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
44282+extern atomic_unchecked_t fscache_n_retrieval_ops;
44283+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
44284
44285-extern atomic_t fscache_n_stores;
44286-extern atomic_t fscache_n_stores_ok;
44287-extern atomic_t fscache_n_stores_again;
44288-extern atomic_t fscache_n_stores_nobufs;
44289-extern atomic_t fscache_n_stores_oom;
44290-extern atomic_t fscache_n_store_ops;
44291-extern atomic_t fscache_n_store_calls;
44292-extern atomic_t fscache_n_store_pages;
44293-extern atomic_t fscache_n_store_radix_deletes;
44294-extern atomic_t fscache_n_store_pages_over_limit;
44295+extern atomic_unchecked_t fscache_n_stores;
44296+extern atomic_unchecked_t fscache_n_stores_ok;
44297+extern atomic_unchecked_t fscache_n_stores_again;
44298+extern atomic_unchecked_t fscache_n_stores_nobufs;
44299+extern atomic_unchecked_t fscache_n_stores_oom;
44300+extern atomic_unchecked_t fscache_n_store_ops;
44301+extern atomic_unchecked_t fscache_n_store_calls;
44302+extern atomic_unchecked_t fscache_n_store_pages;
44303+extern atomic_unchecked_t fscache_n_store_radix_deletes;
44304+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
44305
44306-extern atomic_t fscache_n_store_vmscan_not_storing;
44307-extern atomic_t fscache_n_store_vmscan_gone;
44308-extern atomic_t fscache_n_store_vmscan_busy;
44309-extern atomic_t fscache_n_store_vmscan_cancelled;
44310+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
44311+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
44312+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
44313+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
44314
44315-extern atomic_t fscache_n_marks;
44316-extern atomic_t fscache_n_uncaches;
44317+extern atomic_unchecked_t fscache_n_marks;
44318+extern atomic_unchecked_t fscache_n_uncaches;
44319
44320-extern atomic_t fscache_n_acquires;
44321-extern atomic_t fscache_n_acquires_null;
44322-extern atomic_t fscache_n_acquires_no_cache;
44323-extern atomic_t fscache_n_acquires_ok;
44324-extern atomic_t fscache_n_acquires_nobufs;
44325-extern atomic_t fscache_n_acquires_oom;
44326+extern atomic_unchecked_t fscache_n_acquires;
44327+extern atomic_unchecked_t fscache_n_acquires_null;
44328+extern atomic_unchecked_t fscache_n_acquires_no_cache;
44329+extern atomic_unchecked_t fscache_n_acquires_ok;
44330+extern atomic_unchecked_t fscache_n_acquires_nobufs;
44331+extern atomic_unchecked_t fscache_n_acquires_oom;
44332
44333-extern atomic_t fscache_n_updates;
44334-extern atomic_t fscache_n_updates_null;
44335-extern atomic_t fscache_n_updates_run;
44336+extern atomic_unchecked_t fscache_n_updates;
44337+extern atomic_unchecked_t fscache_n_updates_null;
44338+extern atomic_unchecked_t fscache_n_updates_run;
44339
44340-extern atomic_t fscache_n_relinquishes;
44341-extern atomic_t fscache_n_relinquishes_null;
44342-extern atomic_t fscache_n_relinquishes_waitcrt;
44343-extern atomic_t fscache_n_relinquishes_retire;
44344+extern atomic_unchecked_t fscache_n_relinquishes;
44345+extern atomic_unchecked_t fscache_n_relinquishes_null;
44346+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
44347+extern atomic_unchecked_t fscache_n_relinquishes_retire;
44348
44349-extern atomic_t fscache_n_cookie_index;
44350-extern atomic_t fscache_n_cookie_data;
44351-extern atomic_t fscache_n_cookie_special;
44352+extern atomic_unchecked_t fscache_n_cookie_index;
44353+extern atomic_unchecked_t fscache_n_cookie_data;
44354+extern atomic_unchecked_t fscache_n_cookie_special;
44355
44356-extern atomic_t fscache_n_object_alloc;
44357-extern atomic_t fscache_n_object_no_alloc;
44358-extern atomic_t fscache_n_object_lookups;
44359-extern atomic_t fscache_n_object_lookups_negative;
44360-extern atomic_t fscache_n_object_lookups_positive;
44361-extern atomic_t fscache_n_object_lookups_timed_out;
44362-extern atomic_t fscache_n_object_created;
44363-extern atomic_t fscache_n_object_avail;
44364-extern atomic_t fscache_n_object_dead;
44365+extern atomic_unchecked_t fscache_n_object_alloc;
44366+extern atomic_unchecked_t fscache_n_object_no_alloc;
44367+extern atomic_unchecked_t fscache_n_object_lookups;
44368+extern atomic_unchecked_t fscache_n_object_lookups_negative;
44369+extern atomic_unchecked_t fscache_n_object_lookups_positive;
44370+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
44371+extern atomic_unchecked_t fscache_n_object_created;
44372+extern atomic_unchecked_t fscache_n_object_avail;
44373+extern atomic_unchecked_t fscache_n_object_dead;
44374
44375-extern atomic_t fscache_n_checkaux_none;
44376-extern atomic_t fscache_n_checkaux_okay;
44377-extern atomic_t fscache_n_checkaux_update;
44378-extern atomic_t fscache_n_checkaux_obsolete;
44379+extern atomic_unchecked_t fscache_n_checkaux_none;
44380+extern atomic_unchecked_t fscache_n_checkaux_okay;
44381+extern atomic_unchecked_t fscache_n_checkaux_update;
44382+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
44383
44384 extern atomic_t fscache_n_cop_alloc_object;
44385 extern atomic_t fscache_n_cop_lookup_object;
44386@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
44387 atomic_inc(stat);
44388 }
44389
44390+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
44391+{
44392+ atomic_inc_unchecked(stat);
44393+}
44394+
44395 static inline void fscache_stat_d(atomic_t *stat)
44396 {
44397 atomic_dec(stat);
44398@@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
44399
44400 #define __fscache_stat(stat) (NULL)
44401 #define fscache_stat(stat) do {} while (0)
44402+#define fscache_stat_unchecked(stat) do {} while (0)
44403 #define fscache_stat_d(stat) do {} while (0)
44404 #endif
44405
44406diff --git a/fs/fscache/object.c b/fs/fscache/object.c
44407index b6b897c..0ffff9c 100644
44408--- a/fs/fscache/object.c
44409+++ b/fs/fscache/object.c
44410@@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
44411 /* update the object metadata on disk */
44412 case FSCACHE_OBJECT_UPDATING:
44413 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
44414- fscache_stat(&fscache_n_updates_run);
44415+ fscache_stat_unchecked(&fscache_n_updates_run);
44416 fscache_stat(&fscache_n_cop_update_object);
44417 object->cache->ops->update_object(object);
44418 fscache_stat_d(&fscache_n_cop_update_object);
44419@@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
44420 spin_lock(&object->lock);
44421 object->state = FSCACHE_OBJECT_DEAD;
44422 spin_unlock(&object->lock);
44423- fscache_stat(&fscache_n_object_dead);
44424+ fscache_stat_unchecked(&fscache_n_object_dead);
44425 goto terminal_transit;
44426
44427 /* handle the parent cache of this object being withdrawn from
44428@@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
44429 spin_lock(&object->lock);
44430 object->state = FSCACHE_OBJECT_DEAD;
44431 spin_unlock(&object->lock);
44432- fscache_stat(&fscache_n_object_dead);
44433+ fscache_stat_unchecked(&fscache_n_object_dead);
44434 goto terminal_transit;
44435
44436 /* complain about the object being woken up once it is
44437@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
44438 parent->cookie->def->name, cookie->def->name,
44439 object->cache->tag->name);
44440
44441- fscache_stat(&fscache_n_object_lookups);
44442+ fscache_stat_unchecked(&fscache_n_object_lookups);
44443 fscache_stat(&fscache_n_cop_lookup_object);
44444 ret = object->cache->ops->lookup_object(object);
44445 fscache_stat_d(&fscache_n_cop_lookup_object);
44446@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
44447 if (ret == -ETIMEDOUT) {
44448 /* probably stuck behind another object, so move this one to
44449 * the back of the queue */
44450- fscache_stat(&fscache_n_object_lookups_timed_out);
44451+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
44452 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
44453 }
44454
44455@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
44456
44457 spin_lock(&object->lock);
44458 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
44459- fscache_stat(&fscache_n_object_lookups_negative);
44460+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
44461
44462 /* transit here to allow write requests to begin stacking up
44463 * and read requests to begin returning ENODATA */
44464@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
44465 * result, in which case there may be data available */
44466 spin_lock(&object->lock);
44467 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
44468- fscache_stat(&fscache_n_object_lookups_positive);
44469+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
44470
44471 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
44472
44473@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
44474 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
44475 } else {
44476 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
44477- fscache_stat(&fscache_n_object_created);
44478+ fscache_stat_unchecked(&fscache_n_object_created);
44479
44480 object->state = FSCACHE_OBJECT_AVAILABLE;
44481 spin_unlock(&object->lock);
44482@@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
44483 fscache_enqueue_dependents(object);
44484
44485 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
44486- fscache_stat(&fscache_n_object_avail);
44487+ fscache_stat_unchecked(&fscache_n_object_avail);
44488
44489 _leave("");
44490 }
44491@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
44492 enum fscache_checkaux result;
44493
44494 if (!object->cookie->def->check_aux) {
44495- fscache_stat(&fscache_n_checkaux_none);
44496+ fscache_stat_unchecked(&fscache_n_checkaux_none);
44497 return FSCACHE_CHECKAUX_OKAY;
44498 }
44499
44500@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
44501 switch (result) {
44502 /* entry okay as is */
44503 case FSCACHE_CHECKAUX_OKAY:
44504- fscache_stat(&fscache_n_checkaux_okay);
44505+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
44506 break;
44507
44508 /* entry requires update */
44509 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
44510- fscache_stat(&fscache_n_checkaux_update);
44511+ fscache_stat_unchecked(&fscache_n_checkaux_update);
44512 break;
44513
44514 /* entry requires deletion */
44515 case FSCACHE_CHECKAUX_OBSOLETE:
44516- fscache_stat(&fscache_n_checkaux_obsolete);
44517+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
44518 break;
44519
44520 default:
44521diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
44522index 30afdfa..2256596 100644
44523--- a/fs/fscache/operation.c
44524+++ b/fs/fscache/operation.c
44525@@ -17,7 +17,7 @@
44526 #include <linux/slab.h>
44527 #include "internal.h"
44528
44529-atomic_t fscache_op_debug_id;
44530+atomic_unchecked_t fscache_op_debug_id;
44531 EXPORT_SYMBOL(fscache_op_debug_id);
44532
44533 /**
44534@@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
44535 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
44536 ASSERTCMP(atomic_read(&op->usage), >, 0);
44537
44538- fscache_stat(&fscache_n_op_enqueue);
44539+ fscache_stat_unchecked(&fscache_n_op_enqueue);
44540 switch (op->flags & FSCACHE_OP_TYPE) {
44541 case FSCACHE_OP_ASYNC:
44542 _debug("queue async");
44543@@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
44544 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
44545 if (op->processor)
44546 fscache_enqueue_operation(op);
44547- fscache_stat(&fscache_n_op_run);
44548+ fscache_stat_unchecked(&fscache_n_op_run);
44549 }
44550
44551 /*
44552@@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
44553 if (object->n_ops > 1) {
44554 atomic_inc(&op->usage);
44555 list_add_tail(&op->pend_link, &object->pending_ops);
44556- fscache_stat(&fscache_n_op_pend);
44557+ fscache_stat_unchecked(&fscache_n_op_pend);
44558 } else if (!list_empty(&object->pending_ops)) {
44559 atomic_inc(&op->usage);
44560 list_add_tail(&op->pend_link, &object->pending_ops);
44561- fscache_stat(&fscache_n_op_pend);
44562+ fscache_stat_unchecked(&fscache_n_op_pend);
44563 fscache_start_operations(object);
44564 } else {
44565 ASSERTCMP(object->n_in_progress, ==, 0);
44566@@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
44567 object->n_exclusive++; /* reads and writes must wait */
44568 atomic_inc(&op->usage);
44569 list_add_tail(&op->pend_link, &object->pending_ops);
44570- fscache_stat(&fscache_n_op_pend);
44571+ fscache_stat_unchecked(&fscache_n_op_pend);
44572 ret = 0;
44573 } else {
44574 /* not allowed to submit ops in any other state */
44575@@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
44576 if (object->n_exclusive > 0) {
44577 atomic_inc(&op->usage);
44578 list_add_tail(&op->pend_link, &object->pending_ops);
44579- fscache_stat(&fscache_n_op_pend);
44580+ fscache_stat_unchecked(&fscache_n_op_pend);
44581 } else if (!list_empty(&object->pending_ops)) {
44582 atomic_inc(&op->usage);
44583 list_add_tail(&op->pend_link, &object->pending_ops);
44584- fscache_stat(&fscache_n_op_pend);
44585+ fscache_stat_unchecked(&fscache_n_op_pend);
44586 fscache_start_operations(object);
44587 } else {
44588 ASSERTCMP(object->n_exclusive, ==, 0);
44589@@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
44590 object->n_ops++;
44591 atomic_inc(&op->usage);
44592 list_add_tail(&op->pend_link, &object->pending_ops);
44593- fscache_stat(&fscache_n_op_pend);
44594+ fscache_stat_unchecked(&fscache_n_op_pend);
44595 ret = 0;
44596 } else if (object->state == FSCACHE_OBJECT_DYING ||
44597 object->state == FSCACHE_OBJECT_LC_DYING ||
44598 object->state == FSCACHE_OBJECT_WITHDRAWING) {
44599- fscache_stat(&fscache_n_op_rejected);
44600+ fscache_stat_unchecked(&fscache_n_op_rejected);
44601 ret = -ENOBUFS;
44602 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
44603 fscache_report_unexpected_submission(object, op, ostate);
44604@@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
44605
44606 ret = -EBUSY;
44607 if (!list_empty(&op->pend_link)) {
44608- fscache_stat(&fscache_n_op_cancelled);
44609+ fscache_stat_unchecked(&fscache_n_op_cancelled);
44610 list_del_init(&op->pend_link);
44611 object->n_ops--;
44612 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
44613@@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
44614 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
44615 BUG();
44616
44617- fscache_stat(&fscache_n_op_release);
44618+ fscache_stat_unchecked(&fscache_n_op_release);
44619
44620 if (op->release) {
44621 op->release(op);
44622@@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
44623 * lock, and defer it otherwise */
44624 if (!spin_trylock(&object->lock)) {
44625 _debug("defer put");
44626- fscache_stat(&fscache_n_op_deferred_release);
44627+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
44628
44629 cache = object->cache;
44630 spin_lock(&cache->op_gc_list_lock);
44631@@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
44632
44633 _debug("GC DEFERRED REL OBJ%x OP%x",
44634 object->debug_id, op->debug_id);
44635- fscache_stat(&fscache_n_op_gc);
44636+ fscache_stat_unchecked(&fscache_n_op_gc);
44637
44638 ASSERTCMP(atomic_read(&op->usage), ==, 0);
44639
44640diff --git a/fs/fscache/page.c b/fs/fscache/page.c
44641index 3f7a59b..cf196cc 100644
44642--- a/fs/fscache/page.c
44643+++ b/fs/fscache/page.c
44644@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
44645 val = radix_tree_lookup(&cookie->stores, page->index);
44646 if (!val) {
44647 rcu_read_unlock();
44648- fscache_stat(&fscache_n_store_vmscan_not_storing);
44649+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
44650 __fscache_uncache_page(cookie, page);
44651 return true;
44652 }
44653@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
44654 spin_unlock(&cookie->stores_lock);
44655
44656 if (xpage) {
44657- fscache_stat(&fscache_n_store_vmscan_cancelled);
44658- fscache_stat(&fscache_n_store_radix_deletes);
44659+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
44660+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
44661 ASSERTCMP(xpage, ==, page);
44662 } else {
44663- fscache_stat(&fscache_n_store_vmscan_gone);
44664+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
44665 }
44666
44667 wake_up_bit(&cookie->flags, 0);
44668@@ -107,7 +107,7 @@ page_busy:
44669 /* we might want to wait here, but that could deadlock the allocator as
44670 * the work threads writing to the cache may all end up sleeping
44671 * on memory allocation */
44672- fscache_stat(&fscache_n_store_vmscan_busy);
44673+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
44674 return false;
44675 }
44676 EXPORT_SYMBOL(__fscache_maybe_release_page);
44677@@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
44678 FSCACHE_COOKIE_STORING_TAG);
44679 if (!radix_tree_tag_get(&cookie->stores, page->index,
44680 FSCACHE_COOKIE_PENDING_TAG)) {
44681- fscache_stat(&fscache_n_store_radix_deletes);
44682+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
44683 xpage = radix_tree_delete(&cookie->stores, page->index);
44684 }
44685 spin_unlock(&cookie->stores_lock);
44686@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
44687
44688 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
44689
44690- fscache_stat(&fscache_n_attr_changed_calls);
44691+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
44692
44693 if (fscache_object_is_active(object)) {
44694 fscache_stat(&fscache_n_cop_attr_changed);
44695@@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
44696
44697 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
44698
44699- fscache_stat(&fscache_n_attr_changed);
44700+ fscache_stat_unchecked(&fscache_n_attr_changed);
44701
44702 op = kzalloc(sizeof(*op), GFP_KERNEL);
44703 if (!op) {
44704- fscache_stat(&fscache_n_attr_changed_nomem);
44705+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
44706 _leave(" = -ENOMEM");
44707 return -ENOMEM;
44708 }
44709@@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
44710 if (fscache_submit_exclusive_op(object, op) < 0)
44711 goto nobufs;
44712 spin_unlock(&cookie->lock);
44713- fscache_stat(&fscache_n_attr_changed_ok);
44714+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
44715 fscache_put_operation(op);
44716 _leave(" = 0");
44717 return 0;
44718@@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
44719 nobufs:
44720 spin_unlock(&cookie->lock);
44721 kfree(op);
44722- fscache_stat(&fscache_n_attr_changed_nobufs);
44723+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
44724 _leave(" = %d", -ENOBUFS);
44725 return -ENOBUFS;
44726 }
44727@@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
44728 /* allocate a retrieval operation and attempt to submit it */
44729 op = kzalloc(sizeof(*op), GFP_NOIO);
44730 if (!op) {
44731- fscache_stat(&fscache_n_retrievals_nomem);
44732+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
44733 return NULL;
44734 }
44735
44736@@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
44737 return 0;
44738 }
44739
44740- fscache_stat(&fscache_n_retrievals_wait);
44741+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
44742
44743 jif = jiffies;
44744 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
44745 fscache_wait_bit_interruptible,
44746 TASK_INTERRUPTIBLE) != 0) {
44747- fscache_stat(&fscache_n_retrievals_intr);
44748+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
44749 _leave(" = -ERESTARTSYS");
44750 return -ERESTARTSYS;
44751 }
44752@@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
44753 */
44754 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
44755 struct fscache_retrieval *op,
44756- atomic_t *stat_op_waits,
44757- atomic_t *stat_object_dead)
44758+ atomic_unchecked_t *stat_op_waits,
44759+ atomic_unchecked_t *stat_object_dead)
44760 {
44761 int ret;
44762
44763@@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
44764 goto check_if_dead;
44765
44766 _debug(">>> WT");
44767- fscache_stat(stat_op_waits);
44768+ fscache_stat_unchecked(stat_op_waits);
44769 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
44770 fscache_wait_bit_interruptible,
44771 TASK_INTERRUPTIBLE) < 0) {
44772@@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
44773
44774 check_if_dead:
44775 if (unlikely(fscache_object_is_dead(object))) {
44776- fscache_stat(stat_object_dead);
44777+ fscache_stat_unchecked(stat_object_dead);
44778 return -ENOBUFS;
44779 }
44780 return 0;
44781@@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
44782
44783 _enter("%p,%p,,,", cookie, page);
44784
44785- fscache_stat(&fscache_n_retrievals);
44786+ fscache_stat_unchecked(&fscache_n_retrievals);
44787
44788 if (hlist_empty(&cookie->backing_objects))
44789 goto nobufs;
44790@@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
44791 goto nobufs_unlock;
44792 spin_unlock(&cookie->lock);
44793
44794- fscache_stat(&fscache_n_retrieval_ops);
44795+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
44796
44797 /* pin the netfs read context in case we need to do the actual netfs
44798 * read because we've encountered a cache read failure */
44799@@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
44800
44801 error:
44802 if (ret == -ENOMEM)
44803- fscache_stat(&fscache_n_retrievals_nomem);
44804+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
44805 else if (ret == -ERESTARTSYS)
44806- fscache_stat(&fscache_n_retrievals_intr);
44807+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
44808 else if (ret == -ENODATA)
44809- fscache_stat(&fscache_n_retrievals_nodata);
44810+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
44811 else if (ret < 0)
44812- fscache_stat(&fscache_n_retrievals_nobufs);
44813+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
44814 else
44815- fscache_stat(&fscache_n_retrievals_ok);
44816+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
44817
44818 fscache_put_retrieval(op);
44819 _leave(" = %d", ret);
44820@@ -429,7 +429,7 @@ nobufs_unlock:
44821 spin_unlock(&cookie->lock);
44822 kfree(op);
44823 nobufs:
44824- fscache_stat(&fscache_n_retrievals_nobufs);
44825+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
44826 _leave(" = -ENOBUFS");
44827 return -ENOBUFS;
44828 }
44829@@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
44830
44831 _enter("%p,,%d,,,", cookie, *nr_pages);
44832
44833- fscache_stat(&fscache_n_retrievals);
44834+ fscache_stat_unchecked(&fscache_n_retrievals);
44835
44836 if (hlist_empty(&cookie->backing_objects))
44837 goto nobufs;
44838@@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
44839 goto nobufs_unlock;
44840 spin_unlock(&cookie->lock);
44841
44842- fscache_stat(&fscache_n_retrieval_ops);
44843+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
44844
44845 /* pin the netfs read context in case we need to do the actual netfs
44846 * read because we've encountered a cache read failure */
44847@@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
44848
44849 error:
44850 if (ret == -ENOMEM)
44851- fscache_stat(&fscache_n_retrievals_nomem);
44852+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
44853 else if (ret == -ERESTARTSYS)
44854- fscache_stat(&fscache_n_retrievals_intr);
44855+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
44856 else if (ret == -ENODATA)
44857- fscache_stat(&fscache_n_retrievals_nodata);
44858+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
44859 else if (ret < 0)
44860- fscache_stat(&fscache_n_retrievals_nobufs);
44861+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
44862 else
44863- fscache_stat(&fscache_n_retrievals_ok);
44864+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
44865
44866 fscache_put_retrieval(op);
44867 _leave(" = %d", ret);
44868@@ -545,7 +545,7 @@ nobufs_unlock:
44869 spin_unlock(&cookie->lock);
44870 kfree(op);
44871 nobufs:
44872- fscache_stat(&fscache_n_retrievals_nobufs);
44873+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
44874 _leave(" = -ENOBUFS");
44875 return -ENOBUFS;
44876 }
44877@@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
44878
44879 _enter("%p,%p,,,", cookie, page);
44880
44881- fscache_stat(&fscache_n_allocs);
44882+ fscache_stat_unchecked(&fscache_n_allocs);
44883
44884 if (hlist_empty(&cookie->backing_objects))
44885 goto nobufs;
44886@@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
44887 goto nobufs_unlock;
44888 spin_unlock(&cookie->lock);
44889
44890- fscache_stat(&fscache_n_alloc_ops);
44891+ fscache_stat_unchecked(&fscache_n_alloc_ops);
44892
44893 ret = fscache_wait_for_retrieval_activation(
44894 object, op,
44895@@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
44896
44897 error:
44898 if (ret == -ERESTARTSYS)
44899- fscache_stat(&fscache_n_allocs_intr);
44900+ fscache_stat_unchecked(&fscache_n_allocs_intr);
44901 else if (ret < 0)
44902- fscache_stat(&fscache_n_allocs_nobufs);
44903+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
44904 else
44905- fscache_stat(&fscache_n_allocs_ok);
44906+ fscache_stat_unchecked(&fscache_n_allocs_ok);
44907
44908 fscache_put_retrieval(op);
44909 _leave(" = %d", ret);
44910@@ -625,7 +625,7 @@ nobufs_unlock:
44911 spin_unlock(&cookie->lock);
44912 kfree(op);
44913 nobufs:
44914- fscache_stat(&fscache_n_allocs_nobufs);
44915+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
44916 _leave(" = -ENOBUFS");
44917 return -ENOBUFS;
44918 }
44919@@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
44920
44921 spin_lock(&cookie->stores_lock);
44922
44923- fscache_stat(&fscache_n_store_calls);
44924+ fscache_stat_unchecked(&fscache_n_store_calls);
44925
44926 /* find a page to store */
44927 page = NULL;
44928@@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
44929 page = results[0];
44930 _debug("gang %d [%lx]", n, page->index);
44931 if (page->index > op->store_limit) {
44932- fscache_stat(&fscache_n_store_pages_over_limit);
44933+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
44934 goto superseded;
44935 }
44936
44937@@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
44938 spin_unlock(&cookie->stores_lock);
44939 spin_unlock(&object->lock);
44940
44941- fscache_stat(&fscache_n_store_pages);
44942+ fscache_stat_unchecked(&fscache_n_store_pages);
44943 fscache_stat(&fscache_n_cop_write_page);
44944 ret = object->cache->ops->write_page(op, page);
44945 fscache_stat_d(&fscache_n_cop_write_page);
44946@@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
44947 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
44948 ASSERT(PageFsCache(page));
44949
44950- fscache_stat(&fscache_n_stores);
44951+ fscache_stat_unchecked(&fscache_n_stores);
44952
44953 op = kzalloc(sizeof(*op), GFP_NOIO);
44954 if (!op)
44955@@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
44956 spin_unlock(&cookie->stores_lock);
44957 spin_unlock(&object->lock);
44958
44959- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
44960+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
44961 op->store_limit = object->store_limit;
44962
44963 if (fscache_submit_op(object, &op->op) < 0)
44964@@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
44965
44966 spin_unlock(&cookie->lock);
44967 radix_tree_preload_end();
44968- fscache_stat(&fscache_n_store_ops);
44969- fscache_stat(&fscache_n_stores_ok);
44970+ fscache_stat_unchecked(&fscache_n_store_ops);
44971+ fscache_stat_unchecked(&fscache_n_stores_ok);
44972
44973 /* the work queue now carries its own ref on the object */
44974 fscache_put_operation(&op->op);
44975@@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
44976 return 0;
44977
44978 already_queued:
44979- fscache_stat(&fscache_n_stores_again);
44980+ fscache_stat_unchecked(&fscache_n_stores_again);
44981 already_pending:
44982 spin_unlock(&cookie->stores_lock);
44983 spin_unlock(&object->lock);
44984 spin_unlock(&cookie->lock);
44985 radix_tree_preload_end();
44986 kfree(op);
44987- fscache_stat(&fscache_n_stores_ok);
44988+ fscache_stat_unchecked(&fscache_n_stores_ok);
44989 _leave(" = 0");
44990 return 0;
44991
44992@@ -851,14 +851,14 @@ nobufs:
44993 spin_unlock(&cookie->lock);
44994 radix_tree_preload_end();
44995 kfree(op);
44996- fscache_stat(&fscache_n_stores_nobufs);
44997+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
44998 _leave(" = -ENOBUFS");
44999 return -ENOBUFS;
45000
45001 nomem_free:
45002 kfree(op);
45003 nomem:
45004- fscache_stat(&fscache_n_stores_oom);
45005+ fscache_stat_unchecked(&fscache_n_stores_oom);
45006 _leave(" = -ENOMEM");
45007 return -ENOMEM;
45008 }
45009@@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
45010 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45011 ASSERTCMP(page, !=, NULL);
45012
45013- fscache_stat(&fscache_n_uncaches);
45014+ fscache_stat_unchecked(&fscache_n_uncaches);
45015
45016 /* cache withdrawal may beat us to it */
45017 if (!PageFsCache(page))
45018@@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
45019 unsigned long loop;
45020
45021 #ifdef CONFIG_FSCACHE_STATS
45022- atomic_add(pagevec->nr, &fscache_n_marks);
45023+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
45024 #endif
45025
45026 for (loop = 0; loop < pagevec->nr; loop++) {
45027diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
45028index 4765190..2a067f2 100644
45029--- a/fs/fscache/stats.c
45030+++ b/fs/fscache/stats.c
45031@@ -18,95 +18,95 @@
45032 /*
45033 * operation counters
45034 */
45035-atomic_t fscache_n_op_pend;
45036-atomic_t fscache_n_op_run;
45037-atomic_t fscache_n_op_enqueue;
45038-atomic_t fscache_n_op_requeue;
45039-atomic_t fscache_n_op_deferred_release;
45040-atomic_t fscache_n_op_release;
45041-atomic_t fscache_n_op_gc;
45042-atomic_t fscache_n_op_cancelled;
45043-atomic_t fscache_n_op_rejected;
45044+atomic_unchecked_t fscache_n_op_pend;
45045+atomic_unchecked_t fscache_n_op_run;
45046+atomic_unchecked_t fscache_n_op_enqueue;
45047+atomic_unchecked_t fscache_n_op_requeue;
45048+atomic_unchecked_t fscache_n_op_deferred_release;
45049+atomic_unchecked_t fscache_n_op_release;
45050+atomic_unchecked_t fscache_n_op_gc;
45051+atomic_unchecked_t fscache_n_op_cancelled;
45052+atomic_unchecked_t fscache_n_op_rejected;
45053
45054-atomic_t fscache_n_attr_changed;
45055-atomic_t fscache_n_attr_changed_ok;
45056-atomic_t fscache_n_attr_changed_nobufs;
45057-atomic_t fscache_n_attr_changed_nomem;
45058-atomic_t fscache_n_attr_changed_calls;
45059+atomic_unchecked_t fscache_n_attr_changed;
45060+atomic_unchecked_t fscache_n_attr_changed_ok;
45061+atomic_unchecked_t fscache_n_attr_changed_nobufs;
45062+atomic_unchecked_t fscache_n_attr_changed_nomem;
45063+atomic_unchecked_t fscache_n_attr_changed_calls;
45064
45065-atomic_t fscache_n_allocs;
45066-atomic_t fscache_n_allocs_ok;
45067-atomic_t fscache_n_allocs_wait;
45068-atomic_t fscache_n_allocs_nobufs;
45069-atomic_t fscache_n_allocs_intr;
45070-atomic_t fscache_n_allocs_object_dead;
45071-atomic_t fscache_n_alloc_ops;
45072-atomic_t fscache_n_alloc_op_waits;
45073+atomic_unchecked_t fscache_n_allocs;
45074+atomic_unchecked_t fscache_n_allocs_ok;
45075+atomic_unchecked_t fscache_n_allocs_wait;
45076+atomic_unchecked_t fscache_n_allocs_nobufs;
45077+atomic_unchecked_t fscache_n_allocs_intr;
45078+atomic_unchecked_t fscache_n_allocs_object_dead;
45079+atomic_unchecked_t fscache_n_alloc_ops;
45080+atomic_unchecked_t fscache_n_alloc_op_waits;
45081
45082-atomic_t fscache_n_retrievals;
45083-atomic_t fscache_n_retrievals_ok;
45084-atomic_t fscache_n_retrievals_wait;
45085-atomic_t fscache_n_retrievals_nodata;
45086-atomic_t fscache_n_retrievals_nobufs;
45087-atomic_t fscache_n_retrievals_intr;
45088-atomic_t fscache_n_retrievals_nomem;
45089-atomic_t fscache_n_retrievals_object_dead;
45090-atomic_t fscache_n_retrieval_ops;
45091-atomic_t fscache_n_retrieval_op_waits;
45092+atomic_unchecked_t fscache_n_retrievals;
45093+atomic_unchecked_t fscache_n_retrievals_ok;
45094+atomic_unchecked_t fscache_n_retrievals_wait;
45095+atomic_unchecked_t fscache_n_retrievals_nodata;
45096+atomic_unchecked_t fscache_n_retrievals_nobufs;
45097+atomic_unchecked_t fscache_n_retrievals_intr;
45098+atomic_unchecked_t fscache_n_retrievals_nomem;
45099+atomic_unchecked_t fscache_n_retrievals_object_dead;
45100+atomic_unchecked_t fscache_n_retrieval_ops;
45101+atomic_unchecked_t fscache_n_retrieval_op_waits;
45102
45103-atomic_t fscache_n_stores;
45104-atomic_t fscache_n_stores_ok;
45105-atomic_t fscache_n_stores_again;
45106-atomic_t fscache_n_stores_nobufs;
45107-atomic_t fscache_n_stores_oom;
45108-atomic_t fscache_n_store_ops;
45109-atomic_t fscache_n_store_calls;
45110-atomic_t fscache_n_store_pages;
45111-atomic_t fscache_n_store_radix_deletes;
45112-atomic_t fscache_n_store_pages_over_limit;
45113+atomic_unchecked_t fscache_n_stores;
45114+atomic_unchecked_t fscache_n_stores_ok;
45115+atomic_unchecked_t fscache_n_stores_again;
45116+atomic_unchecked_t fscache_n_stores_nobufs;
45117+atomic_unchecked_t fscache_n_stores_oom;
45118+atomic_unchecked_t fscache_n_store_ops;
45119+atomic_unchecked_t fscache_n_store_calls;
45120+atomic_unchecked_t fscache_n_store_pages;
45121+atomic_unchecked_t fscache_n_store_radix_deletes;
45122+atomic_unchecked_t fscache_n_store_pages_over_limit;
45123
45124-atomic_t fscache_n_store_vmscan_not_storing;
45125-atomic_t fscache_n_store_vmscan_gone;
45126-atomic_t fscache_n_store_vmscan_busy;
45127-atomic_t fscache_n_store_vmscan_cancelled;
45128+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45129+atomic_unchecked_t fscache_n_store_vmscan_gone;
45130+atomic_unchecked_t fscache_n_store_vmscan_busy;
45131+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45132
45133-atomic_t fscache_n_marks;
45134-atomic_t fscache_n_uncaches;
45135+atomic_unchecked_t fscache_n_marks;
45136+atomic_unchecked_t fscache_n_uncaches;
45137
45138-atomic_t fscache_n_acquires;
45139-atomic_t fscache_n_acquires_null;
45140-atomic_t fscache_n_acquires_no_cache;
45141-atomic_t fscache_n_acquires_ok;
45142-atomic_t fscache_n_acquires_nobufs;
45143-atomic_t fscache_n_acquires_oom;
45144+atomic_unchecked_t fscache_n_acquires;
45145+atomic_unchecked_t fscache_n_acquires_null;
45146+atomic_unchecked_t fscache_n_acquires_no_cache;
45147+atomic_unchecked_t fscache_n_acquires_ok;
45148+atomic_unchecked_t fscache_n_acquires_nobufs;
45149+atomic_unchecked_t fscache_n_acquires_oom;
45150
45151-atomic_t fscache_n_updates;
45152-atomic_t fscache_n_updates_null;
45153-atomic_t fscache_n_updates_run;
45154+atomic_unchecked_t fscache_n_updates;
45155+atomic_unchecked_t fscache_n_updates_null;
45156+atomic_unchecked_t fscache_n_updates_run;
45157
45158-atomic_t fscache_n_relinquishes;
45159-atomic_t fscache_n_relinquishes_null;
45160-atomic_t fscache_n_relinquishes_waitcrt;
45161-atomic_t fscache_n_relinquishes_retire;
45162+atomic_unchecked_t fscache_n_relinquishes;
45163+atomic_unchecked_t fscache_n_relinquishes_null;
45164+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45165+atomic_unchecked_t fscache_n_relinquishes_retire;
45166
45167-atomic_t fscache_n_cookie_index;
45168-atomic_t fscache_n_cookie_data;
45169-atomic_t fscache_n_cookie_special;
45170+atomic_unchecked_t fscache_n_cookie_index;
45171+atomic_unchecked_t fscache_n_cookie_data;
45172+atomic_unchecked_t fscache_n_cookie_special;
45173
45174-atomic_t fscache_n_object_alloc;
45175-atomic_t fscache_n_object_no_alloc;
45176-atomic_t fscache_n_object_lookups;
45177-atomic_t fscache_n_object_lookups_negative;
45178-atomic_t fscache_n_object_lookups_positive;
45179-atomic_t fscache_n_object_lookups_timed_out;
45180-atomic_t fscache_n_object_created;
45181-atomic_t fscache_n_object_avail;
45182-atomic_t fscache_n_object_dead;
45183+atomic_unchecked_t fscache_n_object_alloc;
45184+atomic_unchecked_t fscache_n_object_no_alloc;
45185+atomic_unchecked_t fscache_n_object_lookups;
45186+atomic_unchecked_t fscache_n_object_lookups_negative;
45187+atomic_unchecked_t fscache_n_object_lookups_positive;
45188+atomic_unchecked_t fscache_n_object_lookups_timed_out;
45189+atomic_unchecked_t fscache_n_object_created;
45190+atomic_unchecked_t fscache_n_object_avail;
45191+atomic_unchecked_t fscache_n_object_dead;
45192
45193-atomic_t fscache_n_checkaux_none;
45194-atomic_t fscache_n_checkaux_okay;
45195-atomic_t fscache_n_checkaux_update;
45196-atomic_t fscache_n_checkaux_obsolete;
45197+atomic_unchecked_t fscache_n_checkaux_none;
45198+atomic_unchecked_t fscache_n_checkaux_okay;
45199+atomic_unchecked_t fscache_n_checkaux_update;
45200+atomic_unchecked_t fscache_n_checkaux_obsolete;
45201
45202 atomic_t fscache_n_cop_alloc_object;
45203 atomic_t fscache_n_cop_lookup_object;
45204@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
45205 seq_puts(m, "FS-Cache statistics\n");
45206
45207 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
45208- atomic_read(&fscache_n_cookie_index),
45209- atomic_read(&fscache_n_cookie_data),
45210- atomic_read(&fscache_n_cookie_special));
45211+ atomic_read_unchecked(&fscache_n_cookie_index),
45212+ atomic_read_unchecked(&fscache_n_cookie_data),
45213+ atomic_read_unchecked(&fscache_n_cookie_special));
45214
45215 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
45216- atomic_read(&fscache_n_object_alloc),
45217- atomic_read(&fscache_n_object_no_alloc),
45218- atomic_read(&fscache_n_object_avail),
45219- atomic_read(&fscache_n_object_dead));
45220+ atomic_read_unchecked(&fscache_n_object_alloc),
45221+ atomic_read_unchecked(&fscache_n_object_no_alloc),
45222+ atomic_read_unchecked(&fscache_n_object_avail),
45223+ atomic_read_unchecked(&fscache_n_object_dead));
45224 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
45225- atomic_read(&fscache_n_checkaux_none),
45226- atomic_read(&fscache_n_checkaux_okay),
45227- atomic_read(&fscache_n_checkaux_update),
45228- atomic_read(&fscache_n_checkaux_obsolete));
45229+ atomic_read_unchecked(&fscache_n_checkaux_none),
45230+ atomic_read_unchecked(&fscache_n_checkaux_okay),
45231+ atomic_read_unchecked(&fscache_n_checkaux_update),
45232+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
45233
45234 seq_printf(m, "Pages : mrk=%u unc=%u\n",
45235- atomic_read(&fscache_n_marks),
45236- atomic_read(&fscache_n_uncaches));
45237+ atomic_read_unchecked(&fscache_n_marks),
45238+ atomic_read_unchecked(&fscache_n_uncaches));
45239
45240 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
45241 " oom=%u\n",
45242- atomic_read(&fscache_n_acquires),
45243- atomic_read(&fscache_n_acquires_null),
45244- atomic_read(&fscache_n_acquires_no_cache),
45245- atomic_read(&fscache_n_acquires_ok),
45246- atomic_read(&fscache_n_acquires_nobufs),
45247- atomic_read(&fscache_n_acquires_oom));
45248+ atomic_read_unchecked(&fscache_n_acquires),
45249+ atomic_read_unchecked(&fscache_n_acquires_null),
45250+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
45251+ atomic_read_unchecked(&fscache_n_acquires_ok),
45252+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
45253+ atomic_read_unchecked(&fscache_n_acquires_oom));
45254
45255 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
45256- atomic_read(&fscache_n_object_lookups),
45257- atomic_read(&fscache_n_object_lookups_negative),
45258- atomic_read(&fscache_n_object_lookups_positive),
45259- atomic_read(&fscache_n_object_created),
45260- atomic_read(&fscache_n_object_lookups_timed_out));
45261+ atomic_read_unchecked(&fscache_n_object_lookups),
45262+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
45263+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
45264+ atomic_read_unchecked(&fscache_n_object_created),
45265+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
45266
45267 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
45268- atomic_read(&fscache_n_updates),
45269- atomic_read(&fscache_n_updates_null),
45270- atomic_read(&fscache_n_updates_run));
45271+ atomic_read_unchecked(&fscache_n_updates),
45272+ atomic_read_unchecked(&fscache_n_updates_null),
45273+ atomic_read_unchecked(&fscache_n_updates_run));
45274
45275 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
45276- atomic_read(&fscache_n_relinquishes),
45277- atomic_read(&fscache_n_relinquishes_null),
45278- atomic_read(&fscache_n_relinquishes_waitcrt),
45279- atomic_read(&fscache_n_relinquishes_retire));
45280+ atomic_read_unchecked(&fscache_n_relinquishes),
45281+ atomic_read_unchecked(&fscache_n_relinquishes_null),
45282+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
45283+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
45284
45285 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
45286- atomic_read(&fscache_n_attr_changed),
45287- atomic_read(&fscache_n_attr_changed_ok),
45288- atomic_read(&fscache_n_attr_changed_nobufs),
45289- atomic_read(&fscache_n_attr_changed_nomem),
45290- atomic_read(&fscache_n_attr_changed_calls));
45291+ atomic_read_unchecked(&fscache_n_attr_changed),
45292+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
45293+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
45294+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
45295+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
45296
45297 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
45298- atomic_read(&fscache_n_allocs),
45299- atomic_read(&fscache_n_allocs_ok),
45300- atomic_read(&fscache_n_allocs_wait),
45301- atomic_read(&fscache_n_allocs_nobufs),
45302- atomic_read(&fscache_n_allocs_intr));
45303+ atomic_read_unchecked(&fscache_n_allocs),
45304+ atomic_read_unchecked(&fscache_n_allocs_ok),
45305+ atomic_read_unchecked(&fscache_n_allocs_wait),
45306+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
45307+ atomic_read_unchecked(&fscache_n_allocs_intr));
45308 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
45309- atomic_read(&fscache_n_alloc_ops),
45310- atomic_read(&fscache_n_alloc_op_waits),
45311- atomic_read(&fscache_n_allocs_object_dead));
45312+ atomic_read_unchecked(&fscache_n_alloc_ops),
45313+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
45314+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
45315
45316 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
45317 " int=%u oom=%u\n",
45318- atomic_read(&fscache_n_retrievals),
45319- atomic_read(&fscache_n_retrievals_ok),
45320- atomic_read(&fscache_n_retrievals_wait),
45321- atomic_read(&fscache_n_retrievals_nodata),
45322- atomic_read(&fscache_n_retrievals_nobufs),
45323- atomic_read(&fscache_n_retrievals_intr),
45324- atomic_read(&fscache_n_retrievals_nomem));
45325+ atomic_read_unchecked(&fscache_n_retrievals),
45326+ atomic_read_unchecked(&fscache_n_retrievals_ok),
45327+ atomic_read_unchecked(&fscache_n_retrievals_wait),
45328+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
45329+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
45330+ atomic_read_unchecked(&fscache_n_retrievals_intr),
45331+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
45332 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
45333- atomic_read(&fscache_n_retrieval_ops),
45334- atomic_read(&fscache_n_retrieval_op_waits),
45335- atomic_read(&fscache_n_retrievals_object_dead));
45336+ atomic_read_unchecked(&fscache_n_retrieval_ops),
45337+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
45338+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
45339
45340 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
45341- atomic_read(&fscache_n_stores),
45342- atomic_read(&fscache_n_stores_ok),
45343- atomic_read(&fscache_n_stores_again),
45344- atomic_read(&fscache_n_stores_nobufs),
45345- atomic_read(&fscache_n_stores_oom));
45346+ atomic_read_unchecked(&fscache_n_stores),
45347+ atomic_read_unchecked(&fscache_n_stores_ok),
45348+ atomic_read_unchecked(&fscache_n_stores_again),
45349+ atomic_read_unchecked(&fscache_n_stores_nobufs),
45350+ atomic_read_unchecked(&fscache_n_stores_oom));
45351 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
45352- atomic_read(&fscache_n_store_ops),
45353- atomic_read(&fscache_n_store_calls),
45354- atomic_read(&fscache_n_store_pages),
45355- atomic_read(&fscache_n_store_radix_deletes),
45356- atomic_read(&fscache_n_store_pages_over_limit));
45357+ atomic_read_unchecked(&fscache_n_store_ops),
45358+ atomic_read_unchecked(&fscache_n_store_calls),
45359+ atomic_read_unchecked(&fscache_n_store_pages),
45360+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
45361+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
45362
45363 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
45364- atomic_read(&fscache_n_store_vmscan_not_storing),
45365- atomic_read(&fscache_n_store_vmscan_gone),
45366- atomic_read(&fscache_n_store_vmscan_busy),
45367- atomic_read(&fscache_n_store_vmscan_cancelled));
45368+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
45369+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
45370+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
45371+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
45372
45373 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
45374- atomic_read(&fscache_n_op_pend),
45375- atomic_read(&fscache_n_op_run),
45376- atomic_read(&fscache_n_op_enqueue),
45377- atomic_read(&fscache_n_op_cancelled),
45378- atomic_read(&fscache_n_op_rejected));
45379+ atomic_read_unchecked(&fscache_n_op_pend),
45380+ atomic_read_unchecked(&fscache_n_op_run),
45381+ atomic_read_unchecked(&fscache_n_op_enqueue),
45382+ atomic_read_unchecked(&fscache_n_op_cancelled),
45383+ atomic_read_unchecked(&fscache_n_op_rejected));
45384 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
45385- atomic_read(&fscache_n_op_deferred_release),
45386- atomic_read(&fscache_n_op_release),
45387- atomic_read(&fscache_n_op_gc));
45388+ atomic_read_unchecked(&fscache_n_op_deferred_release),
45389+ atomic_read_unchecked(&fscache_n_op_release),
45390+ atomic_read_unchecked(&fscache_n_op_gc));
45391
45392 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
45393 atomic_read(&fscache_n_cop_alloc_object),
45394diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
45395index 3426521..3b75162 100644
45396--- a/fs/fuse/cuse.c
45397+++ b/fs/fuse/cuse.c
45398@@ -587,10 +587,12 @@ static int __init cuse_init(void)
45399 INIT_LIST_HEAD(&cuse_conntbl[i]);
45400
45401 /* inherit and extend fuse_dev_operations */
45402- cuse_channel_fops = fuse_dev_operations;
45403- cuse_channel_fops.owner = THIS_MODULE;
45404- cuse_channel_fops.open = cuse_channel_open;
45405- cuse_channel_fops.release = cuse_channel_release;
45406+ pax_open_kernel();
45407+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
45408+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
45409+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
45410+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
45411+ pax_close_kernel();
45412
45413 cuse_class = class_create(THIS_MODULE, "cuse");
45414 if (IS_ERR(cuse_class))
45415diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
45416index 5f3368a..8306426 100644
45417--- a/fs/fuse/dev.c
45418+++ b/fs/fuse/dev.c
45419@@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
45420 ret = 0;
45421 pipe_lock(pipe);
45422
45423- if (!pipe->readers) {
45424+ if (!atomic_read(&pipe->readers)) {
45425 send_sig(SIGPIPE, current, 0);
45426 if (!ret)
45427 ret = -EPIPE;
45428diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
45429index 2066328..f5add3b 100644
45430--- a/fs/fuse/dir.c
45431+++ b/fs/fuse/dir.c
45432@@ -1175,7 +1175,7 @@ static char *read_link(struct dentry *dentry)
45433 return link;
45434 }
45435
45436-static void free_link(char *link)
45437+static void free_link(const char *link)
45438 {
45439 if (!IS_ERR(link))
45440 free_page((unsigned long) link);
45441diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
45442index 5698746..6086012 100644
45443--- a/fs/gfs2/inode.c
45444+++ b/fs/gfs2/inode.c
45445@@ -1487,7 +1487,7 @@ out:
45446
45447 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
45448 {
45449- char *s = nd_get_link(nd);
45450+ const char *s = nd_get_link(nd);
45451 if (!IS_ERR(s))
45452 kfree(s);
45453 }
45454diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
45455index 3645cd3..786809c 100644
45456--- a/fs/hugetlbfs/inode.c
45457+++ b/fs/hugetlbfs/inode.c
45458@@ -914,7 +914,7 @@ static struct file_system_type hugetlbfs_fs_type = {
45459 .kill_sb = kill_litter_super,
45460 };
45461
45462-static struct vfsmount *hugetlbfs_vfsmount;
45463+struct vfsmount *hugetlbfs_vfsmount;
45464
45465 static int can_do_hugetlb_shm(void)
45466 {
45467diff --git a/fs/inode.c b/fs/inode.c
45468index 83ab215..8842101 100644
45469--- a/fs/inode.c
45470+++ b/fs/inode.c
45471@@ -870,8 +870,8 @@ unsigned int get_next_ino(void)
45472
45473 #ifdef CONFIG_SMP
45474 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
45475- static atomic_t shared_last_ino;
45476- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
45477+ static atomic_unchecked_t shared_last_ino;
45478+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
45479
45480 res = next - LAST_INO_BATCH;
45481 }
45482diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
45483index eafb8d3..f423d37 100644
45484--- a/fs/jffs2/erase.c
45485+++ b/fs/jffs2/erase.c
45486@@ -438,7 +438,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
45487 struct jffs2_unknown_node marker = {
45488 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
45489 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
45490- .totlen = cpu_to_je32(c->cleanmarker_size)
45491+ .totlen = cpu_to_je32(c->cleanmarker_size),
45492+ .hdr_crc = cpu_to_je32(0)
45493 };
45494
45495 jffs2_prealloc_raw_node_refs(c, jeb, 1);
45496diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
45497index 30e8f47..21f600c 100644
45498--- a/fs/jffs2/wbuf.c
45499+++ b/fs/jffs2/wbuf.c
45500@@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
45501 {
45502 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
45503 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
45504- .totlen = constant_cpu_to_je32(8)
45505+ .totlen = constant_cpu_to_je32(8),
45506+ .hdr_crc = constant_cpu_to_je32(0)
45507 };
45508
45509 /*
45510diff --git a/fs/jfs/super.c b/fs/jfs/super.c
45511index 682bca6..86b8e6e 100644
45512--- a/fs/jfs/super.c
45513+++ b/fs/jfs/super.c
45514@@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
45515
45516 jfs_inode_cachep =
45517 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
45518- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
45519+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
45520 init_once);
45521 if (jfs_inode_cachep == NULL)
45522 return -ENOMEM;
45523diff --git a/fs/libfs.c b/fs/libfs.c
45524index 5b2dbb3..7442d54 100644
45525--- a/fs/libfs.c
45526+++ b/fs/libfs.c
45527@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
45528
45529 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
45530 struct dentry *next;
45531+ char d_name[sizeof(next->d_iname)];
45532+ const unsigned char *name;
45533+
45534 next = list_entry(p, struct dentry, d_u.d_child);
45535 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
45536 if (!simple_positive(next)) {
45537@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
45538
45539 spin_unlock(&next->d_lock);
45540 spin_unlock(&dentry->d_lock);
45541- if (filldir(dirent, next->d_name.name,
45542+ name = next->d_name.name;
45543+ if (name == next->d_iname) {
45544+ memcpy(d_name, name, next->d_name.len);
45545+ name = d_name;
45546+ }
45547+ if (filldir(dirent, name,
45548 next->d_name.len, filp->f_pos,
45549 next->d_inode->i_ino,
45550 dt_type(next->d_inode)) < 0)
45551diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
45552index 8392cb8..80d6193 100644
45553--- a/fs/lockd/clntproc.c
45554+++ b/fs/lockd/clntproc.c
45555@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
45556 /*
45557 * Cookie counter for NLM requests
45558 */
45559-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
45560+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
45561
45562 void nlmclnt_next_cookie(struct nlm_cookie *c)
45563 {
45564- u32 cookie = atomic_inc_return(&nlm_cookie);
45565+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
45566
45567 memcpy(c->data, &cookie, 4);
45568 c->len=4;
45569diff --git a/fs/locks.c b/fs/locks.c
45570index 637694b..f84a121 100644
45571--- a/fs/locks.c
45572+++ b/fs/locks.c
45573@@ -2074,16 +2074,16 @@ void locks_remove_flock(struct file *filp)
45574 return;
45575
45576 if (filp->f_op && filp->f_op->flock) {
45577- struct file_lock fl = {
45578+ struct file_lock flock = {
45579 .fl_pid = current->tgid,
45580 .fl_file = filp,
45581 .fl_flags = FL_FLOCK,
45582 .fl_type = F_UNLCK,
45583 .fl_end = OFFSET_MAX,
45584 };
45585- filp->f_op->flock(filp, F_SETLKW, &fl);
45586- if (fl.fl_ops && fl.fl_ops->fl_release_private)
45587- fl.fl_ops->fl_release_private(&fl);
45588+ filp->f_op->flock(filp, F_SETLKW, &flock);
45589+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
45590+ flock.fl_ops->fl_release_private(&flock);
45591 }
45592
45593 lock_flocks();
45594diff --git a/fs/namei.c b/fs/namei.c
45595index 46ea9cc..c7cf3a3 100644
45596--- a/fs/namei.c
45597+++ b/fs/namei.c
45598@@ -278,16 +278,32 @@ int generic_permission(struct inode *inode, int mask)
45599 if (ret != -EACCES)
45600 return ret;
45601
45602+#ifdef CONFIG_GRKERNSEC
45603+ /* we'll block if we have to log due to a denied capability use */
45604+ if (mask & MAY_NOT_BLOCK)
45605+ return -ECHILD;
45606+#endif
45607+
45608 if (S_ISDIR(inode->i_mode)) {
45609 /* DACs are overridable for directories */
45610- if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
45611- return 0;
45612 if (!(mask & MAY_WRITE))
45613- if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
45614+ if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
45615+ ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
45616 return 0;
45617+ if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
45618+ return 0;
45619 return -EACCES;
45620 }
45621 /*
45622+ * Searching includes executable on directories, else just read.
45623+ */
45624+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
45625+ if (mask == MAY_READ)
45626+ if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
45627+ ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
45628+ return 0;
45629+
45630+ /*
45631 * Read/write DACs are always overridable.
45632 * Executable DACs are overridable when there is
45633 * at least one exec bit set.
45634@@ -296,14 +312,6 @@ int generic_permission(struct inode *inode, int mask)
45635 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
45636 return 0;
45637
45638- /*
45639- * Searching includes executable on directories, else just read.
45640- */
45641- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
45642- if (mask == MAY_READ)
45643- if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
45644- return 0;
45645-
45646 return -EACCES;
45647 }
45648
45649@@ -652,11 +660,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
45650 return error;
45651 }
45652
45653+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
45654+ dentry->d_inode, dentry, nd->path.mnt)) {
45655+ error = -EACCES;
45656+ *p = ERR_PTR(error); /* no ->put_link(), please */
45657+ path_put(&nd->path);
45658+ return error;
45659+ }
45660+
45661 nd->last_type = LAST_BIND;
45662 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
45663 error = PTR_ERR(*p);
45664 if (!IS_ERR(*p)) {
45665- char *s = nd_get_link(nd);
45666+ const char *s = nd_get_link(nd);
45667 error = 0;
45668 if (s)
45669 error = __vfs_follow_link(nd, s);
45670@@ -1650,6 +1666,21 @@ static int path_lookupat(int dfd, const char *name,
45671 if (!err)
45672 err = complete_walk(nd);
45673
45674+ if (!(nd->flags & LOOKUP_PARENT)) {
45675+#ifdef CONFIG_GRKERNSEC
45676+ if (flags & LOOKUP_RCU) {
45677+ if (!err)
45678+ path_put(&nd->path);
45679+ err = -ECHILD;
45680+ } else
45681+#endif
45682+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
45683+ if (!err)
45684+ path_put(&nd->path);
45685+ err = -ENOENT;
45686+ }
45687+ }
45688+
45689 if (!err && nd->flags & LOOKUP_DIRECTORY) {
45690 if (!nd->inode->i_op->lookup) {
45691 path_put(&nd->path);
45692@@ -1677,6 +1708,15 @@ static int do_path_lookup(int dfd, const char *name,
45693 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
45694
45695 if (likely(!retval)) {
45696+ if (*name != '/' && nd->path.dentry && nd->inode) {
45697+#ifdef CONFIG_GRKERNSEC
45698+ if (flags & LOOKUP_RCU)
45699+ return -ECHILD;
45700+#endif
45701+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
45702+ return -ENOENT;
45703+ }
45704+
45705 if (unlikely(!audit_dummy_context())) {
45706 if (nd->path.dentry && nd->inode)
45707 audit_inode(name, nd->path.dentry);
45708@@ -2071,6 +2111,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
45709 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
45710 return -EPERM;
45711
45712+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
45713+ return -EPERM;
45714+ if (gr_handle_rawio(inode))
45715+ return -EPERM;
45716+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
45717+ return -EACCES;
45718+
45719 return 0;
45720 }
45721
45722@@ -2132,6 +2179,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
45723 error = complete_walk(nd);
45724 if (error)
45725 return ERR_PTR(error);
45726+#ifdef CONFIG_GRKERNSEC
45727+ if (nd->flags & LOOKUP_RCU) {
45728+ error = -ECHILD;
45729+ goto exit;
45730+ }
45731+#endif
45732+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
45733+ error = -ENOENT;
45734+ goto exit;
45735+ }
45736 audit_inode(pathname, nd->path.dentry);
45737 if (open_flag & O_CREAT) {
45738 error = -EISDIR;
45739@@ -2142,6 +2199,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
45740 error = complete_walk(nd);
45741 if (error)
45742 return ERR_PTR(error);
45743+#ifdef CONFIG_GRKERNSEC
45744+ if (nd->flags & LOOKUP_RCU) {
45745+ error = -ECHILD;
45746+ goto exit;
45747+ }
45748+#endif
45749+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
45750+ error = -ENOENT;
45751+ goto exit;
45752+ }
45753 audit_inode(pathname, dir);
45754 goto ok;
45755 }
45756@@ -2163,6 +2230,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
45757 error = complete_walk(nd);
45758 if (error)
45759 return ERR_PTR(error);
45760+#ifdef CONFIG_GRKERNSEC
45761+ if (nd->flags & LOOKUP_RCU) {
45762+ error = -ECHILD;
45763+ goto exit;
45764+ }
45765+#endif
45766+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
45767+ error = -ENOENT;
45768+ goto exit;
45769+ }
45770
45771 error = -ENOTDIR;
45772 if (nd->flags & LOOKUP_DIRECTORY) {
45773@@ -2203,6 +2280,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
45774 /* Negative dentry, just create the file */
45775 if (!dentry->d_inode) {
45776 umode_t mode = op->mode;
45777+
45778+ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
45779+ error = -EACCES;
45780+ goto exit_mutex_unlock;
45781+ }
45782+
45783 if (!IS_POSIXACL(dir->d_inode))
45784 mode &= ~current_umask();
45785 /*
45786@@ -2226,6 +2309,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
45787 error = vfs_create(dir->d_inode, dentry, mode, nd);
45788 if (error)
45789 goto exit_mutex_unlock;
45790+ else
45791+ gr_handle_create(path->dentry, path->mnt);
45792 mutex_unlock(&dir->d_inode->i_mutex);
45793 dput(nd->path.dentry);
45794 nd->path.dentry = dentry;
45795@@ -2235,6 +2320,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
45796 /*
45797 * It already exists.
45798 */
45799+
45800+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
45801+ error = -ENOENT;
45802+ goto exit_mutex_unlock;
45803+ }
45804+
45805+ /* only check if O_CREAT is specified, all other checks need to go
45806+ into may_open */
45807+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
45808+ error = -EACCES;
45809+ goto exit_mutex_unlock;
45810+ }
45811+
45812 mutex_unlock(&dir->d_inode->i_mutex);
45813 audit_inode(pathname, path->dentry);
45814
45815@@ -2447,6 +2545,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
45816 *path = nd.path;
45817 return dentry;
45818 eexist:
45819+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
45820+ dput(dentry);
45821+ dentry = ERR_PTR(-ENOENT);
45822+ goto fail;
45823+ }
45824 dput(dentry);
45825 dentry = ERR_PTR(-EEXIST);
45826 fail:
45827@@ -2469,6 +2572,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
45828 }
45829 EXPORT_SYMBOL(user_path_create);
45830
45831+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
45832+{
45833+ char *tmp = getname(pathname);
45834+ struct dentry *res;
45835+ if (IS_ERR(tmp))
45836+ return ERR_CAST(tmp);
45837+ res = kern_path_create(dfd, tmp, path, is_dir);
45838+ if (IS_ERR(res))
45839+ putname(tmp);
45840+ else
45841+ *to = tmp;
45842+ return res;
45843+}
45844+
45845 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
45846 {
45847 int error = may_create(dir, dentry);
45848@@ -2536,6 +2653,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
45849 error = mnt_want_write(path.mnt);
45850 if (error)
45851 goto out_dput;
45852+
45853+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
45854+ error = -EPERM;
45855+ goto out_drop_write;
45856+ }
45857+
45858+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
45859+ error = -EACCES;
45860+ goto out_drop_write;
45861+ }
45862+
45863 error = security_path_mknod(&path, dentry, mode, dev);
45864 if (error)
45865 goto out_drop_write;
45866@@ -2553,6 +2681,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
45867 }
45868 out_drop_write:
45869 mnt_drop_write(path.mnt);
45870+
45871+ if (!error)
45872+ gr_handle_create(dentry, path.mnt);
45873 out_dput:
45874 dput(dentry);
45875 mutex_unlock(&path.dentry->d_inode->i_mutex);
45876@@ -2602,12 +2733,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
45877 error = mnt_want_write(path.mnt);
45878 if (error)
45879 goto out_dput;
45880+
45881+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
45882+ error = -EACCES;
45883+ goto out_drop_write;
45884+ }
45885+
45886 error = security_path_mkdir(&path, dentry, mode);
45887 if (error)
45888 goto out_drop_write;
45889 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
45890 out_drop_write:
45891 mnt_drop_write(path.mnt);
45892+
45893+ if (!error)
45894+ gr_handle_create(dentry, path.mnt);
45895 out_dput:
45896 dput(dentry);
45897 mutex_unlock(&path.dentry->d_inode->i_mutex);
45898@@ -2687,6 +2827,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
45899 char * name;
45900 struct dentry *dentry;
45901 struct nameidata nd;
45902+ ino_t saved_ino = 0;
45903+ dev_t saved_dev = 0;
45904
45905 error = user_path_parent(dfd, pathname, &nd, &name);
45906 if (error)
45907@@ -2715,6 +2857,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
45908 error = -ENOENT;
45909 goto exit3;
45910 }
45911+
45912+ saved_ino = dentry->d_inode->i_ino;
45913+ saved_dev = gr_get_dev_from_dentry(dentry);
45914+
45915+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
45916+ error = -EACCES;
45917+ goto exit3;
45918+ }
45919+
45920 error = mnt_want_write(nd.path.mnt);
45921 if (error)
45922 goto exit3;
45923@@ -2722,6 +2873,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
45924 if (error)
45925 goto exit4;
45926 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
45927+ if (!error && (saved_dev || saved_ino))
45928+ gr_handle_delete(saved_ino, saved_dev);
45929 exit4:
45930 mnt_drop_write(nd.path.mnt);
45931 exit3:
45932@@ -2784,6 +2937,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
45933 struct dentry *dentry;
45934 struct nameidata nd;
45935 struct inode *inode = NULL;
45936+ ino_t saved_ino = 0;
45937+ dev_t saved_dev = 0;
45938
45939 error = user_path_parent(dfd, pathname, &nd, &name);
45940 if (error)
45941@@ -2806,6 +2961,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
45942 if (!inode)
45943 goto slashes;
45944 ihold(inode);
45945+
45946+ if (inode->i_nlink <= 1) {
45947+ saved_ino = inode->i_ino;
45948+ saved_dev = gr_get_dev_from_dentry(dentry);
45949+ }
45950+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
45951+ error = -EACCES;
45952+ goto exit2;
45953+ }
45954+
45955 error = mnt_want_write(nd.path.mnt);
45956 if (error)
45957 goto exit2;
45958@@ -2813,6 +2978,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
45959 if (error)
45960 goto exit3;
45961 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
45962+ if (!error && (saved_ino || saved_dev))
45963+ gr_handle_delete(saved_ino, saved_dev);
45964 exit3:
45965 mnt_drop_write(nd.path.mnt);
45966 exit2:
45967@@ -2888,10 +3055,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
45968 error = mnt_want_write(path.mnt);
45969 if (error)
45970 goto out_dput;
45971+
45972+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
45973+ error = -EACCES;
45974+ goto out_drop_write;
45975+ }
45976+
45977 error = security_path_symlink(&path, dentry, from);
45978 if (error)
45979 goto out_drop_write;
45980 error = vfs_symlink(path.dentry->d_inode, dentry, from);
45981+ if (!error)
45982+ gr_handle_create(dentry, path.mnt);
45983 out_drop_write:
45984 mnt_drop_write(path.mnt);
45985 out_dput:
45986@@ -2963,6 +3138,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
45987 {
45988 struct dentry *new_dentry;
45989 struct path old_path, new_path;
45990+ char *to = NULL;
45991 int how = 0;
45992 int error;
45993
45994@@ -2986,7 +3162,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
45995 if (error)
45996 return error;
45997
45998- new_dentry = user_path_create(newdfd, newname, &new_path, 0);
45999+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
46000 error = PTR_ERR(new_dentry);
46001 if (IS_ERR(new_dentry))
46002 goto out;
46003@@ -2997,13 +3173,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46004 error = mnt_want_write(new_path.mnt);
46005 if (error)
46006 goto out_dput;
46007+
46008+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
46009+ old_path.dentry->d_inode,
46010+ old_path.dentry->d_inode->i_mode, to)) {
46011+ error = -EACCES;
46012+ goto out_drop_write;
46013+ }
46014+
46015+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
46016+ old_path.dentry, old_path.mnt, to)) {
46017+ error = -EACCES;
46018+ goto out_drop_write;
46019+ }
46020+
46021 error = security_path_link(old_path.dentry, &new_path, new_dentry);
46022 if (error)
46023 goto out_drop_write;
46024 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
46025+ if (!error)
46026+ gr_handle_create(new_dentry, new_path.mnt);
46027 out_drop_write:
46028 mnt_drop_write(new_path.mnt);
46029 out_dput:
46030+ putname(to);
46031 dput(new_dentry);
46032 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
46033 path_put(&new_path);
46034@@ -3231,6 +3424,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
46035 if (new_dentry == trap)
46036 goto exit5;
46037
46038+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
46039+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
46040+ to);
46041+ if (error)
46042+ goto exit5;
46043+
46044 error = mnt_want_write(oldnd.path.mnt);
46045 if (error)
46046 goto exit5;
46047@@ -3240,6 +3439,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
46048 goto exit6;
46049 error = vfs_rename(old_dir->d_inode, old_dentry,
46050 new_dir->d_inode, new_dentry);
46051+ if (!error)
46052+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
46053+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
46054 exit6:
46055 mnt_drop_write(oldnd.path.mnt);
46056 exit5:
46057@@ -3265,6 +3467,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
46058
46059 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
46060 {
46061+ char tmpbuf[64];
46062+ const char *newlink;
46063 int len;
46064
46065 len = PTR_ERR(link);
46066@@ -3274,7 +3478,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
46067 len = strlen(link);
46068 if (len > (unsigned) buflen)
46069 len = buflen;
46070- if (copy_to_user(buffer, link, len))
46071+
46072+ if (len < sizeof(tmpbuf)) {
46073+ memcpy(tmpbuf, link, len);
46074+ newlink = tmpbuf;
46075+ } else
46076+ newlink = link;
46077+
46078+ if (copy_to_user(buffer, newlink, len))
46079 len = -EFAULT;
46080 out:
46081 return len;
46082diff --git a/fs/namespace.c b/fs/namespace.c
46083index e608199..9609cb9 100644
46084--- a/fs/namespace.c
46085+++ b/fs/namespace.c
46086@@ -1155,6 +1155,9 @@ static int do_umount(struct mount *mnt, int flags)
46087 if (!(sb->s_flags & MS_RDONLY))
46088 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
46089 up_write(&sb->s_umount);
46090+
46091+ gr_log_remount(mnt->mnt_devname, retval);
46092+
46093 return retval;
46094 }
46095
46096@@ -1174,6 +1177,9 @@ static int do_umount(struct mount *mnt, int flags)
46097 br_write_unlock(vfsmount_lock);
46098 up_write(&namespace_sem);
46099 release_mounts(&umount_list);
46100+
46101+ gr_log_unmount(mnt->mnt_devname, retval);
46102+
46103 return retval;
46104 }
46105
46106@@ -2175,6 +2181,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
46107 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
46108 MS_STRICTATIME);
46109
46110+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
46111+ retval = -EPERM;
46112+ goto dput_out;
46113+ }
46114+
46115+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
46116+ retval = -EPERM;
46117+ goto dput_out;
46118+ }
46119+
46120 if (flags & MS_REMOUNT)
46121 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
46122 data_page);
46123@@ -2189,6 +2205,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
46124 dev_name, data_page);
46125 dput_out:
46126 path_put(&path);
46127+
46128+ gr_log_mount(dev_name, dir_name, retval);
46129+
46130 return retval;
46131 }
46132
46133@@ -2470,6 +2489,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
46134 if (error)
46135 goto out2;
46136
46137+ if (gr_handle_chroot_pivot()) {
46138+ error = -EPERM;
46139+ goto out2;
46140+ }
46141+
46142 get_fs_root(current->fs, &root);
46143 error = lock_mount(&old);
46144 if (error)
46145diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
46146index f649fba..236bf92 100644
46147--- a/fs/nfs/inode.c
46148+++ b/fs/nfs/inode.c
46149@@ -151,7 +151,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
46150 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
46151 nfsi->attrtimeo_timestamp = jiffies;
46152
46153- memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
46154+ memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
46155 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
46156 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
46157 else
46158@@ -1003,16 +1003,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
46159 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
46160 }
46161
46162-static atomic_long_t nfs_attr_generation_counter;
46163+static atomic_long_unchecked_t nfs_attr_generation_counter;
46164
46165 static unsigned long nfs_read_attr_generation_counter(void)
46166 {
46167- return atomic_long_read(&nfs_attr_generation_counter);
46168+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
46169 }
46170
46171 unsigned long nfs_inc_attr_generation_counter(void)
46172 {
46173- return atomic_long_inc_return(&nfs_attr_generation_counter);
46174+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
46175 }
46176
46177 void nfs_fattr_init(struct nfs_fattr *fattr)
46178diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
46179index edf6d3e..bdd1da7 100644
46180--- a/fs/nfsd/vfs.c
46181+++ b/fs/nfsd/vfs.c
46182@@ -925,7 +925,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
46183 } else {
46184 oldfs = get_fs();
46185 set_fs(KERNEL_DS);
46186- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
46187+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
46188 set_fs(oldfs);
46189 }
46190
46191@@ -1029,7 +1029,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
46192
46193 /* Write the data. */
46194 oldfs = get_fs(); set_fs(KERNEL_DS);
46195- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
46196+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
46197 set_fs(oldfs);
46198 if (host_err < 0)
46199 goto out_nfserr;
46200@@ -1564,7 +1564,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
46201 */
46202
46203 oldfs = get_fs(); set_fs(KERNEL_DS);
46204- host_err = inode->i_op->readlink(dentry, buf, *lenp);
46205+ host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
46206 set_fs(oldfs);
46207
46208 if (host_err < 0)
46209diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
46210index 3568c8a..e0240d8 100644
46211--- a/fs/notify/fanotify/fanotify_user.c
46212+++ b/fs/notify/fanotify/fanotify_user.c
46213@@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
46214 goto out_close_fd;
46215
46216 ret = -EFAULT;
46217- if (copy_to_user(buf, &fanotify_event_metadata,
46218+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
46219+ copy_to_user(buf, &fanotify_event_metadata,
46220 fanotify_event_metadata.event_len))
46221 goto out_kill_access_response;
46222
46223diff --git a/fs/notify/notification.c b/fs/notify/notification.c
46224index ee18815..7aa5d01 100644
46225--- a/fs/notify/notification.c
46226+++ b/fs/notify/notification.c
46227@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
46228 * get set to 0 so it will never get 'freed'
46229 */
46230 static struct fsnotify_event *q_overflow_event;
46231-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46232+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46233
46234 /**
46235 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
46236@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46237 */
46238 u32 fsnotify_get_cookie(void)
46239 {
46240- return atomic_inc_return(&fsnotify_sync_cookie);
46241+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
46242 }
46243 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
46244
46245diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
46246index 99e3610..02c1068 100644
46247--- a/fs/ntfs/dir.c
46248+++ b/fs/ntfs/dir.c
46249@@ -1329,7 +1329,7 @@ find_next_index_buffer:
46250 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
46251 ~(s64)(ndir->itype.index.block_size - 1)));
46252 /* Bounds checks. */
46253- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
46254+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
46255 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
46256 "inode 0x%lx or driver bug.", vdir->i_ino);
46257 goto err_out;
46258diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
46259index c587e2d..3641eaa 100644
46260--- a/fs/ntfs/file.c
46261+++ b/fs/ntfs/file.c
46262@@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
46263 #endif /* NTFS_RW */
46264 };
46265
46266-const struct file_operations ntfs_empty_file_ops = {};
46267+const struct file_operations ntfs_empty_file_ops __read_only;
46268
46269-const struct inode_operations ntfs_empty_inode_ops = {};
46270+const struct inode_operations ntfs_empty_inode_ops __read_only;
46271diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
46272index 210c352..a174f83 100644
46273--- a/fs/ocfs2/localalloc.c
46274+++ b/fs/ocfs2/localalloc.c
46275@@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
46276 goto bail;
46277 }
46278
46279- atomic_inc(&osb->alloc_stats.moves);
46280+ atomic_inc_unchecked(&osb->alloc_stats.moves);
46281
46282 bail:
46283 if (handle)
46284diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
46285index d355e6e..578d905 100644
46286--- a/fs/ocfs2/ocfs2.h
46287+++ b/fs/ocfs2/ocfs2.h
46288@@ -235,11 +235,11 @@ enum ocfs2_vol_state
46289
46290 struct ocfs2_alloc_stats
46291 {
46292- atomic_t moves;
46293- atomic_t local_data;
46294- atomic_t bitmap_data;
46295- atomic_t bg_allocs;
46296- atomic_t bg_extends;
46297+ atomic_unchecked_t moves;
46298+ atomic_unchecked_t local_data;
46299+ atomic_unchecked_t bitmap_data;
46300+ atomic_unchecked_t bg_allocs;
46301+ atomic_unchecked_t bg_extends;
46302 };
46303
46304 enum ocfs2_local_alloc_state
46305diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
46306index ba5d97e..c77db25 100644
46307--- a/fs/ocfs2/suballoc.c
46308+++ b/fs/ocfs2/suballoc.c
46309@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
46310 mlog_errno(status);
46311 goto bail;
46312 }
46313- atomic_inc(&osb->alloc_stats.bg_extends);
46314+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
46315
46316 /* You should never ask for this much metadata */
46317 BUG_ON(bits_wanted >
46318@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
46319 mlog_errno(status);
46320 goto bail;
46321 }
46322- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46323+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46324
46325 *suballoc_loc = res.sr_bg_blkno;
46326 *suballoc_bit_start = res.sr_bit_offset;
46327@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
46328 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
46329 res->sr_bits);
46330
46331- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46332+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46333
46334 BUG_ON(res->sr_bits != 1);
46335
46336@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
46337 mlog_errno(status);
46338 goto bail;
46339 }
46340- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46341+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46342
46343 BUG_ON(res.sr_bits != 1);
46344
46345@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
46346 cluster_start,
46347 num_clusters);
46348 if (!status)
46349- atomic_inc(&osb->alloc_stats.local_data);
46350+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
46351 } else {
46352 if (min_clusters > (osb->bitmap_cpg - 1)) {
46353 /* The only paths asking for contiguousness
46354@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
46355 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
46356 res.sr_bg_blkno,
46357 res.sr_bit_offset);
46358- atomic_inc(&osb->alloc_stats.bitmap_data);
46359+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
46360 *num_clusters = res.sr_bits;
46361 }
46362 }
46363diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
46364index 604e12c..8426483 100644
46365--- a/fs/ocfs2/super.c
46366+++ b/fs/ocfs2/super.c
46367@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
46368 "%10s => GlobalAllocs: %d LocalAllocs: %d "
46369 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
46370 "Stats",
46371- atomic_read(&osb->alloc_stats.bitmap_data),
46372- atomic_read(&osb->alloc_stats.local_data),
46373- atomic_read(&osb->alloc_stats.bg_allocs),
46374- atomic_read(&osb->alloc_stats.moves),
46375- atomic_read(&osb->alloc_stats.bg_extends));
46376+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
46377+ atomic_read_unchecked(&osb->alloc_stats.local_data),
46378+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
46379+ atomic_read_unchecked(&osb->alloc_stats.moves),
46380+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
46381
46382 out += snprintf(buf + out, len - out,
46383 "%10s => State: %u Descriptor: %llu Size: %u bits "
46384@@ -2117,11 +2117,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
46385 spin_lock_init(&osb->osb_xattr_lock);
46386 ocfs2_init_steal_slots(osb);
46387
46388- atomic_set(&osb->alloc_stats.moves, 0);
46389- atomic_set(&osb->alloc_stats.local_data, 0);
46390- atomic_set(&osb->alloc_stats.bitmap_data, 0);
46391- atomic_set(&osb->alloc_stats.bg_allocs, 0);
46392- atomic_set(&osb->alloc_stats.bg_extends, 0);
46393+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
46394+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
46395+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
46396+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
46397+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
46398
46399 /* Copy the blockcheck stats from the superblock probe */
46400 osb->osb_ecc_stats = *stats;
46401diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
46402index 5d22872..523db20 100644
46403--- a/fs/ocfs2/symlink.c
46404+++ b/fs/ocfs2/symlink.c
46405@@ -142,7 +142,7 @@ bail:
46406
46407 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
46408 {
46409- char *link = nd_get_link(nd);
46410+ const char *link = nd_get_link(nd);
46411 if (!IS_ERR(link))
46412 kfree(link);
46413 }
46414diff --git a/fs/open.c b/fs/open.c
46415index 77becc0..aad7bd9 100644
46416--- a/fs/open.c
46417+++ b/fs/open.c
46418@@ -112,6 +112,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
46419 error = locks_verify_truncate(inode, NULL, length);
46420 if (!error)
46421 error = security_path_truncate(&path);
46422+
46423+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
46424+ error = -EACCES;
46425+
46426 if (!error)
46427 error = do_truncate(path.dentry, length, 0, NULL);
46428
46429@@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
46430 if (__mnt_is_readonly(path.mnt))
46431 res = -EROFS;
46432
46433+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
46434+ res = -EACCES;
46435+
46436 out_path_release:
46437 path_put(&path);
46438 out:
46439@@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
46440 if (error)
46441 goto dput_and_out;
46442
46443+ gr_log_chdir(path.dentry, path.mnt);
46444+
46445 set_fs_pwd(current->fs, &path);
46446
46447 dput_and_out:
46448@@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
46449 goto out_putf;
46450
46451 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
46452+
46453+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
46454+ error = -EPERM;
46455+
46456+ if (!error)
46457+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
46458+
46459 if (!error)
46460 set_fs_pwd(current->fs, &file->f_path);
46461 out_putf:
46462@@ -438,7 +454,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
46463 if (error)
46464 goto dput_and_out;
46465
46466+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
46467+ goto dput_and_out;
46468+
46469 set_fs_root(current->fs, &path);
46470+
46471+ gr_handle_chroot_chdir(&path);
46472+
46473 error = 0;
46474 dput_and_out:
46475 path_put(&path);
46476@@ -456,6 +478,16 @@ static int chmod_common(struct path *path, umode_t mode)
46477 if (error)
46478 return error;
46479 mutex_lock(&inode->i_mutex);
46480+
46481+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
46482+ error = -EACCES;
46483+ goto out_unlock;
46484+ }
46485+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
46486+ error = -EACCES;
46487+ goto out_unlock;
46488+ }
46489+
46490 error = security_path_chmod(path, mode);
46491 if (error)
46492 goto out_unlock;
46493@@ -506,6 +538,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
46494 int error;
46495 struct iattr newattrs;
46496
46497+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
46498+ return -EACCES;
46499+
46500 newattrs.ia_valid = ATTR_CTIME;
46501 if (user != (uid_t) -1) {
46502 newattrs.ia_valid |= ATTR_UID;
46503diff --git a/fs/pipe.c b/fs/pipe.c
46504index a932ced..6495412 100644
46505--- a/fs/pipe.c
46506+++ b/fs/pipe.c
46507@@ -420,9 +420,9 @@ redo:
46508 }
46509 if (bufs) /* More to do? */
46510 continue;
46511- if (!pipe->writers)
46512+ if (!atomic_read(&pipe->writers))
46513 break;
46514- if (!pipe->waiting_writers) {
46515+ if (!atomic_read(&pipe->waiting_writers)) {
46516 /* syscall merging: Usually we must not sleep
46517 * if O_NONBLOCK is set, or if we got some data.
46518 * But if a writer sleeps in kernel space, then
46519@@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
46520 mutex_lock(&inode->i_mutex);
46521 pipe = inode->i_pipe;
46522
46523- if (!pipe->readers) {
46524+ if (!atomic_read(&pipe->readers)) {
46525 send_sig(SIGPIPE, current, 0);
46526 ret = -EPIPE;
46527 goto out;
46528@@ -530,7 +530,7 @@ redo1:
46529 for (;;) {
46530 int bufs;
46531
46532- if (!pipe->readers) {
46533+ if (!atomic_read(&pipe->readers)) {
46534 send_sig(SIGPIPE, current, 0);
46535 if (!ret)
46536 ret = -EPIPE;
46537@@ -616,9 +616,9 @@ redo2:
46538 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
46539 do_wakeup = 0;
46540 }
46541- pipe->waiting_writers++;
46542+ atomic_inc(&pipe->waiting_writers);
46543 pipe_wait(pipe);
46544- pipe->waiting_writers--;
46545+ atomic_dec(&pipe->waiting_writers);
46546 }
46547 out:
46548 mutex_unlock(&inode->i_mutex);
46549@@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table *wait)
46550 mask = 0;
46551 if (filp->f_mode & FMODE_READ) {
46552 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
46553- if (!pipe->writers && filp->f_version != pipe->w_counter)
46554+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
46555 mask |= POLLHUP;
46556 }
46557
46558@@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table *wait)
46559 * Most Unices do not set POLLERR for FIFOs but on Linux they
46560 * behave exactly like pipes for poll().
46561 */
46562- if (!pipe->readers)
46563+ if (!atomic_read(&pipe->readers))
46564 mask |= POLLERR;
46565 }
46566
46567@@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int decr, int decw)
46568
46569 mutex_lock(&inode->i_mutex);
46570 pipe = inode->i_pipe;
46571- pipe->readers -= decr;
46572- pipe->writers -= decw;
46573+ atomic_sub(decr, &pipe->readers);
46574+ atomic_sub(decw, &pipe->writers);
46575
46576- if (!pipe->readers && !pipe->writers) {
46577+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
46578 free_pipe_info(inode);
46579 } else {
46580 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
46581@@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
46582
46583 if (inode->i_pipe) {
46584 ret = 0;
46585- inode->i_pipe->readers++;
46586+ atomic_inc(&inode->i_pipe->readers);
46587 }
46588
46589 mutex_unlock(&inode->i_mutex);
46590@@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
46591
46592 if (inode->i_pipe) {
46593 ret = 0;
46594- inode->i_pipe->writers++;
46595+ atomic_inc(&inode->i_pipe->writers);
46596 }
46597
46598 mutex_unlock(&inode->i_mutex);
46599@@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
46600 if (inode->i_pipe) {
46601 ret = 0;
46602 if (filp->f_mode & FMODE_READ)
46603- inode->i_pipe->readers++;
46604+ atomic_inc(&inode->i_pipe->readers);
46605 if (filp->f_mode & FMODE_WRITE)
46606- inode->i_pipe->writers++;
46607+ atomic_inc(&inode->i_pipe->writers);
46608 }
46609
46610 mutex_unlock(&inode->i_mutex);
46611@@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
46612 inode->i_pipe = NULL;
46613 }
46614
46615-static struct vfsmount *pipe_mnt __read_mostly;
46616+struct vfsmount *pipe_mnt __read_mostly;
46617
46618 /*
46619 * pipefs_dname() is called from d_path().
46620@@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(void)
46621 goto fail_iput;
46622 inode->i_pipe = pipe;
46623
46624- pipe->readers = pipe->writers = 1;
46625+ atomic_set(&pipe->readers, 1);
46626+ atomic_set(&pipe->writers, 1);
46627 inode->i_fop = &rdwr_pipefifo_fops;
46628
46629 /*
46630diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
46631index 15af622..0e9f4467 100644
46632--- a/fs/proc/Kconfig
46633+++ b/fs/proc/Kconfig
46634@@ -30,12 +30,12 @@ config PROC_FS
46635
46636 config PROC_KCORE
46637 bool "/proc/kcore support" if !ARM
46638- depends on PROC_FS && MMU
46639+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
46640
46641 config PROC_VMCORE
46642 bool "/proc/vmcore support"
46643- depends on PROC_FS && CRASH_DUMP
46644- default y
46645+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
46646+ default n
46647 help
46648 Exports the dump image of crashed kernel in ELF format.
46649
46650@@ -59,8 +59,8 @@ config PROC_SYSCTL
46651 limited in memory.
46652
46653 config PROC_PAGE_MONITOR
46654- default y
46655- depends on PROC_FS && MMU
46656+ default n
46657+ depends on PROC_FS && MMU && !GRKERNSEC
46658 bool "Enable /proc page monitoring" if EXPERT
46659 help
46660 Various /proc files exist to monitor process memory utilization:
46661diff --git a/fs/proc/array.c b/fs/proc/array.c
46662index c602b8d..a7de642 100644
46663--- a/fs/proc/array.c
46664+++ b/fs/proc/array.c
46665@@ -60,6 +60,7 @@
46666 #include <linux/tty.h>
46667 #include <linux/string.h>
46668 #include <linux/mman.h>
46669+#include <linux/grsecurity.h>
46670 #include <linux/proc_fs.h>
46671 #include <linux/ioport.h>
46672 #include <linux/uaccess.h>
46673@@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
46674 seq_putc(m, '\n');
46675 }
46676
46677+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
46678+static inline void task_pax(struct seq_file *m, struct task_struct *p)
46679+{
46680+ if (p->mm)
46681+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
46682+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
46683+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
46684+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
46685+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
46686+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
46687+ else
46688+ seq_printf(m, "PaX:\t-----\n");
46689+}
46690+#endif
46691+
46692 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
46693 struct pid *pid, struct task_struct *task)
46694 {
46695@@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
46696 task_cpus_allowed(m, task);
46697 cpuset_task_status_allowed(m, task);
46698 task_context_switch_counts(m, task);
46699+
46700+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
46701+ task_pax(m, task);
46702+#endif
46703+
46704+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
46705+ task_grsec_rbac(m, task);
46706+#endif
46707+
46708 return 0;
46709 }
46710
46711+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46712+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
46713+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
46714+ _mm->pax_flags & MF_PAX_SEGMEXEC))
46715+#endif
46716+
46717 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
46718 struct pid *pid, struct task_struct *task, int whole)
46719 {
46720@@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
46721 char tcomm[sizeof(task->comm)];
46722 unsigned long flags;
46723
46724+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46725+ if (current->exec_id != m->exec_id) {
46726+ gr_log_badprocpid("stat");
46727+ return 0;
46728+ }
46729+#endif
46730+
46731 state = *get_task_state(task);
46732 vsize = eip = esp = 0;
46733 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
46734@@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
46735 gtime = task->gtime;
46736 }
46737
46738+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46739+ if (PAX_RAND_FLAGS(mm)) {
46740+ eip = 0;
46741+ esp = 0;
46742+ wchan = 0;
46743+ }
46744+#endif
46745+#ifdef CONFIG_GRKERNSEC_HIDESYM
46746+ wchan = 0;
46747+ eip =0;
46748+ esp =0;
46749+#endif
46750+
46751 /* scale priority and nice values from timeslices to -20..20 */
46752 /* to make it look like a "normal" Unix priority/nice value */
46753 priority = task_prio(task);
46754@@ -489,9 +540,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
46755 vsize,
46756 mm ? get_mm_rss(mm) : 0,
46757 rsslim,
46758+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46759+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
46760+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
46761+ PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
46762+#else
46763 mm ? (permitted ? mm->start_code : 1) : 0,
46764 mm ? (permitted ? mm->end_code : 1) : 0,
46765 (permitted && mm) ? mm->start_stack : 0,
46766+#endif
46767 esp,
46768 eip,
46769 /* The signal information here is obsolete.
46770@@ -536,8 +593,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
46771 struct pid *pid, struct task_struct *task)
46772 {
46773 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
46774- struct mm_struct *mm = get_task_mm(task);
46775+ struct mm_struct *mm;
46776
46777+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46778+ if (current->exec_id != m->exec_id) {
46779+ gr_log_badprocpid("statm");
46780+ return 0;
46781+ }
46782+#endif
46783+ mm = get_task_mm(task);
46784 if (mm) {
46785 size = task_statm(mm, &shared, &text, &data, &resident);
46786 mmput(mm);
46787@@ -547,3 +611,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
46788
46789 return 0;
46790 }
46791+
46792+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
46793+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
46794+{
46795+ u32 curr_ip = 0;
46796+ unsigned long flags;
46797+
46798+ if (lock_task_sighand(task, &flags)) {
46799+ curr_ip = task->signal->curr_ip;
46800+ unlock_task_sighand(task, &flags);
46801+ }
46802+
46803+ return sprintf(buffer, "%pI4\n", &curr_ip);
46804+}
46805+#endif
46806diff --git a/fs/proc/base.c b/fs/proc/base.c
46807index d4548dd..d101f84 100644
46808--- a/fs/proc/base.c
46809+++ b/fs/proc/base.c
46810@@ -109,6 +109,14 @@ struct pid_entry {
46811 union proc_op op;
46812 };
46813
46814+struct getdents_callback {
46815+ struct linux_dirent __user * current_dir;
46816+ struct linux_dirent __user * previous;
46817+ struct file * file;
46818+ int count;
46819+ int error;
46820+};
46821+
46822 #define NOD(NAME, MODE, IOP, FOP, OP) { \
46823 .name = (NAME), \
46824 .len = sizeof(NAME) - 1, \
46825@@ -213,6 +221,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
46826 if (!mm->arg_end)
46827 goto out_mm; /* Shh! No looking before we're done */
46828
46829+ if (gr_acl_handle_procpidmem(task))
46830+ goto out_mm;
46831+
46832 len = mm->arg_end - mm->arg_start;
46833
46834 if (len > PAGE_SIZE)
46835@@ -240,12 +251,28 @@ out:
46836 return res;
46837 }
46838
46839+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46840+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
46841+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
46842+ _mm->pax_flags & MF_PAX_SEGMEXEC))
46843+#endif
46844+
46845 static int proc_pid_auxv(struct task_struct *task, char *buffer)
46846 {
46847 struct mm_struct *mm = mm_for_maps(task);
46848 int res = PTR_ERR(mm);
46849 if (mm && !IS_ERR(mm)) {
46850 unsigned int nwords = 0;
46851+
46852+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46853+ /* allow if we're currently ptracing this task */
46854+ if (PAX_RAND_FLAGS(mm) &&
46855+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
46856+ mmput(mm);
46857+ return 0;
46858+ }
46859+#endif
46860+
46861 do {
46862 nwords += 2;
46863 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
46864@@ -259,7 +286,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
46865 }
46866
46867
46868-#ifdef CONFIG_KALLSYMS
46869+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
46870 /*
46871 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
46872 * Returns the resolved symbol. If that fails, simply return the address.
46873@@ -298,7 +325,7 @@ static void unlock_trace(struct task_struct *task)
46874 mutex_unlock(&task->signal->cred_guard_mutex);
46875 }
46876
46877-#ifdef CONFIG_STACKTRACE
46878+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
46879
46880 #define MAX_STACK_TRACE_DEPTH 64
46881
46882@@ -489,7 +516,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
46883 return count;
46884 }
46885
46886-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
46887+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
46888 static int proc_pid_syscall(struct task_struct *task, char *buffer)
46889 {
46890 long nr;
46891@@ -518,7 +545,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
46892 /************************************************************************/
46893
46894 /* permission checks */
46895-static int proc_fd_access_allowed(struct inode *inode)
46896+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
46897 {
46898 struct task_struct *task;
46899 int allowed = 0;
46900@@ -528,7 +555,10 @@ static int proc_fd_access_allowed(struct inode *inode)
46901 */
46902 task = get_proc_task(inode);
46903 if (task) {
46904- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
46905+ if (log)
46906+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
46907+ else
46908+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
46909 put_task_struct(task);
46910 }
46911 return allowed;
46912@@ -566,10 +596,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
46913 struct task_struct *task,
46914 int hide_pid_min)
46915 {
46916+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
46917+ return false;
46918+
46919+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46920+ rcu_read_lock();
46921+ {
46922+ const struct cred *tmpcred = current_cred();
46923+ const struct cred *cred = __task_cred(task);
46924+
46925+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
46926+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
46927+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
46928+#endif
46929+ ) {
46930+ rcu_read_unlock();
46931+ return true;
46932+ }
46933+ }
46934+ rcu_read_unlock();
46935+
46936+ if (!pid->hide_pid)
46937+ return false;
46938+#endif
46939+
46940 if (pid->hide_pid < hide_pid_min)
46941 return true;
46942 if (in_group_p(pid->pid_gid))
46943 return true;
46944+
46945 return ptrace_may_access(task, PTRACE_MODE_READ);
46946 }
46947
46948@@ -587,7 +642,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
46949 put_task_struct(task);
46950
46951 if (!has_perms) {
46952+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46953+ {
46954+#else
46955 if (pid->hide_pid == 2) {
46956+#endif
46957 /*
46958 * Let's make getdents(), stat(), and open()
46959 * consistent with each other. If a process
46960@@ -702,6 +761,10 @@ static int mem_open(struct inode* inode, struct file* file)
46961 file->f_mode |= FMODE_UNSIGNED_OFFSET;
46962 file->private_data = mm;
46963
46964+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46965+ file->f_version = current->exec_id;
46966+#endif
46967+
46968 return 0;
46969 }
46970
46971@@ -713,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
46972 ssize_t copied;
46973 char *page;
46974
46975+#ifdef CONFIG_GRKERNSEC
46976+ if (write)
46977+ return -EPERM;
46978+#endif
46979+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46980+ if (file->f_version != current->exec_id) {
46981+ gr_log_badprocpid("mem");
46982+ return 0;
46983+ }
46984+#endif
46985+
46986 if (!mm)
46987 return 0;
46988
46989@@ -813,6 +887,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
46990 if (!task)
46991 goto out_no_task;
46992
46993+ if (gr_acl_handle_procpidmem(task))
46994+ goto out;
46995+
46996 ret = -ENOMEM;
46997 page = (char *)__get_free_page(GFP_TEMPORARY);
46998 if (!page)
46999@@ -1434,7 +1511,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
47000 path_put(&nd->path);
47001
47002 /* Are we allowed to snoop on the tasks file descriptors? */
47003- if (!proc_fd_access_allowed(inode))
47004+ if (!proc_fd_access_allowed(inode, 0))
47005 goto out;
47006
47007 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
47008@@ -1473,8 +1550,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
47009 struct path path;
47010
47011 /* Are we allowed to snoop on the tasks file descriptors? */
47012- if (!proc_fd_access_allowed(inode))
47013- goto out;
47014+ /* logging this is needed for learning on chromium to work properly,
47015+ but we don't want to flood the logs from 'ps' which does a readlink
47016+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
47017+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
47018+ */
47019+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
47020+ if (!proc_fd_access_allowed(inode,0))
47021+ goto out;
47022+ } else {
47023+ if (!proc_fd_access_allowed(inode,1))
47024+ goto out;
47025+ }
47026
47027 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
47028 if (error)
47029@@ -1539,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
47030 rcu_read_lock();
47031 cred = __task_cred(task);
47032 inode->i_uid = cred->euid;
47033+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47034+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47035+#else
47036 inode->i_gid = cred->egid;
47037+#endif
47038 rcu_read_unlock();
47039 }
47040 security_task_to_inode(task, inode);
47041@@ -1575,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
47042 return -ENOENT;
47043 }
47044 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
47045+#ifdef CONFIG_GRKERNSEC_PROC_USER
47046+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
47047+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47048+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
47049+#endif
47050 task_dumpable(task)) {
47051 cred = __task_cred(task);
47052 stat->uid = cred->euid;
47053+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47054+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
47055+#else
47056 stat->gid = cred->egid;
47057+#endif
47058 }
47059 }
47060 rcu_read_unlock();
47061@@ -1616,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
47062
47063 if (task) {
47064 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
47065+#ifdef CONFIG_GRKERNSEC_PROC_USER
47066+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
47067+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47068+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
47069+#endif
47070 task_dumpable(task)) {
47071 rcu_read_lock();
47072 cred = __task_cred(task);
47073 inode->i_uid = cred->euid;
47074+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47075+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47076+#else
47077 inode->i_gid = cred->egid;
47078+#endif
47079 rcu_read_unlock();
47080 } else {
47081 inode->i_uid = 0;
47082@@ -1738,7 +1847,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
47083 int fd = proc_fd(inode);
47084
47085 if (task) {
47086- files = get_files_struct(task);
47087+ if (!gr_acl_handle_procpidmem(task))
47088+ files = get_files_struct(task);
47089 put_task_struct(task);
47090 }
47091 if (files) {
47092@@ -2355,11 +2465,21 @@ static const struct file_operations proc_map_files_operations = {
47093 */
47094 static int proc_fd_permission(struct inode *inode, int mask)
47095 {
47096+ struct task_struct *task;
47097 int rv = generic_permission(inode, mask);
47098- if (rv == 0)
47099- return 0;
47100+
47101 if (task_pid(current) == proc_pid(inode))
47102 rv = 0;
47103+
47104+ task = get_proc_task(inode);
47105+ if (task == NULL)
47106+ return rv;
47107+
47108+ if (gr_acl_handle_procpidmem(task))
47109+ rv = -EACCES;
47110+
47111+ put_task_struct(task);
47112+
47113 return rv;
47114 }
47115
47116@@ -2469,6 +2589,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
47117 if (!task)
47118 goto out_no_task;
47119
47120+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47121+ goto out;
47122+
47123 /*
47124 * Yes, it does not scale. And it should not. Don't add
47125 * new entries into /proc/<tgid>/ without very good reasons.
47126@@ -2513,6 +2636,9 @@ static int proc_pident_readdir(struct file *filp,
47127 if (!task)
47128 goto out_no_task;
47129
47130+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47131+ goto out;
47132+
47133 ret = 0;
47134 i = filp->f_pos;
47135 switch (i) {
47136@@ -2783,7 +2909,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
47137 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
47138 void *cookie)
47139 {
47140- char *s = nd_get_link(nd);
47141+ const char *s = nd_get_link(nd);
47142 if (!IS_ERR(s))
47143 __putname(s);
47144 }
47145@@ -2984,7 +3110,7 @@ static const struct pid_entry tgid_base_stuff[] = {
47146 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
47147 #endif
47148 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
47149-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47150+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47151 INF("syscall", S_IRUGO, proc_pid_syscall),
47152 #endif
47153 INF("cmdline", S_IRUGO, proc_pid_cmdline),
47154@@ -3009,10 +3135,10 @@ static const struct pid_entry tgid_base_stuff[] = {
47155 #ifdef CONFIG_SECURITY
47156 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
47157 #endif
47158-#ifdef CONFIG_KALLSYMS
47159+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47160 INF("wchan", S_IRUGO, proc_pid_wchan),
47161 #endif
47162-#ifdef CONFIG_STACKTRACE
47163+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47164 ONE("stack", S_IRUGO, proc_pid_stack),
47165 #endif
47166 #ifdef CONFIG_SCHEDSTATS
47167@@ -3046,6 +3172,9 @@ static const struct pid_entry tgid_base_stuff[] = {
47168 #ifdef CONFIG_HARDWALL
47169 INF("hardwall", S_IRUGO, proc_pid_hardwall),
47170 #endif
47171+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47172+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
47173+#endif
47174 };
47175
47176 static int proc_tgid_base_readdir(struct file * filp,
47177@@ -3172,7 +3301,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
47178 if (!inode)
47179 goto out;
47180
47181+#ifdef CONFIG_GRKERNSEC_PROC_USER
47182+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
47183+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47184+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47185+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
47186+#else
47187 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
47188+#endif
47189 inode->i_op = &proc_tgid_base_inode_operations;
47190 inode->i_fop = &proc_tgid_base_operations;
47191 inode->i_flags|=S_IMMUTABLE;
47192@@ -3214,7 +3350,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
47193 if (!task)
47194 goto out;
47195
47196+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47197+ goto out_put_task;
47198+
47199 result = proc_pid_instantiate(dir, dentry, task, NULL);
47200+out_put_task:
47201 put_task_struct(task);
47202 out:
47203 return result;
47204@@ -3277,6 +3417,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
47205 static int fake_filldir(void *buf, const char *name, int namelen,
47206 loff_t offset, u64 ino, unsigned d_type)
47207 {
47208+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
47209+ __buf->error = -EINVAL;
47210 return 0;
47211 }
47212
47213@@ -3343,7 +3485,7 @@ static const struct pid_entry tid_base_stuff[] = {
47214 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
47215 #endif
47216 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
47217-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47218+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47219 INF("syscall", S_IRUGO, proc_pid_syscall),
47220 #endif
47221 INF("cmdline", S_IRUGO, proc_pid_cmdline),
47222@@ -3367,10 +3509,10 @@ static const struct pid_entry tid_base_stuff[] = {
47223 #ifdef CONFIG_SECURITY
47224 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
47225 #endif
47226-#ifdef CONFIG_KALLSYMS
47227+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47228 INF("wchan", S_IRUGO, proc_pid_wchan),
47229 #endif
47230-#ifdef CONFIG_STACKTRACE
47231+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47232 ONE("stack", S_IRUGO, proc_pid_stack),
47233 #endif
47234 #ifdef CONFIG_SCHEDSTATS
47235diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
47236index 82676e3..5f8518a 100644
47237--- a/fs/proc/cmdline.c
47238+++ b/fs/proc/cmdline.c
47239@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
47240
47241 static int __init proc_cmdline_init(void)
47242 {
47243+#ifdef CONFIG_GRKERNSEC_PROC_ADD
47244+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
47245+#else
47246 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
47247+#endif
47248 return 0;
47249 }
47250 module_init(proc_cmdline_init);
47251diff --git a/fs/proc/devices.c b/fs/proc/devices.c
47252index b143471..bb105e5 100644
47253--- a/fs/proc/devices.c
47254+++ b/fs/proc/devices.c
47255@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
47256
47257 static int __init proc_devices_init(void)
47258 {
47259+#ifdef CONFIG_GRKERNSEC_PROC_ADD
47260+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
47261+#else
47262 proc_create("devices", 0, NULL, &proc_devinfo_operations);
47263+#endif
47264 return 0;
47265 }
47266 module_init(proc_devices_init);
47267diff --git a/fs/proc/inode.c b/fs/proc/inode.c
47268index 84fd323..f698a32 100644
47269--- a/fs/proc/inode.c
47270+++ b/fs/proc/inode.c
47271@@ -21,12 +21,18 @@
47272 #include <linux/seq_file.h>
47273 #include <linux/slab.h>
47274 #include <linux/mount.h>
47275+#include <linux/grsecurity.h>
47276
47277 #include <asm/system.h>
47278 #include <asm/uaccess.h>
47279
47280 #include "internal.h"
47281
47282+#ifdef CONFIG_PROC_SYSCTL
47283+extern const struct inode_operations proc_sys_inode_operations;
47284+extern const struct inode_operations proc_sys_dir_operations;
47285+#endif
47286+
47287 static void proc_evict_inode(struct inode *inode)
47288 {
47289 struct proc_dir_entry *de;
47290@@ -52,6 +58,13 @@ static void proc_evict_inode(struct inode *inode)
47291 ns_ops = PROC_I(inode)->ns_ops;
47292 if (ns_ops && ns_ops->put)
47293 ns_ops->put(PROC_I(inode)->ns);
47294+
47295+#ifdef CONFIG_PROC_SYSCTL
47296+ if (inode->i_op == &proc_sys_inode_operations ||
47297+ inode->i_op == &proc_sys_dir_operations)
47298+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
47299+#endif
47300+
47301 }
47302
47303 static struct kmem_cache * proc_inode_cachep;
47304@@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
47305 if (de->mode) {
47306 inode->i_mode = de->mode;
47307 inode->i_uid = de->uid;
47308+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47309+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47310+#else
47311 inode->i_gid = de->gid;
47312+#endif
47313 }
47314 if (de->size)
47315 inode->i_size = de->size;
47316diff --git a/fs/proc/internal.h b/fs/proc/internal.h
47317index 2925775..4f08fae 100644
47318--- a/fs/proc/internal.h
47319+++ b/fs/proc/internal.h
47320@@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47321 struct pid *pid, struct task_struct *task);
47322 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47323 struct pid *pid, struct task_struct *task);
47324+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47325+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
47326+#endif
47327 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
47328
47329 extern const struct file_operations proc_maps_operations;
47330diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
47331index d245cb2..f4e8498 100644
47332--- a/fs/proc/kcore.c
47333+++ b/fs/proc/kcore.c
47334@@ -478,9 +478,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
47335 * the addresses in the elf_phdr on our list.
47336 */
47337 start = kc_offset_to_vaddr(*fpos - elf_buflen);
47338- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
47339+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
47340+ if (tsz > buflen)
47341 tsz = buflen;
47342-
47343+
47344 while (buflen) {
47345 struct kcore_list *m;
47346
47347@@ -509,20 +510,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
47348 kfree(elf_buf);
47349 } else {
47350 if (kern_addr_valid(start)) {
47351- unsigned long n;
47352+ char *elf_buf;
47353+ mm_segment_t oldfs;
47354
47355- n = copy_to_user(buffer, (char *)start, tsz);
47356- /*
47357- * We cannot distingush between fault on source
47358- * and fault on destination. When this happens
47359- * we clear too and hope it will trigger the
47360- * EFAULT again.
47361- */
47362- if (n) {
47363- if (clear_user(buffer + tsz - n,
47364- n))
47365+ elf_buf = kmalloc(tsz, GFP_KERNEL);
47366+ if (!elf_buf)
47367+ return -ENOMEM;
47368+ oldfs = get_fs();
47369+ set_fs(KERNEL_DS);
47370+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
47371+ set_fs(oldfs);
47372+ if (copy_to_user(buffer, elf_buf, tsz)) {
47373+ kfree(elf_buf);
47374 return -EFAULT;
47375+ }
47376 }
47377+ set_fs(oldfs);
47378+ kfree(elf_buf);
47379 } else {
47380 if (clear_user(buffer, tsz))
47381 return -EFAULT;
47382@@ -542,6 +546,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
47383
47384 static int open_kcore(struct inode *inode, struct file *filp)
47385 {
47386+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
47387+ return -EPERM;
47388+#endif
47389 if (!capable(CAP_SYS_RAWIO))
47390 return -EPERM;
47391 if (kcore_need_update)
47392diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
47393index 80e4645..53e5fcf 100644
47394--- a/fs/proc/meminfo.c
47395+++ b/fs/proc/meminfo.c
47396@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
47397 vmi.used >> 10,
47398 vmi.largest_chunk >> 10
47399 #ifdef CONFIG_MEMORY_FAILURE
47400- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
47401+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
47402 #endif
47403 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
47404 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
47405diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
47406index b1822dd..df622cb 100644
47407--- a/fs/proc/nommu.c
47408+++ b/fs/proc/nommu.c
47409@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
47410 if (len < 1)
47411 len = 1;
47412 seq_printf(m, "%*c", len, ' ');
47413- seq_path(m, &file->f_path, "");
47414+ seq_path(m, &file->f_path, "\n\\");
47415 }
47416
47417 seq_putc(m, '\n');
47418diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
47419index 06e1cc1..177cd98 100644
47420--- a/fs/proc/proc_net.c
47421+++ b/fs/proc/proc_net.c
47422@@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
47423 struct task_struct *task;
47424 struct nsproxy *ns;
47425 struct net *net = NULL;
47426+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47427+ const struct cred *cred = current_cred();
47428+#endif
47429+
47430+#ifdef CONFIG_GRKERNSEC_PROC_USER
47431+ if (cred->fsuid)
47432+ return net;
47433+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47434+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
47435+ return net;
47436+#endif
47437
47438 rcu_read_lock();
47439 task = pid_task(proc_pid(dir), PIDTYPE_PID);
47440diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
47441index 53c3bce..10ad159 100644
47442--- a/fs/proc/proc_sysctl.c
47443+++ b/fs/proc/proc_sysctl.c
47444@@ -9,11 +9,13 @@
47445 #include <linux/namei.h>
47446 #include "internal.h"
47447
47448+extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
47449+
47450 static const struct dentry_operations proc_sys_dentry_operations;
47451 static const struct file_operations proc_sys_file_operations;
47452-static const struct inode_operations proc_sys_inode_operations;
47453+const struct inode_operations proc_sys_inode_operations;
47454 static const struct file_operations proc_sys_dir_file_operations;
47455-static const struct inode_operations proc_sys_dir_operations;
47456+const struct inode_operations proc_sys_dir_operations;
47457
47458 void proc_sys_poll_notify(struct ctl_table_poll *poll)
47459 {
47460@@ -131,8 +133,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
47461
47462 err = NULL;
47463 d_set_d_op(dentry, &proc_sys_dentry_operations);
47464+
47465+ gr_handle_proc_create(dentry, inode);
47466+
47467 d_add(dentry, inode);
47468
47469+ if (gr_handle_sysctl(p, MAY_EXEC))
47470+ err = ERR_PTR(-ENOENT);
47471+
47472 out:
47473 sysctl_head_finish(head);
47474 return err;
47475@@ -163,6 +171,12 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
47476 if (!table->proc_handler)
47477 goto out;
47478
47479+#ifdef CONFIG_GRKERNSEC
47480+ error = -EPERM;
47481+ if (write && !capable(CAP_SYS_ADMIN))
47482+ goto out;
47483+#endif
47484+
47485 /* careful: calling conventions are nasty here */
47486 res = count;
47487 error = table->proc_handler(table, write, buf, &res, ppos);
47488@@ -260,6 +274,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
47489 return -ENOMEM;
47490 } else {
47491 d_set_d_op(child, &proc_sys_dentry_operations);
47492+
47493+ gr_handle_proc_create(child, inode);
47494+
47495 d_add(child, inode);
47496 }
47497 } else {
47498@@ -288,6 +305,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
47499 if (*pos < file->f_pos)
47500 continue;
47501
47502+ if (gr_handle_sysctl(table, 0))
47503+ continue;
47504+
47505 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
47506 if (res)
47507 return res;
47508@@ -413,6 +433,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
47509 if (IS_ERR(head))
47510 return PTR_ERR(head);
47511
47512+ if (table && gr_handle_sysctl(table, MAY_EXEC))
47513+ return -ENOENT;
47514+
47515 generic_fillattr(inode, stat);
47516 if (table)
47517 stat->mode = (stat->mode & S_IFMT) | table->mode;
47518@@ -435,13 +458,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
47519 .llseek = generic_file_llseek,
47520 };
47521
47522-static const struct inode_operations proc_sys_inode_operations = {
47523+const struct inode_operations proc_sys_inode_operations = {
47524 .permission = proc_sys_permission,
47525 .setattr = proc_sys_setattr,
47526 .getattr = proc_sys_getattr,
47527 };
47528
47529-static const struct inode_operations proc_sys_dir_operations = {
47530+const struct inode_operations proc_sys_dir_operations = {
47531 .lookup = proc_sys_lookup,
47532 .permission = proc_sys_permission,
47533 .setattr = proc_sys_setattr,
47534diff --git a/fs/proc/root.c b/fs/proc/root.c
47535index 46a15d8..335631a 100644
47536--- a/fs/proc/root.c
47537+++ b/fs/proc/root.c
47538@@ -187,7 +187,15 @@ void __init proc_root_init(void)
47539 #ifdef CONFIG_PROC_DEVICETREE
47540 proc_device_tree_init();
47541 #endif
47542+#ifdef CONFIG_GRKERNSEC_PROC_ADD
47543+#ifdef CONFIG_GRKERNSEC_PROC_USER
47544+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
47545+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47546+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47547+#endif
47548+#else
47549 proc_mkdir("bus", NULL);
47550+#endif
47551 proc_sys_init();
47552 }
47553
47554diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
47555index 3efa725..23c925b 100644
47556--- a/fs/proc/task_mmu.c
47557+++ b/fs/proc/task_mmu.c
47558@@ -11,6 +11,7 @@
47559 #include <linux/rmap.h>
47560 #include <linux/swap.h>
47561 #include <linux/swapops.h>
47562+#include <linux/grsecurity.h>
47563
47564 #include <asm/elf.h>
47565 #include <asm/uaccess.h>
47566@@ -52,8 +53,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
47567 "VmExe:\t%8lu kB\n"
47568 "VmLib:\t%8lu kB\n"
47569 "VmPTE:\t%8lu kB\n"
47570- "VmSwap:\t%8lu kB\n",
47571- hiwater_vm << (PAGE_SHIFT-10),
47572+ "VmSwap:\t%8lu kB\n"
47573+
47574+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
47575+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
47576+#endif
47577+
47578+ ,hiwater_vm << (PAGE_SHIFT-10),
47579 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
47580 mm->locked_vm << (PAGE_SHIFT-10),
47581 mm->pinned_vm << (PAGE_SHIFT-10),
47582@@ -62,7 +68,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
47583 data << (PAGE_SHIFT-10),
47584 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
47585 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
47586- swap << (PAGE_SHIFT-10));
47587+ swap << (PAGE_SHIFT-10)
47588+
47589+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
47590+ , mm->context.user_cs_base, mm->context.user_cs_limit
47591+#endif
47592+
47593+ );
47594 }
47595
47596 unsigned long task_vsize(struct mm_struct *mm)
47597@@ -209,6 +221,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
47598 return ret;
47599 }
47600
47601+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47602+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47603+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
47604+ _mm->pax_flags & MF_PAX_SEGMEXEC))
47605+#endif
47606+
47607 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
47608 {
47609 struct mm_struct *mm = vma->vm_mm;
47610@@ -227,13 +245,13 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
47611 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
47612 }
47613
47614- /* We don't show the stack guard page in /proc/maps */
47615+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47616+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
47617+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
47618+#else
47619 start = vma->vm_start;
47620- if (stack_guard_page_start(vma, start))
47621- start += PAGE_SIZE;
47622 end = vma->vm_end;
47623- if (stack_guard_page_end(vma, end))
47624- end -= PAGE_SIZE;
47625+#endif
47626
47627 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
47628 start,
47629@@ -242,7 +260,11 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
47630 flags & VM_WRITE ? 'w' : '-',
47631 flags & VM_EXEC ? 'x' : '-',
47632 flags & VM_MAYSHARE ? 's' : 'p',
47633+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47634+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
47635+#else
47636 pgoff,
47637+#endif
47638 MAJOR(dev), MINOR(dev), ino, &len);
47639
47640 /*
47641@@ -251,7 +273,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
47642 */
47643 if (file) {
47644 pad_len_spaces(m, len);
47645- seq_path(m, &file->f_path, "\n");
47646+ seq_path(m, &file->f_path, "\n\\");
47647 } else {
47648 const char *name = arch_vma_name(vma);
47649 if (!name) {
47650@@ -259,8 +281,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
47651 if (vma->vm_start <= mm->brk &&
47652 vma->vm_end >= mm->start_brk) {
47653 name = "[heap]";
47654- } else if (vma->vm_start <= mm->start_stack &&
47655- vma->vm_end >= mm->start_stack) {
47656+ } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
47657+ (vma->vm_start <= mm->start_stack &&
47658+ vma->vm_end >= mm->start_stack)) {
47659 name = "[stack]";
47660 }
47661 } else {
47662@@ -281,6 +304,13 @@ static int show_map(struct seq_file *m, void *v)
47663 struct proc_maps_private *priv = m->private;
47664 struct task_struct *task = priv->task;
47665
47666+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47667+ if (current->exec_id != m->exec_id) {
47668+ gr_log_badprocpid("maps");
47669+ return 0;
47670+ }
47671+#endif
47672+
47673 show_map_vma(m, vma);
47674
47675 if (m->count < m->size) /* vma is copied successfully */
47676@@ -437,12 +467,23 @@ static int show_smap(struct seq_file *m, void *v)
47677 .private = &mss,
47678 };
47679
47680+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47681+ if (current->exec_id != m->exec_id) {
47682+ gr_log_badprocpid("smaps");
47683+ return 0;
47684+ }
47685+#endif
47686 memset(&mss, 0, sizeof mss);
47687- mss.vma = vma;
47688- /* mmap_sem is held in m_start */
47689- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
47690- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
47691-
47692+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47693+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
47694+#endif
47695+ mss.vma = vma;
47696+ /* mmap_sem is held in m_start */
47697+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
47698+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
47699+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47700+ }
47701+#endif
47702 show_map_vma(m, vma);
47703
47704 seq_printf(m,
47705@@ -460,7 +501,11 @@ static int show_smap(struct seq_file *m, void *v)
47706 "KernelPageSize: %8lu kB\n"
47707 "MMUPageSize: %8lu kB\n"
47708 "Locked: %8lu kB\n",
47709+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47710+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
47711+#else
47712 (vma->vm_end - vma->vm_start) >> 10,
47713+#endif
47714 mss.resident >> 10,
47715 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
47716 mss.shared_clean >> 10,
47717@@ -1024,6 +1069,13 @@ static int show_numa_map(struct seq_file *m, void *v)
47718 int n;
47719 char buffer[50];
47720
47721+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47722+ if (current->exec_id != m->exec_id) {
47723+ gr_log_badprocpid("numa_maps");
47724+ return 0;
47725+ }
47726+#endif
47727+
47728 if (!mm)
47729 return 0;
47730
47731@@ -1041,11 +1093,15 @@ static int show_numa_map(struct seq_file *m, void *v)
47732 mpol_to_str(buffer, sizeof(buffer), pol, 0);
47733 mpol_cond_put(pol);
47734
47735+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47736+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
47737+#else
47738 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
47739+#endif
47740
47741 if (file) {
47742 seq_printf(m, " file=");
47743- seq_path(m, &file->f_path, "\n\t= ");
47744+ seq_path(m, &file->f_path, "\n\t\\= ");
47745 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
47746 seq_printf(m, " heap");
47747 } else if (vma->vm_start <= mm->start_stack &&
47748diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
47749index 980de54..2a4db5f 100644
47750--- a/fs/proc/task_nommu.c
47751+++ b/fs/proc/task_nommu.c
47752@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
47753 else
47754 bytes += kobjsize(mm);
47755
47756- if (current->fs && current->fs->users > 1)
47757+ if (current->fs && atomic_read(&current->fs->users) > 1)
47758 sbytes += kobjsize(current->fs);
47759 else
47760 bytes += kobjsize(current->fs);
47761@@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
47762
47763 if (file) {
47764 pad_len_spaces(m, len);
47765- seq_path(m, &file->f_path, "");
47766+ seq_path(m, &file->f_path, "\n\\");
47767 } else if (mm) {
47768 if (vma->vm_start <= mm->start_stack &&
47769 vma->vm_end >= mm->start_stack) {
47770diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
47771index d67908b..d13f6a6 100644
47772--- a/fs/quota/netlink.c
47773+++ b/fs/quota/netlink.c
47774@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
47775 void quota_send_warning(short type, unsigned int id, dev_t dev,
47776 const char warntype)
47777 {
47778- static atomic_t seq;
47779+ static atomic_unchecked_t seq;
47780 struct sk_buff *skb;
47781 void *msg_head;
47782 int ret;
47783@@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
47784 "VFS: Not enough memory to send quota warning.\n");
47785 return;
47786 }
47787- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
47788+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
47789 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
47790 if (!msg_head) {
47791 printk(KERN_ERR
47792diff --git a/fs/readdir.c b/fs/readdir.c
47793index 356f715..c918d38 100644
47794--- a/fs/readdir.c
47795+++ b/fs/readdir.c
47796@@ -17,6 +17,7 @@
47797 #include <linux/security.h>
47798 #include <linux/syscalls.h>
47799 #include <linux/unistd.h>
47800+#include <linux/namei.h>
47801
47802 #include <asm/uaccess.h>
47803
47804@@ -67,6 +68,7 @@ struct old_linux_dirent {
47805
47806 struct readdir_callback {
47807 struct old_linux_dirent __user * dirent;
47808+ struct file * file;
47809 int result;
47810 };
47811
47812@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
47813 buf->result = -EOVERFLOW;
47814 return -EOVERFLOW;
47815 }
47816+
47817+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47818+ return 0;
47819+
47820 buf->result++;
47821 dirent = buf->dirent;
47822 if (!access_ok(VERIFY_WRITE, dirent,
47823@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
47824
47825 buf.result = 0;
47826 buf.dirent = dirent;
47827+ buf.file = file;
47828
47829 error = vfs_readdir(file, fillonedir, &buf);
47830 if (buf.result)
47831@@ -142,6 +149,7 @@ struct linux_dirent {
47832 struct getdents_callback {
47833 struct linux_dirent __user * current_dir;
47834 struct linux_dirent __user * previous;
47835+ struct file * file;
47836 int count;
47837 int error;
47838 };
47839@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
47840 buf->error = -EOVERFLOW;
47841 return -EOVERFLOW;
47842 }
47843+
47844+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47845+ return 0;
47846+
47847 dirent = buf->previous;
47848 if (dirent) {
47849 if (__put_user(offset, &dirent->d_off))
47850@@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
47851 buf.previous = NULL;
47852 buf.count = count;
47853 buf.error = 0;
47854+ buf.file = file;
47855
47856 error = vfs_readdir(file, filldir, &buf);
47857 if (error >= 0)
47858@@ -229,6 +242,7 @@ out:
47859 struct getdents_callback64 {
47860 struct linux_dirent64 __user * current_dir;
47861 struct linux_dirent64 __user * previous;
47862+ struct file *file;
47863 int count;
47864 int error;
47865 };
47866@@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
47867 buf->error = -EINVAL; /* only used if we fail.. */
47868 if (reclen > buf->count)
47869 return -EINVAL;
47870+
47871+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47872+ return 0;
47873+
47874 dirent = buf->previous;
47875 if (dirent) {
47876 if (__put_user(offset, &dirent->d_off))
47877@@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
47878
47879 buf.current_dir = dirent;
47880 buf.previous = NULL;
47881+ buf.file = file;
47882 buf.count = count;
47883 buf.error = 0;
47884
47885@@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
47886 error = buf.error;
47887 lastdirent = buf.previous;
47888 if (lastdirent) {
47889- typeof(lastdirent->d_off) d_off = file->f_pos;
47890+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
47891 if (__put_user(d_off, &lastdirent->d_off))
47892 error = -EFAULT;
47893 else
47894diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
47895index 60c0804..d814f98 100644
47896--- a/fs/reiserfs/do_balan.c
47897+++ b/fs/reiserfs/do_balan.c
47898@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
47899 return;
47900 }
47901
47902- atomic_inc(&(fs_generation(tb->tb_sb)));
47903+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
47904 do_balance_starts(tb);
47905
47906 /* balance leaf returns 0 except if combining L R and S into
47907diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
47908index 7a99811..a7c96c4 100644
47909--- a/fs/reiserfs/procfs.c
47910+++ b/fs/reiserfs/procfs.c
47911@@ -113,7 +113,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
47912 "SMALL_TAILS " : "NO_TAILS ",
47913 replay_only(sb) ? "REPLAY_ONLY " : "",
47914 convert_reiserfs(sb) ? "CONV " : "",
47915- atomic_read(&r->s_generation_counter),
47916+ atomic_read_unchecked(&r->s_generation_counter),
47917 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
47918 SF(s_do_balance), SF(s_unneeded_left_neighbor),
47919 SF(s_good_search_by_key_reada), SF(s_bmaps),
47920diff --git a/fs/select.c b/fs/select.c
47921index e782258..3b4b44c 100644
47922--- a/fs/select.c
47923+++ b/fs/select.c
47924@@ -20,6 +20,7 @@
47925 #include <linux/module.h>
47926 #include <linux/slab.h>
47927 #include <linux/poll.h>
47928+#include <linux/security.h>
47929 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
47930 #include <linux/file.h>
47931 #include <linux/fdtable.h>
47932@@ -837,6 +838,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
47933 struct poll_list *walk = head;
47934 unsigned long todo = nfds;
47935
47936+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
47937 if (nfds > rlimit(RLIMIT_NOFILE))
47938 return -EINVAL;
47939
47940diff --git a/fs/seq_file.c b/fs/seq_file.c
47941index 4023d6b..53b39c5 100644
47942--- a/fs/seq_file.c
47943+++ b/fs/seq_file.c
47944@@ -9,6 +9,7 @@
47945 #include <linux/module.h>
47946 #include <linux/seq_file.h>
47947 #include <linux/slab.h>
47948+#include <linux/sched.h>
47949
47950 #include <asm/uaccess.h>
47951 #include <asm/page.h>
47952@@ -40,6 +41,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
47953 memset(p, 0, sizeof(*p));
47954 mutex_init(&p->lock);
47955 p->op = op;
47956+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47957+ p->exec_id = current->exec_id;
47958+#endif
47959
47960 /*
47961 * Wrappers around seq_open(e.g. swaps_open) need to be
47962@@ -76,7 +80,8 @@ static int traverse(struct seq_file *m, loff_t offset)
47963 return 0;
47964 }
47965 if (!m->buf) {
47966- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
47967+ m->size = PAGE_SIZE;
47968+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
47969 if (!m->buf)
47970 return -ENOMEM;
47971 }
47972@@ -116,7 +121,8 @@ static int traverse(struct seq_file *m, loff_t offset)
47973 Eoverflow:
47974 m->op->stop(m, p);
47975 kfree(m->buf);
47976- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
47977+ m->size <<= 1;
47978+ m->buf = kmalloc(m->size, GFP_KERNEL);
47979 return !m->buf ? -ENOMEM : -EAGAIN;
47980 }
47981
47982@@ -169,7 +175,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
47983 m->version = file->f_version;
47984 /* grab buffer if we didn't have one */
47985 if (!m->buf) {
47986- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
47987+ m->size = PAGE_SIZE;
47988+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
47989 if (!m->buf)
47990 goto Enomem;
47991 }
47992@@ -210,7 +217,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
47993 goto Fill;
47994 m->op->stop(m, p);
47995 kfree(m->buf);
47996- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
47997+ m->size <<= 1;
47998+ m->buf = kmalloc(m->size, GFP_KERNEL);
47999 if (!m->buf)
48000 goto Enomem;
48001 m->count = 0;
48002@@ -549,7 +557,7 @@ static void single_stop(struct seq_file *p, void *v)
48003 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
48004 void *data)
48005 {
48006- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
48007+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
48008 int res = -ENOMEM;
48009
48010 if (op) {
48011diff --git a/fs/splice.c b/fs/splice.c
48012index 1ec0493..d6ab5c2 100644
48013--- a/fs/splice.c
48014+++ b/fs/splice.c
48015@@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
48016 pipe_lock(pipe);
48017
48018 for (;;) {
48019- if (!pipe->readers) {
48020+ if (!atomic_read(&pipe->readers)) {
48021 send_sig(SIGPIPE, current, 0);
48022 if (!ret)
48023 ret = -EPIPE;
48024@@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
48025 do_wakeup = 0;
48026 }
48027
48028- pipe->waiting_writers++;
48029+ atomic_inc(&pipe->waiting_writers);
48030 pipe_wait(pipe);
48031- pipe->waiting_writers--;
48032+ atomic_dec(&pipe->waiting_writers);
48033 }
48034
48035 pipe_unlock(pipe);
48036@@ -559,7 +559,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
48037 old_fs = get_fs();
48038 set_fs(get_ds());
48039 /* The cast to a user pointer is valid due to the set_fs() */
48040- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
48041+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
48042 set_fs(old_fs);
48043
48044 return res;
48045@@ -574,7 +574,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
48046 old_fs = get_fs();
48047 set_fs(get_ds());
48048 /* The cast to a user pointer is valid due to the set_fs() */
48049- res = vfs_write(file, (const char __user *)buf, count, &pos);
48050+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
48051 set_fs(old_fs);
48052
48053 return res;
48054@@ -625,7 +625,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
48055 goto err;
48056
48057 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
48058- vec[i].iov_base = (void __user *) page_address(page);
48059+ vec[i].iov_base = (void __force_user *) page_address(page);
48060 vec[i].iov_len = this_len;
48061 spd.pages[i] = page;
48062 spd.nr_pages++;
48063@@ -845,10 +845,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
48064 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
48065 {
48066 while (!pipe->nrbufs) {
48067- if (!pipe->writers)
48068+ if (!atomic_read(&pipe->writers))
48069 return 0;
48070
48071- if (!pipe->waiting_writers && sd->num_spliced)
48072+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
48073 return 0;
48074
48075 if (sd->flags & SPLICE_F_NONBLOCK)
48076@@ -1181,7 +1181,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
48077 * out of the pipe right after the splice_to_pipe(). So set
48078 * PIPE_READERS appropriately.
48079 */
48080- pipe->readers = 1;
48081+ atomic_set(&pipe->readers, 1);
48082
48083 current->splice_pipe = pipe;
48084 }
48085@@ -1733,9 +1733,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48086 ret = -ERESTARTSYS;
48087 break;
48088 }
48089- if (!pipe->writers)
48090+ if (!atomic_read(&pipe->writers))
48091 break;
48092- if (!pipe->waiting_writers) {
48093+ if (!atomic_read(&pipe->waiting_writers)) {
48094 if (flags & SPLICE_F_NONBLOCK) {
48095 ret = -EAGAIN;
48096 break;
48097@@ -1767,7 +1767,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48098 pipe_lock(pipe);
48099
48100 while (pipe->nrbufs >= pipe->buffers) {
48101- if (!pipe->readers) {
48102+ if (!atomic_read(&pipe->readers)) {
48103 send_sig(SIGPIPE, current, 0);
48104 ret = -EPIPE;
48105 break;
48106@@ -1780,9 +1780,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48107 ret = -ERESTARTSYS;
48108 break;
48109 }
48110- pipe->waiting_writers++;
48111+ atomic_inc(&pipe->waiting_writers);
48112 pipe_wait(pipe);
48113- pipe->waiting_writers--;
48114+ atomic_dec(&pipe->waiting_writers);
48115 }
48116
48117 pipe_unlock(pipe);
48118@@ -1818,14 +1818,14 @@ retry:
48119 pipe_double_lock(ipipe, opipe);
48120
48121 do {
48122- if (!opipe->readers) {
48123+ if (!atomic_read(&opipe->readers)) {
48124 send_sig(SIGPIPE, current, 0);
48125 if (!ret)
48126 ret = -EPIPE;
48127 break;
48128 }
48129
48130- if (!ipipe->nrbufs && !ipipe->writers)
48131+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
48132 break;
48133
48134 /*
48135@@ -1922,7 +1922,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
48136 pipe_double_lock(ipipe, opipe);
48137
48138 do {
48139- if (!opipe->readers) {
48140+ if (!atomic_read(&opipe->readers)) {
48141 send_sig(SIGPIPE, current, 0);
48142 if (!ret)
48143 ret = -EPIPE;
48144@@ -1967,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
48145 * return EAGAIN if we have the potential of some data in the
48146 * future, otherwise just return 0
48147 */
48148- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
48149+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
48150 ret = -EAGAIN;
48151
48152 pipe_unlock(ipipe);
48153diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
48154index 7fdf6a7..e6cd8ad 100644
48155--- a/fs/sysfs/dir.c
48156+++ b/fs/sysfs/dir.c
48157@@ -642,6 +642,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
48158 struct sysfs_dirent *sd;
48159 int rc;
48160
48161+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
48162+ const char *parent_name = parent_sd->s_name;
48163+
48164+ mode = S_IFDIR | S_IRWXU;
48165+
48166+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
48167+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
48168+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
48169+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
48170+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
48171+#endif
48172+
48173 /* allocate */
48174 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
48175 if (!sd)
48176diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
48177index 00012e3..8392349 100644
48178--- a/fs/sysfs/file.c
48179+++ b/fs/sysfs/file.c
48180@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
48181
48182 struct sysfs_open_dirent {
48183 atomic_t refcnt;
48184- atomic_t event;
48185+ atomic_unchecked_t event;
48186 wait_queue_head_t poll;
48187 struct list_head buffers; /* goes through sysfs_buffer.list */
48188 };
48189@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
48190 if (!sysfs_get_active(attr_sd))
48191 return -ENODEV;
48192
48193- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
48194+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
48195 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
48196
48197 sysfs_put_active(attr_sd);
48198@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
48199 return -ENOMEM;
48200
48201 atomic_set(&new_od->refcnt, 0);
48202- atomic_set(&new_od->event, 1);
48203+ atomic_set_unchecked(&new_od->event, 1);
48204 init_waitqueue_head(&new_od->poll);
48205 INIT_LIST_HEAD(&new_od->buffers);
48206 goto retry;
48207@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
48208
48209 sysfs_put_active(attr_sd);
48210
48211- if (buffer->event != atomic_read(&od->event))
48212+ if (buffer->event != atomic_read_unchecked(&od->event))
48213 goto trigger;
48214
48215 return DEFAULT_POLLMASK;
48216@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
48217
48218 od = sd->s_attr.open;
48219 if (od) {
48220- atomic_inc(&od->event);
48221+ atomic_inc_unchecked(&od->event);
48222 wake_up_interruptible(&od->poll);
48223 }
48224
48225diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
48226index a7ac78f..02158e1 100644
48227--- a/fs/sysfs/symlink.c
48228+++ b/fs/sysfs/symlink.c
48229@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48230
48231 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
48232 {
48233- char *page = nd_get_link(nd);
48234+ const char *page = nd_get_link(nd);
48235 if (!IS_ERR(page))
48236 free_page((unsigned long)page);
48237 }
48238diff --git a/fs/udf/misc.c b/fs/udf/misc.c
48239index c175b4d..8f36a16 100644
48240--- a/fs/udf/misc.c
48241+++ b/fs/udf/misc.c
48242@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
48243
48244 u8 udf_tag_checksum(const struct tag *t)
48245 {
48246- u8 *data = (u8 *)t;
48247+ const u8 *data = (const u8 *)t;
48248 u8 checksum = 0;
48249 int i;
48250 for (i = 0; i < sizeof(struct tag); ++i)
48251diff --git a/fs/utimes.c b/fs/utimes.c
48252index ba653f3..06ea4b1 100644
48253--- a/fs/utimes.c
48254+++ b/fs/utimes.c
48255@@ -1,6 +1,7 @@
48256 #include <linux/compiler.h>
48257 #include <linux/file.h>
48258 #include <linux/fs.h>
48259+#include <linux/security.h>
48260 #include <linux/linkage.h>
48261 #include <linux/mount.h>
48262 #include <linux/namei.h>
48263@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
48264 goto mnt_drop_write_and_out;
48265 }
48266 }
48267+
48268+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
48269+ error = -EACCES;
48270+ goto mnt_drop_write_and_out;
48271+ }
48272+
48273 mutex_lock(&inode->i_mutex);
48274 error = notify_change(path->dentry, &newattrs);
48275 mutex_unlock(&inode->i_mutex);
48276diff --git a/fs/xattr.c b/fs/xattr.c
48277index 82f4337..236473c 100644
48278--- a/fs/xattr.c
48279+++ b/fs/xattr.c
48280@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
48281 * Extended attribute SET operations
48282 */
48283 static long
48284-setxattr(struct dentry *d, const char __user *name, const void __user *value,
48285+setxattr(struct path *path, const char __user *name, const void __user *value,
48286 size_t size, int flags)
48287 {
48288 int error;
48289@@ -339,7 +339,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
48290 return PTR_ERR(kvalue);
48291 }
48292
48293- error = vfs_setxattr(d, kname, kvalue, size, flags);
48294+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
48295+ error = -EACCES;
48296+ goto out;
48297+ }
48298+
48299+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
48300+out:
48301 kfree(kvalue);
48302 return error;
48303 }
48304@@ -356,7 +362,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
48305 return error;
48306 error = mnt_want_write(path.mnt);
48307 if (!error) {
48308- error = setxattr(path.dentry, name, value, size, flags);
48309+ error = setxattr(&path, name, value, size, flags);
48310 mnt_drop_write(path.mnt);
48311 }
48312 path_put(&path);
48313@@ -375,7 +381,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
48314 return error;
48315 error = mnt_want_write(path.mnt);
48316 if (!error) {
48317- error = setxattr(path.dentry, name, value, size, flags);
48318+ error = setxattr(&path, name, value, size, flags);
48319 mnt_drop_write(path.mnt);
48320 }
48321 path_put(&path);
48322@@ -386,17 +392,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
48323 const void __user *,value, size_t, size, int, flags)
48324 {
48325 struct file *f;
48326- struct dentry *dentry;
48327 int error = -EBADF;
48328
48329 f = fget(fd);
48330 if (!f)
48331 return error;
48332- dentry = f->f_path.dentry;
48333- audit_inode(NULL, dentry);
48334+ audit_inode(NULL, f->f_path.dentry);
48335 error = mnt_want_write_file(f);
48336 if (!error) {
48337- error = setxattr(dentry, name, value, size, flags);
48338+ error = setxattr(&f->f_path, name, value, size, flags);
48339 mnt_drop_write_file(f);
48340 }
48341 fput(f);
48342diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
48343index 8d5a506..7f62712 100644
48344--- a/fs/xattr_acl.c
48345+++ b/fs/xattr_acl.c
48346@@ -17,8 +17,8 @@
48347 struct posix_acl *
48348 posix_acl_from_xattr(const void *value, size_t size)
48349 {
48350- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
48351- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
48352+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
48353+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
48354 int count;
48355 struct posix_acl *acl;
48356 struct posix_acl_entry *acl_e;
48357diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
48358index 188ef2f..adcf864 100644
48359--- a/fs/xfs/xfs_bmap.c
48360+++ b/fs/xfs/xfs_bmap.c
48361@@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
48362 int nmap,
48363 int ret_nmap);
48364 #else
48365-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
48366+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
48367 #endif /* DEBUG */
48368
48369 STATIC int
48370diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
48371index 79d05e8..e3e5861 100644
48372--- a/fs/xfs/xfs_dir2_sf.c
48373+++ b/fs/xfs/xfs_dir2_sf.c
48374@@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
48375 }
48376
48377 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
48378- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
48379+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
48380+ char name[sfep->namelen];
48381+ memcpy(name, sfep->name, sfep->namelen);
48382+ if (filldir(dirent, name, sfep->namelen,
48383+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
48384+ *offset = off & 0x7fffffff;
48385+ return 0;
48386+ }
48387+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
48388 off & 0x7fffffff, ino, DT_UNKNOWN)) {
48389 *offset = off & 0x7fffffff;
48390 return 0;
48391diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
48392index 76f3ca5..f57f712 100644
48393--- a/fs/xfs/xfs_ioctl.c
48394+++ b/fs/xfs/xfs_ioctl.c
48395@@ -128,7 +128,7 @@ xfs_find_handle(
48396 }
48397
48398 error = -EFAULT;
48399- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
48400+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
48401 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
48402 goto out_put;
48403
48404diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
48405index ab30253..4d86958 100644
48406--- a/fs/xfs/xfs_iops.c
48407+++ b/fs/xfs/xfs_iops.c
48408@@ -447,7 +447,7 @@ xfs_vn_put_link(
48409 struct nameidata *nd,
48410 void *p)
48411 {
48412- char *s = nd_get_link(nd);
48413+ const char *s = nd_get_link(nd);
48414
48415 if (!IS_ERR(s))
48416 kfree(s);
48417diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
48418new file mode 100644
48419index 0000000..4089e05
48420--- /dev/null
48421+++ b/grsecurity/Kconfig
48422@@ -0,0 +1,1078 @@
48423+#
48424+# grecurity configuration
48425+#
48426+
48427+menu "Grsecurity"
48428+
48429+config GRKERNSEC
48430+ bool "Grsecurity"
48431+ select CRYPTO
48432+ select CRYPTO_SHA256
48433+ help
48434+ If you say Y here, you will be able to configure many features
48435+ that will enhance the security of your system. It is highly
48436+ recommended that you say Y here and read through the help
48437+ for each option so that you fully understand the features and
48438+ can evaluate their usefulness for your machine.
48439+
48440+choice
48441+ prompt "Security Level"
48442+ depends on GRKERNSEC
48443+ default GRKERNSEC_CUSTOM
48444+
48445+config GRKERNSEC_LOW
48446+ bool "Low"
48447+ select GRKERNSEC_LINK
48448+ select GRKERNSEC_FIFO
48449+ select GRKERNSEC_RANDNET
48450+ select GRKERNSEC_DMESG
48451+ select GRKERNSEC_CHROOT
48452+ select GRKERNSEC_CHROOT_CHDIR
48453+
48454+ help
48455+ If you choose this option, several of the grsecurity options will
48456+ be enabled that will give you greater protection against a number
48457+ of attacks, while assuring that none of your software will have any
48458+ conflicts with the additional security measures. If you run a lot
48459+ of unusual software, or you are having problems with the higher
48460+ security levels, you should say Y here. With this option, the
48461+ following features are enabled:
48462+
48463+ - Linking restrictions
48464+ - FIFO restrictions
48465+ - Restricted dmesg
48466+ - Enforced chdir("/") on chroot
48467+ - Runtime module disabling
48468+
48469+config GRKERNSEC_MEDIUM
48470+ bool "Medium"
48471+ select PAX
48472+ select PAX_EI_PAX
48473+ select PAX_PT_PAX_FLAGS
48474+ select PAX_HAVE_ACL_FLAGS
48475+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
48476+ select GRKERNSEC_CHROOT
48477+ select GRKERNSEC_CHROOT_SYSCTL
48478+ select GRKERNSEC_LINK
48479+ select GRKERNSEC_FIFO
48480+ select GRKERNSEC_DMESG
48481+ select GRKERNSEC_RANDNET
48482+ select GRKERNSEC_FORKFAIL
48483+ select GRKERNSEC_TIME
48484+ select GRKERNSEC_SIGNAL
48485+ select GRKERNSEC_CHROOT
48486+ select GRKERNSEC_CHROOT_UNIX
48487+ select GRKERNSEC_CHROOT_MOUNT
48488+ select GRKERNSEC_CHROOT_PIVOT
48489+ select GRKERNSEC_CHROOT_DOUBLE
48490+ select GRKERNSEC_CHROOT_CHDIR
48491+ select GRKERNSEC_CHROOT_MKNOD
48492+ select GRKERNSEC_PROC
48493+ select GRKERNSEC_PROC_USERGROUP
48494+ select PAX_RANDUSTACK
48495+ select PAX_ASLR
48496+ select PAX_RANDMMAP
48497+ select PAX_REFCOUNT if (X86 || SPARC64)
48498+ select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
48499+
48500+ help
48501+ If you say Y here, several features in addition to those included
48502+ in the low additional security level will be enabled. These
48503+ features provide even more security to your system, though in rare
48504+ cases they may be incompatible with very old or poorly written
48505+ software. If you enable this option, make sure that your auth
48506+ service (identd) is running as gid 1001. With this option,
48507+ the following features (in addition to those provided in the
48508+ low additional security level) will be enabled:
48509+
48510+ - Failed fork logging
48511+ - Time change logging
48512+ - Signal logging
48513+ - Deny mounts in chroot
48514+ - Deny double chrooting
48515+ - Deny sysctl writes in chroot
48516+ - Deny mknod in chroot
48517+ - Deny access to abstract AF_UNIX sockets out of chroot
48518+ - Deny pivot_root in chroot
48519+ - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
48520+ - /proc restrictions with special GID set to 10 (usually wheel)
48521+ - Address Space Layout Randomization (ASLR)
48522+ - Prevent exploitation of most refcount overflows
48523+ - Bounds checking of copying between the kernel and userland
48524+
48525+config GRKERNSEC_HIGH
48526+ bool "High"
48527+ select GRKERNSEC_LINK
48528+ select GRKERNSEC_FIFO
48529+ select GRKERNSEC_DMESG
48530+ select GRKERNSEC_FORKFAIL
48531+ select GRKERNSEC_TIME
48532+ select GRKERNSEC_SIGNAL
48533+ select GRKERNSEC_CHROOT
48534+ select GRKERNSEC_CHROOT_SHMAT
48535+ select GRKERNSEC_CHROOT_UNIX
48536+ select GRKERNSEC_CHROOT_MOUNT
48537+ select GRKERNSEC_CHROOT_FCHDIR
48538+ select GRKERNSEC_CHROOT_PIVOT
48539+ select GRKERNSEC_CHROOT_DOUBLE
48540+ select GRKERNSEC_CHROOT_CHDIR
48541+ select GRKERNSEC_CHROOT_MKNOD
48542+ select GRKERNSEC_CHROOT_CAPS
48543+ select GRKERNSEC_CHROOT_SYSCTL
48544+ select GRKERNSEC_CHROOT_FINDTASK
48545+ select GRKERNSEC_SYSFS_RESTRICT
48546+ select GRKERNSEC_PROC
48547+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
48548+ select GRKERNSEC_HIDESYM
48549+ select GRKERNSEC_BRUTE
48550+ select GRKERNSEC_PROC_USERGROUP
48551+ select GRKERNSEC_KMEM
48552+ select GRKERNSEC_RESLOG
48553+ select GRKERNSEC_RANDNET
48554+ select GRKERNSEC_PROC_ADD
48555+ select GRKERNSEC_CHROOT_CHMOD
48556+ select GRKERNSEC_CHROOT_NICE
48557+ select GRKERNSEC_SETXID
48558+ select GRKERNSEC_AUDIT_MOUNT
48559+ select GRKERNSEC_MODHARDEN if (MODULES)
48560+ select GRKERNSEC_HARDEN_PTRACE
48561+ select GRKERNSEC_PTRACE_READEXEC
48562+ select GRKERNSEC_VM86 if (X86_32)
48563+ select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
48564+ select PAX
48565+ select PAX_RANDUSTACK
48566+ select PAX_ASLR
48567+ select PAX_RANDMMAP
48568+ select PAX_NOEXEC
48569+ select PAX_MPROTECT
48570+ select PAX_EI_PAX
48571+ select PAX_PT_PAX_FLAGS
48572+ select PAX_HAVE_ACL_FLAGS
48573+ select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
48574+ select PAX_MEMORY_UDEREF if (X86 && !XEN)
48575+ select PAX_RANDKSTACK if (X86_TSC && X86)
48576+ select PAX_SEGMEXEC if (X86_32)
48577+ select PAX_PAGEEXEC
48578+ select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
48579+ select PAX_EMUTRAMP if (PARISC)
48580+ select PAX_EMUSIGRT if (PARISC)
48581+ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
48582+ select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
48583+ select PAX_REFCOUNT if (X86 || SPARC64)
48584+ select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
48585+ help
48586+ If you say Y here, many of the features of grsecurity will be
48587+ enabled, which will protect you against many kinds of attacks
48588+ against your system. The heightened security comes at a cost
48589+ of an increased chance of incompatibilities with rare software
48590+ on your machine. Since this security level enables PaX, you should
48591+ view <http://pax.grsecurity.net> and read about the PaX
48592+ project. While you are there, download chpax and run it on
48593+ binaries that cause problems with PaX. Also remember that
48594+ since the /proc restrictions are enabled, you must run your
48595+ identd as gid 1001. This security level enables the following
48596+ features in addition to those listed in the low and medium
48597+ security levels:
48598+
48599+ - Additional /proc restrictions
48600+ - Chmod restrictions in chroot
48601+ - No signals, ptrace, or viewing of processes outside of chroot
48602+ - Capability restrictions in chroot
48603+ - Deny fchdir out of chroot
48604+ - Priority restrictions in chroot
48605+ - Segmentation-based implementation of PaX
48606+ - Mprotect restrictions
48607+ - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
48608+ - Kernel stack randomization
48609+ - Mount/unmount/remount logging
48610+ - Kernel symbol hiding
48611+ - Hardening of module auto-loading
48612+ - Ptrace restrictions
48613+ - Restricted vm86 mode
48614+ - Restricted sysfs/debugfs
48615+ - Active kernel exploit response
48616+
48617+config GRKERNSEC_CUSTOM
48618+ bool "Custom"
48619+ help
48620+ If you say Y here, you will be able to configure every grsecurity
48621+ option, which allows you to enable many more features that aren't
48622+ covered in the basic security levels. These additional features
48623+ include TPE, socket restrictions, and the sysctl system for
48624+ grsecurity. It is advised that you read through the help for
48625+ each option to determine its usefulness in your situation.
48626+
48627+endchoice
48628+
48629+menu "Memory Protections"
48630+depends on GRKERNSEC
48631+
48632+config GRKERNSEC_KMEM
48633+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
48634+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
48635+ help
48636+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
48637+ be written to or read from to modify or leak the contents of the running
48638+ kernel. /dev/port will also not be allowed to be opened. If you have module
48639+ support disabled, enabling this will close up four ways that are
48640+ currently used to insert malicious code into the running kernel.
48641+ Even with all these features enabled, we still highly recommend that
48642+ you use the RBAC system, as it is still possible for an attacker to
48643+ modify the running kernel through privileged I/O granted by ioperm/iopl.
48644+ If you are not using XFree86, you may be able to stop this additional
48645+ case by enabling the 'Disable privileged I/O' option. Though nothing
48646+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
48647+ but only to video memory, which is the only writing we allow in this
48648+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
48649+ not be allowed to mprotect it with PROT_WRITE later.
48650+ It is highly recommended that you say Y here if you meet all the
48651+ conditions above.
48652+
48653+config GRKERNSEC_VM86
48654+ bool "Restrict VM86 mode"
48655+ depends on X86_32
48656+
48657+ help
48658+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
48659+ make use of a special execution mode on 32bit x86 processors called
48660+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
48661+ video cards and will still work with this option enabled. The purpose
48662+ of the option is to prevent exploitation of emulation errors in
48663+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
48664+ Nearly all users should be able to enable this option.
48665+
48666+config GRKERNSEC_IO
48667+ bool "Disable privileged I/O"
48668+ depends on X86
48669+ select RTC_CLASS
48670+ select RTC_INTF_DEV
48671+ select RTC_DRV_CMOS
48672+
48673+ help
48674+ If you say Y here, all ioperm and iopl calls will return an error.
48675+ Ioperm and iopl can be used to modify the running kernel.
48676+ Unfortunately, some programs need this access to operate properly,
48677+ the most notable of which are XFree86 and hwclock. hwclock can be
48678+ remedied by having RTC support in the kernel, so real-time
48679+ clock support is enabled if this option is enabled, to ensure
48680+ that hwclock operates correctly. XFree86 still will not
48681+ operate correctly with this option enabled, so DO NOT CHOOSE Y
48682+ IF YOU USE XFree86. If you use XFree86 and you still want to
48683+ protect your kernel against modification, use the RBAC system.
48684+
48685+config GRKERNSEC_PROC_MEMMAP
48686+ bool "Harden ASLR against information leaks and entropy reduction"
48687+ default y if (PAX_NOEXEC || PAX_ASLR)
48688+ depends on PAX_NOEXEC || PAX_ASLR
48689+ help
48690+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
48691+ give no information about the addresses of its mappings if
48692+ PaX features that rely on random addresses are enabled on the task.
48693+ In addition to sanitizing this information and disabling other
48694+ dangerous sources of information, this option causes reads of sensitive
48695+ /proc/<pid> entries where the file descriptor was opened in a different
48696+ task than the one performing the read. Such attempts are logged.
48697+ This option also limits argv/env strings for suid/sgid binaries
48698+ to 512KB to prevent a complete exhaustion of the stack entropy provided
48699+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
48700+ binaries to prevent alternative mmap layouts from being abused.
48701+
48702+ If you use PaX it is essential that you say Y here as it closes up
48703+ several holes that make full ASLR useless locally.
48704+
48705+config GRKERNSEC_BRUTE
48706+ bool "Deter exploit bruteforcing"
48707+ help
48708+ If you say Y here, attempts to bruteforce exploits against forking
48709+ daemons such as apache or sshd, as well as against suid/sgid binaries
48710+ will be deterred. When a child of a forking daemon is killed by PaX
48711+ or crashes due to an illegal instruction or other suspicious signal,
48712+ the parent process will be delayed 30 seconds upon every subsequent
48713+ fork until the administrator is able to assess the situation and
48714+ restart the daemon.
48715+ In the suid/sgid case, the attempt is logged, the user has all their
48716+ processes terminated, and they are prevented from executing any further
48717+ processes for 15 minutes.
48718+ It is recommended that you also enable signal logging in the auditing
48719+ section so that logs are generated when a process triggers a suspicious
48720+ signal.
48721+ If the sysctl option is enabled, a sysctl option with name
48722+ "deter_bruteforce" is created.
48723+
48724+
48725+config GRKERNSEC_MODHARDEN
48726+ bool "Harden module auto-loading"
48727+ depends on MODULES
48728+ help
48729+ If you say Y here, module auto-loading in response to use of some
48730+ feature implemented by an unloaded module will be restricted to
48731+ root users. Enabling this option helps defend against attacks
48732+ by unprivileged users who abuse the auto-loading behavior to
48733+ cause a vulnerable module to load that is then exploited.
48734+
48735+ If this option prevents a legitimate use of auto-loading for a
48736+ non-root user, the administrator can execute modprobe manually
48737+ with the exact name of the module mentioned in the alert log.
48738+ Alternatively, the administrator can add the module to the list
48739+ of modules loaded at boot by modifying init scripts.
48740+
48741+ Modification of init scripts will most likely be needed on
48742+ Ubuntu servers with encrypted home directory support enabled,
48743+ as the first non-root user logging in will cause the ecb(aes),
48744+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
48745+
48746+config GRKERNSEC_HIDESYM
48747+ bool "Hide kernel symbols"
48748+ help
48749+ If you say Y here, getting information on loaded modules, and
48750+ displaying all kernel symbols through a syscall will be restricted
48751+ to users with CAP_SYS_MODULE. For software compatibility reasons,
48752+ /proc/kallsyms will be restricted to the root user. The RBAC
48753+ system can hide that entry even from root.
48754+
48755+ This option also prevents leaking of kernel addresses through
48756+ several /proc entries.
48757+
48758+ Note that this option is only effective provided the following
48759+ conditions are met:
48760+ 1) The kernel using grsecurity is not precompiled by some distribution
48761+ 2) You have also enabled GRKERNSEC_DMESG
48762+ 3) You are using the RBAC system and hiding other files such as your
48763+ kernel image and System.map. Alternatively, enabling this option
48764+ causes the permissions on /boot, /lib/modules, and the kernel
48765+ source directory to change at compile time to prevent
48766+ reading by non-root users.
48767+ If the above conditions are met, this option will aid in providing a
48768+ useful protection against local kernel exploitation of overflows
48769+ and arbitrary read/write vulnerabilities.
48770+
48771+config GRKERNSEC_KERN_LOCKOUT
48772+ bool "Active kernel exploit response"
48773+ depends on X86 || ARM || PPC || SPARC
48774+ help
48775+ If you say Y here, when a PaX alert is triggered due to suspicious
48776+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
48777+ or an OOPs occurs due to bad memory accesses, instead of just
48778+ terminating the offending process (and potentially allowing
48779+ a subsequent exploit from the same user), we will take one of two
48780+ actions:
48781+ If the user was root, we will panic the system
48782+ If the user was non-root, we will log the attempt, terminate
48783+ all processes owned by the user, then prevent them from creating
48784+ any new processes until the system is restarted
48785+ This deters repeated kernel exploitation/bruteforcing attempts
48786+ and is useful for later forensics.
48787+
48788+endmenu
48789+menu "Role Based Access Control Options"
48790+depends on GRKERNSEC
48791+
48792+config GRKERNSEC_RBAC_DEBUG
48793+ bool
48794+
48795+config GRKERNSEC_NO_RBAC
48796+ bool "Disable RBAC system"
48797+ help
48798+ If you say Y here, the /dev/grsec device will be removed from the kernel,
48799+ preventing the RBAC system from being enabled. You should only say Y
48800+ here if you have no intention of using the RBAC system, so as to prevent
48801+ an attacker with root access from misusing the RBAC system to hide files
48802+ and processes when loadable module support and /dev/[k]mem have been
48803+ locked down.
48804+
48805+config GRKERNSEC_ACL_HIDEKERN
48806+ bool "Hide kernel processes"
48807+ help
48808+ If you say Y here, all kernel threads will be hidden to all
48809+ processes but those whose subject has the "view hidden processes"
48810+ flag.
48811+
48812+config GRKERNSEC_ACL_MAXTRIES
48813+ int "Maximum tries before password lockout"
48814+ default 3
48815+ help
48816+ This option enforces the maximum number of times a user can attempt
48817+ to authorize themselves with the grsecurity RBAC system before being
48818+ denied the ability to attempt authorization again for a specified time.
48819+ The lower the number, the harder it will be to brute-force a password.
48820+
48821+config GRKERNSEC_ACL_TIMEOUT
48822+ int "Time to wait after max password tries, in seconds"
48823+ default 30
48824+ help
48825+ This option specifies the time the user must wait after attempting to
48826+ authorize to the RBAC system with the maximum number of invalid
48827+ passwords. The higher the number, the harder it will be to brute-force
48828+ a password.
48829+
48830+endmenu
48831+menu "Filesystem Protections"
48832+depends on GRKERNSEC
48833+
48834+config GRKERNSEC_PROC
48835+ bool "Proc restrictions"
48836+ help
48837+ If you say Y here, the permissions of the /proc filesystem
48838+ will be altered to enhance system security and privacy. You MUST
48839+ choose either a user only restriction or a user and group restriction.
48840+ Depending upon the option you choose, you can either restrict users to
48841+ see only the processes they themselves run, or choose a group that can
48842+ view all processes and files normally restricted to root if you choose
48843+ the "restrict to user only" option. NOTE: If you're running identd or
48844+ ntpd as a non-root user, you will have to run it as the group you
48845+ specify here.
48846+
48847+config GRKERNSEC_PROC_USER
48848+ bool "Restrict /proc to user only"
48849+ depends on GRKERNSEC_PROC
48850+ help
48851+ If you say Y here, non-root users will only be able to view their own
48852+ processes, and restricts them from viewing network-related information,
48853+ and viewing kernel symbol and module information.
48854+
48855+config GRKERNSEC_PROC_USERGROUP
48856+ bool "Allow special group"
48857+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
48858+ help
48859+ If you say Y here, you will be able to select a group that will be
48860+ able to view all processes and network-related information. If you've
48861+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
48862+ remain hidden. This option is useful if you want to run identd as
48863+ a non-root user.
48864+
48865+config GRKERNSEC_PROC_GID
48866+ int "GID for special group"
48867+ depends on GRKERNSEC_PROC_USERGROUP
48868+ default 1001
48869+
48870+config GRKERNSEC_PROC_ADD
48871+ bool "Additional restrictions"
48872+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
48873+ help
48874+ If you say Y here, additional restrictions will be placed on
48875+ /proc that keep normal users from viewing device information and
48876+ slabinfo information that could be useful for exploits.
48877+
48878+config GRKERNSEC_LINK
48879+ bool "Linking restrictions"
48880+ help
48881+ If you say Y here, /tmp race exploits will be prevented, since users
48882+ will no longer be able to follow symlinks owned by other users in
48883+ world-writable +t directories (e.g. /tmp), unless the owner of the
48884+ symlink is the owner of the directory. users will also not be
48885+ able to hardlink to files they do not own. If the sysctl option is
48886+ enabled, a sysctl option with name "linking_restrictions" is created.
48887+
48888+config GRKERNSEC_FIFO
48889+ bool "FIFO restrictions"
48890+ help
48891+ If you say Y here, users will not be able to write to FIFOs they don't
48892+ own in world-writable +t directories (e.g. /tmp), unless the owner of
48893+ the FIFO is the same owner of the directory it's held in. If the sysctl
48894+ option is enabled, a sysctl option with name "fifo_restrictions" is
48895+ created.
48896+
48897+config GRKERNSEC_SYSFS_RESTRICT
48898+ bool "Sysfs/debugfs restriction"
48899+ depends on SYSFS
48900+ help
48901+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
48902+ any filesystem normally mounted under it (e.g. debugfs) will be
48903+ mostly accessible only by root. These filesystems generally provide access
48904+ to hardware and debug information that isn't appropriate for unprivileged
48905+ users of the system. Sysfs and debugfs have also become a large source
48906+ of new vulnerabilities, ranging from infoleaks to local compromise.
48907+ There has been very little oversight with an eye toward security involved
48908+ in adding new exporters of information to these filesystems, so their
48909+ use is discouraged.
48910+ For reasons of compatibility, a few directories have been whitelisted
48911+ for access by non-root users:
48912+ /sys/fs/selinux
48913+ /sys/fs/fuse
48914+ /sys/devices/system/cpu
48915+
48916+config GRKERNSEC_ROFS
48917+ bool "Runtime read-only mount protection"
48918+ help
48919+ If you say Y here, a sysctl option with name "romount_protect" will
48920+ be created. By setting this option to 1 at runtime, filesystems
48921+ will be protected in the following ways:
48922+ * No new writable mounts will be allowed
48923+ * Existing read-only mounts won't be able to be remounted read/write
48924+ * Write operations will be denied on all block devices
48925+ This option acts independently of grsec_lock: once it is set to 1,
48926+ it cannot be turned off. Therefore, please be mindful of the resulting
48927+ behavior if this option is enabled in an init script on a read-only
48928+ filesystem. This feature is mainly intended for secure embedded systems.
48929+
48930+config GRKERNSEC_CHROOT
48931+ bool "Chroot jail restrictions"
48932+ help
48933+ If you say Y here, you will be able to choose several options that will
48934+ make breaking out of a chrooted jail much more difficult. If you
48935+ encounter no software incompatibilities with the following options, it
48936+ is recommended that you enable each one.
48937+
48938+config GRKERNSEC_CHROOT_MOUNT
48939+ bool "Deny mounts"
48940+ depends on GRKERNSEC_CHROOT
48941+ help
48942+ If you say Y here, processes inside a chroot will not be able to
48943+ mount or remount filesystems. If the sysctl option is enabled, a
48944+ sysctl option with name "chroot_deny_mount" is created.
48945+
48946+config GRKERNSEC_CHROOT_DOUBLE
48947+ bool "Deny double-chroots"
48948+ depends on GRKERNSEC_CHROOT
48949+ help
48950+ If you say Y here, processes inside a chroot will not be able to chroot
48951+ again outside the chroot. This is a widely used method of breaking
48952+ out of a chroot jail and should not be allowed. If the sysctl
48953+ option is enabled, a sysctl option with name
48954+ "chroot_deny_chroot" is created.
48955+
48956+config GRKERNSEC_CHROOT_PIVOT
48957+ bool "Deny pivot_root in chroot"
48958+ depends on GRKERNSEC_CHROOT
48959+ help
48960+ If you say Y here, processes inside a chroot will not be able to use
48961+ a function called pivot_root() that was introduced in Linux 2.3.41. It
48962+ works similar to chroot in that it changes the root filesystem. This
48963+ function could be misused in a chrooted process to attempt to break out
48964+ of the chroot, and therefore should not be allowed. If the sysctl
48965+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
48966+ created.
48967+
48968+config GRKERNSEC_CHROOT_CHDIR
48969+ bool "Enforce chdir(\"/\") on all chroots"
48970+ depends on GRKERNSEC_CHROOT
48971+ help
48972+ If you say Y here, the current working directory of all newly-chrooted
48973+ applications will be set to the the root directory of the chroot.
48974+ The man page on chroot(2) states:
48975+ Note that this call does not change the current working
48976+ directory, so that `.' can be outside the tree rooted at
48977+ `/'. In particular, the super-user can escape from a
48978+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
48979+
48980+ It is recommended that you say Y here, since it's not known to break
48981+ any software. If the sysctl option is enabled, a sysctl option with
48982+ name "chroot_enforce_chdir" is created.
48983+
48984+config GRKERNSEC_CHROOT_CHMOD
48985+ bool "Deny (f)chmod +s"
48986+ depends on GRKERNSEC_CHROOT
48987+ help
48988+ If you say Y here, processes inside a chroot will not be able to chmod
48989+ or fchmod files to make them have suid or sgid bits. This protects
48990+ against another published method of breaking a chroot. If the sysctl
48991+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
48992+ created.
48993+
48994+config GRKERNSEC_CHROOT_FCHDIR
48995+ bool "Deny fchdir out of chroot"
48996+ depends on GRKERNSEC_CHROOT
48997+ help
48998+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
48999+ to a file descriptor of the chrooting process that points to a directory
49000+ outside the filesystem will be stopped. If the sysctl option
49001+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
49002+
49003+config GRKERNSEC_CHROOT_MKNOD
49004+ bool "Deny mknod"
49005+ depends on GRKERNSEC_CHROOT
49006+ help
49007+ If you say Y here, processes inside a chroot will not be allowed to
49008+ mknod. The problem with using mknod inside a chroot is that it
49009+ would allow an attacker to create a device entry that is the same
49010+ as one on the physical root of your system, which could range from
49011+ anything from the console device to a device for your harddrive (which
49012+ they could then use to wipe the drive or steal data). It is recommended
49013+ that you say Y here, unless you run into software incompatibilities.
49014+ If the sysctl option is enabled, a sysctl option with name
49015+ "chroot_deny_mknod" is created.
49016+
49017+config GRKERNSEC_CHROOT_SHMAT
49018+ bool "Deny shmat() out of chroot"
49019+ depends on GRKERNSEC_CHROOT
49020+ help
49021+ If you say Y here, processes inside a chroot will not be able to attach
49022+ to shared memory segments that were created outside of the chroot jail.
49023+ It is recommended that you say Y here. If the sysctl option is enabled,
49024+ a sysctl option with name "chroot_deny_shmat" is created.
49025+
49026+config GRKERNSEC_CHROOT_UNIX
49027+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
49028+ depends on GRKERNSEC_CHROOT
49029+ help
49030+ If you say Y here, processes inside a chroot will not be able to
49031+ connect to abstract (meaning not belonging to a filesystem) Unix
49032+ domain sockets that were bound outside of a chroot. It is recommended
49033+ that you say Y here. If the sysctl option is enabled, a sysctl option
49034+ with name "chroot_deny_unix" is created.
49035+
49036+config GRKERNSEC_CHROOT_FINDTASK
49037+ bool "Protect outside processes"
49038+ depends on GRKERNSEC_CHROOT
49039+ help
49040+ If you say Y here, processes inside a chroot will not be able to
49041+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
49042+ getsid, or view any process outside of the chroot. If the sysctl
49043+ option is enabled, a sysctl option with name "chroot_findtask" is
49044+ created.
49045+
49046+config GRKERNSEC_CHROOT_NICE
49047+ bool "Restrict priority changes"
49048+ depends on GRKERNSEC_CHROOT
49049+ help
49050+ If you say Y here, processes inside a chroot will not be able to raise
49051+ the priority of processes in the chroot, or alter the priority of
49052+ processes outside the chroot. This provides more security than simply
49053+ removing CAP_SYS_NICE from the process' capability set. If the
49054+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
49055+ is created.
49056+
49057+config GRKERNSEC_CHROOT_SYSCTL
49058+ bool "Deny sysctl writes"
49059+ depends on GRKERNSEC_CHROOT
49060+ help
49061+ If you say Y here, an attacker in a chroot will not be able to
49062+ write to sysctl entries, either by sysctl(2) or through a /proc
49063+ interface. It is strongly recommended that you say Y here. If the
49064+ sysctl option is enabled, a sysctl option with name
49065+ "chroot_deny_sysctl" is created.
49066+
49067+config GRKERNSEC_CHROOT_CAPS
49068+ bool "Capability restrictions"
49069+ depends on GRKERNSEC_CHROOT
49070+ help
49071+ If you say Y here, the capabilities on all processes within a
49072+ chroot jail will be lowered to stop module insertion, raw i/o,
49073+ system and net admin tasks, rebooting the system, modifying immutable
49074+ files, modifying IPC owned by another, and changing the system time.
49075+ This is left an option because it can break some apps. Disable this
49076+ if your chrooted apps are having problems performing those kinds of
49077+ tasks. If the sysctl option is enabled, a sysctl option with
49078+ name "chroot_caps" is created.
49079+
49080+endmenu
49081+menu "Kernel Auditing"
49082+depends on GRKERNSEC
49083+
49084+config GRKERNSEC_AUDIT_GROUP
49085+ bool "Single group for auditing"
49086+ help
49087+ If you say Y here, the exec, chdir, and (un)mount logging features
49088+ will only operate on a group you specify. This option is recommended
49089+ if you only want to watch certain users instead of having a large
49090+ amount of logs from the entire system. If the sysctl option is enabled,
49091+ a sysctl option with name "audit_group" is created.
49092+
49093+config GRKERNSEC_AUDIT_GID
49094+ int "GID for auditing"
49095+ depends on GRKERNSEC_AUDIT_GROUP
49096+ default 1007
49097+
49098+config GRKERNSEC_EXECLOG
49099+ bool "Exec logging"
49100+ help
49101+ If you say Y here, all execve() calls will be logged (since the
49102+ other exec*() calls are frontends to execve(), all execution
49103+ will be logged). Useful for shell-servers that like to keep track
49104+ of their users. If the sysctl option is enabled, a sysctl option with
49105+ name "exec_logging" is created.
49106+ WARNING: This option when enabled will produce a LOT of logs, especially
49107+ on an active system.
49108+
49109+config GRKERNSEC_RESLOG
49110+ bool "Resource logging"
49111+ help
49112+ If you say Y here, all attempts to overstep resource limits will
49113+ be logged with the resource name, the requested size, and the current
49114+ limit. It is highly recommended that you say Y here. If the sysctl
49115+ option is enabled, a sysctl option with name "resource_logging" is
49116+ created. If the RBAC system is enabled, the sysctl value is ignored.
49117+
49118+config GRKERNSEC_CHROOT_EXECLOG
49119+ bool "Log execs within chroot"
49120+ help
49121+ If you say Y here, all executions inside a chroot jail will be logged
49122+ to syslog. This can cause a large amount of logs if certain
49123+ applications (eg. djb's daemontools) are installed on the system, and
49124+ is therefore left as an option. If the sysctl option is enabled, a
49125+ sysctl option with name "chroot_execlog" is created.
49126+
49127+config GRKERNSEC_AUDIT_PTRACE
49128+ bool "Ptrace logging"
49129+ help
49130+ If you say Y here, all attempts to attach to a process via ptrace
49131+ will be logged. If the sysctl option is enabled, a sysctl option
49132+ with name "audit_ptrace" is created.
49133+
49134+config GRKERNSEC_AUDIT_CHDIR
49135+ bool "Chdir logging"
49136+ help
49137+ If you say Y here, all chdir() calls will be logged. If the sysctl
49138+ option is enabled, a sysctl option with name "audit_chdir" is created.
49139+
49140+config GRKERNSEC_AUDIT_MOUNT
49141+ bool "(Un)Mount logging"
49142+ help
49143+ If you say Y here, all mounts and unmounts will be logged. If the
49144+ sysctl option is enabled, a sysctl option with name "audit_mount" is
49145+ created.
49146+
49147+config GRKERNSEC_SIGNAL
49148+ bool "Signal logging"
49149+ help
49150+ If you say Y here, certain important signals will be logged, such as
49151+ SIGSEGV, which will as a result inform you of when a error in a program
49152+ occurred, which in some cases could mean a possible exploit attempt.
49153+ If the sysctl option is enabled, a sysctl option with name
49154+ "signal_logging" is created.
49155+
49156+config GRKERNSEC_FORKFAIL
49157+ bool "Fork failure logging"
49158+ help
49159+ If you say Y here, all failed fork() attempts will be logged.
49160+ This could suggest a fork bomb, or someone attempting to overstep
49161+ their process limit. If the sysctl option is enabled, a sysctl option
49162+ with name "forkfail_logging" is created.
49163+
49164+config GRKERNSEC_TIME
49165+ bool "Time change logging"
49166+ help
49167+ If you say Y here, any changes of the system clock will be logged.
49168+ If the sysctl option is enabled, a sysctl option with name
49169+ "timechange_logging" is created.
49170+
49171+config GRKERNSEC_PROC_IPADDR
49172+ bool "/proc/<pid>/ipaddr support"
49173+ help
49174+ If you say Y here, a new entry will be added to each /proc/<pid>
49175+ directory that contains the IP address of the person using the task.
49176+ The IP is carried across local TCP and AF_UNIX stream sockets.
49177+ This information can be useful for IDS/IPSes to perform remote response
49178+ to a local attack. The entry is readable by only the owner of the
49179+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
49180+ the RBAC system), and thus does not create privacy concerns.
49181+
49182+config GRKERNSEC_RWXMAP_LOG
49183+ bool 'Denied RWX mmap/mprotect logging'
49184+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
49185+ help
49186+ If you say Y here, calls to mmap() and mprotect() with explicit
49187+ usage of PROT_WRITE and PROT_EXEC together will be logged when
49188+ denied by the PAX_MPROTECT feature. If the sysctl option is
49189+ enabled, a sysctl option with name "rwxmap_logging" is created.
49190+
49191+config GRKERNSEC_AUDIT_TEXTREL
49192+ bool 'ELF text relocations logging (READ HELP)'
49193+ depends on PAX_MPROTECT
49194+ help
49195+ If you say Y here, text relocations will be logged with the filename
49196+ of the offending library or binary. The purpose of the feature is
49197+ to help Linux distribution developers get rid of libraries and
49198+ binaries that need text relocations which hinder the future progress
49199+ of PaX. Only Linux distribution developers should say Y here, and
49200+ never on a production machine, as this option creates an information
49201+ leak that could aid an attacker in defeating the randomization of
49202+ a single memory region. If the sysctl option is enabled, a sysctl
49203+ option with name "audit_textrel" is created.
49204+
49205+endmenu
49206+
49207+menu "Executable Protections"
49208+depends on GRKERNSEC
49209+
49210+config GRKERNSEC_DMESG
49211+ bool "Dmesg(8) restriction"
49212+ help
49213+ If you say Y here, non-root users will not be able to use dmesg(8)
49214+ to view up to the last 4kb of messages in the kernel's log buffer.
49215+ The kernel's log buffer often contains kernel addresses and other
49216+ identifying information useful to an attacker in fingerprinting a
49217+ system for a targeted exploit.
49218+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
49219+ created.
49220+
49221+config GRKERNSEC_HARDEN_PTRACE
49222+ bool "Deter ptrace-based process snooping"
49223+ help
49224+ If you say Y here, TTY sniffers and other malicious monitoring
49225+ programs implemented through ptrace will be defeated. If you
49226+ have been using the RBAC system, this option has already been
49227+ enabled for several years for all users, with the ability to make
49228+ fine-grained exceptions.
49229+
49230+ This option only affects the ability of non-root users to ptrace
49231+ processes that are not a descendent of the ptracing process.
49232+ This means that strace ./binary and gdb ./binary will still work,
49233+ but attaching to arbitrary processes will not. If the sysctl
49234+ option is enabled, a sysctl option with name "harden_ptrace" is
49235+ created.
49236+
49237+config GRKERNSEC_PTRACE_READEXEC
49238+ bool "Require read access to ptrace sensitive binaries"
49239+ help
49240+ If you say Y here, unprivileged users will not be able to ptrace unreadable
49241+ binaries. This option is useful in environments that
49242+ remove the read bits (e.g. file mode 4711) from suid binaries to
49243+ prevent infoleaking of their contents. This option adds
49244+ consistency to the use of that file mode, as the binary could normally
49245+ be read out when run without privileges while ptracing.
49246+
49247+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
49248+ is created.
49249+
49250+config GRKERNSEC_SETXID
49251+ bool "Enforce consistent multithreaded privileges"
49252+ help
49253+ If you say Y here, a change from a root uid to a non-root uid
49254+ in a multithreaded application will cause the resulting uids,
49255+ gids, supplementary groups, and capabilities in that thread
49256+ to be propagated to the other threads of the process. In most
49257+ cases this is unnecessary, as glibc will emulate this behavior
49258+ on behalf of the application. Other libcs do not act in the
49259+ same way, allowing the other threads of the process to continue
49260+ running with root privileges. If the sysctl option is enabled,
49261+ a sysctl option with name "consistent_setxid" is created.
49262+
49263+config GRKERNSEC_TPE
49264+ bool "Trusted Path Execution (TPE)"
49265+ help
49266+ If you say Y here, you will be able to choose a gid to add to the
49267+ supplementary groups of users you want to mark as "untrusted."
49268+ These users will not be able to execute any files that are not in
49269+ root-owned directories writable only by root. If the sysctl option
49270+ is enabled, a sysctl option with name "tpe" is created.
49271+
49272+config GRKERNSEC_TPE_ALL
49273+ bool "Partially restrict all non-root users"
49274+ depends on GRKERNSEC_TPE
49275+ help
49276+ If you say Y here, all non-root users will be covered under
49277+ a weaker TPE restriction. This is separate from, and in addition to,
49278+ the main TPE options that you have selected elsewhere. Thus, if a
49279+ "trusted" GID is chosen, this restriction applies to even that GID.
49280+ Under this restriction, all non-root users will only be allowed to
49281+ execute files in directories they own that are not group or
49282+ world-writable, or in directories owned by root and writable only by
49283+ root. If the sysctl option is enabled, a sysctl option with name
49284+ "tpe_restrict_all" is created.
49285+
49286+config GRKERNSEC_TPE_INVERT
49287+ bool "Invert GID option"
49288+ depends on GRKERNSEC_TPE
49289+ help
49290+ If you say Y here, the group you specify in the TPE configuration will
49291+ decide what group TPE restrictions will be *disabled* for. This
49292+ option is useful if you want TPE restrictions to be applied to most
49293+ users on the system. If the sysctl option is enabled, a sysctl option
49294+ with name "tpe_invert" is created. Unlike other sysctl options, this
49295+ entry will default to on for backward-compatibility.
49296+
49297+config GRKERNSEC_TPE_GID
49298+ int "GID for untrusted users"
49299+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
49300+ default 1005
49301+ help
49302+ Setting this GID determines what group TPE restrictions will be
49303+ *enabled* for. If the sysctl option is enabled, a sysctl option
49304+ with name "tpe_gid" is created.
49305+
49306+config GRKERNSEC_TPE_GID
49307+ int "GID for trusted users"
49308+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
49309+ default 1005
49310+ help
49311+ Setting this GID determines what group TPE restrictions will be
49312+ *disabled* for. If the sysctl option is enabled, a sysctl option
49313+ with name "tpe_gid" is created.
49314+
49315+endmenu
49316+menu "Network Protections"
49317+depends on GRKERNSEC
49318+
49319+config GRKERNSEC_RANDNET
49320+ bool "Larger entropy pools"
49321+ help
49322+ If you say Y here, the entropy pools used for many features of Linux
49323+ and grsecurity will be doubled in size. Since several grsecurity
49324+ features use additional randomness, it is recommended that you say Y
49325+ here. Saying Y here has a similar effect as modifying
49326+ /proc/sys/kernel/random/poolsize.
49327+
49328+config GRKERNSEC_BLACKHOLE
49329+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
49330+ depends on NET
49331+ help
49332+ If you say Y here, neither TCP resets nor ICMP
49333+ destination-unreachable packets will be sent in response to packets
49334+ sent to ports for which no associated listening process exists.
49335+ This feature supports both IPV4 and IPV6 and exempts the
49336+ loopback interface from blackholing. Enabling this feature
49337+ makes a host more resilient to DoS attacks and reduces network
49338+ visibility against scanners.
49339+
49340+ The blackhole feature as-implemented is equivalent to the FreeBSD
49341+ blackhole feature, as it prevents RST responses to all packets, not
49342+ just SYNs. Under most application behavior this causes no
49343+ problems, but applications (like haproxy) may not close certain
49344+ connections in a way that cleanly terminates them on the remote
49345+ end, leaving the remote host in LAST_ACK state. Because of this
49346+ side-effect and to prevent intentional LAST_ACK DoSes, this
49347+ feature also adds automatic mitigation against such attacks.
49348+ The mitigation drastically reduces the amount of time a socket
49349+ can spend in LAST_ACK state. If you're using haproxy and not
49350+ all servers it connects to have this option enabled, consider
49351+ disabling this feature on the haproxy host.
49352+
49353+ If the sysctl option is enabled, two sysctl options with names
49354+ "ip_blackhole" and "lastack_retries" will be created.
49355+ While "ip_blackhole" takes the standard zero/non-zero on/off
49356+ toggle, "lastack_retries" uses the same kinds of values as
49357+ "tcp_retries1" and "tcp_retries2". The default value of 4
49358+ prevents a socket from lasting more than 45 seconds in LAST_ACK
49359+ state.
49360+
49361+config GRKERNSEC_SOCKET
49362+ bool "Socket restrictions"
49363+ depends on NET
49364+ help
49365+ If you say Y here, you will be able to choose from several options.
49366+ If you assign a GID on your system and add it to the supplementary
49367+ groups of users you want to restrict socket access to, this patch
49368+ will perform up to three things, based on the option(s) you choose.
49369+
49370+config GRKERNSEC_SOCKET_ALL
49371+ bool "Deny any sockets to group"
49372+ depends on GRKERNSEC_SOCKET
49373+ help
49374+ If you say Y here, you will be able to choose a GID of whose users will
49375+ be unable to connect to other hosts from your machine or run server
49376+ applications from your machine. If the sysctl option is enabled, a
49377+ sysctl option with name "socket_all" is created.
49378+
49379+config GRKERNSEC_SOCKET_ALL_GID
49380+ int "GID to deny all sockets for"
49381+ depends on GRKERNSEC_SOCKET_ALL
49382+ default 1004
49383+ help
49384+ Here you can choose the GID to disable socket access for. Remember to
49385+ add the users you want socket access disabled for to the GID
49386+ specified here. If the sysctl option is enabled, a sysctl option
49387+ with name "socket_all_gid" is created.
49388+
49389+config GRKERNSEC_SOCKET_CLIENT
49390+ bool "Deny client sockets to group"
49391+ depends on GRKERNSEC_SOCKET
49392+ help
49393+ If you say Y here, you will be able to choose a GID of whose users will
49394+ be unable to connect to other hosts from your machine, but will be
49395+ able to run servers. If this option is enabled, all users in the group
49396+ you specify will have to use passive mode when initiating ftp transfers
49397+ from the shell on your machine. If the sysctl option is enabled, a
49398+ sysctl option with name "socket_client" is created.
49399+
49400+config GRKERNSEC_SOCKET_CLIENT_GID
49401+ int "GID to deny client sockets for"
49402+ depends on GRKERNSEC_SOCKET_CLIENT
49403+ default 1003
49404+ help
49405+ Here you can choose the GID to disable client socket access for.
49406+ Remember to add the users you want client socket access disabled for to
49407+ the GID specified here. If the sysctl option is enabled, a sysctl
49408+ option with name "socket_client_gid" is created.
49409+
49410+config GRKERNSEC_SOCKET_SERVER
49411+ bool "Deny server sockets to group"
49412+ depends on GRKERNSEC_SOCKET
49413+ help
49414+ If you say Y here, you will be able to choose a GID of whose users will
49415+ be unable to run server applications from your machine. If the sysctl
49416+ option is enabled, a sysctl option with name "socket_server" is created.
49417+
49418+config GRKERNSEC_SOCKET_SERVER_GID
49419+ int "GID to deny server sockets for"
49420+ depends on GRKERNSEC_SOCKET_SERVER
49421+ default 1002
49422+ help
49423+ Here you can choose the GID to disable server socket access for.
49424+ Remember to add the users you want server socket access disabled for to
49425+ the GID specified here. If the sysctl option is enabled, a sysctl
49426+ option with name "socket_server_gid" is created.
49427+
49428+endmenu
49429+menu "Sysctl support"
49430+depends on GRKERNSEC && SYSCTL
49431+
49432+config GRKERNSEC_SYSCTL
49433+ bool "Sysctl support"
49434+ help
49435+ If you say Y here, you will be able to change the options that
49436+ grsecurity runs with at bootup, without having to recompile your
49437+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
49438+ to enable (1) or disable (0) various features. All the sysctl entries
49439+ are mutable until the "grsec_lock" entry is set to a non-zero value.
49440+ All features enabled in the kernel configuration are disabled at boot
49441+ if you do not say Y to the "Turn on features by default" option.
49442+ All options should be set at startup, and the grsec_lock entry should
49443+ be set to a non-zero value after all the options are set.
49444+ *THIS IS EXTREMELY IMPORTANT*
49445+
49446+config GRKERNSEC_SYSCTL_DISTRO
49447+ bool "Extra sysctl support for distro makers (READ HELP)"
49448+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
49449+ help
49450+ If you say Y here, additional sysctl options will be created
49451+ for features that affect processes running as root. Therefore,
49452+ it is critical when using this option that the grsec_lock entry be
49453+ enabled after boot. Only distros with prebuilt kernel packages
49454+ with this option enabled that can ensure grsec_lock is enabled
49455+ after boot should use this option.
49456+ *Failure to set grsec_lock after boot makes all grsec features
49457+ this option covers useless*
49458+
49459+ Currently this option creates the following sysctl entries:
49460+ "Disable Privileged I/O": "disable_priv_io"
49461+
49462+config GRKERNSEC_SYSCTL_ON
49463+ bool "Turn on features by default"
49464+ depends on GRKERNSEC_SYSCTL
49465+ help
49466+ If you say Y here, instead of having all features enabled in the
49467+ kernel configuration disabled at boot time, the features will be
49468+ enabled at boot time. It is recommended you say Y here unless
49469+ there is some reason you would want all sysctl-tunable features to
49470+ be disabled by default. As mentioned elsewhere, it is important
49471+ to enable the grsec_lock entry once you have finished modifying
49472+ the sysctl entries.
49473+
49474+endmenu
49475+menu "Logging Options"
49476+depends on GRKERNSEC
49477+
49478+config GRKERNSEC_FLOODTIME
49479+ int "Seconds in between log messages (minimum)"
49480+ default 10
49481+ help
49482+ This option allows you to enforce the number of seconds between
49483+ grsecurity log messages. The default should be suitable for most
49484+ people, however, if you choose to change it, choose a value small enough
49485+ to allow informative logs to be produced, but large enough to
49486+ prevent flooding.
49487+
49488+config GRKERNSEC_FLOODBURST
49489+ int "Number of messages in a burst (maximum)"
49490+ default 6
49491+ help
49492+ This option allows you to choose the maximum number of messages allowed
49493+ within the flood time interval you chose in a separate option. The
49494+ default should be suitable for most people, however if you find that
49495+ many of your logs are being interpreted as flooding, you may want to
49496+ raise this value.
49497+
49498+endmenu
49499+
49500+endmenu
49501diff --git a/grsecurity/Makefile b/grsecurity/Makefile
49502new file mode 100644
49503index 0000000..1b9afa9
49504--- /dev/null
49505+++ b/grsecurity/Makefile
49506@@ -0,0 +1,38 @@
49507+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
49508+# during 2001-2009 it has been completely redesigned by Brad Spengler
49509+# into an RBAC system
49510+#
49511+# All code in this directory and various hooks inserted throughout the kernel
49512+# are copyright Brad Spengler - Open Source Security, Inc., and released
49513+# under the GPL v2 or higher
49514+
49515+KBUILD_CFLAGS += -Werror
49516+
49517+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
49518+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
49519+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
49520+
49521+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
49522+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
49523+ gracl_learn.o grsec_log.o
49524+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
49525+
49526+ifdef CONFIG_NET
49527+obj-y += grsec_sock.o
49528+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
49529+endif
49530+
49531+ifndef CONFIG_GRKERNSEC
49532+obj-y += grsec_disabled.o
49533+endif
49534+
49535+ifdef CONFIG_GRKERNSEC_HIDESYM
49536+extra-y := grsec_hidesym.o
49537+$(obj)/grsec_hidesym.o:
49538+ @-chmod -f 500 /boot
49539+ @-chmod -f 500 /lib/modules
49540+ @-chmod -f 500 /lib64/modules
49541+ @-chmod -f 500 /lib32/modules
49542+ @-chmod -f 700 .
49543+ @echo ' grsec: protected kernel image paths'
49544+endif
49545diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
49546new file mode 100644
49547index 0000000..e8c5d41
49548--- /dev/null
49549+++ b/grsecurity/gracl.c
49550@@ -0,0 +1,4179 @@
49551+#include <linux/kernel.h>
49552+#include <linux/module.h>
49553+#include <linux/sched.h>
49554+#include <linux/mm.h>
49555+#include <linux/file.h>
49556+#include <linux/fs.h>
49557+#include <linux/namei.h>
49558+#include <linux/mount.h>
49559+#include <linux/tty.h>
49560+#include <linux/proc_fs.h>
49561+#include <linux/lglock.h>
49562+#include <linux/slab.h>
49563+#include <linux/vmalloc.h>
49564+#include <linux/types.h>
49565+#include <linux/sysctl.h>
49566+#include <linux/netdevice.h>
49567+#include <linux/ptrace.h>
49568+#include <linux/gracl.h>
49569+#include <linux/gralloc.h>
49570+#include <linux/security.h>
49571+#include <linux/grinternal.h>
49572+#include <linux/pid_namespace.h>
49573+#include <linux/fdtable.h>
49574+#include <linux/percpu.h>
49575+#include "../fs/mount.h"
49576+
49577+#include <asm/uaccess.h>
49578+#include <asm/errno.h>
49579+#include <asm/mman.h>
49580+
49581+static struct acl_role_db acl_role_set;
49582+static struct name_db name_set;
49583+static struct inodev_db inodev_set;
49584+
49585+/* for keeping track of userspace pointers used for subjects, so we
49586+ can share references in the kernel as well
49587+*/
49588+
49589+static struct path real_root;
49590+
49591+static struct acl_subj_map_db subj_map_set;
49592+
49593+static struct acl_role_label *default_role;
49594+
49595+static struct acl_role_label *role_list;
49596+
49597+static u16 acl_sp_role_value;
49598+
49599+extern char *gr_shared_page[4];
49600+static DEFINE_MUTEX(gr_dev_mutex);
49601+DEFINE_RWLOCK(gr_inode_lock);
49602+
49603+struct gr_arg *gr_usermode;
49604+
49605+static unsigned int gr_status __read_only = GR_STATUS_INIT;
49606+
49607+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
49608+extern void gr_clear_learn_entries(void);
49609+
49610+#ifdef CONFIG_GRKERNSEC_RESLOG
49611+extern void gr_log_resource(const struct task_struct *task,
49612+ const int res, const unsigned long wanted, const int gt);
49613+#endif
49614+
49615+unsigned char *gr_system_salt;
49616+unsigned char *gr_system_sum;
49617+
49618+static struct sprole_pw **acl_special_roles = NULL;
49619+static __u16 num_sprole_pws = 0;
49620+
49621+static struct acl_role_label *kernel_role = NULL;
49622+
49623+static unsigned int gr_auth_attempts = 0;
49624+static unsigned long gr_auth_expires = 0UL;
49625+
49626+#ifdef CONFIG_NET
49627+extern struct vfsmount *sock_mnt;
49628+#endif
49629+
49630+extern struct vfsmount *pipe_mnt;
49631+extern struct vfsmount *shm_mnt;
49632+#ifdef CONFIG_HUGETLBFS
49633+extern struct vfsmount *hugetlbfs_vfsmount;
49634+#endif
49635+
49636+static struct acl_object_label *fakefs_obj_rw;
49637+static struct acl_object_label *fakefs_obj_rwx;
49638+
49639+extern int gr_init_uidset(void);
49640+extern void gr_free_uidset(void);
49641+extern void gr_remove_uid(uid_t uid);
49642+extern int gr_find_uid(uid_t uid);
49643+
49644+DECLARE_BRLOCK(vfsmount_lock);
49645+
49646+__inline__ int
49647+gr_acl_is_enabled(void)
49648+{
49649+ return (gr_status & GR_READY);
49650+}
49651+
49652+#ifdef CONFIG_BTRFS_FS
49653+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
49654+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
49655+#endif
49656+
49657+static inline dev_t __get_dev(const struct dentry *dentry)
49658+{
49659+#ifdef CONFIG_BTRFS_FS
49660+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
49661+ return get_btrfs_dev_from_inode(dentry->d_inode);
49662+ else
49663+#endif
49664+ return dentry->d_inode->i_sb->s_dev;
49665+}
49666+
49667+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
49668+{
49669+ return __get_dev(dentry);
49670+}
49671+
49672+static char gr_task_roletype_to_char(struct task_struct *task)
49673+{
49674+ switch (task->role->roletype &
49675+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
49676+ GR_ROLE_SPECIAL)) {
49677+ case GR_ROLE_DEFAULT:
49678+ return 'D';
49679+ case GR_ROLE_USER:
49680+ return 'U';
49681+ case GR_ROLE_GROUP:
49682+ return 'G';
49683+ case GR_ROLE_SPECIAL:
49684+ return 'S';
49685+ }
49686+
49687+ return 'X';
49688+}
49689+
49690+char gr_roletype_to_char(void)
49691+{
49692+ return gr_task_roletype_to_char(current);
49693+}
49694+
49695+__inline__ int
49696+gr_acl_tpe_check(void)
49697+{
49698+ if (unlikely(!(gr_status & GR_READY)))
49699+ return 0;
49700+ if (current->role->roletype & GR_ROLE_TPE)
49701+ return 1;
49702+ else
49703+ return 0;
49704+}
49705+
49706+int
49707+gr_handle_rawio(const struct inode *inode)
49708+{
49709+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
49710+ if (inode && S_ISBLK(inode->i_mode) &&
49711+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
49712+ !capable(CAP_SYS_RAWIO))
49713+ return 1;
49714+#endif
49715+ return 0;
49716+}
49717+
49718+static int
49719+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
49720+{
49721+ if (likely(lena != lenb))
49722+ return 0;
49723+
49724+ return !memcmp(a, b, lena);
49725+}
49726+
49727+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
49728+{
49729+ *buflen -= namelen;
49730+ if (*buflen < 0)
49731+ return -ENAMETOOLONG;
49732+ *buffer -= namelen;
49733+ memcpy(*buffer, str, namelen);
49734+ return 0;
49735+}
49736+
49737+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
49738+{
49739+ return prepend(buffer, buflen, name->name, name->len);
49740+}
49741+
49742+static int prepend_path(const struct path *path, struct path *root,
49743+ char **buffer, int *buflen)
49744+{
49745+ struct dentry *dentry = path->dentry;
49746+ struct vfsmount *vfsmnt = path->mnt;
49747+ struct mount *mnt = real_mount(vfsmnt);
49748+ bool slash = false;
49749+ int error = 0;
49750+
49751+ while (dentry != root->dentry || vfsmnt != root->mnt) {
49752+ struct dentry * parent;
49753+
49754+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
49755+ /* Global root? */
49756+ if (!mnt_has_parent(mnt)) {
49757+ goto out;
49758+ }
49759+ dentry = mnt->mnt_mountpoint;
49760+ mnt = mnt->mnt_parent;
49761+ vfsmnt = &mnt->mnt;
49762+ continue;
49763+ }
49764+ parent = dentry->d_parent;
49765+ prefetch(parent);
49766+ spin_lock(&dentry->d_lock);
49767+ error = prepend_name(buffer, buflen, &dentry->d_name);
49768+ spin_unlock(&dentry->d_lock);
49769+ if (!error)
49770+ error = prepend(buffer, buflen, "/", 1);
49771+ if (error)
49772+ break;
49773+
49774+ slash = true;
49775+ dentry = parent;
49776+ }
49777+
49778+out:
49779+ if (!error && !slash)
49780+ error = prepend(buffer, buflen, "/", 1);
49781+
49782+ return error;
49783+}
49784+
49785+/* this must be called with vfsmount_lock and rename_lock held */
49786+
49787+static char *__our_d_path(const struct path *path, struct path *root,
49788+ char *buf, int buflen)
49789+{
49790+ char *res = buf + buflen;
49791+ int error;
49792+
49793+ prepend(&res, &buflen, "\0", 1);
49794+ error = prepend_path(path, root, &res, &buflen);
49795+ if (error)
49796+ return ERR_PTR(error);
49797+
49798+ return res;
49799+}
49800+
49801+static char *
49802+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
49803+{
49804+ char *retval;
49805+
49806+ retval = __our_d_path(path, root, buf, buflen);
49807+ if (unlikely(IS_ERR(retval)))
49808+ retval = strcpy(buf, "<path too long>");
49809+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
49810+ retval[1] = '\0';
49811+
49812+ return retval;
49813+}
49814+
49815+static char *
49816+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
49817+ char *buf, int buflen)
49818+{
49819+ struct path path;
49820+ char *res;
49821+
49822+ path.dentry = (struct dentry *)dentry;
49823+ path.mnt = (struct vfsmount *)vfsmnt;
49824+
49825+ /* we can use real_root.dentry, real_root.mnt, because this is only called
49826+ by the RBAC system */
49827+ res = gen_full_path(&path, &real_root, buf, buflen);
49828+
49829+ return res;
49830+}
49831+
49832+static char *
49833+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
49834+ char *buf, int buflen)
49835+{
49836+ char *res;
49837+ struct path path;
49838+ struct path root;
49839+ struct task_struct *reaper = &init_task;
49840+
49841+ path.dentry = (struct dentry *)dentry;
49842+ path.mnt = (struct vfsmount *)vfsmnt;
49843+
49844+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
49845+ get_fs_root(reaper->fs, &root);
49846+
49847+ write_seqlock(&rename_lock);
49848+ br_read_lock(vfsmount_lock);
49849+ res = gen_full_path(&path, &root, buf, buflen);
49850+ br_read_unlock(vfsmount_lock);
49851+ write_sequnlock(&rename_lock);
49852+
49853+ path_put(&root);
49854+ return res;
49855+}
49856+
49857+static char *
49858+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
49859+{
49860+ char *ret;
49861+ write_seqlock(&rename_lock);
49862+ br_read_lock(vfsmount_lock);
49863+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
49864+ PAGE_SIZE);
49865+ br_read_unlock(vfsmount_lock);
49866+ write_sequnlock(&rename_lock);
49867+ return ret;
49868+}
49869+
49870+static char *
49871+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
49872+{
49873+ char *ret;
49874+ char *buf;
49875+ int buflen;
49876+
49877+ write_seqlock(&rename_lock);
49878+ br_read_lock(vfsmount_lock);
49879+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
49880+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
49881+ buflen = (int)(ret - buf);
49882+ if (buflen >= 5)
49883+ prepend(&ret, &buflen, "/proc", 5);
49884+ else
49885+ ret = strcpy(buf, "<path too long>");
49886+ br_read_unlock(vfsmount_lock);
49887+ write_sequnlock(&rename_lock);
49888+ return ret;
49889+}
49890+
49891+char *
49892+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
49893+{
49894+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
49895+ PAGE_SIZE);
49896+}
49897+
49898+char *
49899+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
49900+{
49901+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
49902+ PAGE_SIZE);
49903+}
49904+
49905+char *
49906+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
49907+{
49908+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
49909+ PAGE_SIZE);
49910+}
49911+
49912+char *
49913+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
49914+{
49915+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
49916+ PAGE_SIZE);
49917+}
49918+
49919+char *
49920+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
49921+{
49922+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
49923+ PAGE_SIZE);
49924+}
49925+
49926+__inline__ __u32
49927+to_gr_audit(const __u32 reqmode)
49928+{
49929+ /* masks off auditable permission flags, then shifts them to create
49930+ auditing flags, and adds the special case of append auditing if
49931+ we're requesting write */
49932+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
49933+}
49934+
49935+struct acl_subject_label *
49936+lookup_subject_map(const struct acl_subject_label *userp)
49937+{
49938+ unsigned int index = shash(userp, subj_map_set.s_size);
49939+ struct subject_map *match;
49940+
49941+ match = subj_map_set.s_hash[index];
49942+
49943+ while (match && match->user != userp)
49944+ match = match->next;
49945+
49946+ if (match != NULL)
49947+ return match->kernel;
49948+ else
49949+ return NULL;
49950+}
49951+
49952+static void
49953+insert_subj_map_entry(struct subject_map *subjmap)
49954+{
49955+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
49956+ struct subject_map **curr;
49957+
49958+ subjmap->prev = NULL;
49959+
49960+ curr = &subj_map_set.s_hash[index];
49961+ if (*curr != NULL)
49962+ (*curr)->prev = subjmap;
49963+
49964+ subjmap->next = *curr;
49965+ *curr = subjmap;
49966+
49967+ return;
49968+}
49969+
49970+static struct acl_role_label *
49971+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
49972+ const gid_t gid)
49973+{
49974+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
49975+ struct acl_role_label *match;
49976+ struct role_allowed_ip *ipp;
49977+ unsigned int x;
49978+ u32 curr_ip = task->signal->curr_ip;
49979+
49980+ task->signal->saved_ip = curr_ip;
49981+
49982+ match = acl_role_set.r_hash[index];
49983+
49984+ while (match) {
49985+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
49986+ for (x = 0; x < match->domain_child_num; x++) {
49987+ if (match->domain_children[x] == uid)
49988+ goto found;
49989+ }
49990+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
49991+ break;
49992+ match = match->next;
49993+ }
49994+found:
49995+ if (match == NULL) {
49996+ try_group:
49997+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
49998+ match = acl_role_set.r_hash[index];
49999+
50000+ while (match) {
50001+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
50002+ for (x = 0; x < match->domain_child_num; x++) {
50003+ if (match->domain_children[x] == gid)
50004+ goto found2;
50005+ }
50006+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
50007+ break;
50008+ match = match->next;
50009+ }
50010+found2:
50011+ if (match == NULL)
50012+ match = default_role;
50013+ if (match->allowed_ips == NULL)
50014+ return match;
50015+ else {
50016+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
50017+ if (likely
50018+ ((ntohl(curr_ip) & ipp->netmask) ==
50019+ (ntohl(ipp->addr) & ipp->netmask)))
50020+ return match;
50021+ }
50022+ match = default_role;
50023+ }
50024+ } else if (match->allowed_ips == NULL) {
50025+ return match;
50026+ } else {
50027+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
50028+ if (likely
50029+ ((ntohl(curr_ip) & ipp->netmask) ==
50030+ (ntohl(ipp->addr) & ipp->netmask)))
50031+ return match;
50032+ }
50033+ goto try_group;
50034+ }
50035+
50036+ return match;
50037+}
50038+
50039+struct acl_subject_label *
50040+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
50041+ const struct acl_role_label *role)
50042+{
50043+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
50044+ struct acl_subject_label *match;
50045+
50046+ match = role->subj_hash[index];
50047+
50048+ while (match && (match->inode != ino || match->device != dev ||
50049+ (match->mode & GR_DELETED))) {
50050+ match = match->next;
50051+ }
50052+
50053+ if (match && !(match->mode & GR_DELETED))
50054+ return match;
50055+ else
50056+ return NULL;
50057+}
50058+
50059+struct acl_subject_label *
50060+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
50061+ const struct acl_role_label *role)
50062+{
50063+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
50064+ struct acl_subject_label *match;
50065+
50066+ match = role->subj_hash[index];
50067+
50068+ while (match && (match->inode != ino || match->device != dev ||
50069+ !(match->mode & GR_DELETED))) {
50070+ match = match->next;
50071+ }
50072+
50073+ if (match && (match->mode & GR_DELETED))
50074+ return match;
50075+ else
50076+ return NULL;
50077+}
50078+
50079+static struct acl_object_label *
50080+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
50081+ const struct acl_subject_label *subj)
50082+{
50083+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
50084+ struct acl_object_label *match;
50085+
50086+ match = subj->obj_hash[index];
50087+
50088+ while (match && (match->inode != ino || match->device != dev ||
50089+ (match->mode & GR_DELETED))) {
50090+ match = match->next;
50091+ }
50092+
50093+ if (match && !(match->mode & GR_DELETED))
50094+ return match;
50095+ else
50096+ return NULL;
50097+}
50098+
50099+static struct acl_object_label *
50100+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
50101+ const struct acl_subject_label *subj)
50102+{
50103+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
50104+ struct acl_object_label *match;
50105+
50106+ match = subj->obj_hash[index];
50107+
50108+ while (match && (match->inode != ino || match->device != dev ||
50109+ !(match->mode & GR_DELETED))) {
50110+ match = match->next;
50111+ }
50112+
50113+ if (match && (match->mode & GR_DELETED))
50114+ return match;
50115+
50116+ match = subj->obj_hash[index];
50117+
50118+ while (match && (match->inode != ino || match->device != dev ||
50119+ (match->mode & GR_DELETED))) {
50120+ match = match->next;
50121+ }
50122+
50123+ if (match && !(match->mode & GR_DELETED))
50124+ return match;
50125+ else
50126+ return NULL;
50127+}
50128+
50129+static struct name_entry *
50130+lookup_name_entry(const char *name)
50131+{
50132+ unsigned int len = strlen(name);
50133+ unsigned int key = full_name_hash(name, len);
50134+ unsigned int index = key % name_set.n_size;
50135+ struct name_entry *match;
50136+
50137+ match = name_set.n_hash[index];
50138+
50139+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
50140+ match = match->next;
50141+
50142+ return match;
50143+}
50144+
50145+static struct name_entry *
50146+lookup_name_entry_create(const char *name)
50147+{
50148+ unsigned int len = strlen(name);
50149+ unsigned int key = full_name_hash(name, len);
50150+ unsigned int index = key % name_set.n_size;
50151+ struct name_entry *match;
50152+
50153+ match = name_set.n_hash[index];
50154+
50155+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
50156+ !match->deleted))
50157+ match = match->next;
50158+
50159+ if (match && match->deleted)
50160+ return match;
50161+
50162+ match = name_set.n_hash[index];
50163+
50164+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
50165+ match->deleted))
50166+ match = match->next;
50167+
50168+ if (match && !match->deleted)
50169+ return match;
50170+ else
50171+ return NULL;
50172+}
50173+
50174+static struct inodev_entry *
50175+lookup_inodev_entry(const ino_t ino, const dev_t dev)
50176+{
50177+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
50178+ struct inodev_entry *match;
50179+
50180+ match = inodev_set.i_hash[index];
50181+
50182+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
50183+ match = match->next;
50184+
50185+ return match;
50186+}
50187+
50188+static void
50189+insert_inodev_entry(struct inodev_entry *entry)
50190+{
50191+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
50192+ inodev_set.i_size);
50193+ struct inodev_entry **curr;
50194+
50195+ entry->prev = NULL;
50196+
50197+ curr = &inodev_set.i_hash[index];
50198+ if (*curr != NULL)
50199+ (*curr)->prev = entry;
50200+
50201+ entry->next = *curr;
50202+ *curr = entry;
50203+
50204+ return;
50205+}
50206+
50207+static void
50208+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
50209+{
50210+ unsigned int index =
50211+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
50212+ struct acl_role_label **curr;
50213+ struct acl_role_label *tmp, *tmp2;
50214+
50215+ curr = &acl_role_set.r_hash[index];
50216+
50217+ /* simple case, slot is empty, just set it to our role */
50218+ if (*curr == NULL) {
50219+ *curr = role;
50220+ } else {
50221+ /* example:
50222+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
50223+ 2 -> 3
50224+ */
50225+ /* first check to see if we can already be reached via this slot */
50226+ tmp = *curr;
50227+ while (tmp && tmp != role)
50228+ tmp = tmp->next;
50229+ if (tmp == role) {
50230+ /* we don't need to add ourselves to this slot's chain */
50231+ return;
50232+ }
50233+ /* we need to add ourselves to this chain, two cases */
50234+ if (role->next == NULL) {
50235+ /* simple case, append the current chain to our role */
50236+ role->next = *curr;
50237+ *curr = role;
50238+ } else {
50239+ /* 1 -> 2 -> 3 -> 4
50240+ 2 -> 3 -> 4
50241+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
50242+ */
50243+ /* trickier case: walk our role's chain until we find
50244+ the role for the start of the current slot's chain */
50245+ tmp = role;
50246+ tmp2 = *curr;
50247+ while (tmp->next && tmp->next != tmp2)
50248+ tmp = tmp->next;
50249+ if (tmp->next == tmp2) {
50250+ /* from example above, we found 3, so just
50251+ replace this slot's chain with ours */
50252+ *curr = role;
50253+ } else {
50254+ /* we didn't find a subset of our role's chain
50255+ in the current slot's chain, so append their
50256+ chain to ours, and set us as the first role in
50257+ the slot's chain
50258+
50259+ we could fold this case with the case above,
50260+ but making it explicit for clarity
50261+ */
50262+ tmp->next = tmp2;
50263+ *curr = role;
50264+ }
50265+ }
50266+ }
50267+
50268+ return;
50269+}
50270+
50271+static void
50272+insert_acl_role_label(struct acl_role_label *role)
50273+{
50274+ int i;
50275+
50276+ if (role_list == NULL) {
50277+ role_list = role;
50278+ role->prev = NULL;
50279+ } else {
50280+ role->prev = role_list;
50281+ role_list = role;
50282+ }
50283+
50284+ /* used for hash chains */
50285+ role->next = NULL;
50286+
50287+ if (role->roletype & GR_ROLE_DOMAIN) {
50288+ for (i = 0; i < role->domain_child_num; i++)
50289+ __insert_acl_role_label(role, role->domain_children[i]);
50290+ } else
50291+ __insert_acl_role_label(role, role->uidgid);
50292+}
50293+
50294+static int
50295+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
50296+{
50297+ struct name_entry **curr, *nentry;
50298+ struct inodev_entry *ientry;
50299+ unsigned int len = strlen(name);
50300+ unsigned int key = full_name_hash(name, len);
50301+ unsigned int index = key % name_set.n_size;
50302+
50303+ curr = &name_set.n_hash[index];
50304+
50305+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
50306+ curr = &((*curr)->next);
50307+
50308+ if (*curr != NULL)
50309+ return 1;
50310+
50311+ nentry = acl_alloc(sizeof (struct name_entry));
50312+ if (nentry == NULL)
50313+ return 0;
50314+ ientry = acl_alloc(sizeof (struct inodev_entry));
50315+ if (ientry == NULL)
50316+ return 0;
50317+ ientry->nentry = nentry;
50318+
50319+ nentry->key = key;
50320+ nentry->name = name;
50321+ nentry->inode = inode;
50322+ nentry->device = device;
50323+ nentry->len = len;
50324+ nentry->deleted = deleted;
50325+
50326+ nentry->prev = NULL;
50327+ curr = &name_set.n_hash[index];
50328+ if (*curr != NULL)
50329+ (*curr)->prev = nentry;
50330+ nentry->next = *curr;
50331+ *curr = nentry;
50332+
50333+ /* insert us into the table searchable by inode/dev */
50334+ insert_inodev_entry(ientry);
50335+
50336+ return 1;
50337+}
50338+
50339+static void
50340+insert_acl_obj_label(struct acl_object_label *obj,
50341+ struct acl_subject_label *subj)
50342+{
50343+ unsigned int index =
50344+ fhash(obj->inode, obj->device, subj->obj_hash_size);
50345+ struct acl_object_label **curr;
50346+
50347+
50348+ obj->prev = NULL;
50349+
50350+ curr = &subj->obj_hash[index];
50351+ if (*curr != NULL)
50352+ (*curr)->prev = obj;
50353+
50354+ obj->next = *curr;
50355+ *curr = obj;
50356+
50357+ return;
50358+}
50359+
50360+static void
50361+insert_acl_subj_label(struct acl_subject_label *obj,
50362+ struct acl_role_label *role)
50363+{
50364+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
50365+ struct acl_subject_label **curr;
50366+
50367+ obj->prev = NULL;
50368+
50369+ curr = &role->subj_hash[index];
50370+ if (*curr != NULL)
50371+ (*curr)->prev = obj;
50372+
50373+ obj->next = *curr;
50374+ *curr = obj;
50375+
50376+ return;
50377+}
50378+
50379+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
50380+
50381+static void *
50382+create_table(__u32 * len, int elementsize)
50383+{
50384+ unsigned int table_sizes[] = {
50385+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
50386+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
50387+ 4194301, 8388593, 16777213, 33554393, 67108859
50388+ };
50389+ void *newtable = NULL;
50390+ unsigned int pwr = 0;
50391+
50392+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
50393+ table_sizes[pwr] <= *len)
50394+ pwr++;
50395+
50396+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
50397+ return newtable;
50398+
50399+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
50400+ newtable =
50401+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
50402+ else
50403+ newtable = vmalloc(table_sizes[pwr] * elementsize);
50404+
50405+ *len = table_sizes[pwr];
50406+
50407+ return newtable;
50408+}
50409+
50410+static int
50411+init_variables(const struct gr_arg *arg)
50412+{
50413+ struct task_struct *reaper = &init_task;
50414+ unsigned int stacksize;
50415+
50416+ subj_map_set.s_size = arg->role_db.num_subjects;
50417+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
50418+ name_set.n_size = arg->role_db.num_objects;
50419+ inodev_set.i_size = arg->role_db.num_objects;
50420+
50421+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
50422+ !name_set.n_size || !inodev_set.i_size)
50423+ return 1;
50424+
50425+ if (!gr_init_uidset())
50426+ return 1;
50427+
50428+ /* set up the stack that holds allocation info */
50429+
50430+ stacksize = arg->role_db.num_pointers + 5;
50431+
50432+ if (!acl_alloc_stack_init(stacksize))
50433+ return 1;
50434+
50435+ /* grab reference for the real root dentry and vfsmount */
50436+ get_fs_root(reaper->fs, &real_root);
50437+
50438+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
50439+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
50440+#endif
50441+
50442+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
50443+ if (fakefs_obj_rw == NULL)
50444+ return 1;
50445+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
50446+
50447+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
50448+ if (fakefs_obj_rwx == NULL)
50449+ return 1;
50450+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
50451+
50452+ subj_map_set.s_hash =
50453+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
50454+ acl_role_set.r_hash =
50455+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
50456+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
50457+ inodev_set.i_hash =
50458+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
50459+
50460+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
50461+ !name_set.n_hash || !inodev_set.i_hash)
50462+ return 1;
50463+
50464+ memset(subj_map_set.s_hash, 0,
50465+ sizeof(struct subject_map *) * subj_map_set.s_size);
50466+ memset(acl_role_set.r_hash, 0,
50467+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
50468+ memset(name_set.n_hash, 0,
50469+ sizeof (struct name_entry *) * name_set.n_size);
50470+ memset(inodev_set.i_hash, 0,
50471+ sizeof (struct inodev_entry *) * inodev_set.i_size);
50472+
50473+ return 0;
50474+}
50475+
50476+/* free information not needed after startup
50477+ currently contains user->kernel pointer mappings for subjects
50478+*/
50479+
50480+static void
50481+free_init_variables(void)
50482+{
50483+ __u32 i;
50484+
50485+ if (subj_map_set.s_hash) {
50486+ for (i = 0; i < subj_map_set.s_size; i++) {
50487+ if (subj_map_set.s_hash[i]) {
50488+ kfree(subj_map_set.s_hash[i]);
50489+ subj_map_set.s_hash[i] = NULL;
50490+ }
50491+ }
50492+
50493+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
50494+ PAGE_SIZE)
50495+ kfree(subj_map_set.s_hash);
50496+ else
50497+ vfree(subj_map_set.s_hash);
50498+ }
50499+
50500+ return;
50501+}
50502+
50503+static void
50504+free_variables(void)
50505+{
50506+ struct acl_subject_label *s;
50507+ struct acl_role_label *r;
50508+ struct task_struct *task, *task2;
50509+ unsigned int x;
50510+
50511+ gr_clear_learn_entries();
50512+
50513+ read_lock(&tasklist_lock);
50514+ do_each_thread(task2, task) {
50515+ task->acl_sp_role = 0;
50516+ task->acl_role_id = 0;
50517+ task->acl = NULL;
50518+ task->role = NULL;
50519+ } while_each_thread(task2, task);
50520+ read_unlock(&tasklist_lock);
50521+
50522+ /* release the reference to the real root dentry and vfsmount */
50523+ path_put(&real_root);
50524+ memset(&real_root, 0, sizeof(real_root));
50525+
50526+ /* free all object hash tables */
50527+
50528+ FOR_EACH_ROLE_START(r)
50529+ if (r->subj_hash == NULL)
50530+ goto next_role;
50531+ FOR_EACH_SUBJECT_START(r, s, x)
50532+ if (s->obj_hash == NULL)
50533+ break;
50534+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
50535+ kfree(s->obj_hash);
50536+ else
50537+ vfree(s->obj_hash);
50538+ FOR_EACH_SUBJECT_END(s, x)
50539+ FOR_EACH_NESTED_SUBJECT_START(r, s)
50540+ if (s->obj_hash == NULL)
50541+ break;
50542+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
50543+ kfree(s->obj_hash);
50544+ else
50545+ vfree(s->obj_hash);
50546+ FOR_EACH_NESTED_SUBJECT_END(s)
50547+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
50548+ kfree(r->subj_hash);
50549+ else
50550+ vfree(r->subj_hash);
50551+ r->subj_hash = NULL;
50552+next_role:
50553+ FOR_EACH_ROLE_END(r)
50554+
50555+ acl_free_all();
50556+
50557+ if (acl_role_set.r_hash) {
50558+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
50559+ PAGE_SIZE)
50560+ kfree(acl_role_set.r_hash);
50561+ else
50562+ vfree(acl_role_set.r_hash);
50563+ }
50564+ if (name_set.n_hash) {
50565+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
50566+ PAGE_SIZE)
50567+ kfree(name_set.n_hash);
50568+ else
50569+ vfree(name_set.n_hash);
50570+ }
50571+
50572+ if (inodev_set.i_hash) {
50573+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
50574+ PAGE_SIZE)
50575+ kfree(inodev_set.i_hash);
50576+ else
50577+ vfree(inodev_set.i_hash);
50578+ }
50579+
50580+ gr_free_uidset();
50581+
50582+ memset(&name_set, 0, sizeof (struct name_db));
50583+ memset(&inodev_set, 0, sizeof (struct inodev_db));
50584+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
50585+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
50586+
50587+ default_role = NULL;
50588+ kernel_role = NULL;
50589+ role_list = NULL;
50590+
50591+ return;
50592+}
50593+
50594+static __u32
50595+count_user_objs(struct acl_object_label *userp)
50596+{
50597+ struct acl_object_label o_tmp;
50598+ __u32 num = 0;
50599+
50600+ while (userp) {
50601+ if (copy_from_user(&o_tmp, userp,
50602+ sizeof (struct acl_object_label)))
50603+ break;
50604+
50605+ userp = o_tmp.prev;
50606+ num++;
50607+ }
50608+
50609+ return num;
50610+}
50611+
50612+static struct acl_subject_label *
50613+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
50614+
50615+static int
50616+copy_user_glob(struct acl_object_label *obj)
50617+{
50618+ struct acl_object_label *g_tmp, **guser;
50619+ unsigned int len;
50620+ char *tmp;
50621+
50622+ if (obj->globbed == NULL)
50623+ return 0;
50624+
50625+ guser = &obj->globbed;
50626+ while (*guser) {
50627+ g_tmp = (struct acl_object_label *)
50628+ acl_alloc(sizeof (struct acl_object_label));
50629+ if (g_tmp == NULL)
50630+ return -ENOMEM;
50631+
50632+ if (copy_from_user(g_tmp, *guser,
50633+ sizeof (struct acl_object_label)))
50634+ return -EFAULT;
50635+
50636+ len = strnlen_user(g_tmp->filename, PATH_MAX);
50637+
50638+ if (!len || len >= PATH_MAX)
50639+ return -EINVAL;
50640+
50641+ if ((tmp = (char *) acl_alloc(len)) == NULL)
50642+ return -ENOMEM;
50643+
50644+ if (copy_from_user(tmp, g_tmp->filename, len))
50645+ return -EFAULT;
50646+ tmp[len-1] = '\0';
50647+ g_tmp->filename = tmp;
50648+
50649+ *guser = g_tmp;
50650+ guser = &(g_tmp->next);
50651+ }
50652+
50653+ return 0;
50654+}
50655+
50656+static int
50657+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
50658+ struct acl_role_label *role)
50659+{
50660+ struct acl_object_label *o_tmp;
50661+ unsigned int len;
50662+ int ret;
50663+ char *tmp;
50664+
50665+ while (userp) {
50666+ if ((o_tmp = (struct acl_object_label *)
50667+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
50668+ return -ENOMEM;
50669+
50670+ if (copy_from_user(o_tmp, userp,
50671+ sizeof (struct acl_object_label)))
50672+ return -EFAULT;
50673+
50674+ userp = o_tmp->prev;
50675+
50676+ len = strnlen_user(o_tmp->filename, PATH_MAX);
50677+
50678+ if (!len || len >= PATH_MAX)
50679+ return -EINVAL;
50680+
50681+ if ((tmp = (char *) acl_alloc(len)) == NULL)
50682+ return -ENOMEM;
50683+
50684+ if (copy_from_user(tmp, o_tmp->filename, len))
50685+ return -EFAULT;
50686+ tmp[len-1] = '\0';
50687+ o_tmp->filename = tmp;
50688+
50689+ insert_acl_obj_label(o_tmp, subj);
50690+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
50691+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
50692+ return -ENOMEM;
50693+
50694+ ret = copy_user_glob(o_tmp);
50695+ if (ret)
50696+ return ret;
50697+
50698+ if (o_tmp->nested) {
50699+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
50700+ if (IS_ERR(o_tmp->nested))
50701+ return PTR_ERR(o_tmp->nested);
50702+
50703+ /* insert into nested subject list */
50704+ o_tmp->nested->next = role->hash->first;
50705+ role->hash->first = o_tmp->nested;
50706+ }
50707+ }
50708+
50709+ return 0;
50710+}
50711+
50712+static __u32
50713+count_user_subjs(struct acl_subject_label *userp)
50714+{
50715+ struct acl_subject_label s_tmp;
50716+ __u32 num = 0;
50717+
50718+ while (userp) {
50719+ if (copy_from_user(&s_tmp, userp,
50720+ sizeof (struct acl_subject_label)))
50721+ break;
50722+
50723+ userp = s_tmp.prev;
50724+ /* do not count nested subjects against this count, since
50725+ they are not included in the hash table, but are
50726+ attached to objects. We have already counted
50727+ the subjects in userspace for the allocation
50728+ stack
50729+ */
50730+ if (!(s_tmp.mode & GR_NESTED))
50731+ num++;
50732+ }
50733+
50734+ return num;
50735+}
50736+
50737+static int
50738+copy_user_allowedips(struct acl_role_label *rolep)
50739+{
50740+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
50741+
50742+ ruserip = rolep->allowed_ips;
50743+
50744+ while (ruserip) {
50745+ rlast = rtmp;
50746+
50747+ if ((rtmp = (struct role_allowed_ip *)
50748+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
50749+ return -ENOMEM;
50750+
50751+ if (copy_from_user(rtmp, ruserip,
50752+ sizeof (struct role_allowed_ip)))
50753+ return -EFAULT;
50754+
50755+ ruserip = rtmp->prev;
50756+
50757+ if (!rlast) {
50758+ rtmp->prev = NULL;
50759+ rolep->allowed_ips = rtmp;
50760+ } else {
50761+ rlast->next = rtmp;
50762+ rtmp->prev = rlast;
50763+ }
50764+
50765+ if (!ruserip)
50766+ rtmp->next = NULL;
50767+ }
50768+
50769+ return 0;
50770+}
50771+
50772+static int
50773+copy_user_transitions(struct acl_role_label *rolep)
50774+{
50775+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
50776+
50777+ unsigned int len;
50778+ char *tmp;
50779+
50780+ rusertp = rolep->transitions;
50781+
50782+ while (rusertp) {
50783+ rlast = rtmp;
50784+
50785+ if ((rtmp = (struct role_transition *)
50786+ acl_alloc(sizeof (struct role_transition))) == NULL)
50787+ return -ENOMEM;
50788+
50789+ if (copy_from_user(rtmp, rusertp,
50790+ sizeof (struct role_transition)))
50791+ return -EFAULT;
50792+
50793+ rusertp = rtmp->prev;
50794+
50795+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
50796+
50797+ if (!len || len >= GR_SPROLE_LEN)
50798+ return -EINVAL;
50799+
50800+ if ((tmp = (char *) acl_alloc(len)) == NULL)
50801+ return -ENOMEM;
50802+
50803+ if (copy_from_user(tmp, rtmp->rolename, len))
50804+ return -EFAULT;
50805+ tmp[len-1] = '\0';
50806+ rtmp->rolename = tmp;
50807+
50808+ if (!rlast) {
50809+ rtmp->prev = NULL;
50810+ rolep->transitions = rtmp;
50811+ } else {
50812+ rlast->next = rtmp;
50813+ rtmp->prev = rlast;
50814+ }
50815+
50816+ if (!rusertp)
50817+ rtmp->next = NULL;
50818+ }
50819+
50820+ return 0;
50821+}
50822+
50823+static struct acl_subject_label *
50824+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
50825+{
50826+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
50827+ unsigned int len;
50828+ char *tmp;
50829+ __u32 num_objs;
50830+ struct acl_ip_label **i_tmp, *i_utmp2;
50831+ struct gr_hash_struct ghash;
50832+ struct subject_map *subjmap;
50833+ unsigned int i_num;
50834+ int err;
50835+
50836+ s_tmp = lookup_subject_map(userp);
50837+
50838+ /* we've already copied this subject into the kernel, just return
50839+ the reference to it, and don't copy it over again
50840+ */
50841+ if (s_tmp)
50842+ return(s_tmp);
50843+
50844+ if ((s_tmp = (struct acl_subject_label *)
50845+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
50846+ return ERR_PTR(-ENOMEM);
50847+
50848+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
50849+ if (subjmap == NULL)
50850+ return ERR_PTR(-ENOMEM);
50851+
50852+ subjmap->user = userp;
50853+ subjmap->kernel = s_tmp;
50854+ insert_subj_map_entry(subjmap);
50855+
50856+ if (copy_from_user(s_tmp, userp,
50857+ sizeof (struct acl_subject_label)))
50858+ return ERR_PTR(-EFAULT);
50859+
50860+ len = strnlen_user(s_tmp->filename, PATH_MAX);
50861+
50862+ if (!len || len >= PATH_MAX)
50863+ return ERR_PTR(-EINVAL);
50864+
50865+ if ((tmp = (char *) acl_alloc(len)) == NULL)
50866+ return ERR_PTR(-ENOMEM);
50867+
50868+ if (copy_from_user(tmp, s_tmp->filename, len))
50869+ return ERR_PTR(-EFAULT);
50870+ tmp[len-1] = '\0';
50871+ s_tmp->filename = tmp;
50872+
50873+ if (!strcmp(s_tmp->filename, "/"))
50874+ role->root_label = s_tmp;
50875+
50876+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
50877+ return ERR_PTR(-EFAULT);
50878+
50879+ /* copy user and group transition tables */
50880+
50881+ if (s_tmp->user_trans_num) {
50882+ uid_t *uidlist;
50883+
50884+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
50885+ if (uidlist == NULL)
50886+ return ERR_PTR(-ENOMEM);
50887+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
50888+ return ERR_PTR(-EFAULT);
50889+
50890+ s_tmp->user_transitions = uidlist;
50891+ }
50892+
50893+ if (s_tmp->group_trans_num) {
50894+ gid_t *gidlist;
50895+
50896+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
50897+ if (gidlist == NULL)
50898+ return ERR_PTR(-ENOMEM);
50899+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
50900+ return ERR_PTR(-EFAULT);
50901+
50902+ s_tmp->group_transitions = gidlist;
50903+ }
50904+
50905+ /* set up object hash table */
50906+ num_objs = count_user_objs(ghash.first);
50907+
50908+ s_tmp->obj_hash_size = num_objs;
50909+ s_tmp->obj_hash =
50910+ (struct acl_object_label **)
50911+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
50912+
50913+ if (!s_tmp->obj_hash)
50914+ return ERR_PTR(-ENOMEM);
50915+
50916+ memset(s_tmp->obj_hash, 0,
50917+ s_tmp->obj_hash_size *
50918+ sizeof (struct acl_object_label *));
50919+
50920+ /* add in objects */
50921+ err = copy_user_objs(ghash.first, s_tmp, role);
50922+
50923+ if (err)
50924+ return ERR_PTR(err);
50925+
50926+ /* set pointer for parent subject */
50927+ if (s_tmp->parent_subject) {
50928+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
50929+
50930+ if (IS_ERR(s_tmp2))
50931+ return s_tmp2;
50932+
50933+ s_tmp->parent_subject = s_tmp2;
50934+ }
50935+
50936+ /* add in ip acls */
50937+
50938+ if (!s_tmp->ip_num) {
50939+ s_tmp->ips = NULL;
50940+ goto insert;
50941+ }
50942+
50943+ i_tmp =
50944+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
50945+ sizeof (struct acl_ip_label *));
50946+
50947+ if (!i_tmp)
50948+ return ERR_PTR(-ENOMEM);
50949+
50950+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
50951+ *(i_tmp + i_num) =
50952+ (struct acl_ip_label *)
50953+ acl_alloc(sizeof (struct acl_ip_label));
50954+ if (!*(i_tmp + i_num))
50955+ return ERR_PTR(-ENOMEM);
50956+
50957+ if (copy_from_user
50958+ (&i_utmp2, s_tmp->ips + i_num,
50959+ sizeof (struct acl_ip_label *)))
50960+ return ERR_PTR(-EFAULT);
50961+
50962+ if (copy_from_user
50963+ (*(i_tmp + i_num), i_utmp2,
50964+ sizeof (struct acl_ip_label)))
50965+ return ERR_PTR(-EFAULT);
50966+
50967+ if ((*(i_tmp + i_num))->iface == NULL)
50968+ continue;
50969+
50970+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
50971+ if (!len || len >= IFNAMSIZ)
50972+ return ERR_PTR(-EINVAL);
50973+ tmp = acl_alloc(len);
50974+ if (tmp == NULL)
50975+ return ERR_PTR(-ENOMEM);
50976+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
50977+ return ERR_PTR(-EFAULT);
50978+ (*(i_tmp + i_num))->iface = tmp;
50979+ }
50980+
50981+ s_tmp->ips = i_tmp;
50982+
50983+insert:
50984+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
50985+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
50986+ return ERR_PTR(-ENOMEM);
50987+
50988+ return s_tmp;
50989+}
50990+
50991+static int
50992+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
50993+{
50994+ struct acl_subject_label s_pre;
50995+ struct acl_subject_label * ret;
50996+ int err;
50997+
50998+ while (userp) {
50999+ if (copy_from_user(&s_pre, userp,
51000+ sizeof (struct acl_subject_label)))
51001+ return -EFAULT;
51002+
51003+ /* do not add nested subjects here, add
51004+ while parsing objects
51005+ */
51006+
51007+ if (s_pre.mode & GR_NESTED) {
51008+ userp = s_pre.prev;
51009+ continue;
51010+ }
51011+
51012+ ret = do_copy_user_subj(userp, role);
51013+
51014+ err = PTR_ERR(ret);
51015+ if (IS_ERR(ret))
51016+ return err;
51017+
51018+ insert_acl_subj_label(ret, role);
51019+
51020+ userp = s_pre.prev;
51021+ }
51022+
51023+ return 0;
51024+}
51025+
51026+static int
51027+copy_user_acl(struct gr_arg *arg)
51028+{
51029+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
51030+ struct sprole_pw *sptmp;
51031+ struct gr_hash_struct *ghash;
51032+ uid_t *domainlist;
51033+ unsigned int r_num;
51034+ unsigned int len;
51035+ char *tmp;
51036+ int err = 0;
51037+ __u16 i;
51038+ __u32 num_subjs;
51039+
51040+ /* we need a default and kernel role */
51041+ if (arg->role_db.num_roles < 2)
51042+ return -EINVAL;
51043+
51044+ /* copy special role authentication info from userspace */
51045+
51046+ num_sprole_pws = arg->num_sprole_pws;
51047+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
51048+
51049+ if (!acl_special_roles && num_sprole_pws)
51050+ return -ENOMEM;
51051+
51052+ for (i = 0; i < num_sprole_pws; i++) {
51053+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
51054+ if (!sptmp)
51055+ return -ENOMEM;
51056+ if (copy_from_user(sptmp, arg->sprole_pws + i,
51057+ sizeof (struct sprole_pw)))
51058+ return -EFAULT;
51059+
51060+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
51061+
51062+ if (!len || len >= GR_SPROLE_LEN)
51063+ return -EINVAL;
51064+
51065+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51066+ return -ENOMEM;
51067+
51068+ if (copy_from_user(tmp, sptmp->rolename, len))
51069+ return -EFAULT;
51070+
51071+ tmp[len-1] = '\0';
51072+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51073+ printk(KERN_ALERT "Copying special role %s\n", tmp);
51074+#endif
51075+ sptmp->rolename = tmp;
51076+ acl_special_roles[i] = sptmp;
51077+ }
51078+
51079+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
51080+
51081+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
51082+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
51083+
51084+ if (!r_tmp)
51085+ return -ENOMEM;
51086+
51087+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
51088+ sizeof (struct acl_role_label *)))
51089+ return -EFAULT;
51090+
51091+ if (copy_from_user(r_tmp, r_utmp2,
51092+ sizeof (struct acl_role_label)))
51093+ return -EFAULT;
51094+
51095+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
51096+
51097+ if (!len || len >= PATH_MAX)
51098+ return -EINVAL;
51099+
51100+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51101+ return -ENOMEM;
51102+
51103+ if (copy_from_user(tmp, r_tmp->rolename, len))
51104+ return -EFAULT;
51105+
51106+ tmp[len-1] = '\0';
51107+ r_tmp->rolename = tmp;
51108+
51109+ if (!strcmp(r_tmp->rolename, "default")
51110+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
51111+ default_role = r_tmp;
51112+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
51113+ kernel_role = r_tmp;
51114+ }
51115+
51116+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
51117+ return -ENOMEM;
51118+
51119+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
51120+ return -EFAULT;
51121+
51122+ r_tmp->hash = ghash;
51123+
51124+ num_subjs = count_user_subjs(r_tmp->hash->first);
51125+
51126+ r_tmp->subj_hash_size = num_subjs;
51127+ r_tmp->subj_hash =
51128+ (struct acl_subject_label **)
51129+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
51130+
51131+ if (!r_tmp->subj_hash)
51132+ return -ENOMEM;
51133+
51134+ err = copy_user_allowedips(r_tmp);
51135+ if (err)
51136+ return err;
51137+
51138+ /* copy domain info */
51139+ if (r_tmp->domain_children != NULL) {
51140+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
51141+ if (domainlist == NULL)
51142+ return -ENOMEM;
51143+
51144+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
51145+ return -EFAULT;
51146+
51147+ r_tmp->domain_children = domainlist;
51148+ }
51149+
51150+ err = copy_user_transitions(r_tmp);
51151+ if (err)
51152+ return err;
51153+
51154+ memset(r_tmp->subj_hash, 0,
51155+ r_tmp->subj_hash_size *
51156+ sizeof (struct acl_subject_label *));
51157+
51158+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
51159+
51160+ if (err)
51161+ return err;
51162+
51163+ /* set nested subject list to null */
51164+ r_tmp->hash->first = NULL;
51165+
51166+ insert_acl_role_label(r_tmp);
51167+ }
51168+
51169+ if (default_role == NULL || kernel_role == NULL)
51170+ return -EINVAL;
51171+
51172+ return err;
51173+}
51174+
51175+static int
51176+gracl_init(struct gr_arg *args)
51177+{
51178+ int error = 0;
51179+
51180+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
51181+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
51182+
51183+ if (init_variables(args)) {
51184+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
51185+ error = -ENOMEM;
51186+ free_variables();
51187+ goto out;
51188+ }
51189+
51190+ error = copy_user_acl(args);
51191+ free_init_variables();
51192+ if (error) {
51193+ free_variables();
51194+ goto out;
51195+ }
51196+
51197+ if ((error = gr_set_acls(0))) {
51198+ free_variables();
51199+ goto out;
51200+ }
51201+
51202+ pax_open_kernel();
51203+ gr_status |= GR_READY;
51204+ pax_close_kernel();
51205+
51206+ out:
51207+ return error;
51208+}
51209+
51210+/* derived from glibc fnmatch() 0: match, 1: no match*/
51211+
51212+static int
51213+glob_match(const char *p, const char *n)
51214+{
51215+ char c;
51216+
51217+ while ((c = *p++) != '\0') {
51218+ switch (c) {
51219+ case '?':
51220+ if (*n == '\0')
51221+ return 1;
51222+ else if (*n == '/')
51223+ return 1;
51224+ break;
51225+ case '\\':
51226+ if (*n != c)
51227+ return 1;
51228+ break;
51229+ case '*':
51230+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
51231+ if (*n == '/')
51232+ return 1;
51233+ else if (c == '?') {
51234+ if (*n == '\0')
51235+ return 1;
51236+ else
51237+ ++n;
51238+ }
51239+ }
51240+ if (c == '\0') {
51241+ return 0;
51242+ } else {
51243+ const char *endp;
51244+
51245+ if ((endp = strchr(n, '/')) == NULL)
51246+ endp = n + strlen(n);
51247+
51248+ if (c == '[') {
51249+ for (--p; n < endp; ++n)
51250+ if (!glob_match(p, n))
51251+ return 0;
51252+ } else if (c == '/') {
51253+ while (*n != '\0' && *n != '/')
51254+ ++n;
51255+ if (*n == '/' && !glob_match(p, n + 1))
51256+ return 0;
51257+ } else {
51258+ for (--p; n < endp; ++n)
51259+ if (*n == c && !glob_match(p, n))
51260+ return 0;
51261+ }
51262+
51263+ return 1;
51264+ }
51265+ case '[':
51266+ {
51267+ int not;
51268+ char cold;
51269+
51270+ if (*n == '\0' || *n == '/')
51271+ return 1;
51272+
51273+ not = (*p == '!' || *p == '^');
51274+ if (not)
51275+ ++p;
51276+
51277+ c = *p++;
51278+ for (;;) {
51279+ unsigned char fn = (unsigned char)*n;
51280+
51281+ if (c == '\0')
51282+ return 1;
51283+ else {
51284+ if (c == fn)
51285+ goto matched;
51286+ cold = c;
51287+ c = *p++;
51288+
51289+ if (c == '-' && *p != ']') {
51290+ unsigned char cend = *p++;
51291+
51292+ if (cend == '\0')
51293+ return 1;
51294+
51295+ if (cold <= fn && fn <= cend)
51296+ goto matched;
51297+
51298+ c = *p++;
51299+ }
51300+ }
51301+
51302+ if (c == ']')
51303+ break;
51304+ }
51305+ if (!not)
51306+ return 1;
51307+ break;
51308+ matched:
51309+ while (c != ']') {
51310+ if (c == '\0')
51311+ return 1;
51312+
51313+ c = *p++;
51314+ }
51315+ if (not)
51316+ return 1;
51317+ }
51318+ break;
51319+ default:
51320+ if (c != *n)
51321+ return 1;
51322+ }
51323+
51324+ ++n;
51325+ }
51326+
51327+ if (*n == '\0')
51328+ return 0;
51329+
51330+ if (*n == '/')
51331+ return 0;
51332+
51333+ return 1;
51334+}
51335+
51336+static struct acl_object_label *
51337+chk_glob_label(struct acl_object_label *globbed,
51338+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
51339+{
51340+ struct acl_object_label *tmp;
51341+
51342+ if (*path == NULL)
51343+ *path = gr_to_filename_nolock(dentry, mnt);
51344+
51345+ tmp = globbed;
51346+
51347+ while (tmp) {
51348+ if (!glob_match(tmp->filename, *path))
51349+ return tmp;
51350+ tmp = tmp->next;
51351+ }
51352+
51353+ return NULL;
51354+}
51355+
51356+static struct acl_object_label *
51357+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
51358+ const ino_t curr_ino, const dev_t curr_dev,
51359+ const struct acl_subject_label *subj, char **path, const int checkglob)
51360+{
51361+ struct acl_subject_label *tmpsubj;
51362+ struct acl_object_label *retval;
51363+ struct acl_object_label *retval2;
51364+
51365+ tmpsubj = (struct acl_subject_label *) subj;
51366+ read_lock(&gr_inode_lock);
51367+ do {
51368+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
51369+ if (retval) {
51370+ if (checkglob && retval->globbed) {
51371+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
51372+ if (retval2)
51373+ retval = retval2;
51374+ }
51375+ break;
51376+ }
51377+ } while ((tmpsubj = tmpsubj->parent_subject));
51378+ read_unlock(&gr_inode_lock);
51379+
51380+ return retval;
51381+}
51382+
51383+static __inline__ struct acl_object_label *
51384+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
51385+ struct dentry *curr_dentry,
51386+ const struct acl_subject_label *subj, char **path, const int checkglob)
51387+{
51388+ int newglob = checkglob;
51389+ ino_t inode;
51390+ dev_t device;
51391+
51392+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
51393+ as we don't want a / * rule to match instead of the / object
51394+ don't do this for create lookups that call this function though, since they're looking up
51395+ on the parent and thus need globbing checks on all paths
51396+ */
51397+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
51398+ newglob = GR_NO_GLOB;
51399+
51400+ spin_lock(&curr_dentry->d_lock);
51401+ inode = curr_dentry->d_inode->i_ino;
51402+ device = __get_dev(curr_dentry);
51403+ spin_unlock(&curr_dentry->d_lock);
51404+
51405+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
51406+}
51407+
51408+static struct acl_object_label *
51409+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51410+ const struct acl_subject_label *subj, char *path, const int checkglob)
51411+{
51412+ struct dentry *dentry = (struct dentry *) l_dentry;
51413+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
51414+ struct mount *real_mnt = real_mount(mnt);
51415+ struct acl_object_label *retval;
51416+ struct dentry *parent;
51417+
51418+ write_seqlock(&rename_lock);
51419+ br_read_lock(vfsmount_lock);
51420+
51421+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
51422+#ifdef CONFIG_NET
51423+ mnt == sock_mnt ||
51424+#endif
51425+#ifdef CONFIG_HUGETLBFS
51426+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
51427+#endif
51428+ /* ignore Eric Biederman */
51429+ IS_PRIVATE(l_dentry->d_inode))) {
51430+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
51431+ goto out;
51432+ }
51433+
51434+ for (;;) {
51435+ if (dentry == real_root.dentry && mnt == real_root.mnt)
51436+ break;
51437+
51438+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
51439+ if (!mnt_has_parent(real_mnt))
51440+ break;
51441+
51442+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
51443+ if (retval != NULL)
51444+ goto out;
51445+
51446+ dentry = real_mnt->mnt_mountpoint;
51447+ real_mnt = real_mnt->mnt_parent;
51448+ mnt = &real_mnt->mnt;
51449+ continue;
51450+ }
51451+
51452+ parent = dentry->d_parent;
51453+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
51454+ if (retval != NULL)
51455+ goto out;
51456+
51457+ dentry = parent;
51458+ }
51459+
51460+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
51461+
51462+ /* real_root is pinned so we don't have to hold a reference */
51463+ if (retval == NULL)
51464+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
51465+out:
51466+ br_read_unlock(vfsmount_lock);
51467+ write_sequnlock(&rename_lock);
51468+
51469+ BUG_ON(retval == NULL);
51470+
51471+ return retval;
51472+}
51473+
51474+static __inline__ struct acl_object_label *
51475+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51476+ const struct acl_subject_label *subj)
51477+{
51478+ char *path = NULL;
51479+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
51480+}
51481+
51482+static __inline__ struct acl_object_label *
51483+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51484+ const struct acl_subject_label *subj)
51485+{
51486+ char *path = NULL;
51487+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
51488+}
51489+
51490+static __inline__ struct acl_object_label *
51491+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51492+ const struct acl_subject_label *subj, char *path)
51493+{
51494+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
51495+}
51496+
51497+static struct acl_subject_label *
51498+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51499+ const struct acl_role_label *role)
51500+{
51501+ struct dentry *dentry = (struct dentry *) l_dentry;
51502+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
51503+ struct mount *real_mnt = real_mount(mnt);
51504+ struct acl_subject_label *retval;
51505+ struct dentry *parent;
51506+
51507+ write_seqlock(&rename_lock);
51508+ br_read_lock(vfsmount_lock);
51509+
51510+ for (;;) {
51511+ if (dentry == real_root.dentry && mnt == real_root.mnt)
51512+ break;
51513+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
51514+ if (!mnt_has_parent(real_mnt))
51515+ break;
51516+
51517+ spin_lock(&dentry->d_lock);
51518+ read_lock(&gr_inode_lock);
51519+ retval =
51520+ lookup_acl_subj_label(dentry->d_inode->i_ino,
51521+ __get_dev(dentry), role);
51522+ read_unlock(&gr_inode_lock);
51523+ spin_unlock(&dentry->d_lock);
51524+ if (retval != NULL)
51525+ goto out;
51526+
51527+ dentry = real_mnt->mnt_mountpoint;
51528+ real_mnt = real_mnt->mnt_parent;
51529+ mnt = &real_mnt->mnt;
51530+ continue;
51531+ }
51532+
51533+ spin_lock(&dentry->d_lock);
51534+ read_lock(&gr_inode_lock);
51535+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
51536+ __get_dev(dentry), role);
51537+ read_unlock(&gr_inode_lock);
51538+ parent = dentry->d_parent;
51539+ spin_unlock(&dentry->d_lock);
51540+
51541+ if (retval != NULL)
51542+ goto out;
51543+
51544+ dentry = parent;
51545+ }
51546+
51547+ spin_lock(&dentry->d_lock);
51548+ read_lock(&gr_inode_lock);
51549+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
51550+ __get_dev(dentry), role);
51551+ read_unlock(&gr_inode_lock);
51552+ spin_unlock(&dentry->d_lock);
51553+
51554+ if (unlikely(retval == NULL)) {
51555+ /* real_root is pinned, we don't need to hold a reference */
51556+ read_lock(&gr_inode_lock);
51557+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
51558+ __get_dev(real_root.dentry), role);
51559+ read_unlock(&gr_inode_lock);
51560+ }
51561+out:
51562+ br_read_unlock(vfsmount_lock);
51563+ write_sequnlock(&rename_lock);
51564+
51565+ BUG_ON(retval == NULL);
51566+
51567+ return retval;
51568+}
51569+
51570+static void
51571+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
51572+{
51573+ struct task_struct *task = current;
51574+ const struct cred *cred = current_cred();
51575+
51576+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
51577+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
51578+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
51579+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
51580+
51581+ return;
51582+}
51583+
51584+static void
51585+gr_log_learn_sysctl(const char *path, const __u32 mode)
51586+{
51587+ struct task_struct *task = current;
51588+ const struct cred *cred = current_cred();
51589+
51590+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
51591+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
51592+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
51593+ 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
51594+
51595+ return;
51596+}
51597+
51598+static void
51599+gr_log_learn_id_change(const char type, const unsigned int real,
51600+ const unsigned int effective, const unsigned int fs)
51601+{
51602+ struct task_struct *task = current;
51603+ const struct cred *cred = current_cred();
51604+
51605+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
51606+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
51607+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
51608+ type, real, effective, fs, &task->signal->saved_ip);
51609+
51610+ return;
51611+}
51612+
51613+__u32
51614+gr_search_file(const struct dentry * dentry, const __u32 mode,
51615+ const struct vfsmount * mnt)
51616+{
51617+ __u32 retval = mode;
51618+ struct acl_subject_label *curracl;
51619+ struct acl_object_label *currobj;
51620+
51621+ if (unlikely(!(gr_status & GR_READY)))
51622+ return (mode & ~GR_AUDITS);
51623+
51624+ curracl = current->acl;
51625+
51626+ currobj = chk_obj_label(dentry, mnt, curracl);
51627+ retval = currobj->mode & mode;
51628+
51629+ /* if we're opening a specified transfer file for writing
51630+ (e.g. /dev/initctl), then transfer our role to init
51631+ */
51632+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
51633+ current->role->roletype & GR_ROLE_PERSIST)) {
51634+ struct task_struct *task = init_pid_ns.child_reaper;
51635+
51636+ if (task->role != current->role) {
51637+ task->acl_sp_role = 0;
51638+ task->acl_role_id = current->acl_role_id;
51639+ task->role = current->role;
51640+ rcu_read_lock();
51641+ read_lock(&grsec_exec_file_lock);
51642+ gr_apply_subject_to_task(task);
51643+ read_unlock(&grsec_exec_file_lock);
51644+ rcu_read_unlock();
51645+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
51646+ }
51647+ }
51648+
51649+ if (unlikely
51650+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
51651+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
51652+ __u32 new_mode = mode;
51653+
51654+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
51655+
51656+ retval = new_mode;
51657+
51658+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
51659+ new_mode |= GR_INHERIT;
51660+
51661+ if (!(mode & GR_NOLEARN))
51662+ gr_log_learn(dentry, mnt, new_mode);
51663+ }
51664+
51665+ return retval;
51666+}
51667+
51668+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
51669+ const struct dentry *parent,
51670+ const struct vfsmount *mnt)
51671+{
51672+ struct name_entry *match;
51673+ struct acl_object_label *matchpo;
51674+ struct acl_subject_label *curracl;
51675+ char *path;
51676+
51677+ if (unlikely(!(gr_status & GR_READY)))
51678+ return NULL;
51679+
51680+ preempt_disable();
51681+ path = gr_to_filename_rbac(new_dentry, mnt);
51682+ match = lookup_name_entry_create(path);
51683+
51684+ curracl = current->acl;
51685+
51686+ if (match) {
51687+ read_lock(&gr_inode_lock);
51688+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
51689+ read_unlock(&gr_inode_lock);
51690+
51691+ if (matchpo) {
51692+ preempt_enable();
51693+ return matchpo;
51694+ }
51695+ }
51696+
51697+ // lookup parent
51698+
51699+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
51700+
51701+ preempt_enable();
51702+ return matchpo;
51703+}
51704+
51705+__u32
51706+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
51707+ const struct vfsmount * mnt, const __u32 mode)
51708+{
51709+ struct acl_object_label *matchpo;
51710+ __u32 retval;
51711+
51712+ if (unlikely(!(gr_status & GR_READY)))
51713+ return (mode & ~GR_AUDITS);
51714+
51715+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
51716+
51717+ retval = matchpo->mode & mode;
51718+
51719+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
51720+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
51721+ __u32 new_mode = mode;
51722+
51723+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
51724+
51725+ gr_log_learn(new_dentry, mnt, new_mode);
51726+ return new_mode;
51727+ }
51728+
51729+ return retval;
51730+}
51731+
51732+__u32
51733+gr_check_link(const struct dentry * new_dentry,
51734+ const struct dentry * parent_dentry,
51735+ const struct vfsmount * parent_mnt,
51736+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
51737+{
51738+ struct acl_object_label *obj;
51739+ __u32 oldmode, newmode;
51740+ __u32 needmode;
51741+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
51742+ GR_DELETE | GR_INHERIT;
51743+
51744+ if (unlikely(!(gr_status & GR_READY)))
51745+ return (GR_CREATE | GR_LINK);
51746+
51747+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
51748+ oldmode = obj->mode;
51749+
51750+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
51751+ newmode = obj->mode;
51752+
51753+ needmode = newmode & checkmodes;
51754+
51755+ // old name for hardlink must have at least the permissions of the new name
51756+ if ((oldmode & needmode) != needmode)
51757+ goto bad;
51758+
51759+ // if old name had restrictions/auditing, make sure the new name does as well
51760+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
51761+
51762+ // don't allow hardlinking of suid/sgid files without permission
51763+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
51764+ needmode |= GR_SETID;
51765+
51766+ if ((newmode & needmode) != needmode)
51767+ goto bad;
51768+
51769+ // enforce minimum permissions
51770+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
51771+ return newmode;
51772+bad:
51773+ needmode = oldmode;
51774+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
51775+ needmode |= GR_SETID;
51776+
51777+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
51778+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
51779+ return (GR_CREATE | GR_LINK);
51780+ } else if (newmode & GR_SUPPRESS)
51781+ return GR_SUPPRESS;
51782+ else
51783+ return 0;
51784+}
51785+
51786+int
51787+gr_check_hidden_task(const struct task_struct *task)
51788+{
51789+ if (unlikely(!(gr_status & GR_READY)))
51790+ return 0;
51791+
51792+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
51793+ return 1;
51794+
51795+ return 0;
51796+}
51797+
51798+int
51799+gr_check_protected_task(const struct task_struct *task)
51800+{
51801+ if (unlikely(!(gr_status & GR_READY) || !task))
51802+ return 0;
51803+
51804+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
51805+ task->acl != current->acl)
51806+ return 1;
51807+
51808+ return 0;
51809+}
51810+
51811+int
51812+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
51813+{
51814+ struct task_struct *p;
51815+ int ret = 0;
51816+
51817+ if (unlikely(!(gr_status & GR_READY) || !pid))
51818+ return ret;
51819+
51820+ read_lock(&tasklist_lock);
51821+ do_each_pid_task(pid, type, p) {
51822+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
51823+ p->acl != current->acl) {
51824+ ret = 1;
51825+ goto out;
51826+ }
51827+ } while_each_pid_task(pid, type, p);
51828+out:
51829+ read_unlock(&tasklist_lock);
51830+
51831+ return ret;
51832+}
51833+
51834+void
51835+gr_copy_label(struct task_struct *tsk)
51836+{
51837+ /* plain copying of fields is already done by dup_task_struct */
51838+ tsk->signal->used_accept = 0;
51839+ tsk->acl_sp_role = 0;
51840+ //tsk->acl_role_id = current->acl_role_id;
51841+ //tsk->acl = current->acl;
51842+ //tsk->role = current->role;
51843+ tsk->signal->curr_ip = current->signal->curr_ip;
51844+ tsk->signal->saved_ip = current->signal->saved_ip;
51845+ if (current->exec_file)
51846+ get_file(current->exec_file);
51847+ //tsk->exec_file = current->exec_file;
51848+ //tsk->is_writable = current->is_writable;
51849+ if (unlikely(current->signal->used_accept)) {
51850+ current->signal->curr_ip = 0;
51851+ current->signal->saved_ip = 0;
51852+ }
51853+
51854+ return;
51855+}
51856+
51857+static void
51858+gr_set_proc_res(struct task_struct *task)
51859+{
51860+ struct acl_subject_label *proc;
51861+ unsigned short i;
51862+
51863+ proc = task->acl;
51864+
51865+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
51866+ return;
51867+
51868+ for (i = 0; i < RLIM_NLIMITS; i++) {
51869+ if (!(proc->resmask & (1 << i)))
51870+ continue;
51871+
51872+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
51873+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
51874+ }
51875+
51876+ return;
51877+}
51878+
51879+extern int __gr_process_user_ban(struct user_struct *user);
51880+
51881+int
51882+gr_check_user_change(int real, int effective, int fs)
51883+{
51884+ unsigned int i;
51885+ __u16 num;
51886+ uid_t *uidlist;
51887+ int curuid;
51888+ int realok = 0;
51889+ int effectiveok = 0;
51890+ int fsok = 0;
51891+
51892+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
51893+ struct user_struct *user;
51894+
51895+ if (real == -1)
51896+ goto skipit;
51897+
51898+ user = find_user(real);
51899+ if (user == NULL)
51900+ goto skipit;
51901+
51902+ if (__gr_process_user_ban(user)) {
51903+ /* for find_user */
51904+ free_uid(user);
51905+ return 1;
51906+ }
51907+
51908+ /* for find_user */
51909+ free_uid(user);
51910+
51911+skipit:
51912+#endif
51913+
51914+ if (unlikely(!(gr_status & GR_READY)))
51915+ return 0;
51916+
51917+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
51918+ gr_log_learn_id_change('u', real, effective, fs);
51919+
51920+ num = current->acl->user_trans_num;
51921+ uidlist = current->acl->user_transitions;
51922+
51923+ if (uidlist == NULL)
51924+ return 0;
51925+
51926+ if (real == -1)
51927+ realok = 1;
51928+ if (effective == -1)
51929+ effectiveok = 1;
51930+ if (fs == -1)
51931+ fsok = 1;
51932+
51933+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
51934+ for (i = 0; i < num; i++) {
51935+ curuid = (int)uidlist[i];
51936+ if (real == curuid)
51937+ realok = 1;
51938+ if (effective == curuid)
51939+ effectiveok = 1;
51940+ if (fs == curuid)
51941+ fsok = 1;
51942+ }
51943+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
51944+ for (i = 0; i < num; i++) {
51945+ curuid = (int)uidlist[i];
51946+ if (real == curuid)
51947+ break;
51948+ if (effective == curuid)
51949+ break;
51950+ if (fs == curuid)
51951+ break;
51952+ }
51953+ /* not in deny list */
51954+ if (i == num) {
51955+ realok = 1;
51956+ effectiveok = 1;
51957+ fsok = 1;
51958+ }
51959+ }
51960+
51961+ if (realok && effectiveok && fsok)
51962+ return 0;
51963+ else {
51964+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
51965+ return 1;
51966+ }
51967+}
51968+
51969+int
51970+gr_check_group_change(int real, int effective, int fs)
51971+{
51972+ unsigned int i;
51973+ __u16 num;
51974+ gid_t *gidlist;
51975+ int curgid;
51976+ int realok = 0;
51977+ int effectiveok = 0;
51978+ int fsok = 0;
51979+
51980+ if (unlikely(!(gr_status & GR_READY)))
51981+ return 0;
51982+
51983+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
51984+ gr_log_learn_id_change('g', real, effective, fs);
51985+
51986+ num = current->acl->group_trans_num;
51987+ gidlist = current->acl->group_transitions;
51988+
51989+ if (gidlist == NULL)
51990+ return 0;
51991+
51992+ if (real == -1)
51993+ realok = 1;
51994+ if (effective == -1)
51995+ effectiveok = 1;
51996+ if (fs == -1)
51997+ fsok = 1;
51998+
51999+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
52000+ for (i = 0; i < num; i++) {
52001+ curgid = (int)gidlist[i];
52002+ if (real == curgid)
52003+ realok = 1;
52004+ if (effective == curgid)
52005+ effectiveok = 1;
52006+ if (fs == curgid)
52007+ fsok = 1;
52008+ }
52009+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
52010+ for (i = 0; i < num; i++) {
52011+ curgid = (int)gidlist[i];
52012+ if (real == curgid)
52013+ break;
52014+ if (effective == curgid)
52015+ break;
52016+ if (fs == curgid)
52017+ break;
52018+ }
52019+ /* not in deny list */
52020+ if (i == num) {
52021+ realok = 1;
52022+ effectiveok = 1;
52023+ fsok = 1;
52024+ }
52025+ }
52026+
52027+ if (realok && effectiveok && fsok)
52028+ return 0;
52029+ else {
52030+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
52031+ return 1;
52032+ }
52033+}
52034+
52035+extern int gr_acl_is_capable(const int cap);
52036+
52037+void
52038+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
52039+{
52040+ struct acl_role_label *role = task->role;
52041+ struct acl_subject_label *subj = NULL;
52042+ struct acl_object_label *obj;
52043+ struct file *filp;
52044+
52045+ if (unlikely(!(gr_status & GR_READY)))
52046+ return;
52047+
52048+ filp = task->exec_file;
52049+
52050+ /* kernel process, we'll give them the kernel role */
52051+ if (unlikely(!filp)) {
52052+ task->role = kernel_role;
52053+ task->acl = kernel_role->root_label;
52054+ return;
52055+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
52056+ role = lookup_acl_role_label(task, uid, gid);
52057+
52058+ /* don't change the role if we're not a privileged process */
52059+ if (role && task->role != role &&
52060+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
52061+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
52062+ return;
52063+
52064+ /* perform subject lookup in possibly new role
52065+ we can use this result below in the case where role == task->role
52066+ */
52067+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
52068+
52069+ /* if we changed uid/gid, but result in the same role
52070+ and are using inheritance, don't lose the inherited subject
52071+ if current subject is other than what normal lookup
52072+ would result in, we arrived via inheritance, don't
52073+ lose subject
52074+ */
52075+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
52076+ (subj == task->acl)))
52077+ task->acl = subj;
52078+
52079+ task->role = role;
52080+
52081+ task->is_writable = 0;
52082+
52083+ /* ignore additional mmap checks for processes that are writable
52084+ by the default ACL */
52085+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
52086+ if (unlikely(obj->mode & GR_WRITE))
52087+ task->is_writable = 1;
52088+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
52089+ if (unlikely(obj->mode & GR_WRITE))
52090+ task->is_writable = 1;
52091+
52092+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52093+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
52094+#endif
52095+
52096+ gr_set_proc_res(task);
52097+
52098+ return;
52099+}
52100+
52101+int
52102+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
52103+ const int unsafe_flags)
52104+{
52105+ struct task_struct *task = current;
52106+ struct acl_subject_label *newacl;
52107+ struct acl_object_label *obj;
52108+ __u32 retmode;
52109+
52110+ if (unlikely(!(gr_status & GR_READY)))
52111+ return 0;
52112+
52113+ newacl = chk_subj_label(dentry, mnt, task->role);
52114+
52115+ task_lock(task);
52116+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
52117+ !(task->role->roletype & GR_ROLE_GOD) &&
52118+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
52119+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52120+ task_unlock(task);
52121+ if (unsafe_flags & LSM_UNSAFE_SHARE)
52122+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
52123+ else
52124+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
52125+ return -EACCES;
52126+ }
52127+ task_unlock(task);
52128+
52129+ obj = chk_obj_label(dentry, mnt, task->acl);
52130+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
52131+
52132+ if (!(task->acl->mode & GR_INHERITLEARN) &&
52133+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
52134+ if (obj->nested)
52135+ task->acl = obj->nested;
52136+ else
52137+ task->acl = newacl;
52138+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
52139+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
52140+
52141+ task->is_writable = 0;
52142+
52143+ /* ignore additional mmap checks for processes that are writable
52144+ by the default ACL */
52145+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
52146+ if (unlikely(obj->mode & GR_WRITE))
52147+ task->is_writable = 1;
52148+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
52149+ if (unlikely(obj->mode & GR_WRITE))
52150+ task->is_writable = 1;
52151+
52152+ gr_set_proc_res(task);
52153+
52154+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52155+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
52156+#endif
52157+ return 0;
52158+}
52159+
52160+/* always called with valid inodev ptr */
52161+static void
52162+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
52163+{
52164+ struct acl_object_label *matchpo;
52165+ struct acl_subject_label *matchps;
52166+ struct acl_subject_label *subj;
52167+ struct acl_role_label *role;
52168+ unsigned int x;
52169+
52170+ FOR_EACH_ROLE_START(role)
52171+ FOR_EACH_SUBJECT_START(role, subj, x)
52172+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
52173+ matchpo->mode |= GR_DELETED;
52174+ FOR_EACH_SUBJECT_END(subj,x)
52175+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
52176+ if (subj->inode == ino && subj->device == dev)
52177+ subj->mode |= GR_DELETED;
52178+ FOR_EACH_NESTED_SUBJECT_END(subj)
52179+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
52180+ matchps->mode |= GR_DELETED;
52181+ FOR_EACH_ROLE_END(role)
52182+
52183+ inodev->nentry->deleted = 1;
52184+
52185+ return;
52186+}
52187+
52188+void
52189+gr_handle_delete(const ino_t ino, const dev_t dev)
52190+{
52191+ struct inodev_entry *inodev;
52192+
52193+ if (unlikely(!(gr_status & GR_READY)))
52194+ return;
52195+
52196+ write_lock(&gr_inode_lock);
52197+ inodev = lookup_inodev_entry(ino, dev);
52198+ if (inodev != NULL)
52199+ do_handle_delete(inodev, ino, dev);
52200+ write_unlock(&gr_inode_lock);
52201+
52202+ return;
52203+}
52204+
52205+static void
52206+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
52207+ const ino_t newinode, const dev_t newdevice,
52208+ struct acl_subject_label *subj)
52209+{
52210+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
52211+ struct acl_object_label *match;
52212+
52213+ match = subj->obj_hash[index];
52214+
52215+ while (match && (match->inode != oldinode ||
52216+ match->device != olddevice ||
52217+ !(match->mode & GR_DELETED)))
52218+ match = match->next;
52219+
52220+ if (match && (match->inode == oldinode)
52221+ && (match->device == olddevice)
52222+ && (match->mode & GR_DELETED)) {
52223+ if (match->prev == NULL) {
52224+ subj->obj_hash[index] = match->next;
52225+ if (match->next != NULL)
52226+ match->next->prev = NULL;
52227+ } else {
52228+ match->prev->next = match->next;
52229+ if (match->next != NULL)
52230+ match->next->prev = match->prev;
52231+ }
52232+ match->prev = NULL;
52233+ match->next = NULL;
52234+ match->inode = newinode;
52235+ match->device = newdevice;
52236+ match->mode &= ~GR_DELETED;
52237+
52238+ insert_acl_obj_label(match, subj);
52239+ }
52240+
52241+ return;
52242+}
52243+
52244+static void
52245+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
52246+ const ino_t newinode, const dev_t newdevice,
52247+ struct acl_role_label *role)
52248+{
52249+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
52250+ struct acl_subject_label *match;
52251+
52252+ match = role->subj_hash[index];
52253+
52254+ while (match && (match->inode != oldinode ||
52255+ match->device != olddevice ||
52256+ !(match->mode & GR_DELETED)))
52257+ match = match->next;
52258+
52259+ if (match && (match->inode == oldinode)
52260+ && (match->device == olddevice)
52261+ && (match->mode & GR_DELETED)) {
52262+ if (match->prev == NULL) {
52263+ role->subj_hash[index] = match->next;
52264+ if (match->next != NULL)
52265+ match->next->prev = NULL;
52266+ } else {
52267+ match->prev->next = match->next;
52268+ if (match->next != NULL)
52269+ match->next->prev = match->prev;
52270+ }
52271+ match->prev = NULL;
52272+ match->next = NULL;
52273+ match->inode = newinode;
52274+ match->device = newdevice;
52275+ match->mode &= ~GR_DELETED;
52276+
52277+ insert_acl_subj_label(match, role);
52278+ }
52279+
52280+ return;
52281+}
52282+
52283+static void
52284+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
52285+ const ino_t newinode, const dev_t newdevice)
52286+{
52287+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
52288+ struct inodev_entry *match;
52289+
52290+ match = inodev_set.i_hash[index];
52291+
52292+ while (match && (match->nentry->inode != oldinode ||
52293+ match->nentry->device != olddevice || !match->nentry->deleted))
52294+ match = match->next;
52295+
52296+ if (match && (match->nentry->inode == oldinode)
52297+ && (match->nentry->device == olddevice) &&
52298+ match->nentry->deleted) {
52299+ if (match->prev == NULL) {
52300+ inodev_set.i_hash[index] = match->next;
52301+ if (match->next != NULL)
52302+ match->next->prev = NULL;
52303+ } else {
52304+ match->prev->next = match->next;
52305+ if (match->next != NULL)
52306+ match->next->prev = match->prev;
52307+ }
52308+ match->prev = NULL;
52309+ match->next = NULL;
52310+ match->nentry->inode = newinode;
52311+ match->nentry->device = newdevice;
52312+ match->nentry->deleted = 0;
52313+
52314+ insert_inodev_entry(match);
52315+ }
52316+
52317+ return;
52318+}
52319+
52320+static void
52321+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
52322+{
52323+ struct acl_subject_label *subj;
52324+ struct acl_role_label *role;
52325+ unsigned int x;
52326+
52327+ FOR_EACH_ROLE_START(role)
52328+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
52329+
52330+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
52331+ if ((subj->inode == ino) && (subj->device == dev)) {
52332+ subj->inode = ino;
52333+ subj->device = dev;
52334+ }
52335+ FOR_EACH_NESTED_SUBJECT_END(subj)
52336+ FOR_EACH_SUBJECT_START(role, subj, x)
52337+ update_acl_obj_label(matchn->inode, matchn->device,
52338+ ino, dev, subj);
52339+ FOR_EACH_SUBJECT_END(subj,x)
52340+ FOR_EACH_ROLE_END(role)
52341+
52342+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
52343+
52344+ return;
52345+}
52346+
52347+static void
52348+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
52349+ const struct vfsmount *mnt)
52350+{
52351+ ino_t ino = dentry->d_inode->i_ino;
52352+ dev_t dev = __get_dev(dentry);
52353+
52354+ __do_handle_create(matchn, ino, dev);
52355+
52356+ return;
52357+}
52358+
52359+void
52360+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
52361+{
52362+ struct name_entry *matchn;
52363+
52364+ if (unlikely(!(gr_status & GR_READY)))
52365+ return;
52366+
52367+ preempt_disable();
52368+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
52369+
52370+ if (unlikely((unsigned long)matchn)) {
52371+ write_lock(&gr_inode_lock);
52372+ do_handle_create(matchn, dentry, mnt);
52373+ write_unlock(&gr_inode_lock);
52374+ }
52375+ preempt_enable();
52376+
52377+ return;
52378+}
52379+
52380+void
52381+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
52382+{
52383+ struct name_entry *matchn;
52384+
52385+ if (unlikely(!(gr_status & GR_READY)))
52386+ return;
52387+
52388+ preempt_disable();
52389+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
52390+
52391+ if (unlikely((unsigned long)matchn)) {
52392+ write_lock(&gr_inode_lock);
52393+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
52394+ write_unlock(&gr_inode_lock);
52395+ }
52396+ preempt_enable();
52397+
52398+ return;
52399+}
52400+
52401+void
52402+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
52403+ struct dentry *old_dentry,
52404+ struct dentry *new_dentry,
52405+ struct vfsmount *mnt, const __u8 replace)
52406+{
52407+ struct name_entry *matchn;
52408+ struct inodev_entry *inodev;
52409+ struct inode *inode = new_dentry->d_inode;
52410+ ino_t old_ino = old_dentry->d_inode->i_ino;
52411+ dev_t old_dev = __get_dev(old_dentry);
52412+
52413+ /* vfs_rename swaps the name and parent link for old_dentry and
52414+ new_dentry
52415+ at this point, old_dentry has the new name, parent link, and inode
52416+ for the renamed file
52417+ if a file is being replaced by a rename, new_dentry has the inode
52418+ and name for the replaced file
52419+ */
52420+
52421+ if (unlikely(!(gr_status & GR_READY)))
52422+ return;
52423+
52424+ preempt_disable();
52425+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
52426+
52427+ /* we wouldn't have to check d_inode if it weren't for
52428+ NFS silly-renaming
52429+ */
52430+
52431+ write_lock(&gr_inode_lock);
52432+ if (unlikely(replace && inode)) {
52433+ ino_t new_ino = inode->i_ino;
52434+ dev_t new_dev = __get_dev(new_dentry);
52435+
52436+ inodev = lookup_inodev_entry(new_ino, new_dev);
52437+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
52438+ do_handle_delete(inodev, new_ino, new_dev);
52439+ }
52440+
52441+ inodev = lookup_inodev_entry(old_ino, old_dev);
52442+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
52443+ do_handle_delete(inodev, old_ino, old_dev);
52444+
52445+ if (unlikely((unsigned long)matchn))
52446+ do_handle_create(matchn, old_dentry, mnt);
52447+
52448+ write_unlock(&gr_inode_lock);
52449+ preempt_enable();
52450+
52451+ return;
52452+}
52453+
52454+static int
52455+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
52456+ unsigned char **sum)
52457+{
52458+ struct acl_role_label *r;
52459+ struct role_allowed_ip *ipp;
52460+ struct role_transition *trans;
52461+ unsigned int i;
52462+ int found = 0;
52463+ u32 curr_ip = current->signal->curr_ip;
52464+
52465+ current->signal->saved_ip = curr_ip;
52466+
52467+ /* check transition table */
52468+
52469+ for (trans = current->role->transitions; trans; trans = trans->next) {
52470+ if (!strcmp(rolename, trans->rolename)) {
52471+ found = 1;
52472+ break;
52473+ }
52474+ }
52475+
52476+ if (!found)
52477+ return 0;
52478+
52479+ /* handle special roles that do not require authentication
52480+ and check ip */
52481+
52482+ FOR_EACH_ROLE_START(r)
52483+ if (!strcmp(rolename, r->rolename) &&
52484+ (r->roletype & GR_ROLE_SPECIAL)) {
52485+ found = 0;
52486+ if (r->allowed_ips != NULL) {
52487+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
52488+ if ((ntohl(curr_ip) & ipp->netmask) ==
52489+ (ntohl(ipp->addr) & ipp->netmask))
52490+ found = 1;
52491+ }
52492+ } else
52493+ found = 2;
52494+ if (!found)
52495+ return 0;
52496+
52497+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
52498+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
52499+ *salt = NULL;
52500+ *sum = NULL;
52501+ return 1;
52502+ }
52503+ }
52504+ FOR_EACH_ROLE_END(r)
52505+
52506+ for (i = 0; i < num_sprole_pws; i++) {
52507+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
52508+ *salt = acl_special_roles[i]->salt;
52509+ *sum = acl_special_roles[i]->sum;
52510+ return 1;
52511+ }
52512+ }
52513+
52514+ return 0;
52515+}
52516+
52517+static void
52518+assign_special_role(char *rolename)
52519+{
52520+ struct acl_object_label *obj;
52521+ struct acl_role_label *r;
52522+ struct acl_role_label *assigned = NULL;
52523+ struct task_struct *tsk;
52524+ struct file *filp;
52525+
52526+ FOR_EACH_ROLE_START(r)
52527+ if (!strcmp(rolename, r->rolename) &&
52528+ (r->roletype & GR_ROLE_SPECIAL)) {
52529+ assigned = r;
52530+ break;
52531+ }
52532+ FOR_EACH_ROLE_END(r)
52533+
52534+ if (!assigned)
52535+ return;
52536+
52537+ read_lock(&tasklist_lock);
52538+ read_lock(&grsec_exec_file_lock);
52539+
52540+ tsk = current->real_parent;
52541+ if (tsk == NULL)
52542+ goto out_unlock;
52543+
52544+ filp = tsk->exec_file;
52545+ if (filp == NULL)
52546+ goto out_unlock;
52547+
52548+ tsk->is_writable = 0;
52549+
52550+ tsk->acl_sp_role = 1;
52551+ tsk->acl_role_id = ++acl_sp_role_value;
52552+ tsk->role = assigned;
52553+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
52554+
52555+ /* ignore additional mmap checks for processes that are writable
52556+ by the default ACL */
52557+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
52558+ if (unlikely(obj->mode & GR_WRITE))
52559+ tsk->is_writable = 1;
52560+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
52561+ if (unlikely(obj->mode & GR_WRITE))
52562+ tsk->is_writable = 1;
52563+
52564+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52565+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
52566+#endif
52567+
52568+out_unlock:
52569+ read_unlock(&grsec_exec_file_lock);
52570+ read_unlock(&tasklist_lock);
52571+ return;
52572+}
52573+
52574+int gr_check_secure_terminal(struct task_struct *task)
52575+{
52576+ struct task_struct *p, *p2, *p3;
52577+ struct files_struct *files;
52578+ struct fdtable *fdt;
52579+ struct file *our_file = NULL, *file;
52580+ int i;
52581+
52582+ if (task->signal->tty == NULL)
52583+ return 1;
52584+
52585+ files = get_files_struct(task);
52586+ if (files != NULL) {
52587+ rcu_read_lock();
52588+ fdt = files_fdtable(files);
52589+ for (i=0; i < fdt->max_fds; i++) {
52590+ file = fcheck_files(files, i);
52591+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
52592+ get_file(file);
52593+ our_file = file;
52594+ }
52595+ }
52596+ rcu_read_unlock();
52597+ put_files_struct(files);
52598+ }
52599+
52600+ if (our_file == NULL)
52601+ return 1;
52602+
52603+ read_lock(&tasklist_lock);
52604+ do_each_thread(p2, p) {
52605+ files = get_files_struct(p);
52606+ if (files == NULL ||
52607+ (p->signal && p->signal->tty == task->signal->tty)) {
52608+ if (files != NULL)
52609+ put_files_struct(files);
52610+ continue;
52611+ }
52612+ rcu_read_lock();
52613+ fdt = files_fdtable(files);
52614+ for (i=0; i < fdt->max_fds; i++) {
52615+ file = fcheck_files(files, i);
52616+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
52617+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
52618+ p3 = task;
52619+ while (p3->pid > 0) {
52620+ if (p3 == p)
52621+ break;
52622+ p3 = p3->real_parent;
52623+ }
52624+ if (p3 == p)
52625+ break;
52626+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
52627+ gr_handle_alertkill(p);
52628+ rcu_read_unlock();
52629+ put_files_struct(files);
52630+ read_unlock(&tasklist_lock);
52631+ fput(our_file);
52632+ return 0;
52633+ }
52634+ }
52635+ rcu_read_unlock();
52636+ put_files_struct(files);
52637+ } while_each_thread(p2, p);
52638+ read_unlock(&tasklist_lock);
52639+
52640+ fput(our_file);
52641+ return 1;
52642+}
52643+
52644+ssize_t
52645+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
52646+{
52647+ struct gr_arg_wrapper uwrap;
52648+ unsigned char *sprole_salt = NULL;
52649+ unsigned char *sprole_sum = NULL;
52650+ int error = sizeof (struct gr_arg_wrapper);
52651+ int error2 = 0;
52652+
52653+ mutex_lock(&gr_dev_mutex);
52654+
52655+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
52656+ error = -EPERM;
52657+ goto out;
52658+ }
52659+
52660+ if (count != sizeof (struct gr_arg_wrapper)) {
52661+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
52662+ error = -EINVAL;
52663+ goto out;
52664+ }
52665+
52666+
52667+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
52668+ gr_auth_expires = 0;
52669+ gr_auth_attempts = 0;
52670+ }
52671+
52672+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
52673+ error = -EFAULT;
52674+ goto out;
52675+ }
52676+
52677+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
52678+ error = -EINVAL;
52679+ goto out;
52680+ }
52681+
52682+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
52683+ error = -EFAULT;
52684+ goto out;
52685+ }
52686+
52687+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
52688+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
52689+ time_after(gr_auth_expires, get_seconds())) {
52690+ error = -EBUSY;
52691+ goto out;
52692+ }
52693+
52694+ /* if non-root trying to do anything other than use a special role,
52695+ do not attempt authentication, do not count towards authentication
52696+ locking
52697+ */
52698+
52699+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
52700+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
52701+ current_uid()) {
52702+ error = -EPERM;
52703+ goto out;
52704+ }
52705+
52706+ /* ensure pw and special role name are null terminated */
52707+
52708+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
52709+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
52710+
52711+ /* Okay.
52712+ * We have our enough of the argument structure..(we have yet
52713+ * to copy_from_user the tables themselves) . Copy the tables
52714+ * only if we need them, i.e. for loading operations. */
52715+
52716+ switch (gr_usermode->mode) {
52717+ case GR_STATUS:
52718+ if (gr_status & GR_READY) {
52719+ error = 1;
52720+ if (!gr_check_secure_terminal(current))
52721+ error = 3;
52722+ } else
52723+ error = 2;
52724+ goto out;
52725+ case GR_SHUTDOWN:
52726+ if ((gr_status & GR_READY)
52727+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
52728+ pax_open_kernel();
52729+ gr_status &= ~GR_READY;
52730+ pax_close_kernel();
52731+
52732+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
52733+ free_variables();
52734+ memset(gr_usermode, 0, sizeof (struct gr_arg));
52735+ memset(gr_system_salt, 0, GR_SALT_LEN);
52736+ memset(gr_system_sum, 0, GR_SHA_LEN);
52737+ } else if (gr_status & GR_READY) {
52738+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
52739+ error = -EPERM;
52740+ } else {
52741+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
52742+ error = -EAGAIN;
52743+ }
52744+ break;
52745+ case GR_ENABLE:
52746+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
52747+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
52748+ else {
52749+ if (gr_status & GR_READY)
52750+ error = -EAGAIN;
52751+ else
52752+ error = error2;
52753+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
52754+ }
52755+ break;
52756+ case GR_RELOAD:
52757+ if (!(gr_status & GR_READY)) {
52758+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
52759+ error = -EAGAIN;
52760+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
52761+ preempt_disable();
52762+
52763+ pax_open_kernel();
52764+ gr_status &= ~GR_READY;
52765+ pax_close_kernel();
52766+
52767+ free_variables();
52768+ if (!(error2 = gracl_init(gr_usermode))) {
52769+ preempt_enable();
52770+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
52771+ } else {
52772+ preempt_enable();
52773+ error = error2;
52774+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
52775+ }
52776+ } else {
52777+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
52778+ error = -EPERM;
52779+ }
52780+ break;
52781+ case GR_SEGVMOD:
52782+ if (unlikely(!(gr_status & GR_READY))) {
52783+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
52784+ error = -EAGAIN;
52785+ break;
52786+ }
52787+
52788+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
52789+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
52790+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
52791+ struct acl_subject_label *segvacl;
52792+ segvacl =
52793+ lookup_acl_subj_label(gr_usermode->segv_inode,
52794+ gr_usermode->segv_device,
52795+ current->role);
52796+ if (segvacl) {
52797+ segvacl->crashes = 0;
52798+ segvacl->expires = 0;
52799+ }
52800+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
52801+ gr_remove_uid(gr_usermode->segv_uid);
52802+ }
52803+ } else {
52804+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
52805+ error = -EPERM;
52806+ }
52807+ break;
52808+ case GR_SPROLE:
52809+ case GR_SPROLEPAM:
52810+ if (unlikely(!(gr_status & GR_READY))) {
52811+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
52812+ error = -EAGAIN;
52813+ break;
52814+ }
52815+
52816+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
52817+ current->role->expires = 0;
52818+ current->role->auth_attempts = 0;
52819+ }
52820+
52821+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
52822+ time_after(current->role->expires, get_seconds())) {
52823+ error = -EBUSY;
52824+ goto out;
52825+ }
52826+
52827+ if (lookup_special_role_auth
52828+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
52829+ && ((!sprole_salt && !sprole_sum)
52830+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
52831+ char *p = "";
52832+ assign_special_role(gr_usermode->sp_role);
52833+ read_lock(&tasklist_lock);
52834+ if (current->real_parent)
52835+ p = current->real_parent->role->rolename;
52836+ read_unlock(&tasklist_lock);
52837+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
52838+ p, acl_sp_role_value);
52839+ } else {
52840+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
52841+ error = -EPERM;
52842+ if(!(current->role->auth_attempts++))
52843+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
52844+
52845+ goto out;
52846+ }
52847+ break;
52848+ case GR_UNSPROLE:
52849+ if (unlikely(!(gr_status & GR_READY))) {
52850+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
52851+ error = -EAGAIN;
52852+ break;
52853+ }
52854+
52855+ if (current->role->roletype & GR_ROLE_SPECIAL) {
52856+ char *p = "";
52857+ int i = 0;
52858+
52859+ read_lock(&tasklist_lock);
52860+ if (current->real_parent) {
52861+ p = current->real_parent->role->rolename;
52862+ i = current->real_parent->acl_role_id;
52863+ }
52864+ read_unlock(&tasklist_lock);
52865+
52866+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
52867+ gr_set_acls(1);
52868+ } else {
52869+ error = -EPERM;
52870+ goto out;
52871+ }
52872+ break;
52873+ default:
52874+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
52875+ error = -EINVAL;
52876+ break;
52877+ }
52878+
52879+ if (error != -EPERM)
52880+ goto out;
52881+
52882+ if(!(gr_auth_attempts++))
52883+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
52884+
52885+ out:
52886+ mutex_unlock(&gr_dev_mutex);
52887+ return error;
52888+}
52889+
52890+/* must be called with
52891+ rcu_read_lock();
52892+ read_lock(&tasklist_lock);
52893+ read_lock(&grsec_exec_file_lock);
52894+*/
52895+int gr_apply_subject_to_task(struct task_struct *task)
52896+{
52897+ struct acl_object_label *obj;
52898+ char *tmpname;
52899+ struct acl_subject_label *tmpsubj;
52900+ struct file *filp;
52901+ struct name_entry *nmatch;
52902+
52903+ filp = task->exec_file;
52904+ if (filp == NULL)
52905+ return 0;
52906+
52907+ /* the following is to apply the correct subject
52908+ on binaries running when the RBAC system
52909+ is enabled, when the binaries have been
52910+ replaced or deleted since their execution
52911+ -----
52912+ when the RBAC system starts, the inode/dev
52913+ from exec_file will be one the RBAC system
52914+ is unaware of. It only knows the inode/dev
52915+ of the present file on disk, or the absence
52916+ of it.
52917+ */
52918+ preempt_disable();
52919+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
52920+
52921+ nmatch = lookup_name_entry(tmpname);
52922+ preempt_enable();
52923+ tmpsubj = NULL;
52924+ if (nmatch) {
52925+ if (nmatch->deleted)
52926+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
52927+ else
52928+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
52929+ if (tmpsubj != NULL)
52930+ task->acl = tmpsubj;
52931+ }
52932+ if (tmpsubj == NULL)
52933+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
52934+ task->role);
52935+ if (task->acl) {
52936+ task->is_writable = 0;
52937+ /* ignore additional mmap checks for processes that are writable
52938+ by the default ACL */
52939+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
52940+ if (unlikely(obj->mode & GR_WRITE))
52941+ task->is_writable = 1;
52942+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
52943+ if (unlikely(obj->mode & GR_WRITE))
52944+ task->is_writable = 1;
52945+
52946+ gr_set_proc_res(task);
52947+
52948+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52949+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
52950+#endif
52951+ } else {
52952+ return 1;
52953+ }
52954+
52955+ return 0;
52956+}
52957+
52958+int
52959+gr_set_acls(const int type)
52960+{
52961+ struct task_struct *task, *task2;
52962+ struct acl_role_label *role = current->role;
52963+ __u16 acl_role_id = current->acl_role_id;
52964+ const struct cred *cred;
52965+ int ret;
52966+
52967+ rcu_read_lock();
52968+ read_lock(&tasklist_lock);
52969+ read_lock(&grsec_exec_file_lock);
52970+ do_each_thread(task2, task) {
52971+ /* check to see if we're called from the exit handler,
52972+ if so, only replace ACLs that have inherited the admin
52973+ ACL */
52974+
52975+ if (type && (task->role != role ||
52976+ task->acl_role_id != acl_role_id))
52977+ continue;
52978+
52979+ task->acl_role_id = 0;
52980+ task->acl_sp_role = 0;
52981+
52982+ if (task->exec_file) {
52983+ cred = __task_cred(task);
52984+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
52985+ ret = gr_apply_subject_to_task(task);
52986+ if (ret) {
52987+ read_unlock(&grsec_exec_file_lock);
52988+ read_unlock(&tasklist_lock);
52989+ rcu_read_unlock();
52990+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
52991+ return ret;
52992+ }
52993+ } else {
52994+ // it's a kernel process
52995+ task->role = kernel_role;
52996+ task->acl = kernel_role->root_label;
52997+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
52998+ task->acl->mode &= ~GR_PROCFIND;
52999+#endif
53000+ }
53001+ } while_each_thread(task2, task);
53002+ read_unlock(&grsec_exec_file_lock);
53003+ read_unlock(&tasklist_lock);
53004+ rcu_read_unlock();
53005+
53006+ return 0;
53007+}
53008+
53009+void
53010+gr_learn_resource(const struct task_struct *task,
53011+ const int res, const unsigned long wanted, const int gt)
53012+{
53013+ struct acl_subject_label *acl;
53014+ const struct cred *cred;
53015+
53016+ if (unlikely((gr_status & GR_READY) &&
53017+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
53018+ goto skip_reslog;
53019+
53020+#ifdef CONFIG_GRKERNSEC_RESLOG
53021+ gr_log_resource(task, res, wanted, gt);
53022+#endif
53023+ skip_reslog:
53024+
53025+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
53026+ return;
53027+
53028+ acl = task->acl;
53029+
53030+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
53031+ !(acl->resmask & (1 << (unsigned short) res))))
53032+ return;
53033+
53034+ if (wanted >= acl->res[res].rlim_cur) {
53035+ unsigned long res_add;
53036+
53037+ res_add = wanted;
53038+ switch (res) {
53039+ case RLIMIT_CPU:
53040+ res_add += GR_RLIM_CPU_BUMP;
53041+ break;
53042+ case RLIMIT_FSIZE:
53043+ res_add += GR_RLIM_FSIZE_BUMP;
53044+ break;
53045+ case RLIMIT_DATA:
53046+ res_add += GR_RLIM_DATA_BUMP;
53047+ break;
53048+ case RLIMIT_STACK:
53049+ res_add += GR_RLIM_STACK_BUMP;
53050+ break;
53051+ case RLIMIT_CORE:
53052+ res_add += GR_RLIM_CORE_BUMP;
53053+ break;
53054+ case RLIMIT_RSS:
53055+ res_add += GR_RLIM_RSS_BUMP;
53056+ break;
53057+ case RLIMIT_NPROC:
53058+ res_add += GR_RLIM_NPROC_BUMP;
53059+ break;
53060+ case RLIMIT_NOFILE:
53061+ res_add += GR_RLIM_NOFILE_BUMP;
53062+ break;
53063+ case RLIMIT_MEMLOCK:
53064+ res_add += GR_RLIM_MEMLOCK_BUMP;
53065+ break;
53066+ case RLIMIT_AS:
53067+ res_add += GR_RLIM_AS_BUMP;
53068+ break;
53069+ case RLIMIT_LOCKS:
53070+ res_add += GR_RLIM_LOCKS_BUMP;
53071+ break;
53072+ case RLIMIT_SIGPENDING:
53073+ res_add += GR_RLIM_SIGPENDING_BUMP;
53074+ break;
53075+ case RLIMIT_MSGQUEUE:
53076+ res_add += GR_RLIM_MSGQUEUE_BUMP;
53077+ break;
53078+ case RLIMIT_NICE:
53079+ res_add += GR_RLIM_NICE_BUMP;
53080+ break;
53081+ case RLIMIT_RTPRIO:
53082+ res_add += GR_RLIM_RTPRIO_BUMP;
53083+ break;
53084+ case RLIMIT_RTTIME:
53085+ res_add += GR_RLIM_RTTIME_BUMP;
53086+ break;
53087+ }
53088+
53089+ acl->res[res].rlim_cur = res_add;
53090+
53091+ if (wanted > acl->res[res].rlim_max)
53092+ acl->res[res].rlim_max = res_add;
53093+
53094+ /* only log the subject filename, since resource logging is supported for
53095+ single-subject learning only */
53096+ rcu_read_lock();
53097+ cred = __task_cred(task);
53098+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
53099+ task->role->roletype, cred->uid, cred->gid, acl->filename,
53100+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
53101+ "", (unsigned long) res, &task->signal->saved_ip);
53102+ rcu_read_unlock();
53103+ }
53104+
53105+ return;
53106+}
53107+
53108+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
53109+void
53110+pax_set_initial_flags(struct linux_binprm *bprm)
53111+{
53112+ struct task_struct *task = current;
53113+ struct acl_subject_label *proc;
53114+ unsigned long flags;
53115+
53116+ if (unlikely(!(gr_status & GR_READY)))
53117+ return;
53118+
53119+ flags = pax_get_flags(task);
53120+
53121+ proc = task->acl;
53122+
53123+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
53124+ flags &= ~MF_PAX_PAGEEXEC;
53125+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
53126+ flags &= ~MF_PAX_SEGMEXEC;
53127+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
53128+ flags &= ~MF_PAX_RANDMMAP;
53129+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
53130+ flags &= ~MF_PAX_EMUTRAMP;
53131+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
53132+ flags &= ~MF_PAX_MPROTECT;
53133+
53134+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
53135+ flags |= MF_PAX_PAGEEXEC;
53136+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
53137+ flags |= MF_PAX_SEGMEXEC;
53138+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
53139+ flags |= MF_PAX_RANDMMAP;
53140+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
53141+ flags |= MF_PAX_EMUTRAMP;
53142+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
53143+ flags |= MF_PAX_MPROTECT;
53144+
53145+ pax_set_flags(task, flags);
53146+
53147+ return;
53148+}
53149+#endif
53150+
53151+#ifdef CONFIG_SYSCTL
53152+/* Eric Biederman likes breaking userland ABI and every inode-based security
53153+ system to save 35kb of memory */
53154+
53155+/* we modify the passed in filename, but adjust it back before returning */
53156+static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
53157+{
53158+ struct name_entry *nmatch;
53159+ char *p, *lastp = NULL;
53160+ struct acl_object_label *obj = NULL, *tmp;
53161+ struct acl_subject_label *tmpsubj;
53162+ char c = '\0';
53163+
53164+ read_lock(&gr_inode_lock);
53165+
53166+ p = name + len - 1;
53167+ do {
53168+ nmatch = lookup_name_entry(name);
53169+ if (lastp != NULL)
53170+ *lastp = c;
53171+
53172+ if (nmatch == NULL)
53173+ goto next_component;
53174+ tmpsubj = current->acl;
53175+ do {
53176+ obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
53177+ if (obj != NULL) {
53178+ tmp = obj->globbed;
53179+ while (tmp) {
53180+ if (!glob_match(tmp->filename, name)) {
53181+ obj = tmp;
53182+ goto found_obj;
53183+ }
53184+ tmp = tmp->next;
53185+ }
53186+ goto found_obj;
53187+ }
53188+ } while ((tmpsubj = tmpsubj->parent_subject));
53189+next_component:
53190+ /* end case */
53191+ if (p == name)
53192+ break;
53193+
53194+ while (*p != '/')
53195+ p--;
53196+ if (p == name)
53197+ lastp = p + 1;
53198+ else {
53199+ lastp = p;
53200+ p--;
53201+ }
53202+ c = *lastp;
53203+ *lastp = '\0';
53204+ } while (1);
53205+found_obj:
53206+ read_unlock(&gr_inode_lock);
53207+ /* obj returned will always be non-null */
53208+ return obj;
53209+}
53210+
53211+/* returns 0 when allowing, non-zero on error
53212+ op of 0 is used for readdir, so we don't log the names of hidden files
53213+*/
53214+__u32
53215+gr_handle_sysctl(const struct ctl_table *table, const int op)
53216+{
53217+ struct ctl_table *tmp;
53218+ const char *proc_sys = "/proc/sys";
53219+ char *path;
53220+ struct acl_object_label *obj;
53221+ unsigned short len = 0, pos = 0, depth = 0, i;
53222+ __u32 err = 0;
53223+ __u32 mode = 0;
53224+
53225+ if (unlikely(!(gr_status & GR_READY)))
53226+ return 0;
53227+
53228+ /* for now, ignore operations on non-sysctl entries if it's not a
53229+ readdir*/
53230+ if (table->child != NULL && op != 0)
53231+ return 0;
53232+
53233+ mode |= GR_FIND;
53234+ /* it's only a read if it's an entry, read on dirs is for readdir */
53235+ if (op & MAY_READ)
53236+ mode |= GR_READ;
53237+ if (op & MAY_WRITE)
53238+ mode |= GR_WRITE;
53239+
53240+ preempt_disable();
53241+
53242+ path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
53243+
53244+ /* it's only a read/write if it's an actual entry, not a dir
53245+ (which are opened for readdir)
53246+ */
53247+
53248+ /* convert the requested sysctl entry into a pathname */
53249+
53250+ for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
53251+ len += strlen(tmp->procname);
53252+ len++;
53253+ depth++;
53254+ }
53255+
53256+ if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
53257+ /* deny */
53258+ goto out;
53259+ }
53260+
53261+ memset(path, 0, PAGE_SIZE);
53262+
53263+ memcpy(path, proc_sys, strlen(proc_sys));
53264+
53265+ pos += strlen(proc_sys);
53266+
53267+ for (; depth > 0; depth--) {
53268+ path[pos] = '/';
53269+ pos++;
53270+ for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
53271+ if (depth == i) {
53272+ memcpy(path + pos, tmp->procname,
53273+ strlen(tmp->procname));
53274+ pos += strlen(tmp->procname);
53275+ }
53276+ i++;
53277+ }
53278+ }
53279+
53280+ obj = gr_lookup_by_name(path, pos);
53281+ err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
53282+
53283+ if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
53284+ ((err & mode) != mode))) {
53285+ __u32 new_mode = mode;
53286+
53287+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53288+
53289+ err = 0;
53290+ gr_log_learn_sysctl(path, new_mode);
53291+ } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
53292+ gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
53293+ err = -ENOENT;
53294+ } else if (!(err & GR_FIND)) {
53295+ err = -ENOENT;
53296+ } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
53297+ gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
53298+ path, (mode & GR_READ) ? " reading" : "",
53299+ (mode & GR_WRITE) ? " writing" : "");
53300+ err = -EACCES;
53301+ } else if ((err & mode) != mode) {
53302+ err = -EACCES;
53303+ } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
53304+ gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
53305+ path, (mode & GR_READ) ? " reading" : "",
53306+ (mode & GR_WRITE) ? " writing" : "");
53307+ err = 0;
53308+ } else
53309+ err = 0;
53310+
53311+ out:
53312+ preempt_enable();
53313+
53314+ return err;
53315+}
53316+#endif
53317+
53318+int
53319+gr_handle_proc_ptrace(struct task_struct *task)
53320+{
53321+ struct file *filp;
53322+ struct task_struct *tmp = task;
53323+ struct task_struct *curtemp = current;
53324+ __u32 retmode;
53325+
53326+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
53327+ if (unlikely(!(gr_status & GR_READY)))
53328+ return 0;
53329+#endif
53330+
53331+ read_lock(&tasklist_lock);
53332+ read_lock(&grsec_exec_file_lock);
53333+ filp = task->exec_file;
53334+
53335+ while (tmp->pid > 0) {
53336+ if (tmp == curtemp)
53337+ break;
53338+ tmp = tmp->real_parent;
53339+ }
53340+
53341+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
53342+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
53343+ read_unlock(&grsec_exec_file_lock);
53344+ read_unlock(&tasklist_lock);
53345+ return 1;
53346+ }
53347+
53348+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
53349+ if (!(gr_status & GR_READY)) {
53350+ read_unlock(&grsec_exec_file_lock);
53351+ read_unlock(&tasklist_lock);
53352+ return 0;
53353+ }
53354+#endif
53355+
53356+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
53357+ read_unlock(&grsec_exec_file_lock);
53358+ read_unlock(&tasklist_lock);
53359+
53360+ if (retmode & GR_NOPTRACE)
53361+ return 1;
53362+
53363+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
53364+ && (current->acl != task->acl || (current->acl != current->role->root_label
53365+ && current->pid != task->pid)))
53366+ return 1;
53367+
53368+ return 0;
53369+}
53370+
53371+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
53372+{
53373+ if (unlikely(!(gr_status & GR_READY)))
53374+ return;
53375+
53376+ if (!(current->role->roletype & GR_ROLE_GOD))
53377+ return;
53378+
53379+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
53380+ p->role->rolename, gr_task_roletype_to_char(p),
53381+ p->acl->filename);
53382+}
53383+
53384+int
53385+gr_handle_ptrace(struct task_struct *task, const long request)
53386+{
53387+ struct task_struct *tmp = task;
53388+ struct task_struct *curtemp = current;
53389+ __u32 retmode;
53390+
53391+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
53392+ if (unlikely(!(gr_status & GR_READY)))
53393+ return 0;
53394+#endif
53395+
53396+ read_lock(&tasklist_lock);
53397+ while (tmp->pid > 0) {
53398+ if (tmp == curtemp)
53399+ break;
53400+ tmp = tmp->real_parent;
53401+ }
53402+
53403+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
53404+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
53405+ read_unlock(&tasklist_lock);
53406+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53407+ return 1;
53408+ }
53409+ read_unlock(&tasklist_lock);
53410+
53411+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
53412+ if (!(gr_status & GR_READY))
53413+ return 0;
53414+#endif
53415+
53416+ read_lock(&grsec_exec_file_lock);
53417+ if (unlikely(!task->exec_file)) {
53418+ read_unlock(&grsec_exec_file_lock);
53419+ return 0;
53420+ }
53421+
53422+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
53423+ read_unlock(&grsec_exec_file_lock);
53424+
53425+ if (retmode & GR_NOPTRACE) {
53426+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53427+ return 1;
53428+ }
53429+
53430+ if (retmode & GR_PTRACERD) {
53431+ switch (request) {
53432+ case PTRACE_SEIZE:
53433+ case PTRACE_POKETEXT:
53434+ case PTRACE_POKEDATA:
53435+ case PTRACE_POKEUSR:
53436+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
53437+ case PTRACE_SETREGS:
53438+ case PTRACE_SETFPREGS:
53439+#endif
53440+#ifdef CONFIG_X86
53441+ case PTRACE_SETFPXREGS:
53442+#endif
53443+#ifdef CONFIG_ALTIVEC
53444+ case PTRACE_SETVRREGS:
53445+#endif
53446+ return 1;
53447+ default:
53448+ return 0;
53449+ }
53450+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
53451+ !(current->role->roletype & GR_ROLE_GOD) &&
53452+ (current->acl != task->acl)) {
53453+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53454+ return 1;
53455+ }
53456+
53457+ return 0;
53458+}
53459+
53460+static int is_writable_mmap(const struct file *filp)
53461+{
53462+ struct task_struct *task = current;
53463+ struct acl_object_label *obj, *obj2;
53464+
53465+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
53466+ !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))) {
53467+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53468+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
53469+ task->role->root_label);
53470+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
53471+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
53472+ return 1;
53473+ }
53474+ }
53475+ return 0;
53476+}
53477+
53478+int
53479+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
53480+{
53481+ __u32 mode;
53482+
53483+ if (unlikely(!file || !(prot & PROT_EXEC)))
53484+ return 1;
53485+
53486+ if (is_writable_mmap(file))
53487+ return 0;
53488+
53489+ mode =
53490+ gr_search_file(file->f_path.dentry,
53491+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
53492+ file->f_path.mnt);
53493+
53494+ if (!gr_tpe_allow(file))
53495+ return 0;
53496+
53497+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
53498+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53499+ return 0;
53500+ } else if (unlikely(!(mode & GR_EXEC))) {
53501+ return 0;
53502+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
53503+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53504+ return 1;
53505+ }
53506+
53507+ return 1;
53508+}
53509+
53510+int
53511+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
53512+{
53513+ __u32 mode;
53514+
53515+ if (unlikely(!file || !(prot & PROT_EXEC)))
53516+ return 1;
53517+
53518+ if (is_writable_mmap(file))
53519+ return 0;
53520+
53521+ mode =
53522+ gr_search_file(file->f_path.dentry,
53523+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
53524+ file->f_path.mnt);
53525+
53526+ if (!gr_tpe_allow(file))
53527+ return 0;
53528+
53529+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
53530+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53531+ return 0;
53532+ } else if (unlikely(!(mode & GR_EXEC))) {
53533+ return 0;
53534+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
53535+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53536+ return 1;
53537+ }
53538+
53539+ return 1;
53540+}
53541+
53542+void
53543+gr_acl_handle_psacct(struct task_struct *task, const long code)
53544+{
53545+ unsigned long runtime;
53546+ unsigned long cputime;
53547+ unsigned int wday, cday;
53548+ __u8 whr, chr;
53549+ __u8 wmin, cmin;
53550+ __u8 wsec, csec;
53551+ struct timespec timeval;
53552+
53553+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
53554+ !(task->acl->mode & GR_PROCACCT)))
53555+ return;
53556+
53557+ do_posix_clock_monotonic_gettime(&timeval);
53558+ runtime = timeval.tv_sec - task->start_time.tv_sec;
53559+ wday = runtime / (3600 * 24);
53560+ runtime -= wday * (3600 * 24);
53561+ whr = runtime / 3600;
53562+ runtime -= whr * 3600;
53563+ wmin = runtime / 60;
53564+ runtime -= wmin * 60;
53565+ wsec = runtime;
53566+
53567+ cputime = (task->utime + task->stime) / HZ;
53568+ cday = cputime / (3600 * 24);
53569+ cputime -= cday * (3600 * 24);
53570+ chr = cputime / 3600;
53571+ cputime -= chr * 3600;
53572+ cmin = cputime / 60;
53573+ cputime -= cmin * 60;
53574+ csec = cputime;
53575+
53576+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
53577+
53578+ return;
53579+}
53580+
53581+void gr_set_kernel_label(struct task_struct *task)
53582+{
53583+ if (gr_status & GR_READY) {
53584+ task->role = kernel_role;
53585+ task->acl = kernel_role->root_label;
53586+ }
53587+ return;
53588+}
53589+
53590+#ifdef CONFIG_TASKSTATS
53591+int gr_is_taskstats_denied(int pid)
53592+{
53593+ struct task_struct *task;
53594+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53595+ const struct cred *cred;
53596+#endif
53597+ int ret = 0;
53598+
53599+ /* restrict taskstats viewing to un-chrooted root users
53600+ who have the 'view' subject flag if the RBAC system is enabled
53601+ */
53602+
53603+ rcu_read_lock();
53604+ read_lock(&tasklist_lock);
53605+ task = find_task_by_vpid(pid);
53606+ if (task) {
53607+#ifdef CONFIG_GRKERNSEC_CHROOT
53608+ if (proc_is_chrooted(task))
53609+ ret = -EACCES;
53610+#endif
53611+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53612+ cred = __task_cred(task);
53613+#ifdef CONFIG_GRKERNSEC_PROC_USER
53614+ if (cred->uid != 0)
53615+ ret = -EACCES;
53616+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53617+ if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
53618+ ret = -EACCES;
53619+#endif
53620+#endif
53621+ if (gr_status & GR_READY) {
53622+ if (!(task->acl->mode & GR_VIEW))
53623+ ret = -EACCES;
53624+ }
53625+ } else
53626+ ret = -ENOENT;
53627+
53628+ read_unlock(&tasklist_lock);
53629+ rcu_read_unlock();
53630+
53631+ return ret;
53632+}
53633+#endif
53634+
53635+/* AUXV entries are filled via a descendant of search_binary_handler
53636+ after we've already applied the subject for the target
53637+*/
53638+int gr_acl_enable_at_secure(void)
53639+{
53640+ if (unlikely(!(gr_status & GR_READY)))
53641+ return 0;
53642+
53643+ if (current->acl->mode & GR_ATSECURE)
53644+ return 1;
53645+
53646+ return 0;
53647+}
53648+
53649+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
53650+{
53651+ struct task_struct *task = current;
53652+ struct dentry *dentry = file->f_path.dentry;
53653+ struct vfsmount *mnt = file->f_path.mnt;
53654+ struct acl_object_label *obj, *tmp;
53655+ struct acl_subject_label *subj;
53656+ unsigned int bufsize;
53657+ int is_not_root;
53658+ char *path;
53659+ dev_t dev = __get_dev(dentry);
53660+
53661+ if (unlikely(!(gr_status & GR_READY)))
53662+ return 1;
53663+
53664+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53665+ return 1;
53666+
53667+ /* ignore Eric Biederman */
53668+ if (IS_PRIVATE(dentry->d_inode))
53669+ return 1;
53670+
53671+ subj = task->acl;
53672+ do {
53673+ obj = lookup_acl_obj_label(ino, dev, subj);
53674+ if (obj != NULL)
53675+ return (obj->mode & GR_FIND) ? 1 : 0;
53676+ } while ((subj = subj->parent_subject));
53677+
53678+ /* this is purely an optimization since we're looking for an object
53679+ for the directory we're doing a readdir on
53680+ if it's possible for any globbed object to match the entry we're
53681+ filling into the directory, then the object we find here will be
53682+ an anchor point with attached globbed objects
53683+ */
53684+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
53685+ if (obj->globbed == NULL)
53686+ return (obj->mode & GR_FIND) ? 1 : 0;
53687+
53688+ is_not_root = ((obj->filename[0] == '/') &&
53689+ (obj->filename[1] == '\0')) ? 0 : 1;
53690+ bufsize = PAGE_SIZE - namelen - is_not_root;
53691+
53692+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
53693+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
53694+ return 1;
53695+
53696+ preempt_disable();
53697+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
53698+ bufsize);
53699+
53700+ bufsize = strlen(path);
53701+
53702+ /* if base is "/", don't append an additional slash */
53703+ if (is_not_root)
53704+ *(path + bufsize) = '/';
53705+ memcpy(path + bufsize + is_not_root, name, namelen);
53706+ *(path + bufsize + namelen + is_not_root) = '\0';
53707+
53708+ tmp = obj->globbed;
53709+ while (tmp) {
53710+ if (!glob_match(tmp->filename, path)) {
53711+ preempt_enable();
53712+ return (tmp->mode & GR_FIND) ? 1 : 0;
53713+ }
53714+ tmp = tmp->next;
53715+ }
53716+ preempt_enable();
53717+ return (obj->mode & GR_FIND) ? 1 : 0;
53718+}
53719+
53720+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
53721+EXPORT_SYMBOL(gr_acl_is_enabled);
53722+#endif
53723+EXPORT_SYMBOL(gr_learn_resource);
53724+EXPORT_SYMBOL(gr_set_kernel_label);
53725+#ifdef CONFIG_SECURITY
53726+EXPORT_SYMBOL(gr_check_user_change);
53727+EXPORT_SYMBOL(gr_check_group_change);
53728+#endif
53729+
53730diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
53731new file mode 100644
53732index 0000000..34fefda
53733--- /dev/null
53734+++ b/grsecurity/gracl_alloc.c
53735@@ -0,0 +1,105 @@
53736+#include <linux/kernel.h>
53737+#include <linux/mm.h>
53738+#include <linux/slab.h>
53739+#include <linux/vmalloc.h>
53740+#include <linux/gracl.h>
53741+#include <linux/grsecurity.h>
53742+
53743+static unsigned long alloc_stack_next = 1;
53744+static unsigned long alloc_stack_size = 1;
53745+static void **alloc_stack;
53746+
53747+static __inline__ int
53748+alloc_pop(void)
53749+{
53750+ if (alloc_stack_next == 1)
53751+ return 0;
53752+
53753+ kfree(alloc_stack[alloc_stack_next - 2]);
53754+
53755+ alloc_stack_next--;
53756+
53757+ return 1;
53758+}
53759+
53760+static __inline__ int
53761+alloc_push(void *buf)
53762+{
53763+ if (alloc_stack_next >= alloc_stack_size)
53764+ return 1;
53765+
53766+ alloc_stack[alloc_stack_next - 1] = buf;
53767+
53768+ alloc_stack_next++;
53769+
53770+ return 0;
53771+}
53772+
53773+void *
53774+acl_alloc(unsigned long len)
53775+{
53776+ void *ret = NULL;
53777+
53778+ if (!len || len > PAGE_SIZE)
53779+ goto out;
53780+
53781+ ret = kmalloc(len, GFP_KERNEL);
53782+
53783+ if (ret) {
53784+ if (alloc_push(ret)) {
53785+ kfree(ret);
53786+ ret = NULL;
53787+ }
53788+ }
53789+
53790+out:
53791+ return ret;
53792+}
53793+
53794+void *
53795+acl_alloc_num(unsigned long num, unsigned long len)
53796+{
53797+ if (!len || (num > (PAGE_SIZE / len)))
53798+ return NULL;
53799+
53800+ return acl_alloc(num * len);
53801+}
53802+
53803+void
53804+acl_free_all(void)
53805+{
53806+ if (gr_acl_is_enabled() || !alloc_stack)
53807+ return;
53808+
53809+ while (alloc_pop()) ;
53810+
53811+ if (alloc_stack) {
53812+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
53813+ kfree(alloc_stack);
53814+ else
53815+ vfree(alloc_stack);
53816+ }
53817+
53818+ alloc_stack = NULL;
53819+ alloc_stack_size = 1;
53820+ alloc_stack_next = 1;
53821+
53822+ return;
53823+}
53824+
53825+int
53826+acl_alloc_stack_init(unsigned long size)
53827+{
53828+ if ((size * sizeof (void *)) <= PAGE_SIZE)
53829+ alloc_stack =
53830+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
53831+ else
53832+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
53833+
53834+ alloc_stack_size = size;
53835+
53836+ if (!alloc_stack)
53837+ return 0;
53838+ else
53839+ return 1;
53840+}
53841diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
53842new file mode 100644
53843index 0000000..6d21049
53844--- /dev/null
53845+++ b/grsecurity/gracl_cap.c
53846@@ -0,0 +1,110 @@
53847+#include <linux/kernel.h>
53848+#include <linux/module.h>
53849+#include <linux/sched.h>
53850+#include <linux/gracl.h>
53851+#include <linux/grsecurity.h>
53852+#include <linux/grinternal.h>
53853+
53854+extern const char *captab_log[];
53855+extern int captab_log_entries;
53856+
53857+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
53858+{
53859+ struct acl_subject_label *curracl;
53860+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
53861+ kernel_cap_t cap_audit = __cap_empty_set;
53862+
53863+ if (!gr_acl_is_enabled())
53864+ return 1;
53865+
53866+ curracl = task->acl;
53867+
53868+ cap_drop = curracl->cap_lower;
53869+ cap_mask = curracl->cap_mask;
53870+ cap_audit = curracl->cap_invert_audit;
53871+
53872+ while ((curracl = curracl->parent_subject)) {
53873+ /* if the cap isn't specified in the current computed mask but is specified in the
53874+ current level subject, and is lowered in the current level subject, then add
53875+ it to the set of dropped capabilities
53876+ otherwise, add the current level subject's mask to the current computed mask
53877+ */
53878+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
53879+ cap_raise(cap_mask, cap);
53880+ if (cap_raised(curracl->cap_lower, cap))
53881+ cap_raise(cap_drop, cap);
53882+ if (cap_raised(curracl->cap_invert_audit, cap))
53883+ cap_raise(cap_audit, cap);
53884+ }
53885+ }
53886+
53887+ if (!cap_raised(cap_drop, cap)) {
53888+ if (cap_raised(cap_audit, cap))
53889+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
53890+ return 1;
53891+ }
53892+
53893+ curracl = task->acl;
53894+
53895+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
53896+ && cap_raised(cred->cap_effective, cap)) {
53897+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
53898+ task->role->roletype, cred->uid,
53899+ cred->gid, task->exec_file ?
53900+ gr_to_filename(task->exec_file->f_path.dentry,
53901+ task->exec_file->f_path.mnt) : curracl->filename,
53902+ curracl->filename, 0UL,
53903+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
53904+ return 1;
53905+ }
53906+
53907+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
53908+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
53909+
53910+ return 0;
53911+}
53912+
53913+int
53914+gr_acl_is_capable(const int cap)
53915+{
53916+ return gr_task_acl_is_capable(current, current_cred(), cap);
53917+}
53918+
53919+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
53920+{
53921+ struct acl_subject_label *curracl;
53922+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
53923+
53924+ if (!gr_acl_is_enabled())
53925+ return 1;
53926+
53927+ curracl = task->acl;
53928+
53929+ cap_drop = curracl->cap_lower;
53930+ cap_mask = curracl->cap_mask;
53931+
53932+ while ((curracl = curracl->parent_subject)) {
53933+ /* if the cap isn't specified in the current computed mask but is specified in the
53934+ current level subject, and is lowered in the current level subject, then add
53935+ it to the set of dropped capabilities
53936+ otherwise, add the current level subject's mask to the current computed mask
53937+ */
53938+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
53939+ cap_raise(cap_mask, cap);
53940+ if (cap_raised(curracl->cap_lower, cap))
53941+ cap_raise(cap_drop, cap);
53942+ }
53943+ }
53944+
53945+ if (!cap_raised(cap_drop, cap))
53946+ return 1;
53947+
53948+ return 0;
53949+}
53950+
53951+int
53952+gr_acl_is_capable_nolog(const int cap)
53953+{
53954+ return gr_task_acl_is_capable_nolog(current, cap);
53955+}
53956+
53957diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
53958new file mode 100644
53959index 0000000..88d0e87
53960--- /dev/null
53961+++ b/grsecurity/gracl_fs.c
53962@@ -0,0 +1,435 @@
53963+#include <linux/kernel.h>
53964+#include <linux/sched.h>
53965+#include <linux/types.h>
53966+#include <linux/fs.h>
53967+#include <linux/file.h>
53968+#include <linux/stat.h>
53969+#include <linux/grsecurity.h>
53970+#include <linux/grinternal.h>
53971+#include <linux/gracl.h>
53972+
53973+umode_t
53974+gr_acl_umask(void)
53975+{
53976+ if (unlikely(!gr_acl_is_enabled()))
53977+ return 0;
53978+
53979+ return current->role->umask;
53980+}
53981+
53982+__u32
53983+gr_acl_handle_hidden_file(const struct dentry * dentry,
53984+ const struct vfsmount * mnt)
53985+{
53986+ __u32 mode;
53987+
53988+ if (unlikely(!dentry->d_inode))
53989+ return GR_FIND;
53990+
53991+ mode =
53992+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
53993+
53994+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
53995+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
53996+ return mode;
53997+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
53998+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
53999+ return 0;
54000+ } else if (unlikely(!(mode & GR_FIND)))
54001+ return 0;
54002+
54003+ return GR_FIND;
54004+}
54005+
54006+__u32
54007+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
54008+ int acc_mode)
54009+{
54010+ __u32 reqmode = GR_FIND;
54011+ __u32 mode;
54012+
54013+ if (unlikely(!dentry->d_inode))
54014+ return reqmode;
54015+
54016+ if (acc_mode & MAY_APPEND)
54017+ reqmode |= GR_APPEND;
54018+ else if (acc_mode & MAY_WRITE)
54019+ reqmode |= GR_WRITE;
54020+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
54021+ reqmode |= GR_READ;
54022+
54023+ mode =
54024+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
54025+ mnt);
54026+
54027+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54028+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
54029+ reqmode & GR_READ ? " reading" : "",
54030+ reqmode & GR_WRITE ? " writing" : reqmode &
54031+ GR_APPEND ? " appending" : "");
54032+ return reqmode;
54033+ } else
54034+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54035+ {
54036+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
54037+ reqmode & GR_READ ? " reading" : "",
54038+ reqmode & GR_WRITE ? " writing" : reqmode &
54039+ GR_APPEND ? " appending" : "");
54040+ return 0;
54041+ } else if (unlikely((mode & reqmode) != reqmode))
54042+ return 0;
54043+
54044+ return reqmode;
54045+}
54046+
54047+__u32
54048+gr_acl_handle_creat(const struct dentry * dentry,
54049+ const struct dentry * p_dentry,
54050+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
54051+ const int imode)
54052+{
54053+ __u32 reqmode = GR_WRITE | GR_CREATE;
54054+ __u32 mode;
54055+
54056+ if (acc_mode & MAY_APPEND)
54057+ reqmode |= GR_APPEND;
54058+ // if a directory was required or the directory already exists, then
54059+ // don't count this open as a read
54060+ if ((acc_mode & MAY_READ) &&
54061+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
54062+ reqmode |= GR_READ;
54063+ if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
54064+ reqmode |= GR_SETID;
54065+
54066+ mode =
54067+ gr_check_create(dentry, p_dentry, p_mnt,
54068+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
54069+
54070+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54071+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
54072+ reqmode & GR_READ ? " reading" : "",
54073+ reqmode & GR_WRITE ? " writing" : reqmode &
54074+ GR_APPEND ? " appending" : "");
54075+ return reqmode;
54076+ } else
54077+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54078+ {
54079+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
54080+ reqmode & GR_READ ? " reading" : "",
54081+ reqmode & GR_WRITE ? " writing" : reqmode &
54082+ GR_APPEND ? " appending" : "");
54083+ return 0;
54084+ } else if (unlikely((mode & reqmode) != reqmode))
54085+ return 0;
54086+
54087+ return reqmode;
54088+}
54089+
54090+__u32
54091+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
54092+ const int fmode)
54093+{
54094+ __u32 mode, reqmode = GR_FIND;
54095+
54096+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
54097+ reqmode |= GR_EXEC;
54098+ if (fmode & S_IWOTH)
54099+ reqmode |= GR_WRITE;
54100+ if (fmode & S_IROTH)
54101+ reqmode |= GR_READ;
54102+
54103+ mode =
54104+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
54105+ mnt);
54106+
54107+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54108+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
54109+ reqmode & GR_READ ? " reading" : "",
54110+ reqmode & GR_WRITE ? " writing" : "",
54111+ reqmode & GR_EXEC ? " executing" : "");
54112+ return reqmode;
54113+ } else
54114+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54115+ {
54116+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
54117+ reqmode & GR_READ ? " reading" : "",
54118+ reqmode & GR_WRITE ? " writing" : "",
54119+ reqmode & GR_EXEC ? " executing" : "");
54120+ return 0;
54121+ } else if (unlikely((mode & reqmode) != reqmode))
54122+ return 0;
54123+
54124+ return reqmode;
54125+}
54126+
54127+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
54128+{
54129+ __u32 mode;
54130+
54131+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
54132+
54133+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
54134+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
54135+ return mode;
54136+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
54137+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
54138+ return 0;
54139+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
54140+ return 0;
54141+
54142+ return (reqmode);
54143+}
54144+
54145+__u32
54146+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
54147+{
54148+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
54149+}
54150+
54151+__u32
54152+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
54153+{
54154+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
54155+}
54156+
54157+__u32
54158+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
54159+{
54160+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
54161+}
54162+
54163+__u32
54164+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
54165+{
54166+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
54167+}
54168+
54169+__u32
54170+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
54171+ umode_t *modeptr)
54172+{
54173+ umode_t mode;
54174+
54175+ *modeptr &= ~gr_acl_umask();
54176+ mode = *modeptr;
54177+
54178+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
54179+ return 1;
54180+
54181+ if (unlikely(mode & (S_ISUID | S_ISGID))) {
54182+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
54183+ GR_CHMOD_ACL_MSG);
54184+ } else {
54185+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
54186+ }
54187+}
54188+
54189+__u32
54190+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
54191+{
54192+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
54193+}
54194+
54195+__u32
54196+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
54197+{
54198+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
54199+}
54200+
54201+__u32
54202+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
54203+{
54204+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
54205+}
54206+
54207+__u32
54208+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
54209+{
54210+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
54211+ GR_UNIXCONNECT_ACL_MSG);
54212+}
54213+
54214+/* hardlinks require at minimum create and link permission,
54215+ any additional privilege required is based on the
54216+ privilege of the file being linked to
54217+*/
54218+__u32
54219+gr_acl_handle_link(const struct dentry * new_dentry,
54220+ const struct dentry * parent_dentry,
54221+ const struct vfsmount * parent_mnt,
54222+ const struct dentry * old_dentry,
54223+ const struct vfsmount * old_mnt, const char *to)
54224+{
54225+ __u32 mode;
54226+ __u32 needmode = GR_CREATE | GR_LINK;
54227+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
54228+
54229+ mode =
54230+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
54231+ old_mnt);
54232+
54233+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
54234+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
54235+ return mode;
54236+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
54237+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
54238+ return 0;
54239+ } else if (unlikely((mode & needmode) != needmode))
54240+ return 0;
54241+
54242+ return 1;
54243+}
54244+
54245+__u32
54246+gr_acl_handle_symlink(const struct dentry * new_dentry,
54247+ const struct dentry * parent_dentry,
54248+ const struct vfsmount * parent_mnt, const char *from)
54249+{
54250+ __u32 needmode = GR_WRITE | GR_CREATE;
54251+ __u32 mode;
54252+
54253+ mode =
54254+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
54255+ GR_CREATE | GR_AUDIT_CREATE |
54256+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
54257+
54258+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
54259+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
54260+ return mode;
54261+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
54262+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
54263+ return 0;
54264+ } else if (unlikely((mode & needmode) != needmode))
54265+ return 0;
54266+
54267+ return (GR_WRITE | GR_CREATE);
54268+}
54269+
54270+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)
54271+{
54272+ __u32 mode;
54273+
54274+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
54275+
54276+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
54277+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
54278+ return mode;
54279+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
54280+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
54281+ return 0;
54282+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
54283+ return 0;
54284+
54285+ return (reqmode);
54286+}
54287+
54288+__u32
54289+gr_acl_handle_mknod(const struct dentry * new_dentry,
54290+ const struct dentry * parent_dentry,
54291+ const struct vfsmount * parent_mnt,
54292+ const int mode)
54293+{
54294+ __u32 reqmode = GR_WRITE | GR_CREATE;
54295+ if (unlikely(mode & (S_ISUID | S_ISGID)))
54296+ reqmode |= GR_SETID;
54297+
54298+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
54299+ reqmode, GR_MKNOD_ACL_MSG);
54300+}
54301+
54302+__u32
54303+gr_acl_handle_mkdir(const struct dentry *new_dentry,
54304+ const struct dentry *parent_dentry,
54305+ const struct vfsmount *parent_mnt)
54306+{
54307+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
54308+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
54309+}
54310+
54311+#define RENAME_CHECK_SUCCESS(old, new) \
54312+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
54313+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
54314+
54315+int
54316+gr_acl_handle_rename(struct dentry *new_dentry,
54317+ struct dentry *parent_dentry,
54318+ const struct vfsmount *parent_mnt,
54319+ struct dentry *old_dentry,
54320+ struct inode *old_parent_inode,
54321+ struct vfsmount *old_mnt, const char *newname)
54322+{
54323+ __u32 comp1, comp2;
54324+ int error = 0;
54325+
54326+ if (unlikely(!gr_acl_is_enabled()))
54327+ return 0;
54328+
54329+ if (!new_dentry->d_inode) {
54330+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
54331+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
54332+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
54333+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
54334+ GR_DELETE | GR_AUDIT_DELETE |
54335+ GR_AUDIT_READ | GR_AUDIT_WRITE |
54336+ GR_SUPPRESS, old_mnt);
54337+ } else {
54338+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
54339+ GR_CREATE | GR_DELETE |
54340+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
54341+ GR_AUDIT_READ | GR_AUDIT_WRITE |
54342+ GR_SUPPRESS, parent_mnt);
54343+ comp2 =
54344+ gr_search_file(old_dentry,
54345+ GR_READ | GR_WRITE | GR_AUDIT_READ |
54346+ GR_DELETE | GR_AUDIT_DELETE |
54347+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
54348+ }
54349+
54350+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
54351+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
54352+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
54353+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
54354+ && !(comp2 & GR_SUPPRESS)) {
54355+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
54356+ error = -EACCES;
54357+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
54358+ error = -EACCES;
54359+
54360+ return error;
54361+}
54362+
54363+void
54364+gr_acl_handle_exit(void)
54365+{
54366+ u16 id;
54367+ char *rolename;
54368+ struct file *exec_file;
54369+
54370+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
54371+ !(current->role->roletype & GR_ROLE_PERSIST))) {
54372+ id = current->acl_role_id;
54373+ rolename = current->role->rolename;
54374+ gr_set_acls(1);
54375+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
54376+ }
54377+
54378+ write_lock(&grsec_exec_file_lock);
54379+ exec_file = current->exec_file;
54380+ current->exec_file = NULL;
54381+ write_unlock(&grsec_exec_file_lock);
54382+
54383+ if (exec_file)
54384+ fput(exec_file);
54385+}
54386+
54387+int
54388+gr_acl_handle_procpidmem(const struct task_struct *task)
54389+{
54390+ if (unlikely(!gr_acl_is_enabled()))
54391+ return 0;
54392+
54393+ if (task != current && task->acl->mode & GR_PROTPROCFD)
54394+ return -EACCES;
54395+
54396+ return 0;
54397+}
54398diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
54399new file mode 100644
54400index 0000000..17050ca
54401--- /dev/null
54402+++ b/grsecurity/gracl_ip.c
54403@@ -0,0 +1,381 @@
54404+#include <linux/kernel.h>
54405+#include <asm/uaccess.h>
54406+#include <asm/errno.h>
54407+#include <net/sock.h>
54408+#include <linux/file.h>
54409+#include <linux/fs.h>
54410+#include <linux/net.h>
54411+#include <linux/in.h>
54412+#include <linux/skbuff.h>
54413+#include <linux/ip.h>
54414+#include <linux/udp.h>
54415+#include <linux/types.h>
54416+#include <linux/sched.h>
54417+#include <linux/netdevice.h>
54418+#include <linux/inetdevice.h>
54419+#include <linux/gracl.h>
54420+#include <linux/grsecurity.h>
54421+#include <linux/grinternal.h>
54422+
54423+#define GR_BIND 0x01
54424+#define GR_CONNECT 0x02
54425+#define GR_INVERT 0x04
54426+#define GR_BINDOVERRIDE 0x08
54427+#define GR_CONNECTOVERRIDE 0x10
54428+#define GR_SOCK_FAMILY 0x20
54429+
54430+static const char * gr_protocols[IPPROTO_MAX] = {
54431+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
54432+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
54433+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
54434+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
54435+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
54436+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
54437+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
54438+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
54439+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
54440+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
54441+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
54442+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
54443+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
54444+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
54445+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
54446+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
54447+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
54448+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
54449+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
54450+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
54451+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
54452+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
54453+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
54454+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
54455+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
54456+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
54457+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
54458+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
54459+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
54460+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
54461+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
54462+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
54463+ };
54464+
54465+static const char * gr_socktypes[SOCK_MAX] = {
54466+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
54467+ "unknown:7", "unknown:8", "unknown:9", "packet"
54468+ };
54469+
54470+static const char * gr_sockfamilies[AF_MAX+1] = {
54471+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
54472+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
54473+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
54474+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
54475+ };
54476+
54477+const char *
54478+gr_proto_to_name(unsigned char proto)
54479+{
54480+ return gr_protocols[proto];
54481+}
54482+
54483+const char *
54484+gr_socktype_to_name(unsigned char type)
54485+{
54486+ return gr_socktypes[type];
54487+}
54488+
54489+const char *
54490+gr_sockfamily_to_name(unsigned char family)
54491+{
54492+ return gr_sockfamilies[family];
54493+}
54494+
54495+int
54496+gr_search_socket(const int domain, const int type, const int protocol)
54497+{
54498+ struct acl_subject_label *curr;
54499+ const struct cred *cred = current_cred();
54500+
54501+ if (unlikely(!gr_acl_is_enabled()))
54502+ goto exit;
54503+
54504+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
54505+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
54506+ goto exit; // let the kernel handle it
54507+
54508+ curr = current->acl;
54509+
54510+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
54511+ /* the family is allowed, if this is PF_INET allow it only if
54512+ the extra sock type/protocol checks pass */
54513+ if (domain == PF_INET)
54514+ goto inet_check;
54515+ goto exit;
54516+ } else {
54517+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
54518+ __u32 fakeip = 0;
54519+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
54520+ current->role->roletype, cred->uid,
54521+ cred->gid, current->exec_file ?
54522+ gr_to_filename(current->exec_file->f_path.dentry,
54523+ current->exec_file->f_path.mnt) :
54524+ curr->filename, curr->filename,
54525+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
54526+ &current->signal->saved_ip);
54527+ goto exit;
54528+ }
54529+ goto exit_fail;
54530+ }
54531+
54532+inet_check:
54533+ /* the rest of this checking is for IPv4 only */
54534+ if (!curr->ips)
54535+ goto exit;
54536+
54537+ if ((curr->ip_type & (1 << type)) &&
54538+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
54539+ goto exit;
54540+
54541+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
54542+ /* we don't place acls on raw sockets , and sometimes
54543+ dgram/ip sockets are opened for ioctl and not
54544+ bind/connect, so we'll fake a bind learn log */
54545+ if (type == SOCK_RAW || type == SOCK_PACKET) {
54546+ __u32 fakeip = 0;
54547+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
54548+ current->role->roletype, cred->uid,
54549+ cred->gid, current->exec_file ?
54550+ gr_to_filename(current->exec_file->f_path.dentry,
54551+ current->exec_file->f_path.mnt) :
54552+ curr->filename, curr->filename,
54553+ &fakeip, 0, type,
54554+ protocol, GR_CONNECT, &current->signal->saved_ip);
54555+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
54556+ __u32 fakeip = 0;
54557+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
54558+ current->role->roletype, cred->uid,
54559+ cred->gid, current->exec_file ?
54560+ gr_to_filename(current->exec_file->f_path.dentry,
54561+ current->exec_file->f_path.mnt) :
54562+ curr->filename, curr->filename,
54563+ &fakeip, 0, type,
54564+ protocol, GR_BIND, &current->signal->saved_ip);
54565+ }
54566+ /* we'll log when they use connect or bind */
54567+ goto exit;
54568+ }
54569+
54570+exit_fail:
54571+ if (domain == PF_INET)
54572+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
54573+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
54574+ else
54575+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
54576+ gr_socktype_to_name(type), protocol);
54577+
54578+ return 0;
54579+exit:
54580+ return 1;
54581+}
54582+
54583+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)
54584+{
54585+ if ((ip->mode & mode) &&
54586+ (ip_port >= ip->low) &&
54587+ (ip_port <= ip->high) &&
54588+ ((ntohl(ip_addr) & our_netmask) ==
54589+ (ntohl(our_addr) & our_netmask))
54590+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
54591+ && (ip->type & (1 << type))) {
54592+ if (ip->mode & GR_INVERT)
54593+ return 2; // specifically denied
54594+ else
54595+ return 1; // allowed
54596+ }
54597+
54598+ return 0; // not specifically allowed, may continue parsing
54599+}
54600+
54601+static int
54602+gr_search_connectbind(const int full_mode, struct sock *sk,
54603+ struct sockaddr_in *addr, const int type)
54604+{
54605+ char iface[IFNAMSIZ] = {0};
54606+ struct acl_subject_label *curr;
54607+ struct acl_ip_label *ip;
54608+ struct inet_sock *isk;
54609+ struct net_device *dev;
54610+ struct in_device *idev;
54611+ unsigned long i;
54612+ int ret;
54613+ int mode = full_mode & (GR_BIND | GR_CONNECT);
54614+ __u32 ip_addr = 0;
54615+ __u32 our_addr;
54616+ __u32 our_netmask;
54617+ char *p;
54618+ __u16 ip_port = 0;
54619+ const struct cred *cred = current_cred();
54620+
54621+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
54622+ return 0;
54623+
54624+ curr = current->acl;
54625+ isk = inet_sk(sk);
54626+
54627+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
54628+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
54629+ addr->sin_addr.s_addr = curr->inaddr_any_override;
54630+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
54631+ struct sockaddr_in saddr;
54632+ int err;
54633+
54634+ saddr.sin_family = AF_INET;
54635+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
54636+ saddr.sin_port = isk->inet_sport;
54637+
54638+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
54639+ if (err)
54640+ return err;
54641+
54642+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
54643+ if (err)
54644+ return err;
54645+ }
54646+
54647+ if (!curr->ips)
54648+ return 0;
54649+
54650+ ip_addr = addr->sin_addr.s_addr;
54651+ ip_port = ntohs(addr->sin_port);
54652+
54653+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
54654+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
54655+ current->role->roletype, cred->uid,
54656+ cred->gid, current->exec_file ?
54657+ gr_to_filename(current->exec_file->f_path.dentry,
54658+ current->exec_file->f_path.mnt) :
54659+ curr->filename, curr->filename,
54660+ &ip_addr, ip_port, type,
54661+ sk->sk_protocol, mode, &current->signal->saved_ip);
54662+ return 0;
54663+ }
54664+
54665+ for (i = 0; i < curr->ip_num; i++) {
54666+ ip = *(curr->ips + i);
54667+ if (ip->iface != NULL) {
54668+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
54669+ p = strchr(iface, ':');
54670+ if (p != NULL)
54671+ *p = '\0';
54672+ dev = dev_get_by_name(sock_net(sk), iface);
54673+ if (dev == NULL)
54674+ continue;
54675+ idev = in_dev_get(dev);
54676+ if (idev == NULL) {
54677+ dev_put(dev);
54678+ continue;
54679+ }
54680+ rcu_read_lock();
54681+ for_ifa(idev) {
54682+ if (!strcmp(ip->iface, ifa->ifa_label)) {
54683+ our_addr = ifa->ifa_address;
54684+ our_netmask = 0xffffffff;
54685+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
54686+ if (ret == 1) {
54687+ rcu_read_unlock();
54688+ in_dev_put(idev);
54689+ dev_put(dev);
54690+ return 0;
54691+ } else if (ret == 2) {
54692+ rcu_read_unlock();
54693+ in_dev_put(idev);
54694+ dev_put(dev);
54695+ goto denied;
54696+ }
54697+ }
54698+ } endfor_ifa(idev);
54699+ rcu_read_unlock();
54700+ in_dev_put(idev);
54701+ dev_put(dev);
54702+ } else {
54703+ our_addr = ip->addr;
54704+ our_netmask = ip->netmask;
54705+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
54706+ if (ret == 1)
54707+ return 0;
54708+ else if (ret == 2)
54709+ goto denied;
54710+ }
54711+ }
54712+
54713+denied:
54714+ if (mode == GR_BIND)
54715+ 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));
54716+ else if (mode == GR_CONNECT)
54717+ 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));
54718+
54719+ return -EACCES;
54720+}
54721+
54722+int
54723+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
54724+{
54725+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
54726+}
54727+
54728+int
54729+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
54730+{
54731+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
54732+}
54733+
54734+int gr_search_listen(struct socket *sock)
54735+{
54736+ struct sock *sk = sock->sk;
54737+ struct sockaddr_in addr;
54738+
54739+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
54740+ addr.sin_port = inet_sk(sk)->inet_sport;
54741+
54742+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
54743+}
54744+
54745+int gr_search_accept(struct socket *sock)
54746+{
54747+ struct sock *sk = sock->sk;
54748+ struct sockaddr_in addr;
54749+
54750+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
54751+ addr.sin_port = inet_sk(sk)->inet_sport;
54752+
54753+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
54754+}
54755+
54756+int
54757+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
54758+{
54759+ if (addr)
54760+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
54761+ else {
54762+ struct sockaddr_in sin;
54763+ const struct inet_sock *inet = inet_sk(sk);
54764+
54765+ sin.sin_addr.s_addr = inet->inet_daddr;
54766+ sin.sin_port = inet->inet_dport;
54767+
54768+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
54769+ }
54770+}
54771+
54772+int
54773+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
54774+{
54775+ struct sockaddr_in sin;
54776+
54777+ if (unlikely(skb->len < sizeof (struct udphdr)))
54778+ return 0; // skip this packet
54779+
54780+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
54781+ sin.sin_port = udp_hdr(skb)->source;
54782+
54783+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
54784+}
54785diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
54786new file mode 100644
54787index 0000000..25f54ef
54788--- /dev/null
54789+++ b/grsecurity/gracl_learn.c
54790@@ -0,0 +1,207 @@
54791+#include <linux/kernel.h>
54792+#include <linux/mm.h>
54793+#include <linux/sched.h>
54794+#include <linux/poll.h>
54795+#include <linux/string.h>
54796+#include <linux/file.h>
54797+#include <linux/types.h>
54798+#include <linux/vmalloc.h>
54799+#include <linux/grinternal.h>
54800+
54801+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
54802+ size_t count, loff_t *ppos);
54803+extern int gr_acl_is_enabled(void);
54804+
54805+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
54806+static int gr_learn_attached;
54807+
54808+/* use a 512k buffer */
54809+#define LEARN_BUFFER_SIZE (512 * 1024)
54810+
54811+static DEFINE_SPINLOCK(gr_learn_lock);
54812+static DEFINE_MUTEX(gr_learn_user_mutex);
54813+
54814+/* we need to maintain two buffers, so that the kernel context of grlearn
54815+ uses a semaphore around the userspace copying, and the other kernel contexts
54816+ use a spinlock when copying into the buffer, since they cannot sleep
54817+*/
54818+static char *learn_buffer;
54819+static char *learn_buffer_user;
54820+static int learn_buffer_len;
54821+static int learn_buffer_user_len;
54822+
54823+static ssize_t
54824+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
54825+{
54826+ DECLARE_WAITQUEUE(wait, current);
54827+ ssize_t retval = 0;
54828+
54829+ add_wait_queue(&learn_wait, &wait);
54830+ set_current_state(TASK_INTERRUPTIBLE);
54831+ do {
54832+ mutex_lock(&gr_learn_user_mutex);
54833+ spin_lock(&gr_learn_lock);
54834+ if (learn_buffer_len)
54835+ break;
54836+ spin_unlock(&gr_learn_lock);
54837+ mutex_unlock(&gr_learn_user_mutex);
54838+ if (file->f_flags & O_NONBLOCK) {
54839+ retval = -EAGAIN;
54840+ goto out;
54841+ }
54842+ if (signal_pending(current)) {
54843+ retval = -ERESTARTSYS;
54844+ goto out;
54845+ }
54846+
54847+ schedule();
54848+ } while (1);
54849+
54850+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
54851+ learn_buffer_user_len = learn_buffer_len;
54852+ retval = learn_buffer_len;
54853+ learn_buffer_len = 0;
54854+
54855+ spin_unlock(&gr_learn_lock);
54856+
54857+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
54858+ retval = -EFAULT;
54859+
54860+ mutex_unlock(&gr_learn_user_mutex);
54861+out:
54862+ set_current_state(TASK_RUNNING);
54863+ remove_wait_queue(&learn_wait, &wait);
54864+ return retval;
54865+}
54866+
54867+static unsigned int
54868+poll_learn(struct file * file, poll_table * wait)
54869+{
54870+ poll_wait(file, &learn_wait, wait);
54871+
54872+ if (learn_buffer_len)
54873+ return (POLLIN | POLLRDNORM);
54874+
54875+ return 0;
54876+}
54877+
54878+void
54879+gr_clear_learn_entries(void)
54880+{
54881+ char *tmp;
54882+
54883+ mutex_lock(&gr_learn_user_mutex);
54884+ spin_lock(&gr_learn_lock);
54885+ tmp = learn_buffer;
54886+ learn_buffer = NULL;
54887+ spin_unlock(&gr_learn_lock);
54888+ if (tmp)
54889+ vfree(tmp);
54890+ if (learn_buffer_user != NULL) {
54891+ vfree(learn_buffer_user);
54892+ learn_buffer_user = NULL;
54893+ }
54894+ learn_buffer_len = 0;
54895+ mutex_unlock(&gr_learn_user_mutex);
54896+
54897+ return;
54898+}
54899+
54900+void
54901+gr_add_learn_entry(const char *fmt, ...)
54902+{
54903+ va_list args;
54904+ unsigned int len;
54905+
54906+ if (!gr_learn_attached)
54907+ return;
54908+
54909+ spin_lock(&gr_learn_lock);
54910+
54911+ /* leave a gap at the end so we know when it's "full" but don't have to
54912+ compute the exact length of the string we're trying to append
54913+ */
54914+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
54915+ spin_unlock(&gr_learn_lock);
54916+ wake_up_interruptible(&learn_wait);
54917+ return;
54918+ }
54919+ if (learn_buffer == NULL) {
54920+ spin_unlock(&gr_learn_lock);
54921+ return;
54922+ }
54923+
54924+ va_start(args, fmt);
54925+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
54926+ va_end(args);
54927+
54928+ learn_buffer_len += len + 1;
54929+
54930+ spin_unlock(&gr_learn_lock);
54931+ wake_up_interruptible(&learn_wait);
54932+
54933+ return;
54934+}
54935+
54936+static int
54937+open_learn(struct inode *inode, struct file *file)
54938+{
54939+ if (file->f_mode & FMODE_READ && gr_learn_attached)
54940+ return -EBUSY;
54941+ if (file->f_mode & FMODE_READ) {
54942+ int retval = 0;
54943+ mutex_lock(&gr_learn_user_mutex);
54944+ if (learn_buffer == NULL)
54945+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
54946+ if (learn_buffer_user == NULL)
54947+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
54948+ if (learn_buffer == NULL) {
54949+ retval = -ENOMEM;
54950+ goto out_error;
54951+ }
54952+ if (learn_buffer_user == NULL) {
54953+ retval = -ENOMEM;
54954+ goto out_error;
54955+ }
54956+ learn_buffer_len = 0;
54957+ learn_buffer_user_len = 0;
54958+ gr_learn_attached = 1;
54959+out_error:
54960+ mutex_unlock(&gr_learn_user_mutex);
54961+ return retval;
54962+ }
54963+ return 0;
54964+}
54965+
54966+static int
54967+close_learn(struct inode *inode, struct file *file)
54968+{
54969+ if (file->f_mode & FMODE_READ) {
54970+ char *tmp = NULL;
54971+ mutex_lock(&gr_learn_user_mutex);
54972+ spin_lock(&gr_learn_lock);
54973+ tmp = learn_buffer;
54974+ learn_buffer = NULL;
54975+ spin_unlock(&gr_learn_lock);
54976+ if (tmp)
54977+ vfree(tmp);
54978+ if (learn_buffer_user != NULL) {
54979+ vfree(learn_buffer_user);
54980+ learn_buffer_user = NULL;
54981+ }
54982+ learn_buffer_len = 0;
54983+ learn_buffer_user_len = 0;
54984+ gr_learn_attached = 0;
54985+ mutex_unlock(&gr_learn_user_mutex);
54986+ }
54987+
54988+ return 0;
54989+}
54990+
54991+const struct file_operations grsec_fops = {
54992+ .read = read_learn,
54993+ .write = write_grsec_handler,
54994+ .open = open_learn,
54995+ .release = close_learn,
54996+ .poll = poll_learn,
54997+};
54998diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
54999new file mode 100644
55000index 0000000..39645c9
55001--- /dev/null
55002+++ b/grsecurity/gracl_res.c
55003@@ -0,0 +1,68 @@
55004+#include <linux/kernel.h>
55005+#include <linux/sched.h>
55006+#include <linux/gracl.h>
55007+#include <linux/grinternal.h>
55008+
55009+static const char *restab_log[] = {
55010+ [RLIMIT_CPU] = "RLIMIT_CPU",
55011+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
55012+ [RLIMIT_DATA] = "RLIMIT_DATA",
55013+ [RLIMIT_STACK] = "RLIMIT_STACK",
55014+ [RLIMIT_CORE] = "RLIMIT_CORE",
55015+ [RLIMIT_RSS] = "RLIMIT_RSS",
55016+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
55017+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
55018+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
55019+ [RLIMIT_AS] = "RLIMIT_AS",
55020+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
55021+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
55022+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
55023+ [RLIMIT_NICE] = "RLIMIT_NICE",
55024+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
55025+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
55026+ [GR_CRASH_RES] = "RLIMIT_CRASH"
55027+};
55028+
55029+void
55030+gr_log_resource(const struct task_struct *task,
55031+ const int res, const unsigned long wanted, const int gt)
55032+{
55033+ const struct cred *cred;
55034+ unsigned long rlim;
55035+
55036+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
55037+ return;
55038+
55039+ // not yet supported resource
55040+ if (unlikely(!restab_log[res]))
55041+ return;
55042+
55043+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
55044+ rlim = task_rlimit_max(task, res);
55045+ else
55046+ rlim = task_rlimit(task, res);
55047+
55048+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
55049+ return;
55050+
55051+ rcu_read_lock();
55052+ cred = __task_cred(task);
55053+
55054+ if (res == RLIMIT_NPROC &&
55055+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
55056+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
55057+ goto out_rcu_unlock;
55058+ else if (res == RLIMIT_MEMLOCK &&
55059+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
55060+ goto out_rcu_unlock;
55061+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
55062+ goto out_rcu_unlock;
55063+ rcu_read_unlock();
55064+
55065+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
55066+
55067+ return;
55068+out_rcu_unlock:
55069+ rcu_read_unlock();
55070+ return;
55071+}
55072diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
55073new file mode 100644
55074index 0000000..5556be3
55075--- /dev/null
55076+++ b/grsecurity/gracl_segv.c
55077@@ -0,0 +1,299 @@
55078+#include <linux/kernel.h>
55079+#include <linux/mm.h>
55080+#include <asm/uaccess.h>
55081+#include <asm/errno.h>
55082+#include <asm/mman.h>
55083+#include <net/sock.h>
55084+#include <linux/file.h>
55085+#include <linux/fs.h>
55086+#include <linux/net.h>
55087+#include <linux/in.h>
55088+#include <linux/slab.h>
55089+#include <linux/types.h>
55090+#include <linux/sched.h>
55091+#include <linux/timer.h>
55092+#include <linux/gracl.h>
55093+#include <linux/grsecurity.h>
55094+#include <linux/grinternal.h>
55095+
55096+static struct crash_uid *uid_set;
55097+static unsigned short uid_used;
55098+static DEFINE_SPINLOCK(gr_uid_lock);
55099+extern rwlock_t gr_inode_lock;
55100+extern struct acl_subject_label *
55101+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
55102+ struct acl_role_label *role);
55103+
55104+#ifdef CONFIG_BTRFS_FS
55105+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
55106+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
55107+#endif
55108+
55109+static inline dev_t __get_dev(const struct dentry *dentry)
55110+{
55111+#ifdef CONFIG_BTRFS_FS
55112+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
55113+ return get_btrfs_dev_from_inode(dentry->d_inode);
55114+ else
55115+#endif
55116+ return dentry->d_inode->i_sb->s_dev;
55117+}
55118+
55119+int
55120+gr_init_uidset(void)
55121+{
55122+ uid_set =
55123+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
55124+ uid_used = 0;
55125+
55126+ return uid_set ? 1 : 0;
55127+}
55128+
55129+void
55130+gr_free_uidset(void)
55131+{
55132+ if (uid_set)
55133+ kfree(uid_set);
55134+
55135+ return;
55136+}
55137+
55138+int
55139+gr_find_uid(const uid_t uid)
55140+{
55141+ struct crash_uid *tmp = uid_set;
55142+ uid_t buid;
55143+ int low = 0, high = uid_used - 1, mid;
55144+
55145+ while (high >= low) {
55146+ mid = (low + high) >> 1;
55147+ buid = tmp[mid].uid;
55148+ if (buid == uid)
55149+ return mid;
55150+ if (buid > uid)
55151+ high = mid - 1;
55152+ if (buid < uid)
55153+ low = mid + 1;
55154+ }
55155+
55156+ return -1;
55157+}
55158+
55159+static __inline__ void
55160+gr_insertsort(void)
55161+{
55162+ unsigned short i, j;
55163+ struct crash_uid index;
55164+
55165+ for (i = 1; i < uid_used; i++) {
55166+ index = uid_set[i];
55167+ j = i;
55168+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
55169+ uid_set[j] = uid_set[j - 1];
55170+ j--;
55171+ }
55172+ uid_set[j] = index;
55173+ }
55174+
55175+ return;
55176+}
55177+
55178+static __inline__ void
55179+gr_insert_uid(const uid_t uid, const unsigned long expires)
55180+{
55181+ int loc;
55182+
55183+ if (uid_used == GR_UIDTABLE_MAX)
55184+ return;
55185+
55186+ loc = gr_find_uid(uid);
55187+
55188+ if (loc >= 0) {
55189+ uid_set[loc].expires = expires;
55190+ return;
55191+ }
55192+
55193+ uid_set[uid_used].uid = uid;
55194+ uid_set[uid_used].expires = expires;
55195+ uid_used++;
55196+
55197+ gr_insertsort();
55198+
55199+ return;
55200+}
55201+
55202+void
55203+gr_remove_uid(const unsigned short loc)
55204+{
55205+ unsigned short i;
55206+
55207+ for (i = loc + 1; i < uid_used; i++)
55208+ uid_set[i - 1] = uid_set[i];
55209+
55210+ uid_used--;
55211+
55212+ return;
55213+}
55214+
55215+int
55216+gr_check_crash_uid(const uid_t uid)
55217+{
55218+ int loc;
55219+ int ret = 0;
55220+
55221+ if (unlikely(!gr_acl_is_enabled()))
55222+ return 0;
55223+
55224+ spin_lock(&gr_uid_lock);
55225+ loc = gr_find_uid(uid);
55226+
55227+ if (loc < 0)
55228+ goto out_unlock;
55229+
55230+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
55231+ gr_remove_uid(loc);
55232+ else
55233+ ret = 1;
55234+
55235+out_unlock:
55236+ spin_unlock(&gr_uid_lock);
55237+ return ret;
55238+}
55239+
55240+static __inline__ int
55241+proc_is_setxid(const struct cred *cred)
55242+{
55243+ if (cred->uid != cred->euid || cred->uid != cred->suid ||
55244+ cred->uid != cred->fsuid)
55245+ return 1;
55246+ if (cred->gid != cred->egid || cred->gid != cred->sgid ||
55247+ cred->gid != cred->fsgid)
55248+ return 1;
55249+
55250+ return 0;
55251+}
55252+
55253+extern int gr_fake_force_sig(int sig, struct task_struct *t);
55254+
55255+void
55256+gr_handle_crash(struct task_struct *task, const int sig)
55257+{
55258+ struct acl_subject_label *curr;
55259+ struct task_struct *tsk, *tsk2;
55260+ const struct cred *cred;
55261+ const struct cred *cred2;
55262+
55263+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
55264+ return;
55265+
55266+ if (unlikely(!gr_acl_is_enabled()))
55267+ return;
55268+
55269+ curr = task->acl;
55270+
55271+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
55272+ return;
55273+
55274+ if (time_before_eq(curr->expires, get_seconds())) {
55275+ curr->expires = 0;
55276+ curr->crashes = 0;
55277+ }
55278+
55279+ curr->crashes++;
55280+
55281+ if (!curr->expires)
55282+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
55283+
55284+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
55285+ time_after(curr->expires, get_seconds())) {
55286+ rcu_read_lock();
55287+ cred = __task_cred(task);
55288+ if (cred->uid && proc_is_setxid(cred)) {
55289+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
55290+ spin_lock(&gr_uid_lock);
55291+ gr_insert_uid(cred->uid, curr->expires);
55292+ spin_unlock(&gr_uid_lock);
55293+ curr->expires = 0;
55294+ curr->crashes = 0;
55295+ read_lock(&tasklist_lock);
55296+ do_each_thread(tsk2, tsk) {
55297+ cred2 = __task_cred(tsk);
55298+ if (tsk != task && cred2->uid == cred->uid)
55299+ gr_fake_force_sig(SIGKILL, tsk);
55300+ } while_each_thread(tsk2, tsk);
55301+ read_unlock(&tasklist_lock);
55302+ } else {
55303+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
55304+ read_lock(&tasklist_lock);
55305+ read_lock(&grsec_exec_file_lock);
55306+ do_each_thread(tsk2, tsk) {
55307+ if (likely(tsk != task)) {
55308+ // if this thread has the same subject as the one that triggered
55309+ // RES_CRASH and it's the same binary, kill it
55310+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
55311+ gr_fake_force_sig(SIGKILL, tsk);
55312+ }
55313+ } while_each_thread(tsk2, tsk);
55314+ read_unlock(&grsec_exec_file_lock);
55315+ read_unlock(&tasklist_lock);
55316+ }
55317+ rcu_read_unlock();
55318+ }
55319+
55320+ return;
55321+}
55322+
55323+int
55324+gr_check_crash_exec(const struct file *filp)
55325+{
55326+ struct acl_subject_label *curr;
55327+
55328+ if (unlikely(!gr_acl_is_enabled()))
55329+ return 0;
55330+
55331+ read_lock(&gr_inode_lock);
55332+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
55333+ __get_dev(filp->f_path.dentry),
55334+ current->role);
55335+ read_unlock(&gr_inode_lock);
55336+
55337+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
55338+ (!curr->crashes && !curr->expires))
55339+ return 0;
55340+
55341+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
55342+ time_after(curr->expires, get_seconds()))
55343+ return 1;
55344+ else if (time_before_eq(curr->expires, get_seconds())) {
55345+ curr->crashes = 0;
55346+ curr->expires = 0;
55347+ }
55348+
55349+ return 0;
55350+}
55351+
55352+void
55353+gr_handle_alertkill(struct task_struct *task)
55354+{
55355+ struct acl_subject_label *curracl;
55356+ __u32 curr_ip;
55357+ struct task_struct *p, *p2;
55358+
55359+ if (unlikely(!gr_acl_is_enabled()))
55360+ return;
55361+
55362+ curracl = task->acl;
55363+ curr_ip = task->signal->curr_ip;
55364+
55365+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
55366+ read_lock(&tasklist_lock);
55367+ do_each_thread(p2, p) {
55368+ if (p->signal->curr_ip == curr_ip)
55369+ gr_fake_force_sig(SIGKILL, p);
55370+ } while_each_thread(p2, p);
55371+ read_unlock(&tasklist_lock);
55372+ } else if (curracl->mode & GR_KILLPROC)
55373+ gr_fake_force_sig(SIGKILL, task);
55374+
55375+ return;
55376+}
55377diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
55378new file mode 100644
55379index 0000000..9d83a69
55380--- /dev/null
55381+++ b/grsecurity/gracl_shm.c
55382@@ -0,0 +1,40 @@
55383+#include <linux/kernel.h>
55384+#include <linux/mm.h>
55385+#include <linux/sched.h>
55386+#include <linux/file.h>
55387+#include <linux/ipc.h>
55388+#include <linux/gracl.h>
55389+#include <linux/grsecurity.h>
55390+#include <linux/grinternal.h>
55391+
55392+int
55393+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
55394+ const time_t shm_createtime, const uid_t cuid, const int shmid)
55395+{
55396+ struct task_struct *task;
55397+
55398+ if (!gr_acl_is_enabled())
55399+ return 1;
55400+
55401+ rcu_read_lock();
55402+ read_lock(&tasklist_lock);
55403+
55404+ task = find_task_by_vpid(shm_cprid);
55405+
55406+ if (unlikely(!task))
55407+ task = find_task_by_vpid(shm_lapid);
55408+
55409+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
55410+ (task->pid == shm_lapid)) &&
55411+ (task->acl->mode & GR_PROTSHM) &&
55412+ (task->acl != current->acl))) {
55413+ read_unlock(&tasklist_lock);
55414+ rcu_read_unlock();
55415+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
55416+ return 0;
55417+ }
55418+ read_unlock(&tasklist_lock);
55419+ rcu_read_unlock();
55420+
55421+ return 1;
55422+}
55423diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
55424new file mode 100644
55425index 0000000..bc0be01
55426--- /dev/null
55427+++ b/grsecurity/grsec_chdir.c
55428@@ -0,0 +1,19 @@
55429+#include <linux/kernel.h>
55430+#include <linux/sched.h>
55431+#include <linux/fs.h>
55432+#include <linux/file.h>
55433+#include <linux/grsecurity.h>
55434+#include <linux/grinternal.h>
55435+
55436+void
55437+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
55438+{
55439+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
55440+ if ((grsec_enable_chdir && grsec_enable_group &&
55441+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
55442+ !grsec_enable_group)) {
55443+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
55444+ }
55445+#endif
55446+ return;
55447+}
55448diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
55449new file mode 100644
55450index 0000000..9807ee2
55451--- /dev/null
55452+++ b/grsecurity/grsec_chroot.c
55453@@ -0,0 +1,368 @@
55454+#include <linux/kernel.h>
55455+#include <linux/module.h>
55456+#include <linux/sched.h>
55457+#include <linux/file.h>
55458+#include <linux/fs.h>
55459+#include <linux/mount.h>
55460+#include <linux/types.h>
55461+#include "../fs/mount.h"
55462+#include <linux/grsecurity.h>
55463+#include <linux/grinternal.h>
55464+
55465+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
55466+{
55467+#ifdef CONFIG_GRKERNSEC
55468+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
55469+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
55470+ task->gr_is_chrooted = 1;
55471+ else
55472+ task->gr_is_chrooted = 0;
55473+
55474+ task->gr_chroot_dentry = path->dentry;
55475+#endif
55476+ return;
55477+}
55478+
55479+void gr_clear_chroot_entries(struct task_struct *task)
55480+{
55481+#ifdef CONFIG_GRKERNSEC
55482+ task->gr_is_chrooted = 0;
55483+ task->gr_chroot_dentry = NULL;
55484+#endif
55485+ return;
55486+}
55487+
55488+int
55489+gr_handle_chroot_unix(const pid_t pid)
55490+{
55491+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
55492+ struct task_struct *p;
55493+
55494+ if (unlikely(!grsec_enable_chroot_unix))
55495+ return 1;
55496+
55497+ if (likely(!proc_is_chrooted(current)))
55498+ return 1;
55499+
55500+ rcu_read_lock();
55501+ read_lock(&tasklist_lock);
55502+ p = find_task_by_vpid_unrestricted(pid);
55503+ if (unlikely(p && !have_same_root(current, p))) {
55504+ read_unlock(&tasklist_lock);
55505+ rcu_read_unlock();
55506+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
55507+ return 0;
55508+ }
55509+ read_unlock(&tasklist_lock);
55510+ rcu_read_unlock();
55511+#endif
55512+ return 1;
55513+}
55514+
55515+int
55516+gr_handle_chroot_nice(void)
55517+{
55518+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
55519+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
55520+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
55521+ return -EPERM;
55522+ }
55523+#endif
55524+ return 0;
55525+}
55526+
55527+int
55528+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
55529+{
55530+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
55531+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
55532+ && proc_is_chrooted(current)) {
55533+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
55534+ return -EACCES;
55535+ }
55536+#endif
55537+ return 0;
55538+}
55539+
55540+int
55541+gr_handle_chroot_rawio(const struct inode *inode)
55542+{
55543+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55544+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
55545+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
55546+ return 1;
55547+#endif
55548+ return 0;
55549+}
55550+
55551+int
55552+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
55553+{
55554+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
55555+ struct task_struct *p;
55556+ int ret = 0;
55557+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
55558+ return ret;
55559+
55560+ read_lock(&tasklist_lock);
55561+ do_each_pid_task(pid, type, p) {
55562+ if (!have_same_root(current, p)) {
55563+ ret = 1;
55564+ goto out;
55565+ }
55566+ } while_each_pid_task(pid, type, p);
55567+out:
55568+ read_unlock(&tasklist_lock);
55569+ return ret;
55570+#endif
55571+ return 0;
55572+}
55573+
55574+int
55575+gr_pid_is_chrooted(struct task_struct *p)
55576+{
55577+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
55578+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
55579+ return 0;
55580+
55581+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
55582+ !have_same_root(current, p)) {
55583+ return 1;
55584+ }
55585+#endif
55586+ return 0;
55587+}
55588+
55589+EXPORT_SYMBOL(gr_pid_is_chrooted);
55590+
55591+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
55592+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
55593+{
55594+ struct path path, currentroot;
55595+ int ret = 0;
55596+
55597+ path.dentry = (struct dentry *)u_dentry;
55598+ path.mnt = (struct vfsmount *)u_mnt;
55599+ get_fs_root(current->fs, &currentroot);
55600+ if (path_is_under(&path, &currentroot))
55601+ ret = 1;
55602+ path_put(&currentroot);
55603+
55604+ return ret;
55605+}
55606+#endif
55607+
55608+int
55609+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
55610+{
55611+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
55612+ if (!grsec_enable_chroot_fchdir)
55613+ return 1;
55614+
55615+ if (!proc_is_chrooted(current))
55616+ return 1;
55617+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
55618+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
55619+ return 0;
55620+ }
55621+#endif
55622+ return 1;
55623+}
55624+
55625+int
55626+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
55627+ const time_t shm_createtime)
55628+{
55629+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
55630+ struct task_struct *p;
55631+ time_t starttime;
55632+
55633+ if (unlikely(!grsec_enable_chroot_shmat))
55634+ return 1;
55635+
55636+ if (likely(!proc_is_chrooted(current)))
55637+ return 1;
55638+
55639+ rcu_read_lock();
55640+ read_lock(&tasklist_lock);
55641+
55642+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
55643+ starttime = p->start_time.tv_sec;
55644+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
55645+ if (have_same_root(current, p)) {
55646+ goto allow;
55647+ } else {
55648+ read_unlock(&tasklist_lock);
55649+ rcu_read_unlock();
55650+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
55651+ return 0;
55652+ }
55653+ }
55654+ /* creator exited, pid reuse, fall through to next check */
55655+ }
55656+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
55657+ if (unlikely(!have_same_root(current, p))) {
55658+ read_unlock(&tasklist_lock);
55659+ rcu_read_unlock();
55660+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
55661+ return 0;
55662+ }
55663+ }
55664+
55665+allow:
55666+ read_unlock(&tasklist_lock);
55667+ rcu_read_unlock();
55668+#endif
55669+ return 1;
55670+}
55671+
55672+void
55673+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
55674+{
55675+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
55676+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
55677+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
55678+#endif
55679+ return;
55680+}
55681+
55682+int
55683+gr_handle_chroot_mknod(const struct dentry *dentry,
55684+ const struct vfsmount *mnt, const int mode)
55685+{
55686+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
55687+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
55688+ proc_is_chrooted(current)) {
55689+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
55690+ return -EPERM;
55691+ }
55692+#endif
55693+ return 0;
55694+}
55695+
55696+int
55697+gr_handle_chroot_mount(const struct dentry *dentry,
55698+ const struct vfsmount *mnt, const char *dev_name)
55699+{
55700+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
55701+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
55702+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
55703+ return -EPERM;
55704+ }
55705+#endif
55706+ return 0;
55707+}
55708+
55709+int
55710+gr_handle_chroot_pivot(void)
55711+{
55712+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
55713+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
55714+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
55715+ return -EPERM;
55716+ }
55717+#endif
55718+ return 0;
55719+}
55720+
55721+int
55722+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
55723+{
55724+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
55725+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
55726+ !gr_is_outside_chroot(dentry, mnt)) {
55727+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
55728+ return -EPERM;
55729+ }
55730+#endif
55731+ return 0;
55732+}
55733+
55734+extern const char *captab_log[];
55735+extern int captab_log_entries;
55736+
55737+int
55738+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55739+{
55740+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55741+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
55742+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
55743+ if (cap_raised(chroot_caps, cap)) {
55744+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
55745+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
55746+ }
55747+ return 0;
55748+ }
55749+ }
55750+#endif
55751+ return 1;
55752+}
55753+
55754+int
55755+gr_chroot_is_capable(const int cap)
55756+{
55757+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55758+ return gr_task_chroot_is_capable(current, current_cred(), cap);
55759+#endif
55760+ return 1;
55761+}
55762+
55763+int
55764+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
55765+{
55766+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55767+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
55768+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
55769+ if (cap_raised(chroot_caps, cap)) {
55770+ return 0;
55771+ }
55772+ }
55773+#endif
55774+ return 1;
55775+}
55776+
55777+int
55778+gr_chroot_is_capable_nolog(const int cap)
55779+{
55780+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55781+ return gr_task_chroot_is_capable_nolog(current, cap);
55782+#endif
55783+ return 1;
55784+}
55785+
55786+int
55787+gr_handle_chroot_sysctl(const int op)
55788+{
55789+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
55790+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
55791+ proc_is_chrooted(current))
55792+ return -EACCES;
55793+#endif
55794+ return 0;
55795+}
55796+
55797+void
55798+gr_handle_chroot_chdir(struct path *path)
55799+{
55800+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
55801+ if (grsec_enable_chroot_chdir)
55802+ set_fs_pwd(current->fs, path);
55803+#endif
55804+ return;
55805+}
55806+
55807+int
55808+gr_handle_chroot_chmod(const struct dentry *dentry,
55809+ const struct vfsmount *mnt, const int mode)
55810+{
55811+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
55812+ /* allow chmod +s on directories, but not files */
55813+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
55814+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
55815+ proc_is_chrooted(current)) {
55816+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
55817+ return -EPERM;
55818+ }
55819+#endif
55820+ return 0;
55821+}
55822diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
55823new file mode 100644
55824index 0000000..213ad8b
55825--- /dev/null
55826+++ b/grsecurity/grsec_disabled.c
55827@@ -0,0 +1,437 @@
55828+#include <linux/kernel.h>
55829+#include <linux/module.h>
55830+#include <linux/sched.h>
55831+#include <linux/file.h>
55832+#include <linux/fs.h>
55833+#include <linux/kdev_t.h>
55834+#include <linux/net.h>
55835+#include <linux/in.h>
55836+#include <linux/ip.h>
55837+#include <linux/skbuff.h>
55838+#include <linux/sysctl.h>
55839+
55840+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
55841+void
55842+pax_set_initial_flags(struct linux_binprm *bprm)
55843+{
55844+ return;
55845+}
55846+#endif
55847+
55848+#ifdef CONFIG_SYSCTL
55849+__u32
55850+gr_handle_sysctl(const struct ctl_table * table, const int op)
55851+{
55852+ return 0;
55853+}
55854+#endif
55855+
55856+#ifdef CONFIG_TASKSTATS
55857+int gr_is_taskstats_denied(int pid)
55858+{
55859+ return 0;
55860+}
55861+#endif
55862+
55863+int
55864+gr_acl_is_enabled(void)
55865+{
55866+ return 0;
55867+}
55868+
55869+void
55870+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
55871+{
55872+ return;
55873+}
55874+
55875+int
55876+gr_handle_rawio(const struct inode *inode)
55877+{
55878+ return 0;
55879+}
55880+
55881+void
55882+gr_acl_handle_psacct(struct task_struct *task, const long code)
55883+{
55884+ return;
55885+}
55886+
55887+int
55888+gr_handle_ptrace(struct task_struct *task, const long request)
55889+{
55890+ return 0;
55891+}
55892+
55893+int
55894+gr_handle_proc_ptrace(struct task_struct *task)
55895+{
55896+ return 0;
55897+}
55898+
55899+void
55900+gr_learn_resource(const struct task_struct *task,
55901+ const int res, const unsigned long wanted, const int gt)
55902+{
55903+ return;
55904+}
55905+
55906+int
55907+gr_set_acls(const int type)
55908+{
55909+ return 0;
55910+}
55911+
55912+int
55913+gr_check_hidden_task(const struct task_struct *tsk)
55914+{
55915+ return 0;
55916+}
55917+
55918+int
55919+gr_check_protected_task(const struct task_struct *task)
55920+{
55921+ return 0;
55922+}
55923+
55924+int
55925+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
55926+{
55927+ return 0;
55928+}
55929+
55930+void
55931+gr_copy_label(struct task_struct *tsk)
55932+{
55933+ return;
55934+}
55935+
55936+void
55937+gr_set_pax_flags(struct task_struct *task)
55938+{
55939+ return;
55940+}
55941+
55942+int
55943+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
55944+ const int unsafe_share)
55945+{
55946+ return 0;
55947+}
55948+
55949+void
55950+gr_handle_delete(const ino_t ino, const dev_t dev)
55951+{
55952+ return;
55953+}
55954+
55955+void
55956+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
55957+{
55958+ return;
55959+}
55960+
55961+void
55962+gr_handle_crash(struct task_struct *task, const int sig)
55963+{
55964+ return;
55965+}
55966+
55967+int
55968+gr_check_crash_exec(const struct file *filp)
55969+{
55970+ return 0;
55971+}
55972+
55973+int
55974+gr_check_crash_uid(const uid_t uid)
55975+{
55976+ return 0;
55977+}
55978+
55979+void
55980+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
55981+ struct dentry *old_dentry,
55982+ struct dentry *new_dentry,
55983+ struct vfsmount *mnt, const __u8 replace)
55984+{
55985+ return;
55986+}
55987+
55988+int
55989+gr_search_socket(const int family, const int type, const int protocol)
55990+{
55991+ return 1;
55992+}
55993+
55994+int
55995+gr_search_connectbind(const int mode, const struct socket *sock,
55996+ const struct sockaddr_in *addr)
55997+{
55998+ return 0;
55999+}
56000+
56001+void
56002+gr_handle_alertkill(struct task_struct *task)
56003+{
56004+ return;
56005+}
56006+
56007+__u32
56008+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
56009+{
56010+ return 1;
56011+}
56012+
56013+__u32
56014+gr_acl_handle_hidden_file(const struct dentry * dentry,
56015+ const struct vfsmount * mnt)
56016+{
56017+ return 1;
56018+}
56019+
56020+__u32
56021+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56022+ int acc_mode)
56023+{
56024+ return 1;
56025+}
56026+
56027+__u32
56028+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56029+{
56030+ return 1;
56031+}
56032+
56033+__u32
56034+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
56035+{
56036+ return 1;
56037+}
56038+
56039+int
56040+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
56041+ unsigned int *vm_flags)
56042+{
56043+ return 1;
56044+}
56045+
56046+__u32
56047+gr_acl_handle_truncate(const struct dentry * dentry,
56048+ const struct vfsmount * mnt)
56049+{
56050+ return 1;
56051+}
56052+
56053+__u32
56054+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
56055+{
56056+ return 1;
56057+}
56058+
56059+__u32
56060+gr_acl_handle_access(const struct dentry * dentry,
56061+ const struct vfsmount * mnt, const int fmode)
56062+{
56063+ return 1;
56064+}
56065+
56066+__u32
56067+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
56068+ umode_t *mode)
56069+{
56070+ return 1;
56071+}
56072+
56073+__u32
56074+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
56075+{
56076+ return 1;
56077+}
56078+
56079+__u32
56080+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
56081+{
56082+ return 1;
56083+}
56084+
56085+void
56086+grsecurity_init(void)
56087+{
56088+ return;
56089+}
56090+
56091+umode_t gr_acl_umask(void)
56092+{
56093+ return 0;
56094+}
56095+
56096+__u32
56097+gr_acl_handle_mknod(const struct dentry * new_dentry,
56098+ const struct dentry * parent_dentry,
56099+ const struct vfsmount * parent_mnt,
56100+ const int mode)
56101+{
56102+ return 1;
56103+}
56104+
56105+__u32
56106+gr_acl_handle_mkdir(const struct dentry * new_dentry,
56107+ const struct dentry * parent_dentry,
56108+ const struct vfsmount * parent_mnt)
56109+{
56110+ return 1;
56111+}
56112+
56113+__u32
56114+gr_acl_handle_symlink(const struct dentry * new_dentry,
56115+ const struct dentry * parent_dentry,
56116+ const struct vfsmount * parent_mnt, const char *from)
56117+{
56118+ return 1;
56119+}
56120+
56121+__u32
56122+gr_acl_handle_link(const struct dentry * new_dentry,
56123+ const struct dentry * parent_dentry,
56124+ const struct vfsmount * parent_mnt,
56125+ const struct dentry * old_dentry,
56126+ const struct vfsmount * old_mnt, const char *to)
56127+{
56128+ return 1;
56129+}
56130+
56131+int
56132+gr_acl_handle_rename(const struct dentry *new_dentry,
56133+ const struct dentry *parent_dentry,
56134+ const struct vfsmount *parent_mnt,
56135+ const struct dentry *old_dentry,
56136+ const struct inode *old_parent_inode,
56137+ const struct vfsmount *old_mnt, const char *newname)
56138+{
56139+ return 0;
56140+}
56141+
56142+int
56143+gr_acl_handle_filldir(const struct file *file, const char *name,
56144+ const int namelen, const ino_t ino)
56145+{
56146+ return 1;
56147+}
56148+
56149+int
56150+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56151+ const time_t shm_createtime, const uid_t cuid, const int shmid)
56152+{
56153+ return 1;
56154+}
56155+
56156+int
56157+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
56158+{
56159+ return 0;
56160+}
56161+
56162+int
56163+gr_search_accept(const struct socket *sock)
56164+{
56165+ return 0;
56166+}
56167+
56168+int
56169+gr_search_listen(const struct socket *sock)
56170+{
56171+ return 0;
56172+}
56173+
56174+int
56175+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
56176+{
56177+ return 0;
56178+}
56179+
56180+__u32
56181+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
56182+{
56183+ return 1;
56184+}
56185+
56186+__u32
56187+gr_acl_handle_creat(const struct dentry * dentry,
56188+ const struct dentry * p_dentry,
56189+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56190+ const int imode)
56191+{
56192+ return 1;
56193+}
56194+
56195+void
56196+gr_acl_handle_exit(void)
56197+{
56198+ return;
56199+}
56200+
56201+int
56202+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
56203+{
56204+ return 1;
56205+}
56206+
56207+void
56208+gr_set_role_label(const uid_t uid, const gid_t gid)
56209+{
56210+ return;
56211+}
56212+
56213+int
56214+gr_acl_handle_procpidmem(const struct task_struct *task)
56215+{
56216+ return 0;
56217+}
56218+
56219+int
56220+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
56221+{
56222+ return 0;
56223+}
56224+
56225+int
56226+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
56227+{
56228+ return 0;
56229+}
56230+
56231+void
56232+gr_set_kernel_label(struct task_struct *task)
56233+{
56234+ return;
56235+}
56236+
56237+int
56238+gr_check_user_change(int real, int effective, int fs)
56239+{
56240+ return 0;
56241+}
56242+
56243+int
56244+gr_check_group_change(int real, int effective, int fs)
56245+{
56246+ return 0;
56247+}
56248+
56249+int gr_acl_enable_at_secure(void)
56250+{
56251+ return 0;
56252+}
56253+
56254+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
56255+{
56256+ return dentry->d_inode->i_sb->s_dev;
56257+}
56258+
56259+EXPORT_SYMBOL(gr_learn_resource);
56260+EXPORT_SYMBOL(gr_set_kernel_label);
56261+#ifdef CONFIG_SECURITY
56262+EXPORT_SYMBOL(gr_check_user_change);
56263+EXPORT_SYMBOL(gr_check_group_change);
56264+#endif
56265diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
56266new file mode 100644
56267index 0000000..abfa971
56268--- /dev/null
56269+++ b/grsecurity/grsec_exec.c
56270@@ -0,0 +1,174 @@
56271+#include <linux/kernel.h>
56272+#include <linux/sched.h>
56273+#include <linux/file.h>
56274+#include <linux/binfmts.h>
56275+#include <linux/fs.h>
56276+#include <linux/types.h>
56277+#include <linux/grdefs.h>
56278+#include <linux/grsecurity.h>
56279+#include <linux/grinternal.h>
56280+#include <linux/capability.h>
56281+#include <linux/module.h>
56282+
56283+#include <asm/uaccess.h>
56284+
56285+#ifdef CONFIG_GRKERNSEC_EXECLOG
56286+static char gr_exec_arg_buf[132];
56287+static DEFINE_MUTEX(gr_exec_arg_mutex);
56288+#endif
56289+
56290+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
56291+
56292+void
56293+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
56294+{
56295+#ifdef CONFIG_GRKERNSEC_EXECLOG
56296+ char *grarg = gr_exec_arg_buf;
56297+ unsigned int i, x, execlen = 0;
56298+ char c;
56299+
56300+ if (!((grsec_enable_execlog && grsec_enable_group &&
56301+ in_group_p(grsec_audit_gid))
56302+ || (grsec_enable_execlog && !grsec_enable_group)))
56303+ return;
56304+
56305+ mutex_lock(&gr_exec_arg_mutex);
56306+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
56307+
56308+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
56309+ const char __user *p;
56310+ unsigned int len;
56311+
56312+ p = get_user_arg_ptr(argv, i);
56313+ if (IS_ERR(p))
56314+ goto log;
56315+
56316+ len = strnlen_user(p, 128 - execlen);
56317+ if (len > 128 - execlen)
56318+ len = 128 - execlen;
56319+ else if (len > 0)
56320+ len--;
56321+ if (copy_from_user(grarg + execlen, p, len))
56322+ goto log;
56323+
56324+ /* rewrite unprintable characters */
56325+ for (x = 0; x < len; x++) {
56326+ c = *(grarg + execlen + x);
56327+ if (c < 32 || c > 126)
56328+ *(grarg + execlen + x) = ' ';
56329+ }
56330+
56331+ execlen += len;
56332+ *(grarg + execlen) = ' ';
56333+ *(grarg + execlen + 1) = '\0';
56334+ execlen++;
56335+ }
56336+
56337+ log:
56338+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
56339+ bprm->file->f_path.mnt, grarg);
56340+ mutex_unlock(&gr_exec_arg_mutex);
56341+#endif
56342+ return;
56343+}
56344+
56345+#ifdef CONFIG_GRKERNSEC
56346+extern int gr_acl_is_capable(const int cap);
56347+extern int gr_acl_is_capable_nolog(const int cap);
56348+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
56349+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
56350+extern int gr_chroot_is_capable(const int cap);
56351+extern int gr_chroot_is_capable_nolog(const int cap);
56352+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
56353+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
56354+#endif
56355+
56356+const char *captab_log[] = {
56357+ "CAP_CHOWN",
56358+ "CAP_DAC_OVERRIDE",
56359+ "CAP_DAC_READ_SEARCH",
56360+ "CAP_FOWNER",
56361+ "CAP_FSETID",
56362+ "CAP_KILL",
56363+ "CAP_SETGID",
56364+ "CAP_SETUID",
56365+ "CAP_SETPCAP",
56366+ "CAP_LINUX_IMMUTABLE",
56367+ "CAP_NET_BIND_SERVICE",
56368+ "CAP_NET_BROADCAST",
56369+ "CAP_NET_ADMIN",
56370+ "CAP_NET_RAW",
56371+ "CAP_IPC_LOCK",
56372+ "CAP_IPC_OWNER",
56373+ "CAP_SYS_MODULE",
56374+ "CAP_SYS_RAWIO",
56375+ "CAP_SYS_CHROOT",
56376+ "CAP_SYS_PTRACE",
56377+ "CAP_SYS_PACCT",
56378+ "CAP_SYS_ADMIN",
56379+ "CAP_SYS_BOOT",
56380+ "CAP_SYS_NICE",
56381+ "CAP_SYS_RESOURCE",
56382+ "CAP_SYS_TIME",
56383+ "CAP_SYS_TTY_CONFIG",
56384+ "CAP_MKNOD",
56385+ "CAP_LEASE",
56386+ "CAP_AUDIT_WRITE",
56387+ "CAP_AUDIT_CONTROL",
56388+ "CAP_SETFCAP",
56389+ "CAP_MAC_OVERRIDE",
56390+ "CAP_MAC_ADMIN",
56391+ "CAP_SYSLOG",
56392+ "CAP_WAKE_ALARM"
56393+};
56394+
56395+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
56396+
56397+int gr_is_capable(const int cap)
56398+{
56399+#ifdef CONFIG_GRKERNSEC
56400+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
56401+ return 1;
56402+ return 0;
56403+#else
56404+ return 1;
56405+#endif
56406+}
56407+
56408+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56409+{
56410+#ifdef CONFIG_GRKERNSEC
56411+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
56412+ return 1;
56413+ return 0;
56414+#else
56415+ return 1;
56416+#endif
56417+}
56418+
56419+int gr_is_capable_nolog(const int cap)
56420+{
56421+#ifdef CONFIG_GRKERNSEC
56422+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
56423+ return 1;
56424+ return 0;
56425+#else
56426+ return 1;
56427+#endif
56428+}
56429+
56430+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
56431+{
56432+#ifdef CONFIG_GRKERNSEC
56433+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
56434+ return 1;
56435+ return 0;
56436+#else
56437+ return 1;
56438+#endif
56439+}
56440+
56441+EXPORT_SYMBOL(gr_is_capable);
56442+EXPORT_SYMBOL(gr_is_capable_nolog);
56443+EXPORT_SYMBOL(gr_task_is_capable);
56444+EXPORT_SYMBOL(gr_task_is_capable_nolog);
56445diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
56446new file mode 100644
56447index 0000000..d3ee748
56448--- /dev/null
56449+++ b/grsecurity/grsec_fifo.c
56450@@ -0,0 +1,24 @@
56451+#include <linux/kernel.h>
56452+#include <linux/sched.h>
56453+#include <linux/fs.h>
56454+#include <linux/file.h>
56455+#include <linux/grinternal.h>
56456+
56457+int
56458+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
56459+ const struct dentry *dir, const int flag, const int acc_mode)
56460+{
56461+#ifdef CONFIG_GRKERNSEC_FIFO
56462+ const struct cred *cred = current_cred();
56463+
56464+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
56465+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
56466+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
56467+ (cred->fsuid != dentry->d_inode->i_uid)) {
56468+ if (!inode_permission(dentry->d_inode, acc_mode))
56469+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
56470+ return -EACCES;
56471+ }
56472+#endif
56473+ return 0;
56474+}
56475diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
56476new file mode 100644
56477index 0000000..8ca18bf
56478--- /dev/null
56479+++ b/grsecurity/grsec_fork.c
56480@@ -0,0 +1,23 @@
56481+#include <linux/kernel.h>
56482+#include <linux/sched.h>
56483+#include <linux/grsecurity.h>
56484+#include <linux/grinternal.h>
56485+#include <linux/errno.h>
56486+
56487+void
56488+gr_log_forkfail(const int retval)
56489+{
56490+#ifdef CONFIG_GRKERNSEC_FORKFAIL
56491+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
56492+ switch (retval) {
56493+ case -EAGAIN:
56494+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
56495+ break;
56496+ case -ENOMEM:
56497+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
56498+ break;
56499+ }
56500+ }
56501+#endif
56502+ return;
56503+}
56504diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
56505new file mode 100644
56506index 0000000..01ddde4
56507--- /dev/null
56508+++ b/grsecurity/grsec_init.c
56509@@ -0,0 +1,277 @@
56510+#include <linux/kernel.h>
56511+#include <linux/sched.h>
56512+#include <linux/mm.h>
56513+#include <linux/gracl.h>
56514+#include <linux/slab.h>
56515+#include <linux/vmalloc.h>
56516+#include <linux/percpu.h>
56517+#include <linux/module.h>
56518+
56519+int grsec_enable_ptrace_readexec;
56520+int grsec_enable_setxid;
56521+int grsec_enable_brute;
56522+int grsec_enable_link;
56523+int grsec_enable_dmesg;
56524+int grsec_enable_harden_ptrace;
56525+int grsec_enable_fifo;
56526+int grsec_enable_execlog;
56527+int grsec_enable_signal;
56528+int grsec_enable_forkfail;
56529+int grsec_enable_audit_ptrace;
56530+int grsec_enable_time;
56531+int grsec_enable_audit_textrel;
56532+int grsec_enable_group;
56533+int grsec_audit_gid;
56534+int grsec_enable_chdir;
56535+int grsec_enable_mount;
56536+int grsec_enable_rofs;
56537+int grsec_enable_chroot_findtask;
56538+int grsec_enable_chroot_mount;
56539+int grsec_enable_chroot_shmat;
56540+int grsec_enable_chroot_fchdir;
56541+int grsec_enable_chroot_double;
56542+int grsec_enable_chroot_pivot;
56543+int grsec_enable_chroot_chdir;
56544+int grsec_enable_chroot_chmod;
56545+int grsec_enable_chroot_mknod;
56546+int grsec_enable_chroot_nice;
56547+int grsec_enable_chroot_execlog;
56548+int grsec_enable_chroot_caps;
56549+int grsec_enable_chroot_sysctl;
56550+int grsec_enable_chroot_unix;
56551+int grsec_enable_tpe;
56552+int grsec_tpe_gid;
56553+int grsec_enable_blackhole;
56554+#ifdef CONFIG_IPV6_MODULE
56555+EXPORT_SYMBOL(grsec_enable_blackhole);
56556+#endif
56557+int grsec_lastack_retries;
56558+int grsec_enable_tpe_all;
56559+int grsec_enable_tpe_invert;
56560+int grsec_enable_socket_all;
56561+int grsec_socket_all_gid;
56562+int grsec_enable_socket_client;
56563+int grsec_socket_client_gid;
56564+int grsec_enable_socket_server;
56565+int grsec_socket_server_gid;
56566+int grsec_resource_logging;
56567+int grsec_disable_privio;
56568+int grsec_enable_log_rwxmaps;
56569+int grsec_lock;
56570+
56571+DEFINE_SPINLOCK(grsec_alert_lock);
56572+unsigned long grsec_alert_wtime = 0;
56573+unsigned long grsec_alert_fyet = 0;
56574+
56575+DEFINE_SPINLOCK(grsec_audit_lock);
56576+
56577+DEFINE_RWLOCK(grsec_exec_file_lock);
56578+
56579+char *gr_shared_page[4];
56580+
56581+char *gr_alert_log_fmt;
56582+char *gr_audit_log_fmt;
56583+char *gr_alert_log_buf;
56584+char *gr_audit_log_buf;
56585+
56586+extern struct gr_arg *gr_usermode;
56587+extern unsigned char *gr_system_salt;
56588+extern unsigned char *gr_system_sum;
56589+
56590+void __init
56591+grsecurity_init(void)
56592+{
56593+ int j;
56594+ /* create the per-cpu shared pages */
56595+
56596+#ifdef CONFIG_X86
56597+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
56598+#endif
56599+
56600+ for (j = 0; j < 4; j++) {
56601+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
56602+ if (gr_shared_page[j] == NULL) {
56603+ panic("Unable to allocate grsecurity shared page");
56604+ return;
56605+ }
56606+ }
56607+
56608+ /* allocate log buffers */
56609+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
56610+ if (!gr_alert_log_fmt) {
56611+ panic("Unable to allocate grsecurity alert log format buffer");
56612+ return;
56613+ }
56614+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
56615+ if (!gr_audit_log_fmt) {
56616+ panic("Unable to allocate grsecurity audit log format buffer");
56617+ return;
56618+ }
56619+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
56620+ if (!gr_alert_log_buf) {
56621+ panic("Unable to allocate grsecurity alert log buffer");
56622+ return;
56623+ }
56624+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
56625+ if (!gr_audit_log_buf) {
56626+ panic("Unable to allocate grsecurity audit log buffer");
56627+ return;
56628+ }
56629+
56630+ /* allocate memory for authentication structure */
56631+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
56632+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
56633+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
56634+
56635+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
56636+ panic("Unable to allocate grsecurity authentication structure");
56637+ return;
56638+ }
56639+
56640+
56641+#ifdef CONFIG_GRKERNSEC_IO
56642+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
56643+ grsec_disable_privio = 1;
56644+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
56645+ grsec_disable_privio = 1;
56646+#else
56647+ grsec_disable_privio = 0;
56648+#endif
56649+#endif
56650+
56651+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
56652+ /* for backward compatibility, tpe_invert always defaults to on if
56653+ enabled in the kernel
56654+ */
56655+ grsec_enable_tpe_invert = 1;
56656+#endif
56657+
56658+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
56659+#ifndef CONFIG_GRKERNSEC_SYSCTL
56660+ grsec_lock = 1;
56661+#endif
56662+
56663+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
56664+ grsec_enable_audit_textrel = 1;
56665+#endif
56666+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56667+ grsec_enable_log_rwxmaps = 1;
56668+#endif
56669+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
56670+ grsec_enable_group = 1;
56671+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
56672+#endif
56673+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
56674+ grsec_enable_ptrace_readexec = 1;
56675+#endif
56676+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56677+ grsec_enable_chdir = 1;
56678+#endif
56679+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
56680+ grsec_enable_harden_ptrace = 1;
56681+#endif
56682+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
56683+ grsec_enable_mount = 1;
56684+#endif
56685+#ifdef CONFIG_GRKERNSEC_LINK
56686+ grsec_enable_link = 1;
56687+#endif
56688+#ifdef CONFIG_GRKERNSEC_BRUTE
56689+ grsec_enable_brute = 1;
56690+#endif
56691+#ifdef CONFIG_GRKERNSEC_DMESG
56692+ grsec_enable_dmesg = 1;
56693+#endif
56694+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56695+ grsec_enable_blackhole = 1;
56696+ grsec_lastack_retries = 4;
56697+#endif
56698+#ifdef CONFIG_GRKERNSEC_FIFO
56699+ grsec_enable_fifo = 1;
56700+#endif
56701+#ifdef CONFIG_GRKERNSEC_EXECLOG
56702+ grsec_enable_execlog = 1;
56703+#endif
56704+#ifdef CONFIG_GRKERNSEC_SETXID
56705+ grsec_enable_setxid = 1;
56706+#endif
56707+#ifdef CONFIG_GRKERNSEC_SIGNAL
56708+ grsec_enable_signal = 1;
56709+#endif
56710+#ifdef CONFIG_GRKERNSEC_FORKFAIL
56711+ grsec_enable_forkfail = 1;
56712+#endif
56713+#ifdef CONFIG_GRKERNSEC_TIME
56714+ grsec_enable_time = 1;
56715+#endif
56716+#ifdef CONFIG_GRKERNSEC_RESLOG
56717+ grsec_resource_logging = 1;
56718+#endif
56719+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56720+ grsec_enable_chroot_findtask = 1;
56721+#endif
56722+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56723+ grsec_enable_chroot_unix = 1;
56724+#endif
56725+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56726+ grsec_enable_chroot_mount = 1;
56727+#endif
56728+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56729+ grsec_enable_chroot_fchdir = 1;
56730+#endif
56731+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56732+ grsec_enable_chroot_shmat = 1;
56733+#endif
56734+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
56735+ grsec_enable_audit_ptrace = 1;
56736+#endif
56737+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56738+ grsec_enable_chroot_double = 1;
56739+#endif
56740+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56741+ grsec_enable_chroot_pivot = 1;
56742+#endif
56743+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
56744+ grsec_enable_chroot_chdir = 1;
56745+#endif
56746+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
56747+ grsec_enable_chroot_chmod = 1;
56748+#endif
56749+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56750+ grsec_enable_chroot_mknod = 1;
56751+#endif
56752+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56753+ grsec_enable_chroot_nice = 1;
56754+#endif
56755+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56756+ grsec_enable_chroot_execlog = 1;
56757+#endif
56758+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56759+ grsec_enable_chroot_caps = 1;
56760+#endif
56761+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
56762+ grsec_enable_chroot_sysctl = 1;
56763+#endif
56764+#ifdef CONFIG_GRKERNSEC_TPE
56765+ grsec_enable_tpe = 1;
56766+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
56767+#ifdef CONFIG_GRKERNSEC_TPE_ALL
56768+ grsec_enable_tpe_all = 1;
56769+#endif
56770+#endif
56771+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
56772+ grsec_enable_socket_all = 1;
56773+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
56774+#endif
56775+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
56776+ grsec_enable_socket_client = 1;
56777+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
56778+#endif
56779+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
56780+ grsec_enable_socket_server = 1;
56781+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
56782+#endif
56783+#endif
56784+
56785+ return;
56786+}
56787diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
56788new file mode 100644
56789index 0000000..3efe141
56790--- /dev/null
56791+++ b/grsecurity/grsec_link.c
56792@@ -0,0 +1,43 @@
56793+#include <linux/kernel.h>
56794+#include <linux/sched.h>
56795+#include <linux/fs.h>
56796+#include <linux/file.h>
56797+#include <linux/grinternal.h>
56798+
56799+int
56800+gr_handle_follow_link(const struct inode *parent,
56801+ const struct inode *inode,
56802+ const struct dentry *dentry, const struct vfsmount *mnt)
56803+{
56804+#ifdef CONFIG_GRKERNSEC_LINK
56805+ const struct cred *cred = current_cred();
56806+
56807+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
56808+ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
56809+ (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
56810+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
56811+ return -EACCES;
56812+ }
56813+#endif
56814+ return 0;
56815+}
56816+
56817+int
56818+gr_handle_hardlink(const struct dentry *dentry,
56819+ const struct vfsmount *mnt,
56820+ struct inode *inode, const int mode, const char *to)
56821+{
56822+#ifdef CONFIG_GRKERNSEC_LINK
56823+ const struct cred *cred = current_cred();
56824+
56825+ if (grsec_enable_link && cred->fsuid != inode->i_uid &&
56826+ (!S_ISREG(mode) || (mode & S_ISUID) ||
56827+ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
56828+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
56829+ !capable(CAP_FOWNER) && cred->uid) {
56830+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
56831+ return -EPERM;
56832+ }
56833+#endif
56834+ return 0;
56835+}
56836diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
56837new file mode 100644
56838index 0000000..a45d2e9
56839--- /dev/null
56840+++ b/grsecurity/grsec_log.c
56841@@ -0,0 +1,322 @@
56842+#include <linux/kernel.h>
56843+#include <linux/sched.h>
56844+#include <linux/file.h>
56845+#include <linux/tty.h>
56846+#include <linux/fs.h>
56847+#include <linux/grinternal.h>
56848+
56849+#ifdef CONFIG_TREE_PREEMPT_RCU
56850+#define DISABLE_PREEMPT() preempt_disable()
56851+#define ENABLE_PREEMPT() preempt_enable()
56852+#else
56853+#define DISABLE_PREEMPT()
56854+#define ENABLE_PREEMPT()
56855+#endif
56856+
56857+#define BEGIN_LOCKS(x) \
56858+ DISABLE_PREEMPT(); \
56859+ rcu_read_lock(); \
56860+ read_lock(&tasklist_lock); \
56861+ read_lock(&grsec_exec_file_lock); \
56862+ if (x != GR_DO_AUDIT) \
56863+ spin_lock(&grsec_alert_lock); \
56864+ else \
56865+ spin_lock(&grsec_audit_lock)
56866+
56867+#define END_LOCKS(x) \
56868+ if (x != GR_DO_AUDIT) \
56869+ spin_unlock(&grsec_alert_lock); \
56870+ else \
56871+ spin_unlock(&grsec_audit_lock); \
56872+ read_unlock(&grsec_exec_file_lock); \
56873+ read_unlock(&tasklist_lock); \
56874+ rcu_read_unlock(); \
56875+ ENABLE_PREEMPT(); \
56876+ if (x == GR_DONT_AUDIT) \
56877+ gr_handle_alertkill(current)
56878+
56879+enum {
56880+ FLOODING,
56881+ NO_FLOODING
56882+};
56883+
56884+extern char *gr_alert_log_fmt;
56885+extern char *gr_audit_log_fmt;
56886+extern char *gr_alert_log_buf;
56887+extern char *gr_audit_log_buf;
56888+
56889+static int gr_log_start(int audit)
56890+{
56891+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
56892+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
56893+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
56894+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
56895+ unsigned long curr_secs = get_seconds();
56896+
56897+ if (audit == GR_DO_AUDIT)
56898+ goto set_fmt;
56899+
56900+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
56901+ grsec_alert_wtime = curr_secs;
56902+ grsec_alert_fyet = 0;
56903+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
56904+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
56905+ grsec_alert_fyet++;
56906+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
56907+ grsec_alert_wtime = curr_secs;
56908+ grsec_alert_fyet++;
56909+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
56910+ return FLOODING;
56911+ }
56912+ else return FLOODING;
56913+
56914+set_fmt:
56915+#endif
56916+ memset(buf, 0, PAGE_SIZE);
56917+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
56918+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
56919+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
56920+ } else if (current->signal->curr_ip) {
56921+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
56922+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
56923+ } else if (gr_acl_is_enabled()) {
56924+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
56925+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
56926+ } else {
56927+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
56928+ strcpy(buf, fmt);
56929+ }
56930+
56931+ return NO_FLOODING;
56932+}
56933+
56934+static void gr_log_middle(int audit, const char *msg, va_list ap)
56935+ __attribute__ ((format (printf, 2, 0)));
56936+
56937+static void gr_log_middle(int audit, const char *msg, va_list ap)
56938+{
56939+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
56940+ unsigned int len = strlen(buf);
56941+
56942+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
56943+
56944+ return;
56945+}
56946+
56947+static void gr_log_middle_varargs(int audit, const char *msg, ...)
56948+ __attribute__ ((format (printf, 2, 3)));
56949+
56950+static void gr_log_middle_varargs(int audit, const char *msg, ...)
56951+{
56952+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
56953+ unsigned int len = strlen(buf);
56954+ va_list ap;
56955+
56956+ va_start(ap, msg);
56957+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
56958+ va_end(ap);
56959+
56960+ return;
56961+}
56962+
56963+static void gr_log_end(int audit, int append_default)
56964+{
56965+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
56966+
56967+ if (append_default) {
56968+ unsigned int len = strlen(buf);
56969+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
56970+ }
56971+
56972+ printk("%s\n", buf);
56973+
56974+ return;
56975+}
56976+
56977+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
56978+{
56979+ int logtype;
56980+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
56981+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
56982+ void *voidptr = NULL;
56983+ int num1 = 0, num2 = 0;
56984+ unsigned long ulong1 = 0, ulong2 = 0;
56985+ struct dentry *dentry = NULL;
56986+ struct vfsmount *mnt = NULL;
56987+ struct file *file = NULL;
56988+ struct task_struct *task = NULL;
56989+ const struct cred *cred, *pcred;
56990+ va_list ap;
56991+
56992+ BEGIN_LOCKS(audit);
56993+ logtype = gr_log_start(audit);
56994+ if (logtype == FLOODING) {
56995+ END_LOCKS(audit);
56996+ return;
56997+ }
56998+ va_start(ap, argtypes);
56999+ switch (argtypes) {
57000+ case GR_TTYSNIFF:
57001+ task = va_arg(ap, struct task_struct *);
57002+ 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);
57003+ break;
57004+ case GR_SYSCTL_HIDDEN:
57005+ str1 = va_arg(ap, char *);
57006+ gr_log_middle_varargs(audit, msg, result, str1);
57007+ break;
57008+ case GR_RBAC:
57009+ dentry = va_arg(ap, struct dentry *);
57010+ mnt = va_arg(ap, struct vfsmount *);
57011+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
57012+ break;
57013+ case GR_RBAC_STR:
57014+ dentry = va_arg(ap, struct dentry *);
57015+ mnt = va_arg(ap, struct vfsmount *);
57016+ str1 = va_arg(ap, char *);
57017+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
57018+ break;
57019+ case GR_STR_RBAC:
57020+ str1 = va_arg(ap, char *);
57021+ dentry = va_arg(ap, struct dentry *);
57022+ mnt = va_arg(ap, struct vfsmount *);
57023+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
57024+ break;
57025+ case GR_RBAC_MODE2:
57026+ dentry = va_arg(ap, struct dentry *);
57027+ mnt = va_arg(ap, struct vfsmount *);
57028+ str1 = va_arg(ap, char *);
57029+ str2 = va_arg(ap, char *);
57030+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
57031+ break;
57032+ case GR_RBAC_MODE3:
57033+ dentry = va_arg(ap, struct dentry *);
57034+ mnt = va_arg(ap, struct vfsmount *);
57035+ str1 = va_arg(ap, char *);
57036+ str2 = va_arg(ap, char *);
57037+ str3 = va_arg(ap, char *);
57038+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
57039+ break;
57040+ case GR_FILENAME:
57041+ dentry = va_arg(ap, struct dentry *);
57042+ mnt = va_arg(ap, struct vfsmount *);
57043+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
57044+ break;
57045+ case GR_STR_FILENAME:
57046+ str1 = va_arg(ap, char *);
57047+ dentry = va_arg(ap, struct dentry *);
57048+ mnt = va_arg(ap, struct vfsmount *);
57049+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
57050+ break;
57051+ case GR_FILENAME_STR:
57052+ dentry = va_arg(ap, struct dentry *);
57053+ mnt = va_arg(ap, struct vfsmount *);
57054+ str1 = va_arg(ap, char *);
57055+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
57056+ break;
57057+ case GR_FILENAME_TWO_INT:
57058+ dentry = va_arg(ap, struct dentry *);
57059+ mnt = va_arg(ap, struct vfsmount *);
57060+ num1 = va_arg(ap, int);
57061+ num2 = va_arg(ap, int);
57062+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
57063+ break;
57064+ case GR_FILENAME_TWO_INT_STR:
57065+ dentry = va_arg(ap, struct dentry *);
57066+ mnt = va_arg(ap, struct vfsmount *);
57067+ num1 = va_arg(ap, int);
57068+ num2 = va_arg(ap, int);
57069+ str1 = va_arg(ap, char *);
57070+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
57071+ break;
57072+ case GR_TEXTREL:
57073+ file = va_arg(ap, struct file *);
57074+ ulong1 = va_arg(ap, unsigned long);
57075+ ulong2 = va_arg(ap, unsigned long);
57076+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
57077+ break;
57078+ case GR_PTRACE:
57079+ task = va_arg(ap, struct task_struct *);
57080+ 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);
57081+ break;
57082+ case GR_RESOURCE:
57083+ task = va_arg(ap, struct task_struct *);
57084+ cred = __task_cred(task);
57085+ pcred = __task_cred(task->real_parent);
57086+ ulong1 = va_arg(ap, unsigned long);
57087+ str1 = va_arg(ap, char *);
57088+ ulong2 = va_arg(ap, unsigned long);
57089+ 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);
57090+ break;
57091+ case GR_CAP:
57092+ task = va_arg(ap, struct task_struct *);
57093+ cred = __task_cred(task);
57094+ pcred = __task_cred(task->real_parent);
57095+ str1 = va_arg(ap, char *);
57096+ 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);
57097+ break;
57098+ case GR_SIG:
57099+ str1 = va_arg(ap, char *);
57100+ voidptr = va_arg(ap, void *);
57101+ gr_log_middle_varargs(audit, msg, str1, voidptr);
57102+ break;
57103+ case GR_SIG2:
57104+ task = va_arg(ap, struct task_struct *);
57105+ cred = __task_cred(task);
57106+ pcred = __task_cred(task->real_parent);
57107+ num1 = va_arg(ap, int);
57108+ 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);
57109+ break;
57110+ case GR_CRASH1:
57111+ task = va_arg(ap, struct task_struct *);
57112+ cred = __task_cred(task);
57113+ pcred = __task_cred(task->real_parent);
57114+ ulong1 = va_arg(ap, unsigned long);
57115+ 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);
57116+ break;
57117+ case GR_CRASH2:
57118+ task = va_arg(ap, struct task_struct *);
57119+ cred = __task_cred(task);
57120+ pcred = __task_cred(task->real_parent);
57121+ ulong1 = va_arg(ap, unsigned long);
57122+ 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);
57123+ break;
57124+ case GR_RWXMAP:
57125+ file = va_arg(ap, struct file *);
57126+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
57127+ break;
57128+ case GR_PSACCT:
57129+ {
57130+ unsigned int wday, cday;
57131+ __u8 whr, chr;
57132+ __u8 wmin, cmin;
57133+ __u8 wsec, csec;
57134+ char cur_tty[64] = { 0 };
57135+ char parent_tty[64] = { 0 };
57136+
57137+ task = va_arg(ap, struct task_struct *);
57138+ wday = va_arg(ap, unsigned int);
57139+ cday = va_arg(ap, unsigned int);
57140+ whr = va_arg(ap, int);
57141+ chr = va_arg(ap, int);
57142+ wmin = va_arg(ap, int);
57143+ cmin = va_arg(ap, int);
57144+ wsec = va_arg(ap, int);
57145+ csec = va_arg(ap, int);
57146+ ulong1 = va_arg(ap, unsigned long);
57147+ cred = __task_cred(task);
57148+ pcred = __task_cred(task->real_parent);
57149+
57150+ 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);
57151+ }
57152+ break;
57153+ default:
57154+ gr_log_middle(audit, msg, ap);
57155+ }
57156+ va_end(ap);
57157+ // these don't need DEFAULTSECARGS printed on the end
57158+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
57159+ gr_log_end(audit, 0);
57160+ else
57161+ gr_log_end(audit, 1);
57162+ END_LOCKS(audit);
57163+}
57164diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
57165new file mode 100644
57166index 0000000..f536303
57167--- /dev/null
57168+++ b/grsecurity/grsec_mem.c
57169@@ -0,0 +1,40 @@
57170+#include <linux/kernel.h>
57171+#include <linux/sched.h>
57172+#include <linux/mm.h>
57173+#include <linux/mman.h>
57174+#include <linux/grinternal.h>
57175+
57176+void
57177+gr_handle_ioperm(void)
57178+{
57179+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
57180+ return;
57181+}
57182+
57183+void
57184+gr_handle_iopl(void)
57185+{
57186+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
57187+ return;
57188+}
57189+
57190+void
57191+gr_handle_mem_readwrite(u64 from, u64 to)
57192+{
57193+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
57194+ return;
57195+}
57196+
57197+void
57198+gr_handle_vm86(void)
57199+{
57200+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
57201+ return;
57202+}
57203+
57204+void
57205+gr_log_badprocpid(const char *entry)
57206+{
57207+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
57208+ return;
57209+}
57210diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
57211new file mode 100644
57212index 0000000..2131422
57213--- /dev/null
57214+++ b/grsecurity/grsec_mount.c
57215@@ -0,0 +1,62 @@
57216+#include <linux/kernel.h>
57217+#include <linux/sched.h>
57218+#include <linux/mount.h>
57219+#include <linux/grsecurity.h>
57220+#include <linux/grinternal.h>
57221+
57222+void
57223+gr_log_remount(const char *devname, const int retval)
57224+{
57225+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57226+ if (grsec_enable_mount && (retval >= 0))
57227+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
57228+#endif
57229+ return;
57230+}
57231+
57232+void
57233+gr_log_unmount(const char *devname, const int retval)
57234+{
57235+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57236+ if (grsec_enable_mount && (retval >= 0))
57237+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
57238+#endif
57239+ return;
57240+}
57241+
57242+void
57243+gr_log_mount(const char *from, const char *to, const int retval)
57244+{
57245+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57246+ if (grsec_enable_mount && (retval >= 0))
57247+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
57248+#endif
57249+ return;
57250+}
57251+
57252+int
57253+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
57254+{
57255+#ifdef CONFIG_GRKERNSEC_ROFS
57256+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
57257+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
57258+ return -EPERM;
57259+ } else
57260+ return 0;
57261+#endif
57262+ return 0;
57263+}
57264+
57265+int
57266+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
57267+{
57268+#ifdef CONFIG_GRKERNSEC_ROFS
57269+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
57270+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
57271+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
57272+ return -EPERM;
57273+ } else
57274+ return 0;
57275+#endif
57276+ return 0;
57277+}
57278diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
57279new file mode 100644
57280index 0000000..a3b12a0
57281--- /dev/null
57282+++ b/grsecurity/grsec_pax.c
57283@@ -0,0 +1,36 @@
57284+#include <linux/kernel.h>
57285+#include <linux/sched.h>
57286+#include <linux/mm.h>
57287+#include <linux/file.h>
57288+#include <linux/grinternal.h>
57289+#include <linux/grsecurity.h>
57290+
57291+void
57292+gr_log_textrel(struct vm_area_struct * vma)
57293+{
57294+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57295+ if (grsec_enable_audit_textrel)
57296+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
57297+#endif
57298+ return;
57299+}
57300+
57301+void
57302+gr_log_rwxmmap(struct file *file)
57303+{
57304+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57305+ if (grsec_enable_log_rwxmaps)
57306+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
57307+#endif
57308+ return;
57309+}
57310+
57311+void
57312+gr_log_rwxmprotect(struct file *file)
57313+{
57314+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57315+ if (grsec_enable_log_rwxmaps)
57316+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
57317+#endif
57318+ return;
57319+}
57320diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
57321new file mode 100644
57322index 0000000..f7f29aa
57323--- /dev/null
57324+++ b/grsecurity/grsec_ptrace.c
57325@@ -0,0 +1,30 @@
57326+#include <linux/kernel.h>
57327+#include <linux/sched.h>
57328+#include <linux/grinternal.h>
57329+#include <linux/security.h>
57330+
57331+void
57332+gr_audit_ptrace(struct task_struct *task)
57333+{
57334+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57335+ if (grsec_enable_audit_ptrace)
57336+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
57337+#endif
57338+ return;
57339+}
57340+
57341+int
57342+gr_ptrace_readexec(struct file *file, int unsafe_flags)
57343+{
57344+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57345+ const struct dentry *dentry = file->f_path.dentry;
57346+ const struct vfsmount *mnt = file->f_path.mnt;
57347+
57348+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
57349+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
57350+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
57351+ return -EACCES;
57352+ }
57353+#endif
57354+ return 0;
57355+}
57356diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
57357new file mode 100644
57358index 0000000..7a5b2de
57359--- /dev/null
57360+++ b/grsecurity/grsec_sig.c
57361@@ -0,0 +1,207 @@
57362+#include <linux/kernel.h>
57363+#include <linux/sched.h>
57364+#include <linux/delay.h>
57365+#include <linux/grsecurity.h>
57366+#include <linux/grinternal.h>
57367+#include <linux/hardirq.h>
57368+
57369+char *signames[] = {
57370+ [SIGSEGV] = "Segmentation fault",
57371+ [SIGILL] = "Illegal instruction",
57372+ [SIGABRT] = "Abort",
57373+ [SIGBUS] = "Invalid alignment/Bus error"
57374+};
57375+
57376+void
57377+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
57378+{
57379+#ifdef CONFIG_GRKERNSEC_SIGNAL
57380+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
57381+ (sig == SIGABRT) || (sig == SIGBUS))) {
57382+ if (t->pid == current->pid) {
57383+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
57384+ } else {
57385+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
57386+ }
57387+ }
57388+#endif
57389+ return;
57390+}
57391+
57392+int
57393+gr_handle_signal(const struct task_struct *p, const int sig)
57394+{
57395+#ifdef CONFIG_GRKERNSEC
57396+ /* ignore the 0 signal for protected task checks */
57397+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
57398+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
57399+ return -EPERM;
57400+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
57401+ return -EPERM;
57402+ }
57403+#endif
57404+ return 0;
57405+}
57406+
57407+#ifdef CONFIG_GRKERNSEC
57408+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
57409+
57410+int gr_fake_force_sig(int sig, struct task_struct *t)
57411+{
57412+ unsigned long int flags;
57413+ int ret, blocked, ignored;
57414+ struct k_sigaction *action;
57415+
57416+ spin_lock_irqsave(&t->sighand->siglock, flags);
57417+ action = &t->sighand->action[sig-1];
57418+ ignored = action->sa.sa_handler == SIG_IGN;
57419+ blocked = sigismember(&t->blocked, sig);
57420+ if (blocked || ignored) {
57421+ action->sa.sa_handler = SIG_DFL;
57422+ if (blocked) {
57423+ sigdelset(&t->blocked, sig);
57424+ recalc_sigpending_and_wake(t);
57425+ }
57426+ }
57427+ if (action->sa.sa_handler == SIG_DFL)
57428+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
57429+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
57430+
57431+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
57432+
57433+ return ret;
57434+}
57435+#endif
57436+
57437+#ifdef CONFIG_GRKERNSEC_BRUTE
57438+#define GR_USER_BAN_TIME (15 * 60)
57439+
57440+static int __get_dumpable(unsigned long mm_flags)
57441+{
57442+ int ret;
57443+
57444+ ret = mm_flags & MMF_DUMPABLE_MASK;
57445+ return (ret >= 2) ? 2 : ret;
57446+}
57447+#endif
57448+
57449+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
57450+{
57451+#ifdef CONFIG_GRKERNSEC_BRUTE
57452+ uid_t uid = 0;
57453+
57454+ if (!grsec_enable_brute)
57455+ return;
57456+
57457+ rcu_read_lock();
57458+ read_lock(&tasklist_lock);
57459+ read_lock(&grsec_exec_file_lock);
57460+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
57461+ p->real_parent->brute = 1;
57462+ else {
57463+ const struct cred *cred = __task_cred(p), *cred2;
57464+ struct task_struct *tsk, *tsk2;
57465+
57466+ if (!__get_dumpable(mm_flags) && cred->uid) {
57467+ struct user_struct *user;
57468+
57469+ uid = cred->uid;
57470+
57471+ /* this is put upon execution past expiration */
57472+ user = find_user(uid);
57473+ if (user == NULL)
57474+ goto unlock;
57475+ user->banned = 1;
57476+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
57477+ if (user->ban_expires == ~0UL)
57478+ user->ban_expires--;
57479+
57480+ do_each_thread(tsk2, tsk) {
57481+ cred2 = __task_cred(tsk);
57482+ if (tsk != p && cred2->uid == uid)
57483+ gr_fake_force_sig(SIGKILL, tsk);
57484+ } while_each_thread(tsk2, tsk);
57485+ }
57486+ }
57487+unlock:
57488+ read_unlock(&grsec_exec_file_lock);
57489+ read_unlock(&tasklist_lock);
57490+ rcu_read_unlock();
57491+
57492+ if (uid)
57493+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
57494+
57495+#endif
57496+ return;
57497+}
57498+
57499+void gr_handle_brute_check(void)
57500+{
57501+#ifdef CONFIG_GRKERNSEC_BRUTE
57502+ if (current->brute)
57503+ msleep(30 * 1000);
57504+#endif
57505+ return;
57506+}
57507+
57508+void gr_handle_kernel_exploit(void)
57509+{
57510+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
57511+ const struct cred *cred;
57512+ struct task_struct *tsk, *tsk2;
57513+ struct user_struct *user;
57514+ uid_t uid;
57515+
57516+ if (in_irq() || in_serving_softirq() || in_nmi())
57517+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
57518+
57519+ uid = current_uid();
57520+
57521+ if (uid == 0)
57522+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
57523+ else {
57524+ /* kill all the processes of this user, hold a reference
57525+ to their creds struct, and prevent them from creating
57526+ another process until system reset
57527+ */
57528+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
57529+ /* we intentionally leak this ref */
57530+ user = get_uid(current->cred->user);
57531+ if (user) {
57532+ user->banned = 1;
57533+ user->ban_expires = ~0UL;
57534+ }
57535+
57536+ read_lock(&tasklist_lock);
57537+ do_each_thread(tsk2, tsk) {
57538+ cred = __task_cred(tsk);
57539+ if (cred->uid == uid)
57540+ gr_fake_force_sig(SIGKILL, tsk);
57541+ } while_each_thread(tsk2, tsk);
57542+ read_unlock(&tasklist_lock);
57543+ }
57544+#endif
57545+}
57546+
57547+int __gr_process_user_ban(struct user_struct *user)
57548+{
57549+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
57550+ if (unlikely(user->banned)) {
57551+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
57552+ user->banned = 0;
57553+ user->ban_expires = 0;
57554+ free_uid(user);
57555+ } else
57556+ return -EPERM;
57557+ }
57558+#endif
57559+ return 0;
57560+}
57561+
57562+int gr_process_user_ban(void)
57563+{
57564+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
57565+ return __gr_process_user_ban(current->cred->user);
57566+#endif
57567+ return 0;
57568+}
57569diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
57570new file mode 100644
57571index 0000000..4030d57
57572--- /dev/null
57573+++ b/grsecurity/grsec_sock.c
57574@@ -0,0 +1,244 @@
57575+#include <linux/kernel.h>
57576+#include <linux/module.h>
57577+#include <linux/sched.h>
57578+#include <linux/file.h>
57579+#include <linux/net.h>
57580+#include <linux/in.h>
57581+#include <linux/ip.h>
57582+#include <net/sock.h>
57583+#include <net/inet_sock.h>
57584+#include <linux/grsecurity.h>
57585+#include <linux/grinternal.h>
57586+#include <linux/gracl.h>
57587+
57588+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
57589+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
57590+
57591+EXPORT_SYMBOL(gr_search_udp_recvmsg);
57592+EXPORT_SYMBOL(gr_search_udp_sendmsg);
57593+
57594+#ifdef CONFIG_UNIX_MODULE
57595+EXPORT_SYMBOL(gr_acl_handle_unix);
57596+EXPORT_SYMBOL(gr_acl_handle_mknod);
57597+EXPORT_SYMBOL(gr_handle_chroot_unix);
57598+EXPORT_SYMBOL(gr_handle_create);
57599+#endif
57600+
57601+#ifdef CONFIG_GRKERNSEC
57602+#define gr_conn_table_size 32749
57603+struct conn_table_entry {
57604+ struct conn_table_entry *next;
57605+ struct signal_struct *sig;
57606+};
57607+
57608+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
57609+DEFINE_SPINLOCK(gr_conn_table_lock);
57610+
57611+extern const char * gr_socktype_to_name(unsigned char type);
57612+extern const char * gr_proto_to_name(unsigned char proto);
57613+extern const char * gr_sockfamily_to_name(unsigned char family);
57614+
57615+static __inline__ int
57616+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
57617+{
57618+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
57619+}
57620+
57621+static __inline__ int
57622+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
57623+ __u16 sport, __u16 dport)
57624+{
57625+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
57626+ sig->gr_sport == sport && sig->gr_dport == dport))
57627+ return 1;
57628+ else
57629+ return 0;
57630+}
57631+
57632+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
57633+{
57634+ struct conn_table_entry **match;
57635+ unsigned int index;
57636+
57637+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
57638+ sig->gr_sport, sig->gr_dport,
57639+ gr_conn_table_size);
57640+
57641+ newent->sig = sig;
57642+
57643+ match = &gr_conn_table[index];
57644+ newent->next = *match;
57645+ *match = newent;
57646+
57647+ return;
57648+}
57649+
57650+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
57651+{
57652+ struct conn_table_entry *match, *last = NULL;
57653+ unsigned int index;
57654+
57655+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
57656+ sig->gr_sport, sig->gr_dport,
57657+ gr_conn_table_size);
57658+
57659+ match = gr_conn_table[index];
57660+ while (match && !conn_match(match->sig,
57661+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
57662+ sig->gr_dport)) {
57663+ last = match;
57664+ match = match->next;
57665+ }
57666+
57667+ if (match) {
57668+ if (last)
57669+ last->next = match->next;
57670+ else
57671+ gr_conn_table[index] = NULL;
57672+ kfree(match);
57673+ }
57674+
57675+ return;
57676+}
57677+
57678+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
57679+ __u16 sport, __u16 dport)
57680+{
57681+ struct conn_table_entry *match;
57682+ unsigned int index;
57683+
57684+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
57685+
57686+ match = gr_conn_table[index];
57687+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
57688+ match = match->next;
57689+
57690+ if (match)
57691+ return match->sig;
57692+ else
57693+ return NULL;
57694+}
57695+
57696+#endif
57697+
57698+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
57699+{
57700+#ifdef CONFIG_GRKERNSEC
57701+ struct signal_struct *sig = task->signal;
57702+ struct conn_table_entry *newent;
57703+
57704+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
57705+ if (newent == NULL)
57706+ return;
57707+ /* no bh lock needed since we are called with bh disabled */
57708+ spin_lock(&gr_conn_table_lock);
57709+ gr_del_task_from_ip_table_nolock(sig);
57710+ sig->gr_saddr = inet->inet_rcv_saddr;
57711+ sig->gr_daddr = inet->inet_daddr;
57712+ sig->gr_sport = inet->inet_sport;
57713+ sig->gr_dport = inet->inet_dport;
57714+ gr_add_to_task_ip_table_nolock(sig, newent);
57715+ spin_unlock(&gr_conn_table_lock);
57716+#endif
57717+ return;
57718+}
57719+
57720+void gr_del_task_from_ip_table(struct task_struct *task)
57721+{
57722+#ifdef CONFIG_GRKERNSEC
57723+ spin_lock_bh(&gr_conn_table_lock);
57724+ gr_del_task_from_ip_table_nolock(task->signal);
57725+ spin_unlock_bh(&gr_conn_table_lock);
57726+#endif
57727+ return;
57728+}
57729+
57730+void
57731+gr_attach_curr_ip(const struct sock *sk)
57732+{
57733+#ifdef CONFIG_GRKERNSEC
57734+ struct signal_struct *p, *set;
57735+ const struct inet_sock *inet = inet_sk(sk);
57736+
57737+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
57738+ return;
57739+
57740+ set = current->signal;
57741+
57742+ spin_lock_bh(&gr_conn_table_lock);
57743+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
57744+ inet->inet_dport, inet->inet_sport);
57745+ if (unlikely(p != NULL)) {
57746+ set->curr_ip = p->curr_ip;
57747+ set->used_accept = 1;
57748+ gr_del_task_from_ip_table_nolock(p);
57749+ spin_unlock_bh(&gr_conn_table_lock);
57750+ return;
57751+ }
57752+ spin_unlock_bh(&gr_conn_table_lock);
57753+
57754+ set->curr_ip = inet->inet_daddr;
57755+ set->used_accept = 1;
57756+#endif
57757+ return;
57758+}
57759+
57760+int
57761+gr_handle_sock_all(const int family, const int type, const int protocol)
57762+{
57763+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
57764+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
57765+ (family != AF_UNIX)) {
57766+ if (family == AF_INET)
57767+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
57768+ else
57769+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
57770+ return -EACCES;
57771+ }
57772+#endif
57773+ return 0;
57774+}
57775+
57776+int
57777+gr_handle_sock_server(const struct sockaddr *sck)
57778+{
57779+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
57780+ if (grsec_enable_socket_server &&
57781+ in_group_p(grsec_socket_server_gid) &&
57782+ sck && (sck->sa_family != AF_UNIX) &&
57783+ (sck->sa_family != AF_LOCAL)) {
57784+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
57785+ return -EACCES;
57786+ }
57787+#endif
57788+ return 0;
57789+}
57790+
57791+int
57792+gr_handle_sock_server_other(const struct sock *sck)
57793+{
57794+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
57795+ if (grsec_enable_socket_server &&
57796+ in_group_p(grsec_socket_server_gid) &&
57797+ sck && (sck->sk_family != AF_UNIX) &&
57798+ (sck->sk_family != AF_LOCAL)) {
57799+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
57800+ return -EACCES;
57801+ }
57802+#endif
57803+ return 0;
57804+}
57805+
57806+int
57807+gr_handle_sock_client(const struct sockaddr *sck)
57808+{
57809+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
57810+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
57811+ sck && (sck->sa_family != AF_UNIX) &&
57812+ (sck->sa_family != AF_LOCAL)) {
57813+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
57814+ return -EACCES;
57815+ }
57816+#endif
57817+ return 0;
57818+}
57819diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
57820new file mode 100644
57821index 0000000..a1aedd7
57822--- /dev/null
57823+++ b/grsecurity/grsec_sysctl.c
57824@@ -0,0 +1,451 @@
57825+#include <linux/kernel.h>
57826+#include <linux/sched.h>
57827+#include <linux/sysctl.h>
57828+#include <linux/grsecurity.h>
57829+#include <linux/grinternal.h>
57830+
57831+int
57832+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
57833+{
57834+#ifdef CONFIG_GRKERNSEC_SYSCTL
57835+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
57836+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
57837+ return -EACCES;
57838+ }
57839+#endif
57840+ return 0;
57841+}
57842+
57843+#ifdef CONFIG_GRKERNSEC_ROFS
57844+static int __maybe_unused one = 1;
57845+#endif
57846+
57847+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
57848+struct ctl_table grsecurity_table[] = {
57849+#ifdef CONFIG_GRKERNSEC_SYSCTL
57850+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
57851+#ifdef CONFIG_GRKERNSEC_IO
57852+ {
57853+ .procname = "disable_priv_io",
57854+ .data = &grsec_disable_privio,
57855+ .maxlen = sizeof(int),
57856+ .mode = 0600,
57857+ .proc_handler = &proc_dointvec,
57858+ },
57859+#endif
57860+#endif
57861+#ifdef CONFIG_GRKERNSEC_LINK
57862+ {
57863+ .procname = "linking_restrictions",
57864+ .data = &grsec_enable_link,
57865+ .maxlen = sizeof(int),
57866+ .mode = 0600,
57867+ .proc_handler = &proc_dointvec,
57868+ },
57869+#endif
57870+#ifdef CONFIG_GRKERNSEC_BRUTE
57871+ {
57872+ .procname = "deter_bruteforce",
57873+ .data = &grsec_enable_brute,
57874+ .maxlen = sizeof(int),
57875+ .mode = 0600,
57876+ .proc_handler = &proc_dointvec,
57877+ },
57878+#endif
57879+#ifdef CONFIG_GRKERNSEC_FIFO
57880+ {
57881+ .procname = "fifo_restrictions",
57882+ .data = &grsec_enable_fifo,
57883+ .maxlen = sizeof(int),
57884+ .mode = 0600,
57885+ .proc_handler = &proc_dointvec,
57886+ },
57887+#endif
57888+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57889+ {
57890+ .procname = "ptrace_readexec",
57891+ .data = &grsec_enable_ptrace_readexec,
57892+ .maxlen = sizeof(int),
57893+ .mode = 0600,
57894+ .proc_handler = &proc_dointvec,
57895+ },
57896+#endif
57897+#ifdef CONFIG_GRKERNSEC_SETXID
57898+ {
57899+ .procname = "consistent_setxid",
57900+ .data = &grsec_enable_setxid,
57901+ .maxlen = sizeof(int),
57902+ .mode = 0600,
57903+ .proc_handler = &proc_dointvec,
57904+ },
57905+#endif
57906+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
57907+ {
57908+ .procname = "ip_blackhole",
57909+ .data = &grsec_enable_blackhole,
57910+ .maxlen = sizeof(int),
57911+ .mode = 0600,
57912+ .proc_handler = &proc_dointvec,
57913+ },
57914+ {
57915+ .procname = "lastack_retries",
57916+ .data = &grsec_lastack_retries,
57917+ .maxlen = sizeof(int),
57918+ .mode = 0600,
57919+ .proc_handler = &proc_dointvec,
57920+ },
57921+#endif
57922+#ifdef CONFIG_GRKERNSEC_EXECLOG
57923+ {
57924+ .procname = "exec_logging",
57925+ .data = &grsec_enable_execlog,
57926+ .maxlen = sizeof(int),
57927+ .mode = 0600,
57928+ .proc_handler = &proc_dointvec,
57929+ },
57930+#endif
57931+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57932+ {
57933+ .procname = "rwxmap_logging",
57934+ .data = &grsec_enable_log_rwxmaps,
57935+ .maxlen = sizeof(int),
57936+ .mode = 0600,
57937+ .proc_handler = &proc_dointvec,
57938+ },
57939+#endif
57940+#ifdef CONFIG_GRKERNSEC_SIGNAL
57941+ {
57942+ .procname = "signal_logging",
57943+ .data = &grsec_enable_signal,
57944+ .maxlen = sizeof(int),
57945+ .mode = 0600,
57946+ .proc_handler = &proc_dointvec,
57947+ },
57948+#endif
57949+#ifdef CONFIG_GRKERNSEC_FORKFAIL
57950+ {
57951+ .procname = "forkfail_logging",
57952+ .data = &grsec_enable_forkfail,
57953+ .maxlen = sizeof(int),
57954+ .mode = 0600,
57955+ .proc_handler = &proc_dointvec,
57956+ },
57957+#endif
57958+#ifdef CONFIG_GRKERNSEC_TIME
57959+ {
57960+ .procname = "timechange_logging",
57961+ .data = &grsec_enable_time,
57962+ .maxlen = sizeof(int),
57963+ .mode = 0600,
57964+ .proc_handler = &proc_dointvec,
57965+ },
57966+#endif
57967+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57968+ {
57969+ .procname = "chroot_deny_shmat",
57970+ .data = &grsec_enable_chroot_shmat,
57971+ .maxlen = sizeof(int),
57972+ .mode = 0600,
57973+ .proc_handler = &proc_dointvec,
57974+ },
57975+#endif
57976+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57977+ {
57978+ .procname = "chroot_deny_unix",
57979+ .data = &grsec_enable_chroot_unix,
57980+ .maxlen = sizeof(int),
57981+ .mode = 0600,
57982+ .proc_handler = &proc_dointvec,
57983+ },
57984+#endif
57985+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57986+ {
57987+ .procname = "chroot_deny_mount",
57988+ .data = &grsec_enable_chroot_mount,
57989+ .maxlen = sizeof(int),
57990+ .mode = 0600,
57991+ .proc_handler = &proc_dointvec,
57992+ },
57993+#endif
57994+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57995+ {
57996+ .procname = "chroot_deny_fchdir",
57997+ .data = &grsec_enable_chroot_fchdir,
57998+ .maxlen = sizeof(int),
57999+ .mode = 0600,
58000+ .proc_handler = &proc_dointvec,
58001+ },
58002+#endif
58003+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58004+ {
58005+ .procname = "chroot_deny_chroot",
58006+ .data = &grsec_enable_chroot_double,
58007+ .maxlen = sizeof(int),
58008+ .mode = 0600,
58009+ .proc_handler = &proc_dointvec,
58010+ },
58011+#endif
58012+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58013+ {
58014+ .procname = "chroot_deny_pivot",
58015+ .data = &grsec_enable_chroot_pivot,
58016+ .maxlen = sizeof(int),
58017+ .mode = 0600,
58018+ .proc_handler = &proc_dointvec,
58019+ },
58020+#endif
58021+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58022+ {
58023+ .procname = "chroot_enforce_chdir",
58024+ .data = &grsec_enable_chroot_chdir,
58025+ .maxlen = sizeof(int),
58026+ .mode = 0600,
58027+ .proc_handler = &proc_dointvec,
58028+ },
58029+#endif
58030+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58031+ {
58032+ .procname = "chroot_deny_chmod",
58033+ .data = &grsec_enable_chroot_chmod,
58034+ .maxlen = sizeof(int),
58035+ .mode = 0600,
58036+ .proc_handler = &proc_dointvec,
58037+ },
58038+#endif
58039+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58040+ {
58041+ .procname = "chroot_deny_mknod",
58042+ .data = &grsec_enable_chroot_mknod,
58043+ .maxlen = sizeof(int),
58044+ .mode = 0600,
58045+ .proc_handler = &proc_dointvec,
58046+ },
58047+#endif
58048+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58049+ {
58050+ .procname = "chroot_restrict_nice",
58051+ .data = &grsec_enable_chroot_nice,
58052+ .maxlen = sizeof(int),
58053+ .mode = 0600,
58054+ .proc_handler = &proc_dointvec,
58055+ },
58056+#endif
58057+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58058+ {
58059+ .procname = "chroot_execlog",
58060+ .data = &grsec_enable_chroot_execlog,
58061+ .maxlen = sizeof(int),
58062+ .mode = 0600,
58063+ .proc_handler = &proc_dointvec,
58064+ },
58065+#endif
58066+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58067+ {
58068+ .procname = "chroot_caps",
58069+ .data = &grsec_enable_chroot_caps,
58070+ .maxlen = sizeof(int),
58071+ .mode = 0600,
58072+ .proc_handler = &proc_dointvec,
58073+ },
58074+#endif
58075+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58076+ {
58077+ .procname = "chroot_deny_sysctl",
58078+ .data = &grsec_enable_chroot_sysctl,
58079+ .maxlen = sizeof(int),
58080+ .mode = 0600,
58081+ .proc_handler = &proc_dointvec,
58082+ },
58083+#endif
58084+#ifdef CONFIG_GRKERNSEC_TPE
58085+ {
58086+ .procname = "tpe",
58087+ .data = &grsec_enable_tpe,
58088+ .maxlen = sizeof(int),
58089+ .mode = 0600,
58090+ .proc_handler = &proc_dointvec,
58091+ },
58092+ {
58093+ .procname = "tpe_gid",
58094+ .data = &grsec_tpe_gid,
58095+ .maxlen = sizeof(int),
58096+ .mode = 0600,
58097+ .proc_handler = &proc_dointvec,
58098+ },
58099+#endif
58100+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58101+ {
58102+ .procname = "tpe_invert",
58103+ .data = &grsec_enable_tpe_invert,
58104+ .maxlen = sizeof(int),
58105+ .mode = 0600,
58106+ .proc_handler = &proc_dointvec,
58107+ },
58108+#endif
58109+#ifdef CONFIG_GRKERNSEC_TPE_ALL
58110+ {
58111+ .procname = "tpe_restrict_all",
58112+ .data = &grsec_enable_tpe_all,
58113+ .maxlen = sizeof(int),
58114+ .mode = 0600,
58115+ .proc_handler = &proc_dointvec,
58116+ },
58117+#endif
58118+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58119+ {
58120+ .procname = "socket_all",
58121+ .data = &grsec_enable_socket_all,
58122+ .maxlen = sizeof(int),
58123+ .mode = 0600,
58124+ .proc_handler = &proc_dointvec,
58125+ },
58126+ {
58127+ .procname = "socket_all_gid",
58128+ .data = &grsec_socket_all_gid,
58129+ .maxlen = sizeof(int),
58130+ .mode = 0600,
58131+ .proc_handler = &proc_dointvec,
58132+ },
58133+#endif
58134+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58135+ {
58136+ .procname = "socket_client",
58137+ .data = &grsec_enable_socket_client,
58138+ .maxlen = sizeof(int),
58139+ .mode = 0600,
58140+ .proc_handler = &proc_dointvec,
58141+ },
58142+ {
58143+ .procname = "socket_client_gid",
58144+ .data = &grsec_socket_client_gid,
58145+ .maxlen = sizeof(int),
58146+ .mode = 0600,
58147+ .proc_handler = &proc_dointvec,
58148+ },
58149+#endif
58150+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58151+ {
58152+ .procname = "socket_server",
58153+ .data = &grsec_enable_socket_server,
58154+ .maxlen = sizeof(int),
58155+ .mode = 0600,
58156+ .proc_handler = &proc_dointvec,
58157+ },
58158+ {
58159+ .procname = "socket_server_gid",
58160+ .data = &grsec_socket_server_gid,
58161+ .maxlen = sizeof(int),
58162+ .mode = 0600,
58163+ .proc_handler = &proc_dointvec,
58164+ },
58165+#endif
58166+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58167+ {
58168+ .procname = "audit_group",
58169+ .data = &grsec_enable_group,
58170+ .maxlen = sizeof(int),
58171+ .mode = 0600,
58172+ .proc_handler = &proc_dointvec,
58173+ },
58174+ {
58175+ .procname = "audit_gid",
58176+ .data = &grsec_audit_gid,
58177+ .maxlen = sizeof(int),
58178+ .mode = 0600,
58179+ .proc_handler = &proc_dointvec,
58180+ },
58181+#endif
58182+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58183+ {
58184+ .procname = "audit_chdir",
58185+ .data = &grsec_enable_chdir,
58186+ .maxlen = sizeof(int),
58187+ .mode = 0600,
58188+ .proc_handler = &proc_dointvec,
58189+ },
58190+#endif
58191+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58192+ {
58193+ .procname = "audit_mount",
58194+ .data = &grsec_enable_mount,
58195+ .maxlen = sizeof(int),
58196+ .mode = 0600,
58197+ .proc_handler = &proc_dointvec,
58198+ },
58199+#endif
58200+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58201+ {
58202+ .procname = "audit_textrel",
58203+ .data = &grsec_enable_audit_textrel,
58204+ .maxlen = sizeof(int),
58205+ .mode = 0600,
58206+ .proc_handler = &proc_dointvec,
58207+ },
58208+#endif
58209+#ifdef CONFIG_GRKERNSEC_DMESG
58210+ {
58211+ .procname = "dmesg",
58212+ .data = &grsec_enable_dmesg,
58213+ .maxlen = sizeof(int),
58214+ .mode = 0600,
58215+ .proc_handler = &proc_dointvec,
58216+ },
58217+#endif
58218+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58219+ {
58220+ .procname = "chroot_findtask",
58221+ .data = &grsec_enable_chroot_findtask,
58222+ .maxlen = sizeof(int),
58223+ .mode = 0600,
58224+ .proc_handler = &proc_dointvec,
58225+ },
58226+#endif
58227+#ifdef CONFIG_GRKERNSEC_RESLOG
58228+ {
58229+ .procname = "resource_logging",
58230+ .data = &grsec_resource_logging,
58231+ .maxlen = sizeof(int),
58232+ .mode = 0600,
58233+ .proc_handler = &proc_dointvec,
58234+ },
58235+#endif
58236+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58237+ {
58238+ .procname = "audit_ptrace",
58239+ .data = &grsec_enable_audit_ptrace,
58240+ .maxlen = sizeof(int),
58241+ .mode = 0600,
58242+ .proc_handler = &proc_dointvec,
58243+ },
58244+#endif
58245+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58246+ {
58247+ .procname = "harden_ptrace",
58248+ .data = &grsec_enable_harden_ptrace,
58249+ .maxlen = sizeof(int),
58250+ .mode = 0600,
58251+ .proc_handler = &proc_dointvec,
58252+ },
58253+#endif
58254+ {
58255+ .procname = "grsec_lock",
58256+ .data = &grsec_lock,
58257+ .maxlen = sizeof(int),
58258+ .mode = 0600,
58259+ .proc_handler = &proc_dointvec,
58260+ },
58261+#endif
58262+#ifdef CONFIG_GRKERNSEC_ROFS
58263+ {
58264+ .procname = "romount_protect",
58265+ .data = &grsec_enable_rofs,
58266+ .maxlen = sizeof(int),
58267+ .mode = 0600,
58268+ .proc_handler = &proc_dointvec_minmax,
58269+ .extra1 = &one,
58270+ .extra2 = &one,
58271+ },
58272+#endif
58273+ { }
58274+};
58275+#endif
58276diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
58277new file mode 100644
58278index 0000000..0dc13c3
58279--- /dev/null
58280+++ b/grsecurity/grsec_time.c
58281@@ -0,0 +1,16 @@
58282+#include <linux/kernel.h>
58283+#include <linux/sched.h>
58284+#include <linux/grinternal.h>
58285+#include <linux/module.h>
58286+
58287+void
58288+gr_log_timechange(void)
58289+{
58290+#ifdef CONFIG_GRKERNSEC_TIME
58291+ if (grsec_enable_time)
58292+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
58293+#endif
58294+ return;
58295+}
58296+
58297+EXPORT_SYMBOL(gr_log_timechange);
58298diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
58299new file mode 100644
58300index 0000000..07e0dc0
58301--- /dev/null
58302+++ b/grsecurity/grsec_tpe.c
58303@@ -0,0 +1,73 @@
58304+#include <linux/kernel.h>
58305+#include <linux/sched.h>
58306+#include <linux/file.h>
58307+#include <linux/fs.h>
58308+#include <linux/grinternal.h>
58309+
58310+extern int gr_acl_tpe_check(void);
58311+
58312+int
58313+gr_tpe_allow(const struct file *file)
58314+{
58315+#ifdef CONFIG_GRKERNSEC
58316+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
58317+ const struct cred *cred = current_cred();
58318+ char *msg = NULL;
58319+ char *msg2 = NULL;
58320+
58321+ // never restrict root
58322+ if (!cred->uid)
58323+ return 1;
58324+
58325+ if (grsec_enable_tpe) {
58326+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58327+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
58328+ msg = "not being in trusted group";
58329+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
58330+ msg = "being in untrusted group";
58331+#else
58332+ if (in_group_p(grsec_tpe_gid))
58333+ msg = "being in untrusted group";
58334+#endif
58335+ }
58336+ if (!msg && gr_acl_tpe_check())
58337+ msg = "being in untrusted role";
58338+
58339+ // not in any affected group/role
58340+ if (!msg)
58341+ goto next_check;
58342+
58343+ if (inode->i_uid)
58344+ msg2 = "file in non-root-owned directory";
58345+ else if (inode->i_mode & S_IWOTH)
58346+ msg2 = "file in world-writable directory";
58347+ else if (inode->i_mode & S_IWGRP)
58348+ msg2 = "file in group-writable directory";
58349+
58350+ if (msg && msg2) {
58351+ char fullmsg[70] = {0};
58352+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
58353+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
58354+ return 0;
58355+ }
58356+ msg = NULL;
58357+next_check:
58358+#ifdef CONFIG_GRKERNSEC_TPE_ALL
58359+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
58360+ return 1;
58361+
58362+ if (inode->i_uid && (inode->i_uid != cred->uid))
58363+ msg = "directory not owned by user";
58364+ else if (inode->i_mode & S_IWOTH)
58365+ msg = "file in world-writable directory";
58366+ else if (inode->i_mode & S_IWGRP)
58367+ msg = "file in group-writable directory";
58368+
58369+ if (msg) {
58370+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
58371+ return 0;
58372+ }
58373+#endif
58374+#endif
58375+ return 1;
58376+}
58377diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
58378new file mode 100644
58379index 0000000..9f7b1ac
58380--- /dev/null
58381+++ b/grsecurity/grsum.c
58382@@ -0,0 +1,61 @@
58383+#include <linux/err.h>
58384+#include <linux/kernel.h>
58385+#include <linux/sched.h>
58386+#include <linux/mm.h>
58387+#include <linux/scatterlist.h>
58388+#include <linux/crypto.h>
58389+#include <linux/gracl.h>
58390+
58391+
58392+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
58393+#error "crypto and sha256 must be built into the kernel"
58394+#endif
58395+
58396+int
58397+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
58398+{
58399+ char *p;
58400+ struct crypto_hash *tfm;
58401+ struct hash_desc desc;
58402+ struct scatterlist sg;
58403+ unsigned char temp_sum[GR_SHA_LEN];
58404+ volatile int retval = 0;
58405+ volatile int dummy = 0;
58406+ unsigned int i;
58407+
58408+ sg_init_table(&sg, 1);
58409+
58410+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
58411+ if (IS_ERR(tfm)) {
58412+ /* should never happen, since sha256 should be built in */
58413+ return 1;
58414+ }
58415+
58416+ desc.tfm = tfm;
58417+ desc.flags = 0;
58418+
58419+ crypto_hash_init(&desc);
58420+
58421+ p = salt;
58422+ sg_set_buf(&sg, p, GR_SALT_LEN);
58423+ crypto_hash_update(&desc, &sg, sg.length);
58424+
58425+ p = entry->pw;
58426+ sg_set_buf(&sg, p, strlen(p));
58427+
58428+ crypto_hash_update(&desc, &sg, sg.length);
58429+
58430+ crypto_hash_final(&desc, temp_sum);
58431+
58432+ memset(entry->pw, 0, GR_PW_LEN);
58433+
58434+ for (i = 0; i < GR_SHA_LEN; i++)
58435+ if (sum[i] != temp_sum[i])
58436+ retval = 1;
58437+ else
58438+ dummy = 1; // waste a cycle
58439+
58440+ crypto_free_hash(tfm);
58441+
58442+ return retval;
58443+}
58444diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
58445index 6cd5b64..f620d2d 100644
58446--- a/include/acpi/acpi_bus.h
58447+++ b/include/acpi/acpi_bus.h
58448@@ -107,7 +107,7 @@ struct acpi_device_ops {
58449 acpi_op_bind bind;
58450 acpi_op_unbind unbind;
58451 acpi_op_notify notify;
58452-};
58453+} __no_const;
58454
58455 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
58456
58457diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
58458index b7babf0..71e4e74 100644
58459--- a/include/asm-generic/atomic-long.h
58460+++ b/include/asm-generic/atomic-long.h
58461@@ -22,6 +22,12 @@
58462
58463 typedef atomic64_t atomic_long_t;
58464
58465+#ifdef CONFIG_PAX_REFCOUNT
58466+typedef atomic64_unchecked_t atomic_long_unchecked_t;
58467+#else
58468+typedef atomic64_t atomic_long_unchecked_t;
58469+#endif
58470+
58471 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
58472
58473 static inline long atomic_long_read(atomic_long_t *l)
58474@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
58475 return (long)atomic64_read(v);
58476 }
58477
58478+#ifdef CONFIG_PAX_REFCOUNT
58479+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
58480+{
58481+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58482+
58483+ return (long)atomic64_read_unchecked(v);
58484+}
58485+#endif
58486+
58487 static inline void atomic_long_set(atomic_long_t *l, long i)
58488 {
58489 atomic64_t *v = (atomic64_t *)l;
58490@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
58491 atomic64_set(v, i);
58492 }
58493
58494+#ifdef CONFIG_PAX_REFCOUNT
58495+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
58496+{
58497+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58498+
58499+ atomic64_set_unchecked(v, i);
58500+}
58501+#endif
58502+
58503 static inline void atomic_long_inc(atomic_long_t *l)
58504 {
58505 atomic64_t *v = (atomic64_t *)l;
58506@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
58507 atomic64_inc(v);
58508 }
58509
58510+#ifdef CONFIG_PAX_REFCOUNT
58511+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
58512+{
58513+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58514+
58515+ atomic64_inc_unchecked(v);
58516+}
58517+#endif
58518+
58519 static inline void atomic_long_dec(atomic_long_t *l)
58520 {
58521 atomic64_t *v = (atomic64_t *)l;
58522@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
58523 atomic64_dec(v);
58524 }
58525
58526+#ifdef CONFIG_PAX_REFCOUNT
58527+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
58528+{
58529+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58530+
58531+ atomic64_dec_unchecked(v);
58532+}
58533+#endif
58534+
58535 static inline void atomic_long_add(long i, atomic_long_t *l)
58536 {
58537 atomic64_t *v = (atomic64_t *)l;
58538@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
58539 atomic64_add(i, v);
58540 }
58541
58542+#ifdef CONFIG_PAX_REFCOUNT
58543+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
58544+{
58545+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58546+
58547+ atomic64_add_unchecked(i, v);
58548+}
58549+#endif
58550+
58551 static inline void atomic_long_sub(long i, atomic_long_t *l)
58552 {
58553 atomic64_t *v = (atomic64_t *)l;
58554@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
58555 atomic64_sub(i, v);
58556 }
58557
58558+#ifdef CONFIG_PAX_REFCOUNT
58559+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
58560+{
58561+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58562+
58563+ atomic64_sub_unchecked(i, v);
58564+}
58565+#endif
58566+
58567 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
58568 {
58569 atomic64_t *v = (atomic64_t *)l;
58570@@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
58571 return (long)atomic64_inc_return(v);
58572 }
58573
58574+#ifdef CONFIG_PAX_REFCOUNT
58575+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
58576+{
58577+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58578+
58579+ return (long)atomic64_inc_return_unchecked(v);
58580+}
58581+#endif
58582+
58583 static inline long atomic_long_dec_return(atomic_long_t *l)
58584 {
58585 atomic64_t *v = (atomic64_t *)l;
58586@@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
58587
58588 typedef atomic_t atomic_long_t;
58589
58590+#ifdef CONFIG_PAX_REFCOUNT
58591+typedef atomic_unchecked_t atomic_long_unchecked_t;
58592+#else
58593+typedef atomic_t atomic_long_unchecked_t;
58594+#endif
58595+
58596 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
58597 static inline long atomic_long_read(atomic_long_t *l)
58598 {
58599@@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
58600 return (long)atomic_read(v);
58601 }
58602
58603+#ifdef CONFIG_PAX_REFCOUNT
58604+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
58605+{
58606+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58607+
58608+ return (long)atomic_read_unchecked(v);
58609+}
58610+#endif
58611+
58612 static inline void atomic_long_set(atomic_long_t *l, long i)
58613 {
58614 atomic_t *v = (atomic_t *)l;
58615@@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
58616 atomic_set(v, i);
58617 }
58618
58619+#ifdef CONFIG_PAX_REFCOUNT
58620+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
58621+{
58622+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58623+
58624+ atomic_set_unchecked(v, i);
58625+}
58626+#endif
58627+
58628 static inline void atomic_long_inc(atomic_long_t *l)
58629 {
58630 atomic_t *v = (atomic_t *)l;
58631@@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
58632 atomic_inc(v);
58633 }
58634
58635+#ifdef CONFIG_PAX_REFCOUNT
58636+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
58637+{
58638+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58639+
58640+ atomic_inc_unchecked(v);
58641+}
58642+#endif
58643+
58644 static inline void atomic_long_dec(atomic_long_t *l)
58645 {
58646 atomic_t *v = (atomic_t *)l;
58647@@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
58648 atomic_dec(v);
58649 }
58650
58651+#ifdef CONFIG_PAX_REFCOUNT
58652+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
58653+{
58654+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58655+
58656+ atomic_dec_unchecked(v);
58657+}
58658+#endif
58659+
58660 static inline void atomic_long_add(long i, atomic_long_t *l)
58661 {
58662 atomic_t *v = (atomic_t *)l;
58663@@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
58664 atomic_add(i, v);
58665 }
58666
58667+#ifdef CONFIG_PAX_REFCOUNT
58668+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
58669+{
58670+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58671+
58672+ atomic_add_unchecked(i, v);
58673+}
58674+#endif
58675+
58676 static inline void atomic_long_sub(long i, atomic_long_t *l)
58677 {
58678 atomic_t *v = (atomic_t *)l;
58679@@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
58680 atomic_sub(i, v);
58681 }
58682
58683+#ifdef CONFIG_PAX_REFCOUNT
58684+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
58685+{
58686+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58687+
58688+ atomic_sub_unchecked(i, v);
58689+}
58690+#endif
58691+
58692 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
58693 {
58694 atomic_t *v = (atomic_t *)l;
58695@@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
58696 return (long)atomic_inc_return(v);
58697 }
58698
58699+#ifdef CONFIG_PAX_REFCOUNT
58700+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
58701+{
58702+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
58703+
58704+ return (long)atomic_inc_return_unchecked(v);
58705+}
58706+#endif
58707+
58708 static inline long atomic_long_dec_return(atomic_long_t *l)
58709 {
58710 atomic_t *v = (atomic_t *)l;
58711@@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
58712
58713 #endif /* BITS_PER_LONG == 64 */
58714
58715+#ifdef CONFIG_PAX_REFCOUNT
58716+static inline void pax_refcount_needs_these_functions(void)
58717+{
58718+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
58719+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
58720+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
58721+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
58722+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
58723+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
58724+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
58725+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
58726+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
58727+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
58728+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
58729+
58730+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
58731+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
58732+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
58733+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
58734+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
58735+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
58736+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
58737+}
58738+#else
58739+#define atomic_read_unchecked(v) atomic_read(v)
58740+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
58741+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
58742+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
58743+#define atomic_inc_unchecked(v) atomic_inc(v)
58744+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
58745+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
58746+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
58747+#define atomic_dec_unchecked(v) atomic_dec(v)
58748+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
58749+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
58750+
58751+#define atomic_long_read_unchecked(v) atomic_long_read(v)
58752+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
58753+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
58754+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
58755+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
58756+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
58757+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
58758+#endif
58759+
58760 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
58761diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
58762index b18ce4f..2ee2843 100644
58763--- a/include/asm-generic/atomic64.h
58764+++ b/include/asm-generic/atomic64.h
58765@@ -16,6 +16,8 @@ typedef struct {
58766 long long counter;
58767 } atomic64_t;
58768
58769+typedef atomic64_t atomic64_unchecked_t;
58770+
58771 #define ATOMIC64_INIT(i) { (i) }
58772
58773 extern long long atomic64_read(const atomic64_t *v);
58774@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
58775 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
58776 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
58777
58778+#define atomic64_read_unchecked(v) atomic64_read(v)
58779+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
58780+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
58781+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
58782+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
58783+#define atomic64_inc_unchecked(v) atomic64_inc(v)
58784+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
58785+#define atomic64_dec_unchecked(v) atomic64_dec(v)
58786+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
58787+
58788 #endif /* _ASM_GENERIC_ATOMIC64_H */
58789diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
58790index 1bfcfe5..e04c5c9 100644
58791--- a/include/asm-generic/cache.h
58792+++ b/include/asm-generic/cache.h
58793@@ -6,7 +6,7 @@
58794 * cache lines need to provide their own cache.h.
58795 */
58796
58797-#define L1_CACHE_SHIFT 5
58798-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
58799+#define L1_CACHE_SHIFT 5UL
58800+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
58801
58802 #endif /* __ASM_GENERIC_CACHE_H */
58803diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
58804index 0d68a1e..b74a761 100644
58805--- a/include/asm-generic/emergency-restart.h
58806+++ b/include/asm-generic/emergency-restart.h
58807@@ -1,7 +1,7 @@
58808 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
58809 #define _ASM_GENERIC_EMERGENCY_RESTART_H
58810
58811-static inline void machine_emergency_restart(void)
58812+static inline __noreturn void machine_emergency_restart(void)
58813 {
58814 machine_restart(NULL);
58815 }
58816diff --git a/include/asm-generic/int-l64.h b/include/asm-generic/int-l64.h
58817index 1ca3efc..e3dc852 100644
58818--- a/include/asm-generic/int-l64.h
58819+++ b/include/asm-generic/int-l64.h
58820@@ -46,6 +46,8 @@ typedef unsigned int u32;
58821 typedef signed long s64;
58822 typedef unsigned long u64;
58823
58824+typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
58825+
58826 #define S8_C(x) x
58827 #define U8_C(x) x ## U
58828 #define S16_C(x) x
58829diff --git a/include/asm-generic/int-ll64.h b/include/asm-generic/int-ll64.h
58830index f394147..b6152b9 100644
58831--- a/include/asm-generic/int-ll64.h
58832+++ b/include/asm-generic/int-ll64.h
58833@@ -51,6 +51,8 @@ typedef unsigned int u32;
58834 typedef signed long long s64;
58835 typedef unsigned long long u64;
58836
58837+typedef unsigned long long intoverflow_t;
58838+
58839 #define S8_C(x) x
58840 #define U8_C(x) x ## U
58841 #define S16_C(x) x
58842diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
58843index 0232ccb..13d9165 100644
58844--- a/include/asm-generic/kmap_types.h
58845+++ b/include/asm-generic/kmap_types.h
58846@@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
58847 KMAP_D(17) KM_NMI,
58848 KMAP_D(18) KM_NMI_PTE,
58849 KMAP_D(19) KM_KDB,
58850+KMAP_D(20) KM_CLEARPAGE,
58851 /*
58852 * Remember to update debug_kmap_atomic() when adding new kmap types!
58853 */
58854-KMAP_D(20) KM_TYPE_NR
58855+KMAP_D(21) KM_TYPE_NR
58856 };
58857
58858 #undef KMAP_D
58859diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
58860index 9ceb03b..2efbcbd 100644
58861--- a/include/asm-generic/local.h
58862+++ b/include/asm-generic/local.h
58863@@ -39,6 +39,7 @@ typedef struct
58864 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
58865 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
58866 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
58867+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
58868
58869 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
58870 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
58871diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
58872index 725612b..9cc513a 100644
58873--- a/include/asm-generic/pgtable-nopmd.h
58874+++ b/include/asm-generic/pgtable-nopmd.h
58875@@ -1,14 +1,19 @@
58876 #ifndef _PGTABLE_NOPMD_H
58877 #define _PGTABLE_NOPMD_H
58878
58879-#ifndef __ASSEMBLY__
58880-
58881 #include <asm-generic/pgtable-nopud.h>
58882
58883-struct mm_struct;
58884-
58885 #define __PAGETABLE_PMD_FOLDED
58886
58887+#define PMD_SHIFT PUD_SHIFT
58888+#define PTRS_PER_PMD 1
58889+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
58890+#define PMD_MASK (~(PMD_SIZE-1))
58891+
58892+#ifndef __ASSEMBLY__
58893+
58894+struct mm_struct;
58895+
58896 /*
58897 * Having the pmd type consist of a pud gets the size right, and allows
58898 * us to conceptually access the pud entry that this pmd is folded into
58899@@ -16,11 +21,6 @@ struct mm_struct;
58900 */
58901 typedef struct { pud_t pud; } pmd_t;
58902
58903-#define PMD_SHIFT PUD_SHIFT
58904-#define PTRS_PER_PMD 1
58905-#define PMD_SIZE (1UL << PMD_SHIFT)
58906-#define PMD_MASK (~(PMD_SIZE-1))
58907-
58908 /*
58909 * The "pud_xxx()" functions here are trivial for a folded two-level
58910 * setup: the pmd is never bad, and a pmd always exists (as it's folded
58911diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
58912index 810431d..ccc3638 100644
58913--- a/include/asm-generic/pgtable-nopud.h
58914+++ b/include/asm-generic/pgtable-nopud.h
58915@@ -1,10 +1,15 @@
58916 #ifndef _PGTABLE_NOPUD_H
58917 #define _PGTABLE_NOPUD_H
58918
58919-#ifndef __ASSEMBLY__
58920-
58921 #define __PAGETABLE_PUD_FOLDED
58922
58923+#define PUD_SHIFT PGDIR_SHIFT
58924+#define PTRS_PER_PUD 1
58925+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
58926+#define PUD_MASK (~(PUD_SIZE-1))
58927+
58928+#ifndef __ASSEMBLY__
58929+
58930 /*
58931 * Having the pud type consist of a pgd gets the size right, and allows
58932 * us to conceptually access the pgd entry that this pud is folded into
58933@@ -12,11 +17,6 @@
58934 */
58935 typedef struct { pgd_t pgd; } pud_t;
58936
58937-#define PUD_SHIFT PGDIR_SHIFT
58938-#define PTRS_PER_PUD 1
58939-#define PUD_SIZE (1UL << PUD_SHIFT)
58940-#define PUD_MASK (~(PUD_SIZE-1))
58941-
58942 /*
58943 * The "pgd_xxx()" functions here are trivial for a folded two-level
58944 * setup: the pud is never bad, and a pud always exists (as it's folded
58945diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
58946index a03c098..9624b83 100644
58947--- a/include/asm-generic/pgtable.h
58948+++ b/include/asm-generic/pgtable.h
58949@@ -504,6 +504,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
58950
58951 #endif /* CONFIG_MMU */
58952
58953+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
58954+static inline unsigned long pax_open_kernel(void) { return 0; }
58955+#endif
58956+
58957+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
58958+static inline unsigned long pax_close_kernel(void) { return 0; }
58959+#endif
58960+
58961 #endif /* !__ASSEMBLY__ */
58962
58963 #endif /* _ASM_GENERIC_PGTABLE_H */
58964diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
58965index b5e2e4c..6a5373e 100644
58966--- a/include/asm-generic/vmlinux.lds.h
58967+++ b/include/asm-generic/vmlinux.lds.h
58968@@ -217,6 +217,7 @@
58969 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
58970 VMLINUX_SYMBOL(__start_rodata) = .; \
58971 *(.rodata) *(.rodata.*) \
58972+ *(.data..read_only) \
58973 *(__vermagic) /* Kernel version magic */ \
58974 . = ALIGN(8); \
58975 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
58976@@ -722,17 +723,18 @@
58977 * section in the linker script will go there too. @phdr should have
58978 * a leading colon.
58979 *
58980- * Note that this macros defines __per_cpu_load as an absolute symbol.
58981+ * Note that this macros defines per_cpu_load as an absolute symbol.
58982 * If there is no need to put the percpu section at a predetermined
58983 * address, use PERCPU_SECTION.
58984 */
58985 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
58986- VMLINUX_SYMBOL(__per_cpu_load) = .; \
58987- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
58988+ per_cpu_load = .; \
58989+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
58990 - LOAD_OFFSET) { \
58991+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
58992 PERCPU_INPUT(cacheline) \
58993 } phdr \
58994- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
58995+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
58996
58997 /**
58998 * PERCPU_SECTION - define output section for percpu area, simple version
58999diff --git a/include/drm/drmP.h b/include/drm/drmP.h
59000index 92f0981..d44a37c 100644
59001--- a/include/drm/drmP.h
59002+++ b/include/drm/drmP.h
59003@@ -72,6 +72,7 @@
59004 #include <linux/workqueue.h>
59005 #include <linux/poll.h>
59006 #include <asm/pgalloc.h>
59007+#include <asm/local.h>
59008 #include "drm.h"
59009
59010 #include <linux/idr.h>
59011@@ -1038,7 +1039,7 @@ struct drm_device {
59012
59013 /** \name Usage Counters */
59014 /*@{ */
59015- int open_count; /**< Outstanding files open */
59016+ local_t open_count; /**< Outstanding files open */
59017 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
59018 atomic_t vma_count; /**< Outstanding vma areas open */
59019 int buf_use; /**< Buffers in use -- cannot alloc */
59020@@ -1049,7 +1050,7 @@ struct drm_device {
59021 /*@{ */
59022 unsigned long counters;
59023 enum drm_stat_type types[15];
59024- atomic_t counts[15];
59025+ atomic_unchecked_t counts[15];
59026 /*@} */
59027
59028 struct list_head filelist;
59029diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
59030index 37515d1..34fa8b0 100644
59031--- a/include/drm/drm_crtc_helper.h
59032+++ b/include/drm/drm_crtc_helper.h
59033@@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
59034
59035 /* disable crtc when not in use - more explicit than dpms off */
59036 void (*disable)(struct drm_crtc *crtc);
59037-};
59038+} __no_const;
59039
59040 struct drm_encoder_helper_funcs {
59041 void (*dpms)(struct drm_encoder *encoder, int mode);
59042@@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
59043 struct drm_connector *connector);
59044 /* disable encoder when not in use - more explicit than dpms off */
59045 void (*disable)(struct drm_encoder *encoder);
59046-};
59047+} __no_const;
59048
59049 struct drm_connector_helper_funcs {
59050 int (*get_modes)(struct drm_connector *connector);
59051diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
59052index 26c1f78..6722682 100644
59053--- a/include/drm/ttm/ttm_memory.h
59054+++ b/include/drm/ttm/ttm_memory.h
59055@@ -47,7 +47,7 @@
59056
59057 struct ttm_mem_shrink {
59058 int (*do_shrink) (struct ttm_mem_shrink *);
59059-};
59060+} __no_const;
59061
59062 /**
59063 * struct ttm_mem_global - Global memory accounting structure.
59064diff --git a/include/linux/a.out.h b/include/linux/a.out.h
59065index e86dfca..40cc55f 100644
59066--- a/include/linux/a.out.h
59067+++ b/include/linux/a.out.h
59068@@ -39,6 +39,14 @@ enum machine_type {
59069 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
59070 };
59071
59072+/* Constants for the N_FLAGS field */
59073+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
59074+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
59075+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
59076+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
59077+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
59078+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
59079+
59080 #if !defined (N_MAGIC)
59081 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
59082 #endif
59083diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
59084index f4ff882..84b53a6 100644
59085--- a/include/linux/atmdev.h
59086+++ b/include/linux/atmdev.h
59087@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
59088 #endif
59089
59090 struct k_atm_aal_stats {
59091-#define __HANDLE_ITEM(i) atomic_t i
59092+#define __HANDLE_ITEM(i) atomic_unchecked_t i
59093 __AAL_STAT_ITEMS
59094 #undef __HANDLE_ITEM
59095 };
59096diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
59097index 0092102..8a801b4 100644
59098--- a/include/linux/binfmts.h
59099+++ b/include/linux/binfmts.h
59100@@ -89,6 +89,7 @@ struct linux_binfmt {
59101 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
59102 int (*load_shlib)(struct file *);
59103 int (*core_dump)(struct coredump_params *cprm);
59104+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
59105 unsigned long min_coredump; /* minimal dump size */
59106 };
59107
59108diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
59109index 606cf33..b72c577 100644
59110--- a/include/linux/blkdev.h
59111+++ b/include/linux/blkdev.h
59112@@ -1379,7 +1379,7 @@ struct block_device_operations {
59113 /* this callback is with swap_lock and sometimes page table lock held */
59114 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
59115 struct module *owner;
59116-};
59117+} __do_const;
59118
59119 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
59120 unsigned long);
59121diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
59122index 4d1a074..88f929a 100644
59123--- a/include/linux/blktrace_api.h
59124+++ b/include/linux/blktrace_api.h
59125@@ -162,7 +162,7 @@ struct blk_trace {
59126 struct dentry *dir;
59127 struct dentry *dropped_file;
59128 struct dentry *msg_file;
59129- atomic_t dropped;
59130+ atomic_unchecked_t dropped;
59131 };
59132
59133 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
59134diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
59135index 83195fb..0b0f77d 100644
59136--- a/include/linux/byteorder/little_endian.h
59137+++ b/include/linux/byteorder/little_endian.h
59138@@ -42,51 +42,51 @@
59139
59140 static inline __le64 __cpu_to_le64p(const __u64 *p)
59141 {
59142- return (__force __le64)*p;
59143+ return (__force const __le64)*p;
59144 }
59145 static inline __u64 __le64_to_cpup(const __le64 *p)
59146 {
59147- return (__force __u64)*p;
59148+ return (__force const __u64)*p;
59149 }
59150 static inline __le32 __cpu_to_le32p(const __u32 *p)
59151 {
59152- return (__force __le32)*p;
59153+ return (__force const __le32)*p;
59154 }
59155 static inline __u32 __le32_to_cpup(const __le32 *p)
59156 {
59157- return (__force __u32)*p;
59158+ return (__force const __u32)*p;
59159 }
59160 static inline __le16 __cpu_to_le16p(const __u16 *p)
59161 {
59162- return (__force __le16)*p;
59163+ return (__force const __le16)*p;
59164 }
59165 static inline __u16 __le16_to_cpup(const __le16 *p)
59166 {
59167- return (__force __u16)*p;
59168+ return (__force const __u16)*p;
59169 }
59170 static inline __be64 __cpu_to_be64p(const __u64 *p)
59171 {
59172- return (__force __be64)__swab64p(p);
59173+ return (__force const __be64)__swab64p(p);
59174 }
59175 static inline __u64 __be64_to_cpup(const __be64 *p)
59176 {
59177- return __swab64p((__u64 *)p);
59178+ return __swab64p((const __u64 *)p);
59179 }
59180 static inline __be32 __cpu_to_be32p(const __u32 *p)
59181 {
59182- return (__force __be32)__swab32p(p);
59183+ return (__force const __be32)__swab32p(p);
59184 }
59185 static inline __u32 __be32_to_cpup(const __be32 *p)
59186 {
59187- return __swab32p((__u32 *)p);
59188+ return __swab32p((const __u32 *)p);
59189 }
59190 static inline __be16 __cpu_to_be16p(const __u16 *p)
59191 {
59192- return (__force __be16)__swab16p(p);
59193+ return (__force const __be16)__swab16p(p);
59194 }
59195 static inline __u16 __be16_to_cpup(const __be16 *p)
59196 {
59197- return __swab16p((__u16 *)p);
59198+ return __swab16p((const __u16 *)p);
59199 }
59200 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
59201 #define __le64_to_cpus(x) do { (void)(x); } while (0)
59202diff --git a/include/linux/cache.h b/include/linux/cache.h
59203index 4c57065..4307975 100644
59204--- a/include/linux/cache.h
59205+++ b/include/linux/cache.h
59206@@ -16,6 +16,10 @@
59207 #define __read_mostly
59208 #endif
59209
59210+#ifndef __read_only
59211+#define __read_only __read_mostly
59212+#endif
59213+
59214 #ifndef ____cacheline_aligned
59215 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
59216 #endif
59217diff --git a/include/linux/capability.h b/include/linux/capability.h
59218index 12d52de..b5f7fa7 100644
59219--- a/include/linux/capability.h
59220+++ b/include/linux/capability.h
59221@@ -548,6 +548,8 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
59222 extern bool capable(int cap);
59223 extern bool ns_capable(struct user_namespace *ns, int cap);
59224 extern bool nsown_capable(int cap);
59225+extern bool capable_nolog(int cap);
59226+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
59227
59228 /* audit system wants to get cap info from files as well */
59229 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
59230diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
59231index 04ffb2e..6799180 100644
59232--- a/include/linux/cleancache.h
59233+++ b/include/linux/cleancache.h
59234@@ -31,7 +31,7 @@ struct cleancache_ops {
59235 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
59236 void (*flush_inode)(int, struct cleancache_filekey);
59237 void (*flush_fs)(int);
59238-};
59239+} __no_const;
59240
59241 extern struct cleancache_ops
59242 cleancache_register_ops(struct cleancache_ops *ops);
59243diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
59244index 2f40791..89a56fd 100644
59245--- a/include/linux/compiler-gcc4.h
59246+++ b/include/linux/compiler-gcc4.h
59247@@ -32,6 +32,12 @@
59248 #define __linktime_error(message) __attribute__((__error__(message)))
59249
59250 #if __GNUC_MINOR__ >= 5
59251+
59252+#ifdef CONSTIFY_PLUGIN
59253+#define __no_const __attribute__((no_const))
59254+#define __do_const __attribute__((do_const))
59255+#endif
59256+
59257 /*
59258 * Mark a position in code as unreachable. This can be used to
59259 * suppress control flow warnings after asm blocks that transfer
59260@@ -47,6 +53,11 @@
59261 #define __noclone __attribute__((__noclone__))
59262
59263 #endif
59264+
59265+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
59266+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
59267+#define __bos0(ptr) __bos((ptr), 0)
59268+#define __bos1(ptr) __bos((ptr), 1)
59269 #endif
59270
59271 #if __GNUC_MINOR__ > 0
59272diff --git a/include/linux/compiler.h b/include/linux/compiler.h
59273index 4a24354..9570c1b 100644
59274--- a/include/linux/compiler.h
59275+++ b/include/linux/compiler.h
59276@@ -5,31 +5,62 @@
59277
59278 #ifdef __CHECKER__
59279 # define __user __attribute__((noderef, address_space(1)))
59280+# define __force_user __force __user
59281 # define __kernel __attribute__((address_space(0)))
59282+# define __force_kernel __force __kernel
59283 # define __safe __attribute__((safe))
59284 # define __force __attribute__((force))
59285 # define __nocast __attribute__((nocast))
59286 # define __iomem __attribute__((noderef, address_space(2)))
59287+# define __force_iomem __force __iomem
59288 # define __acquires(x) __attribute__((context(x,0,1)))
59289 # define __releases(x) __attribute__((context(x,1,0)))
59290 # define __acquire(x) __context__(x,1)
59291 # define __release(x) __context__(x,-1)
59292 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
59293 # define __percpu __attribute__((noderef, address_space(3)))
59294+# define __force_percpu __force __percpu
59295 #ifdef CONFIG_SPARSE_RCU_POINTER
59296 # define __rcu __attribute__((noderef, address_space(4)))
59297+# define __force_rcu __force __rcu
59298 #else
59299 # define __rcu
59300+# define __force_rcu
59301 #endif
59302 extern void __chk_user_ptr(const volatile void __user *);
59303 extern void __chk_io_ptr(const volatile void __iomem *);
59304+#elif defined(CHECKER_PLUGIN)
59305+//# define __user
59306+//# define __force_user
59307+//# define __kernel
59308+//# define __force_kernel
59309+# define __safe
59310+# define __force
59311+# define __nocast
59312+# define __iomem
59313+# define __force_iomem
59314+# define __chk_user_ptr(x) (void)0
59315+# define __chk_io_ptr(x) (void)0
59316+# define __builtin_warning(x, y...) (1)
59317+# define __acquires(x)
59318+# define __releases(x)
59319+# define __acquire(x) (void)0
59320+# define __release(x) (void)0
59321+# define __cond_lock(x,c) (c)
59322+# define __percpu
59323+# define __force_percpu
59324+# define __rcu
59325+# define __force_rcu
59326 #else
59327 # define __user
59328+# define __force_user
59329 # define __kernel
59330+# define __force_kernel
59331 # define __safe
59332 # define __force
59333 # define __nocast
59334 # define __iomem
59335+# define __force_iomem
59336 # define __chk_user_ptr(x) (void)0
59337 # define __chk_io_ptr(x) (void)0
59338 # define __builtin_warning(x, y...) (1)
59339@@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
59340 # define __release(x) (void)0
59341 # define __cond_lock(x,c) (c)
59342 # define __percpu
59343+# define __force_percpu
59344 # define __rcu
59345+# define __force_rcu
59346 #endif
59347
59348 #ifdef __KERNEL__
59349@@ -264,6 +297,14 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59350 # define __attribute_const__ /* unimplemented */
59351 #endif
59352
59353+#ifndef __no_const
59354+# define __no_const
59355+#endif
59356+
59357+#ifndef __do_const
59358+# define __do_const
59359+#endif
59360+
59361 /*
59362 * Tell gcc if a function is cold. The compiler will assume any path
59363 * directly leading to the call is unlikely.
59364@@ -273,6 +314,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59365 #define __cold
59366 #endif
59367
59368+#ifndef __alloc_size
59369+#define __alloc_size(...)
59370+#endif
59371+
59372+#ifndef __bos
59373+#define __bos(ptr, arg)
59374+#endif
59375+
59376+#ifndef __bos0
59377+#define __bos0(ptr)
59378+#endif
59379+
59380+#ifndef __bos1
59381+#define __bos1(ptr)
59382+#endif
59383+
59384 /* Simple shorthand for a section definition */
59385 #ifndef __section
59386 # define __section(S) __attribute__ ((__section__(#S)))
59387@@ -308,6 +365,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59388 * use is to mediate communication between process-level code and irq/NMI
59389 * handlers, all running on the same CPU.
59390 */
59391-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
59392+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
59393+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
59394
59395 #endif /* __LINUX_COMPILER_H */
59396diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
59397index e9eaec5..bfeb9bb 100644
59398--- a/include/linux/cpuset.h
59399+++ b/include/linux/cpuset.h
59400@@ -118,7 +118,7 @@ static inline void put_mems_allowed(void)
59401 * nodemask.
59402 */
59403 smp_mb();
59404- --ACCESS_ONCE(current->mems_allowed_change_disable);
59405+ --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
59406 }
59407
59408 static inline void set_mems_allowed(nodemask_t nodemask)
59409diff --git a/include/linux/cred.h b/include/linux/cred.h
59410index adadf71..6af5560 100644
59411--- a/include/linux/cred.h
59412+++ b/include/linux/cred.h
59413@@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
59414 static inline void validate_process_creds(void)
59415 {
59416 }
59417+static inline void validate_task_creds(struct task_struct *task)
59418+{
59419+}
59420 #endif
59421
59422 /**
59423diff --git a/include/linux/crypto.h b/include/linux/crypto.h
59424index 8a94217..15d49e3 100644
59425--- a/include/linux/crypto.h
59426+++ b/include/linux/crypto.h
59427@@ -365,7 +365,7 @@ struct cipher_tfm {
59428 const u8 *key, unsigned int keylen);
59429 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
59430 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
59431-};
59432+} __no_const;
59433
59434 struct hash_tfm {
59435 int (*init)(struct hash_desc *desc);
59436@@ -386,13 +386,13 @@ struct compress_tfm {
59437 int (*cot_decompress)(struct crypto_tfm *tfm,
59438 const u8 *src, unsigned int slen,
59439 u8 *dst, unsigned int *dlen);
59440-};
59441+} __no_const;
59442
59443 struct rng_tfm {
59444 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
59445 unsigned int dlen);
59446 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
59447-};
59448+} __no_const;
59449
59450 #define crt_ablkcipher crt_u.ablkcipher
59451 #define crt_aead crt_u.aead
59452diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
59453index 7925bf0..d5143d2 100644
59454--- a/include/linux/decompress/mm.h
59455+++ b/include/linux/decompress/mm.h
59456@@ -77,7 +77,7 @@ static void free(void *where)
59457 * warnings when not needed (indeed large_malloc / large_free are not
59458 * needed by inflate */
59459
59460-#define malloc(a) kmalloc(a, GFP_KERNEL)
59461+#define malloc(a) kmalloc((a), GFP_KERNEL)
59462 #define free(a) kfree(a)
59463
59464 #define large_malloc(a) vmalloc(a)
59465diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
59466index e13117c..e9fc938 100644
59467--- a/include/linux/dma-mapping.h
59468+++ b/include/linux/dma-mapping.h
59469@@ -46,7 +46,7 @@ struct dma_map_ops {
59470 u64 (*get_required_mask)(struct device *dev);
59471 #endif
59472 int is_phys;
59473-};
59474+} __do_const;
59475
59476 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
59477
59478diff --git a/include/linux/efi.h b/include/linux/efi.h
59479index 37c3007..92ab679 100644
59480--- a/include/linux/efi.h
59481+++ b/include/linux/efi.h
59482@@ -580,7 +580,7 @@ struct efivar_operations {
59483 efi_get_variable_t *get_variable;
59484 efi_get_next_variable_t *get_next_variable;
59485 efi_set_variable_t *set_variable;
59486-};
59487+} __no_const;
59488
59489 struct efivars {
59490 /*
59491diff --git a/include/linux/elf.h b/include/linux/elf.h
59492index 999b4f5..57753b4 100644
59493--- a/include/linux/elf.h
59494+++ b/include/linux/elf.h
59495@@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
59496 #define PT_GNU_EH_FRAME 0x6474e550
59497
59498 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
59499+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
59500+
59501+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
59502+
59503+/* Constants for the e_flags field */
59504+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
59505+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
59506+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
59507+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
59508+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
59509+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
59510
59511 /*
59512 * Extended Numbering
59513@@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
59514 #define DT_DEBUG 21
59515 #define DT_TEXTREL 22
59516 #define DT_JMPREL 23
59517+#define DT_FLAGS 30
59518+ #define DF_TEXTREL 0x00000004
59519 #define DT_ENCODING 32
59520 #define OLD_DT_LOOS 0x60000000
59521 #define DT_LOOS 0x6000000d
59522@@ -243,6 +256,19 @@ typedef struct elf64_hdr {
59523 #define PF_W 0x2
59524 #define PF_X 0x1
59525
59526+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
59527+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
59528+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
59529+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
59530+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
59531+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
59532+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
59533+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
59534+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
59535+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
59536+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
59537+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
59538+
59539 typedef struct elf32_phdr{
59540 Elf32_Word p_type;
59541 Elf32_Off p_offset;
59542@@ -335,6 +361,8 @@ typedef struct elf64_shdr {
59543 #define EI_OSABI 7
59544 #define EI_PAD 8
59545
59546+#define EI_PAX 14
59547+
59548 #define ELFMAG0 0x7f /* EI_MAG */
59549 #define ELFMAG1 'E'
59550 #define ELFMAG2 'L'
59551@@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
59552 #define elf_note elf32_note
59553 #define elf_addr_t Elf32_Off
59554 #define Elf_Half Elf32_Half
59555+#define elf_dyn Elf32_Dyn
59556
59557 #else
59558
59559@@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
59560 #define elf_note elf64_note
59561 #define elf_addr_t Elf64_Off
59562 #define Elf_Half Elf64_Half
59563+#define elf_dyn Elf64_Dyn
59564
59565 #endif
59566
59567diff --git a/include/linux/filter.h b/include/linux/filter.h
59568index 8eeb205..d59bfa2 100644
59569--- a/include/linux/filter.h
59570+++ b/include/linux/filter.h
59571@@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
59572
59573 struct sk_buff;
59574 struct sock;
59575+struct bpf_jit_work;
59576
59577 struct sk_filter
59578 {
59579@@ -141,6 +142,9 @@ struct sk_filter
59580 unsigned int len; /* Number of filter blocks */
59581 unsigned int (*bpf_func)(const struct sk_buff *skb,
59582 const struct sock_filter *filter);
59583+#ifdef CONFIG_BPF_JIT
59584+ struct bpf_jit_work *work;
59585+#endif
59586 struct rcu_head rcu;
59587 struct sock_filter insns[0];
59588 };
59589diff --git a/include/linux/firewire.h b/include/linux/firewire.h
59590index 84ccf8e..2e9b14c 100644
59591--- a/include/linux/firewire.h
59592+++ b/include/linux/firewire.h
59593@@ -428,7 +428,7 @@ struct fw_iso_context {
59594 union {
59595 fw_iso_callback_t sc;
59596 fw_iso_mc_callback_t mc;
59597- } callback;
59598+ } __no_const callback;
59599 void *callback_data;
59600 };
59601
59602diff --git a/include/linux/fs.h b/include/linux/fs.h
59603index 69cd5bb..58425c2 100644
59604--- a/include/linux/fs.h
59605+++ b/include/linux/fs.h
59606@@ -1623,7 +1623,8 @@ struct file_operations {
59607 int (*setlease)(struct file *, long, struct file_lock **);
59608 long (*fallocate)(struct file *file, int mode, loff_t offset,
59609 loff_t len);
59610-};
59611+} __do_const;
59612+typedef struct file_operations __no_const file_operations_no_const;
59613
59614 struct inode_operations {
59615 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
59616diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
59617index 003dc0f..3c4ea97 100644
59618--- a/include/linux/fs_struct.h
59619+++ b/include/linux/fs_struct.h
59620@@ -6,7 +6,7 @@
59621 #include <linux/seqlock.h>
59622
59623 struct fs_struct {
59624- int users;
59625+ atomic_t users;
59626 spinlock_t lock;
59627 seqcount_t seq;
59628 int umask;
59629diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
59630index ce31408..b1ad003 100644
59631--- a/include/linux/fscache-cache.h
59632+++ b/include/linux/fscache-cache.h
59633@@ -102,7 +102,7 @@ struct fscache_operation {
59634 fscache_operation_release_t release;
59635 };
59636
59637-extern atomic_t fscache_op_debug_id;
59638+extern atomic_unchecked_t fscache_op_debug_id;
59639 extern void fscache_op_work_func(struct work_struct *work);
59640
59641 extern void fscache_enqueue_operation(struct fscache_operation *);
59642@@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
59643 {
59644 INIT_WORK(&op->work, fscache_op_work_func);
59645 atomic_set(&op->usage, 1);
59646- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
59647+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59648 op->processor = processor;
59649 op->release = release;
59650 INIT_LIST_HEAD(&op->pend_link);
59651diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
59652index 2a53f10..0187fdf 100644
59653--- a/include/linux/fsnotify.h
59654+++ b/include/linux/fsnotify.h
59655@@ -314,7 +314,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
59656 */
59657 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
59658 {
59659- return kstrdup(name, GFP_KERNEL);
59660+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
59661 }
59662
59663 /*
59664diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
59665index 91d0e0a3..035666b 100644
59666--- a/include/linux/fsnotify_backend.h
59667+++ b/include/linux/fsnotify_backend.h
59668@@ -105,6 +105,7 @@ struct fsnotify_ops {
59669 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
59670 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
59671 };
59672+typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
59673
59674 /*
59675 * A group is a "thing" that wants to receive notification about filesystem
59676diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
59677index c3da42d..c70e0df 100644
59678--- a/include/linux/ftrace_event.h
59679+++ b/include/linux/ftrace_event.h
59680@@ -97,7 +97,7 @@ struct trace_event_functions {
59681 trace_print_func raw;
59682 trace_print_func hex;
59683 trace_print_func binary;
59684-};
59685+} __no_const;
59686
59687 struct trace_event {
59688 struct hlist_node node;
59689@@ -254,7 +254,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
59690 extern int trace_add_event_call(struct ftrace_event_call *call);
59691 extern void trace_remove_event_call(struct ftrace_event_call *call);
59692
59693-#define is_signed_type(type) (((type)(-1)) < 0)
59694+#define is_signed_type(type) (((type)(-1)) < (type)1)
59695
59696 int trace_set_clr_event(const char *system, const char *event, int set);
59697
59698diff --git a/include/linux/genhd.h b/include/linux/genhd.h
59699index e61d319..0da8505 100644
59700--- a/include/linux/genhd.h
59701+++ b/include/linux/genhd.h
59702@@ -185,7 +185,7 @@ struct gendisk {
59703 struct kobject *slave_dir;
59704
59705 struct timer_rand_state *random;
59706- atomic_t sync_io; /* RAID */
59707+ atomic_unchecked_t sync_io; /* RAID */
59708 struct disk_events *ev;
59709 #ifdef CONFIG_BLK_DEV_INTEGRITY
59710 struct blk_integrity *integrity;
59711diff --git a/include/linux/gracl.h b/include/linux/gracl.h
59712new file mode 100644
59713index 0000000..8a130b6
59714--- /dev/null
59715+++ b/include/linux/gracl.h
59716@@ -0,0 +1,319 @@
59717+#ifndef GR_ACL_H
59718+#define GR_ACL_H
59719+
59720+#include <linux/grdefs.h>
59721+#include <linux/resource.h>
59722+#include <linux/capability.h>
59723+#include <linux/dcache.h>
59724+#include <asm/resource.h>
59725+
59726+/* Major status information */
59727+
59728+#define GR_VERSION "grsecurity 2.9"
59729+#define GRSECURITY_VERSION 0x2900
59730+
59731+enum {
59732+ GR_SHUTDOWN = 0,
59733+ GR_ENABLE = 1,
59734+ GR_SPROLE = 2,
59735+ GR_RELOAD = 3,
59736+ GR_SEGVMOD = 4,
59737+ GR_STATUS = 5,
59738+ GR_UNSPROLE = 6,
59739+ GR_PASSSET = 7,
59740+ GR_SPROLEPAM = 8,
59741+};
59742+
59743+/* Password setup definitions
59744+ * kernel/grhash.c */
59745+enum {
59746+ GR_PW_LEN = 128,
59747+ GR_SALT_LEN = 16,
59748+ GR_SHA_LEN = 32,
59749+};
59750+
59751+enum {
59752+ GR_SPROLE_LEN = 64,
59753+};
59754+
59755+enum {
59756+ GR_NO_GLOB = 0,
59757+ GR_REG_GLOB,
59758+ GR_CREATE_GLOB
59759+};
59760+
59761+#define GR_NLIMITS 32
59762+
59763+/* Begin Data Structures */
59764+
59765+struct sprole_pw {
59766+ unsigned char *rolename;
59767+ unsigned char salt[GR_SALT_LEN];
59768+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
59769+};
59770+
59771+struct name_entry {
59772+ __u32 key;
59773+ ino_t inode;
59774+ dev_t device;
59775+ char *name;
59776+ __u16 len;
59777+ __u8 deleted;
59778+ struct name_entry *prev;
59779+ struct name_entry *next;
59780+};
59781+
59782+struct inodev_entry {
59783+ struct name_entry *nentry;
59784+ struct inodev_entry *prev;
59785+ struct inodev_entry *next;
59786+};
59787+
59788+struct acl_role_db {
59789+ struct acl_role_label **r_hash;
59790+ __u32 r_size;
59791+};
59792+
59793+struct inodev_db {
59794+ struct inodev_entry **i_hash;
59795+ __u32 i_size;
59796+};
59797+
59798+struct name_db {
59799+ struct name_entry **n_hash;
59800+ __u32 n_size;
59801+};
59802+
59803+struct crash_uid {
59804+ uid_t uid;
59805+ unsigned long expires;
59806+};
59807+
59808+struct gr_hash_struct {
59809+ void **table;
59810+ void **nametable;
59811+ void *first;
59812+ __u32 table_size;
59813+ __u32 used_size;
59814+ int type;
59815+};
59816+
59817+/* Userspace Grsecurity ACL data structures */
59818+
59819+struct acl_subject_label {
59820+ char *filename;
59821+ ino_t inode;
59822+ dev_t device;
59823+ __u32 mode;
59824+ kernel_cap_t cap_mask;
59825+ kernel_cap_t cap_lower;
59826+ kernel_cap_t cap_invert_audit;
59827+
59828+ struct rlimit res[GR_NLIMITS];
59829+ __u32 resmask;
59830+
59831+ __u8 user_trans_type;
59832+ __u8 group_trans_type;
59833+ uid_t *user_transitions;
59834+ gid_t *group_transitions;
59835+ __u16 user_trans_num;
59836+ __u16 group_trans_num;
59837+
59838+ __u32 sock_families[2];
59839+ __u32 ip_proto[8];
59840+ __u32 ip_type;
59841+ struct acl_ip_label **ips;
59842+ __u32 ip_num;
59843+ __u32 inaddr_any_override;
59844+
59845+ __u32 crashes;
59846+ unsigned long expires;
59847+
59848+ struct acl_subject_label *parent_subject;
59849+ struct gr_hash_struct *hash;
59850+ struct acl_subject_label *prev;
59851+ struct acl_subject_label *next;
59852+
59853+ struct acl_object_label **obj_hash;
59854+ __u32 obj_hash_size;
59855+ __u16 pax_flags;
59856+};
59857+
59858+struct role_allowed_ip {
59859+ __u32 addr;
59860+ __u32 netmask;
59861+
59862+ struct role_allowed_ip *prev;
59863+ struct role_allowed_ip *next;
59864+};
59865+
59866+struct role_transition {
59867+ char *rolename;
59868+
59869+ struct role_transition *prev;
59870+ struct role_transition *next;
59871+};
59872+
59873+struct acl_role_label {
59874+ char *rolename;
59875+ uid_t uidgid;
59876+ __u16 roletype;
59877+
59878+ __u16 auth_attempts;
59879+ unsigned long expires;
59880+
59881+ struct acl_subject_label *root_label;
59882+ struct gr_hash_struct *hash;
59883+
59884+ struct acl_role_label *prev;
59885+ struct acl_role_label *next;
59886+
59887+ struct role_transition *transitions;
59888+ struct role_allowed_ip *allowed_ips;
59889+ uid_t *domain_children;
59890+ __u16 domain_child_num;
59891+
59892+ umode_t umask;
59893+
59894+ struct acl_subject_label **subj_hash;
59895+ __u32 subj_hash_size;
59896+};
59897+
59898+struct user_acl_role_db {
59899+ struct acl_role_label **r_table;
59900+ __u32 num_pointers; /* Number of allocations to track */
59901+ __u32 num_roles; /* Number of roles */
59902+ __u32 num_domain_children; /* Number of domain children */
59903+ __u32 num_subjects; /* Number of subjects */
59904+ __u32 num_objects; /* Number of objects */
59905+};
59906+
59907+struct acl_object_label {
59908+ char *filename;
59909+ ino_t inode;
59910+ dev_t device;
59911+ __u32 mode;
59912+
59913+ struct acl_subject_label *nested;
59914+ struct acl_object_label *globbed;
59915+
59916+ /* next two structures not used */
59917+
59918+ struct acl_object_label *prev;
59919+ struct acl_object_label *next;
59920+};
59921+
59922+struct acl_ip_label {
59923+ char *iface;
59924+ __u32 addr;
59925+ __u32 netmask;
59926+ __u16 low, high;
59927+ __u8 mode;
59928+ __u32 type;
59929+ __u32 proto[8];
59930+
59931+ /* next two structures not used */
59932+
59933+ struct acl_ip_label *prev;
59934+ struct acl_ip_label *next;
59935+};
59936+
59937+struct gr_arg {
59938+ struct user_acl_role_db role_db;
59939+ unsigned char pw[GR_PW_LEN];
59940+ unsigned char salt[GR_SALT_LEN];
59941+ unsigned char sum[GR_SHA_LEN];
59942+ unsigned char sp_role[GR_SPROLE_LEN];
59943+ struct sprole_pw *sprole_pws;
59944+ dev_t segv_device;
59945+ ino_t segv_inode;
59946+ uid_t segv_uid;
59947+ __u16 num_sprole_pws;
59948+ __u16 mode;
59949+};
59950+
59951+struct gr_arg_wrapper {
59952+ struct gr_arg *arg;
59953+ __u32 version;
59954+ __u32 size;
59955+};
59956+
59957+struct subject_map {
59958+ struct acl_subject_label *user;
59959+ struct acl_subject_label *kernel;
59960+ struct subject_map *prev;
59961+ struct subject_map *next;
59962+};
59963+
59964+struct acl_subj_map_db {
59965+ struct subject_map **s_hash;
59966+ __u32 s_size;
59967+};
59968+
59969+/* End Data Structures Section */
59970+
59971+/* Hash functions generated by empirical testing by Brad Spengler
59972+ Makes good use of the low bits of the inode. Generally 0-1 times
59973+ in loop for successful match. 0-3 for unsuccessful match.
59974+ Shift/add algorithm with modulus of table size and an XOR*/
59975+
59976+static __inline__ unsigned int
59977+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
59978+{
59979+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
59980+}
59981+
59982+ static __inline__ unsigned int
59983+shash(const struct acl_subject_label *userp, const unsigned int sz)
59984+{
59985+ return ((const unsigned long)userp % sz);
59986+}
59987+
59988+static __inline__ unsigned int
59989+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
59990+{
59991+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
59992+}
59993+
59994+static __inline__ unsigned int
59995+nhash(const char *name, const __u16 len, const unsigned int sz)
59996+{
59997+ return full_name_hash((const unsigned char *)name, len) % sz;
59998+}
59999+
60000+#define FOR_EACH_ROLE_START(role) \
60001+ role = role_list; \
60002+ while (role) {
60003+
60004+#define FOR_EACH_ROLE_END(role) \
60005+ role = role->prev; \
60006+ }
60007+
60008+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
60009+ subj = NULL; \
60010+ iter = 0; \
60011+ while (iter < role->subj_hash_size) { \
60012+ if (subj == NULL) \
60013+ subj = role->subj_hash[iter]; \
60014+ if (subj == NULL) { \
60015+ iter++; \
60016+ continue; \
60017+ }
60018+
60019+#define FOR_EACH_SUBJECT_END(subj,iter) \
60020+ subj = subj->next; \
60021+ if (subj == NULL) \
60022+ iter++; \
60023+ }
60024+
60025+
60026+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
60027+ subj = role->hash->first; \
60028+ while (subj != NULL) {
60029+
60030+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
60031+ subj = subj->next; \
60032+ }
60033+
60034+#endif
60035+
60036diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
60037new file mode 100644
60038index 0000000..323ecf2
60039--- /dev/null
60040+++ b/include/linux/gralloc.h
60041@@ -0,0 +1,9 @@
60042+#ifndef __GRALLOC_H
60043+#define __GRALLOC_H
60044+
60045+void acl_free_all(void);
60046+int acl_alloc_stack_init(unsigned long size);
60047+void *acl_alloc(unsigned long len);
60048+void *acl_alloc_num(unsigned long num, unsigned long len);
60049+
60050+#endif
60051diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
60052new file mode 100644
60053index 0000000..b30e9bc
60054--- /dev/null
60055+++ b/include/linux/grdefs.h
60056@@ -0,0 +1,140 @@
60057+#ifndef GRDEFS_H
60058+#define GRDEFS_H
60059+
60060+/* Begin grsecurity status declarations */
60061+
60062+enum {
60063+ GR_READY = 0x01,
60064+ GR_STATUS_INIT = 0x00 // disabled state
60065+};
60066+
60067+/* Begin ACL declarations */
60068+
60069+/* Role flags */
60070+
60071+enum {
60072+ GR_ROLE_USER = 0x0001,
60073+ GR_ROLE_GROUP = 0x0002,
60074+ GR_ROLE_DEFAULT = 0x0004,
60075+ GR_ROLE_SPECIAL = 0x0008,
60076+ GR_ROLE_AUTH = 0x0010,
60077+ GR_ROLE_NOPW = 0x0020,
60078+ GR_ROLE_GOD = 0x0040,
60079+ GR_ROLE_LEARN = 0x0080,
60080+ GR_ROLE_TPE = 0x0100,
60081+ GR_ROLE_DOMAIN = 0x0200,
60082+ GR_ROLE_PAM = 0x0400,
60083+ GR_ROLE_PERSIST = 0x0800
60084+};
60085+
60086+/* ACL Subject and Object mode flags */
60087+enum {
60088+ GR_DELETED = 0x80000000
60089+};
60090+
60091+/* ACL Object-only mode flags */
60092+enum {
60093+ GR_READ = 0x00000001,
60094+ GR_APPEND = 0x00000002,
60095+ GR_WRITE = 0x00000004,
60096+ GR_EXEC = 0x00000008,
60097+ GR_FIND = 0x00000010,
60098+ GR_INHERIT = 0x00000020,
60099+ GR_SETID = 0x00000040,
60100+ GR_CREATE = 0x00000080,
60101+ GR_DELETE = 0x00000100,
60102+ GR_LINK = 0x00000200,
60103+ GR_AUDIT_READ = 0x00000400,
60104+ GR_AUDIT_APPEND = 0x00000800,
60105+ GR_AUDIT_WRITE = 0x00001000,
60106+ GR_AUDIT_EXEC = 0x00002000,
60107+ GR_AUDIT_FIND = 0x00004000,
60108+ GR_AUDIT_INHERIT= 0x00008000,
60109+ GR_AUDIT_SETID = 0x00010000,
60110+ GR_AUDIT_CREATE = 0x00020000,
60111+ GR_AUDIT_DELETE = 0x00040000,
60112+ GR_AUDIT_LINK = 0x00080000,
60113+ GR_PTRACERD = 0x00100000,
60114+ GR_NOPTRACE = 0x00200000,
60115+ GR_SUPPRESS = 0x00400000,
60116+ GR_NOLEARN = 0x00800000,
60117+ GR_INIT_TRANSFER= 0x01000000
60118+};
60119+
60120+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
60121+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
60122+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
60123+
60124+/* ACL subject-only mode flags */
60125+enum {
60126+ GR_KILL = 0x00000001,
60127+ GR_VIEW = 0x00000002,
60128+ GR_PROTECTED = 0x00000004,
60129+ GR_LEARN = 0x00000008,
60130+ GR_OVERRIDE = 0x00000010,
60131+ /* just a placeholder, this mode is only used in userspace */
60132+ GR_DUMMY = 0x00000020,
60133+ GR_PROTSHM = 0x00000040,
60134+ GR_KILLPROC = 0x00000080,
60135+ GR_KILLIPPROC = 0x00000100,
60136+ /* just a placeholder, this mode is only used in userspace */
60137+ GR_NOTROJAN = 0x00000200,
60138+ GR_PROTPROCFD = 0x00000400,
60139+ GR_PROCACCT = 0x00000800,
60140+ GR_RELAXPTRACE = 0x00001000,
60141+ GR_NESTED = 0x00002000,
60142+ GR_INHERITLEARN = 0x00004000,
60143+ GR_PROCFIND = 0x00008000,
60144+ GR_POVERRIDE = 0x00010000,
60145+ GR_KERNELAUTH = 0x00020000,
60146+ GR_ATSECURE = 0x00040000,
60147+ GR_SHMEXEC = 0x00080000
60148+};
60149+
60150+enum {
60151+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
60152+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
60153+ GR_PAX_ENABLE_MPROTECT = 0x0004,
60154+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
60155+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
60156+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
60157+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
60158+ GR_PAX_DISABLE_MPROTECT = 0x0400,
60159+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
60160+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
60161+};
60162+
60163+enum {
60164+ GR_ID_USER = 0x01,
60165+ GR_ID_GROUP = 0x02,
60166+};
60167+
60168+enum {
60169+ GR_ID_ALLOW = 0x01,
60170+ GR_ID_DENY = 0x02,
60171+};
60172+
60173+#define GR_CRASH_RES 31
60174+#define GR_UIDTABLE_MAX 500
60175+
60176+/* begin resource learning section */
60177+enum {
60178+ GR_RLIM_CPU_BUMP = 60,
60179+ GR_RLIM_FSIZE_BUMP = 50000,
60180+ GR_RLIM_DATA_BUMP = 10000,
60181+ GR_RLIM_STACK_BUMP = 1000,
60182+ GR_RLIM_CORE_BUMP = 10000,
60183+ GR_RLIM_RSS_BUMP = 500000,
60184+ GR_RLIM_NPROC_BUMP = 1,
60185+ GR_RLIM_NOFILE_BUMP = 5,
60186+ GR_RLIM_MEMLOCK_BUMP = 50000,
60187+ GR_RLIM_AS_BUMP = 500000,
60188+ GR_RLIM_LOCKS_BUMP = 2,
60189+ GR_RLIM_SIGPENDING_BUMP = 5,
60190+ GR_RLIM_MSGQUEUE_BUMP = 10000,
60191+ GR_RLIM_NICE_BUMP = 1,
60192+ GR_RLIM_RTPRIO_BUMP = 1,
60193+ GR_RLIM_RTTIME_BUMP = 1000000
60194+};
60195+
60196+#endif
60197diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
60198new file mode 100644
60199index 0000000..da390f1
60200--- /dev/null
60201+++ b/include/linux/grinternal.h
60202@@ -0,0 +1,221 @@
60203+#ifndef __GRINTERNAL_H
60204+#define __GRINTERNAL_H
60205+
60206+#ifdef CONFIG_GRKERNSEC
60207+
60208+#include <linux/fs.h>
60209+#include <linux/mnt_namespace.h>
60210+#include <linux/nsproxy.h>
60211+#include <linux/gracl.h>
60212+#include <linux/grdefs.h>
60213+#include <linux/grmsg.h>
60214+
60215+void gr_add_learn_entry(const char *fmt, ...)
60216+ __attribute__ ((format (printf, 1, 2)));
60217+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
60218+ const struct vfsmount *mnt);
60219+__u32 gr_check_create(const struct dentry *new_dentry,
60220+ const struct dentry *parent,
60221+ const struct vfsmount *mnt, const __u32 mode);
60222+int gr_check_protected_task(const struct task_struct *task);
60223+__u32 to_gr_audit(const __u32 reqmode);
60224+int gr_set_acls(const int type);
60225+int gr_apply_subject_to_task(struct task_struct *task);
60226+int gr_acl_is_enabled(void);
60227+char gr_roletype_to_char(void);
60228+
60229+void gr_handle_alertkill(struct task_struct *task);
60230+char *gr_to_filename(const struct dentry *dentry,
60231+ const struct vfsmount *mnt);
60232+char *gr_to_filename1(const struct dentry *dentry,
60233+ const struct vfsmount *mnt);
60234+char *gr_to_filename2(const struct dentry *dentry,
60235+ const struct vfsmount *mnt);
60236+char *gr_to_filename3(const struct dentry *dentry,
60237+ const struct vfsmount *mnt);
60238+
60239+extern int grsec_enable_ptrace_readexec;
60240+extern int grsec_enable_harden_ptrace;
60241+extern int grsec_enable_link;
60242+extern int grsec_enable_fifo;
60243+extern int grsec_enable_execve;
60244+extern int grsec_enable_shm;
60245+extern int grsec_enable_execlog;
60246+extern int grsec_enable_signal;
60247+extern int grsec_enable_audit_ptrace;
60248+extern int grsec_enable_forkfail;
60249+extern int grsec_enable_time;
60250+extern int grsec_enable_rofs;
60251+extern int grsec_enable_chroot_shmat;
60252+extern int grsec_enable_chroot_mount;
60253+extern int grsec_enable_chroot_double;
60254+extern int grsec_enable_chroot_pivot;
60255+extern int grsec_enable_chroot_chdir;
60256+extern int grsec_enable_chroot_chmod;
60257+extern int grsec_enable_chroot_mknod;
60258+extern int grsec_enable_chroot_fchdir;
60259+extern int grsec_enable_chroot_nice;
60260+extern int grsec_enable_chroot_execlog;
60261+extern int grsec_enable_chroot_caps;
60262+extern int grsec_enable_chroot_sysctl;
60263+extern int grsec_enable_chroot_unix;
60264+extern int grsec_enable_tpe;
60265+extern int grsec_tpe_gid;
60266+extern int grsec_enable_tpe_all;
60267+extern int grsec_enable_tpe_invert;
60268+extern int grsec_enable_socket_all;
60269+extern int grsec_socket_all_gid;
60270+extern int grsec_enable_socket_client;
60271+extern int grsec_socket_client_gid;
60272+extern int grsec_enable_socket_server;
60273+extern int grsec_socket_server_gid;
60274+extern int grsec_audit_gid;
60275+extern int grsec_enable_group;
60276+extern int grsec_enable_audit_textrel;
60277+extern int grsec_enable_log_rwxmaps;
60278+extern int grsec_enable_mount;
60279+extern int grsec_enable_chdir;
60280+extern int grsec_resource_logging;
60281+extern int grsec_enable_blackhole;
60282+extern int grsec_lastack_retries;
60283+extern int grsec_enable_brute;
60284+extern int grsec_lock;
60285+
60286+extern spinlock_t grsec_alert_lock;
60287+extern unsigned long grsec_alert_wtime;
60288+extern unsigned long grsec_alert_fyet;
60289+
60290+extern spinlock_t grsec_audit_lock;
60291+
60292+extern rwlock_t grsec_exec_file_lock;
60293+
60294+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
60295+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
60296+ (tsk)->exec_file->f_vfsmnt) : "/")
60297+
60298+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
60299+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
60300+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
60301+
60302+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
60303+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
60304+ (tsk)->exec_file->f_vfsmnt) : "/")
60305+
60306+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
60307+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
60308+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
60309+
60310+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
60311+
60312+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
60313+
60314+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
60315+ (task)->pid, (cred)->uid, \
60316+ (cred)->euid, (cred)->gid, (cred)->egid, \
60317+ gr_parent_task_fullpath(task), \
60318+ (task)->real_parent->comm, (task)->real_parent->pid, \
60319+ (pcred)->uid, (pcred)->euid, \
60320+ (pcred)->gid, (pcred)->egid
60321+
60322+#define GR_CHROOT_CAPS {{ \
60323+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
60324+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
60325+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
60326+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
60327+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
60328+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
60329+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
60330+
60331+#define security_learn(normal_msg,args...) \
60332+({ \
60333+ read_lock(&grsec_exec_file_lock); \
60334+ gr_add_learn_entry(normal_msg "\n", ## args); \
60335+ read_unlock(&grsec_exec_file_lock); \
60336+})
60337+
60338+enum {
60339+ GR_DO_AUDIT,
60340+ GR_DONT_AUDIT,
60341+ /* used for non-audit messages that we shouldn't kill the task on */
60342+ GR_DONT_AUDIT_GOOD
60343+};
60344+
60345+enum {
60346+ GR_TTYSNIFF,
60347+ GR_RBAC,
60348+ GR_RBAC_STR,
60349+ GR_STR_RBAC,
60350+ GR_RBAC_MODE2,
60351+ GR_RBAC_MODE3,
60352+ GR_FILENAME,
60353+ GR_SYSCTL_HIDDEN,
60354+ GR_NOARGS,
60355+ GR_ONE_INT,
60356+ GR_ONE_INT_TWO_STR,
60357+ GR_ONE_STR,
60358+ GR_STR_INT,
60359+ GR_TWO_STR_INT,
60360+ GR_TWO_INT,
60361+ GR_TWO_U64,
60362+ GR_THREE_INT,
60363+ GR_FIVE_INT_TWO_STR,
60364+ GR_TWO_STR,
60365+ GR_THREE_STR,
60366+ GR_FOUR_STR,
60367+ GR_STR_FILENAME,
60368+ GR_FILENAME_STR,
60369+ GR_FILENAME_TWO_INT,
60370+ GR_FILENAME_TWO_INT_STR,
60371+ GR_TEXTREL,
60372+ GR_PTRACE,
60373+ GR_RESOURCE,
60374+ GR_CAP,
60375+ GR_SIG,
60376+ GR_SIG2,
60377+ GR_CRASH1,
60378+ GR_CRASH2,
60379+ GR_PSACCT,
60380+ GR_RWXMAP
60381+};
60382+
60383+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
60384+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
60385+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
60386+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
60387+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
60388+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
60389+#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)
60390+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
60391+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
60392+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
60393+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
60394+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
60395+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
60396+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
60397+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
60398+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
60399+#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)
60400+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
60401+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
60402+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
60403+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
60404+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
60405+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
60406+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
60407+#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)
60408+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
60409+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
60410+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
60411+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
60412+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
60413+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
60414+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
60415+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
60416+#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)
60417+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
60418+
60419+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
60420+
60421+#endif
60422+
60423+#endif
60424diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
60425new file mode 100644
60426index 0000000..ae576a1
60427--- /dev/null
60428+++ b/include/linux/grmsg.h
60429@@ -0,0 +1,109 @@
60430+#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"
60431+#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"
60432+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
60433+#define GR_STOPMOD_MSG "denied modification of module state by "
60434+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
60435+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
60436+#define GR_IOPERM_MSG "denied use of ioperm() by "
60437+#define GR_IOPL_MSG "denied use of iopl() by "
60438+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
60439+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
60440+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
60441+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
60442+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
60443+#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"
60444+#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"
60445+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
60446+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
60447+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
60448+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
60449+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
60450+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
60451+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
60452+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
60453+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
60454+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
60455+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
60456+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
60457+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
60458+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
60459+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
60460+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
60461+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
60462+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
60463+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
60464+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
60465+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
60466+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
60467+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
60468+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
60469+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
60470+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
60471+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
60472+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
60473+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
60474+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
60475+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
60476+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
60477+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
60478+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
60479+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
60480+#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"
60481+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
60482+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
60483+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
60484+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
60485+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
60486+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
60487+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
60488+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
60489+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
60490+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
60491+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
60492+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
60493+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
60494+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
60495+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
60496+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
60497+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
60498+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
60499+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
60500+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
60501+#define GR_FAILFORK_MSG "failed fork with errno %s by "
60502+#define GR_NICE_CHROOT_MSG "denied priority change by "
60503+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
60504+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
60505+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
60506+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
60507+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
60508+#define GR_TIME_MSG "time set by "
60509+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
60510+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
60511+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
60512+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
60513+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
60514+#define GR_BIND_MSG "denied bind() by "
60515+#define GR_CONNECT_MSG "denied connect() by "
60516+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
60517+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
60518+#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"
60519+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
60520+#define GR_CAP_ACL_MSG "use of %s denied for "
60521+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
60522+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
60523+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
60524+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
60525+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
60526+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
60527+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
60528+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
60529+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
60530+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
60531+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
60532+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
60533+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
60534+#define GR_VM86_MSG "denied use of vm86 by "
60535+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
60536+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
60537+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
60538+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
60539diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
60540new file mode 100644
60541index 0000000..acd05db
60542--- /dev/null
60543+++ b/include/linux/grsecurity.h
60544@@ -0,0 +1,232 @@
60545+#ifndef GR_SECURITY_H
60546+#define GR_SECURITY_H
60547+#include <linux/fs.h>
60548+#include <linux/fs_struct.h>
60549+#include <linux/binfmts.h>
60550+#include <linux/gracl.h>
60551+
60552+/* notify of brain-dead configs */
60553+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60554+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
60555+#endif
60556+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
60557+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
60558+#endif
60559+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
60560+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
60561+#endif
60562+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
60563+#error "CONFIG_PAX enabled, but no PaX options are enabled."
60564+#endif
60565+
60566+#include <linux/compat.h>
60567+
60568+struct user_arg_ptr {
60569+#ifdef CONFIG_COMPAT
60570+ bool is_compat;
60571+#endif
60572+ union {
60573+ const char __user *const __user *native;
60574+#ifdef CONFIG_COMPAT
60575+ compat_uptr_t __user *compat;
60576+#endif
60577+ } ptr;
60578+};
60579+
60580+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
60581+void gr_handle_brute_check(void);
60582+void gr_handle_kernel_exploit(void);
60583+int gr_process_user_ban(void);
60584+
60585+char gr_roletype_to_char(void);
60586+
60587+int gr_acl_enable_at_secure(void);
60588+
60589+int gr_check_user_change(int real, int effective, int fs);
60590+int gr_check_group_change(int real, int effective, int fs);
60591+
60592+void gr_del_task_from_ip_table(struct task_struct *p);
60593+
60594+int gr_pid_is_chrooted(struct task_struct *p);
60595+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
60596+int gr_handle_chroot_nice(void);
60597+int gr_handle_chroot_sysctl(const int op);
60598+int gr_handle_chroot_setpriority(struct task_struct *p,
60599+ const int niceval);
60600+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
60601+int gr_handle_chroot_chroot(const struct dentry *dentry,
60602+ const struct vfsmount *mnt);
60603+void gr_handle_chroot_chdir(struct path *path);
60604+int gr_handle_chroot_chmod(const struct dentry *dentry,
60605+ const struct vfsmount *mnt, const int mode);
60606+int gr_handle_chroot_mknod(const struct dentry *dentry,
60607+ const struct vfsmount *mnt, const int mode);
60608+int gr_handle_chroot_mount(const struct dentry *dentry,
60609+ const struct vfsmount *mnt,
60610+ const char *dev_name);
60611+int gr_handle_chroot_pivot(void);
60612+int gr_handle_chroot_unix(const pid_t pid);
60613+
60614+int gr_handle_rawio(const struct inode *inode);
60615+
60616+void gr_handle_ioperm(void);
60617+void gr_handle_iopl(void);
60618+
60619+umode_t gr_acl_umask(void);
60620+
60621+int gr_tpe_allow(const struct file *file);
60622+
60623+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
60624+void gr_clear_chroot_entries(struct task_struct *task);
60625+
60626+void gr_log_forkfail(const int retval);
60627+void gr_log_timechange(void);
60628+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
60629+void gr_log_chdir(const struct dentry *dentry,
60630+ const struct vfsmount *mnt);
60631+void gr_log_chroot_exec(const struct dentry *dentry,
60632+ const struct vfsmount *mnt);
60633+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
60634+void gr_log_remount(const char *devname, const int retval);
60635+void gr_log_unmount(const char *devname, const int retval);
60636+void gr_log_mount(const char *from, const char *to, const int retval);
60637+void gr_log_textrel(struct vm_area_struct *vma);
60638+void gr_log_rwxmmap(struct file *file);
60639+void gr_log_rwxmprotect(struct file *file);
60640+
60641+int gr_handle_follow_link(const struct inode *parent,
60642+ const struct inode *inode,
60643+ const struct dentry *dentry,
60644+ const struct vfsmount *mnt);
60645+int gr_handle_fifo(const struct dentry *dentry,
60646+ const struct vfsmount *mnt,
60647+ const struct dentry *dir, const int flag,
60648+ const int acc_mode);
60649+int gr_handle_hardlink(const struct dentry *dentry,
60650+ const struct vfsmount *mnt,
60651+ struct inode *inode,
60652+ const int mode, const char *to);
60653+
60654+int gr_is_capable(const int cap);
60655+int gr_is_capable_nolog(const int cap);
60656+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
60657+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
60658+
60659+void gr_learn_resource(const struct task_struct *task, const int limit,
60660+ const unsigned long wanted, const int gt);
60661+void gr_copy_label(struct task_struct *tsk);
60662+void gr_handle_crash(struct task_struct *task, const int sig);
60663+int gr_handle_signal(const struct task_struct *p, const int sig);
60664+int gr_check_crash_uid(const uid_t uid);
60665+int gr_check_protected_task(const struct task_struct *task);
60666+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
60667+int gr_acl_handle_mmap(const struct file *file,
60668+ const unsigned long prot);
60669+int gr_acl_handle_mprotect(const struct file *file,
60670+ const unsigned long prot);
60671+int gr_check_hidden_task(const struct task_struct *tsk);
60672+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
60673+ const struct vfsmount *mnt);
60674+__u32 gr_acl_handle_utime(const struct dentry *dentry,
60675+ const struct vfsmount *mnt);
60676+__u32 gr_acl_handle_access(const struct dentry *dentry,
60677+ const struct vfsmount *mnt, const int fmode);
60678+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
60679+ const struct vfsmount *mnt, umode_t *mode);
60680+__u32 gr_acl_handle_chown(const struct dentry *dentry,
60681+ const struct vfsmount *mnt);
60682+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
60683+ const struct vfsmount *mnt);
60684+int gr_handle_ptrace(struct task_struct *task, const long request);
60685+int gr_handle_proc_ptrace(struct task_struct *task);
60686+__u32 gr_acl_handle_execve(const struct dentry *dentry,
60687+ const struct vfsmount *mnt);
60688+int gr_check_crash_exec(const struct file *filp);
60689+int gr_acl_is_enabled(void);
60690+void gr_set_kernel_label(struct task_struct *task);
60691+void gr_set_role_label(struct task_struct *task, const uid_t uid,
60692+ const gid_t gid);
60693+int gr_set_proc_label(const struct dentry *dentry,
60694+ const struct vfsmount *mnt,
60695+ const int unsafe_flags);
60696+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
60697+ const struct vfsmount *mnt);
60698+__u32 gr_acl_handle_open(const struct dentry *dentry,
60699+ const struct vfsmount *mnt, int acc_mode);
60700+__u32 gr_acl_handle_creat(const struct dentry *dentry,
60701+ const struct dentry *p_dentry,
60702+ const struct vfsmount *p_mnt,
60703+ int open_flags, int acc_mode, const int imode);
60704+void gr_handle_create(const struct dentry *dentry,
60705+ const struct vfsmount *mnt);
60706+void gr_handle_proc_create(const struct dentry *dentry,
60707+ const struct inode *inode);
60708+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
60709+ const struct dentry *parent_dentry,
60710+ const struct vfsmount *parent_mnt,
60711+ const int mode);
60712+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
60713+ const struct dentry *parent_dentry,
60714+ const struct vfsmount *parent_mnt);
60715+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
60716+ const struct vfsmount *mnt);
60717+void gr_handle_delete(const ino_t ino, const dev_t dev);
60718+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
60719+ const struct vfsmount *mnt);
60720+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
60721+ const struct dentry *parent_dentry,
60722+ const struct vfsmount *parent_mnt,
60723+ const char *from);
60724+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
60725+ const struct dentry *parent_dentry,
60726+ const struct vfsmount *parent_mnt,
60727+ const struct dentry *old_dentry,
60728+ const struct vfsmount *old_mnt, const char *to);
60729+int gr_acl_handle_rename(struct dentry *new_dentry,
60730+ struct dentry *parent_dentry,
60731+ const struct vfsmount *parent_mnt,
60732+ struct dentry *old_dentry,
60733+ struct inode *old_parent_inode,
60734+ struct vfsmount *old_mnt, const char *newname);
60735+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
60736+ struct dentry *old_dentry,
60737+ struct dentry *new_dentry,
60738+ struct vfsmount *mnt, const __u8 replace);
60739+__u32 gr_check_link(const struct dentry *new_dentry,
60740+ const struct dentry *parent_dentry,
60741+ const struct vfsmount *parent_mnt,
60742+ const struct dentry *old_dentry,
60743+ const struct vfsmount *old_mnt);
60744+int gr_acl_handle_filldir(const struct file *file, const char *name,
60745+ const unsigned int namelen, const ino_t ino);
60746+
60747+__u32 gr_acl_handle_unix(const struct dentry *dentry,
60748+ const struct vfsmount *mnt);
60749+void gr_acl_handle_exit(void);
60750+void gr_acl_handle_psacct(struct task_struct *task, const long code);
60751+int gr_acl_handle_procpidmem(const struct task_struct *task);
60752+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
60753+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
60754+void gr_audit_ptrace(struct task_struct *task);
60755+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
60756+
60757+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
60758+
60759+#ifdef CONFIG_GRKERNSEC
60760+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
60761+void gr_handle_vm86(void);
60762+void gr_handle_mem_readwrite(u64 from, u64 to);
60763+
60764+void gr_log_badprocpid(const char *entry);
60765+
60766+extern int grsec_enable_dmesg;
60767+extern int grsec_disable_privio;
60768+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60769+extern int grsec_enable_chroot_findtask;
60770+#endif
60771+#ifdef CONFIG_GRKERNSEC_SETXID
60772+extern int grsec_enable_setxid;
60773+#endif
60774+#endif
60775+
60776+#endif
60777diff --git a/include/linux/grsock.h b/include/linux/grsock.h
60778new file mode 100644
60779index 0000000..e7ffaaf
60780--- /dev/null
60781+++ b/include/linux/grsock.h
60782@@ -0,0 +1,19 @@
60783+#ifndef __GRSOCK_H
60784+#define __GRSOCK_H
60785+
60786+extern void gr_attach_curr_ip(const struct sock *sk);
60787+extern int gr_handle_sock_all(const int family, const int type,
60788+ const int protocol);
60789+extern int gr_handle_sock_server(const struct sockaddr *sck);
60790+extern int gr_handle_sock_server_other(const struct sock *sck);
60791+extern int gr_handle_sock_client(const struct sockaddr *sck);
60792+extern int gr_search_connect(struct socket * sock,
60793+ struct sockaddr_in * addr);
60794+extern int gr_search_bind(struct socket * sock,
60795+ struct sockaddr_in * addr);
60796+extern int gr_search_listen(struct socket * sock);
60797+extern int gr_search_accept(struct socket * sock);
60798+extern int gr_search_socket(const int domain, const int type,
60799+ const int protocol);
60800+
60801+#endif
60802diff --git a/include/linux/hid.h b/include/linux/hid.h
60803index 3a95da6..51986f1 100644
60804--- a/include/linux/hid.h
60805+++ b/include/linux/hid.h
60806@@ -696,7 +696,7 @@ struct hid_ll_driver {
60807 unsigned int code, int value);
60808
60809 int (*parse)(struct hid_device *hdev);
60810-};
60811+} __no_const;
60812
60813 #define PM_HINT_FULLON 1<<5
60814 #define PM_HINT_NORMAL 1<<1
60815diff --git a/include/linux/highmem.h b/include/linux/highmem.h
60816index 3a93f73..b19d0b3 100644
60817--- a/include/linux/highmem.h
60818+++ b/include/linux/highmem.h
60819@@ -185,6 +185,18 @@ static inline void clear_highpage(struct page *page)
60820 kunmap_atomic(kaddr, KM_USER0);
60821 }
60822
60823+static inline void sanitize_highpage(struct page *page)
60824+{
60825+ void *kaddr;
60826+ unsigned long flags;
60827+
60828+ local_irq_save(flags);
60829+ kaddr = kmap_atomic(page, KM_CLEARPAGE);
60830+ clear_page(kaddr);
60831+ kunmap_atomic(kaddr, KM_CLEARPAGE);
60832+ local_irq_restore(flags);
60833+}
60834+
60835 static inline void zero_user_segments(struct page *page,
60836 unsigned start1, unsigned end1,
60837 unsigned start2, unsigned end2)
60838diff --git a/include/linux/i2c.h b/include/linux/i2c.h
60839index 8e25a91..551b161 100644
60840--- a/include/linux/i2c.h
60841+++ b/include/linux/i2c.h
60842@@ -364,6 +364,7 @@ struct i2c_algorithm {
60843 /* To determine what the adapter supports */
60844 u32 (*functionality) (struct i2c_adapter *);
60845 };
60846+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
60847
60848 /*
60849 * i2c_adapter is the structure used to identify a physical i2c bus along
60850diff --git a/include/linux/i2o.h b/include/linux/i2o.h
60851index a6deef4..c56a7f2 100644
60852--- a/include/linux/i2o.h
60853+++ b/include/linux/i2o.h
60854@@ -564,7 +564,7 @@ struct i2o_controller {
60855 struct i2o_device *exec; /* Executive */
60856 #if BITS_PER_LONG == 64
60857 spinlock_t context_list_lock; /* lock for context_list */
60858- atomic_t context_list_counter; /* needed for unique contexts */
60859+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
60860 struct list_head context_list; /* list of context id's
60861 and pointers */
60862 #endif
60863diff --git a/include/linux/if_team.h b/include/linux/if_team.h
60864index 58404b0..439ed95 100644
60865--- a/include/linux/if_team.h
60866+++ b/include/linux/if_team.h
60867@@ -64,6 +64,7 @@ struct team_mode_ops {
60868 void (*port_leave)(struct team *team, struct team_port *port);
60869 void (*port_change_mac)(struct team *team, struct team_port *port);
60870 };
60871+typedef struct team_mode_ops __no_const team_mode_ops_no_const;
60872
60873 enum team_option_type {
60874 TEAM_OPTION_TYPE_U32,
60875@@ -112,7 +113,7 @@ struct team {
60876 struct list_head option_list;
60877
60878 const struct team_mode *mode;
60879- struct team_mode_ops ops;
60880+ team_mode_ops_no_const ops;
60881 long mode_priv[TEAM_MODE_PRIV_LONGS];
60882 };
60883
60884diff --git a/include/linux/init.h b/include/linux/init.h
60885index 6b95109..4aca62c 100644
60886--- a/include/linux/init.h
60887+++ b/include/linux/init.h
60888@@ -294,13 +294,13 @@ void __init parse_early_options(char *cmdline);
60889
60890 /* Each module must use one module_init(). */
60891 #define module_init(initfn) \
60892- static inline initcall_t __inittest(void) \
60893+ static inline __used initcall_t __inittest(void) \
60894 { return initfn; } \
60895 int init_module(void) __attribute__((alias(#initfn)));
60896
60897 /* This is only required if you want to be unloadable. */
60898 #define module_exit(exitfn) \
60899- static inline exitcall_t __exittest(void) \
60900+ static inline __used exitcall_t __exittest(void) \
60901 { return exitfn; } \
60902 void cleanup_module(void) __attribute__((alias(#exitfn)));
60903
60904diff --git a/include/linux/init_task.h b/include/linux/init_task.h
60905index 9c66b1a..a3fdded 100644
60906--- a/include/linux/init_task.h
60907+++ b/include/linux/init_task.h
60908@@ -127,6 +127,12 @@ extern struct cred init_cred;
60909
60910 #define INIT_TASK_COMM "swapper"
60911
60912+#ifdef CONFIG_X86
60913+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
60914+#else
60915+#define INIT_TASK_THREAD_INFO
60916+#endif
60917+
60918 /*
60919 * INIT_TASK is used to set up the first task table, touch at
60920 * your own risk!. Base=0, limit=0x1fffff (=2MB)
60921@@ -165,6 +171,7 @@ extern struct cred init_cred;
60922 RCU_INIT_POINTER(.cred, &init_cred), \
60923 .comm = INIT_TASK_COMM, \
60924 .thread = INIT_THREAD, \
60925+ INIT_TASK_THREAD_INFO \
60926 .fs = &init_fs, \
60927 .files = &init_files, \
60928 .signal = &init_signals, \
60929diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
60930index e6ca56d..8583707 100644
60931--- a/include/linux/intel-iommu.h
60932+++ b/include/linux/intel-iommu.h
60933@@ -296,7 +296,7 @@ struct iommu_flush {
60934 u8 fm, u64 type);
60935 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
60936 unsigned int size_order, u64 type);
60937-};
60938+} __no_const;
60939
60940 enum {
60941 SR_DMAR_FECTL_REG,
60942diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
60943index a64b00e..464d8bc 100644
60944--- a/include/linux/interrupt.h
60945+++ b/include/linux/interrupt.h
60946@@ -441,7 +441,7 @@ enum
60947 /* map softirq index to softirq name. update 'softirq_to_name' in
60948 * kernel/softirq.c when adding a new softirq.
60949 */
60950-extern char *softirq_to_name[NR_SOFTIRQS];
60951+extern const char * const softirq_to_name[NR_SOFTIRQS];
60952
60953 /* softirq mask and active fields moved to irq_cpustat_t in
60954 * asm/hardirq.h to get better cache usage. KAO
60955@@ -449,12 +449,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
60956
60957 struct softirq_action
60958 {
60959- void (*action)(struct softirq_action *);
60960+ void (*action)(void);
60961 };
60962
60963 asmlinkage void do_softirq(void);
60964 asmlinkage void __do_softirq(void);
60965-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
60966+extern void open_softirq(int nr, void (*action)(void));
60967 extern void softirq_init(void);
60968 static inline void __raise_softirq_irqoff(unsigned int nr)
60969 {
60970diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
60971index 3875719..4cd454c 100644
60972--- a/include/linux/kallsyms.h
60973+++ b/include/linux/kallsyms.h
60974@@ -15,7 +15,8 @@
60975
60976 struct module;
60977
60978-#ifdef CONFIG_KALLSYMS
60979+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
60980+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60981 /* Lookup the address for a symbol. Returns 0 if not found. */
60982 unsigned long kallsyms_lookup_name(const char *name);
60983
60984@@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
60985 /* Stupid that this does nothing, but I didn't create this mess. */
60986 #define __print_symbol(fmt, addr)
60987 #endif /*CONFIG_KALLSYMS*/
60988+#else /* when included by kallsyms.c, vsnprintf.c, or
60989+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
60990+extern void __print_symbol(const char *fmt, unsigned long address);
60991+extern int sprint_backtrace(char *buffer, unsigned long address);
60992+extern int sprint_symbol(char *buffer, unsigned long address);
60993+const char *kallsyms_lookup(unsigned long addr,
60994+ unsigned long *symbolsize,
60995+ unsigned long *offset,
60996+ char **modname, char *namebuf);
60997+#endif
60998
60999 /* This macro allows us to keep printk typechecking */
61000 static __printf(1, 2)
61001diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
61002index fa39183..40160be 100644
61003--- a/include/linux/kgdb.h
61004+++ b/include/linux/kgdb.h
61005@@ -53,7 +53,7 @@ extern int kgdb_connected;
61006 extern int kgdb_io_module_registered;
61007
61008 extern atomic_t kgdb_setting_breakpoint;
61009-extern atomic_t kgdb_cpu_doing_single_step;
61010+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
61011
61012 extern struct task_struct *kgdb_usethread;
61013 extern struct task_struct *kgdb_contthread;
61014@@ -251,7 +251,7 @@ struct kgdb_arch {
61015 void (*disable_hw_break)(struct pt_regs *regs);
61016 void (*remove_all_hw_break)(void);
61017 void (*correct_hw_break)(void);
61018-};
61019+} __do_const;
61020
61021 /**
61022 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
61023@@ -276,7 +276,7 @@ struct kgdb_io {
61024 void (*pre_exception) (void);
61025 void (*post_exception) (void);
61026 int is_console;
61027-};
61028+} __do_const;
61029
61030 extern struct kgdb_arch arch_kgdb_ops;
61031
61032diff --git a/include/linux/kmod.h b/include/linux/kmod.h
61033index 722f477..eef2a27 100644
61034--- a/include/linux/kmod.h
61035+++ b/include/linux/kmod.h
61036@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
61037 * usually useless though. */
61038 extern __printf(2, 3)
61039 int __request_module(bool wait, const char *name, ...);
61040+extern __printf(3, 4)
61041+int ___request_module(bool wait, char *param_name, const char *name, ...);
61042 #define request_module(mod...) __request_module(true, mod)
61043 #define request_module_nowait(mod...) __request_module(false, mod)
61044 #define try_then_request_module(x, mod...) \
61045diff --git a/include/linux/kref.h b/include/linux/kref.h
61046index 9c07dce..a92fa71 100644
61047--- a/include/linux/kref.h
61048+++ b/include/linux/kref.h
61049@@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
61050 static inline int kref_sub(struct kref *kref, unsigned int count,
61051 void (*release)(struct kref *kref))
61052 {
61053- WARN_ON(release == NULL);
61054+ BUG_ON(release == NULL);
61055
61056 if (atomic_sub_and_test((int) count, &kref->refcount)) {
61057 release(kref);
61058diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
61059index 900c763..43260cf 100644
61060--- a/include/linux/kvm_host.h
61061+++ b/include/linux/kvm_host.h
61062@@ -326,7 +326,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
61063 void vcpu_load(struct kvm_vcpu *vcpu);
61064 void vcpu_put(struct kvm_vcpu *vcpu);
61065
61066-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
61067+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
61068 struct module *module);
61069 void kvm_exit(void);
61070
61071@@ -485,7 +485,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
61072 struct kvm_guest_debug *dbg);
61073 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
61074
61075-int kvm_arch_init(void *opaque);
61076+int kvm_arch_init(const void *opaque);
61077 void kvm_arch_exit(void);
61078
61079 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
61080diff --git a/include/linux/libata.h b/include/linux/libata.h
61081index cafc09a..d7e7829 100644
61082--- a/include/linux/libata.h
61083+++ b/include/linux/libata.h
61084@@ -909,7 +909,7 @@ struct ata_port_operations {
61085 * fields must be pointers.
61086 */
61087 const struct ata_port_operations *inherits;
61088-};
61089+} __do_const;
61090
61091 struct ata_port_info {
61092 unsigned long flags;
61093diff --git a/include/linux/mca.h b/include/linux/mca.h
61094index 3797270..7765ede 100644
61095--- a/include/linux/mca.h
61096+++ b/include/linux/mca.h
61097@@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
61098 int region);
61099 void * (*mca_transform_memory)(struct mca_device *,
61100 void *memory);
61101-};
61102+} __no_const;
61103
61104 struct mca_bus {
61105 u64 default_dma_mask;
61106diff --git a/include/linux/memory.h b/include/linux/memory.h
61107index 1ac7f6e..a5794d0 100644
61108--- a/include/linux/memory.h
61109+++ b/include/linux/memory.h
61110@@ -143,7 +143,7 @@ struct memory_accessor {
61111 size_t count);
61112 ssize_t (*write)(struct memory_accessor *, const char *buf,
61113 off_t offset, size_t count);
61114-};
61115+} __no_const;
61116
61117 /*
61118 * Kernel text modification mutex, used for code patching. Users of this lock
61119diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
61120index 9970337..9444122 100644
61121--- a/include/linux/mfd/abx500.h
61122+++ b/include/linux/mfd/abx500.h
61123@@ -188,6 +188,7 @@ struct abx500_ops {
61124 int (*event_registers_startup_state_get) (struct device *, u8 *);
61125 int (*startup_irq_enabled) (struct device *, unsigned int);
61126 };
61127+typedef struct abx500_ops __no_const abx500_ops_no_const;
61128
61129 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
61130 void abx500_remove_ops(struct device *dev);
61131diff --git a/include/linux/mm.h b/include/linux/mm.h
61132index 17b27cd..467ba2f 100644
61133--- a/include/linux/mm.h
61134+++ b/include/linux/mm.h
61135@@ -115,7 +115,14 @@ extern unsigned int kobjsize(const void *objp);
61136
61137 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
61138 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
61139+
61140+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
61141+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
61142+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
61143+#else
61144 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
61145+#endif
61146+
61147 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
61148 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
61149
61150@@ -1012,34 +1019,6 @@ int set_page_dirty(struct page *page);
61151 int set_page_dirty_lock(struct page *page);
61152 int clear_page_dirty_for_io(struct page *page);
61153
61154-/* Is the vma a continuation of the stack vma above it? */
61155-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
61156-{
61157- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
61158-}
61159-
61160-static inline int stack_guard_page_start(struct vm_area_struct *vma,
61161- unsigned long addr)
61162-{
61163- return (vma->vm_flags & VM_GROWSDOWN) &&
61164- (vma->vm_start == addr) &&
61165- !vma_growsdown(vma->vm_prev, addr);
61166-}
61167-
61168-/* Is the vma a continuation of the stack vma below it? */
61169-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
61170-{
61171- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
61172-}
61173-
61174-static inline int stack_guard_page_end(struct vm_area_struct *vma,
61175- unsigned long addr)
61176-{
61177- return (vma->vm_flags & VM_GROWSUP) &&
61178- (vma->vm_end == addr) &&
61179- !vma_growsup(vma->vm_next, addr);
61180-}
61181-
61182 extern unsigned long move_page_tables(struct vm_area_struct *vma,
61183 unsigned long old_addr, struct vm_area_struct *new_vma,
61184 unsigned long new_addr, unsigned long len);
61185@@ -1134,6 +1113,15 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
61186 }
61187 #endif
61188
61189+#ifdef CONFIG_MMU
61190+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
61191+#else
61192+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
61193+{
61194+ return __pgprot(0);
61195+}
61196+#endif
61197+
61198 int vma_wants_writenotify(struct vm_area_struct *vma);
61199
61200 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
61201@@ -1409,6 +1397,7 @@ out:
61202 }
61203
61204 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
61205+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
61206
61207 extern unsigned long do_brk(unsigned long, unsigned long);
61208
61209@@ -1466,6 +1455,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
61210 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
61211 struct vm_area_struct **pprev);
61212
61213+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
61214+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
61215+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
61216+
61217 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
61218 NULL if none. Assume start_addr < end_addr. */
61219 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
61220@@ -1494,15 +1487,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
61221 return vma;
61222 }
61223
61224-#ifdef CONFIG_MMU
61225-pgprot_t vm_get_page_prot(unsigned long vm_flags);
61226-#else
61227-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
61228-{
61229- return __pgprot(0);
61230-}
61231-#endif
61232-
61233 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
61234 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
61235 unsigned long pfn, unsigned long size, pgprot_t);
61236@@ -1606,7 +1590,7 @@ extern int unpoison_memory(unsigned long pfn);
61237 extern int sysctl_memory_failure_early_kill;
61238 extern int sysctl_memory_failure_recovery;
61239 extern void shake_page(struct page *p, int access);
61240-extern atomic_long_t mce_bad_pages;
61241+extern atomic_long_unchecked_t mce_bad_pages;
61242 extern int soft_offline_page(struct page *page, int flags);
61243
61244 extern void dump_page(struct page *page);
61245@@ -1637,5 +1621,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
61246 static inline bool page_is_guard(struct page *page) { return false; }
61247 #endif /* CONFIG_DEBUG_PAGEALLOC */
61248
61249+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
61250+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
61251+#else
61252+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
61253+#endif
61254+
61255 #endif /* __KERNEL__ */
61256 #endif /* _LINUX_MM_H */
61257diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
61258index 3cc3062..8947a82 100644
61259--- a/include/linux/mm_types.h
61260+++ b/include/linux/mm_types.h
61261@@ -252,6 +252,8 @@ struct vm_area_struct {
61262 #ifdef CONFIG_NUMA
61263 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
61264 #endif
61265+
61266+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
61267 };
61268
61269 struct core_thread {
61270@@ -388,6 +390,24 @@ struct mm_struct {
61271 #ifdef CONFIG_CPUMASK_OFFSTACK
61272 struct cpumask cpumask_allocation;
61273 #endif
61274+
61275+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
61276+ unsigned long pax_flags;
61277+#endif
61278+
61279+#ifdef CONFIG_PAX_DLRESOLVE
61280+ unsigned long call_dl_resolve;
61281+#endif
61282+
61283+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
61284+ unsigned long call_syscall;
61285+#endif
61286+
61287+#ifdef CONFIG_PAX_ASLR
61288+ unsigned long delta_mmap; /* randomized offset */
61289+ unsigned long delta_stack; /* randomized offset */
61290+#endif
61291+
61292 };
61293
61294 static inline void mm_init_cpumask(struct mm_struct *mm)
61295diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
61296index 1d1b1e1..2a13c78 100644
61297--- a/include/linux/mmu_notifier.h
61298+++ b/include/linux/mmu_notifier.h
61299@@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
61300 */
61301 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
61302 ({ \
61303- pte_t __pte; \
61304+ pte_t ___pte; \
61305 struct vm_area_struct *___vma = __vma; \
61306 unsigned long ___address = __address; \
61307- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
61308+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
61309 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
61310- __pte; \
61311+ ___pte; \
61312 })
61313
61314 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
61315diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
61316index 650ba2f..af0a58c 100644
61317--- a/include/linux/mmzone.h
61318+++ b/include/linux/mmzone.h
61319@@ -379,7 +379,7 @@ struct zone {
61320 unsigned long flags; /* zone flags, see below */
61321
61322 /* Zone statistics */
61323- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61324+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61325
61326 /*
61327 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
61328diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
61329index 83ac071..2656e0e 100644
61330--- a/include/linux/mod_devicetable.h
61331+++ b/include/linux/mod_devicetable.h
61332@@ -12,7 +12,7 @@
61333 typedef unsigned long kernel_ulong_t;
61334 #endif
61335
61336-#define PCI_ANY_ID (~0)
61337+#define PCI_ANY_ID ((__u16)~0)
61338
61339 struct pci_device_id {
61340 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
61341@@ -131,7 +131,7 @@ struct usb_device_id {
61342 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
61343 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
61344
61345-#define HID_ANY_ID (~0)
61346+#define HID_ANY_ID (~0U)
61347
61348 struct hid_device_id {
61349 __u16 bus;
61350diff --git a/include/linux/module.h b/include/linux/module.h
61351index 4598bf0..e069d7f 100644
61352--- a/include/linux/module.h
61353+++ b/include/linux/module.h
61354@@ -17,6 +17,7 @@
61355 #include <linux/moduleparam.h>
61356 #include <linux/tracepoint.h>
61357 #include <linux/export.h>
61358+#include <linux/fs.h>
61359
61360 #include <linux/percpu.h>
61361 #include <asm/module.h>
61362@@ -275,19 +276,16 @@ struct module
61363 int (*init)(void);
61364
61365 /* If this is non-NULL, vfree after init() returns */
61366- void *module_init;
61367+ void *module_init_rx, *module_init_rw;
61368
61369 /* Here is the actual code + data, vfree'd on unload. */
61370- void *module_core;
61371+ void *module_core_rx, *module_core_rw;
61372
61373 /* Here are the sizes of the init and core sections */
61374- unsigned int init_size, core_size;
61375+ unsigned int init_size_rw, core_size_rw;
61376
61377 /* The size of the executable code in each section. */
61378- unsigned int init_text_size, core_text_size;
61379-
61380- /* Size of RO sections of the module (text+rodata) */
61381- unsigned int init_ro_size, core_ro_size;
61382+ unsigned int init_size_rx, core_size_rx;
61383
61384 /* Arch-specific module values */
61385 struct mod_arch_specific arch;
61386@@ -343,6 +341,10 @@ struct module
61387 #ifdef CONFIG_EVENT_TRACING
61388 struct ftrace_event_call **trace_events;
61389 unsigned int num_trace_events;
61390+ struct file_operations trace_id;
61391+ struct file_operations trace_enable;
61392+ struct file_operations trace_format;
61393+ struct file_operations trace_filter;
61394 #endif
61395 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
61396 unsigned int num_ftrace_callsites;
61397@@ -390,16 +392,46 @@ bool is_module_address(unsigned long addr);
61398 bool is_module_percpu_address(unsigned long addr);
61399 bool is_module_text_address(unsigned long addr);
61400
61401+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
61402+{
61403+
61404+#ifdef CONFIG_PAX_KERNEXEC
61405+ if (ktla_ktva(addr) >= (unsigned long)start &&
61406+ ktla_ktva(addr) < (unsigned long)start + size)
61407+ return 1;
61408+#endif
61409+
61410+ return ((void *)addr >= start && (void *)addr < start + size);
61411+}
61412+
61413+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
61414+{
61415+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
61416+}
61417+
61418+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
61419+{
61420+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
61421+}
61422+
61423+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
61424+{
61425+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
61426+}
61427+
61428+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
61429+{
61430+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
61431+}
61432+
61433 static inline int within_module_core(unsigned long addr, struct module *mod)
61434 {
61435- return (unsigned long)mod->module_core <= addr &&
61436- addr < (unsigned long)mod->module_core + mod->core_size;
61437+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
61438 }
61439
61440 static inline int within_module_init(unsigned long addr, struct module *mod)
61441 {
61442- return (unsigned long)mod->module_init <= addr &&
61443- addr < (unsigned long)mod->module_init + mod->init_size;
61444+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
61445 }
61446
61447 /* Search for module by name: must hold module_mutex. */
61448diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
61449index b2be02e..6a9fdb1 100644
61450--- a/include/linux/moduleloader.h
61451+++ b/include/linux/moduleloader.h
61452@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
61453 sections. Returns NULL on failure. */
61454 void *module_alloc(unsigned long size);
61455
61456+#ifdef CONFIG_PAX_KERNEXEC
61457+void *module_alloc_exec(unsigned long size);
61458+#else
61459+#define module_alloc_exec(x) module_alloc(x)
61460+#endif
61461+
61462 /* Free memory returned from module_alloc. */
61463 void module_free(struct module *mod, void *module_region);
61464
61465+#ifdef CONFIG_PAX_KERNEXEC
61466+void module_free_exec(struct module *mod, void *module_region);
61467+#else
61468+#define module_free_exec(x, y) module_free((x), (y))
61469+#endif
61470+
61471 /* Apply the given relocation to the (simplified) ELF. Return -error
61472 or 0. */
61473 int apply_relocate(Elf_Shdr *sechdrs,
61474diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
61475index c47f4d6..23f9bdb 100644
61476--- a/include/linux/moduleparam.h
61477+++ b/include/linux/moduleparam.h
61478@@ -260,7 +260,7 @@ static inline void __kernel_param_unlock(void)
61479 * @len is usually just sizeof(string).
61480 */
61481 #define module_param_string(name, string, len, perm) \
61482- static const struct kparam_string __param_string_##name \
61483+ static const struct kparam_string __param_string_##name __used \
61484 = { len, string }; \
61485 __module_param_call(MODULE_PARAM_PREFIX, name, \
61486 &param_ops_string, \
61487@@ -396,7 +396,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
61488 */
61489 #define module_param_array_named(name, array, type, nump, perm) \
61490 param_check_##type(name, &(array)[0]); \
61491- static const struct kparam_array __param_arr_##name \
61492+ static const struct kparam_array __param_arr_##name __used \
61493 = { .max = ARRAY_SIZE(array), .num = nump, \
61494 .ops = &param_ops_##type, \
61495 .elemsize = sizeof(array[0]), .elem = array }; \
61496diff --git a/include/linux/namei.h b/include/linux/namei.h
61497index ffc0213..2c1f2cb 100644
61498--- a/include/linux/namei.h
61499+++ b/include/linux/namei.h
61500@@ -24,7 +24,7 @@ struct nameidata {
61501 unsigned seq;
61502 int last_type;
61503 unsigned depth;
61504- char *saved_names[MAX_NESTED_LINKS + 1];
61505+ const char *saved_names[MAX_NESTED_LINKS + 1];
61506
61507 /* Intent data */
61508 union {
61509@@ -94,12 +94,12 @@ extern int follow_up(struct path *);
61510 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
61511 extern void unlock_rename(struct dentry *, struct dentry *);
61512
61513-static inline void nd_set_link(struct nameidata *nd, char *path)
61514+static inline void nd_set_link(struct nameidata *nd, const char *path)
61515 {
61516 nd->saved_names[nd->depth] = path;
61517 }
61518
61519-static inline char *nd_get_link(struct nameidata *nd)
61520+static inline const char *nd_get_link(const struct nameidata *nd)
61521 {
61522 return nd->saved_names[nd->depth];
61523 }
61524diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
61525index 0eac07c..a59f6a8 100644
61526--- a/include/linux/netdevice.h
61527+++ b/include/linux/netdevice.h
61528@@ -1002,6 +1002,7 @@ struct net_device_ops {
61529 int (*ndo_neigh_construct)(struct neighbour *n);
61530 void (*ndo_neigh_destroy)(struct neighbour *n);
61531 };
61532+typedef struct net_device_ops __no_const net_device_ops_no_const;
61533
61534 /*
61535 * The DEVICE structure.
61536@@ -1063,7 +1064,7 @@ struct net_device {
61537 int iflink;
61538
61539 struct net_device_stats stats;
61540- atomic_long_t rx_dropped; /* dropped packets by core network
61541+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
61542 * Do not use this in drivers.
61543 */
61544
61545diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
61546new file mode 100644
61547index 0000000..33f4af8
61548--- /dev/null
61549+++ b/include/linux/netfilter/xt_gradm.h
61550@@ -0,0 +1,9 @@
61551+#ifndef _LINUX_NETFILTER_XT_GRADM_H
61552+#define _LINUX_NETFILTER_XT_GRADM_H 1
61553+
61554+struct xt_gradm_mtinfo {
61555+ __u16 flags;
61556+ __u16 invflags;
61557+};
61558+
61559+#endif
61560diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
61561index c65a18a..0c05f3a 100644
61562--- a/include/linux/of_pdt.h
61563+++ b/include/linux/of_pdt.h
61564@@ -32,7 +32,7 @@ struct of_pdt_ops {
61565
61566 /* return 0 on success; fill in 'len' with number of bytes in path */
61567 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
61568-};
61569+} __no_const;
61570
61571 extern void *prom_early_alloc(unsigned long size);
61572
61573diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
61574index a4c5624..79d6d88 100644
61575--- a/include/linux/oprofile.h
61576+++ b/include/linux/oprofile.h
61577@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
61578 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
61579 char const * name, ulong * val);
61580
61581-/** Create a file for read-only access to an atomic_t. */
61582+/** Create a file for read-only access to an atomic_unchecked_t. */
61583 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
61584- char const * name, atomic_t * val);
61585+ char const * name, atomic_unchecked_t * val);
61586
61587 /** create a directory */
61588 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
61589diff --git a/include/linux/padata.h b/include/linux/padata.h
61590index 4633b2f..988bc08 100644
61591--- a/include/linux/padata.h
61592+++ b/include/linux/padata.h
61593@@ -129,7 +129,7 @@ struct parallel_data {
61594 struct padata_instance *pinst;
61595 struct padata_parallel_queue __percpu *pqueue;
61596 struct padata_serial_queue __percpu *squeue;
61597- atomic_t seq_nr;
61598+ atomic_unchecked_t seq_nr;
61599 atomic_t reorder_objects;
61600 atomic_t refcnt;
61601 unsigned int max_seq_nr;
61602diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
61603index abb2776..d8b8e15 100644
61604--- a/include/linux/perf_event.h
61605+++ b/include/linux/perf_event.h
61606@@ -750,8 +750,8 @@ struct perf_event {
61607
61608 enum perf_event_active_state state;
61609 unsigned int attach_state;
61610- local64_t count;
61611- atomic64_t child_count;
61612+ local64_t count; /* PaX: fix it one day */
61613+ atomic64_unchecked_t child_count;
61614
61615 /*
61616 * These are the total time in nanoseconds that the event
61617@@ -802,8 +802,8 @@ struct perf_event {
61618 * These accumulate total time (in nanoseconds) that children
61619 * events have been enabled and running, respectively.
61620 */
61621- atomic64_t child_total_time_enabled;
61622- atomic64_t child_total_time_running;
61623+ atomic64_unchecked_t child_total_time_enabled;
61624+ atomic64_unchecked_t child_total_time_running;
61625
61626 /*
61627 * Protect attach/detach and child_list:
61628diff --git a/include/linux/personality.h b/include/linux/personality.h
61629index 8fc7dd1a..c19d89e 100644
61630--- a/include/linux/personality.h
61631+++ b/include/linux/personality.h
61632@@ -44,6 +44,7 @@ enum {
61633 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
61634 ADDR_NO_RANDOMIZE | \
61635 ADDR_COMPAT_LAYOUT | \
61636+ ADDR_LIMIT_3GB | \
61637 MMAP_PAGE_ZERO)
61638
61639 /*
61640diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
61641index 77257c9..51d473a 100644
61642--- a/include/linux/pipe_fs_i.h
61643+++ b/include/linux/pipe_fs_i.h
61644@@ -46,9 +46,9 @@ struct pipe_buffer {
61645 struct pipe_inode_info {
61646 wait_queue_head_t wait;
61647 unsigned int nrbufs, curbuf, buffers;
61648- unsigned int readers;
61649- unsigned int writers;
61650- unsigned int waiting_writers;
61651+ atomic_t readers;
61652+ atomic_t writers;
61653+ atomic_t waiting_writers;
61654 unsigned int r_counter;
61655 unsigned int w_counter;
61656 struct page *tmp_page;
61657diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
61658index 609daae..5392427 100644
61659--- a/include/linux/pm_runtime.h
61660+++ b/include/linux/pm_runtime.h
61661@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
61662
61663 static inline void pm_runtime_mark_last_busy(struct device *dev)
61664 {
61665- ACCESS_ONCE(dev->power.last_busy) = jiffies;
61666+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
61667 }
61668
61669 #else /* !CONFIG_PM_RUNTIME */
61670diff --git a/include/linux/poison.h b/include/linux/poison.h
61671index 2110a81..13a11bb 100644
61672--- a/include/linux/poison.h
61673+++ b/include/linux/poison.h
61674@@ -19,8 +19,8 @@
61675 * under normal circumstances, used to verify that nobody uses
61676 * non-initialized list entries.
61677 */
61678-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
61679-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
61680+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
61681+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
61682
61683 /********** include/linux/timer.h **********/
61684 /*
61685diff --git a/include/linux/preempt.h b/include/linux/preempt.h
61686index 58969b2..ead129b 100644
61687--- a/include/linux/preempt.h
61688+++ b/include/linux/preempt.h
61689@@ -123,7 +123,7 @@ struct preempt_ops {
61690 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
61691 void (*sched_out)(struct preempt_notifier *notifier,
61692 struct task_struct *next);
61693-};
61694+} __no_const;
61695
61696 /**
61697 * preempt_notifier - key for installing preemption notifiers
61698diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
61699index 85c5073..51fac8b 100644
61700--- a/include/linux/proc_fs.h
61701+++ b/include/linux/proc_fs.h
61702@@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
61703 return proc_create_data(name, mode, parent, proc_fops, NULL);
61704 }
61705
61706+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
61707+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
61708+{
61709+#ifdef CONFIG_GRKERNSEC_PROC_USER
61710+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
61711+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61712+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
61713+#else
61714+ return proc_create_data(name, mode, parent, proc_fops, NULL);
61715+#endif
61716+}
61717+
61718 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
61719 umode_t mode, struct proc_dir_entry *base,
61720 read_proc_t *read_proc, void * data)
61721@@ -258,7 +270,7 @@ union proc_op {
61722 int (*proc_show)(struct seq_file *m,
61723 struct pid_namespace *ns, struct pid *pid,
61724 struct task_struct *task);
61725-};
61726+} __no_const;
61727
61728 struct ctl_table_header;
61729 struct ctl_table;
61730diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
61731index c2f1f6a..6fdb196 100644
61732--- a/include/linux/ptrace.h
61733+++ b/include/linux/ptrace.h
61734@@ -199,9 +199,10 @@ static inline void ptrace_event(int event, unsigned long message)
61735 if (unlikely(ptrace_event_enabled(current, event))) {
61736 current->ptrace_message = message;
61737 ptrace_notify((event << 8) | SIGTRAP);
61738- } else if (event == PTRACE_EVENT_EXEC && unlikely(current->ptrace)) {
61739+ } else if (event == PTRACE_EVENT_EXEC) {
61740 /* legacy EXEC report via SIGTRAP */
61741- send_sig(SIGTRAP, current, 0);
61742+ if ((current->ptrace & (PT_PTRACED|PT_SEIZED)) == PT_PTRACED)
61743+ send_sig(SIGTRAP, current, 0);
61744 }
61745 }
61746
61747diff --git a/include/linux/random.h b/include/linux/random.h
61748index 8f74538..02a1012 100644
61749--- a/include/linux/random.h
61750+++ b/include/linux/random.h
61751@@ -69,12 +69,17 @@ void srandom32(u32 seed);
61752
61753 u32 prandom32(struct rnd_state *);
61754
61755+static inline unsigned long pax_get_random_long(void)
61756+{
61757+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
61758+}
61759+
61760 /*
61761 * Handle minimum values for seeds
61762 */
61763 static inline u32 __seed(u32 x, u32 m)
61764 {
61765- return (x < m) ? x + m : x;
61766+ return (x <= m) ? x + m + 1 : x;
61767 }
61768
61769 /**
61770diff --git a/include/linux/reboot.h b/include/linux/reboot.h
61771index e0879a7..a12f962 100644
61772--- a/include/linux/reboot.h
61773+++ b/include/linux/reboot.h
61774@@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
61775 * Architecture-specific implementations of sys_reboot commands.
61776 */
61777
61778-extern void machine_restart(char *cmd);
61779-extern void machine_halt(void);
61780-extern void machine_power_off(void);
61781+extern void machine_restart(char *cmd) __noreturn;
61782+extern void machine_halt(void) __noreturn;
61783+extern void machine_power_off(void) __noreturn;
61784
61785 extern void machine_shutdown(void);
61786 struct pt_regs;
61787@@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
61788 */
61789
61790 extern void kernel_restart_prepare(char *cmd);
61791-extern void kernel_restart(char *cmd);
61792-extern void kernel_halt(void);
61793-extern void kernel_power_off(void);
61794+extern void kernel_restart(char *cmd) __noreturn;
61795+extern void kernel_halt(void) __noreturn;
61796+extern void kernel_power_off(void) __noreturn;
61797
61798 extern int C_A_D; /* for sysctl */
61799 void ctrl_alt_del(void);
61800@@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
61801 * Emergency restart, callable from an interrupt handler.
61802 */
61803
61804-extern void emergency_restart(void);
61805+extern void emergency_restart(void) __noreturn;
61806 #include <asm/emergency-restart.h>
61807
61808 #endif
61809diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
61810index 2213ddc..650212a 100644
61811--- a/include/linux/reiserfs_fs.h
61812+++ b/include/linux/reiserfs_fs.h
61813@@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
61814 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
61815
61816 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
61817-#define get_generation(s) atomic_read (&fs_generation(s))
61818+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
61819 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
61820 #define __fs_changed(gen,s) (gen != get_generation (s))
61821 #define fs_changed(gen,s) \
61822diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
61823index 8c9e85c..1698e9a 100644
61824--- a/include/linux/reiserfs_fs_sb.h
61825+++ b/include/linux/reiserfs_fs_sb.h
61826@@ -386,7 +386,7 @@ struct reiserfs_sb_info {
61827 /* Comment? -Hans */
61828 wait_queue_head_t s_wait;
61829 /* To be obsoleted soon by per buffer seals.. -Hans */
61830- atomic_t s_generation_counter; // increased by one every time the
61831+ atomic_unchecked_t s_generation_counter; // increased by one every time the
61832 // tree gets re-balanced
61833 unsigned long s_properties; /* File system properties. Currently holds
61834 on-disk FS format */
61835diff --git a/include/linux/relay.h b/include/linux/relay.h
61836index a822fd7..62b70f6 100644
61837--- a/include/linux/relay.h
61838+++ b/include/linux/relay.h
61839@@ -159,7 +159,7 @@ struct rchan_callbacks
61840 * The callback should return 0 if successful, negative if not.
61841 */
61842 int (*remove_buf_file)(struct dentry *dentry);
61843-};
61844+} __no_const;
61845
61846 /*
61847 * CONFIG_RELAY kernel API, kernel/relay.c
61848diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
61849index c6c6084..5bf1212 100644
61850--- a/include/linux/rfkill.h
61851+++ b/include/linux/rfkill.h
61852@@ -147,6 +147,7 @@ struct rfkill_ops {
61853 void (*query)(struct rfkill *rfkill, void *data);
61854 int (*set_block)(void *data, bool blocked);
61855 };
61856+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
61857
61858 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
61859 /**
61860diff --git a/include/linux/rio.h b/include/linux/rio.h
61861index 4d50611..c6858a2 100644
61862--- a/include/linux/rio.h
61863+++ b/include/linux/rio.h
61864@@ -315,7 +315,7 @@ struct rio_ops {
61865 int mbox, void *buffer, size_t len);
61866 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
61867 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
61868-};
61869+} __no_const;
61870
61871 #define RIO_RESOURCE_MEM 0x00000100
61872 #define RIO_RESOURCE_DOORBELL 0x00000200
61873diff --git a/include/linux/rmap.h b/include/linux/rmap.h
61874index 1cdd62a..e399f0d 100644
61875--- a/include/linux/rmap.h
61876+++ b/include/linux/rmap.h
61877@@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
61878 void anon_vma_init(void); /* create anon_vma_cachep */
61879 int anon_vma_prepare(struct vm_area_struct *);
61880 void unlink_anon_vmas(struct vm_area_struct *);
61881-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
61882+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
61883 void anon_vma_moveto_tail(struct vm_area_struct *);
61884-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
61885+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
61886 void __anon_vma_link(struct vm_area_struct *);
61887
61888 static inline void anon_vma_merge(struct vm_area_struct *vma,
61889diff --git a/include/linux/sched.h b/include/linux/sched.h
61890index 0657368..765f70f 100644
61891--- a/include/linux/sched.h
61892+++ b/include/linux/sched.h
61893@@ -101,6 +101,7 @@ struct bio_list;
61894 struct fs_struct;
61895 struct perf_event_context;
61896 struct blk_plug;
61897+struct linux_binprm;
61898
61899 /*
61900 * List of flags we want to share for kernel threads,
61901@@ -382,10 +383,13 @@ struct user_namespace;
61902 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
61903
61904 extern int sysctl_max_map_count;
61905+extern unsigned long sysctl_heap_stack_gap;
61906
61907 #include <linux/aio.h>
61908
61909 #ifdef CONFIG_MMU
61910+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
61911+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
61912 extern void arch_pick_mmap_layout(struct mm_struct *mm);
61913 extern unsigned long
61914 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
61915@@ -631,6 +635,17 @@ struct signal_struct {
61916 #ifdef CONFIG_TASKSTATS
61917 struct taskstats *stats;
61918 #endif
61919+
61920+#ifdef CONFIG_GRKERNSEC
61921+ u32 curr_ip;
61922+ u32 saved_ip;
61923+ u32 gr_saddr;
61924+ u32 gr_daddr;
61925+ u16 gr_sport;
61926+ u16 gr_dport;
61927+ u8 used_accept:1;
61928+#endif
61929+
61930 #ifdef CONFIG_AUDIT
61931 unsigned audit_tty;
61932 struct tty_audit_buf *tty_audit_buf;
61933@@ -714,6 +729,11 @@ struct user_struct {
61934 struct key *session_keyring; /* UID's default session keyring */
61935 #endif
61936
61937+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61938+ unsigned int banned;
61939+ unsigned long ban_expires;
61940+#endif
61941+
61942 /* Hash table maintenance information */
61943 struct hlist_node uidhash_node;
61944 uid_t uid;
61945@@ -1354,8 +1374,8 @@ struct task_struct {
61946 struct list_head thread_group;
61947
61948 struct completion *vfork_done; /* for vfork() */
61949- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
61950- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
61951+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
61952+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
61953
61954 cputime_t utime, stime, utimescaled, stimescaled;
61955 cputime_t gtime;
61956@@ -1371,13 +1391,6 @@ struct task_struct {
61957 struct task_cputime cputime_expires;
61958 struct list_head cpu_timers[3];
61959
61960-/* process credentials */
61961- const struct cred __rcu *real_cred; /* objective and real subjective task
61962- * credentials (COW) */
61963- const struct cred __rcu *cred; /* effective (overridable) subjective task
61964- * credentials (COW) */
61965- struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
61966-
61967 char comm[TASK_COMM_LEN]; /* executable name excluding path
61968 - access with [gs]et_task_comm (which lock
61969 it with task_lock())
61970@@ -1394,8 +1407,16 @@ struct task_struct {
61971 #endif
61972 /* CPU-specific state of this task */
61973 struct thread_struct thread;
61974+/* thread_info moved to task_struct */
61975+#ifdef CONFIG_X86
61976+ struct thread_info tinfo;
61977+#endif
61978 /* filesystem information */
61979 struct fs_struct *fs;
61980+
61981+ const struct cred __rcu *cred; /* effective (overridable) subjective task
61982+ * credentials (COW) */
61983+
61984 /* open file information */
61985 struct files_struct *files;
61986 /* namespaces */
61987@@ -1442,6 +1463,11 @@ struct task_struct {
61988 struct rt_mutex_waiter *pi_blocked_on;
61989 #endif
61990
61991+/* process credentials */
61992+ const struct cred __rcu *real_cred; /* objective and real subjective task
61993+ * credentials (COW) */
61994+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
61995+
61996 #ifdef CONFIG_DEBUG_MUTEXES
61997 /* mutex deadlock detection */
61998 struct mutex_waiter *blocked_on;
61999@@ -1558,6 +1584,27 @@ struct task_struct {
62000 unsigned long default_timer_slack_ns;
62001
62002 struct list_head *scm_work_list;
62003+
62004+#ifdef CONFIG_GRKERNSEC
62005+ /* grsecurity */
62006+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62007+ u64 exec_id;
62008+#endif
62009+#ifdef CONFIG_GRKERNSEC_SETXID
62010+ const struct cred *delayed_cred;
62011+#endif
62012+ struct dentry *gr_chroot_dentry;
62013+ struct acl_subject_label *acl;
62014+ struct acl_role_label *role;
62015+ struct file *exec_file;
62016+ u16 acl_role_id;
62017+ /* is this the task that authenticated to the special role */
62018+ u8 acl_sp_role;
62019+ u8 is_writable;
62020+ u8 brute;
62021+ u8 gr_is_chrooted;
62022+#endif
62023+
62024 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
62025 /* Index of current stored address in ret_stack */
62026 int curr_ret_stack;
62027@@ -1592,6 +1639,51 @@ struct task_struct {
62028 #endif
62029 };
62030
62031+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
62032+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
62033+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
62034+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
62035+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
62036+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
62037+
62038+#ifdef CONFIG_PAX_SOFTMODE
62039+extern int pax_softmode;
62040+#endif
62041+
62042+extern int pax_check_flags(unsigned long *);
62043+
62044+/* if tsk != current then task_lock must be held on it */
62045+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62046+static inline unsigned long pax_get_flags(struct task_struct *tsk)
62047+{
62048+ if (likely(tsk->mm))
62049+ return tsk->mm->pax_flags;
62050+ else
62051+ return 0UL;
62052+}
62053+
62054+/* if tsk != current then task_lock must be held on it */
62055+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
62056+{
62057+ if (likely(tsk->mm)) {
62058+ tsk->mm->pax_flags = flags;
62059+ return 0;
62060+ }
62061+ return -EINVAL;
62062+}
62063+#endif
62064+
62065+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
62066+extern void pax_set_initial_flags(struct linux_binprm *bprm);
62067+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
62068+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
62069+#endif
62070+
62071+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
62072+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
62073+extern void pax_report_refcount_overflow(struct pt_regs *regs);
62074+extern __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
62075+
62076 /* Future-safe accessor for struct task_struct's cpus_allowed. */
62077 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
62078
62079@@ -2104,7 +2196,9 @@ void yield(void);
62080 extern struct exec_domain default_exec_domain;
62081
62082 union thread_union {
62083+#ifndef CONFIG_X86
62084 struct thread_info thread_info;
62085+#endif
62086 unsigned long stack[THREAD_SIZE/sizeof(long)];
62087 };
62088
62089@@ -2137,6 +2231,7 @@ extern struct pid_namespace init_pid_ns;
62090 */
62091
62092 extern struct task_struct *find_task_by_vpid(pid_t nr);
62093+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
62094 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
62095 struct pid_namespace *ns);
62096
62097@@ -2280,7 +2375,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
62098 extern void exit_itimers(struct signal_struct *);
62099 extern void flush_itimer_signals(void);
62100
62101-extern void do_group_exit(int);
62102+extern __noreturn void do_group_exit(int);
62103
62104 extern void daemonize(const char *, ...);
62105 extern int allow_signal(int);
62106@@ -2478,13 +2573,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
62107
62108 #endif
62109
62110-static inline int object_is_on_stack(void *obj)
62111+static inline int object_starts_on_stack(void *obj)
62112 {
62113- void *stack = task_stack_page(current);
62114+ const void *stack = task_stack_page(current);
62115
62116 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
62117 }
62118
62119+#ifdef CONFIG_PAX_USERCOPY
62120+extern int object_is_on_stack(const void *obj, unsigned long len);
62121+#endif
62122+
62123 extern void thread_info_cache_init(void);
62124
62125 #ifdef CONFIG_DEBUG_STACK_USAGE
62126diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
62127index 899fbb4..1cb4138 100644
62128--- a/include/linux/screen_info.h
62129+++ b/include/linux/screen_info.h
62130@@ -43,7 +43,8 @@ struct screen_info {
62131 __u16 pages; /* 0x32 */
62132 __u16 vesa_attributes; /* 0x34 */
62133 __u32 capabilities; /* 0x36 */
62134- __u8 _reserved[6]; /* 0x3a */
62135+ __u16 vesapm_size; /* 0x3a */
62136+ __u8 _reserved[4]; /* 0x3c */
62137 } __attribute__((packed));
62138
62139 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
62140diff --git a/include/linux/security.h b/include/linux/security.h
62141index 83c18e8..2d98860 100644
62142--- a/include/linux/security.h
62143+++ b/include/linux/security.h
62144@@ -37,6 +37,7 @@
62145 #include <linux/xfrm.h>
62146 #include <linux/slab.h>
62147 #include <linux/xattr.h>
62148+#include <linux/grsecurity.h>
62149 #include <net/flow.h>
62150
62151 /* Maximum number of letters for an LSM name string */
62152diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
62153index 44f1514..2bbf6c1 100644
62154--- a/include/linux/seq_file.h
62155+++ b/include/linux/seq_file.h
62156@@ -24,6 +24,9 @@ struct seq_file {
62157 struct mutex lock;
62158 const struct seq_operations *op;
62159 int poll_event;
62160+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62161+ u64 exec_id;
62162+#endif
62163 void *private;
62164 };
62165
62166@@ -33,6 +36,7 @@ struct seq_operations {
62167 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
62168 int (*show) (struct seq_file *m, void *v);
62169 };
62170+typedef struct seq_operations __no_const seq_operations_no_const;
62171
62172 #define SEQ_SKIP 1
62173
62174diff --git a/include/linux/shm.h b/include/linux/shm.h
62175index 92808b8..c28cac4 100644
62176--- a/include/linux/shm.h
62177+++ b/include/linux/shm.h
62178@@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
62179
62180 /* The task created the shm object. NULL if the task is dead. */
62181 struct task_struct *shm_creator;
62182+#ifdef CONFIG_GRKERNSEC
62183+ time_t shm_createtime;
62184+ pid_t shm_lapid;
62185+#endif
62186 };
62187
62188 /* shm_mode upper byte flags */
62189diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
62190index ae86ade..2b51468 100644
62191--- a/include/linux/skbuff.h
62192+++ b/include/linux/skbuff.h
62193@@ -654,7 +654,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
62194 */
62195 static inline int skb_queue_empty(const struct sk_buff_head *list)
62196 {
62197- return list->next == (struct sk_buff *)list;
62198+ return list->next == (const struct sk_buff *)list;
62199 }
62200
62201 /**
62202@@ -667,7 +667,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
62203 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
62204 const struct sk_buff *skb)
62205 {
62206- return skb->next == (struct sk_buff *)list;
62207+ return skb->next == (const struct sk_buff *)list;
62208 }
62209
62210 /**
62211@@ -680,7 +680,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
62212 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
62213 const struct sk_buff *skb)
62214 {
62215- return skb->prev == (struct sk_buff *)list;
62216+ return skb->prev == (const struct sk_buff *)list;
62217 }
62218
62219 /**
62220@@ -1545,7 +1545,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
62221 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
62222 */
62223 #ifndef NET_SKB_PAD
62224-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
62225+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
62226 #endif
62227
62228 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
62229diff --git a/include/linux/slab.h b/include/linux/slab.h
62230index 573c809..e84c132 100644
62231--- a/include/linux/slab.h
62232+++ b/include/linux/slab.h
62233@@ -11,12 +11,20 @@
62234
62235 #include <linux/gfp.h>
62236 #include <linux/types.h>
62237+#include <linux/err.h>
62238
62239 /*
62240 * Flags to pass to kmem_cache_create().
62241 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
62242 */
62243 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
62244+
62245+#ifdef CONFIG_PAX_USERCOPY
62246+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
62247+#else
62248+#define SLAB_USERCOPY 0x00000000UL
62249+#endif
62250+
62251 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
62252 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
62253 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
62254@@ -87,10 +95,13 @@
62255 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
62256 * Both make kfree a no-op.
62257 */
62258-#define ZERO_SIZE_PTR ((void *)16)
62259+#define ZERO_SIZE_PTR \
62260+({ \
62261+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
62262+ (void *)(-MAX_ERRNO-1L); \
62263+})
62264
62265-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
62266- (unsigned long)ZERO_SIZE_PTR)
62267+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
62268
62269 /*
62270 * struct kmem_cache related prototypes
62271@@ -161,6 +172,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
62272 void kfree(const void *);
62273 void kzfree(const void *);
62274 size_t ksize(const void *);
62275+void check_object_size(const void *ptr, unsigned long n, bool to);
62276
62277 /*
62278 * Allocator specific definitions. These are mainly used to establish optimized
62279@@ -353,4 +365,59 @@ static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
62280
62281 void __init kmem_cache_init_late(void);
62282
62283+#define kmalloc(x, y) \
62284+({ \
62285+ void *___retval; \
62286+ intoverflow_t ___x = (intoverflow_t)x; \
62287+ if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n")) \
62288+ ___retval = NULL; \
62289+ else \
62290+ ___retval = kmalloc((size_t)___x, (y)); \
62291+ ___retval; \
62292+})
62293+
62294+#define kmalloc_node(x, y, z) \
62295+({ \
62296+ void *___retval; \
62297+ intoverflow_t ___x = (intoverflow_t)x; \
62298+ if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
62299+ ___retval = NULL; \
62300+ else \
62301+ ___retval = kmalloc_node((size_t)___x, (y), (z));\
62302+ ___retval; \
62303+})
62304+
62305+#define kzalloc(x, y) \
62306+({ \
62307+ void *___retval; \
62308+ intoverflow_t ___x = (intoverflow_t)x; \
62309+ if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n")) \
62310+ ___retval = NULL; \
62311+ else \
62312+ ___retval = kzalloc((size_t)___x, (y)); \
62313+ ___retval; \
62314+})
62315+
62316+#define __krealloc(x, y, z) \
62317+({ \
62318+ void *___retval; \
62319+ intoverflow_t ___y = (intoverflow_t)y; \
62320+ if (WARN(___y > ULONG_MAX, "__krealloc size overflow\n"))\
62321+ ___retval = NULL; \
62322+ else \
62323+ ___retval = __krealloc((x), (size_t)___y, (z)); \
62324+ ___retval; \
62325+})
62326+
62327+#define krealloc(x, y, z) \
62328+({ \
62329+ void *___retval; \
62330+ intoverflow_t ___y = (intoverflow_t)y; \
62331+ if (WARN(___y > ULONG_MAX, "krealloc size overflow\n")) \
62332+ ___retval = NULL; \
62333+ else \
62334+ ___retval = krealloc((x), (size_t)___y, (z)); \
62335+ ___retval; \
62336+})
62337+
62338 #endif /* _LINUX_SLAB_H */
62339diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
62340index fbd1117..1e5e46c 100644
62341--- a/include/linux/slab_def.h
62342+++ b/include/linux/slab_def.h
62343@@ -66,10 +66,10 @@ struct kmem_cache {
62344 unsigned long node_allocs;
62345 unsigned long node_frees;
62346 unsigned long node_overflow;
62347- atomic_t allochit;
62348- atomic_t allocmiss;
62349- atomic_t freehit;
62350- atomic_t freemiss;
62351+ atomic_unchecked_t allochit;
62352+ atomic_unchecked_t allocmiss;
62353+ atomic_unchecked_t freehit;
62354+ atomic_unchecked_t freemiss;
62355
62356 /*
62357 * If debugging is enabled, then the allocator can add additional
62358diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
62359index a32bcfd..53b71f4 100644
62360--- a/include/linux/slub_def.h
62361+++ b/include/linux/slub_def.h
62362@@ -89,7 +89,7 @@ struct kmem_cache {
62363 struct kmem_cache_order_objects max;
62364 struct kmem_cache_order_objects min;
62365 gfp_t allocflags; /* gfp flags to use on each alloc */
62366- int refcount; /* Refcount for slab cache destroy */
62367+ atomic_t refcount; /* Refcount for slab cache destroy */
62368 void (*ctor)(void *);
62369 int inuse; /* Offset to metadata */
62370 int align; /* Alignment */
62371@@ -215,7 +215,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
62372 }
62373
62374 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
62375-void *__kmalloc(size_t size, gfp_t flags);
62376+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
62377
62378 static __always_inline void *
62379 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
62380diff --git a/include/linux/sonet.h b/include/linux/sonet.h
62381index de8832d..0147b46 100644
62382--- a/include/linux/sonet.h
62383+++ b/include/linux/sonet.h
62384@@ -61,7 +61,7 @@ struct sonet_stats {
62385 #include <linux/atomic.h>
62386
62387 struct k_sonet_stats {
62388-#define __HANDLE_ITEM(i) atomic_t i
62389+#define __HANDLE_ITEM(i) atomic_unchecked_t i
62390 __SONET_ITEMS
62391 #undef __HANDLE_ITEM
62392 };
62393diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
62394index 2c5993a..b0e79f0 100644
62395--- a/include/linux/sunrpc/clnt.h
62396+++ b/include/linux/sunrpc/clnt.h
62397@@ -172,9 +172,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
62398 {
62399 switch (sap->sa_family) {
62400 case AF_INET:
62401- return ntohs(((struct sockaddr_in *)sap)->sin_port);
62402+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
62403 case AF_INET6:
62404- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
62405+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
62406 }
62407 return 0;
62408 }
62409@@ -207,7 +207,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
62410 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
62411 const struct sockaddr *src)
62412 {
62413- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
62414+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
62415 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
62416
62417 dsin->sin_family = ssin->sin_family;
62418@@ -310,7 +310,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
62419 if (sa->sa_family != AF_INET6)
62420 return 0;
62421
62422- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
62423+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
62424 }
62425
62426 #endif /* __KERNEL__ */
62427diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
62428index e775689..9e206d9 100644
62429--- a/include/linux/sunrpc/sched.h
62430+++ b/include/linux/sunrpc/sched.h
62431@@ -105,6 +105,7 @@ struct rpc_call_ops {
62432 void (*rpc_call_done)(struct rpc_task *, void *);
62433 void (*rpc_release)(void *);
62434 };
62435+typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
62436
62437 struct rpc_task_setup {
62438 struct rpc_task *task;
62439diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
62440index c14fe86..393245e 100644
62441--- a/include/linux/sunrpc/svc_rdma.h
62442+++ b/include/linux/sunrpc/svc_rdma.h
62443@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
62444 extern unsigned int svcrdma_max_requests;
62445 extern unsigned int svcrdma_max_req_size;
62446
62447-extern atomic_t rdma_stat_recv;
62448-extern atomic_t rdma_stat_read;
62449-extern atomic_t rdma_stat_write;
62450-extern atomic_t rdma_stat_sq_starve;
62451-extern atomic_t rdma_stat_rq_starve;
62452-extern atomic_t rdma_stat_rq_poll;
62453-extern atomic_t rdma_stat_rq_prod;
62454-extern atomic_t rdma_stat_sq_poll;
62455-extern atomic_t rdma_stat_sq_prod;
62456+extern atomic_unchecked_t rdma_stat_recv;
62457+extern atomic_unchecked_t rdma_stat_read;
62458+extern atomic_unchecked_t rdma_stat_write;
62459+extern atomic_unchecked_t rdma_stat_sq_starve;
62460+extern atomic_unchecked_t rdma_stat_rq_starve;
62461+extern atomic_unchecked_t rdma_stat_rq_poll;
62462+extern atomic_unchecked_t rdma_stat_rq_prod;
62463+extern atomic_unchecked_t rdma_stat_sq_poll;
62464+extern atomic_unchecked_t rdma_stat_sq_prod;
62465
62466 #define RPCRDMA_VERSION 1
62467
62468diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
62469index bb9127d..34ab358 100644
62470--- a/include/linux/sysctl.h
62471+++ b/include/linux/sysctl.h
62472@@ -155,7 +155,11 @@ enum
62473 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
62474 };
62475
62476-
62477+#ifdef CONFIG_PAX_SOFTMODE
62478+enum {
62479+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
62480+};
62481+#endif
62482
62483 /* CTL_VM names: */
62484 enum
62485@@ -968,6 +972,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
62486
62487 extern int proc_dostring(struct ctl_table *, int,
62488 void __user *, size_t *, loff_t *);
62489+extern int proc_dostring_modpriv(struct ctl_table *, int,
62490+ void __user *, size_t *, loff_t *);
62491 extern int proc_dointvec(struct ctl_table *, int,
62492 void __user *, size_t *, loff_t *);
62493 extern int proc_dointvec_minmax(struct ctl_table *, int,
62494diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
62495index a71a292..51bd91d 100644
62496--- a/include/linux/tracehook.h
62497+++ b/include/linux/tracehook.h
62498@@ -54,12 +54,12 @@ struct linux_binprm;
62499 /*
62500 * ptrace report for syscall entry and exit looks identical.
62501 */
62502-static inline void ptrace_report_syscall(struct pt_regs *regs)
62503+static inline int ptrace_report_syscall(struct pt_regs *regs)
62504 {
62505 int ptrace = current->ptrace;
62506
62507 if (!(ptrace & PT_PTRACED))
62508- return;
62509+ return 0;
62510
62511 ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
62512
62513@@ -72,6 +72,8 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
62514 send_sig(current->exit_code, current, 1);
62515 current->exit_code = 0;
62516 }
62517+
62518+ return fatal_signal_pending(current);
62519 }
62520
62521 /**
62522@@ -96,8 +98,7 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
62523 static inline __must_check int tracehook_report_syscall_entry(
62524 struct pt_regs *regs)
62525 {
62526- ptrace_report_syscall(regs);
62527- return 0;
62528+ return ptrace_report_syscall(regs);
62529 }
62530
62531 /**
62532diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
62533index ff7dc08..893e1bd 100644
62534--- a/include/linux/tty_ldisc.h
62535+++ b/include/linux/tty_ldisc.h
62536@@ -148,7 +148,7 @@ struct tty_ldisc_ops {
62537
62538 struct module *owner;
62539
62540- int refcount;
62541+ atomic_t refcount;
62542 };
62543
62544 struct tty_ldisc {
62545diff --git a/include/linux/types.h b/include/linux/types.h
62546index e5fa503..df6e8a4 100644
62547--- a/include/linux/types.h
62548+++ b/include/linux/types.h
62549@@ -214,10 +214,26 @@ typedef struct {
62550 int counter;
62551 } atomic_t;
62552
62553+#ifdef CONFIG_PAX_REFCOUNT
62554+typedef struct {
62555+ int counter;
62556+} atomic_unchecked_t;
62557+#else
62558+typedef atomic_t atomic_unchecked_t;
62559+#endif
62560+
62561 #ifdef CONFIG_64BIT
62562 typedef struct {
62563 long counter;
62564 } atomic64_t;
62565+
62566+#ifdef CONFIG_PAX_REFCOUNT
62567+typedef struct {
62568+ long counter;
62569+} atomic64_unchecked_t;
62570+#else
62571+typedef atomic64_t atomic64_unchecked_t;
62572+#endif
62573 #endif
62574
62575 struct list_head {
62576diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
62577index 5ca0951..ab496a5 100644
62578--- a/include/linux/uaccess.h
62579+++ b/include/linux/uaccess.h
62580@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
62581 long ret; \
62582 mm_segment_t old_fs = get_fs(); \
62583 \
62584- set_fs(KERNEL_DS); \
62585 pagefault_disable(); \
62586- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
62587- pagefault_enable(); \
62588+ set_fs(KERNEL_DS); \
62589+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
62590 set_fs(old_fs); \
62591+ pagefault_enable(); \
62592 ret; \
62593 })
62594
62595diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
62596index 99c1b4d..bb94261 100644
62597--- a/include/linux/unaligned/access_ok.h
62598+++ b/include/linux/unaligned/access_ok.h
62599@@ -6,32 +6,32 @@
62600
62601 static inline u16 get_unaligned_le16(const void *p)
62602 {
62603- return le16_to_cpup((__le16 *)p);
62604+ return le16_to_cpup((const __le16 *)p);
62605 }
62606
62607 static inline u32 get_unaligned_le32(const void *p)
62608 {
62609- return le32_to_cpup((__le32 *)p);
62610+ return le32_to_cpup((const __le32 *)p);
62611 }
62612
62613 static inline u64 get_unaligned_le64(const void *p)
62614 {
62615- return le64_to_cpup((__le64 *)p);
62616+ return le64_to_cpup((const __le64 *)p);
62617 }
62618
62619 static inline u16 get_unaligned_be16(const void *p)
62620 {
62621- return be16_to_cpup((__be16 *)p);
62622+ return be16_to_cpup((const __be16 *)p);
62623 }
62624
62625 static inline u32 get_unaligned_be32(const void *p)
62626 {
62627- return be32_to_cpup((__be32 *)p);
62628+ return be32_to_cpup((const __be32 *)p);
62629 }
62630
62631 static inline u64 get_unaligned_be64(const void *p)
62632 {
62633- return be64_to_cpup((__be64 *)p);
62634+ return be64_to_cpup((const __be64 *)p);
62635 }
62636
62637 static inline void put_unaligned_le16(u16 val, void *p)
62638diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
62639index 0d3f988..000f101 100644
62640--- a/include/linux/usb/renesas_usbhs.h
62641+++ b/include/linux/usb/renesas_usbhs.h
62642@@ -39,7 +39,7 @@ enum {
62643 */
62644 struct renesas_usbhs_driver_callback {
62645 int (*notify_hotplug)(struct platform_device *pdev);
62646-};
62647+} __no_const;
62648
62649 /*
62650 * callback functions for platform
62651@@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
62652 * VBUS control is needed for Host
62653 */
62654 int (*set_vbus)(struct platform_device *pdev, int enable);
62655-};
62656+} __no_const;
62657
62658 /*
62659 * parameters for renesas usbhs
62660diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
62661index 6f8fbcf..8259001 100644
62662--- a/include/linux/vermagic.h
62663+++ b/include/linux/vermagic.h
62664@@ -25,9 +25,35 @@
62665 #define MODULE_ARCH_VERMAGIC ""
62666 #endif
62667
62668+#ifdef CONFIG_PAX_REFCOUNT
62669+#define MODULE_PAX_REFCOUNT "REFCOUNT "
62670+#else
62671+#define MODULE_PAX_REFCOUNT ""
62672+#endif
62673+
62674+#ifdef CONSTIFY_PLUGIN
62675+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
62676+#else
62677+#define MODULE_CONSTIFY_PLUGIN ""
62678+#endif
62679+
62680+#ifdef STACKLEAK_PLUGIN
62681+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
62682+#else
62683+#define MODULE_STACKLEAK_PLUGIN ""
62684+#endif
62685+
62686+#ifdef CONFIG_GRKERNSEC
62687+#define MODULE_GRSEC "GRSEC "
62688+#else
62689+#define MODULE_GRSEC ""
62690+#endif
62691+
62692 #define VERMAGIC_STRING \
62693 UTS_RELEASE " " \
62694 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
62695 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
62696- MODULE_ARCH_VERMAGIC
62697+ MODULE_ARCH_VERMAGIC \
62698+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
62699+ MODULE_GRSEC
62700
62701diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
62702index dcdfc2b..f937197 100644
62703--- a/include/linux/vmalloc.h
62704+++ b/include/linux/vmalloc.h
62705@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
62706 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
62707 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
62708 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
62709+
62710+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
62711+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
62712+#endif
62713+
62714 /* bits [20..32] reserved for arch specific ioremap internals */
62715
62716 /*
62717@@ -157,4 +162,103 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
62718 # endif
62719 #endif
62720
62721+#define vmalloc(x) \
62722+({ \
62723+ void *___retval; \
62724+ intoverflow_t ___x = (intoverflow_t)x; \
62725+ if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
62726+ ___retval = NULL; \
62727+ else \
62728+ ___retval = vmalloc((unsigned long)___x); \
62729+ ___retval; \
62730+})
62731+
62732+#define vzalloc(x) \
62733+({ \
62734+ void *___retval; \
62735+ intoverflow_t ___x = (intoverflow_t)x; \
62736+ if (WARN(___x > ULONG_MAX, "vzalloc size overflow\n")) \
62737+ ___retval = NULL; \
62738+ else \
62739+ ___retval = vzalloc((unsigned long)___x); \
62740+ ___retval; \
62741+})
62742+
62743+#define __vmalloc(x, y, z) \
62744+({ \
62745+ void *___retval; \
62746+ intoverflow_t ___x = (intoverflow_t)x; \
62747+ if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
62748+ ___retval = NULL; \
62749+ else \
62750+ ___retval = __vmalloc((unsigned long)___x, (y), (z));\
62751+ ___retval; \
62752+})
62753+
62754+#define vmalloc_user(x) \
62755+({ \
62756+ void *___retval; \
62757+ intoverflow_t ___x = (intoverflow_t)x; \
62758+ if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
62759+ ___retval = NULL; \
62760+ else \
62761+ ___retval = vmalloc_user((unsigned long)___x); \
62762+ ___retval; \
62763+})
62764+
62765+#define vmalloc_exec(x) \
62766+({ \
62767+ void *___retval; \
62768+ intoverflow_t ___x = (intoverflow_t)x; \
62769+ if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
62770+ ___retval = NULL; \
62771+ else \
62772+ ___retval = vmalloc_exec((unsigned long)___x); \
62773+ ___retval; \
62774+})
62775+
62776+#define vmalloc_node(x, y) \
62777+({ \
62778+ void *___retval; \
62779+ intoverflow_t ___x = (intoverflow_t)x; \
62780+ if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
62781+ ___retval = NULL; \
62782+ else \
62783+ ___retval = vmalloc_node((unsigned long)___x, (y));\
62784+ ___retval; \
62785+})
62786+
62787+#define vzalloc_node(x, y) \
62788+({ \
62789+ void *___retval; \
62790+ intoverflow_t ___x = (intoverflow_t)x; \
62791+ if (WARN(___x > ULONG_MAX, "vzalloc_node size overflow\n"))\
62792+ ___retval = NULL; \
62793+ else \
62794+ ___retval = vzalloc_node((unsigned long)___x, (y));\
62795+ ___retval; \
62796+})
62797+
62798+#define vmalloc_32(x) \
62799+({ \
62800+ void *___retval; \
62801+ intoverflow_t ___x = (intoverflow_t)x; \
62802+ if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
62803+ ___retval = NULL; \
62804+ else \
62805+ ___retval = vmalloc_32((unsigned long)___x); \
62806+ ___retval; \
62807+})
62808+
62809+#define vmalloc_32_user(x) \
62810+({ \
62811+void *___retval; \
62812+ intoverflow_t ___x = (intoverflow_t)x; \
62813+ if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
62814+ ___retval = NULL; \
62815+ else \
62816+ ___retval = vmalloc_32_user((unsigned long)___x);\
62817+ ___retval; \
62818+})
62819+
62820 #endif /* _LINUX_VMALLOC_H */
62821diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
62822index 65efb92..137adbb 100644
62823--- a/include/linux/vmstat.h
62824+++ b/include/linux/vmstat.h
62825@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
62826 /*
62827 * Zone based page accounting with per cpu differentials.
62828 */
62829-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62830+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62831
62832 static inline void zone_page_state_add(long x, struct zone *zone,
62833 enum zone_stat_item item)
62834 {
62835- atomic_long_add(x, &zone->vm_stat[item]);
62836- atomic_long_add(x, &vm_stat[item]);
62837+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
62838+ atomic_long_add_unchecked(x, &vm_stat[item]);
62839 }
62840
62841 static inline unsigned long global_page_state(enum zone_stat_item item)
62842 {
62843- long x = atomic_long_read(&vm_stat[item]);
62844+ long x = atomic_long_read_unchecked(&vm_stat[item]);
62845 #ifdef CONFIG_SMP
62846 if (x < 0)
62847 x = 0;
62848@@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
62849 static inline unsigned long zone_page_state(struct zone *zone,
62850 enum zone_stat_item item)
62851 {
62852- long x = atomic_long_read(&zone->vm_stat[item]);
62853+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
62854 #ifdef CONFIG_SMP
62855 if (x < 0)
62856 x = 0;
62857@@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
62858 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
62859 enum zone_stat_item item)
62860 {
62861- long x = atomic_long_read(&zone->vm_stat[item]);
62862+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
62863
62864 #ifdef CONFIG_SMP
62865 int cpu;
62866@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
62867
62868 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
62869 {
62870- atomic_long_inc(&zone->vm_stat[item]);
62871- atomic_long_inc(&vm_stat[item]);
62872+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
62873+ atomic_long_inc_unchecked(&vm_stat[item]);
62874 }
62875
62876 static inline void __inc_zone_page_state(struct page *page,
62877@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
62878
62879 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
62880 {
62881- atomic_long_dec(&zone->vm_stat[item]);
62882- atomic_long_dec(&vm_stat[item]);
62883+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
62884+ atomic_long_dec_unchecked(&vm_stat[item]);
62885 }
62886
62887 static inline void __dec_zone_page_state(struct page *page,
62888diff --git a/include/linux/xattr.h b/include/linux/xattr.h
62889index e5d1220..ef6e406 100644
62890--- a/include/linux/xattr.h
62891+++ b/include/linux/xattr.h
62892@@ -57,6 +57,11 @@
62893 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
62894 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
62895
62896+/* User namespace */
62897+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
62898+#define XATTR_PAX_FLAGS_SUFFIX "flags"
62899+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
62900+
62901 #ifdef __KERNEL__
62902
62903 #include <linux/types.h>
62904diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
62905index 4aeff96..b378cdc 100644
62906--- a/include/media/saa7146_vv.h
62907+++ b/include/media/saa7146_vv.h
62908@@ -163,7 +163,7 @@ struct saa7146_ext_vv
62909 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
62910
62911 /* the extension can override this */
62912- struct v4l2_ioctl_ops ops;
62913+ v4l2_ioctl_ops_no_const ops;
62914 /* pointer to the saa7146 core ops */
62915 const struct v4l2_ioctl_ops *core_ops;
62916
62917diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
62918index c7c40f1..4f01585 100644
62919--- a/include/media/v4l2-dev.h
62920+++ b/include/media/v4l2-dev.h
62921@@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
62922
62923
62924 struct v4l2_file_operations {
62925- struct module *owner;
62926+ struct module * const owner;
62927 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
62928 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
62929 unsigned int (*poll) (struct file *, struct poll_table_struct *);
62930@@ -68,6 +68,7 @@ struct v4l2_file_operations {
62931 int (*open) (struct file *);
62932 int (*release) (struct file *);
62933 };
62934+typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
62935
62936 /*
62937 * Newer version of video_device, handled by videodev2.c
62938diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
62939index 3f5d60f..44210ed 100644
62940--- a/include/media/v4l2-ioctl.h
62941+++ b/include/media/v4l2-ioctl.h
62942@@ -278,7 +278,7 @@ struct v4l2_ioctl_ops {
62943 long (*vidioc_default) (struct file *file, void *fh,
62944 bool valid_prio, int cmd, void *arg);
62945 };
62946-
62947+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
62948
62949 /* v4l debugging and diagnostics */
62950
62951diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
62952index 8d55251..dfe5b0a 100644
62953--- a/include/net/caif/caif_hsi.h
62954+++ b/include/net/caif/caif_hsi.h
62955@@ -98,7 +98,7 @@ struct cfhsi_drv {
62956 void (*rx_done_cb) (struct cfhsi_drv *drv);
62957 void (*wake_up_cb) (struct cfhsi_drv *drv);
62958 void (*wake_down_cb) (struct cfhsi_drv *drv);
62959-};
62960+} __no_const;
62961
62962 /* Structure implemented by HSI device. */
62963 struct cfhsi_dev {
62964diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
62965index 9e5425b..8136ffc 100644
62966--- a/include/net/caif/cfctrl.h
62967+++ b/include/net/caif/cfctrl.h
62968@@ -52,7 +52,7 @@ struct cfctrl_rsp {
62969 void (*radioset_rsp)(void);
62970 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
62971 struct cflayer *client_layer);
62972-};
62973+} __no_const;
62974
62975 /* Link Setup Parameters for CAIF-Links. */
62976 struct cfctrl_link_param {
62977@@ -101,8 +101,8 @@ struct cfctrl_request_info {
62978 struct cfctrl {
62979 struct cfsrvl serv;
62980 struct cfctrl_rsp res;
62981- atomic_t req_seq_no;
62982- atomic_t rsp_seq_no;
62983+ atomic_unchecked_t req_seq_no;
62984+ atomic_unchecked_t rsp_seq_no;
62985 struct list_head list;
62986 /* Protects from simultaneous access to first_req list */
62987 spinlock_t info_list_lock;
62988diff --git a/include/net/flow.h b/include/net/flow.h
62989index 6c469db..7743b8e 100644
62990--- a/include/net/flow.h
62991+++ b/include/net/flow.h
62992@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
62993
62994 extern void flow_cache_flush(void);
62995 extern void flow_cache_flush_deferred(void);
62996-extern atomic_t flow_cache_genid;
62997+extern atomic_unchecked_t flow_cache_genid;
62998
62999 #endif
63000diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
63001index b94765e..053f68b 100644
63002--- a/include/net/inetpeer.h
63003+++ b/include/net/inetpeer.h
63004@@ -48,8 +48,8 @@ struct inet_peer {
63005 */
63006 union {
63007 struct {
63008- atomic_t rid; /* Frag reception counter */
63009- atomic_t ip_id_count; /* IP ID for the next packet */
63010+ atomic_unchecked_t rid; /* Frag reception counter */
63011+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
63012 __u32 tcp_ts;
63013 __u32 tcp_ts_stamp;
63014 };
63015@@ -115,11 +115,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
63016 more++;
63017 inet_peer_refcheck(p);
63018 do {
63019- old = atomic_read(&p->ip_id_count);
63020+ old = atomic_read_unchecked(&p->ip_id_count);
63021 new = old + more;
63022 if (!new)
63023 new = 1;
63024- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
63025+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
63026 return new;
63027 }
63028
63029diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
63030index 10422ef..662570f 100644
63031--- a/include/net/ip_fib.h
63032+++ b/include/net/ip_fib.h
63033@@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
63034
63035 #define FIB_RES_SADDR(net, res) \
63036 ((FIB_RES_NH(res).nh_saddr_genid == \
63037- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
63038+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
63039 FIB_RES_NH(res).nh_saddr : \
63040 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
63041 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
63042diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
63043index ebe517f..1bd286b 100644
63044--- a/include/net/ip_vs.h
63045+++ b/include/net/ip_vs.h
63046@@ -509,7 +509,7 @@ struct ip_vs_conn {
63047 struct ip_vs_conn *control; /* Master control connection */
63048 atomic_t n_control; /* Number of controlled ones */
63049 struct ip_vs_dest *dest; /* real server */
63050- atomic_t in_pkts; /* incoming packet counter */
63051+ atomic_unchecked_t in_pkts; /* incoming packet counter */
63052
63053 /* packet transmitter for different forwarding methods. If it
63054 mangles the packet, it must return NF_DROP or better NF_STOLEN,
63055@@ -647,7 +647,7 @@ struct ip_vs_dest {
63056 __be16 port; /* port number of the server */
63057 union nf_inet_addr addr; /* IP address of the server */
63058 volatile unsigned flags; /* dest status flags */
63059- atomic_t conn_flags; /* flags to copy to conn */
63060+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
63061 atomic_t weight; /* server weight */
63062
63063 atomic_t refcnt; /* reference counter */
63064diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
63065index 69b610a..fe3962c 100644
63066--- a/include/net/irda/ircomm_core.h
63067+++ b/include/net/irda/ircomm_core.h
63068@@ -51,7 +51,7 @@ typedef struct {
63069 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
63070 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
63071 struct ircomm_info *);
63072-} call_t;
63073+} __no_const call_t;
63074
63075 struct ircomm_cb {
63076 irda_queue_t queue;
63077diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
63078index 59ba38bc..d515662 100644
63079--- a/include/net/irda/ircomm_tty.h
63080+++ b/include/net/irda/ircomm_tty.h
63081@@ -35,6 +35,7 @@
63082 #include <linux/termios.h>
63083 #include <linux/timer.h>
63084 #include <linux/tty.h> /* struct tty_struct */
63085+#include <asm/local.h>
63086
63087 #include <net/irda/irias_object.h>
63088 #include <net/irda/ircomm_core.h>
63089@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
63090 unsigned short close_delay;
63091 unsigned short closing_wait; /* time to wait before closing */
63092
63093- int open_count;
63094- int blocked_open; /* # of blocked opens */
63095+ local_t open_count;
63096+ local_t blocked_open; /* # of blocked opens */
63097
63098 /* Protect concurent access to :
63099 * o self->open_count
63100diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
63101index 0954ec9..7413562 100644
63102--- a/include/net/iucv/af_iucv.h
63103+++ b/include/net/iucv/af_iucv.h
63104@@ -138,7 +138,7 @@ struct iucv_sock {
63105 struct iucv_sock_list {
63106 struct hlist_head head;
63107 rwlock_t lock;
63108- atomic_t autobind_name;
63109+ atomic_unchecked_t autobind_name;
63110 };
63111
63112 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
63113diff --git a/include/net/neighbour.h b/include/net/neighbour.h
63114index 34c996f..bb3b4d4 100644
63115--- a/include/net/neighbour.h
63116+++ b/include/net/neighbour.h
63117@@ -123,7 +123,7 @@ struct neigh_ops {
63118 void (*error_report)(struct neighbour *, struct sk_buff *);
63119 int (*output)(struct neighbour *, struct sk_buff *);
63120 int (*connected_output)(struct neighbour *, struct sk_buff *);
63121-};
63122+} __do_const;
63123
63124 struct pneigh_entry {
63125 struct pneigh_entry *next;
63126diff --git a/include/net/netlink.h b/include/net/netlink.h
63127index cb1f350..3279d2c 100644
63128--- a/include/net/netlink.h
63129+++ b/include/net/netlink.h
63130@@ -569,7 +569,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
63131 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
63132 {
63133 if (mark)
63134- skb_trim(skb, (unsigned char *) mark - skb->data);
63135+ skb_trim(skb, (const unsigned char *) mark - skb->data);
63136 }
63137
63138 /**
63139diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
63140index bbd023a..97c6d0d 100644
63141--- a/include/net/netns/ipv4.h
63142+++ b/include/net/netns/ipv4.h
63143@@ -57,8 +57,8 @@ struct netns_ipv4 {
63144 unsigned int sysctl_ping_group_range[2];
63145 long sysctl_tcp_mem[3];
63146
63147- atomic_t rt_genid;
63148- atomic_t dev_addr_genid;
63149+ atomic_unchecked_t rt_genid;
63150+ atomic_unchecked_t dev_addr_genid;
63151
63152 #ifdef CONFIG_IP_MROUTE
63153 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
63154diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
63155index d368561..96aaa17 100644
63156--- a/include/net/sctp/sctp.h
63157+++ b/include/net/sctp/sctp.h
63158@@ -318,9 +318,9 @@ do { \
63159
63160 #else /* SCTP_DEBUG */
63161
63162-#define SCTP_DEBUG_PRINTK(whatever...)
63163-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
63164-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
63165+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
63166+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
63167+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
63168 #define SCTP_ENABLE_DEBUG
63169 #define SCTP_DISABLE_DEBUG
63170 #define SCTP_ASSERT(expr, str, func)
63171diff --git a/include/net/sock.h b/include/net/sock.h
63172index 91c1c8b..15ae923 100644
63173--- a/include/net/sock.h
63174+++ b/include/net/sock.h
63175@@ -299,7 +299,7 @@ struct sock {
63176 #ifdef CONFIG_RPS
63177 __u32 sk_rxhash;
63178 #endif
63179- atomic_t sk_drops;
63180+ atomic_unchecked_t sk_drops;
63181 int sk_rcvbuf;
63182
63183 struct sk_filter __rcu *sk_filter;
63184@@ -1660,7 +1660,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
63185 }
63186
63187 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
63188- char __user *from, char *to,
63189+ char __user *from, unsigned char *to,
63190 int copy, int offset)
63191 {
63192 if (skb->ip_summed == CHECKSUM_NONE) {
63193diff --git a/include/net/tcp.h b/include/net/tcp.h
63194index 2d80c29..aa07caf 100644
63195--- a/include/net/tcp.h
63196+++ b/include/net/tcp.h
63197@@ -1426,7 +1426,7 @@ struct tcp_seq_afinfo {
63198 char *name;
63199 sa_family_t family;
63200 const struct file_operations *seq_fops;
63201- struct seq_operations seq_ops;
63202+ seq_operations_no_const seq_ops;
63203 };
63204
63205 struct tcp_iter_state {
63206diff --git a/include/net/udp.h b/include/net/udp.h
63207index e39592f..fef9680 100644
63208--- a/include/net/udp.h
63209+++ b/include/net/udp.h
63210@@ -243,7 +243,7 @@ struct udp_seq_afinfo {
63211 sa_family_t family;
63212 struct udp_table *udp_table;
63213 const struct file_operations *seq_fops;
63214- struct seq_operations seq_ops;
63215+ seq_operations_no_const seq_ops;
63216 };
63217
63218 struct udp_iter_state {
63219diff --git a/include/net/xfrm.h b/include/net/xfrm.h
63220index 89174e2..1f82598 100644
63221--- a/include/net/xfrm.h
63222+++ b/include/net/xfrm.h
63223@@ -505,7 +505,7 @@ struct xfrm_policy {
63224 struct timer_list timer;
63225
63226 struct flow_cache_object flo;
63227- atomic_t genid;
63228+ atomic_unchecked_t genid;
63229 u32 priority;
63230 u32 index;
63231 struct xfrm_mark mark;
63232diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
63233index 1a046b1..ee0bef0 100644
63234--- a/include/rdma/iw_cm.h
63235+++ b/include/rdma/iw_cm.h
63236@@ -122,7 +122,7 @@ struct iw_cm_verbs {
63237 int backlog);
63238
63239 int (*destroy_listen)(struct iw_cm_id *cm_id);
63240-};
63241+} __no_const;
63242
63243 /**
63244 * iw_create_cm_id - Create an IW CM identifier.
63245diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
63246index 6a3922f..0b73022 100644
63247--- a/include/scsi/libfc.h
63248+++ b/include/scsi/libfc.h
63249@@ -748,6 +748,7 @@ struct libfc_function_template {
63250 */
63251 void (*disc_stop_final) (struct fc_lport *);
63252 };
63253+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
63254
63255 /**
63256 * struct fc_disc - Discovery context
63257@@ -851,7 +852,7 @@ struct fc_lport {
63258 struct fc_vport *vport;
63259
63260 /* Operational Information */
63261- struct libfc_function_template tt;
63262+ libfc_function_template_no_const tt;
63263 u8 link_up;
63264 u8 qfull;
63265 enum fc_lport_state state;
63266diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
63267index 77273f2..dd4031f 100644
63268--- a/include/scsi/scsi_device.h
63269+++ b/include/scsi/scsi_device.h
63270@@ -161,9 +161,9 @@ struct scsi_device {
63271 unsigned int max_device_blocked; /* what device_blocked counts down from */
63272 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
63273
63274- atomic_t iorequest_cnt;
63275- atomic_t iodone_cnt;
63276- atomic_t ioerr_cnt;
63277+ atomic_unchecked_t iorequest_cnt;
63278+ atomic_unchecked_t iodone_cnt;
63279+ atomic_unchecked_t ioerr_cnt;
63280
63281 struct device sdev_gendev,
63282 sdev_dev;
63283diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
63284index 2a65167..91e01f8 100644
63285--- a/include/scsi/scsi_transport_fc.h
63286+++ b/include/scsi/scsi_transport_fc.h
63287@@ -711,7 +711,7 @@ struct fc_function_template {
63288 unsigned long show_host_system_hostname:1;
63289
63290 unsigned long disable_target_scan:1;
63291-};
63292+} __do_const;
63293
63294
63295 /**
63296diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
63297index 030b87c..98a6954 100644
63298--- a/include/sound/ak4xxx-adda.h
63299+++ b/include/sound/ak4xxx-adda.h
63300@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
63301 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
63302 unsigned char val);
63303 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
63304-};
63305+} __no_const;
63306
63307 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
63308
63309diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
63310index 8c05e47..2b5df97 100644
63311--- a/include/sound/hwdep.h
63312+++ b/include/sound/hwdep.h
63313@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
63314 struct snd_hwdep_dsp_status *status);
63315 int (*dsp_load)(struct snd_hwdep *hw,
63316 struct snd_hwdep_dsp_image *image);
63317-};
63318+} __no_const;
63319
63320 struct snd_hwdep {
63321 struct snd_card *card;
63322diff --git a/include/sound/info.h b/include/sound/info.h
63323index 9ca1a49..aba1728 100644
63324--- a/include/sound/info.h
63325+++ b/include/sound/info.h
63326@@ -44,7 +44,7 @@ struct snd_info_entry_text {
63327 struct snd_info_buffer *buffer);
63328 void (*write)(struct snd_info_entry *entry,
63329 struct snd_info_buffer *buffer);
63330-};
63331+} __no_const;
63332
63333 struct snd_info_entry_ops {
63334 int (*open)(struct snd_info_entry *entry,
63335diff --git a/include/sound/pcm.h b/include/sound/pcm.h
63336index 0cf91b2..b70cae4 100644
63337--- a/include/sound/pcm.h
63338+++ b/include/sound/pcm.h
63339@@ -81,6 +81,7 @@ struct snd_pcm_ops {
63340 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
63341 int (*ack)(struct snd_pcm_substream *substream);
63342 };
63343+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
63344
63345 /*
63346 *
63347diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
63348index af1b49e..a5d55a5 100644
63349--- a/include/sound/sb16_csp.h
63350+++ b/include/sound/sb16_csp.h
63351@@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
63352 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
63353 int (*csp_stop) (struct snd_sb_csp * p);
63354 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
63355-};
63356+} __no_const;
63357
63358 /*
63359 * CSP private data
63360diff --git a/include/sound/soc.h b/include/sound/soc.h
63361index 0992dff..bb366fe 100644
63362--- a/include/sound/soc.h
63363+++ b/include/sound/soc.h
63364@@ -682,7 +682,7 @@ struct snd_soc_platform_driver {
63365 /* platform IO - used for platform DAPM */
63366 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
63367 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
63368-};
63369+} __do_const;
63370
63371 struct snd_soc_platform {
63372 const char *name;
63373@@ -852,7 +852,7 @@ struct snd_soc_pcm_runtime {
63374 struct snd_soc_dai_link *dai_link;
63375 struct mutex pcm_mutex;
63376 enum snd_soc_pcm_subclass pcm_subclass;
63377- struct snd_pcm_ops ops;
63378+ snd_pcm_ops_no_const ops;
63379
63380 unsigned int complete:1;
63381 unsigned int dev_registered:1;
63382diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
63383index 444cd6b..3327cc5 100644
63384--- a/include/sound/ymfpci.h
63385+++ b/include/sound/ymfpci.h
63386@@ -358,7 +358,7 @@ struct snd_ymfpci {
63387 spinlock_t reg_lock;
63388 spinlock_t voice_lock;
63389 wait_queue_head_t interrupt_sleep;
63390- atomic_t interrupt_sleep_count;
63391+ atomic_unchecked_t interrupt_sleep_count;
63392 struct snd_info_entry *proc_entry;
63393 const struct firmware *dsp_microcode;
63394 const struct firmware *controller_microcode;
63395diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
63396index fe73eb8..56388b1 100644
63397--- a/include/target/target_core_base.h
63398+++ b/include/target/target_core_base.h
63399@@ -443,7 +443,7 @@ struct t10_reservation_ops {
63400 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
63401 int (*t10_pr_register)(struct se_cmd *);
63402 int (*t10_pr_clear)(struct se_cmd *);
63403-};
63404+} __no_const;
63405
63406 struct t10_reservation {
63407 /* Reservation effects all target ports */
63408@@ -561,8 +561,8 @@ struct se_cmd {
63409 atomic_t t_se_count;
63410 atomic_t t_task_cdbs_left;
63411 atomic_t t_task_cdbs_ex_left;
63412- atomic_t t_task_cdbs_sent;
63413- atomic_t t_transport_aborted;
63414+ atomic_unchecked_t t_task_cdbs_sent;
63415+ atomic_unchecked_t t_transport_aborted;
63416 atomic_t t_transport_active;
63417 atomic_t t_transport_complete;
63418 atomic_t t_transport_queue_active;
63419@@ -799,7 +799,7 @@ struct se_device {
63420 spinlock_t stats_lock;
63421 /* Active commands on this virtual SE device */
63422 atomic_t simple_cmds;
63423- atomic_t dev_ordered_id;
63424+ atomic_unchecked_t dev_ordered_id;
63425 atomic_t execute_tasks;
63426 atomic_t dev_ordered_sync;
63427 atomic_t dev_qf_count;
63428diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
63429index 1c09820..7f5ec79 100644
63430--- a/include/trace/events/irq.h
63431+++ b/include/trace/events/irq.h
63432@@ -36,7 +36,7 @@ struct softirq_action;
63433 */
63434 TRACE_EVENT(irq_handler_entry,
63435
63436- TP_PROTO(int irq, struct irqaction *action),
63437+ TP_PROTO(int irq, const struct irqaction *action),
63438
63439 TP_ARGS(irq, action),
63440
63441@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
63442 */
63443 TRACE_EVENT(irq_handler_exit,
63444
63445- TP_PROTO(int irq, struct irqaction *action, int ret),
63446+ TP_PROTO(int irq, const struct irqaction *action, int ret),
63447
63448 TP_ARGS(irq, action, ret),
63449
63450diff --git a/include/video/udlfb.h b/include/video/udlfb.h
63451index c41f308..6918de3 100644
63452--- a/include/video/udlfb.h
63453+++ b/include/video/udlfb.h
63454@@ -52,10 +52,10 @@ struct dlfb_data {
63455 u32 pseudo_palette[256];
63456 int blank_mode; /*one of FB_BLANK_ */
63457 /* blit-only rendering path metrics, exposed through sysfs */
63458- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
63459- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
63460- atomic_t bytes_sent; /* to usb, after compression including overhead */
63461- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
63462+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
63463+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
63464+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
63465+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
63466 };
63467
63468 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
63469diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
63470index 0993a22..32ba2fe 100644
63471--- a/include/video/uvesafb.h
63472+++ b/include/video/uvesafb.h
63473@@ -177,6 +177,7 @@ struct uvesafb_par {
63474 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
63475 u8 pmi_setpal; /* PMI for palette changes */
63476 u16 *pmi_base; /* protected mode interface location */
63477+ u8 *pmi_code; /* protected mode code location */
63478 void *pmi_start;
63479 void *pmi_pal;
63480 u8 *vbe_state_orig; /*
63481diff --git a/init/Kconfig b/init/Kconfig
63482index 3f42cd6..613f41d 100644
63483--- a/init/Kconfig
63484+++ b/init/Kconfig
63485@@ -799,6 +799,7 @@ endif # CGROUPS
63486
63487 config CHECKPOINT_RESTORE
63488 bool "Checkpoint/restore support" if EXPERT
63489+ depends on !GRKERNSEC
63490 default n
63491 help
63492 Enables additional kernel features in a sake of checkpoint/restore.
63493@@ -1249,7 +1250,7 @@ config SLUB_DEBUG
63494
63495 config COMPAT_BRK
63496 bool "Disable heap randomization"
63497- default y
63498+ default n
63499 help
63500 Randomizing heap placement makes heap exploits harder, but it
63501 also breaks ancient binaries (including anything libc5 based).
63502diff --git a/init/do_mounts.c b/init/do_mounts.c
63503index 2974c8b..0b863ae 100644
63504--- a/init/do_mounts.c
63505+++ b/init/do_mounts.c
63506@@ -326,11 +326,11 @@ static void __init get_fs_names(char *page)
63507 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
63508 {
63509 struct super_block *s;
63510- int err = sys_mount(name, "/root", fs, flags, data);
63511+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
63512 if (err)
63513 return err;
63514
63515- sys_chdir((const char __user __force *)"/root");
63516+ sys_chdir((const char __force_user *)"/root");
63517 s = current->fs->pwd.dentry->d_sb;
63518 ROOT_DEV = s->s_dev;
63519 printk(KERN_INFO
63520@@ -450,18 +450,18 @@ void __init change_floppy(char *fmt, ...)
63521 va_start(args, fmt);
63522 vsprintf(buf, fmt, args);
63523 va_end(args);
63524- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
63525+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
63526 if (fd >= 0) {
63527 sys_ioctl(fd, FDEJECT, 0);
63528 sys_close(fd);
63529 }
63530 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
63531- fd = sys_open("/dev/console", O_RDWR, 0);
63532+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
63533 if (fd >= 0) {
63534 sys_ioctl(fd, TCGETS, (long)&termios);
63535 termios.c_lflag &= ~ICANON;
63536 sys_ioctl(fd, TCSETSF, (long)&termios);
63537- sys_read(fd, &c, 1);
63538+ sys_read(fd, (char __user *)&c, 1);
63539 termios.c_lflag |= ICANON;
63540 sys_ioctl(fd, TCSETSF, (long)&termios);
63541 sys_close(fd);
63542@@ -555,6 +555,6 @@ void __init prepare_namespace(void)
63543 mount_root();
63544 out:
63545 devtmpfs_mount("dev");
63546- sys_mount(".", "/", NULL, MS_MOVE, NULL);
63547- sys_chroot((const char __user __force *)".");
63548+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
63549+ sys_chroot((const char __force_user *)".");
63550 }
63551diff --git a/init/do_mounts.h b/init/do_mounts.h
63552index f5b978a..69dbfe8 100644
63553--- a/init/do_mounts.h
63554+++ b/init/do_mounts.h
63555@@ -15,15 +15,15 @@ extern int root_mountflags;
63556
63557 static inline int create_dev(char *name, dev_t dev)
63558 {
63559- sys_unlink(name);
63560- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
63561+ sys_unlink((char __force_user *)name);
63562+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
63563 }
63564
63565 #if BITS_PER_LONG == 32
63566 static inline u32 bstat(char *name)
63567 {
63568 struct stat64 stat;
63569- if (sys_stat64(name, &stat) != 0)
63570+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
63571 return 0;
63572 if (!S_ISBLK(stat.st_mode))
63573 return 0;
63574@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
63575 static inline u32 bstat(char *name)
63576 {
63577 struct stat stat;
63578- if (sys_newstat(name, &stat) != 0)
63579+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
63580 return 0;
63581 if (!S_ISBLK(stat.st_mode))
63582 return 0;
63583diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
63584index 3098a38..253064e 100644
63585--- a/init/do_mounts_initrd.c
63586+++ b/init/do_mounts_initrd.c
63587@@ -44,13 +44,13 @@ static void __init handle_initrd(void)
63588 create_dev("/dev/root.old", Root_RAM0);
63589 /* mount initrd on rootfs' /root */
63590 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
63591- sys_mkdir("/old", 0700);
63592- root_fd = sys_open("/", 0, 0);
63593- old_fd = sys_open("/old", 0, 0);
63594+ sys_mkdir((const char __force_user *)"/old", 0700);
63595+ root_fd = sys_open((const char __force_user *)"/", 0, 0);
63596+ old_fd = sys_open((const char __force_user *)"/old", 0, 0);
63597 /* move initrd over / and chdir/chroot in initrd root */
63598- sys_chdir("/root");
63599- sys_mount(".", "/", NULL, MS_MOVE, NULL);
63600- sys_chroot(".");
63601+ sys_chdir((const char __force_user *)"/root");
63602+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
63603+ sys_chroot((const char __force_user *)".");
63604
63605 /*
63606 * In case that a resume from disk is carried out by linuxrc or one of
63607@@ -67,15 +67,15 @@ static void __init handle_initrd(void)
63608
63609 /* move initrd to rootfs' /old */
63610 sys_fchdir(old_fd);
63611- sys_mount("/", ".", NULL, MS_MOVE, NULL);
63612+ sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
63613 /* switch root and cwd back to / of rootfs */
63614 sys_fchdir(root_fd);
63615- sys_chroot(".");
63616+ sys_chroot((const char __force_user *)".");
63617 sys_close(old_fd);
63618 sys_close(root_fd);
63619
63620 if (new_decode_dev(real_root_dev) == Root_RAM0) {
63621- sys_chdir("/old");
63622+ sys_chdir((const char __force_user *)"/old");
63623 return;
63624 }
63625
63626@@ -83,17 +83,17 @@ static void __init handle_initrd(void)
63627 mount_root();
63628
63629 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
63630- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
63631+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
63632 if (!error)
63633 printk("okay\n");
63634 else {
63635- int fd = sys_open("/dev/root.old", O_RDWR, 0);
63636+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
63637 if (error == -ENOENT)
63638 printk("/initrd does not exist. Ignored.\n");
63639 else
63640 printk("failed\n");
63641 printk(KERN_NOTICE "Unmounting old root\n");
63642- sys_umount("/old", MNT_DETACH);
63643+ sys_umount((char __force_user *)"/old", MNT_DETACH);
63644 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
63645 if (fd < 0) {
63646 error = fd;
63647@@ -116,11 +116,11 @@ int __init initrd_load(void)
63648 * mounted in the normal path.
63649 */
63650 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
63651- sys_unlink("/initrd.image");
63652+ sys_unlink((const char __force_user *)"/initrd.image");
63653 handle_initrd();
63654 return 1;
63655 }
63656 }
63657- sys_unlink("/initrd.image");
63658+ sys_unlink((const char __force_user *)"/initrd.image");
63659 return 0;
63660 }
63661diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
63662index 32c4799..c27ee74 100644
63663--- a/init/do_mounts_md.c
63664+++ b/init/do_mounts_md.c
63665@@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
63666 partitioned ? "_d" : "", minor,
63667 md_setup_args[ent].device_names);
63668
63669- fd = sys_open(name, 0, 0);
63670+ fd = sys_open((char __force_user *)name, 0, 0);
63671 if (fd < 0) {
63672 printk(KERN_ERR "md: open failed - cannot start "
63673 "array %s\n", name);
63674@@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
63675 * array without it
63676 */
63677 sys_close(fd);
63678- fd = sys_open(name, 0, 0);
63679+ fd = sys_open((char __force_user *)name, 0, 0);
63680 sys_ioctl(fd, BLKRRPART, 0);
63681 }
63682 sys_close(fd);
63683@@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
63684
63685 wait_for_device_probe();
63686
63687- fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
63688+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
63689 if (fd >= 0) {
63690 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
63691 sys_close(fd);
63692diff --git a/init/initramfs.c b/init/initramfs.c
63693index 8216c30..25e8e32 100644
63694--- a/init/initramfs.c
63695+++ b/init/initramfs.c
63696@@ -74,7 +74,7 @@ static void __init free_hash(void)
63697 }
63698 }
63699
63700-static long __init do_utime(char __user *filename, time_t mtime)
63701+static long __init do_utime(__force char __user *filename, time_t mtime)
63702 {
63703 struct timespec t[2];
63704
63705@@ -109,7 +109,7 @@ static void __init dir_utime(void)
63706 struct dir_entry *de, *tmp;
63707 list_for_each_entry_safe(de, tmp, &dir_list, list) {
63708 list_del(&de->list);
63709- do_utime(de->name, de->mtime);
63710+ do_utime((char __force_user *)de->name, de->mtime);
63711 kfree(de->name);
63712 kfree(de);
63713 }
63714@@ -271,7 +271,7 @@ static int __init maybe_link(void)
63715 if (nlink >= 2) {
63716 char *old = find_link(major, minor, ino, mode, collected);
63717 if (old)
63718- return (sys_link(old, collected) < 0) ? -1 : 1;
63719+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
63720 }
63721 return 0;
63722 }
63723@@ -280,11 +280,11 @@ static void __init clean_path(char *path, umode_t mode)
63724 {
63725 struct stat st;
63726
63727- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
63728+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
63729 if (S_ISDIR(st.st_mode))
63730- sys_rmdir(path);
63731+ sys_rmdir((char __force_user *)path);
63732 else
63733- sys_unlink(path);
63734+ sys_unlink((char __force_user *)path);
63735 }
63736 }
63737
63738@@ -305,7 +305,7 @@ static int __init do_name(void)
63739 int openflags = O_WRONLY|O_CREAT;
63740 if (ml != 1)
63741 openflags |= O_TRUNC;
63742- wfd = sys_open(collected, openflags, mode);
63743+ wfd = sys_open((char __force_user *)collected, openflags, mode);
63744
63745 if (wfd >= 0) {
63746 sys_fchown(wfd, uid, gid);
63747@@ -317,17 +317,17 @@ static int __init do_name(void)
63748 }
63749 }
63750 } else if (S_ISDIR(mode)) {
63751- sys_mkdir(collected, mode);
63752- sys_chown(collected, uid, gid);
63753- sys_chmod(collected, mode);
63754+ sys_mkdir((char __force_user *)collected, mode);
63755+ sys_chown((char __force_user *)collected, uid, gid);
63756+ sys_chmod((char __force_user *)collected, mode);
63757 dir_add(collected, mtime);
63758 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
63759 S_ISFIFO(mode) || S_ISSOCK(mode)) {
63760 if (maybe_link() == 0) {
63761- sys_mknod(collected, mode, rdev);
63762- sys_chown(collected, uid, gid);
63763- sys_chmod(collected, mode);
63764- do_utime(collected, mtime);
63765+ sys_mknod((char __force_user *)collected, mode, rdev);
63766+ sys_chown((char __force_user *)collected, uid, gid);
63767+ sys_chmod((char __force_user *)collected, mode);
63768+ do_utime((char __force_user *)collected, mtime);
63769 }
63770 }
63771 return 0;
63772@@ -336,15 +336,15 @@ static int __init do_name(void)
63773 static int __init do_copy(void)
63774 {
63775 if (count >= body_len) {
63776- sys_write(wfd, victim, body_len);
63777+ sys_write(wfd, (char __force_user *)victim, body_len);
63778 sys_close(wfd);
63779- do_utime(vcollected, mtime);
63780+ do_utime((char __force_user *)vcollected, mtime);
63781 kfree(vcollected);
63782 eat(body_len);
63783 state = SkipIt;
63784 return 0;
63785 } else {
63786- sys_write(wfd, victim, count);
63787+ sys_write(wfd, (char __force_user *)victim, count);
63788 body_len -= count;
63789 eat(count);
63790 return 1;
63791@@ -355,9 +355,9 @@ static int __init do_symlink(void)
63792 {
63793 collected[N_ALIGN(name_len) + body_len] = '\0';
63794 clean_path(collected, 0);
63795- sys_symlink(collected + N_ALIGN(name_len), collected);
63796- sys_lchown(collected, uid, gid);
63797- do_utime(collected, mtime);
63798+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
63799+ sys_lchown((char __force_user *)collected, uid, gid);
63800+ do_utime((char __force_user *)collected, mtime);
63801 state = SkipIt;
63802 next_state = Reset;
63803 return 0;
63804diff --git a/init/main.c b/init/main.c
63805index ff49a6d..5fa0429 100644
63806--- a/init/main.c
63807+++ b/init/main.c
63808@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
63809 extern void tc_init(void);
63810 #endif
63811
63812+extern void grsecurity_init(void);
63813+
63814 /*
63815 * Debug helper: via this flag we know that we are in 'early bootup code'
63816 * where only the boot processor is running with IRQ disabled. This means
63817@@ -149,6 +151,49 @@ static int __init set_reset_devices(char *str)
63818
63819 __setup("reset_devices", set_reset_devices);
63820
63821+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
63822+extern char pax_enter_kernel_user[];
63823+extern char pax_exit_kernel_user[];
63824+extern pgdval_t clone_pgd_mask;
63825+#endif
63826+
63827+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
63828+static int __init setup_pax_nouderef(char *str)
63829+{
63830+#ifdef CONFIG_X86_32
63831+ unsigned int cpu;
63832+ struct desc_struct *gdt;
63833+
63834+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
63835+ gdt = get_cpu_gdt_table(cpu);
63836+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
63837+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
63838+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
63839+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
63840+ }
63841+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
63842+#else
63843+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
63844+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
63845+ clone_pgd_mask = ~(pgdval_t)0UL;
63846+#endif
63847+
63848+ return 0;
63849+}
63850+early_param("pax_nouderef", setup_pax_nouderef);
63851+#endif
63852+
63853+#ifdef CONFIG_PAX_SOFTMODE
63854+int pax_softmode;
63855+
63856+static int __init setup_pax_softmode(char *str)
63857+{
63858+ get_option(&str, &pax_softmode);
63859+ return 1;
63860+}
63861+__setup("pax_softmode=", setup_pax_softmode);
63862+#endif
63863+
63864 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
63865 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
63866 static const char *panic_later, *panic_param;
63867@@ -675,6 +720,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
63868 {
63869 int count = preempt_count();
63870 int ret;
63871+ const char *msg1 = "", *msg2 = "";
63872
63873 if (initcall_debug)
63874 ret = do_one_initcall_debug(fn);
63875@@ -687,15 +733,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
63876 sprintf(msgbuf, "error code %d ", ret);
63877
63878 if (preempt_count() != count) {
63879- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
63880+ msg1 = " preemption imbalance";
63881 preempt_count() = count;
63882 }
63883 if (irqs_disabled()) {
63884- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
63885+ msg2 = " disabled interrupts";
63886 local_irq_enable();
63887 }
63888- if (msgbuf[0]) {
63889- printk("initcall %pF returned with %s\n", fn, msgbuf);
63890+ if (msgbuf[0] || *msg1 || *msg2) {
63891+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
63892 }
63893
63894 return ret;
63895@@ -814,7 +860,7 @@ static int __init kernel_init(void * unused)
63896 do_basic_setup();
63897
63898 /* Open the /dev/console on the rootfs, this should never fail */
63899- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
63900+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
63901 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
63902
63903 (void) sys_dup(0);
63904@@ -827,11 +873,13 @@ static int __init kernel_init(void * unused)
63905 if (!ramdisk_execute_command)
63906 ramdisk_execute_command = "/init";
63907
63908- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
63909+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
63910 ramdisk_execute_command = NULL;
63911 prepare_namespace();
63912 }
63913
63914+ grsecurity_init();
63915+
63916 /*
63917 * Ok, we have completed the initial bootup, and
63918 * we're essentially up and running. Get rid of the
63919diff --git a/ipc/mqueue.c b/ipc/mqueue.c
63920index 86ee272..773d937 100644
63921--- a/ipc/mqueue.c
63922+++ b/ipc/mqueue.c
63923@@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
63924 mq_bytes = (mq_msg_tblsz +
63925 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
63926
63927+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
63928 spin_lock(&mq_lock);
63929 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
63930 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
63931diff --git a/ipc/msg.c b/ipc/msg.c
63932index 7385de2..a8180e08 100644
63933--- a/ipc/msg.c
63934+++ b/ipc/msg.c
63935@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
63936 return security_msg_queue_associate(msq, msgflg);
63937 }
63938
63939+static struct ipc_ops msg_ops = {
63940+ .getnew = newque,
63941+ .associate = msg_security,
63942+ .more_checks = NULL
63943+};
63944+
63945 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
63946 {
63947 struct ipc_namespace *ns;
63948- struct ipc_ops msg_ops;
63949 struct ipc_params msg_params;
63950
63951 ns = current->nsproxy->ipc_ns;
63952
63953- msg_ops.getnew = newque;
63954- msg_ops.associate = msg_security;
63955- msg_ops.more_checks = NULL;
63956-
63957 msg_params.key = key;
63958 msg_params.flg = msgflg;
63959
63960diff --git a/ipc/sem.c b/ipc/sem.c
63961index 5215a81..cfc0cac 100644
63962--- a/ipc/sem.c
63963+++ b/ipc/sem.c
63964@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
63965 return 0;
63966 }
63967
63968+static struct ipc_ops sem_ops = {
63969+ .getnew = newary,
63970+ .associate = sem_security,
63971+ .more_checks = sem_more_checks
63972+};
63973+
63974 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
63975 {
63976 struct ipc_namespace *ns;
63977- struct ipc_ops sem_ops;
63978 struct ipc_params sem_params;
63979
63980 ns = current->nsproxy->ipc_ns;
63981@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
63982 if (nsems < 0 || nsems > ns->sc_semmsl)
63983 return -EINVAL;
63984
63985- sem_ops.getnew = newary;
63986- sem_ops.associate = sem_security;
63987- sem_ops.more_checks = sem_more_checks;
63988-
63989 sem_params.key = key;
63990 sem_params.flg = semflg;
63991 sem_params.u.nsems = nsems;
63992diff --git a/ipc/shm.c b/ipc/shm.c
63993index b76be5b..859e750 100644
63994--- a/ipc/shm.c
63995+++ b/ipc/shm.c
63996@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
63997 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
63998 #endif
63999
64000+#ifdef CONFIG_GRKERNSEC
64001+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64002+ const time_t shm_createtime, const uid_t cuid,
64003+ const int shmid);
64004+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64005+ const time_t shm_createtime);
64006+#endif
64007+
64008 void shm_init_ns(struct ipc_namespace *ns)
64009 {
64010 ns->shm_ctlmax = SHMMAX;
64011@@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
64012 shp->shm_lprid = 0;
64013 shp->shm_atim = shp->shm_dtim = 0;
64014 shp->shm_ctim = get_seconds();
64015+#ifdef CONFIG_GRKERNSEC
64016+ {
64017+ struct timespec timeval;
64018+ do_posix_clock_monotonic_gettime(&timeval);
64019+
64020+ shp->shm_createtime = timeval.tv_sec;
64021+ }
64022+#endif
64023 shp->shm_segsz = size;
64024 shp->shm_nattch = 0;
64025 shp->shm_file = file;
64026@@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
64027 return 0;
64028 }
64029
64030+static struct ipc_ops shm_ops = {
64031+ .getnew = newseg,
64032+ .associate = shm_security,
64033+ .more_checks = shm_more_checks
64034+};
64035+
64036 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
64037 {
64038 struct ipc_namespace *ns;
64039- struct ipc_ops shm_ops;
64040 struct ipc_params shm_params;
64041
64042 ns = current->nsproxy->ipc_ns;
64043
64044- shm_ops.getnew = newseg;
64045- shm_ops.associate = shm_security;
64046- shm_ops.more_checks = shm_more_checks;
64047-
64048 shm_params.key = key;
64049 shm_params.flg = shmflg;
64050 shm_params.u.size = size;
64051@@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
64052 f_mode = FMODE_READ | FMODE_WRITE;
64053 }
64054 if (shmflg & SHM_EXEC) {
64055+
64056+#ifdef CONFIG_PAX_MPROTECT
64057+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
64058+ goto out;
64059+#endif
64060+
64061 prot |= PROT_EXEC;
64062 acc_mode |= S_IXUGO;
64063 }
64064@@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
64065 if (err)
64066 goto out_unlock;
64067
64068+#ifdef CONFIG_GRKERNSEC
64069+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
64070+ shp->shm_perm.cuid, shmid) ||
64071+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
64072+ err = -EACCES;
64073+ goto out_unlock;
64074+ }
64075+#endif
64076+
64077 path = shp->shm_file->f_path;
64078 path_get(&path);
64079 shp->shm_nattch++;
64080+#ifdef CONFIG_GRKERNSEC
64081+ shp->shm_lapid = current->pid;
64082+#endif
64083 size = i_size_read(path.dentry->d_inode);
64084 shm_unlock(shp);
64085
64086diff --git a/kernel/acct.c b/kernel/acct.c
64087index 02e6167..54824f7 100644
64088--- a/kernel/acct.c
64089+++ b/kernel/acct.c
64090@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
64091 */
64092 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
64093 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
64094- file->f_op->write(file, (char *)&ac,
64095+ file->f_op->write(file, (char __force_user *)&ac,
64096 sizeof(acct_t), &file->f_pos);
64097 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
64098 set_fs(fs);
64099diff --git a/kernel/audit.c b/kernel/audit.c
64100index bb0eb5b..cf2a03a 100644
64101--- a/kernel/audit.c
64102+++ b/kernel/audit.c
64103@@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
64104 3) suppressed due to audit_rate_limit
64105 4) suppressed due to audit_backlog_limit
64106 */
64107-static atomic_t audit_lost = ATOMIC_INIT(0);
64108+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
64109
64110 /* The netlink socket. */
64111 static struct sock *audit_sock;
64112@@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
64113 unsigned long now;
64114 int print;
64115
64116- atomic_inc(&audit_lost);
64117+ atomic_inc_unchecked(&audit_lost);
64118
64119 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
64120
64121@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
64122 printk(KERN_WARNING
64123 "audit: audit_lost=%d audit_rate_limit=%d "
64124 "audit_backlog_limit=%d\n",
64125- atomic_read(&audit_lost),
64126+ atomic_read_unchecked(&audit_lost),
64127 audit_rate_limit,
64128 audit_backlog_limit);
64129 audit_panic(message);
64130@@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
64131 status_set.pid = audit_pid;
64132 status_set.rate_limit = audit_rate_limit;
64133 status_set.backlog_limit = audit_backlog_limit;
64134- status_set.lost = atomic_read(&audit_lost);
64135+ status_set.lost = atomic_read_unchecked(&audit_lost);
64136 status_set.backlog = skb_queue_len(&audit_skb_queue);
64137 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
64138 &status_set, sizeof(status_set));
64139diff --git a/kernel/auditsc.c b/kernel/auditsc.c
64140index af1de0f..06dfe57 100644
64141--- a/kernel/auditsc.c
64142+++ b/kernel/auditsc.c
64143@@ -2288,7 +2288,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
64144 }
64145
64146 /* global counter which is incremented every time something logs in */
64147-static atomic_t session_id = ATOMIC_INIT(0);
64148+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
64149
64150 /**
64151 * audit_set_loginuid - set current task's audit_context loginuid
64152@@ -2312,7 +2312,7 @@ int audit_set_loginuid(uid_t loginuid)
64153 return -EPERM;
64154 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
64155
64156- sessionid = atomic_inc_return(&session_id);
64157+ sessionid = atomic_inc_return_unchecked(&session_id);
64158 if (context && context->in_syscall) {
64159 struct audit_buffer *ab;
64160
64161diff --git a/kernel/capability.c b/kernel/capability.c
64162index 3f1adb6..c564db0 100644
64163--- a/kernel/capability.c
64164+++ b/kernel/capability.c
64165@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
64166 * before modification is attempted and the application
64167 * fails.
64168 */
64169+ if (tocopy > ARRAY_SIZE(kdata))
64170+ return -EFAULT;
64171+
64172 if (copy_to_user(dataptr, kdata, tocopy
64173 * sizeof(struct __user_cap_data_struct))) {
64174 return -EFAULT;
64175@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
64176 int ret;
64177
64178 rcu_read_lock();
64179- ret = security_capable(__task_cred(t), ns, cap);
64180+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
64181+ gr_task_is_capable(t, __task_cred(t), cap);
64182 rcu_read_unlock();
64183
64184- return (ret == 0);
64185+ return ret;
64186 }
64187
64188 /**
64189@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
64190 int ret;
64191
64192 rcu_read_lock();
64193- ret = security_capable_noaudit(__task_cred(t), ns, cap);
64194+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
64195 rcu_read_unlock();
64196
64197- return (ret == 0);
64198+ return ret;
64199 }
64200
64201 /**
64202@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
64203 BUG();
64204 }
64205
64206- if (security_capable(current_cred(), ns, cap) == 0) {
64207+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
64208 current->flags |= PF_SUPERPRIV;
64209 return true;
64210 }
64211@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
64212 }
64213 EXPORT_SYMBOL(ns_capable);
64214
64215+bool ns_capable_nolog(struct user_namespace *ns, int cap)
64216+{
64217+ if (unlikely(!cap_valid(cap))) {
64218+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
64219+ BUG();
64220+ }
64221+
64222+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
64223+ current->flags |= PF_SUPERPRIV;
64224+ return true;
64225+ }
64226+ return false;
64227+}
64228+EXPORT_SYMBOL(ns_capable_nolog);
64229+
64230 /**
64231 * capable - Determine if the current task has a superior capability in effect
64232 * @cap: The capability to be tested for
64233@@ -408,6 +427,12 @@ bool capable(int cap)
64234 }
64235 EXPORT_SYMBOL(capable);
64236
64237+bool capable_nolog(int cap)
64238+{
64239+ return ns_capable_nolog(&init_user_ns, cap);
64240+}
64241+EXPORT_SYMBOL(capable_nolog);
64242+
64243 /**
64244 * nsown_capable - Check superior capability to one's own user_ns
64245 * @cap: The capability in question
64246diff --git a/kernel/compat.c b/kernel/compat.c
64247index f346ced..aa2b1f4 100644
64248--- a/kernel/compat.c
64249+++ b/kernel/compat.c
64250@@ -13,6 +13,7 @@
64251
64252 #include <linux/linkage.h>
64253 #include <linux/compat.h>
64254+#include <linux/module.h>
64255 #include <linux/errno.h>
64256 #include <linux/time.h>
64257 #include <linux/signal.h>
64258@@ -168,7 +169,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
64259 mm_segment_t oldfs;
64260 long ret;
64261
64262- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
64263+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
64264 oldfs = get_fs();
64265 set_fs(KERNEL_DS);
64266 ret = hrtimer_nanosleep_restart(restart);
64267@@ -200,7 +201,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
64268 oldfs = get_fs();
64269 set_fs(KERNEL_DS);
64270 ret = hrtimer_nanosleep(&tu,
64271- rmtp ? (struct timespec __user *)&rmt : NULL,
64272+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
64273 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
64274 set_fs(oldfs);
64275
64276@@ -309,7 +310,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
64277 mm_segment_t old_fs = get_fs();
64278
64279 set_fs(KERNEL_DS);
64280- ret = sys_sigpending((old_sigset_t __user *) &s);
64281+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
64282 set_fs(old_fs);
64283 if (ret == 0)
64284 ret = put_user(s, set);
64285@@ -332,8 +333,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
64286 old_fs = get_fs();
64287 set_fs(KERNEL_DS);
64288 ret = sys_sigprocmask(how,
64289- set ? (old_sigset_t __user *) &s : NULL,
64290- oset ? (old_sigset_t __user *) &s : NULL);
64291+ set ? (old_sigset_t __force_user *) &s : NULL,
64292+ oset ? (old_sigset_t __force_user *) &s : NULL);
64293 set_fs(old_fs);
64294 if (ret == 0)
64295 if (oset)
64296@@ -370,7 +371,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
64297 mm_segment_t old_fs = get_fs();
64298
64299 set_fs(KERNEL_DS);
64300- ret = sys_old_getrlimit(resource, &r);
64301+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
64302 set_fs(old_fs);
64303
64304 if (!ret) {
64305@@ -442,7 +443,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
64306 mm_segment_t old_fs = get_fs();
64307
64308 set_fs(KERNEL_DS);
64309- ret = sys_getrusage(who, (struct rusage __user *) &r);
64310+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
64311 set_fs(old_fs);
64312
64313 if (ret)
64314@@ -469,8 +470,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
64315 set_fs (KERNEL_DS);
64316 ret = sys_wait4(pid,
64317 (stat_addr ?
64318- (unsigned int __user *) &status : NULL),
64319- options, (struct rusage __user *) &r);
64320+ (unsigned int __force_user *) &status : NULL),
64321+ options, (struct rusage __force_user *) &r);
64322 set_fs (old_fs);
64323
64324 if (ret > 0) {
64325@@ -495,8 +496,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
64326 memset(&info, 0, sizeof(info));
64327
64328 set_fs(KERNEL_DS);
64329- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
64330- uru ? (struct rusage __user *)&ru : NULL);
64331+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
64332+ uru ? (struct rusage __force_user *)&ru : NULL);
64333 set_fs(old_fs);
64334
64335 if ((ret < 0) || (info.si_signo == 0))
64336@@ -626,8 +627,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
64337 oldfs = get_fs();
64338 set_fs(KERNEL_DS);
64339 err = sys_timer_settime(timer_id, flags,
64340- (struct itimerspec __user *) &newts,
64341- (struct itimerspec __user *) &oldts);
64342+ (struct itimerspec __force_user *) &newts,
64343+ (struct itimerspec __force_user *) &oldts);
64344 set_fs(oldfs);
64345 if (!err && old && put_compat_itimerspec(old, &oldts))
64346 return -EFAULT;
64347@@ -644,7 +645,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
64348 oldfs = get_fs();
64349 set_fs(KERNEL_DS);
64350 err = sys_timer_gettime(timer_id,
64351- (struct itimerspec __user *) &ts);
64352+ (struct itimerspec __force_user *) &ts);
64353 set_fs(oldfs);
64354 if (!err && put_compat_itimerspec(setting, &ts))
64355 return -EFAULT;
64356@@ -663,7 +664,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
64357 oldfs = get_fs();
64358 set_fs(KERNEL_DS);
64359 err = sys_clock_settime(which_clock,
64360- (struct timespec __user *) &ts);
64361+ (struct timespec __force_user *) &ts);
64362 set_fs(oldfs);
64363 return err;
64364 }
64365@@ -678,7 +679,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
64366 oldfs = get_fs();
64367 set_fs(KERNEL_DS);
64368 err = sys_clock_gettime(which_clock,
64369- (struct timespec __user *) &ts);
64370+ (struct timespec __force_user *) &ts);
64371 set_fs(oldfs);
64372 if (!err && put_compat_timespec(&ts, tp))
64373 return -EFAULT;
64374@@ -698,7 +699,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
64375
64376 oldfs = get_fs();
64377 set_fs(KERNEL_DS);
64378- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
64379+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
64380 set_fs(oldfs);
64381
64382 err = compat_put_timex(utp, &txc);
64383@@ -718,7 +719,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
64384 oldfs = get_fs();
64385 set_fs(KERNEL_DS);
64386 err = sys_clock_getres(which_clock,
64387- (struct timespec __user *) &ts);
64388+ (struct timespec __force_user *) &ts);
64389 set_fs(oldfs);
64390 if (!err && tp && put_compat_timespec(&ts, tp))
64391 return -EFAULT;
64392@@ -730,9 +731,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
64393 long err;
64394 mm_segment_t oldfs;
64395 struct timespec tu;
64396- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
64397+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
64398
64399- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
64400+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
64401 oldfs = get_fs();
64402 set_fs(KERNEL_DS);
64403 err = clock_nanosleep_restart(restart);
64404@@ -764,8 +765,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
64405 oldfs = get_fs();
64406 set_fs(KERNEL_DS);
64407 err = sys_clock_nanosleep(which_clock, flags,
64408- (struct timespec __user *) &in,
64409- (struct timespec __user *) &out);
64410+ (struct timespec __force_user *) &in,
64411+ (struct timespec __force_user *) &out);
64412 set_fs(oldfs);
64413
64414 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
64415diff --git a/kernel/configs.c b/kernel/configs.c
64416index 42e8fa0..9e7406b 100644
64417--- a/kernel/configs.c
64418+++ b/kernel/configs.c
64419@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
64420 struct proc_dir_entry *entry;
64421
64422 /* create the current config file */
64423+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64424+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
64425+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
64426+ &ikconfig_file_ops);
64427+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64428+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
64429+ &ikconfig_file_ops);
64430+#endif
64431+#else
64432 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
64433 &ikconfig_file_ops);
64434+#endif
64435+
64436 if (!entry)
64437 return -ENOMEM;
64438
64439diff --git a/kernel/cred.c b/kernel/cred.c
64440index 5791612..a3c04dc 100644
64441--- a/kernel/cred.c
64442+++ b/kernel/cred.c
64443@@ -204,6 +204,15 @@ void exit_creds(struct task_struct *tsk)
64444 validate_creds(cred);
64445 put_cred(cred);
64446 }
64447+
64448+#ifdef CONFIG_GRKERNSEC_SETXID
64449+ cred = (struct cred *) tsk->delayed_cred;
64450+ if (cred) {
64451+ tsk->delayed_cred = NULL;
64452+ validate_creds(cred);
64453+ put_cred(cred);
64454+ }
64455+#endif
64456 }
64457
64458 /**
64459@@ -470,7 +479,7 @@ error_put:
64460 * Always returns 0 thus allowing this function to be tail-called at the end
64461 * of, say, sys_setgid().
64462 */
64463-int commit_creds(struct cred *new)
64464+static int __commit_creds(struct cred *new)
64465 {
64466 struct task_struct *task = current;
64467 const struct cred *old = task->real_cred;
64468@@ -489,6 +498,8 @@ int commit_creds(struct cred *new)
64469
64470 get_cred(new); /* we will require a ref for the subj creds too */
64471
64472+ gr_set_role_label(task, new->uid, new->gid);
64473+
64474 /* dumpability changes */
64475 if (old->euid != new->euid ||
64476 old->egid != new->egid ||
64477@@ -538,6 +549,92 @@ int commit_creds(struct cred *new)
64478 put_cred(old);
64479 return 0;
64480 }
64481+#ifdef CONFIG_GRKERNSEC_SETXID
64482+extern int set_user(struct cred *new);
64483+
64484+void gr_delayed_cred_worker(void)
64485+{
64486+ const struct cred *new = current->delayed_cred;
64487+ struct cred *ncred;
64488+
64489+ current->delayed_cred = NULL;
64490+
64491+ if (current_uid() && new != NULL) {
64492+ // from doing get_cred on it when queueing this
64493+ put_cred(new);
64494+ return;
64495+ } else if (new == NULL)
64496+ return;
64497+
64498+ ncred = prepare_creds();
64499+ if (!ncred)
64500+ goto die;
64501+ // uids
64502+ ncred->uid = new->uid;
64503+ ncred->euid = new->euid;
64504+ ncred->suid = new->suid;
64505+ ncred->fsuid = new->fsuid;
64506+ // gids
64507+ ncred->gid = new->gid;
64508+ ncred->egid = new->egid;
64509+ ncred->sgid = new->sgid;
64510+ ncred->fsgid = new->fsgid;
64511+ // groups
64512+ if (set_groups(ncred, new->group_info) < 0) {
64513+ abort_creds(ncred);
64514+ goto die;
64515+ }
64516+ // caps
64517+ ncred->securebits = new->securebits;
64518+ ncred->cap_inheritable = new->cap_inheritable;
64519+ ncred->cap_permitted = new->cap_permitted;
64520+ ncred->cap_effective = new->cap_effective;
64521+ ncred->cap_bset = new->cap_bset;
64522+
64523+ if (set_user(ncred)) {
64524+ abort_creds(ncred);
64525+ goto die;
64526+ }
64527+
64528+ // from doing get_cred on it when queueing this
64529+ put_cred(new);
64530+
64531+ __commit_creds(ncred);
64532+ return;
64533+die:
64534+ // from doing get_cred on it when queueing this
64535+ put_cred(new);
64536+ do_group_exit(SIGKILL);
64537+}
64538+#endif
64539+
64540+int commit_creds(struct cred *new)
64541+{
64542+#ifdef CONFIG_GRKERNSEC_SETXID
64543+ struct task_struct *t;
64544+
64545+ /* we won't get called with tasklist_lock held for writing
64546+ and interrupts disabled as the cred struct in that case is
64547+ init_cred
64548+ */
64549+ if (grsec_enable_setxid && !current_is_single_threaded() &&
64550+ !current_uid() && new->uid) {
64551+ rcu_read_lock();
64552+ read_lock(&tasklist_lock);
64553+ for (t = next_thread(current); t != current;
64554+ t = next_thread(t)) {
64555+ if (t->delayed_cred == NULL) {
64556+ t->delayed_cred = get_cred(new);
64557+ set_tsk_need_resched(t);
64558+ }
64559+ }
64560+ read_unlock(&tasklist_lock);
64561+ rcu_read_unlock();
64562+ }
64563+#endif
64564+ return __commit_creds(new);
64565+}
64566+
64567 EXPORT_SYMBOL(commit_creds);
64568
64569 /**
64570diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
64571index 0d7c087..01b8cef 100644
64572--- a/kernel/debug/debug_core.c
64573+++ b/kernel/debug/debug_core.c
64574@@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
64575 */
64576 static atomic_t masters_in_kgdb;
64577 static atomic_t slaves_in_kgdb;
64578-static atomic_t kgdb_break_tasklet_var;
64579+static atomic_unchecked_t kgdb_break_tasklet_var;
64580 atomic_t kgdb_setting_breakpoint;
64581
64582 struct task_struct *kgdb_usethread;
64583@@ -129,7 +129,7 @@ int kgdb_single_step;
64584 static pid_t kgdb_sstep_pid;
64585
64586 /* to keep track of the CPU which is doing the single stepping*/
64587-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
64588+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
64589
64590 /*
64591 * If you are debugging a problem where roundup (the collection of
64592@@ -542,7 +542,7 @@ return_normal:
64593 * kernel will only try for the value of sstep_tries before
64594 * giving up and continuing on.
64595 */
64596- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
64597+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
64598 (kgdb_info[cpu].task &&
64599 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
64600 atomic_set(&kgdb_active, -1);
64601@@ -636,8 +636,8 @@ cpu_master_loop:
64602 }
64603
64604 kgdb_restore:
64605- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
64606- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
64607+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
64608+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
64609 if (kgdb_info[sstep_cpu].task)
64610 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
64611 else
64612@@ -834,18 +834,18 @@ static void kgdb_unregister_callbacks(void)
64613 static void kgdb_tasklet_bpt(unsigned long ing)
64614 {
64615 kgdb_breakpoint();
64616- atomic_set(&kgdb_break_tasklet_var, 0);
64617+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
64618 }
64619
64620 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
64621
64622 void kgdb_schedule_breakpoint(void)
64623 {
64624- if (atomic_read(&kgdb_break_tasklet_var) ||
64625+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
64626 atomic_read(&kgdb_active) != -1 ||
64627 atomic_read(&kgdb_setting_breakpoint))
64628 return;
64629- atomic_inc(&kgdb_break_tasklet_var);
64630+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
64631 tasklet_schedule(&kgdb_tasklet_breakpoint);
64632 }
64633 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
64634diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
64635index e2ae734..08a4c5c 100644
64636--- a/kernel/debug/kdb/kdb_main.c
64637+++ b/kernel/debug/kdb/kdb_main.c
64638@@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const char **argv)
64639 list_for_each_entry(mod, kdb_modules, list) {
64640
64641 kdb_printf("%-20s%8u 0x%p ", mod->name,
64642- mod->core_size, (void *)mod);
64643+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
64644 #ifdef CONFIG_MODULE_UNLOAD
64645 kdb_printf("%4ld ", module_refcount(mod));
64646 #endif
64647@@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const char **argv)
64648 kdb_printf(" (Loading)");
64649 else
64650 kdb_printf(" (Live)");
64651- kdb_printf(" 0x%p", mod->module_core);
64652+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
64653
64654 #ifdef CONFIG_MODULE_UNLOAD
64655 {
64656diff --git a/kernel/events/core.c b/kernel/events/core.c
64657index 1b5c081..c375f83 100644
64658--- a/kernel/events/core.c
64659+++ b/kernel/events/core.c
64660@@ -173,7 +173,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
64661 return 0;
64662 }
64663
64664-static atomic64_t perf_event_id;
64665+static atomic64_unchecked_t perf_event_id;
64666
64667 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
64668 enum event_type_t event_type);
64669@@ -2581,7 +2581,7 @@ static void __perf_event_read(void *info)
64670
64671 static inline u64 perf_event_count(struct perf_event *event)
64672 {
64673- return local64_read(&event->count) + atomic64_read(&event->child_count);
64674+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
64675 }
64676
64677 static u64 perf_event_read(struct perf_event *event)
64678@@ -2897,9 +2897,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
64679 mutex_lock(&event->child_mutex);
64680 total += perf_event_read(event);
64681 *enabled += event->total_time_enabled +
64682- atomic64_read(&event->child_total_time_enabled);
64683+ atomic64_read_unchecked(&event->child_total_time_enabled);
64684 *running += event->total_time_running +
64685- atomic64_read(&event->child_total_time_running);
64686+ atomic64_read_unchecked(&event->child_total_time_running);
64687
64688 list_for_each_entry(child, &event->child_list, child_list) {
64689 total += perf_event_read(child);
64690@@ -3306,10 +3306,10 @@ void perf_event_update_userpage(struct perf_event *event)
64691 userpg->offset -= local64_read(&event->hw.prev_count);
64692
64693 userpg->time_enabled = enabled +
64694- atomic64_read(&event->child_total_time_enabled);
64695+ atomic64_read_unchecked(&event->child_total_time_enabled);
64696
64697 userpg->time_running = running +
64698- atomic64_read(&event->child_total_time_running);
64699+ atomic64_read_unchecked(&event->child_total_time_running);
64700
64701 barrier();
64702 ++userpg->lock;
64703@@ -3738,11 +3738,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
64704 values[n++] = perf_event_count(event);
64705 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
64706 values[n++] = enabled +
64707- atomic64_read(&event->child_total_time_enabled);
64708+ atomic64_read_unchecked(&event->child_total_time_enabled);
64709 }
64710 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
64711 values[n++] = running +
64712- atomic64_read(&event->child_total_time_running);
64713+ atomic64_read_unchecked(&event->child_total_time_running);
64714 }
64715 if (read_format & PERF_FORMAT_ID)
64716 values[n++] = primary_event_id(event);
64717@@ -4393,12 +4393,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
64718 * need to add enough zero bytes after the string to handle
64719 * the 64bit alignment we do later.
64720 */
64721- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
64722+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
64723 if (!buf) {
64724 name = strncpy(tmp, "//enomem", sizeof(tmp));
64725 goto got_name;
64726 }
64727- name = d_path(&file->f_path, buf, PATH_MAX);
64728+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
64729 if (IS_ERR(name)) {
64730 name = strncpy(tmp, "//toolong", sizeof(tmp));
64731 goto got_name;
64732@@ -5765,7 +5765,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
64733 event->parent = parent_event;
64734
64735 event->ns = get_pid_ns(current->nsproxy->pid_ns);
64736- event->id = atomic64_inc_return(&perf_event_id);
64737+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
64738
64739 event->state = PERF_EVENT_STATE_INACTIVE;
64740
64741@@ -6287,10 +6287,10 @@ static void sync_child_event(struct perf_event *child_event,
64742 /*
64743 * Add back the child's count to the parent's count:
64744 */
64745- atomic64_add(child_val, &parent_event->child_count);
64746- atomic64_add(child_event->total_time_enabled,
64747+ atomic64_add_unchecked(child_val, &parent_event->child_count);
64748+ atomic64_add_unchecked(child_event->total_time_enabled,
64749 &parent_event->child_total_time_enabled);
64750- atomic64_add(child_event->total_time_running,
64751+ atomic64_add_unchecked(child_event->total_time_running,
64752 &parent_event->child_total_time_running);
64753
64754 /*
64755diff --git a/kernel/exit.c b/kernel/exit.c
64756index 4b4042f..5bdd8d5 100644
64757--- a/kernel/exit.c
64758+++ b/kernel/exit.c
64759@@ -58,6 +58,10 @@
64760 #include <asm/pgtable.h>
64761 #include <asm/mmu_context.h>
64762
64763+#ifdef CONFIG_GRKERNSEC
64764+extern rwlock_t grsec_exec_file_lock;
64765+#endif
64766+
64767 static void exit_mm(struct task_struct * tsk);
64768
64769 static void __unhash_process(struct task_struct *p, bool group_dead)
64770@@ -169,6 +173,10 @@ void release_task(struct task_struct * p)
64771 struct task_struct *leader;
64772 int zap_leader;
64773 repeat:
64774+#ifdef CONFIG_NET
64775+ gr_del_task_from_ip_table(p);
64776+#endif
64777+
64778 /* don't need to get the RCU readlock here - the process is dead and
64779 * can't be modifying its own credentials. But shut RCU-lockdep up */
64780 rcu_read_lock();
64781@@ -381,7 +389,7 @@ int allow_signal(int sig)
64782 * know it'll be handled, so that they don't get converted to
64783 * SIGKILL or just silently dropped.
64784 */
64785- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
64786+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
64787 recalc_sigpending();
64788 spin_unlock_irq(&current->sighand->siglock);
64789 return 0;
64790@@ -417,6 +425,17 @@ void daemonize(const char *name, ...)
64791 vsnprintf(current->comm, sizeof(current->comm), name, args);
64792 va_end(args);
64793
64794+#ifdef CONFIG_GRKERNSEC
64795+ write_lock(&grsec_exec_file_lock);
64796+ if (current->exec_file) {
64797+ fput(current->exec_file);
64798+ current->exec_file = NULL;
64799+ }
64800+ write_unlock(&grsec_exec_file_lock);
64801+#endif
64802+
64803+ gr_set_kernel_label(current);
64804+
64805 /*
64806 * If we were started as result of loading a module, close all of the
64807 * user space pages. We don't need them, and if we didn't close them
64808@@ -892,6 +911,8 @@ void do_exit(long code)
64809 struct task_struct *tsk = current;
64810 int group_dead;
64811
64812+ set_fs(USER_DS);
64813+
64814 profile_task_exit(tsk);
64815
64816 WARN_ON(blk_needs_flush_plug(tsk));
64817@@ -908,7 +929,6 @@ void do_exit(long code)
64818 * mm_release()->clear_child_tid() from writing to a user-controlled
64819 * kernel address.
64820 */
64821- set_fs(USER_DS);
64822
64823 ptrace_event(PTRACE_EVENT_EXIT, code);
64824
64825@@ -969,6 +989,9 @@ void do_exit(long code)
64826 tsk->exit_code = code;
64827 taskstats_exit(tsk, group_dead);
64828
64829+ gr_acl_handle_psacct(tsk, code);
64830+ gr_acl_handle_exit();
64831+
64832 exit_mm(tsk);
64833
64834 if (group_dead)
64835@@ -1085,7 +1108,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
64836 * Take down every thread in the group. This is called by fatal signals
64837 * as well as by sys_exit_group (below).
64838 */
64839-void
64840+__noreturn void
64841 do_group_exit(int exit_code)
64842 {
64843 struct signal_struct *sig = current->signal;
64844diff --git a/kernel/fork.c b/kernel/fork.c
64845index 26a7a67..a1053f9 100644
64846--- a/kernel/fork.c
64847+++ b/kernel/fork.c
64848@@ -284,7 +284,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
64849 *stackend = STACK_END_MAGIC; /* for overflow detection */
64850
64851 #ifdef CONFIG_CC_STACKPROTECTOR
64852- tsk->stack_canary = get_random_int();
64853+ tsk->stack_canary = pax_get_random_long();
64854 #endif
64855
64856 /*
64857@@ -308,13 +308,77 @@ out:
64858 }
64859
64860 #ifdef CONFIG_MMU
64861+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
64862+{
64863+ struct vm_area_struct *tmp;
64864+ unsigned long charge;
64865+ struct mempolicy *pol;
64866+ struct file *file;
64867+
64868+ charge = 0;
64869+ if (mpnt->vm_flags & VM_ACCOUNT) {
64870+ unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
64871+ if (security_vm_enough_memory(len))
64872+ goto fail_nomem;
64873+ charge = len;
64874+ }
64875+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
64876+ if (!tmp)
64877+ goto fail_nomem;
64878+ *tmp = *mpnt;
64879+ tmp->vm_mm = mm;
64880+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
64881+ pol = mpol_dup(vma_policy(mpnt));
64882+ if (IS_ERR(pol))
64883+ goto fail_nomem_policy;
64884+ vma_set_policy(tmp, pol);
64885+ if (anon_vma_fork(tmp, mpnt))
64886+ goto fail_nomem_anon_vma_fork;
64887+ tmp->vm_flags &= ~VM_LOCKED;
64888+ tmp->vm_next = tmp->vm_prev = NULL;
64889+ tmp->vm_mirror = NULL;
64890+ file = tmp->vm_file;
64891+ if (file) {
64892+ struct inode *inode = file->f_path.dentry->d_inode;
64893+ struct address_space *mapping = file->f_mapping;
64894+
64895+ get_file(file);
64896+ if (tmp->vm_flags & VM_DENYWRITE)
64897+ atomic_dec(&inode->i_writecount);
64898+ mutex_lock(&mapping->i_mmap_mutex);
64899+ if (tmp->vm_flags & VM_SHARED)
64900+ mapping->i_mmap_writable++;
64901+ flush_dcache_mmap_lock(mapping);
64902+ /* insert tmp into the share list, just after mpnt */
64903+ vma_prio_tree_add(tmp, mpnt);
64904+ flush_dcache_mmap_unlock(mapping);
64905+ mutex_unlock(&mapping->i_mmap_mutex);
64906+ }
64907+
64908+ /*
64909+ * Clear hugetlb-related page reserves for children. This only
64910+ * affects MAP_PRIVATE mappings. Faults generated by the child
64911+ * are not guaranteed to succeed, even if read-only
64912+ */
64913+ if (is_vm_hugetlb_page(tmp))
64914+ reset_vma_resv_huge_pages(tmp);
64915+
64916+ return tmp;
64917+
64918+fail_nomem_anon_vma_fork:
64919+ mpol_put(pol);
64920+fail_nomem_policy:
64921+ kmem_cache_free(vm_area_cachep, tmp);
64922+fail_nomem:
64923+ vm_unacct_memory(charge);
64924+ return NULL;
64925+}
64926+
64927 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
64928 {
64929 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
64930 struct rb_node **rb_link, *rb_parent;
64931 int retval;
64932- unsigned long charge;
64933- struct mempolicy *pol;
64934
64935 down_write(&oldmm->mmap_sem);
64936 flush_cache_dup_mm(oldmm);
64937@@ -326,8 +390,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
64938 mm->locked_vm = 0;
64939 mm->mmap = NULL;
64940 mm->mmap_cache = NULL;
64941- mm->free_area_cache = oldmm->mmap_base;
64942- mm->cached_hole_size = ~0UL;
64943+ mm->free_area_cache = oldmm->free_area_cache;
64944+ mm->cached_hole_size = oldmm->cached_hole_size;
64945 mm->map_count = 0;
64946 cpumask_clear(mm_cpumask(mm));
64947 mm->mm_rb = RB_ROOT;
64948@@ -343,8 +407,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
64949
64950 prev = NULL;
64951 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
64952- struct file *file;
64953-
64954 if (mpnt->vm_flags & VM_DONTCOPY) {
64955 long pages = vma_pages(mpnt);
64956 mm->total_vm -= pages;
64957@@ -352,53 +414,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
64958 -pages);
64959 continue;
64960 }
64961- charge = 0;
64962- if (mpnt->vm_flags & VM_ACCOUNT) {
64963- unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
64964- if (security_vm_enough_memory(len))
64965- goto fail_nomem;
64966- charge = len;
64967+ tmp = dup_vma(mm, mpnt);
64968+ if (!tmp) {
64969+ retval = -ENOMEM;
64970+ goto out;
64971 }
64972- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
64973- if (!tmp)
64974- goto fail_nomem;
64975- *tmp = *mpnt;
64976- INIT_LIST_HEAD(&tmp->anon_vma_chain);
64977- pol = mpol_dup(vma_policy(mpnt));
64978- retval = PTR_ERR(pol);
64979- if (IS_ERR(pol))
64980- goto fail_nomem_policy;
64981- vma_set_policy(tmp, pol);
64982- tmp->vm_mm = mm;
64983- if (anon_vma_fork(tmp, mpnt))
64984- goto fail_nomem_anon_vma_fork;
64985- tmp->vm_flags &= ~VM_LOCKED;
64986- tmp->vm_next = tmp->vm_prev = NULL;
64987- file = tmp->vm_file;
64988- if (file) {
64989- struct inode *inode = file->f_path.dentry->d_inode;
64990- struct address_space *mapping = file->f_mapping;
64991-
64992- get_file(file);
64993- if (tmp->vm_flags & VM_DENYWRITE)
64994- atomic_dec(&inode->i_writecount);
64995- mutex_lock(&mapping->i_mmap_mutex);
64996- if (tmp->vm_flags & VM_SHARED)
64997- mapping->i_mmap_writable++;
64998- flush_dcache_mmap_lock(mapping);
64999- /* insert tmp into the share list, just after mpnt */
65000- vma_prio_tree_add(tmp, mpnt);
65001- flush_dcache_mmap_unlock(mapping);
65002- mutex_unlock(&mapping->i_mmap_mutex);
65003- }
65004-
65005- /*
65006- * Clear hugetlb-related page reserves for children. This only
65007- * affects MAP_PRIVATE mappings. Faults generated by the child
65008- * are not guaranteed to succeed, even if read-only
65009- */
65010- if (is_vm_hugetlb_page(tmp))
65011- reset_vma_resv_huge_pages(tmp);
65012
65013 /*
65014 * Link in the new vma and copy the page table entries.
65015@@ -421,6 +441,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65016 if (retval)
65017 goto out;
65018 }
65019+
65020+#ifdef CONFIG_PAX_SEGMEXEC
65021+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
65022+ struct vm_area_struct *mpnt_m;
65023+
65024+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
65025+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
65026+
65027+ if (!mpnt->vm_mirror)
65028+ continue;
65029+
65030+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
65031+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
65032+ mpnt->vm_mirror = mpnt_m;
65033+ } else {
65034+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
65035+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
65036+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
65037+ mpnt->vm_mirror->vm_mirror = mpnt;
65038+ }
65039+ }
65040+ BUG_ON(mpnt_m);
65041+ }
65042+#endif
65043+
65044 /* a new mm has just been created */
65045 arch_dup_mmap(oldmm, mm);
65046 retval = 0;
65047@@ -429,14 +474,6 @@ out:
65048 flush_tlb_mm(oldmm);
65049 up_write(&oldmm->mmap_sem);
65050 return retval;
65051-fail_nomem_anon_vma_fork:
65052- mpol_put(pol);
65053-fail_nomem_policy:
65054- kmem_cache_free(vm_area_cachep, tmp);
65055-fail_nomem:
65056- retval = -ENOMEM;
65057- vm_unacct_memory(charge);
65058- goto out;
65059 }
65060
65061 static inline int mm_alloc_pgd(struct mm_struct *mm)
65062@@ -658,8 +695,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
65063 return ERR_PTR(err);
65064
65065 mm = get_task_mm(task);
65066- if (mm && mm != current->mm &&
65067- !ptrace_may_access(task, mode)) {
65068+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
65069+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
65070 mmput(mm);
65071 mm = ERR_PTR(-EACCES);
65072 }
65073@@ -881,13 +918,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
65074 spin_unlock(&fs->lock);
65075 return -EAGAIN;
65076 }
65077- fs->users++;
65078+ atomic_inc(&fs->users);
65079 spin_unlock(&fs->lock);
65080 return 0;
65081 }
65082 tsk->fs = copy_fs_struct(fs);
65083 if (!tsk->fs)
65084 return -ENOMEM;
65085+ gr_set_chroot_entries(tsk, &tsk->fs->root);
65086 return 0;
65087 }
65088
65089@@ -1151,6 +1189,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
65090 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
65091 #endif
65092 retval = -EAGAIN;
65093+
65094+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
65095+
65096 if (atomic_read(&p->real_cred->user->processes) >=
65097 task_rlimit(p, RLIMIT_NPROC)) {
65098 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
65099@@ -1306,6 +1347,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
65100 if (clone_flags & CLONE_THREAD)
65101 p->tgid = current->tgid;
65102
65103+ gr_copy_label(p);
65104+
65105 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
65106 /*
65107 * Clear TID on mm_release()?
65108@@ -1472,6 +1515,8 @@ bad_fork_cleanup_count:
65109 bad_fork_free:
65110 free_task(p);
65111 fork_out:
65112+ gr_log_forkfail(retval);
65113+
65114 return ERR_PTR(retval);
65115 }
65116
65117@@ -1572,6 +1617,8 @@ long do_fork(unsigned long clone_flags,
65118 if (clone_flags & CLONE_PARENT_SETTID)
65119 put_user(nr, parent_tidptr);
65120
65121+ gr_handle_brute_check();
65122+
65123 if (clone_flags & CLONE_VFORK) {
65124 p->vfork_done = &vfork;
65125 init_completion(&vfork);
65126@@ -1670,7 +1717,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
65127 return 0;
65128
65129 /* don't need lock here; in the worst case we'll do useless copy */
65130- if (fs->users == 1)
65131+ if (atomic_read(&fs->users) == 1)
65132 return 0;
65133
65134 *new_fsp = copy_fs_struct(fs);
65135@@ -1759,7 +1806,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
65136 fs = current->fs;
65137 spin_lock(&fs->lock);
65138 current->fs = new_fs;
65139- if (--fs->users)
65140+ gr_set_chroot_entries(current, &current->fs->root);
65141+ if (atomic_dec_return(&fs->users))
65142 new_fs = NULL;
65143 else
65144 new_fs = fs;
65145diff --git a/kernel/futex.c b/kernel/futex.c
65146index 0677023..f3c3b79 100644
65147--- a/kernel/futex.c
65148+++ b/kernel/futex.c
65149@@ -54,6 +54,7 @@
65150 #include <linux/mount.h>
65151 #include <linux/pagemap.h>
65152 #include <linux/syscalls.h>
65153+#include <linux/ptrace.h>
65154 #include <linux/signal.h>
65155 #include <linux/export.h>
65156 #include <linux/magic.h>
65157@@ -238,6 +239,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
65158 struct page *page, *page_head;
65159 int err, ro = 0;
65160
65161+#ifdef CONFIG_PAX_SEGMEXEC
65162+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
65163+ return -EFAULT;
65164+#endif
65165+
65166 /*
65167 * The futex address must be "naturally" aligned.
65168 */
65169@@ -2459,6 +2465,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
65170 if (!p)
65171 goto err_unlock;
65172 ret = -EPERM;
65173+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65174+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
65175+ goto err_unlock;
65176+#endif
65177 pcred = __task_cred(p);
65178 /* If victim is in different user_ns, then uids are not
65179 comparable, so we must have CAP_SYS_PTRACE */
65180@@ -2731,6 +2741,7 @@ static int __init futex_init(void)
65181 {
65182 u32 curval;
65183 int i;
65184+ mm_segment_t oldfs;
65185
65186 /*
65187 * This will fail and we want it. Some arch implementations do
65188@@ -2742,8 +2753,11 @@ static int __init futex_init(void)
65189 * implementation, the non-functional ones will return
65190 * -ENOSYS.
65191 */
65192+ oldfs = get_fs();
65193+ set_fs(USER_DS);
65194 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
65195 futex_cmpxchg_enabled = 1;
65196+ set_fs(oldfs);
65197
65198 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
65199 plist_head_init(&futex_queues[i].chain);
65200diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
65201index 5f9e689..582d46d 100644
65202--- a/kernel/futex_compat.c
65203+++ b/kernel/futex_compat.c
65204@@ -10,6 +10,7 @@
65205 #include <linux/compat.h>
65206 #include <linux/nsproxy.h>
65207 #include <linux/futex.h>
65208+#include <linux/ptrace.h>
65209
65210 #include <asm/uaccess.h>
65211
65212@@ -136,7 +137,8 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
65213 {
65214 struct compat_robust_list_head __user *head;
65215 unsigned long ret;
65216- const struct cred *cred = current_cred(), *pcred;
65217+ const struct cred *cred = current_cred();
65218+ const struct cred *pcred;
65219
65220 if (!futex_cmpxchg_enabled)
65221 return -ENOSYS;
65222@@ -152,6 +154,10 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
65223 if (!p)
65224 goto err_unlock;
65225 ret = -EPERM;
65226+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65227+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
65228+ goto err_unlock;
65229+#endif
65230 pcred = __task_cred(p);
65231 /* If victim is in different user_ns, then uids are not
65232 comparable, so we must have CAP_SYS_PTRACE */
65233diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
65234index 9b22d03..6295b62 100644
65235--- a/kernel/gcov/base.c
65236+++ b/kernel/gcov/base.c
65237@@ -102,11 +102,6 @@ void gcov_enable_events(void)
65238 }
65239
65240 #ifdef CONFIG_MODULES
65241-static inline int within(void *addr, void *start, unsigned long size)
65242-{
65243- return ((addr >= start) && (addr < start + size));
65244-}
65245-
65246 /* Update list and generate events when modules are unloaded. */
65247 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
65248 void *data)
65249@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
65250 prev = NULL;
65251 /* Remove entries located in module from linked list. */
65252 for (info = gcov_info_head; info; info = info->next) {
65253- if (within(info, mod->module_core, mod->core_size)) {
65254+ if (within_module_core_rw((unsigned long)info, mod)) {
65255 if (prev)
65256 prev->next = info->next;
65257 else
65258diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
65259index ae34bf5..4e2f3d0 100644
65260--- a/kernel/hrtimer.c
65261+++ b/kernel/hrtimer.c
65262@@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
65263 local_irq_restore(flags);
65264 }
65265
65266-static void run_hrtimer_softirq(struct softirq_action *h)
65267+static void run_hrtimer_softirq(void)
65268 {
65269 hrtimer_peek_ahead_timers();
65270 }
65271diff --git a/kernel/jump_label.c b/kernel/jump_label.c
65272index 01d3b70..9e4d098 100644
65273--- a/kernel/jump_label.c
65274+++ b/kernel/jump_label.c
65275@@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
65276
65277 size = (((unsigned long)stop - (unsigned long)start)
65278 / sizeof(struct jump_entry));
65279+ pax_open_kernel();
65280 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
65281+ pax_close_kernel();
65282 }
65283
65284 static void jump_label_update(struct jump_label_key *key, int enable);
65285@@ -340,10 +342,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
65286 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
65287 struct jump_entry *iter;
65288
65289+ pax_open_kernel();
65290 for (iter = iter_start; iter < iter_stop; iter++) {
65291 if (within_module_init(iter->code, mod))
65292 iter->code = 0;
65293 }
65294+ pax_close_kernel();
65295 }
65296
65297 static int
65298diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
65299index 079f1d3..a407562 100644
65300--- a/kernel/kallsyms.c
65301+++ b/kernel/kallsyms.c
65302@@ -11,6 +11,9 @@
65303 * Changed the compression method from stem compression to "table lookup"
65304 * compression (see scripts/kallsyms.c for a more complete description)
65305 */
65306+#ifdef CONFIG_GRKERNSEC_HIDESYM
65307+#define __INCLUDED_BY_HIDESYM 1
65308+#endif
65309 #include <linux/kallsyms.h>
65310 #include <linux/module.h>
65311 #include <linux/init.h>
65312@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
65313
65314 static inline int is_kernel_inittext(unsigned long addr)
65315 {
65316+ if (system_state != SYSTEM_BOOTING)
65317+ return 0;
65318+
65319 if (addr >= (unsigned long)_sinittext
65320 && addr <= (unsigned long)_einittext)
65321 return 1;
65322 return 0;
65323 }
65324
65325+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65326+#ifdef CONFIG_MODULES
65327+static inline int is_module_text(unsigned long addr)
65328+{
65329+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
65330+ return 1;
65331+
65332+ addr = ktla_ktva(addr);
65333+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
65334+}
65335+#else
65336+static inline int is_module_text(unsigned long addr)
65337+{
65338+ return 0;
65339+}
65340+#endif
65341+#endif
65342+
65343 static inline int is_kernel_text(unsigned long addr)
65344 {
65345 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
65346@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
65347
65348 static inline int is_kernel(unsigned long addr)
65349 {
65350+
65351+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65352+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
65353+ return 1;
65354+
65355+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
65356+#else
65357 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
65358+#endif
65359+
65360 return 1;
65361 return in_gate_area_no_mm(addr);
65362 }
65363
65364 static int is_ksym_addr(unsigned long addr)
65365 {
65366+
65367+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65368+ if (is_module_text(addr))
65369+ return 0;
65370+#endif
65371+
65372 if (all_var)
65373 return is_kernel(addr);
65374
65375@@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
65376
65377 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
65378 {
65379- iter->name[0] = '\0';
65380 iter->nameoff = get_symbol_offset(new_pos);
65381 iter->pos = new_pos;
65382 }
65383@@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
65384 {
65385 struct kallsym_iter *iter = m->private;
65386
65387+#ifdef CONFIG_GRKERNSEC_HIDESYM
65388+ if (current_uid())
65389+ return 0;
65390+#endif
65391+
65392 /* Some debugging symbols have no name. Ignore them. */
65393 if (!iter->name[0])
65394 return 0;
65395@@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
65396 struct kallsym_iter *iter;
65397 int ret;
65398
65399- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
65400+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
65401 if (!iter)
65402 return -ENOMEM;
65403 reset_iter(iter, 0);
65404diff --git a/kernel/kexec.c b/kernel/kexec.c
65405index 7b08867..3bac516 100644
65406--- a/kernel/kexec.c
65407+++ b/kernel/kexec.c
65408@@ -1047,7 +1047,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
65409 unsigned long flags)
65410 {
65411 struct compat_kexec_segment in;
65412- struct kexec_segment out, __user *ksegments;
65413+ struct kexec_segment out;
65414+ struct kexec_segment __user *ksegments;
65415 unsigned long i, result;
65416
65417 /* Don't allow clients that don't understand the native
65418diff --git a/kernel/kmod.c b/kernel/kmod.c
65419index a0a8854..642b106 100644
65420--- a/kernel/kmod.c
65421+++ b/kernel/kmod.c
65422@@ -75,13 +75,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
65423 * If module auto-loading support is disabled then this function
65424 * becomes a no-operation.
65425 */
65426-int __request_module(bool wait, const char *fmt, ...)
65427+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
65428 {
65429- va_list args;
65430 char module_name[MODULE_NAME_LEN];
65431 unsigned int max_modprobes;
65432 int ret;
65433- char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
65434+ char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
65435 static char *envp[] = { "HOME=/",
65436 "TERM=linux",
65437 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
65438@@ -90,9 +89,7 @@ int __request_module(bool wait, const char *fmt, ...)
65439 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
65440 static int kmod_loop_msg;
65441
65442- va_start(args, fmt);
65443- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
65444- va_end(args);
65445+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
65446 if (ret >= MODULE_NAME_LEN)
65447 return -ENAMETOOLONG;
65448
65449@@ -100,6 +97,20 @@ int __request_module(bool wait, const char *fmt, ...)
65450 if (ret)
65451 return ret;
65452
65453+#ifdef CONFIG_GRKERNSEC_MODHARDEN
65454+ if (!current_uid()) {
65455+ /* hack to workaround consolekit/udisks stupidity */
65456+ read_lock(&tasklist_lock);
65457+ if (!strcmp(current->comm, "mount") &&
65458+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
65459+ read_unlock(&tasklist_lock);
65460+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
65461+ return -EPERM;
65462+ }
65463+ read_unlock(&tasklist_lock);
65464+ }
65465+#endif
65466+
65467 /* If modprobe needs a service that is in a module, we get a recursive
65468 * loop. Limit the number of running kmod threads to max_threads/2 or
65469 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
65470@@ -135,6 +146,47 @@ int __request_module(bool wait, const char *fmt, ...)
65471 atomic_dec(&kmod_concurrent);
65472 return ret;
65473 }
65474+
65475+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
65476+{
65477+ va_list args;
65478+ int ret;
65479+
65480+ va_start(args, fmt);
65481+ ret = ____request_module(wait, module_param, fmt, args);
65482+ va_end(args);
65483+
65484+ return ret;
65485+}
65486+
65487+int __request_module(bool wait, const char *fmt, ...)
65488+{
65489+ va_list args;
65490+ int ret;
65491+
65492+#ifdef CONFIG_GRKERNSEC_MODHARDEN
65493+ if (current_uid()) {
65494+ char module_param[MODULE_NAME_LEN];
65495+
65496+ memset(module_param, 0, sizeof(module_param));
65497+
65498+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
65499+
65500+ va_start(args, fmt);
65501+ ret = ____request_module(wait, module_param, fmt, args);
65502+ va_end(args);
65503+
65504+ return ret;
65505+ }
65506+#endif
65507+
65508+ va_start(args, fmt);
65509+ ret = ____request_module(wait, NULL, fmt, args);
65510+ va_end(args);
65511+
65512+ return ret;
65513+}
65514+
65515 EXPORT_SYMBOL(__request_module);
65516 #endif /* CONFIG_MODULES */
65517
65518@@ -224,7 +276,7 @@ static int wait_for_helper(void *data)
65519 *
65520 * Thus the __user pointer cast is valid here.
65521 */
65522- sys_wait4(pid, (int __user *)&ret, 0, NULL);
65523+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
65524
65525 /*
65526 * If ret is 0, either ____call_usermodehelper failed and the
65527diff --git a/kernel/kprobes.c b/kernel/kprobes.c
65528index c62b854..cb67968 100644
65529--- a/kernel/kprobes.c
65530+++ b/kernel/kprobes.c
65531@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
65532 * kernel image and loaded module images reside. This is required
65533 * so x86_64 can correctly handle the %rip-relative fixups.
65534 */
65535- kip->insns = module_alloc(PAGE_SIZE);
65536+ kip->insns = module_alloc_exec(PAGE_SIZE);
65537 if (!kip->insns) {
65538 kfree(kip);
65539 return NULL;
65540@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
65541 */
65542 if (!list_is_singular(&kip->list)) {
65543 list_del(&kip->list);
65544- module_free(NULL, kip->insns);
65545+ module_free_exec(NULL, kip->insns);
65546 kfree(kip);
65547 }
65548 return 1;
65549@@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
65550 {
65551 int i, err = 0;
65552 unsigned long offset = 0, size = 0;
65553- char *modname, namebuf[128];
65554+ char *modname, namebuf[KSYM_NAME_LEN];
65555 const char *symbol_name;
65556 void *addr;
65557 struct kprobe_blackpoint *kb;
65558@@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
65559 const char *sym = NULL;
65560 unsigned int i = *(loff_t *) v;
65561 unsigned long offset = 0;
65562- char *modname, namebuf[128];
65563+ char *modname, namebuf[KSYM_NAME_LEN];
65564
65565 head = &kprobe_table[i];
65566 preempt_disable();
65567diff --git a/kernel/lockdep.c b/kernel/lockdep.c
65568index 8889f7d..95319b7 100644
65569--- a/kernel/lockdep.c
65570+++ b/kernel/lockdep.c
65571@@ -590,6 +590,10 @@ static int static_obj(void *obj)
65572 end = (unsigned long) &_end,
65573 addr = (unsigned long) obj;
65574
65575+#ifdef CONFIG_PAX_KERNEXEC
65576+ start = ktla_ktva(start);
65577+#endif
65578+
65579 /*
65580 * static variable?
65581 */
65582@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
65583 if (!static_obj(lock->key)) {
65584 debug_locks_off();
65585 printk("INFO: trying to register non-static key.\n");
65586+ printk("lock:%pS key:%pS.\n", lock, lock->key);
65587 printk("the code is fine but needs lockdep annotation.\n");
65588 printk("turning off the locking correctness validator.\n");
65589 dump_stack();
65590@@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
65591 if (!class)
65592 return 0;
65593 }
65594- atomic_inc((atomic_t *)&class->ops);
65595+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
65596 if (very_verbose(class)) {
65597 printk("\nacquire class [%p] %s", class->key, class->name);
65598 if (class->name_version > 1)
65599diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
65600index 91c32a0..b2c71c5 100644
65601--- a/kernel/lockdep_proc.c
65602+++ b/kernel/lockdep_proc.c
65603@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
65604
65605 static void print_name(struct seq_file *m, struct lock_class *class)
65606 {
65607- char str[128];
65608+ char str[KSYM_NAME_LEN];
65609 const char *name = class->name;
65610
65611 if (!name) {
65612diff --git a/kernel/module.c b/kernel/module.c
65613index 3d56b6f..2a22bd0 100644
65614--- a/kernel/module.c
65615+++ b/kernel/module.c
65616@@ -58,6 +58,7 @@
65617 #include <linux/jump_label.h>
65618 #include <linux/pfn.h>
65619 #include <linux/bsearch.h>
65620+#include <linux/grsecurity.h>
65621
65622 #define CREATE_TRACE_POINTS
65623 #include <trace/events/module.h>
65624@@ -113,7 +114,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
65625
65626 /* Bounds of module allocation, for speeding __module_address.
65627 * Protected by module_mutex. */
65628-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
65629+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
65630+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
65631
65632 int register_module_notifier(struct notifier_block * nb)
65633 {
65634@@ -277,7 +279,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
65635 return true;
65636
65637 list_for_each_entry_rcu(mod, &modules, list) {
65638- struct symsearch arr[] = {
65639+ struct symsearch modarr[] = {
65640 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
65641 NOT_GPL_ONLY, false },
65642 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
65643@@ -299,7 +301,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
65644 #endif
65645 };
65646
65647- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
65648+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
65649 return true;
65650 }
65651 return false;
65652@@ -431,7 +433,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
65653 static int percpu_modalloc(struct module *mod,
65654 unsigned long size, unsigned long align)
65655 {
65656- if (align > PAGE_SIZE) {
65657+ if (align-1 >= PAGE_SIZE) {
65658 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
65659 mod->name, align, PAGE_SIZE);
65660 align = PAGE_SIZE;
65661@@ -1001,7 +1003,7 @@ struct module_attribute module_uevent =
65662 static ssize_t show_coresize(struct module_attribute *mattr,
65663 struct module_kobject *mk, char *buffer)
65664 {
65665- return sprintf(buffer, "%u\n", mk->mod->core_size);
65666+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
65667 }
65668
65669 static struct module_attribute modinfo_coresize =
65670@@ -1010,7 +1012,7 @@ static struct module_attribute modinfo_coresize =
65671 static ssize_t show_initsize(struct module_attribute *mattr,
65672 struct module_kobject *mk, char *buffer)
65673 {
65674- return sprintf(buffer, "%u\n", mk->mod->init_size);
65675+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
65676 }
65677
65678 static struct module_attribute modinfo_initsize =
65679@@ -1224,7 +1226,7 @@ resolve_symbol_wait(struct module *mod,
65680 */
65681 #ifdef CONFIG_SYSFS
65682
65683-#ifdef CONFIG_KALLSYMS
65684+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65685 static inline bool sect_empty(const Elf_Shdr *sect)
65686 {
65687 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
65688@@ -1690,21 +1692,21 @@ static void set_section_ro_nx(void *base,
65689
65690 static void unset_module_core_ro_nx(struct module *mod)
65691 {
65692- set_page_attributes(mod->module_core + mod->core_text_size,
65693- mod->module_core + mod->core_size,
65694+ set_page_attributes(mod->module_core_rw,
65695+ mod->module_core_rw + mod->core_size_rw,
65696 set_memory_x);
65697- set_page_attributes(mod->module_core,
65698- mod->module_core + mod->core_ro_size,
65699+ set_page_attributes(mod->module_core_rx,
65700+ mod->module_core_rx + mod->core_size_rx,
65701 set_memory_rw);
65702 }
65703
65704 static void unset_module_init_ro_nx(struct module *mod)
65705 {
65706- set_page_attributes(mod->module_init + mod->init_text_size,
65707- mod->module_init + mod->init_size,
65708+ set_page_attributes(mod->module_init_rw,
65709+ mod->module_init_rw + mod->init_size_rw,
65710 set_memory_x);
65711- set_page_attributes(mod->module_init,
65712- mod->module_init + mod->init_ro_size,
65713+ set_page_attributes(mod->module_init_rx,
65714+ mod->module_init_rx + mod->init_size_rx,
65715 set_memory_rw);
65716 }
65717
65718@@ -1715,14 +1717,14 @@ void set_all_modules_text_rw(void)
65719
65720 mutex_lock(&module_mutex);
65721 list_for_each_entry_rcu(mod, &modules, list) {
65722- if ((mod->module_core) && (mod->core_text_size)) {
65723- set_page_attributes(mod->module_core,
65724- mod->module_core + mod->core_text_size,
65725+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
65726+ set_page_attributes(mod->module_core_rx,
65727+ mod->module_core_rx + mod->core_size_rx,
65728 set_memory_rw);
65729 }
65730- if ((mod->module_init) && (mod->init_text_size)) {
65731- set_page_attributes(mod->module_init,
65732- mod->module_init + mod->init_text_size,
65733+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
65734+ set_page_attributes(mod->module_init_rx,
65735+ mod->module_init_rx + mod->init_size_rx,
65736 set_memory_rw);
65737 }
65738 }
65739@@ -1736,14 +1738,14 @@ void set_all_modules_text_ro(void)
65740
65741 mutex_lock(&module_mutex);
65742 list_for_each_entry_rcu(mod, &modules, list) {
65743- if ((mod->module_core) && (mod->core_text_size)) {
65744- set_page_attributes(mod->module_core,
65745- mod->module_core + mod->core_text_size,
65746+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
65747+ set_page_attributes(mod->module_core_rx,
65748+ mod->module_core_rx + mod->core_size_rx,
65749 set_memory_ro);
65750 }
65751- if ((mod->module_init) && (mod->init_text_size)) {
65752- set_page_attributes(mod->module_init,
65753- mod->module_init + mod->init_text_size,
65754+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
65755+ set_page_attributes(mod->module_init_rx,
65756+ mod->module_init_rx + mod->init_size_rx,
65757 set_memory_ro);
65758 }
65759 }
65760@@ -1789,16 +1791,19 @@ static void free_module(struct module *mod)
65761
65762 /* This may be NULL, but that's OK */
65763 unset_module_init_ro_nx(mod);
65764- module_free(mod, mod->module_init);
65765+ module_free(mod, mod->module_init_rw);
65766+ module_free_exec(mod, mod->module_init_rx);
65767 kfree(mod->args);
65768 percpu_modfree(mod);
65769
65770 /* Free lock-classes: */
65771- lockdep_free_key_range(mod->module_core, mod->core_size);
65772+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
65773+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
65774
65775 /* Finally, free the core (containing the module structure) */
65776 unset_module_core_ro_nx(mod);
65777- module_free(mod, mod->module_core);
65778+ module_free_exec(mod, mod->module_core_rx);
65779+ module_free(mod, mod->module_core_rw);
65780
65781 #ifdef CONFIG_MPU
65782 update_protections(current->mm);
65783@@ -1867,10 +1872,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
65784 unsigned int i;
65785 int ret = 0;
65786 const struct kernel_symbol *ksym;
65787+#ifdef CONFIG_GRKERNSEC_MODHARDEN
65788+ int is_fs_load = 0;
65789+ int register_filesystem_found = 0;
65790+ char *p;
65791+
65792+ p = strstr(mod->args, "grsec_modharden_fs");
65793+ if (p) {
65794+ char *endptr = p + strlen("grsec_modharden_fs");
65795+ /* copy \0 as well */
65796+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
65797+ is_fs_load = 1;
65798+ }
65799+#endif
65800
65801 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
65802 const char *name = info->strtab + sym[i].st_name;
65803
65804+#ifdef CONFIG_GRKERNSEC_MODHARDEN
65805+ /* it's a real shame this will never get ripped and copied
65806+ upstream! ;(
65807+ */
65808+ if (is_fs_load && !strcmp(name, "register_filesystem"))
65809+ register_filesystem_found = 1;
65810+#endif
65811+
65812 switch (sym[i].st_shndx) {
65813 case SHN_COMMON:
65814 /* We compiled with -fno-common. These are not
65815@@ -1891,7 +1917,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
65816 ksym = resolve_symbol_wait(mod, info, name);
65817 /* Ok if resolved. */
65818 if (ksym && !IS_ERR(ksym)) {
65819+ pax_open_kernel();
65820 sym[i].st_value = ksym->value;
65821+ pax_close_kernel();
65822 break;
65823 }
65824
65825@@ -1910,11 +1938,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
65826 secbase = (unsigned long)mod_percpu(mod);
65827 else
65828 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
65829+ pax_open_kernel();
65830 sym[i].st_value += secbase;
65831+ pax_close_kernel();
65832 break;
65833 }
65834 }
65835
65836+#ifdef CONFIG_GRKERNSEC_MODHARDEN
65837+ if (is_fs_load && !register_filesystem_found) {
65838+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
65839+ ret = -EPERM;
65840+ }
65841+#endif
65842+
65843 return ret;
65844 }
65845
65846@@ -2018,22 +2055,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
65847 || s->sh_entsize != ~0UL
65848 || strstarts(sname, ".init"))
65849 continue;
65850- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
65851+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
65852+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
65853+ else
65854+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
65855 pr_debug("\t%s\n", sname);
65856 }
65857- switch (m) {
65858- case 0: /* executable */
65859- mod->core_size = debug_align(mod->core_size);
65860- mod->core_text_size = mod->core_size;
65861- break;
65862- case 1: /* RO: text and ro-data */
65863- mod->core_size = debug_align(mod->core_size);
65864- mod->core_ro_size = mod->core_size;
65865- break;
65866- case 3: /* whole core */
65867- mod->core_size = debug_align(mod->core_size);
65868- break;
65869- }
65870 }
65871
65872 pr_debug("Init section allocation order:\n");
65873@@ -2047,23 +2074,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
65874 || s->sh_entsize != ~0UL
65875 || !strstarts(sname, ".init"))
65876 continue;
65877- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
65878- | INIT_OFFSET_MASK);
65879+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
65880+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
65881+ else
65882+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
65883+ s->sh_entsize |= INIT_OFFSET_MASK;
65884 pr_debug("\t%s\n", sname);
65885 }
65886- switch (m) {
65887- case 0: /* executable */
65888- mod->init_size = debug_align(mod->init_size);
65889- mod->init_text_size = mod->init_size;
65890- break;
65891- case 1: /* RO: text and ro-data */
65892- mod->init_size = debug_align(mod->init_size);
65893- mod->init_ro_size = mod->init_size;
65894- break;
65895- case 3: /* whole init */
65896- mod->init_size = debug_align(mod->init_size);
65897- break;
65898- }
65899 }
65900 }
65901
65902@@ -2235,7 +2252,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
65903
65904 /* Put symbol section at end of init part of module. */
65905 symsect->sh_flags |= SHF_ALLOC;
65906- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
65907+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
65908 info->index.sym) | INIT_OFFSET_MASK;
65909 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
65910
65911@@ -2250,13 +2267,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
65912 }
65913
65914 /* Append room for core symbols at end of core part. */
65915- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
65916- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
65917- mod->core_size += strtab_size;
65918+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
65919+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
65920+ mod->core_size_rx += strtab_size;
65921
65922 /* Put string table section at end of init part of module. */
65923 strsect->sh_flags |= SHF_ALLOC;
65924- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
65925+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
65926 info->index.str) | INIT_OFFSET_MASK;
65927 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
65928 }
65929@@ -2274,12 +2291,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
65930 /* Make sure we get permanent strtab: don't use info->strtab. */
65931 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
65932
65933+ pax_open_kernel();
65934+
65935 /* Set types up while we still have access to sections. */
65936 for (i = 0; i < mod->num_symtab; i++)
65937 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
65938
65939- mod->core_symtab = dst = mod->module_core + info->symoffs;
65940- mod->core_strtab = s = mod->module_core + info->stroffs;
65941+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
65942+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
65943 src = mod->symtab;
65944 *dst = *src;
65945 *s++ = 0;
65946@@ -2292,6 +2311,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
65947 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
65948 }
65949 mod->core_num_syms = ndst;
65950+
65951+ pax_close_kernel();
65952 }
65953 #else
65954 static inline void layout_symtab(struct module *mod, struct load_info *info)
65955@@ -2325,17 +2346,33 @@ void * __weak module_alloc(unsigned long size)
65956 return size == 0 ? NULL : vmalloc_exec(size);
65957 }
65958
65959-static void *module_alloc_update_bounds(unsigned long size)
65960+static void *module_alloc_update_bounds_rw(unsigned long size)
65961 {
65962 void *ret = module_alloc(size);
65963
65964 if (ret) {
65965 mutex_lock(&module_mutex);
65966 /* Update module bounds. */
65967- if ((unsigned long)ret < module_addr_min)
65968- module_addr_min = (unsigned long)ret;
65969- if ((unsigned long)ret + size > module_addr_max)
65970- module_addr_max = (unsigned long)ret + size;
65971+ if ((unsigned long)ret < module_addr_min_rw)
65972+ module_addr_min_rw = (unsigned long)ret;
65973+ if ((unsigned long)ret + size > module_addr_max_rw)
65974+ module_addr_max_rw = (unsigned long)ret + size;
65975+ mutex_unlock(&module_mutex);
65976+ }
65977+ return ret;
65978+}
65979+
65980+static void *module_alloc_update_bounds_rx(unsigned long size)
65981+{
65982+ void *ret = module_alloc_exec(size);
65983+
65984+ if (ret) {
65985+ mutex_lock(&module_mutex);
65986+ /* Update module bounds. */
65987+ if ((unsigned long)ret < module_addr_min_rx)
65988+ module_addr_min_rx = (unsigned long)ret;
65989+ if ((unsigned long)ret + size > module_addr_max_rx)
65990+ module_addr_max_rx = (unsigned long)ret + size;
65991 mutex_unlock(&module_mutex);
65992 }
65993 return ret;
65994@@ -2512,8 +2549,14 @@ static struct module *setup_load_info(struct load_info *info)
65995 static int check_modinfo(struct module *mod, struct load_info *info)
65996 {
65997 const char *modmagic = get_modinfo(info, "vermagic");
65998+ const char *license = get_modinfo(info, "license");
65999 int err;
66000
66001+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
66002+ if (!license || !license_is_gpl_compatible(license))
66003+ return -ENOEXEC;
66004+#endif
66005+
66006 /* This is allowed: modprobe --force will invalidate it. */
66007 if (!modmagic) {
66008 err = try_to_force_load(mod, "bad vermagic");
66009@@ -2536,7 +2579,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
66010 }
66011
66012 /* Set up license info based on the info section */
66013- set_license(mod, get_modinfo(info, "license"));
66014+ set_license(mod, license);
66015
66016 return 0;
66017 }
66018@@ -2630,7 +2673,7 @@ static int move_module(struct module *mod, struct load_info *info)
66019 void *ptr;
66020
66021 /* Do the allocs. */
66022- ptr = module_alloc_update_bounds(mod->core_size);
66023+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
66024 /*
66025 * The pointer to this block is stored in the module structure
66026 * which is inside the block. Just mark it as not being a
66027@@ -2640,23 +2683,50 @@ static int move_module(struct module *mod, struct load_info *info)
66028 if (!ptr)
66029 return -ENOMEM;
66030
66031- memset(ptr, 0, mod->core_size);
66032- mod->module_core = ptr;
66033+ memset(ptr, 0, mod->core_size_rw);
66034+ mod->module_core_rw = ptr;
66035
66036- ptr = module_alloc_update_bounds(mod->init_size);
66037+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
66038 /*
66039 * The pointer to this block is stored in the module structure
66040 * which is inside the block. This block doesn't need to be
66041 * scanned as it contains data and code that will be freed
66042 * after the module is initialized.
66043 */
66044- kmemleak_ignore(ptr);
66045- if (!ptr && mod->init_size) {
66046- module_free(mod, mod->module_core);
66047+ kmemleak_not_leak(ptr);
66048+ if (!ptr && mod->init_size_rw) {
66049+ module_free(mod, mod->module_core_rw);
66050 return -ENOMEM;
66051 }
66052- memset(ptr, 0, mod->init_size);
66053- mod->module_init = ptr;
66054+ memset(ptr, 0, mod->init_size_rw);
66055+ mod->module_init_rw = ptr;
66056+
66057+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
66058+ kmemleak_not_leak(ptr);
66059+ if (!ptr) {
66060+ module_free(mod, mod->module_init_rw);
66061+ module_free(mod, mod->module_core_rw);
66062+ return -ENOMEM;
66063+ }
66064+
66065+ pax_open_kernel();
66066+ memset(ptr, 0, mod->core_size_rx);
66067+ pax_close_kernel();
66068+ mod->module_core_rx = ptr;
66069+
66070+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
66071+ kmemleak_not_leak(ptr);
66072+ if (!ptr && mod->init_size_rx) {
66073+ module_free_exec(mod, mod->module_core_rx);
66074+ module_free(mod, mod->module_init_rw);
66075+ module_free(mod, mod->module_core_rw);
66076+ return -ENOMEM;
66077+ }
66078+
66079+ pax_open_kernel();
66080+ memset(ptr, 0, mod->init_size_rx);
66081+ pax_close_kernel();
66082+ mod->module_init_rx = ptr;
66083
66084 /* Transfer each section which specifies SHF_ALLOC */
66085 pr_debug("final section addresses:\n");
66086@@ -2667,16 +2737,45 @@ static int move_module(struct module *mod, struct load_info *info)
66087 if (!(shdr->sh_flags & SHF_ALLOC))
66088 continue;
66089
66090- if (shdr->sh_entsize & INIT_OFFSET_MASK)
66091- dest = mod->module_init
66092- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66093- else
66094- dest = mod->module_core + shdr->sh_entsize;
66095+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
66096+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
66097+ dest = mod->module_init_rw
66098+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66099+ else
66100+ dest = mod->module_init_rx
66101+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66102+ } else {
66103+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
66104+ dest = mod->module_core_rw + shdr->sh_entsize;
66105+ else
66106+ dest = mod->module_core_rx + shdr->sh_entsize;
66107+ }
66108+
66109+ if (shdr->sh_type != SHT_NOBITS) {
66110+
66111+#ifdef CONFIG_PAX_KERNEXEC
66112+#ifdef CONFIG_X86_64
66113+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
66114+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
66115+#endif
66116+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
66117+ pax_open_kernel();
66118+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
66119+ pax_close_kernel();
66120+ } else
66121+#endif
66122
66123- if (shdr->sh_type != SHT_NOBITS)
66124 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
66125+ }
66126 /* Update sh_addr to point to copy in image. */
66127- shdr->sh_addr = (unsigned long)dest;
66128+
66129+#ifdef CONFIG_PAX_KERNEXEC
66130+ if (shdr->sh_flags & SHF_EXECINSTR)
66131+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
66132+ else
66133+#endif
66134+
66135+ shdr->sh_addr = (unsigned long)dest;
66136 pr_debug("\t0x%lx %s\n",
66137 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
66138 }
66139@@ -2727,12 +2826,12 @@ static void flush_module_icache(const struct module *mod)
66140 * Do it before processing of module parameters, so the module
66141 * can provide parameter accessor functions of its own.
66142 */
66143- if (mod->module_init)
66144- flush_icache_range((unsigned long)mod->module_init,
66145- (unsigned long)mod->module_init
66146- + mod->init_size);
66147- flush_icache_range((unsigned long)mod->module_core,
66148- (unsigned long)mod->module_core + mod->core_size);
66149+ if (mod->module_init_rx)
66150+ flush_icache_range((unsigned long)mod->module_init_rx,
66151+ (unsigned long)mod->module_init_rx
66152+ + mod->init_size_rx);
66153+ flush_icache_range((unsigned long)mod->module_core_rx,
66154+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
66155
66156 set_fs(old_fs);
66157 }
66158@@ -2802,8 +2901,10 @@ out:
66159 static void module_deallocate(struct module *mod, struct load_info *info)
66160 {
66161 percpu_modfree(mod);
66162- module_free(mod, mod->module_init);
66163- module_free(mod, mod->module_core);
66164+ module_free_exec(mod, mod->module_init_rx);
66165+ module_free_exec(mod, mod->module_core_rx);
66166+ module_free(mod, mod->module_init_rw);
66167+ module_free(mod, mod->module_core_rw);
66168 }
66169
66170 int __weak module_finalize(const Elf_Ehdr *hdr,
66171@@ -2867,9 +2968,38 @@ static struct module *load_module(void __user *umod,
66172 if (err)
66173 goto free_unload;
66174
66175+ /* Now copy in args */
66176+ mod->args = strndup_user(uargs, ~0UL >> 1);
66177+ if (IS_ERR(mod->args)) {
66178+ err = PTR_ERR(mod->args);
66179+ goto free_unload;
66180+ }
66181+
66182 /* Set up MODINFO_ATTR fields */
66183 setup_modinfo(mod, &info);
66184
66185+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66186+ {
66187+ char *p, *p2;
66188+
66189+ if (strstr(mod->args, "grsec_modharden_netdev")) {
66190+ 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);
66191+ err = -EPERM;
66192+ goto free_modinfo;
66193+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
66194+ p += strlen("grsec_modharden_normal");
66195+ p2 = strstr(p, "_");
66196+ if (p2) {
66197+ *p2 = '\0';
66198+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
66199+ *p2 = '_';
66200+ }
66201+ err = -EPERM;
66202+ goto free_modinfo;
66203+ }
66204+ }
66205+#endif
66206+
66207 /* Fix up syms, so that st_value is a pointer to location. */
66208 err = simplify_symbols(mod, &info);
66209 if (err < 0)
66210@@ -2885,13 +3015,6 @@ static struct module *load_module(void __user *umod,
66211
66212 flush_module_icache(mod);
66213
66214- /* Now copy in args */
66215- mod->args = strndup_user(uargs, ~0UL >> 1);
66216- if (IS_ERR(mod->args)) {
66217- err = PTR_ERR(mod->args);
66218- goto free_arch_cleanup;
66219- }
66220-
66221 /* Mark state as coming so strong_try_module_get() ignores us. */
66222 mod->state = MODULE_STATE_COMING;
66223
66224@@ -2948,11 +3071,10 @@ static struct module *load_module(void __user *umod,
66225 unlock:
66226 mutex_unlock(&module_mutex);
66227 synchronize_sched();
66228- kfree(mod->args);
66229- free_arch_cleanup:
66230 module_arch_cleanup(mod);
66231 free_modinfo:
66232 free_modinfo(mod);
66233+ kfree(mod->args);
66234 free_unload:
66235 module_unload_free(mod);
66236 free_module:
66237@@ -2993,16 +3115,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
66238 MODULE_STATE_COMING, mod);
66239
66240 /* Set RO and NX regions for core */
66241- set_section_ro_nx(mod->module_core,
66242- mod->core_text_size,
66243- mod->core_ro_size,
66244- mod->core_size);
66245+ set_section_ro_nx(mod->module_core_rx,
66246+ mod->core_size_rx,
66247+ mod->core_size_rx,
66248+ mod->core_size_rx);
66249
66250 /* Set RO and NX regions for init */
66251- set_section_ro_nx(mod->module_init,
66252- mod->init_text_size,
66253- mod->init_ro_size,
66254- mod->init_size);
66255+ set_section_ro_nx(mod->module_init_rx,
66256+ mod->init_size_rx,
66257+ mod->init_size_rx,
66258+ mod->init_size_rx);
66259
66260 do_mod_ctors(mod);
66261 /* Start the module */
66262@@ -3048,11 +3170,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
66263 mod->strtab = mod->core_strtab;
66264 #endif
66265 unset_module_init_ro_nx(mod);
66266- module_free(mod, mod->module_init);
66267- mod->module_init = NULL;
66268- mod->init_size = 0;
66269- mod->init_ro_size = 0;
66270- mod->init_text_size = 0;
66271+ module_free(mod, mod->module_init_rw);
66272+ module_free_exec(mod, mod->module_init_rx);
66273+ mod->module_init_rw = NULL;
66274+ mod->module_init_rx = NULL;
66275+ mod->init_size_rw = 0;
66276+ mod->init_size_rx = 0;
66277 mutex_unlock(&module_mutex);
66278
66279 return 0;
66280@@ -3083,10 +3206,16 @@ static const char *get_ksymbol(struct module *mod,
66281 unsigned long nextval;
66282
66283 /* At worse, next value is at end of module */
66284- if (within_module_init(addr, mod))
66285- nextval = (unsigned long)mod->module_init+mod->init_text_size;
66286+ if (within_module_init_rx(addr, mod))
66287+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
66288+ else if (within_module_init_rw(addr, mod))
66289+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
66290+ else if (within_module_core_rx(addr, mod))
66291+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
66292+ else if (within_module_core_rw(addr, mod))
66293+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
66294 else
66295- nextval = (unsigned long)mod->module_core+mod->core_text_size;
66296+ return NULL;
66297
66298 /* Scan for closest preceding symbol, and next symbol. (ELF
66299 starts real symbols at 1). */
66300@@ -3321,7 +3450,7 @@ static int m_show(struct seq_file *m, void *p)
66301 char buf[8];
66302
66303 seq_printf(m, "%s %u",
66304- mod->name, mod->init_size + mod->core_size);
66305+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
66306 print_unload_info(m, mod);
66307
66308 /* Informative for users. */
66309@@ -3330,7 +3459,7 @@ static int m_show(struct seq_file *m, void *p)
66310 mod->state == MODULE_STATE_COMING ? "Loading":
66311 "Live");
66312 /* Used by oprofile and other similar tools. */
66313- seq_printf(m, " 0x%pK", mod->module_core);
66314+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
66315
66316 /* Taints info */
66317 if (mod->taints)
66318@@ -3366,7 +3495,17 @@ static const struct file_operations proc_modules_operations = {
66319
66320 static int __init proc_modules_init(void)
66321 {
66322+#ifndef CONFIG_GRKERNSEC_HIDESYM
66323+#ifdef CONFIG_GRKERNSEC_PROC_USER
66324+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
66325+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66326+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
66327+#else
66328 proc_create("modules", 0, NULL, &proc_modules_operations);
66329+#endif
66330+#else
66331+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
66332+#endif
66333 return 0;
66334 }
66335 module_init(proc_modules_init);
66336@@ -3425,12 +3564,12 @@ struct module *__module_address(unsigned long addr)
66337 {
66338 struct module *mod;
66339
66340- if (addr < module_addr_min || addr > module_addr_max)
66341+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
66342+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
66343 return NULL;
66344
66345 list_for_each_entry_rcu(mod, &modules, list)
66346- if (within_module_core(addr, mod)
66347- || within_module_init(addr, mod))
66348+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
66349 return mod;
66350 return NULL;
66351 }
66352@@ -3464,11 +3603,20 @@ bool is_module_text_address(unsigned long addr)
66353 */
66354 struct module *__module_text_address(unsigned long addr)
66355 {
66356- struct module *mod = __module_address(addr);
66357+ struct module *mod;
66358+
66359+#ifdef CONFIG_X86_32
66360+ addr = ktla_ktva(addr);
66361+#endif
66362+
66363+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
66364+ return NULL;
66365+
66366+ mod = __module_address(addr);
66367+
66368 if (mod) {
66369 /* Make sure it's within the text section. */
66370- if (!within(addr, mod->module_init, mod->init_text_size)
66371- && !within(addr, mod->module_core, mod->core_text_size))
66372+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
66373 mod = NULL;
66374 }
66375 return mod;
66376diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
66377index 7e3443f..b2a1e6b 100644
66378--- a/kernel/mutex-debug.c
66379+++ b/kernel/mutex-debug.c
66380@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
66381 }
66382
66383 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66384- struct thread_info *ti)
66385+ struct task_struct *task)
66386 {
66387 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
66388
66389 /* Mark the current thread as blocked on the lock: */
66390- ti->task->blocked_on = waiter;
66391+ task->blocked_on = waiter;
66392 }
66393
66394 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66395- struct thread_info *ti)
66396+ struct task_struct *task)
66397 {
66398 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
66399- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
66400- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
66401- ti->task->blocked_on = NULL;
66402+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
66403+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
66404+ task->blocked_on = NULL;
66405
66406 list_del_init(&waiter->list);
66407 waiter->task = NULL;
66408diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
66409index 0799fd3..d06ae3b 100644
66410--- a/kernel/mutex-debug.h
66411+++ b/kernel/mutex-debug.h
66412@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
66413 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
66414 extern void debug_mutex_add_waiter(struct mutex *lock,
66415 struct mutex_waiter *waiter,
66416- struct thread_info *ti);
66417+ struct task_struct *task);
66418 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66419- struct thread_info *ti);
66420+ struct task_struct *task);
66421 extern void debug_mutex_unlock(struct mutex *lock);
66422 extern void debug_mutex_init(struct mutex *lock, const char *name,
66423 struct lock_class_key *key);
66424diff --git a/kernel/mutex.c b/kernel/mutex.c
66425index 89096dd..f91ebc5 100644
66426--- a/kernel/mutex.c
66427+++ b/kernel/mutex.c
66428@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66429 spin_lock_mutex(&lock->wait_lock, flags);
66430
66431 debug_mutex_lock_common(lock, &waiter);
66432- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
66433+ debug_mutex_add_waiter(lock, &waiter, task);
66434
66435 /* add waiting tasks to the end of the waitqueue (FIFO): */
66436 list_add_tail(&waiter.list, &lock->wait_list);
66437@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66438 * TASK_UNINTERRUPTIBLE case.)
66439 */
66440 if (unlikely(signal_pending_state(state, task))) {
66441- mutex_remove_waiter(lock, &waiter,
66442- task_thread_info(task));
66443+ mutex_remove_waiter(lock, &waiter, task);
66444 mutex_release(&lock->dep_map, 1, ip);
66445 spin_unlock_mutex(&lock->wait_lock, flags);
66446
66447@@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66448 done:
66449 lock_acquired(&lock->dep_map, ip);
66450 /* got the lock - rejoice! */
66451- mutex_remove_waiter(lock, &waiter, current_thread_info());
66452+ mutex_remove_waiter(lock, &waiter, task);
66453 mutex_set_owner(lock);
66454
66455 /* set it to 0 if there are no waiters left: */
66456diff --git a/kernel/padata.c b/kernel/padata.c
66457index b452599..5d68f4e 100644
66458--- a/kernel/padata.c
66459+++ b/kernel/padata.c
66460@@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_instance *pinst,
66461 padata->pd = pd;
66462 padata->cb_cpu = cb_cpu;
66463
66464- if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
66465- atomic_set(&pd->seq_nr, -1);
66466+ if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
66467+ atomic_set_unchecked(&pd->seq_nr, -1);
66468
66469- padata->seq_nr = atomic_inc_return(&pd->seq_nr);
66470+ padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
66471
66472 target_cpu = padata_cpu_hash(padata);
66473 queue = per_cpu_ptr(pd->pqueue, target_cpu);
66474@@ -444,7 +444,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
66475 padata_init_pqueues(pd);
66476 padata_init_squeues(pd);
66477 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
66478- atomic_set(&pd->seq_nr, -1);
66479+ atomic_set_unchecked(&pd->seq_nr, -1);
66480 atomic_set(&pd->reorder_objects, 0);
66481 atomic_set(&pd->refcnt, 0);
66482 pd->pinst = pinst;
66483diff --git a/kernel/panic.c b/kernel/panic.c
66484index 80aed44..f291d37 100644
66485--- a/kernel/panic.c
66486+++ b/kernel/panic.c
66487@@ -402,7 +402,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
66488 const char *board;
66489
66490 printk(KERN_WARNING "------------[ cut here ]------------\n");
66491- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
66492+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
66493 board = dmi_get_system_info(DMI_PRODUCT_NAME);
66494 if (board)
66495 printk(KERN_WARNING "Hardware name: %s\n", board);
66496@@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
66497 */
66498 void __stack_chk_fail(void)
66499 {
66500- panic("stack-protector: Kernel stack is corrupted in: %p\n",
66501+ dump_stack();
66502+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
66503 __builtin_return_address(0));
66504 }
66505 EXPORT_SYMBOL(__stack_chk_fail);
66506diff --git a/kernel/pid.c b/kernel/pid.c
66507index 9f08dfa..6765c40 100644
66508--- a/kernel/pid.c
66509+++ b/kernel/pid.c
66510@@ -33,6 +33,7 @@
66511 #include <linux/rculist.h>
66512 #include <linux/bootmem.h>
66513 #include <linux/hash.h>
66514+#include <linux/security.h>
66515 #include <linux/pid_namespace.h>
66516 #include <linux/init_task.h>
66517 #include <linux/syscalls.h>
66518@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
66519
66520 int pid_max = PID_MAX_DEFAULT;
66521
66522-#define RESERVED_PIDS 300
66523+#define RESERVED_PIDS 500
66524
66525 int pid_max_min = RESERVED_PIDS + 1;
66526 int pid_max_max = PID_MAX_LIMIT;
66527@@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
66528 */
66529 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
66530 {
66531+ struct task_struct *task;
66532+
66533 rcu_lockdep_assert(rcu_read_lock_held(),
66534 "find_task_by_pid_ns() needs rcu_read_lock()"
66535 " protection");
66536- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
66537+
66538+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
66539+
66540+ if (gr_pid_is_chrooted(task))
66541+ return NULL;
66542+
66543+ return task;
66544 }
66545
66546 struct task_struct *find_task_by_vpid(pid_t vnr)
66547@@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
66548 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
66549 }
66550
66551+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
66552+{
66553+ rcu_lockdep_assert(rcu_read_lock_held(),
66554+ "find_task_by_pid_ns() needs rcu_read_lock()"
66555+ " protection");
66556+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
66557+}
66558+
66559 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
66560 {
66561 struct pid *pid;
66562diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
66563index 125cb67..a4d1c30 100644
66564--- a/kernel/posix-cpu-timers.c
66565+++ b/kernel/posix-cpu-timers.c
66566@@ -6,6 +6,7 @@
66567 #include <linux/posix-timers.h>
66568 #include <linux/errno.h>
66569 #include <linux/math64.h>
66570+#include <linux/security.h>
66571 #include <asm/uaccess.h>
66572 #include <linux/kernel_stat.h>
66573 #include <trace/events/timer.h>
66574@@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
66575
66576 static __init int init_posix_cpu_timers(void)
66577 {
66578- struct k_clock process = {
66579+ static struct k_clock process = {
66580 .clock_getres = process_cpu_clock_getres,
66581 .clock_get = process_cpu_clock_get,
66582 .timer_create = process_cpu_timer_create,
66583 .nsleep = process_cpu_nsleep,
66584 .nsleep_restart = process_cpu_nsleep_restart,
66585 };
66586- struct k_clock thread = {
66587+ static struct k_clock thread = {
66588 .clock_getres = thread_cpu_clock_getres,
66589 .clock_get = thread_cpu_clock_get,
66590 .timer_create = thread_cpu_timer_create,
66591diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
66592index 69185ae..cc2847a 100644
66593--- a/kernel/posix-timers.c
66594+++ b/kernel/posix-timers.c
66595@@ -43,6 +43,7 @@
66596 #include <linux/idr.h>
66597 #include <linux/posix-clock.h>
66598 #include <linux/posix-timers.h>
66599+#include <linux/grsecurity.h>
66600 #include <linux/syscalls.h>
66601 #include <linux/wait.h>
66602 #include <linux/workqueue.h>
66603@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
66604 * which we beg off on and pass to do_sys_settimeofday().
66605 */
66606
66607-static struct k_clock posix_clocks[MAX_CLOCKS];
66608+static struct k_clock *posix_clocks[MAX_CLOCKS];
66609
66610 /*
66611 * These ones are defined below.
66612@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
66613 */
66614 static __init int init_posix_timers(void)
66615 {
66616- struct k_clock clock_realtime = {
66617+ static struct k_clock clock_realtime = {
66618 .clock_getres = hrtimer_get_res,
66619 .clock_get = posix_clock_realtime_get,
66620 .clock_set = posix_clock_realtime_set,
66621@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
66622 .timer_get = common_timer_get,
66623 .timer_del = common_timer_del,
66624 };
66625- struct k_clock clock_monotonic = {
66626+ static struct k_clock clock_monotonic = {
66627 .clock_getres = hrtimer_get_res,
66628 .clock_get = posix_ktime_get_ts,
66629 .nsleep = common_nsleep,
66630@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
66631 .timer_get = common_timer_get,
66632 .timer_del = common_timer_del,
66633 };
66634- struct k_clock clock_monotonic_raw = {
66635+ static struct k_clock clock_monotonic_raw = {
66636 .clock_getres = hrtimer_get_res,
66637 .clock_get = posix_get_monotonic_raw,
66638 };
66639- struct k_clock clock_realtime_coarse = {
66640+ static struct k_clock clock_realtime_coarse = {
66641 .clock_getres = posix_get_coarse_res,
66642 .clock_get = posix_get_realtime_coarse,
66643 };
66644- struct k_clock clock_monotonic_coarse = {
66645+ static struct k_clock clock_monotonic_coarse = {
66646 .clock_getres = posix_get_coarse_res,
66647 .clock_get = posix_get_monotonic_coarse,
66648 };
66649- struct k_clock clock_boottime = {
66650+ static struct k_clock clock_boottime = {
66651 .clock_getres = hrtimer_get_res,
66652 .clock_get = posix_get_boottime,
66653 .nsleep = common_nsleep,
66654@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
66655 return;
66656 }
66657
66658- posix_clocks[clock_id] = *new_clock;
66659+ posix_clocks[clock_id] = new_clock;
66660 }
66661 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
66662
66663@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
66664 return (id & CLOCKFD_MASK) == CLOCKFD ?
66665 &clock_posix_dynamic : &clock_posix_cpu;
66666
66667- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
66668+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
66669 return NULL;
66670- return &posix_clocks[id];
66671+ return posix_clocks[id];
66672 }
66673
66674 static int common_timer_create(struct k_itimer *new_timer)
66675@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
66676 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
66677 return -EFAULT;
66678
66679+ /* only the CLOCK_REALTIME clock can be set, all other clocks
66680+ have their clock_set fptr set to a nosettime dummy function
66681+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
66682+ call common_clock_set, which calls do_sys_settimeofday, which
66683+ we hook
66684+ */
66685+
66686 return kc->clock_set(which_clock, &new_tp);
66687 }
66688
66689diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
66690index d523593..68197a4 100644
66691--- a/kernel/power/poweroff.c
66692+++ b/kernel/power/poweroff.c
66693@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
66694 .enable_mask = SYSRQ_ENABLE_BOOT,
66695 };
66696
66697-static int pm_sysrq_init(void)
66698+static int __init pm_sysrq_init(void)
66699 {
66700 register_sysrq_key('o', &sysrq_poweroff_op);
66701 return 0;
66702diff --git a/kernel/power/process.c b/kernel/power/process.c
66703index 7e42645..3d43df1 100644
66704--- a/kernel/power/process.c
66705+++ b/kernel/power/process.c
66706@@ -32,6 +32,7 @@ static int try_to_freeze_tasks(bool user_only)
66707 u64 elapsed_csecs64;
66708 unsigned int elapsed_csecs;
66709 bool wakeup = false;
66710+ bool timedout = false;
66711
66712 do_gettimeofday(&start);
66713
66714@@ -42,6 +43,8 @@ static int try_to_freeze_tasks(bool user_only)
66715
66716 while (true) {
66717 todo = 0;
66718+ if (time_after(jiffies, end_time))
66719+ timedout = true;
66720 read_lock(&tasklist_lock);
66721 do_each_thread(g, p) {
66722 if (p == current || !freeze_task(p))
66723@@ -59,9 +62,13 @@ static int try_to_freeze_tasks(bool user_only)
66724 * try_to_stop() after schedule() in ptrace/signal
66725 * stop sees TIF_FREEZE.
66726 */
66727- if (!task_is_stopped_or_traced(p) &&
66728- !freezer_should_skip(p))
66729+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
66730 todo++;
66731+ if (timedout) {
66732+ printk(KERN_ERR "Task refusing to freeze:\n");
66733+ sched_show_task(p);
66734+ }
66735+ }
66736 } while_each_thread(g, p);
66737 read_unlock(&tasklist_lock);
66738
66739@@ -70,7 +77,7 @@ static int try_to_freeze_tasks(bool user_only)
66740 todo += wq_busy;
66741 }
66742
66743- if (!todo || time_after(jiffies, end_time))
66744+ if (!todo || timedout)
66745 break;
66746
66747 if (pm_wakeup_pending()) {
66748diff --git a/kernel/printk.c b/kernel/printk.c
66749index 32690a0..cd7c798 100644
66750--- a/kernel/printk.c
66751+++ b/kernel/printk.c
66752@@ -313,6 +313,11 @@ static int check_syslog_permissions(int type, bool from_file)
66753 if (from_file && type != SYSLOG_ACTION_OPEN)
66754 return 0;
66755
66756+#ifdef CONFIG_GRKERNSEC_DMESG
66757+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
66758+ return -EPERM;
66759+#endif
66760+
66761 if (syslog_action_restricted(type)) {
66762 if (capable(CAP_SYSLOG))
66763 return 0;
66764diff --git a/kernel/profile.c b/kernel/profile.c
66765index 76b8e77..a2930e8 100644
66766--- a/kernel/profile.c
66767+++ b/kernel/profile.c
66768@@ -39,7 +39,7 @@ struct profile_hit {
66769 /* Oprofile timer tick hook */
66770 static int (*timer_hook)(struct pt_regs *) __read_mostly;
66771
66772-static atomic_t *prof_buffer;
66773+static atomic_unchecked_t *prof_buffer;
66774 static unsigned long prof_len, prof_shift;
66775
66776 int prof_on __read_mostly;
66777@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
66778 hits[i].pc = 0;
66779 continue;
66780 }
66781- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
66782+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
66783 hits[i].hits = hits[i].pc = 0;
66784 }
66785 }
66786@@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
66787 * Add the current hit(s) and flush the write-queue out
66788 * to the global buffer:
66789 */
66790- atomic_add(nr_hits, &prof_buffer[pc]);
66791+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
66792 for (i = 0; i < NR_PROFILE_HIT; ++i) {
66793- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
66794+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
66795 hits[i].pc = hits[i].hits = 0;
66796 }
66797 out:
66798@@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
66799 {
66800 unsigned long pc;
66801 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
66802- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
66803+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
66804 }
66805 #endif /* !CONFIG_SMP */
66806
66807@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
66808 return -EFAULT;
66809 buf++; p++; count--; read++;
66810 }
66811- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
66812+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
66813 if (copy_to_user(buf, (void *)pnt, count))
66814 return -EFAULT;
66815 read += count;
66816@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
66817 }
66818 #endif
66819 profile_discard_flip_buffers();
66820- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
66821+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
66822 return count;
66823 }
66824
66825diff --git a/kernel/ptrace.c b/kernel/ptrace.c
66826index 00ab2ca..d237f61 100644
66827--- a/kernel/ptrace.c
66828+++ b/kernel/ptrace.c
66829@@ -285,7 +285,7 @@ static int ptrace_attach(struct task_struct *task, long request,
66830 task->ptrace = PT_PTRACED;
66831 if (seize)
66832 task->ptrace |= PT_SEIZED;
66833- if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
66834+ if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
66835 task->ptrace |= PT_PTRACE_CAP;
66836
66837 __ptrace_link(task, current);
66838@@ -491,7 +491,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
66839 break;
66840 return -EIO;
66841 }
66842- if (copy_to_user(dst, buf, retval))
66843+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
66844 return -EFAULT;
66845 copied += retval;
66846 src += retval;
66847@@ -688,7 +688,7 @@ int ptrace_request(struct task_struct *child, long request,
66848 bool seized = child->ptrace & PT_SEIZED;
66849 int ret = -EIO;
66850 siginfo_t siginfo, *si;
66851- void __user *datavp = (void __user *) data;
66852+ void __user *datavp = (__force void __user *) data;
66853 unsigned long __user *datalp = datavp;
66854 unsigned long flags;
66855
66856@@ -890,14 +890,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
66857 goto out;
66858 }
66859
66860+ if (gr_handle_ptrace(child, request)) {
66861+ ret = -EPERM;
66862+ goto out_put_task_struct;
66863+ }
66864+
66865 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
66866 ret = ptrace_attach(child, request, data);
66867 /*
66868 * Some architectures need to do book-keeping after
66869 * a ptrace attach.
66870 */
66871- if (!ret)
66872+ if (!ret) {
66873 arch_ptrace_attach(child);
66874+ gr_audit_ptrace(child);
66875+ }
66876 goto out_put_task_struct;
66877 }
66878
66879@@ -923,7 +930,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
66880 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
66881 if (copied != sizeof(tmp))
66882 return -EIO;
66883- return put_user(tmp, (unsigned long __user *)data);
66884+ return put_user(tmp, (__force unsigned long __user *)data);
66885 }
66886
66887 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
66888@@ -1033,14 +1040,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
66889 goto out;
66890 }
66891
66892+ if (gr_handle_ptrace(child, request)) {
66893+ ret = -EPERM;
66894+ goto out_put_task_struct;
66895+ }
66896+
66897 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
66898 ret = ptrace_attach(child, request, data);
66899 /*
66900 * Some architectures need to do book-keeping after
66901 * a ptrace attach.
66902 */
66903- if (!ret)
66904+ if (!ret) {
66905 arch_ptrace_attach(child);
66906+ gr_audit_ptrace(child);
66907+ }
66908 goto out_put_task_struct;
66909 }
66910
66911diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
66912index 977296d..c4744dc 100644
66913--- a/kernel/rcutiny.c
66914+++ b/kernel/rcutiny.c
66915@@ -46,7 +46,7 @@
66916 struct rcu_ctrlblk;
66917 static void invoke_rcu_callbacks(void);
66918 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
66919-static void rcu_process_callbacks(struct softirq_action *unused);
66920+static void rcu_process_callbacks(void);
66921 static void __call_rcu(struct rcu_head *head,
66922 void (*func)(struct rcu_head *rcu),
66923 struct rcu_ctrlblk *rcp);
66924@@ -297,7 +297,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
66925 rcu_is_callbacks_kthread()));
66926 }
66927
66928-static void rcu_process_callbacks(struct softirq_action *unused)
66929+static void rcu_process_callbacks(void)
66930 {
66931 __rcu_process_callbacks(&rcu_sched_ctrlblk);
66932 __rcu_process_callbacks(&rcu_bh_ctrlblk);
66933diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
66934index 9cb1ae4..aac7d3e 100644
66935--- a/kernel/rcutiny_plugin.h
66936+++ b/kernel/rcutiny_plugin.h
66937@@ -920,7 +920,7 @@ static int rcu_kthread(void *arg)
66938 have_rcu_kthread_work = morework;
66939 local_irq_restore(flags);
66940 if (work)
66941- rcu_process_callbacks(NULL);
66942+ rcu_process_callbacks();
66943 schedule_timeout_interruptible(1); /* Leave CPU for others. */
66944 }
66945
66946diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
66947index a58ac28..196a3d8 100644
66948--- a/kernel/rcutorture.c
66949+++ b/kernel/rcutorture.c
66950@@ -148,12 +148,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
66951 { 0 };
66952 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
66953 { 0 };
66954-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
66955-static atomic_t n_rcu_torture_alloc;
66956-static atomic_t n_rcu_torture_alloc_fail;
66957-static atomic_t n_rcu_torture_free;
66958-static atomic_t n_rcu_torture_mberror;
66959-static atomic_t n_rcu_torture_error;
66960+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
66961+static atomic_unchecked_t n_rcu_torture_alloc;
66962+static atomic_unchecked_t n_rcu_torture_alloc_fail;
66963+static atomic_unchecked_t n_rcu_torture_free;
66964+static atomic_unchecked_t n_rcu_torture_mberror;
66965+static atomic_unchecked_t n_rcu_torture_error;
66966 static long n_rcu_torture_boost_ktrerror;
66967 static long n_rcu_torture_boost_rterror;
66968 static long n_rcu_torture_boost_failure;
66969@@ -243,11 +243,11 @@ rcu_torture_alloc(void)
66970
66971 spin_lock_bh(&rcu_torture_lock);
66972 if (list_empty(&rcu_torture_freelist)) {
66973- atomic_inc(&n_rcu_torture_alloc_fail);
66974+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
66975 spin_unlock_bh(&rcu_torture_lock);
66976 return NULL;
66977 }
66978- atomic_inc(&n_rcu_torture_alloc);
66979+ atomic_inc_unchecked(&n_rcu_torture_alloc);
66980 p = rcu_torture_freelist.next;
66981 list_del_init(p);
66982 spin_unlock_bh(&rcu_torture_lock);
66983@@ -260,7 +260,7 @@ rcu_torture_alloc(void)
66984 static void
66985 rcu_torture_free(struct rcu_torture *p)
66986 {
66987- atomic_inc(&n_rcu_torture_free);
66988+ atomic_inc_unchecked(&n_rcu_torture_free);
66989 spin_lock_bh(&rcu_torture_lock);
66990 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
66991 spin_unlock_bh(&rcu_torture_lock);
66992@@ -380,7 +380,7 @@ rcu_torture_cb(struct rcu_head *p)
66993 i = rp->rtort_pipe_count;
66994 if (i > RCU_TORTURE_PIPE_LEN)
66995 i = RCU_TORTURE_PIPE_LEN;
66996- atomic_inc(&rcu_torture_wcount[i]);
66997+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
66998 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
66999 rp->rtort_mbtest = 0;
67000 rcu_torture_free(rp);
67001@@ -427,7 +427,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
67002 i = rp->rtort_pipe_count;
67003 if (i > RCU_TORTURE_PIPE_LEN)
67004 i = RCU_TORTURE_PIPE_LEN;
67005- atomic_inc(&rcu_torture_wcount[i]);
67006+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
67007 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
67008 rp->rtort_mbtest = 0;
67009 list_del(&rp->rtort_free);
67010@@ -916,7 +916,7 @@ rcu_torture_writer(void *arg)
67011 i = old_rp->rtort_pipe_count;
67012 if (i > RCU_TORTURE_PIPE_LEN)
67013 i = RCU_TORTURE_PIPE_LEN;
67014- atomic_inc(&rcu_torture_wcount[i]);
67015+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
67016 old_rp->rtort_pipe_count++;
67017 cur_ops->deferred_free(old_rp);
67018 }
67019@@ -997,7 +997,7 @@ static void rcu_torture_timer(unsigned long unused)
67020 return;
67021 }
67022 if (p->rtort_mbtest == 0)
67023- atomic_inc(&n_rcu_torture_mberror);
67024+ atomic_inc_unchecked(&n_rcu_torture_mberror);
67025 spin_lock(&rand_lock);
67026 cur_ops->read_delay(&rand);
67027 n_rcu_torture_timers++;
67028@@ -1061,7 +1061,7 @@ rcu_torture_reader(void *arg)
67029 continue;
67030 }
67031 if (p->rtort_mbtest == 0)
67032- atomic_inc(&n_rcu_torture_mberror);
67033+ atomic_inc_unchecked(&n_rcu_torture_mberror);
67034 cur_ops->read_delay(&rand);
67035 preempt_disable();
67036 pipe_count = p->rtort_pipe_count;
67037@@ -1123,10 +1123,10 @@ rcu_torture_printk(char *page)
67038 rcu_torture_current,
67039 rcu_torture_current_version,
67040 list_empty(&rcu_torture_freelist),
67041- atomic_read(&n_rcu_torture_alloc),
67042- atomic_read(&n_rcu_torture_alloc_fail),
67043- atomic_read(&n_rcu_torture_free),
67044- atomic_read(&n_rcu_torture_mberror),
67045+ atomic_read_unchecked(&n_rcu_torture_alloc),
67046+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
67047+ atomic_read_unchecked(&n_rcu_torture_free),
67048+ atomic_read_unchecked(&n_rcu_torture_mberror),
67049 n_rcu_torture_boost_ktrerror,
67050 n_rcu_torture_boost_rterror,
67051 n_rcu_torture_boost_failure,
67052@@ -1136,7 +1136,7 @@ rcu_torture_printk(char *page)
67053 n_online_attempts,
67054 n_offline_successes,
67055 n_offline_attempts);
67056- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
67057+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
67058 n_rcu_torture_boost_ktrerror != 0 ||
67059 n_rcu_torture_boost_rterror != 0 ||
67060 n_rcu_torture_boost_failure != 0)
67061@@ -1144,7 +1144,7 @@ rcu_torture_printk(char *page)
67062 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
67063 if (i > 1) {
67064 cnt += sprintf(&page[cnt], "!!! ");
67065- atomic_inc(&n_rcu_torture_error);
67066+ atomic_inc_unchecked(&n_rcu_torture_error);
67067 WARN_ON_ONCE(1);
67068 }
67069 cnt += sprintf(&page[cnt], "Reader Pipe: ");
67070@@ -1158,7 +1158,7 @@ rcu_torture_printk(char *page)
67071 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
67072 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
67073 cnt += sprintf(&page[cnt], " %d",
67074- atomic_read(&rcu_torture_wcount[i]));
67075+ atomic_read_unchecked(&rcu_torture_wcount[i]));
67076 }
67077 cnt += sprintf(&page[cnt], "\n");
67078 if (cur_ops->stats)
67079@@ -1600,7 +1600,7 @@ rcu_torture_cleanup(void)
67080
67081 if (cur_ops->cleanup)
67082 cur_ops->cleanup();
67083- if (atomic_read(&n_rcu_torture_error))
67084+ if (atomic_read_unchecked(&n_rcu_torture_error))
67085 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
67086 else
67087 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
67088@@ -1664,17 +1664,17 @@ rcu_torture_init(void)
67089
67090 rcu_torture_current = NULL;
67091 rcu_torture_current_version = 0;
67092- atomic_set(&n_rcu_torture_alloc, 0);
67093- atomic_set(&n_rcu_torture_alloc_fail, 0);
67094- atomic_set(&n_rcu_torture_free, 0);
67095- atomic_set(&n_rcu_torture_mberror, 0);
67096- atomic_set(&n_rcu_torture_error, 0);
67097+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
67098+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
67099+ atomic_set_unchecked(&n_rcu_torture_free, 0);
67100+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
67101+ atomic_set_unchecked(&n_rcu_torture_error, 0);
67102 n_rcu_torture_boost_ktrerror = 0;
67103 n_rcu_torture_boost_rterror = 0;
67104 n_rcu_torture_boost_failure = 0;
67105 n_rcu_torture_boosts = 0;
67106 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
67107- atomic_set(&rcu_torture_wcount[i], 0);
67108+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
67109 for_each_possible_cpu(cpu) {
67110 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
67111 per_cpu(rcu_torture_count, cpu)[i] = 0;
67112diff --git a/kernel/rcutree.c b/kernel/rcutree.c
67113index 6c4a672..70f3202 100644
67114--- a/kernel/rcutree.c
67115+++ b/kernel/rcutree.c
67116@@ -363,9 +363,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
67117 rcu_prepare_for_idle(smp_processor_id());
67118 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
67119 smp_mb__before_atomic_inc(); /* See above. */
67120- atomic_inc(&rdtp->dynticks);
67121+ atomic_inc_unchecked(&rdtp->dynticks);
67122 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
67123- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
67124+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
67125 }
67126
67127 /**
67128@@ -438,10 +438,10 @@ void rcu_irq_exit(void)
67129 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
67130 {
67131 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
67132- atomic_inc(&rdtp->dynticks);
67133+ atomic_inc_unchecked(&rdtp->dynticks);
67134 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
67135 smp_mb__after_atomic_inc(); /* See above. */
67136- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
67137+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
67138 rcu_cleanup_after_idle(smp_processor_id());
67139 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
67140 if (!is_idle_task(current)) {
67141@@ -531,14 +531,14 @@ void rcu_nmi_enter(void)
67142 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
67143
67144 if (rdtp->dynticks_nmi_nesting == 0 &&
67145- (atomic_read(&rdtp->dynticks) & 0x1))
67146+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
67147 return;
67148 rdtp->dynticks_nmi_nesting++;
67149 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
67150- atomic_inc(&rdtp->dynticks);
67151+ atomic_inc_unchecked(&rdtp->dynticks);
67152 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
67153 smp_mb__after_atomic_inc(); /* See above. */
67154- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
67155+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
67156 }
67157
67158 /**
67159@@ -557,9 +557,9 @@ void rcu_nmi_exit(void)
67160 return;
67161 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
67162 smp_mb__before_atomic_inc(); /* See above. */
67163- atomic_inc(&rdtp->dynticks);
67164+ atomic_inc_unchecked(&rdtp->dynticks);
67165 smp_mb__after_atomic_inc(); /* Force delay to next write. */
67166- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
67167+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
67168 }
67169
67170 #ifdef CONFIG_PROVE_RCU
67171@@ -575,7 +575,7 @@ int rcu_is_cpu_idle(void)
67172 int ret;
67173
67174 preempt_disable();
67175- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
67176+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
67177 preempt_enable();
67178 return ret;
67179 }
67180@@ -604,7 +604,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
67181 */
67182 static int dyntick_save_progress_counter(struct rcu_data *rdp)
67183 {
67184- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
67185+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
67186 return (rdp->dynticks_snap & 0x1) == 0;
67187 }
67188
67189@@ -619,7 +619,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
67190 unsigned int curr;
67191 unsigned int snap;
67192
67193- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
67194+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
67195 snap = (unsigned int)rdp->dynticks_snap;
67196
67197 /*
67198@@ -1667,7 +1667,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
67199 /*
67200 * Do RCU core processing for the current CPU.
67201 */
67202-static void rcu_process_callbacks(struct softirq_action *unused)
67203+static void rcu_process_callbacks(void)
67204 {
67205 trace_rcu_utilization("Start RCU core");
67206 __rcu_process_callbacks(&rcu_sched_state,
67207@@ -2030,7 +2030,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
67208 rdp->qlen = 0;
67209 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
67210 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_NESTING);
67211- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
67212+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
67213 rdp->cpu = cpu;
67214 rdp->rsp = rsp;
67215 raw_spin_unlock_irqrestore(&rnp->lock, flags);
67216@@ -2058,8 +2058,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
67217 rdp->n_force_qs_snap = rsp->n_force_qs;
67218 rdp->blimit = blimit;
67219 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_NESTING;
67220- atomic_set(&rdp->dynticks->dynticks,
67221- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
67222+ atomic_set_unchecked(&rdp->dynticks->dynticks,
67223+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
67224 rcu_prepare_for_idle_init(cpu);
67225 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
67226
67227diff --git a/kernel/rcutree.h b/kernel/rcutree.h
67228index fddff92..2c08359 100644
67229--- a/kernel/rcutree.h
67230+++ b/kernel/rcutree.h
67231@@ -87,7 +87,7 @@ struct rcu_dynticks {
67232 long long dynticks_nesting; /* Track irq/process nesting level. */
67233 /* Process level is worth LLONG_MAX/2. */
67234 int dynticks_nmi_nesting; /* Track NMI nesting level. */
67235- atomic_t dynticks; /* Even value for idle, else odd. */
67236+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
67237 };
67238
67239 /* RCU's kthread states for tracing. */
67240diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
67241index 8bb35d7..6ea0a463 100644
67242--- a/kernel/rcutree_plugin.h
67243+++ b/kernel/rcutree_plugin.h
67244@@ -850,7 +850,7 @@ void synchronize_rcu_expedited(void)
67245
67246 /* Clean up and exit. */
67247 smp_mb(); /* ensure expedited GP seen before counter increment. */
67248- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
67249+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
67250 unlock_mb_ret:
67251 mutex_unlock(&sync_rcu_preempt_exp_mutex);
67252 mb_ret:
67253@@ -1833,8 +1833,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
67254
67255 #else /* #ifndef CONFIG_SMP */
67256
67257-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
67258-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
67259+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
67260+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
67261
67262 static int synchronize_sched_expedited_cpu_stop(void *data)
67263 {
67264@@ -1889,7 +1889,7 @@ void synchronize_sched_expedited(void)
67265 int firstsnap, s, snap, trycount = 0;
67266
67267 /* Note that atomic_inc_return() implies full memory barrier. */
67268- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
67269+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
67270 get_online_cpus();
67271
67272 /*
67273@@ -1910,7 +1910,7 @@ void synchronize_sched_expedited(void)
67274 }
67275
67276 /* Check to see if someone else did our work for us. */
67277- s = atomic_read(&sync_sched_expedited_done);
67278+ s = atomic_read_unchecked(&sync_sched_expedited_done);
67279 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
67280 smp_mb(); /* ensure test happens before caller kfree */
67281 return;
67282@@ -1925,7 +1925,7 @@ void synchronize_sched_expedited(void)
67283 * grace period works for us.
67284 */
67285 get_online_cpus();
67286- snap = atomic_read(&sync_sched_expedited_started);
67287+ snap = atomic_read_unchecked(&sync_sched_expedited_started);
67288 smp_mb(); /* ensure read is before try_stop_cpus(). */
67289 }
67290
67291@@ -1936,12 +1936,12 @@ void synchronize_sched_expedited(void)
67292 * than we did beat us to the punch.
67293 */
67294 do {
67295- s = atomic_read(&sync_sched_expedited_done);
67296+ s = atomic_read_unchecked(&sync_sched_expedited_done);
67297 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
67298 smp_mb(); /* ensure test happens before caller kfree */
67299 break;
67300 }
67301- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
67302+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
67303
67304 put_online_cpus();
67305 }
67306diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
67307index 654cfe6..c0b28e2 100644
67308--- a/kernel/rcutree_trace.c
67309+++ b/kernel/rcutree_trace.c
67310@@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
67311 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
67312 rdp->qs_pending);
67313 seq_printf(m, " dt=%d/%llx/%d df=%lu",
67314- atomic_read(&rdp->dynticks->dynticks),
67315+ atomic_read_unchecked(&rdp->dynticks->dynticks),
67316 rdp->dynticks->dynticks_nesting,
67317 rdp->dynticks->dynticks_nmi_nesting,
67318 rdp->dynticks_fqs);
67319@@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
67320 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
67321 rdp->qs_pending);
67322 seq_printf(m, ",%d,%llx,%d,%lu",
67323- atomic_read(&rdp->dynticks->dynticks),
67324+ atomic_read_unchecked(&rdp->dynticks->dynticks),
67325 rdp->dynticks->dynticks_nesting,
67326 rdp->dynticks->dynticks_nmi_nesting,
67327 rdp->dynticks_fqs);
67328diff --git a/kernel/resource.c b/kernel/resource.c
67329index 7640b3a..5879283 100644
67330--- a/kernel/resource.c
67331+++ b/kernel/resource.c
67332@@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
67333
67334 static int __init ioresources_init(void)
67335 {
67336+#ifdef CONFIG_GRKERNSEC_PROC_ADD
67337+#ifdef CONFIG_GRKERNSEC_PROC_USER
67338+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
67339+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
67340+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67341+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
67342+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
67343+#endif
67344+#else
67345 proc_create("ioports", 0, NULL, &proc_ioports_operations);
67346 proc_create("iomem", 0, NULL, &proc_iomem_operations);
67347+#endif
67348 return 0;
67349 }
67350 __initcall(ioresources_init);
67351diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
67352index 98ec494..4241d6d 100644
67353--- a/kernel/rtmutex-tester.c
67354+++ b/kernel/rtmutex-tester.c
67355@@ -20,7 +20,7 @@
67356 #define MAX_RT_TEST_MUTEXES 8
67357
67358 static spinlock_t rttest_lock;
67359-static atomic_t rttest_event;
67360+static atomic_unchecked_t rttest_event;
67361
67362 struct test_thread_data {
67363 int opcode;
67364@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67365
67366 case RTTEST_LOCKCONT:
67367 td->mutexes[td->opdata] = 1;
67368- td->event = atomic_add_return(1, &rttest_event);
67369+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67370 return 0;
67371
67372 case RTTEST_RESET:
67373@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67374 return 0;
67375
67376 case RTTEST_RESETEVENT:
67377- atomic_set(&rttest_event, 0);
67378+ atomic_set_unchecked(&rttest_event, 0);
67379 return 0;
67380
67381 default:
67382@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67383 return ret;
67384
67385 td->mutexes[id] = 1;
67386- td->event = atomic_add_return(1, &rttest_event);
67387+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67388 rt_mutex_lock(&mutexes[id]);
67389- td->event = atomic_add_return(1, &rttest_event);
67390+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67391 td->mutexes[id] = 4;
67392 return 0;
67393
67394@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67395 return ret;
67396
67397 td->mutexes[id] = 1;
67398- td->event = atomic_add_return(1, &rttest_event);
67399+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67400 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
67401- td->event = atomic_add_return(1, &rttest_event);
67402+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67403 td->mutexes[id] = ret ? 0 : 4;
67404 return ret ? -EINTR : 0;
67405
67406@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67407 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
67408 return ret;
67409
67410- td->event = atomic_add_return(1, &rttest_event);
67411+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67412 rt_mutex_unlock(&mutexes[id]);
67413- td->event = atomic_add_return(1, &rttest_event);
67414+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67415 td->mutexes[id] = 0;
67416 return 0;
67417
67418@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67419 break;
67420
67421 td->mutexes[dat] = 2;
67422- td->event = atomic_add_return(1, &rttest_event);
67423+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67424 break;
67425
67426 default:
67427@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67428 return;
67429
67430 td->mutexes[dat] = 3;
67431- td->event = atomic_add_return(1, &rttest_event);
67432+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67433 break;
67434
67435 case RTTEST_LOCKNOWAIT:
67436@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67437 return;
67438
67439 td->mutexes[dat] = 1;
67440- td->event = atomic_add_return(1, &rttest_event);
67441+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67442 return;
67443
67444 default:
67445diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
67446index e8a1f83..363d17d 100644
67447--- a/kernel/sched/auto_group.c
67448+++ b/kernel/sched/auto_group.c
67449@@ -11,7 +11,7 @@
67450
67451 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
67452 static struct autogroup autogroup_default;
67453-static atomic_t autogroup_seq_nr;
67454+static atomic_unchecked_t autogroup_seq_nr;
67455
67456 void __init autogroup_init(struct task_struct *init_task)
67457 {
67458@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
67459
67460 kref_init(&ag->kref);
67461 init_rwsem(&ag->lock);
67462- ag->id = atomic_inc_return(&autogroup_seq_nr);
67463+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
67464 ag->tg = tg;
67465 #ifdef CONFIG_RT_GROUP_SCHED
67466 /*
67467diff --git a/kernel/sched/core.c b/kernel/sched/core.c
67468index b342f57..00324a0 100644
67469--- a/kernel/sched/core.c
67470+++ b/kernel/sched/core.c
67471@@ -3143,6 +3143,19 @@ pick_next_task(struct rq *rq)
67472 BUG(); /* the idle class will always have a runnable task */
67473 }
67474
67475+#ifdef CONFIG_GRKERNSEC_SETXID
67476+extern void gr_delayed_cred_worker(void);
67477+static inline void gr_cred_schedule(void)
67478+{
67479+ if (unlikely(current->delayed_cred))
67480+ gr_delayed_cred_worker();
67481+}
67482+#else
67483+static inline void gr_cred_schedule(void)
67484+{
67485+}
67486+#endif
67487+
67488 /*
67489 * __schedule() is the main scheduler function.
67490 */
67491@@ -3162,6 +3175,8 @@ need_resched:
67492
67493 schedule_debug(prev);
67494
67495+ gr_cred_schedule();
67496+
67497 if (sched_feat(HRTICK))
67498 hrtick_clear(rq);
67499
67500@@ -3852,6 +3867,8 @@ int can_nice(const struct task_struct *p, const int nice)
67501 /* convert nice value [19,-20] to rlimit style value [1,40] */
67502 int nice_rlim = 20 - nice;
67503
67504+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
67505+
67506 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
67507 capable(CAP_SYS_NICE));
67508 }
67509@@ -3885,7 +3902,8 @@ SYSCALL_DEFINE1(nice, int, increment)
67510 if (nice > 19)
67511 nice = 19;
67512
67513- if (increment < 0 && !can_nice(current, nice))
67514+ if (increment < 0 && (!can_nice(current, nice) ||
67515+ gr_handle_chroot_nice()))
67516 return -EPERM;
67517
67518 retval = security_task_setnice(current, nice);
67519@@ -4042,6 +4060,7 @@ recheck:
67520 unsigned long rlim_rtprio =
67521 task_rlimit(p, RLIMIT_RTPRIO);
67522
67523+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
67524 /* can't set/change the rt policy */
67525 if (policy != p->policy && !rlim_rtprio)
67526 return -EPERM;
67527diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
67528index aca16b8..8e3acc4 100644
67529--- a/kernel/sched/fair.c
67530+++ b/kernel/sched/fair.c
67531@@ -5147,7 +5147,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
67532 * run_rebalance_domains is triggered when needed from the scheduler tick.
67533 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
67534 */
67535-static void run_rebalance_domains(struct softirq_action *h)
67536+static void run_rebalance_domains(void)
67537 {
67538 int this_cpu = smp_processor_id();
67539 struct rq *this_rq = cpu_rq(this_cpu);
67540diff --git a/kernel/signal.c b/kernel/signal.c
67541index c73c428..7040057 100644
67542--- a/kernel/signal.c
67543+++ b/kernel/signal.c
67544@@ -46,12 +46,12 @@ static struct kmem_cache *sigqueue_cachep;
67545
67546 int print_fatal_signals __read_mostly;
67547
67548-static void __user *sig_handler(struct task_struct *t, int sig)
67549+static __sighandler_t sig_handler(struct task_struct *t, int sig)
67550 {
67551 return t->sighand->action[sig - 1].sa.sa_handler;
67552 }
67553
67554-static int sig_handler_ignored(void __user *handler, int sig)
67555+static int sig_handler_ignored(__sighandler_t handler, int sig)
67556 {
67557 /* Is it explicitly or implicitly ignored? */
67558 return handler == SIG_IGN ||
67559@@ -61,7 +61,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
67560 static int sig_task_ignored(struct task_struct *t, int sig,
67561 int from_ancestor_ns)
67562 {
67563- void __user *handler;
67564+ __sighandler_t handler;
67565
67566 handler = sig_handler(t, sig);
67567
67568@@ -365,6 +365,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
67569 atomic_inc(&user->sigpending);
67570 rcu_read_unlock();
67571
67572+ if (!override_rlimit)
67573+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
67574+
67575 if (override_rlimit ||
67576 atomic_read(&user->sigpending) <=
67577 task_rlimit(t, RLIMIT_SIGPENDING)) {
67578@@ -489,7 +492,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
67579
67580 int unhandled_signal(struct task_struct *tsk, int sig)
67581 {
67582- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
67583+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
67584 if (is_global_init(tsk))
67585 return 1;
67586 if (handler != SIG_IGN && handler != SIG_DFL)
67587@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
67588 }
67589 }
67590
67591+ /* allow glibc communication via tgkill to other threads in our
67592+ thread group */
67593+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
67594+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
67595+ && gr_handle_signal(t, sig))
67596+ return -EPERM;
67597+
67598 return security_task_kill(t, info, sig, 0);
67599 }
67600
67601@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
67602 return send_signal(sig, info, p, 1);
67603 }
67604
67605-static int
67606+int
67607 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
67608 {
67609 return send_signal(sig, info, t, 0);
67610@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
67611 unsigned long int flags;
67612 int ret, blocked, ignored;
67613 struct k_sigaction *action;
67614+ int is_unhandled = 0;
67615
67616 spin_lock_irqsave(&t->sighand->siglock, flags);
67617 action = &t->sighand->action[sig-1];
67618@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
67619 }
67620 if (action->sa.sa_handler == SIG_DFL)
67621 t->signal->flags &= ~SIGNAL_UNKILLABLE;
67622+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
67623+ is_unhandled = 1;
67624 ret = specific_send_sig_info(sig, info, t);
67625 spin_unlock_irqrestore(&t->sighand->siglock, flags);
67626
67627+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
67628+ normal operation */
67629+ if (is_unhandled) {
67630+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
67631+ gr_handle_crash(t, sig);
67632+ }
67633+
67634 return ret;
67635 }
67636
67637@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
67638 ret = check_kill_permission(sig, info, p);
67639 rcu_read_unlock();
67640
67641- if (!ret && sig)
67642+ if (!ret && sig) {
67643 ret = do_send_sig_info(sig, info, p, true);
67644+ if (!ret)
67645+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
67646+ }
67647
67648 return ret;
67649 }
67650@@ -2820,7 +2843,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
67651 int error = -ESRCH;
67652
67653 rcu_read_lock();
67654- p = find_task_by_vpid(pid);
67655+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
67656+ /* allow glibc communication via tgkill to other threads in our
67657+ thread group */
67658+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
67659+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
67660+ p = find_task_by_vpid_unrestricted(pid);
67661+ else
67662+#endif
67663+ p = find_task_by_vpid(pid);
67664 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
67665 error = check_kill_permission(sig, info, p);
67666 /*
67667diff --git a/kernel/smp.c b/kernel/smp.c
67668index db197d6..17aef0b 100644
67669--- a/kernel/smp.c
67670+++ b/kernel/smp.c
67671@@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
67672 }
67673 EXPORT_SYMBOL(smp_call_function);
67674
67675-void ipi_call_lock(void)
67676+void ipi_call_lock(void) __acquires(call_function.lock)
67677 {
67678 raw_spin_lock(&call_function.lock);
67679 }
67680
67681-void ipi_call_unlock(void)
67682+void ipi_call_unlock(void) __releases(call_function.lock)
67683 {
67684 raw_spin_unlock(&call_function.lock);
67685 }
67686
67687-void ipi_call_lock_irq(void)
67688+void ipi_call_lock_irq(void) __acquires(call_function.lock)
67689 {
67690 raw_spin_lock_irq(&call_function.lock);
67691 }
67692
67693-void ipi_call_unlock_irq(void)
67694+void ipi_call_unlock_irq(void) __releases(call_function.lock)
67695 {
67696 raw_spin_unlock_irq(&call_function.lock);
67697 }
67698diff --git a/kernel/softirq.c b/kernel/softirq.c
67699index 4eb3a0f..6f1fa81 100644
67700--- a/kernel/softirq.c
67701+++ b/kernel/softirq.c
67702@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
67703
67704 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
67705
67706-char *softirq_to_name[NR_SOFTIRQS] = {
67707+const char * const softirq_to_name[NR_SOFTIRQS] = {
67708 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
67709 "TASKLET", "SCHED", "HRTIMER", "RCU"
67710 };
67711@@ -235,7 +235,7 @@ restart:
67712 kstat_incr_softirqs_this_cpu(vec_nr);
67713
67714 trace_softirq_entry(vec_nr);
67715- h->action(h);
67716+ h->action();
67717 trace_softirq_exit(vec_nr);
67718 if (unlikely(prev_count != preempt_count())) {
67719 printk(KERN_ERR "huh, entered softirq %u %s %p"
67720@@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
67721 local_irq_restore(flags);
67722 }
67723
67724-void open_softirq(int nr, void (*action)(struct softirq_action *))
67725+void open_softirq(int nr, void (*action)(void))
67726 {
67727- softirq_vec[nr].action = action;
67728+ pax_open_kernel();
67729+ *(void **)&softirq_vec[nr].action = action;
67730+ pax_close_kernel();
67731 }
67732
67733 /*
67734@@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
67735
67736 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
67737
67738-static void tasklet_action(struct softirq_action *a)
67739+static void tasklet_action(void)
67740 {
67741 struct tasklet_struct *list;
67742
67743@@ -476,7 +478,7 @@ static void tasklet_action(struct softirq_action *a)
67744 }
67745 }
67746
67747-static void tasklet_hi_action(struct softirq_action *a)
67748+static void tasklet_hi_action(void)
67749 {
67750 struct tasklet_struct *list;
67751
67752diff --git a/kernel/sys.c b/kernel/sys.c
67753index 888d227..f04b318 100644
67754--- a/kernel/sys.c
67755+++ b/kernel/sys.c
67756@@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
67757 error = -EACCES;
67758 goto out;
67759 }
67760+
67761+ if (gr_handle_chroot_setpriority(p, niceval)) {
67762+ error = -EACCES;
67763+ goto out;
67764+ }
67765+
67766 no_nice = security_task_setnice(p, niceval);
67767 if (no_nice) {
67768 error = no_nice;
67769@@ -572,6 +578,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
67770 goto error;
67771 }
67772
67773+ if (gr_check_group_change(new->gid, new->egid, -1))
67774+ goto error;
67775+
67776 if (rgid != (gid_t) -1 ||
67777 (egid != (gid_t) -1 && egid != old->gid))
67778 new->sgid = new->egid;
67779@@ -601,6 +610,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
67780 old = current_cred();
67781
67782 retval = -EPERM;
67783+
67784+ if (gr_check_group_change(gid, gid, gid))
67785+ goto error;
67786+
67787 if (nsown_capable(CAP_SETGID))
67788 new->gid = new->egid = new->sgid = new->fsgid = gid;
67789 else if (gid == old->gid || gid == old->sgid)
67790@@ -618,7 +631,7 @@ error:
67791 /*
67792 * change the user struct in a credentials set to match the new UID
67793 */
67794-static int set_user(struct cred *new)
67795+int set_user(struct cred *new)
67796 {
67797 struct user_struct *new_user;
67798
67799@@ -688,6 +701,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
67800 goto error;
67801 }
67802
67803+ if (gr_check_user_change(new->uid, new->euid, -1))
67804+ goto error;
67805+
67806 if (new->uid != old->uid) {
67807 retval = set_user(new);
67808 if (retval < 0)
67809@@ -732,6 +748,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
67810 old = current_cred();
67811
67812 retval = -EPERM;
67813+
67814+ if (gr_check_crash_uid(uid))
67815+ goto error;
67816+ if (gr_check_user_change(uid, uid, uid))
67817+ goto error;
67818+
67819 if (nsown_capable(CAP_SETUID)) {
67820 new->suid = new->uid = uid;
67821 if (uid != old->uid) {
67822@@ -786,6 +808,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
67823 goto error;
67824 }
67825
67826+ if (gr_check_user_change(ruid, euid, -1))
67827+ goto error;
67828+
67829 if (ruid != (uid_t) -1) {
67830 new->uid = ruid;
67831 if (ruid != old->uid) {
67832@@ -850,6 +875,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
67833 goto error;
67834 }
67835
67836+ if (gr_check_group_change(rgid, egid, -1))
67837+ goto error;
67838+
67839 if (rgid != (gid_t) -1)
67840 new->gid = rgid;
67841 if (egid != (gid_t) -1)
67842@@ -896,6 +924,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
67843 old = current_cred();
67844 old_fsuid = old->fsuid;
67845
67846+ if (gr_check_user_change(-1, -1, uid))
67847+ goto error;
67848+
67849 if (uid == old->uid || uid == old->euid ||
67850 uid == old->suid || uid == old->fsuid ||
67851 nsown_capable(CAP_SETUID)) {
67852@@ -906,6 +937,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
67853 }
67854 }
67855
67856+error:
67857 abort_creds(new);
67858 return old_fsuid;
67859
67860@@ -932,12 +964,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
67861 if (gid == old->gid || gid == old->egid ||
67862 gid == old->sgid || gid == old->fsgid ||
67863 nsown_capable(CAP_SETGID)) {
67864+ if (gr_check_group_change(-1, -1, gid))
67865+ goto error;
67866+
67867 if (gid != old_fsgid) {
67868 new->fsgid = gid;
67869 goto change_okay;
67870 }
67871 }
67872
67873+error:
67874 abort_creds(new);
67875 return old_fsgid;
67876
67877@@ -1189,7 +1225,10 @@ static int override_release(char __user *release, int len)
67878 }
67879 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
67880 snprintf(buf, len, "2.6.%u%s", v, rest);
67881- ret = copy_to_user(release, buf, len);
67882+ if (len > sizeof(buf))
67883+ ret = -EFAULT;
67884+ else
67885+ ret = copy_to_user(release, buf, len);
67886 }
67887 return ret;
67888 }
67889@@ -1243,19 +1282,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
67890 return -EFAULT;
67891
67892 down_read(&uts_sem);
67893- error = __copy_to_user(&name->sysname, &utsname()->sysname,
67894+ error = __copy_to_user(name->sysname, &utsname()->sysname,
67895 __OLD_UTS_LEN);
67896 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
67897- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
67898+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
67899 __OLD_UTS_LEN);
67900 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
67901- error |= __copy_to_user(&name->release, &utsname()->release,
67902+ error |= __copy_to_user(name->release, &utsname()->release,
67903 __OLD_UTS_LEN);
67904 error |= __put_user(0, name->release + __OLD_UTS_LEN);
67905- error |= __copy_to_user(&name->version, &utsname()->version,
67906+ error |= __copy_to_user(name->version, &utsname()->version,
67907 __OLD_UTS_LEN);
67908 error |= __put_user(0, name->version + __OLD_UTS_LEN);
67909- error |= __copy_to_user(&name->machine, &utsname()->machine,
67910+ error |= __copy_to_user(name->machine, &utsname()->machine,
67911 __OLD_UTS_LEN);
67912 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
67913 up_read(&uts_sem);
67914@@ -1838,7 +1877,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
67915 error = get_dumpable(me->mm);
67916 break;
67917 case PR_SET_DUMPABLE:
67918- if (arg2 < 0 || arg2 > 1) {
67919+ if (arg2 > 1) {
67920 error = -EINVAL;
67921 break;
67922 }
67923diff --git a/kernel/sysctl.c b/kernel/sysctl.c
67924index f487f25..9056a9e 100644
67925--- a/kernel/sysctl.c
67926+++ b/kernel/sysctl.c
67927@@ -86,6 +86,13 @@
67928
67929
67930 #if defined(CONFIG_SYSCTL)
67931+#include <linux/grsecurity.h>
67932+#include <linux/grinternal.h>
67933+
67934+extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
67935+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
67936+ const int op);
67937+extern int gr_handle_chroot_sysctl(const int op);
67938
67939 /* External variables not in a header file. */
67940 extern int sysctl_overcommit_memory;
67941@@ -191,6 +198,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
67942 }
67943
67944 #endif
67945+extern struct ctl_table grsecurity_table[];
67946
67947 static struct ctl_table root_table[];
67948 static struct ctl_table_root sysctl_table_root;
67949@@ -220,6 +228,20 @@ extern struct ctl_table epoll_table[];
67950 int sysctl_legacy_va_layout;
67951 #endif
67952
67953+#ifdef CONFIG_PAX_SOFTMODE
67954+static ctl_table pax_table[] = {
67955+ {
67956+ .procname = "softmode",
67957+ .data = &pax_softmode,
67958+ .maxlen = sizeof(unsigned int),
67959+ .mode = 0600,
67960+ .proc_handler = &proc_dointvec,
67961+ },
67962+
67963+ { }
67964+};
67965+#endif
67966+
67967 /* The default sysctl tables: */
67968
67969 static struct ctl_table root_table[] = {
67970@@ -266,6 +288,22 @@ static int max_extfrag_threshold = 1000;
67971 #endif
67972
67973 static struct ctl_table kern_table[] = {
67974+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
67975+ {
67976+ .procname = "grsecurity",
67977+ .mode = 0500,
67978+ .child = grsecurity_table,
67979+ },
67980+#endif
67981+
67982+#ifdef CONFIG_PAX_SOFTMODE
67983+ {
67984+ .procname = "pax",
67985+ .mode = 0500,
67986+ .child = pax_table,
67987+ },
67988+#endif
67989+
67990 {
67991 .procname = "sched_child_runs_first",
67992 .data = &sysctl_sched_child_runs_first,
67993@@ -550,7 +588,7 @@ static struct ctl_table kern_table[] = {
67994 .data = &modprobe_path,
67995 .maxlen = KMOD_PATH_LEN,
67996 .mode = 0644,
67997- .proc_handler = proc_dostring,
67998+ .proc_handler = proc_dostring_modpriv,
67999 },
68000 {
68001 .procname = "modules_disabled",
68002@@ -717,16 +755,20 @@ static struct ctl_table kern_table[] = {
68003 .extra1 = &zero,
68004 .extra2 = &one,
68005 },
68006+#endif
68007 {
68008 .procname = "kptr_restrict",
68009 .data = &kptr_restrict,
68010 .maxlen = sizeof(int),
68011 .mode = 0644,
68012 .proc_handler = proc_dmesg_restrict,
68013+#ifdef CONFIG_GRKERNSEC_HIDESYM
68014+ .extra1 = &two,
68015+#else
68016 .extra1 = &zero,
68017+#endif
68018 .extra2 = &two,
68019 },
68020-#endif
68021 {
68022 .procname = "ngroups_max",
68023 .data = &ngroups_max,
68024@@ -1225,6 +1267,13 @@ static struct ctl_table vm_table[] = {
68025 .proc_handler = proc_dointvec_minmax,
68026 .extra1 = &zero,
68027 },
68028+ {
68029+ .procname = "heap_stack_gap",
68030+ .data = &sysctl_heap_stack_gap,
68031+ .maxlen = sizeof(sysctl_heap_stack_gap),
68032+ .mode = 0644,
68033+ .proc_handler = proc_doulongvec_minmax,
68034+ },
68035 #else
68036 {
68037 .procname = "nr_trim_pages",
68038@@ -1729,6 +1778,17 @@ static int test_perm(int mode, int op)
68039 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
68040 {
68041 int mode;
68042+ int error;
68043+
68044+ if (table->parent != NULL && table->parent->procname != NULL &&
68045+ table->procname != NULL &&
68046+ gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
68047+ return -EACCES;
68048+ if (gr_handle_chroot_sysctl(op))
68049+ return -EACCES;
68050+ error = gr_handle_sysctl(table, op);
68051+ if (error)
68052+ return error;
68053
68054 if (root->permissions)
68055 mode = root->permissions(root, current->nsproxy, table);
68056@@ -2133,6 +2193,16 @@ int proc_dostring(struct ctl_table *table, int write,
68057 buffer, lenp, ppos);
68058 }
68059
68060+int proc_dostring_modpriv(struct ctl_table *table, int write,
68061+ void __user *buffer, size_t *lenp, loff_t *ppos)
68062+{
68063+ if (write && !capable(CAP_SYS_MODULE))
68064+ return -EPERM;
68065+
68066+ return _proc_do_string(table->data, table->maxlen, write,
68067+ buffer, lenp, ppos);
68068+}
68069+
68070 static size_t proc_skip_spaces(char **buf)
68071 {
68072 size_t ret;
68073@@ -2238,6 +2308,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
68074 len = strlen(tmp);
68075 if (len > *size)
68076 len = *size;
68077+ if (len > sizeof(tmp))
68078+ len = sizeof(tmp);
68079 if (copy_to_user(*buf, tmp, len))
68080 return -EFAULT;
68081 *size -= len;
68082@@ -2554,8 +2626,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
68083 *i = val;
68084 } else {
68085 val = convdiv * (*i) / convmul;
68086- if (!first)
68087+ if (!first) {
68088 err = proc_put_char(&buffer, &left, '\t');
68089+ if (err)
68090+ break;
68091+ }
68092 err = proc_put_long(&buffer, &left, val, false);
68093 if (err)
68094 break;
68095@@ -2950,6 +3025,12 @@ int proc_dostring(struct ctl_table *table, int write,
68096 return -ENOSYS;
68097 }
68098
68099+int proc_dostring_modpriv(struct ctl_table *table, int write,
68100+ void __user *buffer, size_t *lenp, loff_t *ppos)
68101+{
68102+ return -ENOSYS;
68103+}
68104+
68105 int proc_dointvec(struct ctl_table *table, int write,
68106 void __user *buffer, size_t *lenp, loff_t *ppos)
68107 {
68108@@ -3006,6 +3087,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
68109 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
68110 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
68111 EXPORT_SYMBOL(proc_dostring);
68112+EXPORT_SYMBOL(proc_dostring_modpriv);
68113 EXPORT_SYMBOL(proc_doulongvec_minmax);
68114 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
68115 EXPORT_SYMBOL(register_sysctl_table);
68116diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
68117index a650694..aaeeb20 100644
68118--- a/kernel/sysctl_binary.c
68119+++ b/kernel/sysctl_binary.c
68120@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
68121 int i;
68122
68123 set_fs(KERNEL_DS);
68124- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
68125+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
68126 set_fs(old_fs);
68127 if (result < 0)
68128 goto out_kfree;
68129@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
68130 }
68131
68132 set_fs(KERNEL_DS);
68133- result = vfs_write(file, buffer, str - buffer, &pos);
68134+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
68135 set_fs(old_fs);
68136 if (result < 0)
68137 goto out_kfree;
68138@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
68139 int i;
68140
68141 set_fs(KERNEL_DS);
68142- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
68143+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
68144 set_fs(old_fs);
68145 if (result < 0)
68146 goto out_kfree;
68147@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
68148 }
68149
68150 set_fs(KERNEL_DS);
68151- result = vfs_write(file, buffer, str - buffer, &pos);
68152+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
68153 set_fs(old_fs);
68154 if (result < 0)
68155 goto out_kfree;
68156@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
68157 int i;
68158
68159 set_fs(KERNEL_DS);
68160- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
68161+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
68162 set_fs(old_fs);
68163 if (result < 0)
68164 goto out;
68165@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
68166 __le16 dnaddr;
68167
68168 set_fs(KERNEL_DS);
68169- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
68170+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
68171 set_fs(old_fs);
68172 if (result < 0)
68173 goto out;
68174@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
68175 le16_to_cpu(dnaddr) & 0x3ff);
68176
68177 set_fs(KERNEL_DS);
68178- result = vfs_write(file, buf, len, &pos);
68179+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
68180 set_fs(old_fs);
68181 if (result < 0)
68182 goto out;
68183diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
68184index 362da65..ab8ef8c 100644
68185--- a/kernel/sysctl_check.c
68186+++ b/kernel/sysctl_check.c
68187@@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
68188 set_fail(&fail, table, "Directory with extra2");
68189 } else {
68190 if ((table->proc_handler == proc_dostring) ||
68191+ (table->proc_handler == proc_dostring_modpriv) ||
68192 (table->proc_handler == proc_dointvec) ||
68193 (table->proc_handler == proc_dointvec_minmax) ||
68194 (table->proc_handler == proc_dointvec_jiffies) ||
68195diff --git a/kernel/taskstats.c b/kernel/taskstats.c
68196index e660464..c8b9e67 100644
68197--- a/kernel/taskstats.c
68198+++ b/kernel/taskstats.c
68199@@ -27,9 +27,12 @@
68200 #include <linux/cgroup.h>
68201 #include <linux/fs.h>
68202 #include <linux/file.h>
68203+#include <linux/grsecurity.h>
68204 #include <net/genetlink.h>
68205 #include <linux/atomic.h>
68206
68207+extern int gr_is_taskstats_denied(int pid);
68208+
68209 /*
68210 * Maximum length of a cpumask that can be specified in
68211 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
68212@@ -556,6 +559,9 @@ err:
68213
68214 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
68215 {
68216+ if (gr_is_taskstats_denied(current->pid))
68217+ return -EACCES;
68218+
68219 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
68220 return cmd_attr_register_cpumask(info);
68221 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
68222diff --git a/kernel/time.c b/kernel/time.c
68223index 73e416d..cfc6f69 100644
68224--- a/kernel/time.c
68225+++ b/kernel/time.c
68226@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
68227 return error;
68228
68229 if (tz) {
68230+ /* we log in do_settimeofday called below, so don't log twice
68231+ */
68232+ if (!tv)
68233+ gr_log_timechange();
68234+
68235 /* SMP safe, global irq locking makes it work. */
68236 sys_tz = *tz;
68237 update_vsyscall_tz();
68238diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
68239index 8a46f5d..bbe6f9c 100644
68240--- a/kernel/time/alarmtimer.c
68241+++ b/kernel/time/alarmtimer.c
68242@@ -773,7 +773,7 @@ static int __init alarmtimer_init(void)
68243 struct platform_device *pdev;
68244 int error = 0;
68245 int i;
68246- struct k_clock alarm_clock = {
68247+ static struct k_clock alarm_clock = {
68248 .clock_getres = alarm_clock_getres,
68249 .clock_get = alarm_clock_get,
68250 .timer_create = alarm_timer_create,
68251diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
68252index fd4a7b1..fae5c2a 100644
68253--- a/kernel/time/tick-broadcast.c
68254+++ b/kernel/time/tick-broadcast.c
68255@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
68256 * then clear the broadcast bit.
68257 */
68258 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
68259- int cpu = smp_processor_id();
68260+ cpu = smp_processor_id();
68261
68262 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
68263 tick_broadcast_clear_oneshot(cpu);
68264diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
68265index 0c63581..e25dcb6 100644
68266--- a/kernel/time/timekeeping.c
68267+++ b/kernel/time/timekeeping.c
68268@@ -14,6 +14,7 @@
68269 #include <linux/init.h>
68270 #include <linux/mm.h>
68271 #include <linux/sched.h>
68272+#include <linux/grsecurity.h>
68273 #include <linux/syscore_ops.h>
68274 #include <linux/clocksource.h>
68275 #include <linux/jiffies.h>
68276@@ -365,6 +366,8 @@ int do_settimeofday(const struct timespec *tv)
68277 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
68278 return -EINVAL;
68279
68280+ gr_log_timechange();
68281+
68282 write_seqlock_irqsave(&xtime_lock, flags);
68283
68284 timekeeping_forward_now();
68285diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
68286index 3258455..f35227d 100644
68287--- a/kernel/time/timer_list.c
68288+++ b/kernel/time/timer_list.c
68289@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
68290
68291 static void print_name_offset(struct seq_file *m, void *sym)
68292 {
68293+#ifdef CONFIG_GRKERNSEC_HIDESYM
68294+ SEQ_printf(m, "<%p>", NULL);
68295+#else
68296 char symname[KSYM_NAME_LEN];
68297
68298 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
68299 SEQ_printf(m, "<%pK>", sym);
68300 else
68301 SEQ_printf(m, "%s", symname);
68302+#endif
68303 }
68304
68305 static void
68306@@ -112,7 +116,11 @@ next_one:
68307 static void
68308 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
68309 {
68310+#ifdef CONFIG_GRKERNSEC_HIDESYM
68311+ SEQ_printf(m, " .base: %p\n", NULL);
68312+#else
68313 SEQ_printf(m, " .base: %pK\n", base);
68314+#endif
68315 SEQ_printf(m, " .index: %d\n",
68316 base->index);
68317 SEQ_printf(m, " .resolution: %Lu nsecs\n",
68318@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
68319 {
68320 struct proc_dir_entry *pe;
68321
68322+#ifdef CONFIG_GRKERNSEC_PROC_ADD
68323+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
68324+#else
68325 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
68326+#endif
68327 if (!pe)
68328 return -ENOMEM;
68329 return 0;
68330diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
68331index 0b537f2..9e71eca 100644
68332--- a/kernel/time/timer_stats.c
68333+++ b/kernel/time/timer_stats.c
68334@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
68335 static unsigned long nr_entries;
68336 static struct entry entries[MAX_ENTRIES];
68337
68338-static atomic_t overflow_count;
68339+static atomic_unchecked_t overflow_count;
68340
68341 /*
68342 * The entries are in a hash-table, for fast lookup:
68343@@ -140,7 +140,7 @@ static void reset_entries(void)
68344 nr_entries = 0;
68345 memset(entries, 0, sizeof(entries));
68346 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
68347- atomic_set(&overflow_count, 0);
68348+ atomic_set_unchecked(&overflow_count, 0);
68349 }
68350
68351 static struct entry *alloc_entry(void)
68352@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
68353 if (likely(entry))
68354 entry->count++;
68355 else
68356- atomic_inc(&overflow_count);
68357+ atomic_inc_unchecked(&overflow_count);
68358
68359 out_unlock:
68360 raw_spin_unlock_irqrestore(lock, flags);
68361@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
68362
68363 static void print_name_offset(struct seq_file *m, unsigned long addr)
68364 {
68365+#ifdef CONFIG_GRKERNSEC_HIDESYM
68366+ seq_printf(m, "<%p>", NULL);
68367+#else
68368 char symname[KSYM_NAME_LEN];
68369
68370 if (lookup_symbol_name(addr, symname) < 0)
68371 seq_printf(m, "<%p>", (void *)addr);
68372 else
68373 seq_printf(m, "%s", symname);
68374+#endif
68375 }
68376
68377 static int tstats_show(struct seq_file *m, void *v)
68378@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
68379
68380 seq_puts(m, "Timer Stats Version: v0.2\n");
68381 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
68382- if (atomic_read(&overflow_count))
68383+ if (atomic_read_unchecked(&overflow_count))
68384 seq_printf(m, "Overflow: %d entries\n",
68385- atomic_read(&overflow_count));
68386+ atomic_read_unchecked(&overflow_count));
68387
68388 for (i = 0; i < nr_entries; i++) {
68389 entry = entries + i;
68390@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
68391 {
68392 struct proc_dir_entry *pe;
68393
68394+#ifdef CONFIG_GRKERNSEC_PROC_ADD
68395+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
68396+#else
68397 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
68398+#endif
68399 if (!pe)
68400 return -ENOMEM;
68401 return 0;
68402diff --git a/kernel/timer.c b/kernel/timer.c
68403index a297ffc..5e16b0b 100644
68404--- a/kernel/timer.c
68405+++ b/kernel/timer.c
68406@@ -1354,7 +1354,7 @@ void update_process_times(int user_tick)
68407 /*
68408 * This function runs timers and the timer-tq in bottom half context.
68409 */
68410-static void run_timer_softirq(struct softirq_action *h)
68411+static void run_timer_softirq(void)
68412 {
68413 struct tvec_base *base = __this_cpu_read(tvec_bases);
68414
68415diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
68416index cdea7b5..9b820d4 100644
68417--- a/kernel/trace/blktrace.c
68418+++ b/kernel/trace/blktrace.c
68419@@ -324,7 +324,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
68420 struct blk_trace *bt = filp->private_data;
68421 char buf[16];
68422
68423- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
68424+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
68425
68426 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
68427 }
68428@@ -389,7 +389,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
68429 return 1;
68430
68431 bt = buf->chan->private_data;
68432- atomic_inc(&bt->dropped);
68433+ atomic_inc_unchecked(&bt->dropped);
68434 return 0;
68435 }
68436
68437@@ -490,7 +490,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
68438
68439 bt->dir = dir;
68440 bt->dev = dev;
68441- atomic_set(&bt->dropped, 0);
68442+ atomic_set_unchecked(&bt->dropped, 0);
68443
68444 ret = -EIO;
68445 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
68446diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
68447index 683d559..d70d914 100644
68448--- a/kernel/trace/ftrace.c
68449+++ b/kernel/trace/ftrace.c
68450@@ -1726,12 +1726,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
68451 if (unlikely(ftrace_disabled))
68452 return 0;
68453
68454+ ret = ftrace_arch_code_modify_prepare();
68455+ FTRACE_WARN_ON(ret);
68456+ if (ret)
68457+ return 0;
68458+
68459 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
68460+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
68461 if (ret) {
68462 ftrace_bug(ret, ip);
68463- return 0;
68464 }
68465- return 1;
68466+ return ret ? 0 : 1;
68467 }
68468
68469 /*
68470@@ -2843,7 +2848,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
68471
68472 int
68473 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
68474- void *data)
68475+ void *data)
68476 {
68477 struct ftrace_func_probe *entry;
68478 struct ftrace_page *pg;
68479diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
68480index a3f1bc5..5e651718 100644
68481--- a/kernel/trace/trace.c
68482+++ b/kernel/trace/trace.c
68483@@ -4254,10 +4254,9 @@ static const struct file_operations tracing_dyn_info_fops = {
68484 };
68485 #endif
68486
68487-static struct dentry *d_tracer;
68488-
68489 struct dentry *tracing_init_dentry(void)
68490 {
68491+ static struct dentry *d_tracer;
68492 static int once;
68493
68494 if (d_tracer)
68495@@ -4277,10 +4276,9 @@ struct dentry *tracing_init_dentry(void)
68496 return d_tracer;
68497 }
68498
68499-static struct dentry *d_percpu;
68500-
68501 struct dentry *tracing_dentry_percpu(void)
68502 {
68503+ static struct dentry *d_percpu;
68504 static int once;
68505 struct dentry *d_tracer;
68506
68507diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
68508index c212a7f..7b02394 100644
68509--- a/kernel/trace/trace_events.c
68510+++ b/kernel/trace/trace_events.c
68511@@ -1299,10 +1299,6 @@ static LIST_HEAD(ftrace_module_file_list);
68512 struct ftrace_module_file_ops {
68513 struct list_head list;
68514 struct module *mod;
68515- struct file_operations id;
68516- struct file_operations enable;
68517- struct file_operations format;
68518- struct file_operations filter;
68519 };
68520
68521 static struct ftrace_module_file_ops *
68522@@ -1323,17 +1319,12 @@ trace_create_file_ops(struct module *mod)
68523
68524 file_ops->mod = mod;
68525
68526- file_ops->id = ftrace_event_id_fops;
68527- file_ops->id.owner = mod;
68528-
68529- file_ops->enable = ftrace_enable_fops;
68530- file_ops->enable.owner = mod;
68531-
68532- file_ops->filter = ftrace_event_filter_fops;
68533- file_ops->filter.owner = mod;
68534-
68535- file_ops->format = ftrace_event_format_fops;
68536- file_ops->format.owner = mod;
68537+ pax_open_kernel();
68538+ *(void **)&mod->trace_id.owner = mod;
68539+ *(void **)&mod->trace_enable.owner = mod;
68540+ *(void **)&mod->trace_filter.owner = mod;
68541+ *(void **)&mod->trace_format.owner = mod;
68542+ pax_close_kernel();
68543
68544 list_add(&file_ops->list, &ftrace_module_file_list);
68545
68546@@ -1357,8 +1348,8 @@ static void trace_module_add_events(struct module *mod)
68547
68548 for_each_event(call, start, end) {
68549 __trace_add_event_call(*call, mod,
68550- &file_ops->id, &file_ops->enable,
68551- &file_ops->filter, &file_ops->format);
68552+ &mod->trace_id, &mod->trace_enable,
68553+ &mod->trace_filter, &mod->trace_format);
68554 }
68555 }
68556
68557diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
68558index 00d527c..7c5b1a3 100644
68559--- a/kernel/trace/trace_kprobe.c
68560+++ b/kernel/trace/trace_kprobe.c
68561@@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
68562 long ret;
68563 int maxlen = get_rloc_len(*(u32 *)dest);
68564 u8 *dst = get_rloc_data(dest);
68565- u8 *src = addr;
68566+ const u8 __user *src = (const u8 __force_user *)addr;
68567 mm_segment_t old_fs = get_fs();
68568 if (!maxlen)
68569 return;
68570@@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
68571 pagefault_disable();
68572 do
68573 ret = __copy_from_user_inatomic(dst++, src++, 1);
68574- while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
68575+ while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
68576 dst[-1] = '\0';
68577 pagefault_enable();
68578 set_fs(old_fs);
68579@@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
68580 ((u8 *)get_rloc_data(dest))[0] = '\0';
68581 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
68582 } else
68583- *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
68584+ *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
68585 get_rloc_offs(*(u32 *)dest));
68586 }
68587 /* Return the length of string -- including null terminal byte */
68588@@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
68589 set_fs(KERNEL_DS);
68590 pagefault_disable();
68591 do {
68592- ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
68593+ ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
68594 len++;
68595 } while (c && ret == 0 && len < MAX_STRING_SIZE);
68596 pagefault_enable();
68597diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
68598index fd3c8aa..5f324a6 100644
68599--- a/kernel/trace/trace_mmiotrace.c
68600+++ b/kernel/trace/trace_mmiotrace.c
68601@@ -24,7 +24,7 @@ struct header_iter {
68602 static struct trace_array *mmio_trace_array;
68603 static bool overrun_detected;
68604 static unsigned long prev_overruns;
68605-static atomic_t dropped_count;
68606+static atomic_unchecked_t dropped_count;
68607
68608 static void mmio_reset_data(struct trace_array *tr)
68609 {
68610@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
68611
68612 static unsigned long count_overruns(struct trace_iterator *iter)
68613 {
68614- unsigned long cnt = atomic_xchg(&dropped_count, 0);
68615+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
68616 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
68617
68618 if (over > prev_overruns)
68619@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
68620 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
68621 sizeof(*entry), 0, pc);
68622 if (!event) {
68623- atomic_inc(&dropped_count);
68624+ atomic_inc_unchecked(&dropped_count);
68625 return;
68626 }
68627 entry = ring_buffer_event_data(event);
68628@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
68629 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
68630 sizeof(*entry), 0, pc);
68631 if (!event) {
68632- atomic_inc(&dropped_count);
68633+ atomic_inc_unchecked(&dropped_count);
68634 return;
68635 }
68636 entry = ring_buffer_event_data(event);
68637diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
68638index 0d6ff35..67e0ed7 100644
68639--- a/kernel/trace/trace_output.c
68640+++ b/kernel/trace/trace_output.c
68641@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
68642
68643 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
68644 if (!IS_ERR(p)) {
68645- p = mangle_path(s->buffer + s->len, p, "\n");
68646+ p = mangle_path(s->buffer + s->len, p, "\n\\");
68647 if (p) {
68648 s->len = p - s->buffer;
68649 return 1;
68650diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
68651index d4545f4..a9010a1 100644
68652--- a/kernel/trace/trace_stack.c
68653+++ b/kernel/trace/trace_stack.c
68654@@ -53,7 +53,7 @@ static inline void check_stack(void)
68655 return;
68656
68657 /* we do not handle interrupt stacks yet */
68658- if (!object_is_on_stack(&this_size))
68659+ if (!object_starts_on_stack(&this_size))
68660 return;
68661
68662 local_irq_save(flags);
68663diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
68664index 209b379..7f76423 100644
68665--- a/kernel/trace/trace_workqueue.c
68666+++ b/kernel/trace/trace_workqueue.c
68667@@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
68668 int cpu;
68669 pid_t pid;
68670 /* Can be inserted from interrupt or user context, need to be atomic */
68671- atomic_t inserted;
68672+ atomic_unchecked_t inserted;
68673 /*
68674 * Don't need to be atomic, works are serialized in a single workqueue thread
68675 * on a single CPU.
68676@@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
68677 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
68678 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
68679 if (node->pid == wq_thread->pid) {
68680- atomic_inc(&node->inserted);
68681+ atomic_inc_unchecked(&node->inserted);
68682 goto found;
68683 }
68684 }
68685@@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
68686 tsk = get_pid_task(pid, PIDTYPE_PID);
68687 if (tsk) {
68688 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
68689- atomic_read(&cws->inserted), cws->executed,
68690+ atomic_read_unchecked(&cws->inserted), cws->executed,
68691 tsk->comm);
68692 put_task_struct(tsk);
68693 }
68694diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
68695index 8745ac7..d144e37 100644
68696--- a/lib/Kconfig.debug
68697+++ b/lib/Kconfig.debug
68698@@ -1103,6 +1103,7 @@ config LATENCYTOP
68699 depends on DEBUG_KERNEL
68700 depends on STACKTRACE_SUPPORT
68701 depends on PROC_FS
68702+ depends on !GRKERNSEC_HIDESYM
68703 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
68704 select KALLSYMS
68705 select KALLSYMS_ALL
68706diff --git a/lib/bitmap.c b/lib/bitmap.c
68707index 0d4a127..33a06c7 100644
68708--- a/lib/bitmap.c
68709+++ b/lib/bitmap.c
68710@@ -419,7 +419,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
68711 {
68712 int c, old_c, totaldigits, ndigits, nchunks, nbits;
68713 u32 chunk;
68714- const char __user __force *ubuf = (const char __user __force *)buf;
68715+ const char __user *ubuf = (const char __force_user *)buf;
68716
68717 bitmap_zero(maskp, nmaskbits);
68718
68719@@ -504,7 +504,7 @@ int bitmap_parse_user(const char __user *ubuf,
68720 {
68721 if (!access_ok(VERIFY_READ, ubuf, ulen))
68722 return -EFAULT;
68723- return __bitmap_parse((const char __force *)ubuf,
68724+ return __bitmap_parse((const char __force_kernel *)ubuf,
68725 ulen, 1, maskp, nmaskbits);
68726
68727 }
68728@@ -596,7 +596,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
68729 {
68730 unsigned a, b;
68731 int c, old_c, totaldigits;
68732- const char __user __force *ubuf = (const char __user __force *)buf;
68733+ const char __user *ubuf = (const char __force_user *)buf;
68734 int exp_digit, in_range;
68735
68736 totaldigits = c = 0;
68737@@ -696,7 +696,7 @@ int bitmap_parselist_user(const char __user *ubuf,
68738 {
68739 if (!access_ok(VERIFY_READ, ubuf, ulen))
68740 return -EFAULT;
68741- return __bitmap_parselist((const char __force *)ubuf,
68742+ return __bitmap_parselist((const char __force_kernel *)ubuf,
68743 ulen, 1, maskp, nmaskbits);
68744 }
68745 EXPORT_SYMBOL(bitmap_parselist_user);
68746diff --git a/lib/bug.c b/lib/bug.c
68747index a28c141..2bd3d95 100644
68748--- a/lib/bug.c
68749+++ b/lib/bug.c
68750@@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
68751 return BUG_TRAP_TYPE_NONE;
68752
68753 bug = find_bug(bugaddr);
68754+ if (!bug)
68755+ return BUG_TRAP_TYPE_NONE;
68756
68757 file = NULL;
68758 line = 0;
68759diff --git a/lib/debugobjects.c b/lib/debugobjects.c
68760index 0ab9ae8..f01ceca 100644
68761--- a/lib/debugobjects.c
68762+++ b/lib/debugobjects.c
68763@@ -288,7 +288,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
68764 if (limit > 4)
68765 return;
68766
68767- is_on_stack = object_is_on_stack(addr);
68768+ is_on_stack = object_starts_on_stack(addr);
68769 if (is_on_stack == onstack)
68770 return;
68771
68772diff --git a/lib/devres.c b/lib/devres.c
68773index 9676617..5149e15 100644
68774--- a/lib/devres.c
68775+++ b/lib/devres.c
68776@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
68777 void devm_iounmap(struct device *dev, void __iomem *addr)
68778 {
68779 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
68780- (void *)addr));
68781+ (void __force *)addr));
68782 iounmap(addr);
68783 }
68784 EXPORT_SYMBOL(devm_iounmap);
68785@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
68786 {
68787 ioport_unmap(addr);
68788 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
68789- devm_ioport_map_match, (void *)addr));
68790+ devm_ioport_map_match, (void __force *)addr));
68791 }
68792 EXPORT_SYMBOL(devm_ioport_unmap);
68793
68794diff --git a/lib/dma-debug.c b/lib/dma-debug.c
68795index fea790a..ebb0e82 100644
68796--- a/lib/dma-debug.c
68797+++ b/lib/dma-debug.c
68798@@ -925,7 +925,7 @@ out:
68799
68800 static void check_for_stack(struct device *dev, void *addr)
68801 {
68802- if (object_is_on_stack(addr))
68803+ if (object_starts_on_stack(addr))
68804 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
68805 "stack [addr=%p]\n", addr);
68806 }
68807diff --git a/lib/extable.c b/lib/extable.c
68808index 4cac81e..63e9b8f 100644
68809--- a/lib/extable.c
68810+++ b/lib/extable.c
68811@@ -13,6 +13,7 @@
68812 #include <linux/init.h>
68813 #include <linux/sort.h>
68814 #include <asm/uaccess.h>
68815+#include <asm/pgtable.h>
68816
68817 #ifndef ARCH_HAS_SORT_EXTABLE
68818 /*
68819@@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
68820 void sort_extable(struct exception_table_entry *start,
68821 struct exception_table_entry *finish)
68822 {
68823+ pax_open_kernel();
68824 sort(start, finish - start, sizeof(struct exception_table_entry),
68825 cmp_ex, NULL);
68826+ pax_close_kernel();
68827 }
68828
68829 #ifdef CONFIG_MODULES
68830diff --git a/lib/inflate.c b/lib/inflate.c
68831index 013a761..c28f3fc 100644
68832--- a/lib/inflate.c
68833+++ b/lib/inflate.c
68834@@ -269,7 +269,7 @@ static void free(void *where)
68835 malloc_ptr = free_mem_ptr;
68836 }
68837 #else
68838-#define malloc(a) kmalloc(a, GFP_KERNEL)
68839+#define malloc(a) kmalloc((a), GFP_KERNEL)
68840 #define free(a) kfree(a)
68841 #endif
68842
68843diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
68844index bd2bea9..6b3c95e 100644
68845--- a/lib/is_single_threaded.c
68846+++ b/lib/is_single_threaded.c
68847@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
68848 struct task_struct *p, *t;
68849 bool ret;
68850
68851+ if (!mm)
68852+ return true;
68853+
68854 if (atomic_read(&task->signal->live) != 1)
68855 return false;
68856
68857diff --git a/lib/radix-tree.c b/lib/radix-tree.c
68858index dc63d08..95ae14a 100644
68859--- a/lib/radix-tree.c
68860+++ b/lib/radix-tree.c
68861@@ -78,7 +78,7 @@ struct radix_tree_preload {
68862 int nr;
68863 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
68864 };
68865-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
68866+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
68867
68868 static inline void *ptr_to_indirect(void *ptr)
68869 {
68870diff --git a/lib/vsprintf.c b/lib/vsprintf.c
68871index 38e612e..4fb99a8 100644
68872--- a/lib/vsprintf.c
68873+++ b/lib/vsprintf.c
68874@@ -16,6 +16,9 @@
68875 * - scnprintf and vscnprintf
68876 */
68877
68878+#ifdef CONFIG_GRKERNSEC_HIDESYM
68879+#define __INCLUDED_BY_HIDESYM 1
68880+#endif
68881 #include <stdarg.h>
68882 #include <linux/module.h>
68883 #include <linux/types.h>
68884@@ -413,7 +416,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
68885 char sym[KSYM_SYMBOL_LEN];
68886 if (ext == 'B')
68887 sprint_backtrace(sym, value);
68888- else if (ext != 'f' && ext != 's')
68889+ else if (ext != 'f' && ext != 's' && ext != 'a')
68890 sprint_symbol(sym, value);
68891 else
68892 kallsyms_lookup(value, NULL, NULL, NULL, sym);
68893@@ -789,7 +792,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
68894 return number(buf, end, *(const netdev_features_t *)addr, spec);
68895 }
68896
68897+#ifdef CONFIG_GRKERNSEC_HIDESYM
68898+int kptr_restrict __read_mostly = 2;
68899+#else
68900 int kptr_restrict __read_mostly;
68901+#endif
68902
68903 /*
68904 * Show a '%p' thing. A kernel extension is that the '%p' is followed
68905@@ -803,6 +810,8 @@ int kptr_restrict __read_mostly;
68906 * - 'S' For symbolic direct pointers with offset
68907 * - 's' For symbolic direct pointers without offset
68908 * - 'B' For backtraced symbolic direct pointers with offset
68909+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
68910+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
68911 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
68912 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
68913 * - 'M' For a 6-byte MAC address, it prints the address in the
68914@@ -848,12 +857,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
68915 {
68916 if (!ptr && *fmt != 'K') {
68917 /*
68918- * Print (null) with the same width as a pointer so it makes
68919+ * Print (nil) with the same width as a pointer so it makes
68920 * tabular output look nice.
68921 */
68922 if (spec.field_width == -1)
68923 spec.field_width = 2 * sizeof(void *);
68924- return string(buf, end, "(null)", spec);
68925+ return string(buf, end, "(nil)", spec);
68926 }
68927
68928 switch (*fmt) {
68929@@ -863,6 +872,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
68930 /* Fallthrough */
68931 case 'S':
68932 case 's':
68933+#ifdef CONFIG_GRKERNSEC_HIDESYM
68934+ break;
68935+#else
68936+ return symbol_string(buf, end, ptr, spec, *fmt);
68937+#endif
68938+ case 'A':
68939+ case 'a':
68940 case 'B':
68941 return symbol_string(buf, end, ptr, spec, *fmt);
68942 case 'R':
68943@@ -1633,11 +1649,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
68944 typeof(type) value; \
68945 if (sizeof(type) == 8) { \
68946 args = PTR_ALIGN(args, sizeof(u32)); \
68947- *(u32 *)&value = *(u32 *)args; \
68948- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
68949+ *(u32 *)&value = *(const u32 *)args; \
68950+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
68951 } else { \
68952 args = PTR_ALIGN(args, sizeof(type)); \
68953- value = *(typeof(type) *)args; \
68954+ value = *(const typeof(type) *)args; \
68955 } \
68956 args += sizeof(type); \
68957 value; \
68958@@ -1700,7 +1716,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
68959 case FORMAT_TYPE_STR: {
68960 const char *str_arg = args;
68961 args += strlen(str_arg) + 1;
68962- str = string(str, end, (char *)str_arg, spec);
68963+ str = string(str, end, str_arg, spec);
68964 break;
68965 }
68966
68967diff --git a/localversion-grsec b/localversion-grsec
68968new file mode 100644
68969index 0000000..7cd6065
68970--- /dev/null
68971+++ b/localversion-grsec
68972@@ -0,0 +1 @@
68973+-grsec
68974diff --git a/mm/Kconfig b/mm/Kconfig
68975index e338407..49b5b7a 100644
68976--- a/mm/Kconfig
68977+++ b/mm/Kconfig
68978@@ -247,10 +247,10 @@ config KSM
68979 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
68980
68981 config DEFAULT_MMAP_MIN_ADDR
68982- int "Low address space to protect from user allocation"
68983+ int "Low address space to protect from user allocation"
68984 depends on MMU
68985- default 4096
68986- help
68987+ default 65536
68988+ help
68989 This is the portion of low virtual memory which should be protected
68990 from userspace allocation. Keeping a user from writing to low pages
68991 can help reduce the impact of kernel NULL pointer bugs.
68992diff --git a/mm/filemap.c b/mm/filemap.c
68993index b662757..3081ddd 100644
68994--- a/mm/filemap.c
68995+++ b/mm/filemap.c
68996@@ -1770,7 +1770,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
68997 struct address_space *mapping = file->f_mapping;
68998
68999 if (!mapping->a_ops->readpage)
69000- return -ENOEXEC;
69001+ return -ENODEV;
69002 file_accessed(file);
69003 vma->vm_ops = &generic_file_vm_ops;
69004 vma->vm_flags |= VM_CAN_NONLINEAR;
69005@@ -2176,6 +2176,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
69006 *pos = i_size_read(inode);
69007
69008 if (limit != RLIM_INFINITY) {
69009+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
69010 if (*pos >= limit) {
69011 send_sig(SIGXFSZ, current, 0);
69012 return -EFBIG;
69013diff --git a/mm/fremap.c b/mm/fremap.c
69014index 9ed4fd4..c42648d 100644
69015--- a/mm/fremap.c
69016+++ b/mm/fremap.c
69017@@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
69018 retry:
69019 vma = find_vma(mm, start);
69020
69021+#ifdef CONFIG_PAX_SEGMEXEC
69022+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
69023+ goto out;
69024+#endif
69025+
69026 /*
69027 * Make sure the vma is shared, that it supports prefaulting,
69028 * and that the remapped range is valid and fully within
69029diff --git a/mm/highmem.c b/mm/highmem.c
69030index 57d82c6..e9e0552 100644
69031--- a/mm/highmem.c
69032+++ b/mm/highmem.c
69033@@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
69034 * So no dangers, even with speculative execution.
69035 */
69036 page = pte_page(pkmap_page_table[i]);
69037+ pax_open_kernel();
69038 pte_clear(&init_mm, (unsigned long)page_address(page),
69039 &pkmap_page_table[i]);
69040-
69041+ pax_close_kernel();
69042 set_page_address(page, NULL);
69043 need_flush = 1;
69044 }
69045@@ -186,9 +187,11 @@ start:
69046 }
69047 }
69048 vaddr = PKMAP_ADDR(last_pkmap_nr);
69049+
69050+ pax_open_kernel();
69051 set_pte_at(&init_mm, vaddr,
69052 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
69053-
69054+ pax_close_kernel();
69055 pkmap_count[last_pkmap_nr] = 1;
69056 set_page_address(page, (void *)vaddr);
69057
69058diff --git a/mm/huge_memory.c b/mm/huge_memory.c
69059index 8f7fc39..69bf1e9 100644
69060--- a/mm/huge_memory.c
69061+++ b/mm/huge_memory.c
69062@@ -733,7 +733,7 @@ out:
69063 * run pte_offset_map on the pmd, if an huge pmd could
69064 * materialize from under us from a different thread.
69065 */
69066- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
69067+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
69068 return VM_FAULT_OOM;
69069 /* if an huge pmd materialized from under us just retry later */
69070 if (unlikely(pmd_trans_huge(*pmd)))
69071diff --git a/mm/hugetlb.c b/mm/hugetlb.c
69072index a876871..132cde0 100644
69073--- a/mm/hugetlb.c
69074+++ b/mm/hugetlb.c
69075@@ -2346,6 +2346,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
69076 return 1;
69077 }
69078
69079+#ifdef CONFIG_PAX_SEGMEXEC
69080+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
69081+{
69082+ struct mm_struct *mm = vma->vm_mm;
69083+ struct vm_area_struct *vma_m;
69084+ unsigned long address_m;
69085+ pte_t *ptep_m;
69086+
69087+ vma_m = pax_find_mirror_vma(vma);
69088+ if (!vma_m)
69089+ return;
69090+
69091+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
69092+ address_m = address + SEGMEXEC_TASK_SIZE;
69093+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
69094+ get_page(page_m);
69095+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
69096+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
69097+}
69098+#endif
69099+
69100 /*
69101 * Hugetlb_cow() should be called with page lock of the original hugepage held.
69102 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
69103@@ -2459,6 +2480,11 @@ retry_avoidcopy:
69104 make_huge_pte(vma, new_page, 1));
69105 page_remove_rmap(old_page);
69106 hugepage_add_new_anon_rmap(new_page, vma, address);
69107+
69108+#ifdef CONFIG_PAX_SEGMEXEC
69109+ pax_mirror_huge_pte(vma, address, new_page);
69110+#endif
69111+
69112 /* Make the old page be freed below */
69113 new_page = old_page;
69114 mmu_notifier_invalidate_range_end(mm,
69115@@ -2613,6 +2639,10 @@ retry:
69116 && (vma->vm_flags & VM_SHARED)));
69117 set_huge_pte_at(mm, address, ptep, new_pte);
69118
69119+#ifdef CONFIG_PAX_SEGMEXEC
69120+ pax_mirror_huge_pte(vma, address, page);
69121+#endif
69122+
69123 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
69124 /* Optimization, do the COW without a second fault */
69125 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
69126@@ -2642,6 +2672,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69127 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
69128 struct hstate *h = hstate_vma(vma);
69129
69130+#ifdef CONFIG_PAX_SEGMEXEC
69131+ struct vm_area_struct *vma_m;
69132+#endif
69133+
69134 address &= huge_page_mask(h);
69135
69136 ptep = huge_pte_offset(mm, address);
69137@@ -2655,6 +2689,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69138 VM_FAULT_SET_HINDEX(h - hstates);
69139 }
69140
69141+#ifdef CONFIG_PAX_SEGMEXEC
69142+ vma_m = pax_find_mirror_vma(vma);
69143+ if (vma_m) {
69144+ unsigned long address_m;
69145+
69146+ if (vma->vm_start > vma_m->vm_start) {
69147+ address_m = address;
69148+ address -= SEGMEXEC_TASK_SIZE;
69149+ vma = vma_m;
69150+ h = hstate_vma(vma);
69151+ } else
69152+ address_m = address + SEGMEXEC_TASK_SIZE;
69153+
69154+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
69155+ return VM_FAULT_OOM;
69156+ address_m &= HPAGE_MASK;
69157+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
69158+ }
69159+#endif
69160+
69161 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
69162 if (!ptep)
69163 return VM_FAULT_OOM;
69164diff --git a/mm/internal.h b/mm/internal.h
69165index 2189af4..f2ca332 100644
69166--- a/mm/internal.h
69167+++ b/mm/internal.h
69168@@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
69169 * in mm/page_alloc.c
69170 */
69171 extern void __free_pages_bootmem(struct page *page, unsigned int order);
69172+extern void free_compound_page(struct page *page);
69173 extern void prep_compound_page(struct page *page, unsigned long order);
69174 #ifdef CONFIG_MEMORY_FAILURE
69175 extern bool is_free_buddy_page(struct page *page);
69176diff --git a/mm/kmemleak.c b/mm/kmemleak.c
69177index 45eb621..6ccd8ea 100644
69178--- a/mm/kmemleak.c
69179+++ b/mm/kmemleak.c
69180@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
69181
69182 for (i = 0; i < object->trace_len; i++) {
69183 void *ptr = (void *)object->trace[i];
69184- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
69185+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
69186 }
69187 }
69188
69189diff --git a/mm/maccess.c b/mm/maccess.c
69190index d53adf9..03a24bf 100644
69191--- a/mm/maccess.c
69192+++ b/mm/maccess.c
69193@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
69194 set_fs(KERNEL_DS);
69195 pagefault_disable();
69196 ret = __copy_from_user_inatomic(dst,
69197- (__force const void __user *)src, size);
69198+ (const void __force_user *)src, size);
69199 pagefault_enable();
69200 set_fs(old_fs);
69201
69202@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
69203
69204 set_fs(KERNEL_DS);
69205 pagefault_disable();
69206- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
69207+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
69208 pagefault_enable();
69209 set_fs(old_fs);
69210
69211diff --git a/mm/madvise.c b/mm/madvise.c
69212index 74bf193..feb6fd3 100644
69213--- a/mm/madvise.c
69214+++ b/mm/madvise.c
69215@@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
69216 pgoff_t pgoff;
69217 unsigned long new_flags = vma->vm_flags;
69218
69219+#ifdef CONFIG_PAX_SEGMEXEC
69220+ struct vm_area_struct *vma_m;
69221+#endif
69222+
69223 switch (behavior) {
69224 case MADV_NORMAL:
69225 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
69226@@ -110,6 +114,13 @@ success:
69227 /*
69228 * vm_flags is protected by the mmap_sem held in write mode.
69229 */
69230+
69231+#ifdef CONFIG_PAX_SEGMEXEC
69232+ vma_m = pax_find_mirror_vma(vma);
69233+ if (vma_m)
69234+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
69235+#endif
69236+
69237 vma->vm_flags = new_flags;
69238
69239 out:
69240@@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
69241 struct vm_area_struct ** prev,
69242 unsigned long start, unsigned long end)
69243 {
69244+
69245+#ifdef CONFIG_PAX_SEGMEXEC
69246+ struct vm_area_struct *vma_m;
69247+#endif
69248+
69249 *prev = vma;
69250 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
69251 return -EINVAL;
69252@@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
69253 zap_page_range(vma, start, end - start, &details);
69254 } else
69255 zap_page_range(vma, start, end - start, NULL);
69256+
69257+#ifdef CONFIG_PAX_SEGMEXEC
69258+ vma_m = pax_find_mirror_vma(vma);
69259+ if (vma_m) {
69260+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
69261+ struct zap_details details = {
69262+ .nonlinear_vma = vma_m,
69263+ .last_index = ULONG_MAX,
69264+ };
69265+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
69266+ } else
69267+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
69268+ }
69269+#endif
69270+
69271 return 0;
69272 }
69273
69274@@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
69275 if (end < start)
69276 goto out;
69277
69278+#ifdef CONFIG_PAX_SEGMEXEC
69279+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
69280+ if (end > SEGMEXEC_TASK_SIZE)
69281+ goto out;
69282+ } else
69283+#endif
69284+
69285+ if (end > TASK_SIZE)
69286+ goto out;
69287+
69288 error = 0;
69289 if (end == start)
69290 goto out;
69291diff --git a/mm/memory-failure.c b/mm/memory-failure.c
69292index 56080ea..115071e 100644
69293--- a/mm/memory-failure.c
69294+++ b/mm/memory-failure.c
69295@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
69296
69297 int sysctl_memory_failure_recovery __read_mostly = 1;
69298
69299-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
69300+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
69301
69302 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
69303
69304@@ -202,7 +202,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
69305 si.si_signo = SIGBUS;
69306 si.si_errno = 0;
69307 si.si_code = BUS_MCEERR_AO;
69308- si.si_addr = (void *)addr;
69309+ si.si_addr = (void __user *)addr;
69310 #ifdef __ARCH_SI_TRAPNO
69311 si.si_trapno = trapno;
69312 #endif
69313@@ -1010,7 +1010,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
69314 }
69315
69316 nr_pages = 1 << compound_trans_order(hpage);
69317- atomic_long_add(nr_pages, &mce_bad_pages);
69318+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
69319
69320 /*
69321 * We need/can do nothing about count=0 pages.
69322@@ -1040,7 +1040,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
69323 if (!PageHWPoison(hpage)
69324 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
69325 || (p != hpage && TestSetPageHWPoison(hpage))) {
69326- atomic_long_sub(nr_pages, &mce_bad_pages);
69327+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69328 return 0;
69329 }
69330 set_page_hwpoison_huge_page(hpage);
69331@@ -1098,7 +1098,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
69332 }
69333 if (hwpoison_filter(p)) {
69334 if (TestClearPageHWPoison(p))
69335- atomic_long_sub(nr_pages, &mce_bad_pages);
69336+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69337 unlock_page(hpage);
69338 put_page(hpage);
69339 return 0;
69340@@ -1315,7 +1315,7 @@ int unpoison_memory(unsigned long pfn)
69341 return 0;
69342 }
69343 if (TestClearPageHWPoison(p))
69344- atomic_long_sub(nr_pages, &mce_bad_pages);
69345+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69346 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
69347 return 0;
69348 }
69349@@ -1329,7 +1329,7 @@ int unpoison_memory(unsigned long pfn)
69350 */
69351 if (TestClearPageHWPoison(page)) {
69352 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
69353- atomic_long_sub(nr_pages, &mce_bad_pages);
69354+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69355 freeit = 1;
69356 if (PageHuge(page))
69357 clear_page_hwpoison_huge_page(page);
69358@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
69359 }
69360 done:
69361 if (!PageHWPoison(hpage))
69362- atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
69363+ atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
69364 set_page_hwpoison_huge_page(hpage);
69365 dequeue_hwpoisoned_huge_page(hpage);
69366 /* keep elevated page count for bad page */
69367@@ -1573,7 +1573,7 @@ int soft_offline_page(struct page *page, int flags)
69368 return ret;
69369
69370 done:
69371- atomic_long_add(1, &mce_bad_pages);
69372+ atomic_long_add_unchecked(1, &mce_bad_pages);
69373 SetPageHWPoison(page);
69374 /* keep elevated page count for bad page */
69375 return ret;
69376diff --git a/mm/memory.c b/mm/memory.c
69377index 10b4dda..764ee07 100644
69378--- a/mm/memory.c
69379+++ b/mm/memory.c
69380@@ -457,8 +457,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
69381 return;
69382
69383 pmd = pmd_offset(pud, start);
69384+
69385+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
69386 pud_clear(pud);
69387 pmd_free_tlb(tlb, pmd, start);
69388+#endif
69389+
69390 }
69391
69392 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
69393@@ -489,9 +493,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
69394 if (end - 1 > ceiling - 1)
69395 return;
69396
69397+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
69398 pud = pud_offset(pgd, start);
69399 pgd_clear(pgd);
69400 pud_free_tlb(tlb, pud, start);
69401+#endif
69402+
69403 }
69404
69405 /*
69406@@ -1593,12 +1600,6 @@ no_page_table:
69407 return page;
69408 }
69409
69410-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
69411-{
69412- return stack_guard_page_start(vma, addr) ||
69413- stack_guard_page_end(vma, addr+PAGE_SIZE);
69414-}
69415-
69416 /**
69417 * __get_user_pages() - pin user pages in memory
69418 * @tsk: task_struct of target task
69419@@ -1671,10 +1672,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69420 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
69421 i = 0;
69422
69423- do {
69424+ while (nr_pages) {
69425 struct vm_area_struct *vma;
69426
69427- vma = find_extend_vma(mm, start);
69428+ vma = find_vma(mm, start);
69429 if (!vma && in_gate_area(mm, start)) {
69430 unsigned long pg = start & PAGE_MASK;
69431 pgd_t *pgd;
69432@@ -1722,7 +1723,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69433 goto next_page;
69434 }
69435
69436- if (!vma ||
69437+ if (!vma || start < vma->vm_start ||
69438 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
69439 !(vm_flags & vma->vm_flags))
69440 return i ? : -EFAULT;
69441@@ -1749,11 +1750,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69442 int ret;
69443 unsigned int fault_flags = 0;
69444
69445- /* For mlock, just skip the stack guard page. */
69446- if (foll_flags & FOLL_MLOCK) {
69447- if (stack_guard_page(vma, start))
69448- goto next_page;
69449- }
69450 if (foll_flags & FOLL_WRITE)
69451 fault_flags |= FAULT_FLAG_WRITE;
69452 if (nonblocking)
69453@@ -1827,7 +1823,7 @@ next_page:
69454 start += PAGE_SIZE;
69455 nr_pages--;
69456 } while (nr_pages && start < vma->vm_end);
69457- } while (nr_pages);
69458+ }
69459 return i;
69460 }
69461 EXPORT_SYMBOL(__get_user_pages);
69462@@ -2034,6 +2030,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
69463 page_add_file_rmap(page);
69464 set_pte_at(mm, addr, pte, mk_pte(page, prot));
69465
69466+#ifdef CONFIG_PAX_SEGMEXEC
69467+ pax_mirror_file_pte(vma, addr, page, ptl);
69468+#endif
69469+
69470 retval = 0;
69471 pte_unmap_unlock(pte, ptl);
69472 return retval;
69473@@ -2068,10 +2068,22 @@ out:
69474 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
69475 struct page *page)
69476 {
69477+
69478+#ifdef CONFIG_PAX_SEGMEXEC
69479+ struct vm_area_struct *vma_m;
69480+#endif
69481+
69482 if (addr < vma->vm_start || addr >= vma->vm_end)
69483 return -EFAULT;
69484 if (!page_count(page))
69485 return -EINVAL;
69486+
69487+#ifdef CONFIG_PAX_SEGMEXEC
69488+ vma_m = pax_find_mirror_vma(vma);
69489+ if (vma_m)
69490+ vma_m->vm_flags |= VM_INSERTPAGE;
69491+#endif
69492+
69493 vma->vm_flags |= VM_INSERTPAGE;
69494 return insert_page(vma, addr, page, vma->vm_page_prot);
69495 }
69496@@ -2157,6 +2169,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
69497 unsigned long pfn)
69498 {
69499 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
69500+ BUG_ON(vma->vm_mirror);
69501
69502 if (addr < vma->vm_start || addr >= vma->vm_end)
69503 return -EFAULT;
69504@@ -2472,6 +2485,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
69505 copy_user_highpage(dst, src, va, vma);
69506 }
69507
69508+#ifdef CONFIG_PAX_SEGMEXEC
69509+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
69510+{
69511+ struct mm_struct *mm = vma->vm_mm;
69512+ spinlock_t *ptl;
69513+ pte_t *pte, entry;
69514+
69515+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
69516+ entry = *pte;
69517+ if (!pte_present(entry)) {
69518+ if (!pte_none(entry)) {
69519+ BUG_ON(pte_file(entry));
69520+ free_swap_and_cache(pte_to_swp_entry(entry));
69521+ pte_clear_not_present_full(mm, address, pte, 0);
69522+ }
69523+ } else {
69524+ struct page *page;
69525+
69526+ flush_cache_page(vma, address, pte_pfn(entry));
69527+ entry = ptep_clear_flush(vma, address, pte);
69528+ BUG_ON(pte_dirty(entry));
69529+ page = vm_normal_page(vma, address, entry);
69530+ if (page) {
69531+ update_hiwater_rss(mm);
69532+ if (PageAnon(page))
69533+ dec_mm_counter_fast(mm, MM_ANONPAGES);
69534+ else
69535+ dec_mm_counter_fast(mm, MM_FILEPAGES);
69536+ page_remove_rmap(page);
69537+ page_cache_release(page);
69538+ }
69539+ }
69540+ pte_unmap_unlock(pte, ptl);
69541+}
69542+
69543+/* PaX: if vma is mirrored, synchronize the mirror's PTE
69544+ *
69545+ * the ptl of the lower mapped page is held on entry and is not released on exit
69546+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
69547+ */
69548+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
69549+{
69550+ struct mm_struct *mm = vma->vm_mm;
69551+ unsigned long address_m;
69552+ spinlock_t *ptl_m;
69553+ struct vm_area_struct *vma_m;
69554+ pmd_t *pmd_m;
69555+ pte_t *pte_m, entry_m;
69556+
69557+ BUG_ON(!page_m || !PageAnon(page_m));
69558+
69559+ vma_m = pax_find_mirror_vma(vma);
69560+ if (!vma_m)
69561+ return;
69562+
69563+ BUG_ON(!PageLocked(page_m));
69564+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
69565+ address_m = address + SEGMEXEC_TASK_SIZE;
69566+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
69567+ pte_m = pte_offset_map(pmd_m, address_m);
69568+ ptl_m = pte_lockptr(mm, pmd_m);
69569+ if (ptl != ptl_m) {
69570+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
69571+ if (!pte_none(*pte_m))
69572+ goto out;
69573+ }
69574+
69575+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
69576+ page_cache_get(page_m);
69577+ page_add_anon_rmap(page_m, vma_m, address_m);
69578+ inc_mm_counter_fast(mm, MM_ANONPAGES);
69579+ set_pte_at(mm, address_m, pte_m, entry_m);
69580+ update_mmu_cache(vma_m, address_m, entry_m);
69581+out:
69582+ if (ptl != ptl_m)
69583+ spin_unlock(ptl_m);
69584+ pte_unmap(pte_m);
69585+ unlock_page(page_m);
69586+}
69587+
69588+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
69589+{
69590+ struct mm_struct *mm = vma->vm_mm;
69591+ unsigned long address_m;
69592+ spinlock_t *ptl_m;
69593+ struct vm_area_struct *vma_m;
69594+ pmd_t *pmd_m;
69595+ pte_t *pte_m, entry_m;
69596+
69597+ BUG_ON(!page_m || PageAnon(page_m));
69598+
69599+ vma_m = pax_find_mirror_vma(vma);
69600+ if (!vma_m)
69601+ return;
69602+
69603+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
69604+ address_m = address + SEGMEXEC_TASK_SIZE;
69605+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
69606+ pte_m = pte_offset_map(pmd_m, address_m);
69607+ ptl_m = pte_lockptr(mm, pmd_m);
69608+ if (ptl != ptl_m) {
69609+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
69610+ if (!pte_none(*pte_m))
69611+ goto out;
69612+ }
69613+
69614+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
69615+ page_cache_get(page_m);
69616+ page_add_file_rmap(page_m);
69617+ inc_mm_counter_fast(mm, MM_FILEPAGES);
69618+ set_pte_at(mm, address_m, pte_m, entry_m);
69619+ update_mmu_cache(vma_m, address_m, entry_m);
69620+out:
69621+ if (ptl != ptl_m)
69622+ spin_unlock(ptl_m);
69623+ pte_unmap(pte_m);
69624+}
69625+
69626+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
69627+{
69628+ struct mm_struct *mm = vma->vm_mm;
69629+ unsigned long address_m;
69630+ spinlock_t *ptl_m;
69631+ struct vm_area_struct *vma_m;
69632+ pmd_t *pmd_m;
69633+ pte_t *pte_m, entry_m;
69634+
69635+ vma_m = pax_find_mirror_vma(vma);
69636+ if (!vma_m)
69637+ return;
69638+
69639+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
69640+ address_m = address + SEGMEXEC_TASK_SIZE;
69641+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
69642+ pte_m = pte_offset_map(pmd_m, address_m);
69643+ ptl_m = pte_lockptr(mm, pmd_m);
69644+ if (ptl != ptl_m) {
69645+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
69646+ if (!pte_none(*pte_m))
69647+ goto out;
69648+ }
69649+
69650+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
69651+ set_pte_at(mm, address_m, pte_m, entry_m);
69652+out:
69653+ if (ptl != ptl_m)
69654+ spin_unlock(ptl_m);
69655+ pte_unmap(pte_m);
69656+}
69657+
69658+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
69659+{
69660+ struct page *page_m;
69661+ pte_t entry;
69662+
69663+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
69664+ goto out;
69665+
69666+ entry = *pte;
69667+ page_m = vm_normal_page(vma, address, entry);
69668+ if (!page_m)
69669+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
69670+ else if (PageAnon(page_m)) {
69671+ if (pax_find_mirror_vma(vma)) {
69672+ pte_unmap_unlock(pte, ptl);
69673+ lock_page(page_m);
69674+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
69675+ if (pte_same(entry, *pte))
69676+ pax_mirror_anon_pte(vma, address, page_m, ptl);
69677+ else
69678+ unlock_page(page_m);
69679+ }
69680+ } else
69681+ pax_mirror_file_pte(vma, address, page_m, ptl);
69682+
69683+out:
69684+ pte_unmap_unlock(pte, ptl);
69685+}
69686+#endif
69687+
69688 /*
69689 * This routine handles present pages, when users try to write
69690 * to a shared page. It is done by copying the page to a new address
69691@@ -2683,6 +2876,12 @@ gotten:
69692 */
69693 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
69694 if (likely(pte_same(*page_table, orig_pte))) {
69695+
69696+#ifdef CONFIG_PAX_SEGMEXEC
69697+ if (pax_find_mirror_vma(vma))
69698+ BUG_ON(!trylock_page(new_page));
69699+#endif
69700+
69701 if (old_page) {
69702 if (!PageAnon(old_page)) {
69703 dec_mm_counter_fast(mm, MM_FILEPAGES);
69704@@ -2734,6 +2933,10 @@ gotten:
69705 page_remove_rmap(old_page);
69706 }
69707
69708+#ifdef CONFIG_PAX_SEGMEXEC
69709+ pax_mirror_anon_pte(vma, address, new_page, ptl);
69710+#endif
69711+
69712 /* Free the old page.. */
69713 new_page = old_page;
69714 ret |= VM_FAULT_WRITE;
69715@@ -3013,6 +3216,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
69716 swap_free(entry);
69717 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
69718 try_to_free_swap(page);
69719+
69720+#ifdef CONFIG_PAX_SEGMEXEC
69721+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
69722+#endif
69723+
69724 unlock_page(page);
69725 if (swapcache) {
69726 /*
69727@@ -3036,6 +3244,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
69728
69729 /* No need to invalidate - it was non-present before */
69730 update_mmu_cache(vma, address, page_table);
69731+
69732+#ifdef CONFIG_PAX_SEGMEXEC
69733+ pax_mirror_anon_pte(vma, address, page, ptl);
69734+#endif
69735+
69736 unlock:
69737 pte_unmap_unlock(page_table, ptl);
69738 out:
69739@@ -3055,40 +3268,6 @@ out_release:
69740 }
69741
69742 /*
69743- * This is like a special single-page "expand_{down|up}wards()",
69744- * except we must first make sure that 'address{-|+}PAGE_SIZE'
69745- * doesn't hit another vma.
69746- */
69747-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
69748-{
69749- address &= PAGE_MASK;
69750- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
69751- struct vm_area_struct *prev = vma->vm_prev;
69752-
69753- /*
69754- * Is there a mapping abutting this one below?
69755- *
69756- * That's only ok if it's the same stack mapping
69757- * that has gotten split..
69758- */
69759- if (prev && prev->vm_end == address)
69760- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
69761-
69762- expand_downwards(vma, address - PAGE_SIZE);
69763- }
69764- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
69765- struct vm_area_struct *next = vma->vm_next;
69766-
69767- /* As VM_GROWSDOWN but s/below/above/ */
69768- if (next && next->vm_start == address + PAGE_SIZE)
69769- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
69770-
69771- expand_upwards(vma, address + PAGE_SIZE);
69772- }
69773- return 0;
69774-}
69775-
69776-/*
69777 * We enter with non-exclusive mmap_sem (to exclude vma changes,
69778 * but allow concurrent faults), and pte mapped but not yet locked.
69779 * We return with mmap_sem still held, but pte unmapped and unlocked.
69780@@ -3097,27 +3276,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
69781 unsigned long address, pte_t *page_table, pmd_t *pmd,
69782 unsigned int flags)
69783 {
69784- struct page *page;
69785+ struct page *page = NULL;
69786 spinlock_t *ptl;
69787 pte_t entry;
69788
69789- pte_unmap(page_table);
69790-
69791- /* Check if we need to add a guard page to the stack */
69792- if (check_stack_guard_page(vma, address) < 0)
69793- return VM_FAULT_SIGBUS;
69794-
69795- /* Use the zero-page for reads */
69796 if (!(flags & FAULT_FLAG_WRITE)) {
69797 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
69798 vma->vm_page_prot));
69799- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
69800+ ptl = pte_lockptr(mm, pmd);
69801+ spin_lock(ptl);
69802 if (!pte_none(*page_table))
69803 goto unlock;
69804 goto setpte;
69805 }
69806
69807 /* Allocate our own private page. */
69808+ pte_unmap(page_table);
69809+
69810 if (unlikely(anon_vma_prepare(vma)))
69811 goto oom;
69812 page = alloc_zeroed_user_highpage_movable(vma, address);
69813@@ -3136,6 +3311,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
69814 if (!pte_none(*page_table))
69815 goto release;
69816
69817+#ifdef CONFIG_PAX_SEGMEXEC
69818+ if (pax_find_mirror_vma(vma))
69819+ BUG_ON(!trylock_page(page));
69820+#endif
69821+
69822 inc_mm_counter_fast(mm, MM_ANONPAGES);
69823 page_add_new_anon_rmap(page, vma, address);
69824 setpte:
69825@@ -3143,6 +3323,12 @@ setpte:
69826
69827 /* No need to invalidate - it was non-present before */
69828 update_mmu_cache(vma, address, page_table);
69829+
69830+#ifdef CONFIG_PAX_SEGMEXEC
69831+ if (page)
69832+ pax_mirror_anon_pte(vma, address, page, ptl);
69833+#endif
69834+
69835 unlock:
69836 pte_unmap_unlock(page_table, ptl);
69837 return 0;
69838@@ -3286,6 +3472,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69839 */
69840 /* Only go through if we didn't race with anybody else... */
69841 if (likely(pte_same(*page_table, orig_pte))) {
69842+
69843+#ifdef CONFIG_PAX_SEGMEXEC
69844+ if (anon && pax_find_mirror_vma(vma))
69845+ BUG_ON(!trylock_page(page));
69846+#endif
69847+
69848 flush_icache_page(vma, page);
69849 entry = mk_pte(page, vma->vm_page_prot);
69850 if (flags & FAULT_FLAG_WRITE)
69851@@ -3305,6 +3497,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69852
69853 /* no need to invalidate: a not-present page won't be cached */
69854 update_mmu_cache(vma, address, page_table);
69855+
69856+#ifdef CONFIG_PAX_SEGMEXEC
69857+ if (anon)
69858+ pax_mirror_anon_pte(vma, address, page, ptl);
69859+ else
69860+ pax_mirror_file_pte(vma, address, page, ptl);
69861+#endif
69862+
69863 } else {
69864 if (cow_page)
69865 mem_cgroup_uncharge_page(cow_page);
69866@@ -3458,6 +3658,12 @@ int handle_pte_fault(struct mm_struct *mm,
69867 if (flags & FAULT_FLAG_WRITE)
69868 flush_tlb_fix_spurious_fault(vma, address);
69869 }
69870+
69871+#ifdef CONFIG_PAX_SEGMEXEC
69872+ pax_mirror_pte(vma, address, pte, pmd, ptl);
69873+ return 0;
69874+#endif
69875+
69876 unlock:
69877 pte_unmap_unlock(pte, ptl);
69878 return 0;
69879@@ -3474,6 +3680,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69880 pmd_t *pmd;
69881 pte_t *pte;
69882
69883+#ifdef CONFIG_PAX_SEGMEXEC
69884+ struct vm_area_struct *vma_m;
69885+#endif
69886+
69887 __set_current_state(TASK_RUNNING);
69888
69889 count_vm_event(PGFAULT);
69890@@ -3485,6 +3695,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69891 if (unlikely(is_vm_hugetlb_page(vma)))
69892 return hugetlb_fault(mm, vma, address, flags);
69893
69894+#ifdef CONFIG_PAX_SEGMEXEC
69895+ vma_m = pax_find_mirror_vma(vma);
69896+ if (vma_m) {
69897+ unsigned long address_m;
69898+ pgd_t *pgd_m;
69899+ pud_t *pud_m;
69900+ pmd_t *pmd_m;
69901+
69902+ if (vma->vm_start > vma_m->vm_start) {
69903+ address_m = address;
69904+ address -= SEGMEXEC_TASK_SIZE;
69905+ vma = vma_m;
69906+ } else
69907+ address_m = address + SEGMEXEC_TASK_SIZE;
69908+
69909+ pgd_m = pgd_offset(mm, address_m);
69910+ pud_m = pud_alloc(mm, pgd_m, address_m);
69911+ if (!pud_m)
69912+ return VM_FAULT_OOM;
69913+ pmd_m = pmd_alloc(mm, pud_m, address_m);
69914+ if (!pmd_m)
69915+ return VM_FAULT_OOM;
69916+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
69917+ return VM_FAULT_OOM;
69918+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
69919+ }
69920+#endif
69921+
69922 pgd = pgd_offset(mm, address);
69923 pud = pud_alloc(mm, pgd, address);
69924 if (!pud)
69925@@ -3514,7 +3752,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69926 * run pte_offset_map on the pmd, if an huge pmd could
69927 * materialize from under us from a different thread.
69928 */
69929- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
69930+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
69931 return VM_FAULT_OOM;
69932 /* if an huge pmd materialized from under us just retry later */
69933 if (unlikely(pmd_trans_huge(*pmd)))
69934@@ -3618,7 +3856,7 @@ static int __init gate_vma_init(void)
69935 gate_vma.vm_start = FIXADDR_USER_START;
69936 gate_vma.vm_end = FIXADDR_USER_END;
69937 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
69938- gate_vma.vm_page_prot = __P101;
69939+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
69940 /*
69941 * Make sure the vDSO gets into every core dump.
69942 * Dumping its contents makes post-mortem fully interpretable later
69943diff --git a/mm/mempolicy.c b/mm/mempolicy.c
69944index 0a37570..2048346 100644
69945--- a/mm/mempolicy.c
69946+++ b/mm/mempolicy.c
69947@@ -640,6 +640,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
69948 unsigned long vmstart;
69949 unsigned long vmend;
69950
69951+#ifdef CONFIG_PAX_SEGMEXEC
69952+ struct vm_area_struct *vma_m;
69953+#endif
69954+
69955 vma = find_vma(mm, start);
69956 if (!vma || vma->vm_start > start)
69957 return -EFAULT;
69958@@ -679,6 +683,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
69959 err = policy_vma(vma, new_pol);
69960 if (err)
69961 goto out;
69962+
69963+#ifdef CONFIG_PAX_SEGMEXEC
69964+ vma_m = pax_find_mirror_vma(vma);
69965+ if (vma_m) {
69966+ err = policy_vma(vma_m, new_pol);
69967+ if (err)
69968+ goto out;
69969+ }
69970+#endif
69971+
69972 }
69973
69974 out:
69975@@ -1112,6 +1126,17 @@ static long do_mbind(unsigned long start, unsigned long len,
69976
69977 if (end < start)
69978 return -EINVAL;
69979+
69980+#ifdef CONFIG_PAX_SEGMEXEC
69981+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
69982+ if (end > SEGMEXEC_TASK_SIZE)
69983+ return -EINVAL;
69984+ } else
69985+#endif
69986+
69987+ if (end > TASK_SIZE)
69988+ return -EINVAL;
69989+
69990 if (end == start)
69991 return 0;
69992
69993@@ -1330,6 +1355,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
69994 if (!mm)
69995 goto out;
69996
69997+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
69998+ if (mm != current->mm &&
69999+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
70000+ err = -EPERM;
70001+ goto out;
70002+ }
70003+#endif
70004+
70005 /*
70006 * Check if this process has the right to modify the specified
70007 * process. The right exists if the process has administrative
70008@@ -1339,8 +1372,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
70009 rcu_read_lock();
70010 tcred = __task_cred(task);
70011 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
70012- cred->uid != tcred->suid && cred->uid != tcred->uid &&
70013- !capable(CAP_SYS_NICE)) {
70014+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
70015 rcu_read_unlock();
70016 err = -EPERM;
70017 goto out;
70018diff --git a/mm/migrate.c b/mm/migrate.c
70019index 1503b6b..156c672 100644
70020--- a/mm/migrate.c
70021+++ b/mm/migrate.c
70022@@ -1370,6 +1370,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
70023 if (!mm)
70024 return -EINVAL;
70025
70026+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70027+ if (mm != current->mm &&
70028+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
70029+ err = -EPERM;
70030+ goto out;
70031+ }
70032+#endif
70033+
70034 /*
70035 * Check if this process has the right to modify the specified
70036 * process. The right exists if the process has administrative
70037@@ -1379,8 +1387,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
70038 rcu_read_lock();
70039 tcred = __task_cred(task);
70040 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
70041- cred->uid != tcred->suid && cred->uid != tcred->uid &&
70042- !capable(CAP_SYS_NICE)) {
70043+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
70044 rcu_read_unlock();
70045 err = -EPERM;
70046 goto out;
70047diff --git a/mm/mlock.c b/mm/mlock.c
70048index ef726e8..13e0901 100644
70049--- a/mm/mlock.c
70050+++ b/mm/mlock.c
70051@@ -13,6 +13,7 @@
70052 #include <linux/pagemap.h>
70053 #include <linux/mempolicy.h>
70054 #include <linux/syscalls.h>
70055+#include <linux/security.h>
70056 #include <linux/sched.h>
70057 #include <linux/export.h>
70058 #include <linux/rmap.h>
70059@@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
70060 return -EINVAL;
70061 if (end == start)
70062 return 0;
70063+ if (end > TASK_SIZE)
70064+ return -EINVAL;
70065+
70066 vma = find_vma(current->mm, start);
70067 if (!vma || vma->vm_start > start)
70068 return -ENOMEM;
70069@@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
70070 for (nstart = start ; ; ) {
70071 vm_flags_t newflags;
70072
70073+#ifdef CONFIG_PAX_SEGMEXEC
70074+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
70075+ break;
70076+#endif
70077+
70078 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
70079
70080 newflags = vma->vm_flags | VM_LOCKED;
70081@@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
70082 lock_limit >>= PAGE_SHIFT;
70083
70084 /* check against resource limits */
70085+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
70086 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
70087 error = do_mlock(start, len, 1);
70088 up_write(&current->mm->mmap_sem);
70089@@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
70090 static int do_mlockall(int flags)
70091 {
70092 struct vm_area_struct * vma, * prev = NULL;
70093- unsigned int def_flags = 0;
70094
70095 if (flags & MCL_FUTURE)
70096- def_flags = VM_LOCKED;
70097- current->mm->def_flags = def_flags;
70098+ current->mm->def_flags |= VM_LOCKED;
70099+ else
70100+ current->mm->def_flags &= ~VM_LOCKED;
70101 if (flags == MCL_FUTURE)
70102 goto out;
70103
70104 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
70105 vm_flags_t newflags;
70106
70107+#ifdef CONFIG_PAX_SEGMEXEC
70108+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
70109+ break;
70110+#endif
70111+
70112+ BUG_ON(vma->vm_end > TASK_SIZE);
70113 newflags = vma->vm_flags | VM_LOCKED;
70114 if (!(flags & MCL_CURRENT))
70115 newflags &= ~VM_LOCKED;
70116@@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
70117 lock_limit >>= PAGE_SHIFT;
70118
70119 ret = -ENOMEM;
70120+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
70121 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
70122 capable(CAP_IPC_LOCK))
70123 ret = do_mlockall(flags);
70124diff --git a/mm/mmap.c b/mm/mmap.c
70125index da15a79..333850b 100644
70126--- a/mm/mmap.c
70127+++ b/mm/mmap.c
70128@@ -46,6 +46,16 @@
70129 #define arch_rebalance_pgtables(addr, len) (addr)
70130 #endif
70131
70132+static inline void verify_mm_writelocked(struct mm_struct *mm)
70133+{
70134+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
70135+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
70136+ up_read(&mm->mmap_sem);
70137+ BUG();
70138+ }
70139+#endif
70140+}
70141+
70142 static void unmap_region(struct mm_struct *mm,
70143 struct vm_area_struct *vma, struct vm_area_struct *prev,
70144 unsigned long start, unsigned long end);
70145@@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
70146 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
70147 *
70148 */
70149-pgprot_t protection_map[16] = {
70150+pgprot_t protection_map[16] __read_only = {
70151 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
70152 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
70153 };
70154
70155-pgprot_t vm_get_page_prot(unsigned long vm_flags)
70156+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
70157 {
70158- return __pgprot(pgprot_val(protection_map[vm_flags &
70159+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
70160 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
70161 pgprot_val(arch_vm_get_page_prot(vm_flags)));
70162+
70163+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70164+ if (!(__supported_pte_mask & _PAGE_NX) &&
70165+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
70166+ (vm_flags & (VM_READ | VM_WRITE)))
70167+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
70168+#endif
70169+
70170+ return prot;
70171 }
70172 EXPORT_SYMBOL(vm_get_page_prot);
70173
70174 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
70175 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
70176 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
70177+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
70178 /*
70179 * Make sure vm_committed_as in one cacheline and not cacheline shared with
70180 * other variables. It can be updated by several CPUs frequently.
70181@@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
70182 struct vm_area_struct *next = vma->vm_next;
70183
70184 might_sleep();
70185+ BUG_ON(vma->vm_mirror);
70186 if (vma->vm_ops && vma->vm_ops->close)
70187 vma->vm_ops->close(vma);
70188 if (vma->vm_file) {
70189@@ -272,6 +293,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
70190 * not page aligned -Ram Gupta
70191 */
70192 rlim = rlimit(RLIMIT_DATA);
70193+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
70194 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
70195 (mm->end_data - mm->start_data) > rlim)
70196 goto out;
70197@@ -689,6 +711,12 @@ static int
70198 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
70199 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
70200 {
70201+
70202+#ifdef CONFIG_PAX_SEGMEXEC
70203+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
70204+ return 0;
70205+#endif
70206+
70207 if (is_mergeable_vma(vma, file, vm_flags) &&
70208 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
70209 if (vma->vm_pgoff == vm_pgoff)
70210@@ -708,6 +736,12 @@ static int
70211 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
70212 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
70213 {
70214+
70215+#ifdef CONFIG_PAX_SEGMEXEC
70216+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
70217+ return 0;
70218+#endif
70219+
70220 if (is_mergeable_vma(vma, file, vm_flags) &&
70221 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
70222 pgoff_t vm_pglen;
70223@@ -750,13 +784,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
70224 struct vm_area_struct *vma_merge(struct mm_struct *mm,
70225 struct vm_area_struct *prev, unsigned long addr,
70226 unsigned long end, unsigned long vm_flags,
70227- struct anon_vma *anon_vma, struct file *file,
70228+ struct anon_vma *anon_vma, struct file *file,
70229 pgoff_t pgoff, struct mempolicy *policy)
70230 {
70231 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
70232 struct vm_area_struct *area, *next;
70233 int err;
70234
70235+#ifdef CONFIG_PAX_SEGMEXEC
70236+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
70237+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
70238+
70239+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
70240+#endif
70241+
70242 /*
70243 * We later require that vma->vm_flags == vm_flags,
70244 * so this tests vma->vm_flags & VM_SPECIAL, too.
70245@@ -772,6 +813,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70246 if (next && next->vm_end == end) /* cases 6, 7, 8 */
70247 next = next->vm_next;
70248
70249+#ifdef CONFIG_PAX_SEGMEXEC
70250+ if (prev)
70251+ prev_m = pax_find_mirror_vma(prev);
70252+ if (area)
70253+ area_m = pax_find_mirror_vma(area);
70254+ if (next)
70255+ next_m = pax_find_mirror_vma(next);
70256+#endif
70257+
70258 /*
70259 * Can it merge with the predecessor?
70260 */
70261@@ -791,9 +841,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70262 /* cases 1, 6 */
70263 err = vma_adjust(prev, prev->vm_start,
70264 next->vm_end, prev->vm_pgoff, NULL);
70265- } else /* cases 2, 5, 7 */
70266+
70267+#ifdef CONFIG_PAX_SEGMEXEC
70268+ if (!err && prev_m)
70269+ err = vma_adjust(prev_m, prev_m->vm_start,
70270+ next_m->vm_end, prev_m->vm_pgoff, NULL);
70271+#endif
70272+
70273+ } else { /* cases 2, 5, 7 */
70274 err = vma_adjust(prev, prev->vm_start,
70275 end, prev->vm_pgoff, NULL);
70276+
70277+#ifdef CONFIG_PAX_SEGMEXEC
70278+ if (!err && prev_m)
70279+ err = vma_adjust(prev_m, prev_m->vm_start,
70280+ end_m, prev_m->vm_pgoff, NULL);
70281+#endif
70282+
70283+ }
70284 if (err)
70285 return NULL;
70286 khugepaged_enter_vma_merge(prev);
70287@@ -807,12 +872,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70288 mpol_equal(policy, vma_policy(next)) &&
70289 can_vma_merge_before(next, vm_flags,
70290 anon_vma, file, pgoff+pglen)) {
70291- if (prev && addr < prev->vm_end) /* case 4 */
70292+ if (prev && addr < prev->vm_end) { /* case 4 */
70293 err = vma_adjust(prev, prev->vm_start,
70294 addr, prev->vm_pgoff, NULL);
70295- else /* cases 3, 8 */
70296+
70297+#ifdef CONFIG_PAX_SEGMEXEC
70298+ if (!err && prev_m)
70299+ err = vma_adjust(prev_m, prev_m->vm_start,
70300+ addr_m, prev_m->vm_pgoff, NULL);
70301+#endif
70302+
70303+ } else { /* cases 3, 8 */
70304 err = vma_adjust(area, addr, next->vm_end,
70305 next->vm_pgoff - pglen, NULL);
70306+
70307+#ifdef CONFIG_PAX_SEGMEXEC
70308+ if (!err && area_m)
70309+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
70310+ next_m->vm_pgoff - pglen, NULL);
70311+#endif
70312+
70313+ }
70314 if (err)
70315 return NULL;
70316 khugepaged_enter_vma_merge(area);
70317@@ -921,14 +1001,11 @@ none:
70318 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
70319 struct file *file, long pages)
70320 {
70321- const unsigned long stack_flags
70322- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
70323-
70324 if (file) {
70325 mm->shared_vm += pages;
70326 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
70327 mm->exec_vm += pages;
70328- } else if (flags & stack_flags)
70329+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
70330 mm->stack_vm += pages;
70331 if (flags & (VM_RESERVED|VM_IO))
70332 mm->reserved_vm += pages;
70333@@ -955,7 +1032,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70334 * (the exception is when the underlying filesystem is noexec
70335 * mounted, in which case we dont add PROT_EXEC.)
70336 */
70337- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
70338+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
70339 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
70340 prot |= PROT_EXEC;
70341
70342@@ -981,7 +1058,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70343 /* Obtain the address to map to. we verify (or select) it and ensure
70344 * that it represents a valid section of the address space.
70345 */
70346- addr = get_unmapped_area(file, addr, len, pgoff, flags);
70347+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
70348 if (addr & ~PAGE_MASK)
70349 return addr;
70350
70351@@ -992,6 +1069,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70352 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
70353 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
70354
70355+#ifdef CONFIG_PAX_MPROTECT
70356+ if (mm->pax_flags & MF_PAX_MPROTECT) {
70357+#ifndef CONFIG_PAX_MPROTECT_COMPAT
70358+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
70359+ gr_log_rwxmmap(file);
70360+
70361+#ifdef CONFIG_PAX_EMUPLT
70362+ vm_flags &= ~VM_EXEC;
70363+#else
70364+ return -EPERM;
70365+#endif
70366+
70367+ }
70368+
70369+ if (!(vm_flags & VM_EXEC))
70370+ vm_flags &= ~VM_MAYEXEC;
70371+#else
70372+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
70373+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
70374+#endif
70375+ else
70376+ vm_flags &= ~VM_MAYWRITE;
70377+ }
70378+#endif
70379+
70380+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70381+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
70382+ vm_flags &= ~VM_PAGEEXEC;
70383+#endif
70384+
70385 if (flags & MAP_LOCKED)
70386 if (!can_do_mlock())
70387 return -EPERM;
70388@@ -1003,6 +1110,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70389 locked += mm->locked_vm;
70390 lock_limit = rlimit(RLIMIT_MEMLOCK);
70391 lock_limit >>= PAGE_SHIFT;
70392+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
70393 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
70394 return -EAGAIN;
70395 }
70396@@ -1073,6 +1181,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70397 if (error)
70398 return error;
70399
70400+ if (!gr_acl_handle_mmap(file, prot))
70401+ return -EACCES;
70402+
70403 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
70404 }
70405 EXPORT_SYMBOL(do_mmap_pgoff);
70406@@ -1153,7 +1264,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
70407 vm_flags_t vm_flags = vma->vm_flags;
70408
70409 /* If it was private or non-writable, the write bit is already clear */
70410- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
70411+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
70412 return 0;
70413
70414 /* The backer wishes to know when pages are first written to? */
70415@@ -1202,14 +1313,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
70416 unsigned long charged = 0;
70417 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
70418
70419+#ifdef CONFIG_PAX_SEGMEXEC
70420+ struct vm_area_struct *vma_m = NULL;
70421+#endif
70422+
70423+ /*
70424+ * mm->mmap_sem is required to protect against another thread
70425+ * changing the mappings in case we sleep.
70426+ */
70427+ verify_mm_writelocked(mm);
70428+
70429 /* Clear old maps */
70430 error = -ENOMEM;
70431-munmap_back:
70432 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
70433 if (vma && vma->vm_start < addr + len) {
70434 if (do_munmap(mm, addr, len))
70435 return -ENOMEM;
70436- goto munmap_back;
70437+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
70438+ BUG_ON(vma && vma->vm_start < addr + len);
70439 }
70440
70441 /* Check against address space limit. */
70442@@ -1258,6 +1379,16 @@ munmap_back:
70443 goto unacct_error;
70444 }
70445
70446+#ifdef CONFIG_PAX_SEGMEXEC
70447+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
70448+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
70449+ if (!vma_m) {
70450+ error = -ENOMEM;
70451+ goto free_vma;
70452+ }
70453+ }
70454+#endif
70455+
70456 vma->vm_mm = mm;
70457 vma->vm_start = addr;
70458 vma->vm_end = addr + len;
70459@@ -1282,6 +1413,19 @@ munmap_back:
70460 error = file->f_op->mmap(file, vma);
70461 if (error)
70462 goto unmap_and_free_vma;
70463+
70464+#ifdef CONFIG_PAX_SEGMEXEC
70465+ if (vma_m && (vm_flags & VM_EXECUTABLE))
70466+ added_exe_file_vma(mm);
70467+#endif
70468+
70469+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70470+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
70471+ vma->vm_flags |= VM_PAGEEXEC;
70472+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
70473+ }
70474+#endif
70475+
70476 if (vm_flags & VM_EXECUTABLE)
70477 added_exe_file_vma(mm);
70478
70479@@ -1319,6 +1463,11 @@ munmap_back:
70480 vma_link(mm, vma, prev, rb_link, rb_parent);
70481 file = vma->vm_file;
70482
70483+#ifdef CONFIG_PAX_SEGMEXEC
70484+ if (vma_m)
70485+ BUG_ON(pax_mirror_vma(vma_m, vma));
70486+#endif
70487+
70488 /* Once vma denies write, undo our temporary denial count */
70489 if (correct_wcount)
70490 atomic_inc(&inode->i_writecount);
70491@@ -1327,6 +1476,7 @@ out:
70492
70493 mm->total_vm += len >> PAGE_SHIFT;
70494 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
70495+ track_exec_limit(mm, addr, addr + len, vm_flags);
70496 if (vm_flags & VM_LOCKED) {
70497 if (!mlock_vma_pages_range(vma, addr, addr + len))
70498 mm->locked_vm += (len >> PAGE_SHIFT);
70499@@ -1344,6 +1494,12 @@ unmap_and_free_vma:
70500 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
70501 charged = 0;
70502 free_vma:
70503+
70504+#ifdef CONFIG_PAX_SEGMEXEC
70505+ if (vma_m)
70506+ kmem_cache_free(vm_area_cachep, vma_m);
70507+#endif
70508+
70509 kmem_cache_free(vm_area_cachep, vma);
70510 unacct_error:
70511 if (charged)
70512@@ -1351,6 +1507,44 @@ unacct_error:
70513 return error;
70514 }
70515
70516+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
70517+{
70518+ if (!vma) {
70519+#ifdef CONFIG_STACK_GROWSUP
70520+ if (addr > sysctl_heap_stack_gap)
70521+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
70522+ else
70523+ vma = find_vma(current->mm, 0);
70524+ if (vma && (vma->vm_flags & VM_GROWSUP))
70525+ return false;
70526+#endif
70527+ return true;
70528+ }
70529+
70530+ if (addr + len > vma->vm_start)
70531+ return false;
70532+
70533+ if (vma->vm_flags & VM_GROWSDOWN)
70534+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
70535+#ifdef CONFIG_STACK_GROWSUP
70536+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
70537+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
70538+#endif
70539+
70540+ return true;
70541+}
70542+
70543+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
70544+{
70545+ if (vma->vm_start < len)
70546+ return -ENOMEM;
70547+ if (!(vma->vm_flags & VM_GROWSDOWN))
70548+ return vma->vm_start - len;
70549+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
70550+ return vma->vm_start - len - sysctl_heap_stack_gap;
70551+ return -ENOMEM;
70552+}
70553+
70554 /* Get an address range which is currently unmapped.
70555 * For shmat() with addr=0.
70556 *
70557@@ -1377,18 +1571,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
70558 if (flags & MAP_FIXED)
70559 return addr;
70560
70561+#ifdef CONFIG_PAX_RANDMMAP
70562+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
70563+#endif
70564+
70565 if (addr) {
70566 addr = PAGE_ALIGN(addr);
70567- vma = find_vma(mm, addr);
70568- if (TASK_SIZE - len >= addr &&
70569- (!vma || addr + len <= vma->vm_start))
70570- return addr;
70571+ if (TASK_SIZE - len >= addr) {
70572+ vma = find_vma(mm, addr);
70573+ if (check_heap_stack_gap(vma, addr, len))
70574+ return addr;
70575+ }
70576 }
70577 if (len > mm->cached_hole_size) {
70578- start_addr = addr = mm->free_area_cache;
70579+ start_addr = addr = mm->free_area_cache;
70580 } else {
70581- start_addr = addr = TASK_UNMAPPED_BASE;
70582- mm->cached_hole_size = 0;
70583+ start_addr = addr = mm->mmap_base;
70584+ mm->cached_hole_size = 0;
70585 }
70586
70587 full_search:
70588@@ -1399,34 +1598,40 @@ full_search:
70589 * Start a new search - just in case we missed
70590 * some holes.
70591 */
70592- if (start_addr != TASK_UNMAPPED_BASE) {
70593- addr = TASK_UNMAPPED_BASE;
70594- start_addr = addr;
70595+ if (start_addr != mm->mmap_base) {
70596+ start_addr = addr = mm->mmap_base;
70597 mm->cached_hole_size = 0;
70598 goto full_search;
70599 }
70600 return -ENOMEM;
70601 }
70602- if (!vma || addr + len <= vma->vm_start) {
70603- /*
70604- * Remember the place where we stopped the search:
70605- */
70606- mm->free_area_cache = addr + len;
70607- return addr;
70608- }
70609+ if (check_heap_stack_gap(vma, addr, len))
70610+ break;
70611 if (addr + mm->cached_hole_size < vma->vm_start)
70612 mm->cached_hole_size = vma->vm_start - addr;
70613 addr = vma->vm_end;
70614 }
70615+
70616+ /*
70617+ * Remember the place where we stopped the search:
70618+ */
70619+ mm->free_area_cache = addr + len;
70620+ return addr;
70621 }
70622 #endif
70623
70624 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
70625 {
70626+
70627+#ifdef CONFIG_PAX_SEGMEXEC
70628+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
70629+ return;
70630+#endif
70631+
70632 /*
70633 * Is this a new hole at the lowest possible address?
70634 */
70635- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
70636+ if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
70637 mm->free_area_cache = addr;
70638 mm->cached_hole_size = ~0UL;
70639 }
70640@@ -1444,7 +1649,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
70641 {
70642 struct vm_area_struct *vma;
70643 struct mm_struct *mm = current->mm;
70644- unsigned long addr = addr0;
70645+ unsigned long base = mm->mmap_base, addr = addr0;
70646
70647 /* requested length too big for entire address space */
70648 if (len > TASK_SIZE)
70649@@ -1453,13 +1658,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
70650 if (flags & MAP_FIXED)
70651 return addr;
70652
70653+#ifdef CONFIG_PAX_RANDMMAP
70654+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
70655+#endif
70656+
70657 /* requesting a specific address */
70658 if (addr) {
70659 addr = PAGE_ALIGN(addr);
70660- vma = find_vma(mm, addr);
70661- if (TASK_SIZE - len >= addr &&
70662- (!vma || addr + len <= vma->vm_start))
70663- return addr;
70664+ if (TASK_SIZE - len >= addr) {
70665+ vma = find_vma(mm, addr);
70666+ if (check_heap_stack_gap(vma, addr, len))
70667+ return addr;
70668+ }
70669 }
70670
70671 /* check if free_area_cache is useful for us */
70672@@ -1474,7 +1684,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
70673 /* make sure it can fit in the remaining address space */
70674 if (addr > len) {
70675 vma = find_vma(mm, addr-len);
70676- if (!vma || addr <= vma->vm_start)
70677+ if (check_heap_stack_gap(vma, addr - len, len))
70678 /* remember the address as a hint for next time */
70679 return (mm->free_area_cache = addr-len);
70680 }
70681@@ -1491,7 +1701,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
70682 * return with success:
70683 */
70684 vma = find_vma(mm, addr);
70685- if (!vma || addr+len <= vma->vm_start)
70686+ if (check_heap_stack_gap(vma, addr, len))
70687 /* remember the address as a hint for next time */
70688 return (mm->free_area_cache = addr);
70689
70690@@ -1500,8 +1710,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
70691 mm->cached_hole_size = vma->vm_start - addr;
70692
70693 /* try just below the current vma->vm_start */
70694- addr = vma->vm_start-len;
70695- } while (len < vma->vm_start);
70696+ addr = skip_heap_stack_gap(vma, len);
70697+ } while (!IS_ERR_VALUE(addr));
70698
70699 bottomup:
70700 /*
70701@@ -1510,13 +1720,21 @@ bottomup:
70702 * can happen with large stack limits and large mmap()
70703 * allocations.
70704 */
70705+ mm->mmap_base = TASK_UNMAPPED_BASE;
70706+
70707+#ifdef CONFIG_PAX_RANDMMAP
70708+ if (mm->pax_flags & MF_PAX_RANDMMAP)
70709+ mm->mmap_base += mm->delta_mmap;
70710+#endif
70711+
70712+ mm->free_area_cache = mm->mmap_base;
70713 mm->cached_hole_size = ~0UL;
70714- mm->free_area_cache = TASK_UNMAPPED_BASE;
70715 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
70716 /*
70717 * Restore the topdown base:
70718 */
70719- mm->free_area_cache = mm->mmap_base;
70720+ mm->mmap_base = base;
70721+ mm->free_area_cache = base;
70722 mm->cached_hole_size = ~0UL;
70723
70724 return addr;
70725@@ -1525,6 +1743,12 @@ bottomup:
70726
70727 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
70728 {
70729+
70730+#ifdef CONFIG_PAX_SEGMEXEC
70731+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
70732+ return;
70733+#endif
70734+
70735 /*
70736 * Is this a new hole at the highest possible address?
70737 */
70738@@ -1532,8 +1756,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
70739 mm->free_area_cache = addr;
70740
70741 /* dont allow allocations above current base */
70742- if (mm->free_area_cache > mm->mmap_base)
70743+ if (mm->free_area_cache > mm->mmap_base) {
70744 mm->free_area_cache = mm->mmap_base;
70745+ mm->cached_hole_size = ~0UL;
70746+ }
70747 }
70748
70749 unsigned long
70750@@ -1629,6 +1855,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
70751 return vma;
70752 }
70753
70754+#ifdef CONFIG_PAX_SEGMEXEC
70755+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
70756+{
70757+ struct vm_area_struct *vma_m;
70758+
70759+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
70760+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
70761+ BUG_ON(vma->vm_mirror);
70762+ return NULL;
70763+ }
70764+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
70765+ vma_m = vma->vm_mirror;
70766+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
70767+ BUG_ON(vma->vm_file != vma_m->vm_file);
70768+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
70769+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
70770+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
70771+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
70772+ return vma_m;
70773+}
70774+#endif
70775+
70776 /*
70777 * Verify that the stack growth is acceptable and
70778 * update accounting. This is shared with both the
70779@@ -1645,6 +1893,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
70780 return -ENOMEM;
70781
70782 /* Stack limit test */
70783+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
70784 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
70785 return -ENOMEM;
70786
70787@@ -1655,6 +1904,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
70788 locked = mm->locked_vm + grow;
70789 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
70790 limit >>= PAGE_SHIFT;
70791+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
70792 if (locked > limit && !capable(CAP_IPC_LOCK))
70793 return -ENOMEM;
70794 }
70795@@ -1685,37 +1935,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
70796 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
70797 * vma is the last one with address > vma->vm_end. Have to extend vma.
70798 */
70799+#ifndef CONFIG_IA64
70800+static
70801+#endif
70802 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
70803 {
70804 int error;
70805+ bool locknext;
70806
70807 if (!(vma->vm_flags & VM_GROWSUP))
70808 return -EFAULT;
70809
70810+ /* Also guard against wrapping around to address 0. */
70811+ if (address < PAGE_ALIGN(address+1))
70812+ address = PAGE_ALIGN(address+1);
70813+ else
70814+ return -ENOMEM;
70815+
70816 /*
70817 * We must make sure the anon_vma is allocated
70818 * so that the anon_vma locking is not a noop.
70819 */
70820 if (unlikely(anon_vma_prepare(vma)))
70821 return -ENOMEM;
70822+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
70823+ if (locknext && anon_vma_prepare(vma->vm_next))
70824+ return -ENOMEM;
70825 vma_lock_anon_vma(vma);
70826+ if (locknext)
70827+ vma_lock_anon_vma(vma->vm_next);
70828
70829 /*
70830 * vma->vm_start/vm_end cannot change under us because the caller
70831 * is required to hold the mmap_sem in read mode. We need the
70832- * anon_vma lock to serialize against concurrent expand_stacks.
70833- * Also guard against wrapping around to address 0.
70834+ * anon_vma locks to serialize against concurrent expand_stacks
70835+ * and expand_upwards.
70836 */
70837- if (address < PAGE_ALIGN(address+4))
70838- address = PAGE_ALIGN(address+4);
70839- else {
70840- vma_unlock_anon_vma(vma);
70841- return -ENOMEM;
70842- }
70843 error = 0;
70844
70845 /* Somebody else might have raced and expanded it already */
70846- if (address > vma->vm_end) {
70847+ 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)
70848+ error = -ENOMEM;
70849+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
70850 unsigned long size, grow;
70851
70852 size = address - vma->vm_start;
70853@@ -1730,6 +1991,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
70854 }
70855 }
70856 }
70857+ if (locknext)
70858+ vma_unlock_anon_vma(vma->vm_next);
70859 vma_unlock_anon_vma(vma);
70860 khugepaged_enter_vma_merge(vma);
70861 return error;
70862@@ -1743,6 +2006,8 @@ int expand_downwards(struct vm_area_struct *vma,
70863 unsigned long address)
70864 {
70865 int error;
70866+ bool lockprev = false;
70867+ struct vm_area_struct *prev;
70868
70869 /*
70870 * We must make sure the anon_vma is allocated
70871@@ -1756,6 +2021,15 @@ int expand_downwards(struct vm_area_struct *vma,
70872 if (error)
70873 return error;
70874
70875+ prev = vma->vm_prev;
70876+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
70877+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
70878+#endif
70879+ if (lockprev && anon_vma_prepare(prev))
70880+ return -ENOMEM;
70881+ if (lockprev)
70882+ vma_lock_anon_vma(prev);
70883+
70884 vma_lock_anon_vma(vma);
70885
70886 /*
70887@@ -1765,9 +2039,17 @@ int expand_downwards(struct vm_area_struct *vma,
70888 */
70889
70890 /* Somebody else might have raced and expanded it already */
70891- if (address < vma->vm_start) {
70892+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
70893+ error = -ENOMEM;
70894+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
70895 unsigned long size, grow;
70896
70897+#ifdef CONFIG_PAX_SEGMEXEC
70898+ struct vm_area_struct *vma_m;
70899+
70900+ vma_m = pax_find_mirror_vma(vma);
70901+#endif
70902+
70903 size = vma->vm_end - address;
70904 grow = (vma->vm_start - address) >> PAGE_SHIFT;
70905
70906@@ -1777,11 +2059,22 @@ int expand_downwards(struct vm_area_struct *vma,
70907 if (!error) {
70908 vma->vm_start = address;
70909 vma->vm_pgoff -= grow;
70910+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
70911+
70912+#ifdef CONFIG_PAX_SEGMEXEC
70913+ if (vma_m) {
70914+ vma_m->vm_start -= grow << PAGE_SHIFT;
70915+ vma_m->vm_pgoff -= grow;
70916+ }
70917+#endif
70918+
70919 perf_event_mmap(vma);
70920 }
70921 }
70922 }
70923 vma_unlock_anon_vma(vma);
70924+ if (lockprev)
70925+ vma_unlock_anon_vma(prev);
70926 khugepaged_enter_vma_merge(vma);
70927 return error;
70928 }
70929@@ -1851,6 +2144,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
70930 do {
70931 long nrpages = vma_pages(vma);
70932
70933+#ifdef CONFIG_PAX_SEGMEXEC
70934+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
70935+ vma = remove_vma(vma);
70936+ continue;
70937+ }
70938+#endif
70939+
70940 mm->total_vm -= nrpages;
70941 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
70942 vma = remove_vma(vma);
70943@@ -1896,6 +2196,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
70944 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
70945 vma->vm_prev = NULL;
70946 do {
70947+
70948+#ifdef CONFIG_PAX_SEGMEXEC
70949+ if (vma->vm_mirror) {
70950+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
70951+ vma->vm_mirror->vm_mirror = NULL;
70952+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
70953+ vma->vm_mirror = NULL;
70954+ }
70955+#endif
70956+
70957 rb_erase(&vma->vm_rb, &mm->mm_rb);
70958 mm->map_count--;
70959 tail_vma = vma;
70960@@ -1924,14 +2234,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
70961 struct vm_area_struct *new;
70962 int err = -ENOMEM;
70963
70964+#ifdef CONFIG_PAX_SEGMEXEC
70965+ struct vm_area_struct *vma_m, *new_m = NULL;
70966+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
70967+#endif
70968+
70969 if (is_vm_hugetlb_page(vma) && (addr &
70970 ~(huge_page_mask(hstate_vma(vma)))))
70971 return -EINVAL;
70972
70973+#ifdef CONFIG_PAX_SEGMEXEC
70974+ vma_m = pax_find_mirror_vma(vma);
70975+#endif
70976+
70977 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
70978 if (!new)
70979 goto out_err;
70980
70981+#ifdef CONFIG_PAX_SEGMEXEC
70982+ if (vma_m) {
70983+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
70984+ if (!new_m) {
70985+ kmem_cache_free(vm_area_cachep, new);
70986+ goto out_err;
70987+ }
70988+ }
70989+#endif
70990+
70991 /* most fields are the same, copy all, and then fixup */
70992 *new = *vma;
70993
70994@@ -1944,6 +2273,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
70995 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
70996 }
70997
70998+#ifdef CONFIG_PAX_SEGMEXEC
70999+ if (vma_m) {
71000+ *new_m = *vma_m;
71001+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
71002+ new_m->vm_mirror = new;
71003+ new->vm_mirror = new_m;
71004+
71005+ if (new_below)
71006+ new_m->vm_end = addr_m;
71007+ else {
71008+ new_m->vm_start = addr_m;
71009+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
71010+ }
71011+ }
71012+#endif
71013+
71014 pol = mpol_dup(vma_policy(vma));
71015 if (IS_ERR(pol)) {
71016 err = PTR_ERR(pol);
71017@@ -1969,6 +2314,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71018 else
71019 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
71020
71021+#ifdef CONFIG_PAX_SEGMEXEC
71022+ if (!err && vma_m) {
71023+ if (anon_vma_clone(new_m, vma_m))
71024+ goto out_free_mpol;
71025+
71026+ mpol_get(pol);
71027+ vma_set_policy(new_m, pol);
71028+
71029+ if (new_m->vm_file) {
71030+ get_file(new_m->vm_file);
71031+ if (vma_m->vm_flags & VM_EXECUTABLE)
71032+ added_exe_file_vma(mm);
71033+ }
71034+
71035+ if (new_m->vm_ops && new_m->vm_ops->open)
71036+ new_m->vm_ops->open(new_m);
71037+
71038+ if (new_below)
71039+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
71040+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
71041+ else
71042+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
71043+
71044+ if (err) {
71045+ if (new_m->vm_ops && new_m->vm_ops->close)
71046+ new_m->vm_ops->close(new_m);
71047+ if (new_m->vm_file) {
71048+ if (vma_m->vm_flags & VM_EXECUTABLE)
71049+ removed_exe_file_vma(mm);
71050+ fput(new_m->vm_file);
71051+ }
71052+ mpol_put(pol);
71053+ }
71054+ }
71055+#endif
71056+
71057 /* Success. */
71058 if (!err)
71059 return 0;
71060@@ -1981,10 +2362,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71061 removed_exe_file_vma(mm);
71062 fput(new->vm_file);
71063 }
71064- unlink_anon_vmas(new);
71065 out_free_mpol:
71066 mpol_put(pol);
71067 out_free_vma:
71068+
71069+#ifdef CONFIG_PAX_SEGMEXEC
71070+ if (new_m) {
71071+ unlink_anon_vmas(new_m);
71072+ kmem_cache_free(vm_area_cachep, new_m);
71073+ }
71074+#endif
71075+
71076+ unlink_anon_vmas(new);
71077 kmem_cache_free(vm_area_cachep, new);
71078 out_err:
71079 return err;
71080@@ -1997,6 +2386,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71081 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
71082 unsigned long addr, int new_below)
71083 {
71084+
71085+#ifdef CONFIG_PAX_SEGMEXEC
71086+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71087+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
71088+ if (mm->map_count >= sysctl_max_map_count-1)
71089+ return -ENOMEM;
71090+ } else
71091+#endif
71092+
71093 if (mm->map_count >= sysctl_max_map_count)
71094 return -ENOMEM;
71095
71096@@ -2008,11 +2406,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
71097 * work. This now handles partial unmappings.
71098 * Jeremy Fitzhardinge <jeremy@goop.org>
71099 */
71100+#ifdef CONFIG_PAX_SEGMEXEC
71101 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71102 {
71103+ int ret = __do_munmap(mm, start, len);
71104+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
71105+ return ret;
71106+
71107+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
71108+}
71109+
71110+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71111+#else
71112+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71113+#endif
71114+{
71115 unsigned long end;
71116 struct vm_area_struct *vma, *prev, *last;
71117
71118+ /*
71119+ * mm->mmap_sem is required to protect against another thread
71120+ * changing the mappings in case we sleep.
71121+ */
71122+ verify_mm_writelocked(mm);
71123+
71124 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
71125 return -EINVAL;
71126
71127@@ -2087,6 +2504,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71128 /* Fix up all other VM information */
71129 remove_vma_list(mm, vma);
71130
71131+ track_exec_limit(mm, start, end, 0UL);
71132+
71133 return 0;
71134 }
71135
71136@@ -2099,22 +2518,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
71137
71138 profile_munmap(addr);
71139
71140+#ifdef CONFIG_PAX_SEGMEXEC
71141+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
71142+ (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
71143+ return -EINVAL;
71144+#endif
71145+
71146 down_write(&mm->mmap_sem);
71147 ret = do_munmap(mm, addr, len);
71148 up_write(&mm->mmap_sem);
71149 return ret;
71150 }
71151
71152-static inline void verify_mm_writelocked(struct mm_struct *mm)
71153-{
71154-#ifdef CONFIG_DEBUG_VM
71155- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71156- WARN_ON(1);
71157- up_read(&mm->mmap_sem);
71158- }
71159-#endif
71160-}
71161-
71162 /*
71163 * this is really a simplified "do_mmap". it only handles
71164 * anonymous maps. eventually we may be able to do some
71165@@ -2128,6 +2543,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
71166 struct rb_node ** rb_link, * rb_parent;
71167 pgoff_t pgoff = addr >> PAGE_SHIFT;
71168 int error;
71169+ unsigned long charged;
71170
71171 len = PAGE_ALIGN(len);
71172 if (!len)
71173@@ -2139,16 +2555,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
71174
71175 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
71176
71177+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
71178+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
71179+ flags &= ~VM_EXEC;
71180+
71181+#ifdef CONFIG_PAX_MPROTECT
71182+ if (mm->pax_flags & MF_PAX_MPROTECT)
71183+ flags &= ~VM_MAYEXEC;
71184+#endif
71185+
71186+ }
71187+#endif
71188+
71189 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
71190 if (error & ~PAGE_MASK)
71191 return error;
71192
71193+ charged = len >> PAGE_SHIFT;
71194+
71195 /*
71196 * mlock MCL_FUTURE?
71197 */
71198 if (mm->def_flags & VM_LOCKED) {
71199 unsigned long locked, lock_limit;
71200- locked = len >> PAGE_SHIFT;
71201+ locked = charged;
71202 locked += mm->locked_vm;
71203 lock_limit = rlimit(RLIMIT_MEMLOCK);
71204 lock_limit >>= PAGE_SHIFT;
71205@@ -2165,22 +2595,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
71206 /*
71207 * Clear old maps. this also does some error checking for us
71208 */
71209- munmap_back:
71210 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71211 if (vma && vma->vm_start < addr + len) {
71212 if (do_munmap(mm, addr, len))
71213 return -ENOMEM;
71214- goto munmap_back;
71215+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71216+ BUG_ON(vma && vma->vm_start < addr + len);
71217 }
71218
71219 /* Check against address space limits *after* clearing old maps... */
71220- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
71221+ if (!may_expand_vm(mm, charged))
71222 return -ENOMEM;
71223
71224 if (mm->map_count > sysctl_max_map_count)
71225 return -ENOMEM;
71226
71227- if (security_vm_enough_memory(len >> PAGE_SHIFT))
71228+ if (security_vm_enough_memory(charged))
71229 return -ENOMEM;
71230
71231 /* Can we just expand an old private anonymous mapping? */
71232@@ -2194,7 +2624,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
71233 */
71234 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71235 if (!vma) {
71236- vm_unacct_memory(len >> PAGE_SHIFT);
71237+ vm_unacct_memory(charged);
71238 return -ENOMEM;
71239 }
71240
71241@@ -2208,11 +2638,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
71242 vma_link(mm, vma, prev, rb_link, rb_parent);
71243 out:
71244 perf_event_mmap(vma);
71245- mm->total_vm += len >> PAGE_SHIFT;
71246+ mm->total_vm += charged;
71247 if (flags & VM_LOCKED) {
71248 if (!mlock_vma_pages_range(vma, addr, addr + len))
71249- mm->locked_vm += (len >> PAGE_SHIFT);
71250+ mm->locked_vm += charged;
71251 }
71252+ track_exec_limit(mm, addr, addr + len, flags);
71253 return addr;
71254 }
71255
71256@@ -2259,8 +2690,10 @@ void exit_mmap(struct mm_struct *mm)
71257 * Walk the list again, actually closing and freeing it,
71258 * with preemption enabled, without holding any MM locks.
71259 */
71260- while (vma)
71261+ while (vma) {
71262+ vma->vm_mirror = NULL;
71263 vma = remove_vma(vma);
71264+ }
71265
71266 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
71267 }
71268@@ -2274,6 +2707,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
71269 struct vm_area_struct * __vma, * prev;
71270 struct rb_node ** rb_link, * rb_parent;
71271
71272+#ifdef CONFIG_PAX_SEGMEXEC
71273+ struct vm_area_struct *vma_m = NULL;
71274+#endif
71275+
71276+ if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
71277+ return -EPERM;
71278+
71279 /*
71280 * The vm_pgoff of a purely anonymous vma should be irrelevant
71281 * until its first write fault, when page's anon_vma and index
71282@@ -2296,7 +2736,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
71283 if ((vma->vm_flags & VM_ACCOUNT) &&
71284 security_vm_enough_memory_mm(mm, vma_pages(vma)))
71285 return -ENOMEM;
71286+
71287+#ifdef CONFIG_PAX_SEGMEXEC
71288+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
71289+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71290+ if (!vma_m)
71291+ return -ENOMEM;
71292+ }
71293+#endif
71294+
71295 vma_link(mm, vma, prev, rb_link, rb_parent);
71296+
71297+#ifdef CONFIG_PAX_SEGMEXEC
71298+ if (vma_m)
71299+ BUG_ON(pax_mirror_vma(vma_m, vma));
71300+#endif
71301+
71302 return 0;
71303 }
71304
71305@@ -2315,6 +2770,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
71306 struct mempolicy *pol;
71307 bool faulted_in_anon_vma = true;
71308
71309+ BUG_ON(vma->vm_mirror);
71310+
71311 /*
71312 * If anonymous vma has not yet been faulted, update new pgoff
71313 * to match new location, to increase its chance of merging.
71314@@ -2382,6 +2839,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
71315 return NULL;
71316 }
71317
71318+#ifdef CONFIG_PAX_SEGMEXEC
71319+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
71320+{
71321+ struct vm_area_struct *prev_m;
71322+ struct rb_node **rb_link_m, *rb_parent_m;
71323+ struct mempolicy *pol_m;
71324+
71325+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
71326+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
71327+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
71328+ *vma_m = *vma;
71329+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
71330+ if (anon_vma_clone(vma_m, vma))
71331+ return -ENOMEM;
71332+ pol_m = vma_policy(vma_m);
71333+ mpol_get(pol_m);
71334+ vma_set_policy(vma_m, pol_m);
71335+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
71336+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
71337+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
71338+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
71339+ if (vma_m->vm_file)
71340+ get_file(vma_m->vm_file);
71341+ if (vma_m->vm_ops && vma_m->vm_ops->open)
71342+ vma_m->vm_ops->open(vma_m);
71343+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
71344+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
71345+ vma_m->vm_mirror = vma;
71346+ vma->vm_mirror = vma_m;
71347+ return 0;
71348+}
71349+#endif
71350+
71351 /*
71352 * Return true if the calling process may expand its vm space by the passed
71353 * number of pages
71354@@ -2391,8 +2881,13 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
71355 unsigned long cur = mm->total_vm; /* pages */
71356 unsigned long lim;
71357
71358+#ifdef CONFIG_PAX_RANDMMAP
71359+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && mm->end_data)
71360+ cur -= (mm->start_brk - mm->end_data) >> PAGE_SHIFT;
71361+#endif
71362+
71363 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
71364-
71365+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
71366 if (cur + npages > lim)
71367 return 0;
71368 return 1;
71369@@ -2463,6 +2958,22 @@ int install_special_mapping(struct mm_struct *mm,
71370 vma->vm_start = addr;
71371 vma->vm_end = addr + len;
71372
71373+#ifdef CONFIG_PAX_MPROTECT
71374+ if (mm->pax_flags & MF_PAX_MPROTECT) {
71375+#ifndef CONFIG_PAX_MPROTECT_COMPAT
71376+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
71377+ return -EPERM;
71378+ if (!(vm_flags & VM_EXEC))
71379+ vm_flags &= ~VM_MAYEXEC;
71380+#else
71381+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
71382+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
71383+#endif
71384+ else
71385+ vm_flags &= ~VM_MAYWRITE;
71386+ }
71387+#endif
71388+
71389 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
71390 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71391
71392diff --git a/mm/mprotect.c b/mm/mprotect.c
71393index f437d05..e3763f6 100644
71394--- a/mm/mprotect.c
71395+++ b/mm/mprotect.c
71396@@ -23,10 +23,16 @@
71397 #include <linux/mmu_notifier.h>
71398 #include <linux/migrate.h>
71399 #include <linux/perf_event.h>
71400+
71401+#ifdef CONFIG_PAX_MPROTECT
71402+#include <linux/elf.h>
71403+#endif
71404+
71405 #include <asm/uaccess.h>
71406 #include <asm/pgtable.h>
71407 #include <asm/cacheflush.h>
71408 #include <asm/tlbflush.h>
71409+#include <asm/mmu_context.h>
71410
71411 #ifndef pgprot_modify
71412 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
71413@@ -141,6 +147,48 @@ static void change_protection(struct vm_area_struct *vma,
71414 flush_tlb_range(vma, start, end);
71415 }
71416
71417+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
71418+/* called while holding the mmap semaphor for writing except stack expansion */
71419+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
71420+{
71421+ unsigned long oldlimit, newlimit = 0UL;
71422+
71423+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
71424+ return;
71425+
71426+ spin_lock(&mm->page_table_lock);
71427+ oldlimit = mm->context.user_cs_limit;
71428+ if ((prot & VM_EXEC) && oldlimit < end)
71429+ /* USER_CS limit moved up */
71430+ newlimit = end;
71431+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
71432+ /* USER_CS limit moved down */
71433+ newlimit = start;
71434+
71435+ if (newlimit) {
71436+ mm->context.user_cs_limit = newlimit;
71437+
71438+#ifdef CONFIG_SMP
71439+ wmb();
71440+ cpus_clear(mm->context.cpu_user_cs_mask);
71441+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
71442+#endif
71443+
71444+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
71445+ }
71446+ spin_unlock(&mm->page_table_lock);
71447+ if (newlimit == end) {
71448+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
71449+
71450+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
71451+ if (is_vm_hugetlb_page(vma))
71452+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
71453+ else
71454+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
71455+ }
71456+}
71457+#endif
71458+
71459 int
71460 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
71461 unsigned long start, unsigned long end, unsigned long newflags)
71462@@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
71463 int error;
71464 int dirty_accountable = 0;
71465
71466+#ifdef CONFIG_PAX_SEGMEXEC
71467+ struct vm_area_struct *vma_m = NULL;
71468+ unsigned long start_m, end_m;
71469+
71470+ start_m = start + SEGMEXEC_TASK_SIZE;
71471+ end_m = end + SEGMEXEC_TASK_SIZE;
71472+#endif
71473+
71474 if (newflags == oldflags) {
71475 *pprev = vma;
71476 return 0;
71477 }
71478
71479+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
71480+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
71481+
71482+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
71483+ return -ENOMEM;
71484+
71485+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
71486+ return -ENOMEM;
71487+ }
71488+
71489 /*
71490 * If we make a private mapping writable we increase our commit;
71491 * but (without finer accounting) cannot reduce our commit if we
71492@@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
71493 }
71494 }
71495
71496+#ifdef CONFIG_PAX_SEGMEXEC
71497+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
71498+ if (start != vma->vm_start) {
71499+ error = split_vma(mm, vma, start, 1);
71500+ if (error)
71501+ goto fail;
71502+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
71503+ *pprev = (*pprev)->vm_next;
71504+ }
71505+
71506+ if (end != vma->vm_end) {
71507+ error = split_vma(mm, vma, end, 0);
71508+ if (error)
71509+ goto fail;
71510+ }
71511+
71512+ if (pax_find_mirror_vma(vma)) {
71513+ error = __do_munmap(mm, start_m, end_m - start_m);
71514+ if (error)
71515+ goto fail;
71516+ } else {
71517+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71518+ if (!vma_m) {
71519+ error = -ENOMEM;
71520+ goto fail;
71521+ }
71522+ vma->vm_flags = newflags;
71523+ error = pax_mirror_vma(vma_m, vma);
71524+ if (error) {
71525+ vma->vm_flags = oldflags;
71526+ goto fail;
71527+ }
71528+ }
71529+ }
71530+#endif
71531+
71532 /*
71533 * First try to merge with previous and/or next vma.
71534 */
71535@@ -204,9 +306,21 @@ success:
71536 * vm_flags and vm_page_prot are protected by the mmap_sem
71537 * held in write mode.
71538 */
71539+
71540+#ifdef CONFIG_PAX_SEGMEXEC
71541+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
71542+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
71543+#endif
71544+
71545 vma->vm_flags = newflags;
71546+
71547+#ifdef CONFIG_PAX_MPROTECT
71548+ if (mm->binfmt && mm->binfmt->handle_mprotect)
71549+ mm->binfmt->handle_mprotect(vma, newflags);
71550+#endif
71551+
71552 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
71553- vm_get_page_prot(newflags));
71554+ vm_get_page_prot(vma->vm_flags));
71555
71556 if (vma_wants_writenotify(vma)) {
71557 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
71558@@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
71559 end = start + len;
71560 if (end <= start)
71561 return -ENOMEM;
71562+
71563+#ifdef CONFIG_PAX_SEGMEXEC
71564+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71565+ if (end > SEGMEXEC_TASK_SIZE)
71566+ return -EINVAL;
71567+ } else
71568+#endif
71569+
71570+ if (end > TASK_SIZE)
71571+ return -EINVAL;
71572+
71573 if (!arch_validate_prot(prot))
71574 return -EINVAL;
71575
71576@@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
71577 /*
71578 * Does the application expect PROT_READ to imply PROT_EXEC:
71579 */
71580- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
71581+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
71582 prot |= PROT_EXEC;
71583
71584 vm_flags = calc_vm_prot_bits(prot);
71585@@ -288,6 +413,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
71586 if (start > vma->vm_start)
71587 prev = vma;
71588
71589+#ifdef CONFIG_PAX_MPROTECT
71590+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
71591+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
71592+#endif
71593+
71594 for (nstart = start ; ; ) {
71595 unsigned long newflags;
71596
71597@@ -297,6 +427,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
71598
71599 /* newflags >> 4 shift VM_MAY% in place of VM_% */
71600 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
71601+ if (prot & (PROT_WRITE | PROT_EXEC))
71602+ gr_log_rwxmprotect(vma->vm_file);
71603+
71604+ error = -EACCES;
71605+ goto out;
71606+ }
71607+
71608+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
71609 error = -EACCES;
71610 goto out;
71611 }
71612@@ -311,6 +449,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
71613 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
71614 if (error)
71615 goto out;
71616+
71617+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
71618+
71619 nstart = tmp;
71620
71621 if (nstart < prev->vm_end)
71622diff --git a/mm/mremap.c b/mm/mremap.c
71623index 87bb839..c3bfadb 100644
71624--- a/mm/mremap.c
71625+++ b/mm/mremap.c
71626@@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
71627 continue;
71628 pte = ptep_get_and_clear(mm, old_addr, old_pte);
71629 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
71630+
71631+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
71632+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
71633+ pte = pte_exprotect(pte);
71634+#endif
71635+
71636 set_pte_at(mm, new_addr, new_pte, pte);
71637 }
71638
71639@@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
71640 if (is_vm_hugetlb_page(vma))
71641 goto Einval;
71642
71643+#ifdef CONFIG_PAX_SEGMEXEC
71644+ if (pax_find_mirror_vma(vma))
71645+ goto Einval;
71646+#endif
71647+
71648 /* We can't remap across vm area boundaries */
71649 if (old_len > vma->vm_end - addr)
71650 goto Efault;
71651@@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
71652 unsigned long ret = -EINVAL;
71653 unsigned long charged = 0;
71654 unsigned long map_flags;
71655+ unsigned long pax_task_size = TASK_SIZE;
71656
71657 if (new_addr & ~PAGE_MASK)
71658 goto out;
71659
71660- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
71661+#ifdef CONFIG_PAX_SEGMEXEC
71662+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
71663+ pax_task_size = SEGMEXEC_TASK_SIZE;
71664+#endif
71665+
71666+ pax_task_size -= PAGE_SIZE;
71667+
71668+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
71669 goto out;
71670
71671 /* Check if the location we're moving into overlaps the
71672 * old location at all, and fail if it does.
71673 */
71674- if ((new_addr <= addr) && (new_addr+new_len) > addr)
71675- goto out;
71676-
71677- if ((addr <= new_addr) && (addr+old_len) > new_addr)
71678+ if (addr + old_len > new_addr && new_addr + new_len > addr)
71679 goto out;
71680
71681 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
71682@@ -440,6 +456,7 @@ unsigned long do_mremap(unsigned long addr,
71683 struct vm_area_struct *vma;
71684 unsigned long ret = -EINVAL;
71685 unsigned long charged = 0;
71686+ unsigned long pax_task_size = TASK_SIZE;
71687
71688 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
71689 goto out;
71690@@ -458,6 +475,17 @@ unsigned long do_mremap(unsigned long addr,
71691 if (!new_len)
71692 goto out;
71693
71694+#ifdef CONFIG_PAX_SEGMEXEC
71695+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
71696+ pax_task_size = SEGMEXEC_TASK_SIZE;
71697+#endif
71698+
71699+ pax_task_size -= PAGE_SIZE;
71700+
71701+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
71702+ old_len > pax_task_size || addr > pax_task_size-old_len)
71703+ goto out;
71704+
71705 if (flags & MREMAP_FIXED) {
71706 if (flags & MREMAP_MAYMOVE)
71707 ret = mremap_to(addr, old_len, new_addr, new_len);
71708@@ -507,6 +535,7 @@ unsigned long do_mremap(unsigned long addr,
71709 addr + new_len);
71710 }
71711 ret = addr;
71712+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
71713 goto out;
71714 }
71715 }
71716@@ -533,7 +562,13 @@ unsigned long do_mremap(unsigned long addr,
71717 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
71718 if (ret)
71719 goto out;
71720+
71721+ map_flags = vma->vm_flags;
71722 ret = move_vma(vma, addr, old_len, new_len, new_addr);
71723+ if (!(ret & ~PAGE_MASK)) {
71724+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
71725+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
71726+ }
71727 }
71728 out:
71729 if (ret & ~PAGE_MASK)
71730diff --git a/mm/nommu.c b/mm/nommu.c
71731index f59e170..34e2a2b 100644
71732--- a/mm/nommu.c
71733+++ b/mm/nommu.c
71734@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
71735 int sysctl_overcommit_ratio = 50; /* default is 50% */
71736 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
71737 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
71738-int heap_stack_gap = 0;
71739
71740 atomic_long_t mmap_pages_allocated;
71741
71742@@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
71743 EXPORT_SYMBOL(find_vma);
71744
71745 /*
71746- * find a VMA
71747- * - we don't extend stack VMAs under NOMMU conditions
71748- */
71749-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
71750-{
71751- return find_vma(mm, addr);
71752-}
71753-
71754-/*
71755 * expand a stack to a given address
71756 * - not supported under NOMMU conditions
71757 */
71758@@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
71759
71760 /* most fields are the same, copy all, and then fixup */
71761 *new = *vma;
71762+ INIT_LIST_HEAD(&new->anon_vma_chain);
71763 *region = *vma->vm_region;
71764 new->vm_region = region;
71765
71766diff --git a/mm/page_alloc.c b/mm/page_alloc.c
71767index a13ded1..b949d15 100644
71768--- a/mm/page_alloc.c
71769+++ b/mm/page_alloc.c
71770@@ -335,7 +335,7 @@ out:
71771 * This usage means that zero-order pages may not be compound.
71772 */
71773
71774-static void free_compound_page(struct page *page)
71775+void free_compound_page(struct page *page)
71776 {
71777 __free_pages_ok(page, compound_order(page));
71778 }
71779@@ -692,6 +692,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
71780 int i;
71781 int bad = 0;
71782
71783+#ifdef CONFIG_PAX_MEMORY_SANITIZE
71784+ unsigned long index = 1UL << order;
71785+#endif
71786+
71787 trace_mm_page_free(page, order);
71788 kmemcheck_free_shadow(page, order);
71789
71790@@ -707,6 +711,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
71791 debug_check_no_obj_freed(page_address(page),
71792 PAGE_SIZE << order);
71793 }
71794+
71795+#ifdef CONFIG_PAX_MEMORY_SANITIZE
71796+ for (; index; --index)
71797+ sanitize_highpage(page + index - 1);
71798+#endif
71799+
71800 arch_free_page(page, order);
71801 kernel_map_pages(page, 1 << order, 0);
71802
71803@@ -830,8 +840,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
71804 arch_alloc_page(page, order);
71805 kernel_map_pages(page, 1 << order, 1);
71806
71807+#ifndef CONFIG_PAX_MEMORY_SANITIZE
71808 if (gfp_flags & __GFP_ZERO)
71809 prep_zero_page(page, order, gfp_flags);
71810+#endif
71811
71812 if (order && (gfp_flags & __GFP_COMP))
71813 prep_compound_page(page, order);
71814@@ -3468,7 +3480,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
71815 unsigned long pfn;
71816
71817 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
71818+#ifdef CONFIG_X86_32
71819+ /* boot failures in VMware 8 on 32bit vanilla since
71820+ this change */
71821+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
71822+#else
71823 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
71824+#endif
71825 return 1;
71826 }
71827 return 0;
71828diff --git a/mm/percpu.c b/mm/percpu.c
71829index f47af91..7eeef99 100644
71830--- a/mm/percpu.c
71831+++ b/mm/percpu.c
71832@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
71833 static unsigned int pcpu_high_unit_cpu __read_mostly;
71834
71835 /* the address of the first chunk which starts with the kernel static area */
71836-void *pcpu_base_addr __read_mostly;
71837+void *pcpu_base_addr __read_only;
71838 EXPORT_SYMBOL_GPL(pcpu_base_addr);
71839
71840 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
71841diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
71842index c20ff48..137702a 100644
71843--- a/mm/process_vm_access.c
71844+++ b/mm/process_vm_access.c
71845@@ -13,6 +13,7 @@
71846 #include <linux/uio.h>
71847 #include <linux/sched.h>
71848 #include <linux/highmem.h>
71849+#include <linux/security.h>
71850 #include <linux/ptrace.h>
71851 #include <linux/slab.h>
71852 #include <linux/syscalls.h>
71853@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
71854 size_t iov_l_curr_offset = 0;
71855 ssize_t iov_len;
71856
71857+ return -ENOSYS; // PaX: until properly audited
71858+
71859 /*
71860 * Work out how many pages of struct pages we're going to need
71861 * when eventually calling get_user_pages
71862 */
71863 for (i = 0; i < riovcnt; i++) {
71864 iov_len = rvec[i].iov_len;
71865- if (iov_len > 0) {
71866- nr_pages_iov = ((unsigned long)rvec[i].iov_base
71867- + iov_len)
71868- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
71869- / PAGE_SIZE + 1;
71870- nr_pages = max(nr_pages, nr_pages_iov);
71871- }
71872+ if (iov_len <= 0)
71873+ continue;
71874+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
71875+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
71876+ nr_pages = max(nr_pages, nr_pages_iov);
71877 }
71878
71879 if (nr_pages == 0)
71880@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
71881 goto free_proc_pages;
71882 }
71883
71884+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
71885+ rc = -EPERM;
71886+ goto put_task_struct;
71887+ }
71888+
71889 mm = mm_access(task, PTRACE_MODE_ATTACH);
71890 if (!mm || IS_ERR(mm)) {
71891 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
71892diff --git a/mm/rmap.c b/mm/rmap.c
71893index c8454e0..b04f3a2 100644
71894--- a/mm/rmap.c
71895+++ b/mm/rmap.c
71896@@ -152,6 +152,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
71897 struct anon_vma *anon_vma = vma->anon_vma;
71898 struct anon_vma_chain *avc;
71899
71900+#ifdef CONFIG_PAX_SEGMEXEC
71901+ struct anon_vma_chain *avc_m = NULL;
71902+#endif
71903+
71904 might_sleep();
71905 if (unlikely(!anon_vma)) {
71906 struct mm_struct *mm = vma->vm_mm;
71907@@ -161,6 +165,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
71908 if (!avc)
71909 goto out_enomem;
71910
71911+#ifdef CONFIG_PAX_SEGMEXEC
71912+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
71913+ if (!avc_m)
71914+ goto out_enomem_free_avc;
71915+#endif
71916+
71917 anon_vma = find_mergeable_anon_vma(vma);
71918 allocated = NULL;
71919 if (!anon_vma) {
71920@@ -174,6 +184,21 @@ int anon_vma_prepare(struct vm_area_struct *vma)
71921 /* page_table_lock to protect against threads */
71922 spin_lock(&mm->page_table_lock);
71923 if (likely(!vma->anon_vma)) {
71924+
71925+#ifdef CONFIG_PAX_SEGMEXEC
71926+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
71927+
71928+ if (vma_m) {
71929+ BUG_ON(vma_m->anon_vma);
71930+ vma_m->anon_vma = anon_vma;
71931+ avc_m->anon_vma = anon_vma;
71932+ avc_m->vma = vma;
71933+ list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
71934+ list_add(&avc_m->same_anon_vma, &anon_vma->head);
71935+ avc_m = NULL;
71936+ }
71937+#endif
71938+
71939 vma->anon_vma = anon_vma;
71940 avc->anon_vma = anon_vma;
71941 avc->vma = vma;
71942@@ -187,12 +212,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
71943
71944 if (unlikely(allocated))
71945 put_anon_vma(allocated);
71946+
71947+#ifdef CONFIG_PAX_SEGMEXEC
71948+ if (unlikely(avc_m))
71949+ anon_vma_chain_free(avc_m);
71950+#endif
71951+
71952 if (unlikely(avc))
71953 anon_vma_chain_free(avc);
71954 }
71955 return 0;
71956
71957 out_enomem_free_avc:
71958+
71959+#ifdef CONFIG_PAX_SEGMEXEC
71960+ if (avc_m)
71961+ anon_vma_chain_free(avc_m);
71962+#endif
71963+
71964 anon_vma_chain_free(avc);
71965 out_enomem:
71966 return -ENOMEM;
71967@@ -243,7 +280,7 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
71968 * Attach the anon_vmas from src to dst.
71969 * Returns 0 on success, -ENOMEM on failure.
71970 */
71971-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
71972+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
71973 {
71974 struct anon_vma_chain *avc, *pavc;
71975 struct anon_vma *root = NULL;
71976@@ -321,7 +358,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
71977 * the corresponding VMA in the parent process is attached to.
71978 * Returns 0 on success, non-zero on failure.
71979 */
71980-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
71981+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
71982 {
71983 struct anon_vma_chain *avc;
71984 struct anon_vma *anon_vma;
71985diff --git a/mm/shmem.c b/mm/shmem.c
71986index 269d049..a9d2b50 100644
71987--- a/mm/shmem.c
71988+++ b/mm/shmem.c
71989@@ -31,7 +31,7 @@
71990 #include <linux/export.h>
71991 #include <linux/swap.h>
71992
71993-static struct vfsmount *shm_mnt;
71994+struct vfsmount *shm_mnt;
71995
71996 #ifdef CONFIG_SHMEM
71997 /*
71998@@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
71999 #define BOGO_DIRENT_SIZE 20
72000
72001 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
72002-#define SHORT_SYMLINK_LEN 128
72003+#define SHORT_SYMLINK_LEN 64
72004
72005 struct shmem_xattr {
72006 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
72007@@ -2180,8 +2180,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
72008 int err = -ENOMEM;
72009
72010 /* Round up to L1_CACHE_BYTES to resist false sharing */
72011- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
72012- L1_CACHE_BYTES), GFP_KERNEL);
72013+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
72014 if (!sbinfo)
72015 return -ENOMEM;
72016
72017diff --git a/mm/slab.c b/mm/slab.c
72018index f0bd785..348b96a 100644
72019--- a/mm/slab.c
72020+++ b/mm/slab.c
72021@@ -153,7 +153,7 @@
72022
72023 /* Legal flag mask for kmem_cache_create(). */
72024 #if DEBUG
72025-# define CREATE_MASK (SLAB_RED_ZONE | \
72026+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
72027 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
72028 SLAB_CACHE_DMA | \
72029 SLAB_STORE_USER | \
72030@@ -161,7 +161,7 @@
72031 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
72032 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
72033 #else
72034-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
72035+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
72036 SLAB_CACHE_DMA | \
72037 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
72038 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
72039@@ -290,7 +290,7 @@ struct kmem_list3 {
72040 * Need this for bootstrapping a per node allocator.
72041 */
72042 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
72043-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
72044+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
72045 #define CACHE_CACHE 0
72046 #define SIZE_AC MAX_NUMNODES
72047 #define SIZE_L3 (2 * MAX_NUMNODES)
72048@@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
72049 if ((x)->max_freeable < i) \
72050 (x)->max_freeable = i; \
72051 } while (0)
72052-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
72053-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
72054-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
72055-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
72056+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
72057+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
72058+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
72059+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
72060 #else
72061 #define STATS_INC_ACTIVE(x) do { } while (0)
72062 #define STATS_DEC_ACTIVE(x) do { } while (0)
72063@@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
72064 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
72065 */
72066 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
72067- const struct slab *slab, void *obj)
72068+ const struct slab *slab, const void *obj)
72069 {
72070 u32 offset = (obj - slab->s_mem);
72071 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
72072@@ -568,7 +568,7 @@ struct cache_names {
72073 static struct cache_names __initdata cache_names[] = {
72074 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
72075 #include <linux/kmalloc_sizes.h>
72076- {NULL,}
72077+ {NULL}
72078 #undef CACHE
72079 };
72080
72081@@ -1588,7 +1588,7 @@ void __init kmem_cache_init(void)
72082 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
72083 sizes[INDEX_AC].cs_size,
72084 ARCH_KMALLOC_MINALIGN,
72085- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72086+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72087 NULL);
72088
72089 if (INDEX_AC != INDEX_L3) {
72090@@ -1596,7 +1596,7 @@ void __init kmem_cache_init(void)
72091 kmem_cache_create(names[INDEX_L3].name,
72092 sizes[INDEX_L3].cs_size,
72093 ARCH_KMALLOC_MINALIGN,
72094- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72095+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72096 NULL);
72097 }
72098
72099@@ -1614,7 +1614,7 @@ void __init kmem_cache_init(void)
72100 sizes->cs_cachep = kmem_cache_create(names->name,
72101 sizes->cs_size,
72102 ARCH_KMALLOC_MINALIGN,
72103- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72104+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72105 NULL);
72106 }
72107 #ifdef CONFIG_ZONE_DMA
72108@@ -4339,10 +4339,10 @@ static int s_show(struct seq_file *m, void *p)
72109 }
72110 /* cpu stats */
72111 {
72112- unsigned long allochit = atomic_read(&cachep->allochit);
72113- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
72114- unsigned long freehit = atomic_read(&cachep->freehit);
72115- unsigned long freemiss = atomic_read(&cachep->freemiss);
72116+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
72117+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
72118+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
72119+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
72120
72121 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
72122 allochit, allocmiss, freehit, freemiss);
72123@@ -4601,13 +4601,62 @@ static int __init slab_proc_init(void)
72124 {
72125 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
72126 #ifdef CONFIG_DEBUG_SLAB_LEAK
72127- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
72128+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
72129 #endif
72130 return 0;
72131 }
72132 module_init(slab_proc_init);
72133 #endif
72134
72135+void check_object_size(const void *ptr, unsigned long n, bool to)
72136+{
72137+
72138+#ifdef CONFIG_PAX_USERCOPY
72139+ struct page *page;
72140+ struct kmem_cache *cachep = NULL;
72141+ struct slab *slabp;
72142+ unsigned int objnr;
72143+ unsigned long offset;
72144+ const char *type;
72145+
72146+ if (!n)
72147+ return;
72148+
72149+ type = "<null>";
72150+ if (ZERO_OR_NULL_PTR(ptr))
72151+ goto report;
72152+
72153+ if (!virt_addr_valid(ptr))
72154+ return;
72155+
72156+ page = virt_to_head_page(ptr);
72157+
72158+ type = "<process stack>";
72159+ if (!PageSlab(page)) {
72160+ if (object_is_on_stack(ptr, n) == -1)
72161+ goto report;
72162+ return;
72163+ }
72164+
72165+ cachep = page_get_cache(page);
72166+ type = cachep->name;
72167+ if (!(cachep->flags & SLAB_USERCOPY))
72168+ goto report;
72169+
72170+ slabp = page_get_slab(page);
72171+ objnr = obj_to_index(cachep, slabp, ptr);
72172+ BUG_ON(objnr >= cachep->num);
72173+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
72174+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
72175+ return;
72176+
72177+report:
72178+ pax_report_usercopy(ptr, n, to, type);
72179+#endif
72180+
72181+}
72182+EXPORT_SYMBOL(check_object_size);
72183+
72184 /**
72185 * ksize - get the actual amount of memory allocated for a given object
72186 * @objp: Pointer to the object
72187diff --git a/mm/slob.c b/mm/slob.c
72188index 8105be4..e045f96 100644
72189--- a/mm/slob.c
72190+++ b/mm/slob.c
72191@@ -29,7 +29,7 @@
72192 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
72193 * alloc_pages() directly, allocating compound pages so the page order
72194 * does not have to be separately tracked, and also stores the exact
72195- * allocation size in page->private so that it can be used to accurately
72196+ * allocation size in slob_page->size so that it can be used to accurately
72197 * provide ksize(). These objects are detected in kfree() because slob_page()
72198 * is false for them.
72199 *
72200@@ -58,6 +58,7 @@
72201 */
72202
72203 #include <linux/kernel.h>
72204+#include <linux/sched.h>
72205 #include <linux/slab.h>
72206 #include <linux/mm.h>
72207 #include <linux/swap.h> /* struct reclaim_state */
72208@@ -102,7 +103,8 @@ struct slob_page {
72209 unsigned long flags; /* mandatory */
72210 atomic_t _count; /* mandatory */
72211 slobidx_t units; /* free units left in page */
72212- unsigned long pad[2];
72213+ unsigned long pad[1];
72214+ unsigned long size; /* size when >=PAGE_SIZE */
72215 slob_t *free; /* first free slob_t in page */
72216 struct list_head list; /* linked list of free pages */
72217 };
72218@@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
72219 */
72220 static inline int is_slob_page(struct slob_page *sp)
72221 {
72222- return PageSlab((struct page *)sp);
72223+ return PageSlab((struct page *)sp) && !sp->size;
72224 }
72225
72226 static inline void set_slob_page(struct slob_page *sp)
72227@@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
72228
72229 static inline struct slob_page *slob_page(const void *addr)
72230 {
72231- return (struct slob_page *)virt_to_page(addr);
72232+ return (struct slob_page *)virt_to_head_page(addr);
72233 }
72234
72235 /*
72236@@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
72237 /*
72238 * Return the size of a slob block.
72239 */
72240-static slobidx_t slob_units(slob_t *s)
72241+static slobidx_t slob_units(const slob_t *s)
72242 {
72243 if (s->units > 0)
72244 return s->units;
72245@@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
72246 /*
72247 * Return the next free slob block pointer after this one.
72248 */
72249-static slob_t *slob_next(slob_t *s)
72250+static slob_t *slob_next(const slob_t *s)
72251 {
72252 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
72253 slobidx_t next;
72254@@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
72255 /*
72256 * Returns true if s is the last free block in its page.
72257 */
72258-static int slob_last(slob_t *s)
72259+static int slob_last(const slob_t *s)
72260 {
72261 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
72262 }
72263@@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
72264 if (!page)
72265 return NULL;
72266
72267+ set_slob_page(page);
72268 return page_address(page);
72269 }
72270
72271@@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
72272 if (!b)
72273 return NULL;
72274 sp = slob_page(b);
72275- set_slob_page(sp);
72276
72277 spin_lock_irqsave(&slob_lock, flags);
72278 sp->units = SLOB_UNITS(PAGE_SIZE);
72279 sp->free = b;
72280+ sp->size = 0;
72281 INIT_LIST_HEAD(&sp->list);
72282 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
72283 set_slob_page_free(sp, slob_list);
72284@@ -476,10 +479,9 @@ out:
72285 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
72286 */
72287
72288-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72289+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
72290 {
72291- unsigned int *m;
72292- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72293+ slob_t *m;
72294 void *ret;
72295
72296 gfp &= gfp_allowed_mask;
72297@@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72298
72299 if (!m)
72300 return NULL;
72301- *m = size;
72302+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
72303+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
72304+ m[0].units = size;
72305+ m[1].units = align;
72306 ret = (void *)m + align;
72307
72308 trace_kmalloc_node(_RET_IP_, ret,
72309@@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72310 gfp |= __GFP_COMP;
72311 ret = slob_new_pages(gfp, order, node);
72312 if (ret) {
72313- struct page *page;
72314- page = virt_to_page(ret);
72315- page->private = size;
72316+ struct slob_page *sp;
72317+ sp = slob_page(ret);
72318+ sp->size = size;
72319 }
72320
72321 trace_kmalloc_node(_RET_IP_, ret,
72322 size, PAGE_SIZE << order, gfp, node);
72323 }
72324
72325- kmemleak_alloc(ret, size, 1, gfp);
72326+ return ret;
72327+}
72328+
72329+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72330+{
72331+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72332+ void *ret = __kmalloc_node_align(size, gfp, node, align);
72333+
72334+ if (!ZERO_OR_NULL_PTR(ret))
72335+ kmemleak_alloc(ret, size, 1, gfp);
72336 return ret;
72337 }
72338 EXPORT_SYMBOL(__kmalloc_node);
72339@@ -533,13 +547,92 @@ void kfree(const void *block)
72340 sp = slob_page(block);
72341 if (is_slob_page(sp)) {
72342 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72343- unsigned int *m = (unsigned int *)(block - align);
72344- slob_free(m, *m + align);
72345- } else
72346+ slob_t *m = (slob_t *)(block - align);
72347+ slob_free(m, m[0].units + align);
72348+ } else {
72349+ clear_slob_page(sp);
72350+ free_slob_page(sp);
72351+ sp->size = 0;
72352 put_page(&sp->page);
72353+ }
72354 }
72355 EXPORT_SYMBOL(kfree);
72356
72357+void check_object_size(const void *ptr, unsigned long n, bool to)
72358+{
72359+
72360+#ifdef CONFIG_PAX_USERCOPY
72361+ struct slob_page *sp;
72362+ const slob_t *free;
72363+ const void *base;
72364+ unsigned long flags;
72365+ const char *type;
72366+
72367+ if (!n)
72368+ return;
72369+
72370+ type = "<null>";
72371+ if (ZERO_OR_NULL_PTR(ptr))
72372+ goto report;
72373+
72374+ if (!virt_addr_valid(ptr))
72375+ return;
72376+
72377+ type = "<process stack>";
72378+ sp = slob_page(ptr);
72379+ if (!PageSlab((struct page *)sp)) {
72380+ if (object_is_on_stack(ptr, n) == -1)
72381+ goto report;
72382+ return;
72383+ }
72384+
72385+ type = "<slob>";
72386+ if (sp->size) {
72387+ base = page_address(&sp->page);
72388+ if (base <= ptr && n <= sp->size - (ptr - base))
72389+ return;
72390+ goto report;
72391+ }
72392+
72393+ /* some tricky double walking to find the chunk */
72394+ spin_lock_irqsave(&slob_lock, flags);
72395+ base = (void *)((unsigned long)ptr & PAGE_MASK);
72396+ free = sp->free;
72397+
72398+ while (!slob_last(free) && (void *)free <= ptr) {
72399+ base = free + slob_units(free);
72400+ free = slob_next(free);
72401+ }
72402+
72403+ while (base < (void *)free) {
72404+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
72405+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
72406+ int offset;
72407+
72408+ if (ptr < base + align)
72409+ break;
72410+
72411+ offset = ptr - base - align;
72412+ if (offset >= m) {
72413+ base += size;
72414+ continue;
72415+ }
72416+
72417+ if (n > m - offset)
72418+ break;
72419+
72420+ spin_unlock_irqrestore(&slob_lock, flags);
72421+ return;
72422+ }
72423+
72424+ spin_unlock_irqrestore(&slob_lock, flags);
72425+report:
72426+ pax_report_usercopy(ptr, n, to, type);
72427+#endif
72428+
72429+}
72430+EXPORT_SYMBOL(check_object_size);
72431+
72432 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
72433 size_t ksize(const void *block)
72434 {
72435@@ -552,10 +645,10 @@ size_t ksize(const void *block)
72436 sp = slob_page(block);
72437 if (is_slob_page(sp)) {
72438 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72439- unsigned int *m = (unsigned int *)(block - align);
72440- return SLOB_UNITS(*m) * SLOB_UNIT;
72441+ slob_t *m = (slob_t *)(block - align);
72442+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
72443 } else
72444- return sp->page.private;
72445+ return sp->size;
72446 }
72447 EXPORT_SYMBOL(ksize);
72448
72449@@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
72450 {
72451 struct kmem_cache *c;
72452
72453+#ifdef CONFIG_PAX_USERCOPY
72454+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
72455+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
72456+#else
72457 c = slob_alloc(sizeof(struct kmem_cache),
72458 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
72459+#endif
72460
72461 if (c) {
72462 c->name = name;
72463@@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
72464
72465 lockdep_trace_alloc(flags);
72466
72467+#ifdef CONFIG_PAX_USERCOPY
72468+ b = __kmalloc_node_align(c->size, flags, node, c->align);
72469+#else
72470 if (c->size < PAGE_SIZE) {
72471 b = slob_alloc(c->size, flags, c->align, node);
72472 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
72473 SLOB_UNITS(c->size) * SLOB_UNIT,
72474 flags, node);
72475 } else {
72476+ struct slob_page *sp;
72477+
72478 b = slob_new_pages(flags, get_order(c->size), node);
72479+ sp = slob_page(b);
72480+ sp->size = c->size;
72481 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
72482 PAGE_SIZE << get_order(c->size),
72483 flags, node);
72484 }
72485+#endif
72486
72487 if (c->ctor)
72488 c->ctor(b);
72489@@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
72490
72491 static void __kmem_cache_free(void *b, int size)
72492 {
72493- if (size < PAGE_SIZE)
72494+ struct slob_page *sp = slob_page(b);
72495+
72496+ if (is_slob_page(sp))
72497 slob_free(b, size);
72498- else
72499+ else {
72500+ clear_slob_page(sp);
72501+ free_slob_page(sp);
72502+ sp->size = 0;
72503 slob_free_pages(b, get_order(size));
72504+ }
72505 }
72506
72507 static void kmem_rcu_free(struct rcu_head *head)
72508@@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
72509
72510 void kmem_cache_free(struct kmem_cache *c, void *b)
72511 {
72512+ int size = c->size;
72513+
72514+#ifdef CONFIG_PAX_USERCOPY
72515+ if (size + c->align < PAGE_SIZE) {
72516+ size += c->align;
72517+ b -= c->align;
72518+ }
72519+#endif
72520+
72521 kmemleak_free_recursive(b, c->flags);
72522 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
72523 struct slob_rcu *slob_rcu;
72524- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
72525- slob_rcu->size = c->size;
72526+ slob_rcu = b + (size - sizeof(struct slob_rcu));
72527+ slob_rcu->size = size;
72528 call_rcu(&slob_rcu->head, kmem_rcu_free);
72529 } else {
72530- __kmem_cache_free(b, c->size);
72531+ __kmem_cache_free(b, size);
72532 }
72533
72534+#ifdef CONFIG_PAX_USERCOPY
72535+ trace_kfree(_RET_IP_, b);
72536+#else
72537 trace_kmem_cache_free(_RET_IP_, b);
72538+#endif
72539+
72540 }
72541 EXPORT_SYMBOL(kmem_cache_free);
72542
72543diff --git a/mm/slub.c b/mm/slub.c
72544index 0342a5d..8180ae9 100644
72545--- a/mm/slub.c
72546+++ b/mm/slub.c
72547@@ -208,7 +208,7 @@ struct track {
72548
72549 enum track_item { TRACK_ALLOC, TRACK_FREE };
72550
72551-#ifdef CONFIG_SYSFS
72552+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
72553 static int sysfs_slab_add(struct kmem_cache *);
72554 static int sysfs_slab_alias(struct kmem_cache *, const char *);
72555 static void sysfs_slab_remove(struct kmem_cache *);
72556@@ -532,7 +532,7 @@ static void print_track(const char *s, struct track *t)
72557 if (!t->addr)
72558 return;
72559
72560- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
72561+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
72562 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
72563 #ifdef CONFIG_STACKTRACE
72564 {
72565@@ -2571,6 +2571,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
72566
72567 page = virt_to_head_page(x);
72568
72569+ BUG_ON(!PageSlab(page));
72570+
72571 slab_free(s, page, x, _RET_IP_);
72572
72573 trace_kmem_cache_free(_RET_IP_, x);
72574@@ -2604,7 +2606,7 @@ static int slub_min_objects;
72575 * Merge control. If this is set then no merging of slab caches will occur.
72576 * (Could be removed. This was introduced to pacify the merge skeptics.)
72577 */
72578-static int slub_nomerge;
72579+static int slub_nomerge = 1;
72580
72581 /*
72582 * Calculate the order of allocation given an slab object size.
72583@@ -3057,7 +3059,7 @@ static int kmem_cache_open(struct kmem_cache *s,
72584 else
72585 s->cpu_partial = 30;
72586
72587- s->refcount = 1;
72588+ atomic_set(&s->refcount, 1);
72589 #ifdef CONFIG_NUMA
72590 s->remote_node_defrag_ratio = 1000;
72591 #endif
72592@@ -3161,8 +3163,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
72593 void kmem_cache_destroy(struct kmem_cache *s)
72594 {
72595 down_write(&slub_lock);
72596- s->refcount--;
72597- if (!s->refcount) {
72598+ if (atomic_dec_and_test(&s->refcount)) {
72599 list_del(&s->list);
72600 up_write(&slub_lock);
72601 if (kmem_cache_close(s)) {
72602@@ -3373,6 +3374,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
72603 EXPORT_SYMBOL(__kmalloc_node);
72604 #endif
72605
72606+void check_object_size(const void *ptr, unsigned long n, bool to)
72607+{
72608+
72609+#ifdef CONFIG_PAX_USERCOPY
72610+ struct page *page;
72611+ struct kmem_cache *s = NULL;
72612+ unsigned long offset;
72613+ const char *type;
72614+
72615+ if (!n)
72616+ return;
72617+
72618+ type = "<null>";
72619+ if (ZERO_OR_NULL_PTR(ptr))
72620+ goto report;
72621+
72622+ if (!virt_addr_valid(ptr))
72623+ return;
72624+
72625+ page = virt_to_head_page(ptr);
72626+
72627+ type = "<process stack>";
72628+ if (!PageSlab(page)) {
72629+ if (object_is_on_stack(ptr, n) == -1)
72630+ goto report;
72631+ return;
72632+ }
72633+
72634+ s = page->slab;
72635+ type = s->name;
72636+ if (!(s->flags & SLAB_USERCOPY))
72637+ goto report;
72638+
72639+ offset = (ptr - page_address(page)) % s->size;
72640+ if (offset <= s->objsize && n <= s->objsize - offset)
72641+ return;
72642+
72643+report:
72644+ pax_report_usercopy(ptr, n, to, type);
72645+#endif
72646+
72647+}
72648+EXPORT_SYMBOL(check_object_size);
72649+
72650 size_t ksize(const void *object)
72651 {
72652 struct page *page;
72653@@ -3647,7 +3692,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
72654 int node;
72655
72656 list_add(&s->list, &slab_caches);
72657- s->refcount = -1;
72658+ atomic_set(&s->refcount, -1);
72659
72660 for_each_node_state(node, N_NORMAL_MEMORY) {
72661 struct kmem_cache_node *n = get_node(s, node);
72662@@ -3767,17 +3812,17 @@ void __init kmem_cache_init(void)
72663
72664 /* Caches that are not of the two-to-the-power-of size */
72665 if (KMALLOC_MIN_SIZE <= 32) {
72666- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
72667+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
72668 caches++;
72669 }
72670
72671 if (KMALLOC_MIN_SIZE <= 64) {
72672- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
72673+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
72674 caches++;
72675 }
72676
72677 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
72678- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
72679+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
72680 caches++;
72681 }
72682
72683@@ -3845,7 +3890,7 @@ static int slab_unmergeable(struct kmem_cache *s)
72684 /*
72685 * We may have set a slab to be unmergeable during bootstrap.
72686 */
72687- if (s->refcount < 0)
72688+ if (atomic_read(&s->refcount) < 0)
72689 return 1;
72690
72691 return 0;
72692@@ -3904,7 +3949,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
72693 down_write(&slub_lock);
72694 s = find_mergeable(size, align, flags, name, ctor);
72695 if (s) {
72696- s->refcount++;
72697+ atomic_inc(&s->refcount);
72698 /*
72699 * Adjust the object sizes so that we clear
72700 * the complete object on kzalloc.
72701@@ -3913,7 +3958,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
72702 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
72703
72704 if (sysfs_slab_alias(s, name)) {
72705- s->refcount--;
72706+ atomic_dec(&s->refcount);
72707 goto err;
72708 }
72709 up_write(&slub_lock);
72710@@ -4042,7 +4087,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
72711 }
72712 #endif
72713
72714-#ifdef CONFIG_SYSFS
72715+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
72716 static int count_inuse(struct page *page)
72717 {
72718 return page->inuse;
72719@@ -4429,12 +4474,12 @@ static void resiliency_test(void)
72720 validate_slab_cache(kmalloc_caches[9]);
72721 }
72722 #else
72723-#ifdef CONFIG_SYSFS
72724+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
72725 static void resiliency_test(void) {};
72726 #endif
72727 #endif
72728
72729-#ifdef CONFIG_SYSFS
72730+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
72731 enum slab_stat_type {
72732 SL_ALL, /* All slabs */
72733 SL_PARTIAL, /* Only partially allocated slabs */
72734@@ -4677,7 +4722,7 @@ SLAB_ATTR_RO(ctor);
72735
72736 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
72737 {
72738- return sprintf(buf, "%d\n", s->refcount - 1);
72739+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
72740 }
72741 SLAB_ATTR_RO(aliases);
72742
72743@@ -5244,6 +5289,7 @@ static char *create_unique_id(struct kmem_cache *s)
72744 return name;
72745 }
72746
72747+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
72748 static int sysfs_slab_add(struct kmem_cache *s)
72749 {
72750 int err;
72751@@ -5306,6 +5352,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
72752 kobject_del(&s->kobj);
72753 kobject_put(&s->kobj);
72754 }
72755+#endif
72756
72757 /*
72758 * Need to buffer aliases during bootup until sysfs becomes
72759@@ -5319,6 +5366,7 @@ struct saved_alias {
72760
72761 static struct saved_alias *alias_list;
72762
72763+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
72764 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
72765 {
72766 struct saved_alias *al;
72767@@ -5341,6 +5389,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
72768 alias_list = al;
72769 return 0;
72770 }
72771+#endif
72772
72773 static int __init slab_sysfs_init(void)
72774 {
72775diff --git a/mm/swap.c b/mm/swap.c
72776index 14380e9..e244704 100644
72777--- a/mm/swap.c
72778+++ b/mm/swap.c
72779@@ -30,6 +30,7 @@
72780 #include <linux/backing-dev.h>
72781 #include <linux/memcontrol.h>
72782 #include <linux/gfp.h>
72783+#include <linux/hugetlb.h>
72784
72785 #include "internal.h"
72786
72787@@ -70,6 +71,8 @@ static void __put_compound_page(struct page *page)
72788
72789 __page_cache_release(page);
72790 dtor = get_compound_page_dtor(page);
72791+ if (!PageHuge(page))
72792+ BUG_ON(dtor != free_compound_page);
72793 (*dtor)(page);
72794 }
72795
72796diff --git a/mm/swapfile.c b/mm/swapfile.c
72797index f31b29d..8bdcae2 100644
72798--- a/mm/swapfile.c
72799+++ b/mm/swapfile.c
72800@@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
72801
72802 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
72803 /* Activity counter to indicate that a swapon or swapoff has occurred */
72804-static atomic_t proc_poll_event = ATOMIC_INIT(0);
72805+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
72806
72807 static inline unsigned char swap_count(unsigned char ent)
72808 {
72809@@ -1669,7 +1669,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
72810 }
72811 filp_close(swap_file, NULL);
72812 err = 0;
72813- atomic_inc(&proc_poll_event);
72814+ atomic_inc_unchecked(&proc_poll_event);
72815 wake_up_interruptible(&proc_poll_wait);
72816
72817 out_dput:
72818@@ -1685,8 +1685,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
72819
72820 poll_wait(file, &proc_poll_wait, wait);
72821
72822- if (seq->poll_event != atomic_read(&proc_poll_event)) {
72823- seq->poll_event = atomic_read(&proc_poll_event);
72824+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
72825+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
72826 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
72827 }
72828
72829@@ -1784,7 +1784,7 @@ static int swaps_open(struct inode *inode, struct file *file)
72830 return ret;
72831
72832 seq = file->private_data;
72833- seq->poll_event = atomic_read(&proc_poll_event);
72834+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
72835 return 0;
72836 }
72837
72838@@ -2122,7 +2122,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
72839 (p->flags & SWP_DISCARDABLE) ? "D" : "");
72840
72841 mutex_unlock(&swapon_mutex);
72842- atomic_inc(&proc_poll_event);
72843+ atomic_inc_unchecked(&proc_poll_event);
72844 wake_up_interruptible(&proc_poll_wait);
72845
72846 if (S_ISREG(inode->i_mode))
72847diff --git a/mm/util.c b/mm/util.c
72848index 136ac4f..5117eef 100644
72849--- a/mm/util.c
72850+++ b/mm/util.c
72851@@ -114,6 +114,7 @@ EXPORT_SYMBOL(memdup_user);
72852 * allocated buffer. Use this if you don't want to free the buffer immediately
72853 * like, for example, with RCU.
72854 */
72855+#undef __krealloc
72856 void *__krealloc(const void *p, size_t new_size, gfp_t flags)
72857 {
72858 void *ret;
72859@@ -147,6 +148,7 @@ EXPORT_SYMBOL(__krealloc);
72860 * behaves exactly like kmalloc(). If @size is 0 and @p is not a
72861 * %NULL pointer, the object pointed to is freed.
72862 */
72863+#undef krealloc
72864 void *krealloc(const void *p, size_t new_size, gfp_t flags)
72865 {
72866 void *ret;
72867@@ -243,6 +245,12 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
72868 void arch_pick_mmap_layout(struct mm_struct *mm)
72869 {
72870 mm->mmap_base = TASK_UNMAPPED_BASE;
72871+
72872+#ifdef CONFIG_PAX_RANDMMAP
72873+ if (mm->pax_flags & MF_PAX_RANDMMAP)
72874+ mm->mmap_base += mm->delta_mmap;
72875+#endif
72876+
72877 mm->get_unmapped_area = arch_get_unmapped_area;
72878 mm->unmap_area = arch_unmap_area;
72879 }
72880diff --git a/mm/vmalloc.c b/mm/vmalloc.c
72881index 86ce9a5..0fa4d89 100644
72882--- a/mm/vmalloc.c
72883+++ b/mm/vmalloc.c
72884@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
72885
72886 pte = pte_offset_kernel(pmd, addr);
72887 do {
72888- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
72889- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
72890+
72891+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
72892+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
72893+ BUG_ON(!pte_exec(*pte));
72894+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
72895+ continue;
72896+ }
72897+#endif
72898+
72899+ {
72900+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
72901+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
72902+ }
72903 } while (pte++, addr += PAGE_SIZE, addr != end);
72904 }
72905
72906@@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
72907 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
72908 {
72909 pte_t *pte;
72910+ int ret = -ENOMEM;
72911
72912 /*
72913 * nr is a running index into the array which helps higher level
72914@@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
72915 pte = pte_alloc_kernel(pmd, addr);
72916 if (!pte)
72917 return -ENOMEM;
72918+
72919+ pax_open_kernel();
72920 do {
72921 struct page *page = pages[*nr];
72922
72923- if (WARN_ON(!pte_none(*pte)))
72924- return -EBUSY;
72925- if (WARN_ON(!page))
72926- return -ENOMEM;
72927+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
72928+ if (pgprot_val(prot) & _PAGE_NX)
72929+#endif
72930+
72931+ if (WARN_ON(!pte_none(*pte))) {
72932+ ret = -EBUSY;
72933+ goto out;
72934+ }
72935+ if (WARN_ON(!page)) {
72936+ ret = -ENOMEM;
72937+ goto out;
72938+ }
72939 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
72940 (*nr)++;
72941 } while (pte++, addr += PAGE_SIZE, addr != end);
72942- return 0;
72943+ ret = 0;
72944+out:
72945+ pax_close_kernel();
72946+ return ret;
72947 }
72948
72949 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
72950@@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
72951 * and fall back on vmalloc() if that fails. Others
72952 * just put it in the vmalloc space.
72953 */
72954-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
72955+#ifdef CONFIG_MODULES
72956+#ifdef MODULES_VADDR
72957 unsigned long addr = (unsigned long)x;
72958 if (addr >= MODULES_VADDR && addr < MODULES_END)
72959 return 1;
72960 #endif
72961+
72962+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
72963+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
72964+ return 1;
72965+#endif
72966+
72967+#endif
72968+
72969 return is_vmalloc_addr(x);
72970 }
72971
72972@@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
72973
72974 if (!pgd_none(*pgd)) {
72975 pud_t *pud = pud_offset(pgd, addr);
72976+#ifdef CONFIG_X86
72977+ if (!pud_large(*pud))
72978+#endif
72979 if (!pud_none(*pud)) {
72980 pmd_t *pmd = pmd_offset(pud, addr);
72981+#ifdef CONFIG_X86
72982+ if (!pmd_large(*pmd))
72983+#endif
72984 if (!pmd_none(*pmd)) {
72985 pte_t *ptep, pte;
72986
72987@@ -1319,6 +1359,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
72988 struct vm_struct *area;
72989
72990 BUG_ON(in_interrupt());
72991+
72992+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
72993+ if (flags & VM_KERNEXEC) {
72994+ if (start != VMALLOC_START || end != VMALLOC_END)
72995+ return NULL;
72996+ start = (unsigned long)MODULES_EXEC_VADDR;
72997+ end = (unsigned long)MODULES_EXEC_END;
72998+ }
72999+#endif
73000+
73001 if (flags & VM_IOREMAP) {
73002 int bit = fls(size);
73003
73004@@ -1551,6 +1601,11 @@ void *vmap(struct page **pages, unsigned int count,
73005 if (count > totalram_pages)
73006 return NULL;
73007
73008+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73009+ if (!(pgprot_val(prot) & _PAGE_NX))
73010+ flags |= VM_KERNEXEC;
73011+#endif
73012+
73013 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
73014 __builtin_return_address(0));
73015 if (!area)
73016@@ -1652,6 +1707,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
73017 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
73018 goto fail;
73019
73020+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73021+ if (!(pgprot_val(prot) & _PAGE_NX))
73022+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
73023+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
73024+ else
73025+#endif
73026+
73027 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
73028 start, end, node, gfp_mask, caller);
73029 if (!area)
73030@@ -1704,6 +1766,7 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
73031 gfp_mask, prot, node, caller);
73032 }
73033
73034+#undef __vmalloc
73035 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
73036 {
73037 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
73038@@ -1727,6 +1790,7 @@ static inline void *__vmalloc_node_flags(unsigned long size,
73039 * For tight control over page level allocator and protection flags
73040 * use __vmalloc() instead.
73041 */
73042+#undef vmalloc
73043 void *vmalloc(unsigned long size)
73044 {
73045 return __vmalloc_node_flags(size, -1, GFP_KERNEL | __GFP_HIGHMEM);
73046@@ -1743,6 +1807,7 @@ EXPORT_SYMBOL(vmalloc);
73047 * For tight control over page level allocator and protection flags
73048 * use __vmalloc() instead.
73049 */
73050+#undef vzalloc
73051 void *vzalloc(unsigned long size)
73052 {
73053 return __vmalloc_node_flags(size, -1,
73054@@ -1757,6 +1822,7 @@ EXPORT_SYMBOL(vzalloc);
73055 * The resulting memory area is zeroed so it can be mapped to userspace
73056 * without leaking data.
73057 */
73058+#undef vmalloc_user
73059 void *vmalloc_user(unsigned long size)
73060 {
73061 struct vm_struct *area;
73062@@ -1784,6 +1850,7 @@ EXPORT_SYMBOL(vmalloc_user);
73063 * For tight control over page level allocator and protection flags
73064 * use __vmalloc() instead.
73065 */
73066+#undef vmalloc_node
73067 void *vmalloc_node(unsigned long size, int node)
73068 {
73069 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
73070@@ -1803,6 +1870,7 @@ EXPORT_SYMBOL(vmalloc_node);
73071 * For tight control over page level allocator and protection flags
73072 * use __vmalloc_node() instead.
73073 */
73074+#undef vzalloc_node
73075 void *vzalloc_node(unsigned long size, int node)
73076 {
73077 return __vmalloc_node_flags(size, node,
73078@@ -1825,10 +1893,10 @@ EXPORT_SYMBOL(vzalloc_node);
73079 * For tight control over page level allocator and protection flags
73080 * use __vmalloc() instead.
73081 */
73082-
73083+#undef vmalloc_exec
73084 void *vmalloc_exec(unsigned long size)
73085 {
73086- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
73087+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
73088 -1, __builtin_return_address(0));
73089 }
73090
73091@@ -1847,6 +1915,7 @@ void *vmalloc_exec(unsigned long size)
73092 * Allocate enough 32bit PA addressable pages to cover @size from the
73093 * page level allocator and map them into contiguous kernel virtual space.
73094 */
73095+#undef vmalloc_32
73096 void *vmalloc_32(unsigned long size)
73097 {
73098 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
73099@@ -1861,6 +1930,7 @@ EXPORT_SYMBOL(vmalloc_32);
73100 * The resulting memory area is 32bit addressable and zeroed so it can be
73101 * mapped to userspace without leaking data.
73102 */
73103+#undef vmalloc_32_user
73104 void *vmalloc_32_user(unsigned long size)
73105 {
73106 struct vm_struct *area;
73107@@ -2123,6 +2193,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
73108 unsigned long uaddr = vma->vm_start;
73109 unsigned long usize = vma->vm_end - vma->vm_start;
73110
73111+ BUG_ON(vma->vm_mirror);
73112+
73113 if ((PAGE_SIZE-1) & (unsigned long)addr)
73114 return -EINVAL;
73115
73116diff --git a/mm/vmstat.c b/mm/vmstat.c
73117index f600557..1459fc8 100644
73118--- a/mm/vmstat.c
73119+++ b/mm/vmstat.c
73120@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
73121 *
73122 * vm_stat contains the global counters
73123 */
73124-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
73125+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
73126 EXPORT_SYMBOL(vm_stat);
73127
73128 #ifdef CONFIG_SMP
73129@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
73130 v = p->vm_stat_diff[i];
73131 p->vm_stat_diff[i] = 0;
73132 local_irq_restore(flags);
73133- atomic_long_add(v, &zone->vm_stat[i]);
73134+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
73135 global_diff[i] += v;
73136 #ifdef CONFIG_NUMA
73137 /* 3 seconds idle till flush */
73138@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
73139
73140 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
73141 if (global_diff[i])
73142- atomic_long_add(global_diff[i], &vm_stat[i]);
73143+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
73144 }
73145
73146 #endif
73147@@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
73148 start_cpu_timer(cpu);
73149 #endif
73150 #ifdef CONFIG_PROC_FS
73151- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
73152- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
73153- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
73154- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
73155+ {
73156+ mode_t gr_mode = S_IRUGO;
73157+#ifdef CONFIG_GRKERNSEC_PROC_ADD
73158+ gr_mode = S_IRUSR;
73159+#endif
73160+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
73161+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
73162+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
73163+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
73164+#else
73165+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
73166+#endif
73167+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
73168+ }
73169 #endif
73170 return 0;
73171 }
73172diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
73173index efea35b..9c8dd0b 100644
73174--- a/net/8021q/vlan.c
73175+++ b/net/8021q/vlan.c
73176@@ -554,8 +554,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
73177 err = -EPERM;
73178 if (!capable(CAP_NET_ADMIN))
73179 break;
73180- if ((args.u.name_type >= 0) &&
73181- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
73182+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
73183 struct vlan_net *vn;
73184
73185 vn = net_generic(net, vlan_net_id);
73186diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
73187index fccae26..e7ece2f 100644
73188--- a/net/9p/trans_fd.c
73189+++ b/net/9p/trans_fd.c
73190@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
73191 oldfs = get_fs();
73192 set_fs(get_ds());
73193 /* The cast to a user pointer is valid due to the set_fs() */
73194- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
73195+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
73196 set_fs(oldfs);
73197
73198 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
73199diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
73200index 876fbe8..8bbea9f 100644
73201--- a/net/atm/atm_misc.c
73202+++ b/net/atm/atm_misc.c
73203@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
73204 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
73205 return 1;
73206 atm_return(vcc, truesize);
73207- atomic_inc(&vcc->stats->rx_drop);
73208+ atomic_inc_unchecked(&vcc->stats->rx_drop);
73209 return 0;
73210 }
73211 EXPORT_SYMBOL(atm_charge);
73212@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
73213 }
73214 }
73215 atm_return(vcc, guess);
73216- atomic_inc(&vcc->stats->rx_drop);
73217+ atomic_inc_unchecked(&vcc->stats->rx_drop);
73218 return NULL;
73219 }
73220 EXPORT_SYMBOL(atm_alloc_charge);
73221@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
73222
73223 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
73224 {
73225-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
73226+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
73227 __SONET_ITEMS
73228 #undef __HANDLE_ITEM
73229 }
73230@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
73231
73232 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
73233 {
73234-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
73235+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
73236 __SONET_ITEMS
73237 #undef __HANDLE_ITEM
73238 }
73239diff --git a/net/atm/lec.h b/net/atm/lec.h
73240index dfc0719..47c5322 100644
73241--- a/net/atm/lec.h
73242+++ b/net/atm/lec.h
73243@@ -48,7 +48,7 @@ struct lane2_ops {
73244 const u8 *tlvs, u32 sizeoftlvs);
73245 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
73246 const u8 *tlvs, u32 sizeoftlvs);
73247-};
73248+} __no_const;
73249
73250 /*
73251 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
73252diff --git a/net/atm/mpc.h b/net/atm/mpc.h
73253index 0919a88..a23d54e 100644
73254--- a/net/atm/mpc.h
73255+++ b/net/atm/mpc.h
73256@@ -33,7 +33,7 @@ struct mpoa_client {
73257 struct mpc_parameters parameters; /* parameters for this client */
73258
73259 const struct net_device_ops *old_ops;
73260- struct net_device_ops new_ops;
73261+ net_device_ops_no_const new_ops;
73262 };
73263
73264
73265diff --git a/net/atm/proc.c b/net/atm/proc.c
73266index 0d020de..011c7bb 100644
73267--- a/net/atm/proc.c
73268+++ b/net/atm/proc.c
73269@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
73270 const struct k_atm_aal_stats *stats)
73271 {
73272 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
73273- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
73274- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
73275- atomic_read(&stats->rx_drop));
73276+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
73277+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
73278+ atomic_read_unchecked(&stats->rx_drop));
73279 }
73280
73281 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
73282diff --git a/net/atm/resources.c b/net/atm/resources.c
73283index 23f45ce..c748f1a 100644
73284--- a/net/atm/resources.c
73285+++ b/net/atm/resources.c
73286@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
73287 static void copy_aal_stats(struct k_atm_aal_stats *from,
73288 struct atm_aal_stats *to)
73289 {
73290-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
73291+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
73292 __AAL_STAT_ITEMS
73293 #undef __HANDLE_ITEM
73294 }
73295@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
73296 static void subtract_aal_stats(struct k_atm_aal_stats *from,
73297 struct atm_aal_stats *to)
73298 {
73299-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
73300+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
73301 __AAL_STAT_ITEMS
73302 #undef __HANDLE_ITEM
73303 }
73304diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
73305index 3512e25..2b33401 100644
73306--- a/net/batman-adv/bat_iv_ogm.c
73307+++ b/net/batman-adv/bat_iv_ogm.c
73308@@ -541,7 +541,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
73309
73310 /* change sequence number to network order */
73311 batman_ogm_packet->seqno =
73312- htonl((uint32_t)atomic_read(&hard_iface->seqno));
73313+ htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
73314
73315 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
73316 batman_ogm_packet->tt_crc = htons((uint16_t)
73317@@ -561,7 +561,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
73318 else
73319 batman_ogm_packet->gw_flags = NO_FLAGS;
73320
73321- atomic_inc(&hard_iface->seqno);
73322+ atomic_inc_unchecked(&hard_iface->seqno);
73323
73324 slide_own_bcast_window(hard_iface);
73325 bat_ogm_queue_add(bat_priv, hard_iface->packet_buff,
73326@@ -922,7 +922,7 @@ static void bat_ogm_process(const struct ethhdr *ethhdr,
73327 return;
73328
73329 /* could be changed by schedule_own_packet() */
73330- if_incoming_seqno = atomic_read(&if_incoming->seqno);
73331+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
73332
73333 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
73334
73335diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
73336index 7704df4..beb4e16 100644
73337--- a/net/batman-adv/hard-interface.c
73338+++ b/net/batman-adv/hard-interface.c
73339@@ -326,8 +326,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
73340 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
73341 dev_add_pack(&hard_iface->batman_adv_ptype);
73342
73343- atomic_set(&hard_iface->seqno, 1);
73344- atomic_set(&hard_iface->frag_seqno, 1);
73345+ atomic_set_unchecked(&hard_iface->seqno, 1);
73346+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
73347 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
73348 hard_iface->net_dev->name);
73349
73350diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
73351index 987c75a..20d6f36 100644
73352--- a/net/batman-adv/soft-interface.c
73353+++ b/net/batman-adv/soft-interface.c
73354@@ -645,7 +645,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
73355
73356 /* set broadcast sequence number */
73357 bcast_packet->seqno =
73358- htonl(atomic_inc_return(&bat_priv->bcast_seqno));
73359+ htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
73360
73361 add_bcast_packet_to_list(bat_priv, skb, 1);
73362
73363@@ -843,7 +843,7 @@ struct net_device *softif_create(const char *name)
73364 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
73365
73366 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
73367- atomic_set(&bat_priv->bcast_seqno, 1);
73368+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
73369 atomic_set(&bat_priv->ttvn, 0);
73370 atomic_set(&bat_priv->tt_local_changes, 0);
73371 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
73372diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
73373index e9eb043..d174eeb 100644
73374--- a/net/batman-adv/types.h
73375+++ b/net/batman-adv/types.h
73376@@ -38,8 +38,8 @@ struct hard_iface {
73377 int16_t if_num;
73378 char if_status;
73379 struct net_device *net_dev;
73380- atomic_t seqno;
73381- atomic_t frag_seqno;
73382+ atomic_unchecked_t seqno;
73383+ atomic_unchecked_t frag_seqno;
73384 unsigned char *packet_buff;
73385 int packet_len;
73386 struct kobject *hardif_obj;
73387@@ -154,7 +154,7 @@ struct bat_priv {
73388 atomic_t orig_interval; /* uint */
73389 atomic_t hop_penalty; /* uint */
73390 atomic_t log_level; /* uint */
73391- atomic_t bcast_seqno;
73392+ atomic_unchecked_t bcast_seqno;
73393 atomic_t bcast_queue_left;
73394 atomic_t batman_queue_left;
73395 atomic_t ttvn; /* translation table version number */
73396diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
73397index 07d1c1d..7e9bea9 100644
73398--- a/net/batman-adv/unicast.c
73399+++ b/net/batman-adv/unicast.c
73400@@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
73401 frag1->flags = UNI_FRAG_HEAD | large_tail;
73402 frag2->flags = large_tail;
73403
73404- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
73405+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
73406 frag1->seqno = htons(seqno - 1);
73407 frag2->seqno = htons(seqno);
73408
73409diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
73410index 07bc69e..21e76b1 100644
73411--- a/net/bluetooth/hci_conn.c
73412+++ b/net/bluetooth/hci_conn.c
73413@@ -234,7 +234,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
73414 memset(&cp, 0, sizeof(cp));
73415
73416 cp.handle = cpu_to_le16(conn->handle);
73417- memcpy(cp.ltk, ltk, sizeof(ltk));
73418+ memcpy(cp.ltk, ltk, sizeof(cp.ltk));
73419
73420 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
73421 }
73422diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
73423index 32d338c..d24bcdb 100644
73424--- a/net/bluetooth/l2cap_core.c
73425+++ b/net/bluetooth/l2cap_core.c
73426@@ -2418,8 +2418,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
73427 break;
73428
73429 case L2CAP_CONF_RFC:
73430- if (olen == sizeof(rfc))
73431- memcpy(&rfc, (void *)val, olen);
73432+ if (olen != sizeof(rfc))
73433+ break;
73434+
73435+ memcpy(&rfc, (void *)val, olen);
73436
73437 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
73438 rfc.mode != chan->mode)
73439@@ -2537,8 +2539,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
73440
73441 switch (type) {
73442 case L2CAP_CONF_RFC:
73443- if (olen == sizeof(rfc))
73444- memcpy(&rfc, (void *)val, olen);
73445+ if (olen != sizeof(rfc))
73446+ break;
73447+
73448+ memcpy(&rfc, (void *)val, olen);
73449 goto done;
73450 }
73451 }
73452diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
73453index 5fe2ff3..10968b5 100644
73454--- a/net/bridge/netfilter/ebtables.c
73455+++ b/net/bridge/netfilter/ebtables.c
73456@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
73457 tmp.valid_hooks = t->table->valid_hooks;
73458 }
73459 mutex_unlock(&ebt_mutex);
73460- if (copy_to_user(user, &tmp, *len) != 0){
73461+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
73462 BUGPRINT("c2u Didn't work\n");
73463 ret = -EFAULT;
73464 break;
73465diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
73466index a97d97a..6f679ed 100644
73467--- a/net/caif/caif_socket.c
73468+++ b/net/caif/caif_socket.c
73469@@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
73470 #ifdef CONFIG_DEBUG_FS
73471 struct debug_fs_counter {
73472 atomic_t caif_nr_socks;
73473- atomic_t caif_sock_create;
73474- atomic_t num_connect_req;
73475- atomic_t num_connect_resp;
73476- atomic_t num_connect_fail_resp;
73477- atomic_t num_disconnect;
73478- atomic_t num_remote_shutdown_ind;
73479- atomic_t num_tx_flow_off_ind;
73480- atomic_t num_tx_flow_on_ind;
73481- atomic_t num_rx_flow_off;
73482- atomic_t num_rx_flow_on;
73483+ atomic_unchecked_t caif_sock_create;
73484+ atomic_unchecked_t num_connect_req;
73485+ atomic_unchecked_t num_connect_resp;
73486+ atomic_unchecked_t num_connect_fail_resp;
73487+ atomic_unchecked_t num_disconnect;
73488+ atomic_unchecked_t num_remote_shutdown_ind;
73489+ atomic_unchecked_t num_tx_flow_off_ind;
73490+ atomic_unchecked_t num_tx_flow_on_ind;
73491+ atomic_unchecked_t num_rx_flow_off;
73492+ atomic_unchecked_t num_rx_flow_on;
73493 };
73494 static struct debug_fs_counter cnt;
73495 #define dbfs_atomic_inc(v) atomic_inc_return(v)
73496+#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
73497 #define dbfs_atomic_dec(v) atomic_dec_return(v)
73498 #else
73499 #define dbfs_atomic_inc(v) 0
73500@@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
73501 atomic_read(&cf_sk->sk.sk_rmem_alloc),
73502 sk_rcvbuf_lowwater(cf_sk));
73503 set_rx_flow_off(cf_sk);
73504- dbfs_atomic_inc(&cnt.num_rx_flow_off);
73505+ dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
73506 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
73507 }
73508
73509@@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
73510 set_rx_flow_off(cf_sk);
73511 if (net_ratelimit())
73512 pr_debug("sending flow OFF due to rmem_schedule\n");
73513- dbfs_atomic_inc(&cnt.num_rx_flow_off);
73514+ dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
73515 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
73516 }
73517 skb->dev = NULL;
73518@@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer *layr,
73519 switch (flow) {
73520 case CAIF_CTRLCMD_FLOW_ON_IND:
73521 /* OK from modem to start sending again */
73522- dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
73523+ dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
73524 set_tx_flow_on(cf_sk);
73525 cf_sk->sk.sk_state_change(&cf_sk->sk);
73526 break;
73527
73528 case CAIF_CTRLCMD_FLOW_OFF_IND:
73529 /* Modem asks us to shut up */
73530- dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
73531+ dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
73532 set_tx_flow_off(cf_sk);
73533 cf_sk->sk.sk_state_change(&cf_sk->sk);
73534 break;
73535@@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
73536 /* We're now connected */
73537 caif_client_register_refcnt(&cf_sk->layer,
73538 cfsk_hold, cfsk_put);
73539- dbfs_atomic_inc(&cnt.num_connect_resp);
73540+ dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
73541 cf_sk->sk.sk_state = CAIF_CONNECTED;
73542 set_tx_flow_on(cf_sk);
73543 cf_sk->sk.sk_state_change(&cf_sk->sk);
73544@@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
73545
73546 case CAIF_CTRLCMD_INIT_FAIL_RSP:
73547 /* Connect request failed */
73548- dbfs_atomic_inc(&cnt.num_connect_fail_resp);
73549+ dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
73550 cf_sk->sk.sk_err = ECONNREFUSED;
73551 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
73552 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
73553@@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
73554
73555 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
73556 /* Modem has closed this connection, or device is down. */
73557- dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
73558+ dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
73559 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
73560 cf_sk->sk.sk_err = ECONNRESET;
73561 set_rx_flow_on(cf_sk);
73562@@ -297,7 +298,7 @@ static void caif_check_flow_release(struct sock *sk)
73563 return;
73564
73565 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
73566- dbfs_atomic_inc(&cnt.num_rx_flow_on);
73567+ dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
73568 set_rx_flow_on(cf_sk);
73569 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
73570 }
73571@@ -856,7 +857,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
73572 /*ifindex = id of the interface.*/
73573 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
73574
73575- dbfs_atomic_inc(&cnt.num_connect_req);
73576+ dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
73577 cf_sk->layer.receive = caif_sktrecv_cb;
73578
73579 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
73580@@ -945,7 +946,7 @@ static int caif_release(struct socket *sock)
73581 spin_unlock_bh(&sk->sk_receive_queue.lock);
73582 sock->sk = NULL;
73583
73584- dbfs_atomic_inc(&cnt.num_disconnect);
73585+ dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
73586
73587 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
73588 if (cf_sk->debugfs_socket_dir != NULL)
73589@@ -1124,7 +1125,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
73590 cf_sk->conn_req.protocol = protocol;
73591 /* Increase the number of sockets created. */
73592 dbfs_atomic_inc(&cnt.caif_nr_socks);
73593- num = dbfs_atomic_inc(&cnt.caif_sock_create);
73594+ num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
73595 #ifdef CONFIG_DEBUG_FS
73596 if (!IS_ERR(debugfsdir)) {
73597
73598diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
73599index 5cf5222..6f704ad 100644
73600--- a/net/caif/cfctrl.c
73601+++ b/net/caif/cfctrl.c
73602@@ -9,6 +9,7 @@
73603 #include <linux/stddef.h>
73604 #include <linux/spinlock.h>
73605 #include <linux/slab.h>
73606+#include <linux/sched.h>
73607 #include <net/caif/caif_layer.h>
73608 #include <net/caif/cfpkt.h>
73609 #include <net/caif/cfctrl.h>
73610@@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
73611 memset(&dev_info, 0, sizeof(dev_info));
73612 dev_info.id = 0xff;
73613 cfsrvl_init(&this->serv, 0, &dev_info, false);
73614- atomic_set(&this->req_seq_no, 1);
73615- atomic_set(&this->rsp_seq_no, 1);
73616+ atomic_set_unchecked(&this->req_seq_no, 1);
73617+ atomic_set_unchecked(&this->rsp_seq_no, 1);
73618 this->serv.layer.receive = cfctrl_recv;
73619 sprintf(this->serv.layer.name, "ctrl");
73620 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
73621@@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
73622 struct cfctrl_request_info *req)
73623 {
73624 spin_lock_bh(&ctrl->info_list_lock);
73625- atomic_inc(&ctrl->req_seq_no);
73626- req->sequence_no = atomic_read(&ctrl->req_seq_no);
73627+ atomic_inc_unchecked(&ctrl->req_seq_no);
73628+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
73629 list_add_tail(&req->list, &ctrl->list);
73630 spin_unlock_bh(&ctrl->info_list_lock);
73631 }
73632@@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
73633 if (p != first)
73634 pr_warn("Requests are not received in order\n");
73635
73636- atomic_set(&ctrl->rsp_seq_no,
73637+ atomic_set_unchecked(&ctrl->rsp_seq_no,
73638 p->sequence_no);
73639 list_del(&p->list);
73640 goto out;
73641diff --git a/net/can/gw.c b/net/can/gw.c
73642index 3d79b12..8de85fa 100644
73643--- a/net/can/gw.c
73644+++ b/net/can/gw.c
73645@@ -96,7 +96,7 @@ struct cf_mod {
73646 struct {
73647 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
73648 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
73649- } csumfunc;
73650+ } __no_const csumfunc;
73651 };
73652
73653
73654diff --git a/net/compat.c b/net/compat.c
73655index 6def90e..c6992fa 100644
73656--- a/net/compat.c
73657+++ b/net/compat.c
73658@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
73659 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
73660 __get_user(kmsg->msg_flags, &umsg->msg_flags))
73661 return -EFAULT;
73662- kmsg->msg_name = compat_ptr(tmp1);
73663- kmsg->msg_iov = compat_ptr(tmp2);
73664- kmsg->msg_control = compat_ptr(tmp3);
73665+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
73666+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
73667+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
73668 return 0;
73669 }
73670
73671@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
73672
73673 if (kern_msg->msg_namelen) {
73674 if (mode == VERIFY_READ) {
73675- int err = move_addr_to_kernel(kern_msg->msg_name,
73676+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
73677 kern_msg->msg_namelen,
73678 kern_address);
73679 if (err < 0)
73680@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
73681 kern_msg->msg_name = NULL;
73682
73683 tot_len = iov_from_user_compat_to_kern(kern_iov,
73684- (struct compat_iovec __user *)kern_msg->msg_iov,
73685+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
73686 kern_msg->msg_iovlen);
73687 if (tot_len >= 0)
73688 kern_msg->msg_iov = kern_iov;
73689@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
73690
73691 #define CMSG_COMPAT_FIRSTHDR(msg) \
73692 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
73693- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
73694+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
73695 (struct compat_cmsghdr __user *)NULL)
73696
73697 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
73698 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
73699 (ucmlen) <= (unsigned long) \
73700 ((mhdr)->msg_controllen - \
73701- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
73702+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
73703
73704 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
73705 struct compat_cmsghdr __user *cmsg, int cmsg_len)
73706 {
73707 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
73708- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
73709+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
73710 msg->msg_controllen)
73711 return NULL;
73712 return (struct compat_cmsghdr __user *)ptr;
73713@@ -221,7 +221,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
73714 {
73715 struct compat_timeval ctv;
73716 struct compat_timespec cts[3];
73717- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
73718+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
73719 struct compat_cmsghdr cmhdr;
73720 int cmlen;
73721
73722@@ -273,7 +273,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
73723
73724 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
73725 {
73726- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
73727+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
73728 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
73729 int fdnum = scm->fp->count;
73730 struct file **fp = scm->fp->fp;
73731@@ -370,7 +370,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
73732 return -EFAULT;
73733 old_fs = get_fs();
73734 set_fs(KERNEL_DS);
73735- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
73736+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
73737 set_fs(old_fs);
73738
73739 return err;
73740@@ -431,7 +431,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
73741 len = sizeof(ktime);
73742 old_fs = get_fs();
73743 set_fs(KERNEL_DS);
73744- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
73745+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
73746 set_fs(old_fs);
73747
73748 if (!err) {
73749@@ -566,7 +566,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
73750 case MCAST_JOIN_GROUP:
73751 case MCAST_LEAVE_GROUP:
73752 {
73753- struct compat_group_req __user *gr32 = (void *)optval;
73754+ struct compat_group_req __user *gr32 = (void __user *)optval;
73755 struct group_req __user *kgr =
73756 compat_alloc_user_space(sizeof(struct group_req));
73757 u32 interface;
73758@@ -587,7 +587,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
73759 case MCAST_BLOCK_SOURCE:
73760 case MCAST_UNBLOCK_SOURCE:
73761 {
73762- struct compat_group_source_req __user *gsr32 = (void *)optval;
73763+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
73764 struct group_source_req __user *kgsr = compat_alloc_user_space(
73765 sizeof(struct group_source_req));
73766 u32 interface;
73767@@ -608,7 +608,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
73768 }
73769 case MCAST_MSFILTER:
73770 {
73771- struct compat_group_filter __user *gf32 = (void *)optval;
73772+ struct compat_group_filter __user *gf32 = (void __user *)optval;
73773 struct group_filter __user *kgf;
73774 u32 interface, fmode, numsrc;
73775
73776@@ -646,7 +646,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
73777 char __user *optval, int __user *optlen,
73778 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
73779 {
73780- struct compat_group_filter __user *gf32 = (void *)optval;
73781+ struct compat_group_filter __user *gf32 = (void __user *)optval;
73782 struct group_filter __user *kgf;
73783 int __user *koptlen;
73784 u32 interface, fmode, numsrc;
73785diff --git a/net/core/datagram.c b/net/core/datagram.c
73786index 68bbf9f..5ef0d12 100644
73787--- a/net/core/datagram.c
73788+++ b/net/core/datagram.c
73789@@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
73790 }
73791
73792 kfree_skb(skb);
73793- atomic_inc(&sk->sk_drops);
73794+ atomic_inc_unchecked(&sk->sk_drops);
73795 sk_mem_reclaim_partial(sk);
73796
73797 return err;
73798diff --git a/net/core/dev.c b/net/core/dev.c
73799index a4bf943..9c83051 100644
73800--- a/net/core/dev.c
73801+++ b/net/core/dev.c
73802@@ -1138,10 +1138,14 @@ void dev_load(struct net *net, const char *name)
73803 if (no_module && capable(CAP_NET_ADMIN))
73804 no_module = request_module("netdev-%s", name);
73805 if (no_module && capable(CAP_SYS_MODULE)) {
73806+#ifdef CONFIG_GRKERNSEC_MODHARDEN
73807+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
73808+#else
73809 if (!request_module("%s", name))
73810 pr_err("Loading kernel module for a network device "
73811 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
73812 "instead\n", name);
73813+#endif
73814 }
73815 }
73816 EXPORT_SYMBOL(dev_load);
73817@@ -1585,7 +1589,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
73818 {
73819 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
73820 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
73821- atomic_long_inc(&dev->rx_dropped);
73822+ atomic_long_inc_unchecked(&dev->rx_dropped);
73823 kfree_skb(skb);
73824 return NET_RX_DROP;
73825 }
73826@@ -1595,7 +1599,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
73827 nf_reset(skb);
73828
73829 if (unlikely(!is_skb_forwardable(dev, skb))) {
73830- atomic_long_inc(&dev->rx_dropped);
73831+ atomic_long_inc_unchecked(&dev->rx_dropped);
73832 kfree_skb(skb);
73833 return NET_RX_DROP;
73834 }
73835@@ -2057,7 +2061,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
73836
73837 struct dev_gso_cb {
73838 void (*destructor)(struct sk_buff *skb);
73839-};
73840+} __no_const;
73841
73842 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
73843
73844@@ -2913,7 +2917,7 @@ enqueue:
73845
73846 local_irq_restore(flags);
73847
73848- atomic_long_inc(&skb->dev->rx_dropped);
73849+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
73850 kfree_skb(skb);
73851 return NET_RX_DROP;
73852 }
73853@@ -2985,7 +2989,7 @@ int netif_rx_ni(struct sk_buff *skb)
73854 }
73855 EXPORT_SYMBOL(netif_rx_ni);
73856
73857-static void net_tx_action(struct softirq_action *h)
73858+static void net_tx_action(void)
73859 {
73860 struct softnet_data *sd = &__get_cpu_var(softnet_data);
73861
73862@@ -3273,7 +3277,7 @@ ncls:
73863 if (pt_prev) {
73864 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
73865 } else {
73866- atomic_long_inc(&skb->dev->rx_dropped);
73867+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
73868 kfree_skb(skb);
73869 /* Jamal, now you will not able to escape explaining
73870 * me how you were going to use this. :-)
73871@@ -3833,7 +3837,7 @@ void netif_napi_del(struct napi_struct *napi)
73872 }
73873 EXPORT_SYMBOL(netif_napi_del);
73874
73875-static void net_rx_action(struct softirq_action *h)
73876+static void net_rx_action(void)
73877 {
73878 struct softnet_data *sd = &__get_cpu_var(softnet_data);
73879 unsigned long time_limit = jiffies + 2;
73880@@ -5890,7 +5894,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
73881 } else {
73882 netdev_stats_to_stats64(storage, &dev->stats);
73883 }
73884- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
73885+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
73886 return storage;
73887 }
73888 EXPORT_SYMBOL(dev_get_stats);
73889diff --git a/net/core/flow.c b/net/core/flow.c
73890index e318c7e..168b1d0 100644
73891--- a/net/core/flow.c
73892+++ b/net/core/flow.c
73893@@ -61,7 +61,7 @@ struct flow_cache {
73894 struct timer_list rnd_timer;
73895 };
73896
73897-atomic_t flow_cache_genid = ATOMIC_INIT(0);
73898+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
73899 EXPORT_SYMBOL(flow_cache_genid);
73900 static struct flow_cache flow_cache_global;
73901 static struct kmem_cache *flow_cachep __read_mostly;
73902@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
73903
73904 static int flow_entry_valid(struct flow_cache_entry *fle)
73905 {
73906- if (atomic_read(&flow_cache_genid) != fle->genid)
73907+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
73908 return 0;
73909 if (fle->object && !fle->object->ops->check(fle->object))
73910 return 0;
73911@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
73912 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
73913 fcp->hash_count++;
73914 }
73915- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
73916+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
73917 flo = fle->object;
73918 if (!flo)
73919 goto ret_object;
73920@@ -280,7 +280,7 @@ nocache:
73921 }
73922 flo = resolver(net, key, family, dir, flo, ctx);
73923 if (fle) {
73924- fle->genid = atomic_read(&flow_cache_genid);
73925+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
73926 if (!IS_ERR(flo))
73927 fle->object = flo;
73928 else
73929diff --git a/net/core/iovec.c b/net/core/iovec.c
73930index c40f27e..7f49254 100644
73931--- a/net/core/iovec.c
73932+++ b/net/core/iovec.c
73933@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
73934 if (m->msg_namelen) {
73935 if (mode == VERIFY_READ) {
73936 void __user *namep;
73937- namep = (void __user __force *) m->msg_name;
73938+ namep = (void __force_user *) m->msg_name;
73939 err = move_addr_to_kernel(namep, m->msg_namelen,
73940 address);
73941 if (err < 0)
73942@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
73943 }
73944
73945 size = m->msg_iovlen * sizeof(struct iovec);
73946- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
73947+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
73948 return -EFAULT;
73949
73950 m->msg_iov = iov;
73951diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
73952index 5c30296..ebe7b61 100644
73953--- a/net/core/rtnetlink.c
73954+++ b/net/core/rtnetlink.c
73955@@ -57,7 +57,7 @@ struct rtnl_link {
73956 rtnl_doit_func doit;
73957 rtnl_dumpit_func dumpit;
73958 rtnl_calcit_func calcit;
73959-};
73960+} __no_const;
73961
73962 static DEFINE_MUTEX(rtnl_mutex);
73963
73964diff --git a/net/core/scm.c b/net/core/scm.c
73965index ff52ad0..aff1c0f 100644
73966--- a/net/core/scm.c
73967+++ b/net/core/scm.c
73968@@ -220,7 +220,7 @@ EXPORT_SYMBOL(__scm_send);
73969 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
73970 {
73971 struct cmsghdr __user *cm
73972- = (__force struct cmsghdr __user *)msg->msg_control;
73973+ = (struct cmsghdr __force_user *)msg->msg_control;
73974 struct cmsghdr cmhdr;
73975 int cmlen = CMSG_LEN(len);
73976 int err;
73977@@ -243,7 +243,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
73978 err = -EFAULT;
73979 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
73980 goto out;
73981- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
73982+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
73983 goto out;
73984 cmlen = CMSG_SPACE(len);
73985 if (msg->msg_controllen < cmlen)
73986@@ -259,7 +259,7 @@ EXPORT_SYMBOL(put_cmsg);
73987 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
73988 {
73989 struct cmsghdr __user *cm
73990- = (__force struct cmsghdr __user*)msg->msg_control;
73991+ = (struct cmsghdr __force_user *)msg->msg_control;
73992
73993 int fdmax = 0;
73994 int fdnum = scm->fp->count;
73995@@ -279,7 +279,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
73996 if (fdnum < fdmax)
73997 fdmax = fdnum;
73998
73999- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
74000+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
74001 i++, cmfptr++)
74002 {
74003 int new_fd;
74004diff --git a/net/core/sock.c b/net/core/sock.c
74005index 02f8dfe..86dfd4a 100644
74006--- a/net/core/sock.c
74007+++ b/net/core/sock.c
74008@@ -341,7 +341,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74009 struct sk_buff_head *list = &sk->sk_receive_queue;
74010
74011 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
74012- atomic_inc(&sk->sk_drops);
74013+ atomic_inc_unchecked(&sk->sk_drops);
74014 trace_sock_rcvqueue_full(sk, skb);
74015 return -ENOMEM;
74016 }
74017@@ -351,7 +351,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74018 return err;
74019
74020 if (!sk_rmem_schedule(sk, skb->truesize)) {
74021- atomic_inc(&sk->sk_drops);
74022+ atomic_inc_unchecked(&sk->sk_drops);
74023 return -ENOBUFS;
74024 }
74025
74026@@ -371,7 +371,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74027 skb_dst_force(skb);
74028
74029 spin_lock_irqsave(&list->lock, flags);
74030- skb->dropcount = atomic_read(&sk->sk_drops);
74031+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
74032 __skb_queue_tail(list, skb);
74033 spin_unlock_irqrestore(&list->lock, flags);
74034
74035@@ -391,7 +391,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
74036 skb->dev = NULL;
74037
74038 if (sk_rcvqueues_full(sk, skb)) {
74039- atomic_inc(&sk->sk_drops);
74040+ atomic_inc_unchecked(&sk->sk_drops);
74041 goto discard_and_relse;
74042 }
74043 if (nested)
74044@@ -409,7 +409,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
74045 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
74046 } else if (sk_add_backlog(sk, skb)) {
74047 bh_unlock_sock(sk);
74048- atomic_inc(&sk->sk_drops);
74049+ atomic_inc_unchecked(&sk->sk_drops);
74050 goto discard_and_relse;
74051 }
74052
74053@@ -974,7 +974,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74054 if (len > sizeof(peercred))
74055 len = sizeof(peercred);
74056 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
74057- if (copy_to_user(optval, &peercred, len))
74058+ if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
74059 return -EFAULT;
74060 goto lenout;
74061 }
74062@@ -987,7 +987,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74063 return -ENOTCONN;
74064 if (lv < len)
74065 return -EINVAL;
74066- if (copy_to_user(optval, address, len))
74067+ if (len > sizeof(address) || copy_to_user(optval, address, len))
74068 return -EFAULT;
74069 goto lenout;
74070 }
74071@@ -1024,7 +1024,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74072
74073 if (len > lv)
74074 len = lv;
74075- if (copy_to_user(optval, &v, len))
74076+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
74077 return -EFAULT;
74078 lenout:
74079 if (put_user(len, optlen))
74080@@ -2108,7 +2108,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
74081 */
74082 smp_wmb();
74083 atomic_set(&sk->sk_refcnt, 1);
74084- atomic_set(&sk->sk_drops, 0);
74085+ atomic_set_unchecked(&sk->sk_drops, 0);
74086 }
74087 EXPORT_SYMBOL(sock_init_data);
74088
74089diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
74090index b9868e1..849f809 100644
74091--- a/net/core/sock_diag.c
74092+++ b/net/core/sock_diag.c
74093@@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
74094
74095 int sock_diag_check_cookie(void *sk, __u32 *cookie)
74096 {
74097+#ifndef CONFIG_GRKERNSEC_HIDESYM
74098 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
74099 cookie[1] != INET_DIAG_NOCOOKIE) &&
74100 ((u32)(unsigned long)sk != cookie[0] ||
74101 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
74102 return -ESTALE;
74103 else
74104+#endif
74105 return 0;
74106 }
74107 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
74108
74109 void sock_diag_save_cookie(void *sk, __u32 *cookie)
74110 {
74111+#ifdef CONFIG_GRKERNSEC_HIDESYM
74112+ cookie[0] = 0;
74113+ cookie[1] = 0;
74114+#else
74115 cookie[0] = (u32)(unsigned long)sk;
74116 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
74117+#endif
74118 }
74119 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
74120
74121diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
74122index 02e75d1..9a57a7c 100644
74123--- a/net/decnet/sysctl_net_decnet.c
74124+++ b/net/decnet/sysctl_net_decnet.c
74125@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
74126
74127 if (len > *lenp) len = *lenp;
74128
74129- if (copy_to_user(buffer, addr, len))
74130+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
74131 return -EFAULT;
74132
74133 *lenp = len;
74134@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
74135
74136 if (len > *lenp) len = *lenp;
74137
74138- if (copy_to_user(buffer, devname, len))
74139+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
74140 return -EFAULT;
74141
74142 *lenp = len;
74143diff --git a/net/econet/Kconfig b/net/econet/Kconfig
74144index 39a2d29..f39c0fe 100644
74145--- a/net/econet/Kconfig
74146+++ b/net/econet/Kconfig
74147@@ -4,7 +4,7 @@
74148
74149 config ECONET
74150 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
74151- depends on EXPERIMENTAL && INET
74152+ depends on EXPERIMENTAL && INET && BROKEN
74153 ---help---
74154 Econet is a fairly old and slow networking protocol mainly used by
74155 Acorn computers to access file and print servers. It uses native
74156diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
74157index 92fc5f6..b790d91 100644
74158--- a/net/ipv4/fib_frontend.c
74159+++ b/net/ipv4/fib_frontend.c
74160@@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
74161 #ifdef CONFIG_IP_ROUTE_MULTIPATH
74162 fib_sync_up(dev);
74163 #endif
74164- atomic_inc(&net->ipv4.dev_addr_genid);
74165+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74166 rt_cache_flush(dev_net(dev), -1);
74167 break;
74168 case NETDEV_DOWN:
74169 fib_del_ifaddr(ifa, NULL);
74170- atomic_inc(&net->ipv4.dev_addr_genid);
74171+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74172 if (ifa->ifa_dev->ifa_list == NULL) {
74173 /* Last address was deleted from this interface.
74174 * Disable IP.
74175@@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
74176 #ifdef CONFIG_IP_ROUTE_MULTIPATH
74177 fib_sync_up(dev);
74178 #endif
74179- atomic_inc(&net->ipv4.dev_addr_genid);
74180+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74181 rt_cache_flush(dev_net(dev), -1);
74182 break;
74183 case NETDEV_DOWN:
74184diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
74185index 80106d8..232e898 100644
74186--- a/net/ipv4/fib_semantics.c
74187+++ b/net/ipv4/fib_semantics.c
74188@@ -699,7 +699,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
74189 nh->nh_saddr = inet_select_addr(nh->nh_dev,
74190 nh->nh_gw,
74191 nh->nh_parent->fib_scope);
74192- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
74193+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
74194
74195 return nh->nh_saddr;
74196 }
74197diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
74198index 984ec65..97ac518 100644
74199--- a/net/ipv4/inet_hashtables.c
74200+++ b/net/ipv4/inet_hashtables.c
74201@@ -18,12 +18,15 @@
74202 #include <linux/sched.h>
74203 #include <linux/slab.h>
74204 #include <linux/wait.h>
74205+#include <linux/security.h>
74206
74207 #include <net/inet_connection_sock.h>
74208 #include <net/inet_hashtables.h>
74209 #include <net/secure_seq.h>
74210 #include <net/ip.h>
74211
74212+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
74213+
74214 /*
74215 * Allocate and initialize a new local port bind bucket.
74216 * The bindhash mutex for snum's hash chain must be held here.
74217@@ -530,6 +533,8 @@ ok:
74218 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
74219 spin_unlock(&head->lock);
74220
74221+ gr_update_task_in_ip_table(current, inet_sk(sk));
74222+
74223 if (tw) {
74224 inet_twsk_deschedule(tw, death_row);
74225 while (twrefcnt) {
74226diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
74227index d4d61b6..b81aec8 100644
74228--- a/net/ipv4/inetpeer.c
74229+++ b/net/ipv4/inetpeer.c
74230@@ -487,8 +487,8 @@ relookup:
74231 if (p) {
74232 p->daddr = *daddr;
74233 atomic_set(&p->refcnt, 1);
74234- atomic_set(&p->rid, 0);
74235- atomic_set(&p->ip_id_count,
74236+ atomic_set_unchecked(&p->rid, 0);
74237+ atomic_set_unchecked(&p->ip_id_count,
74238 (daddr->family == AF_INET) ?
74239 secure_ip_id(daddr->addr.a4) :
74240 secure_ipv6_id(daddr->addr.a6));
74241diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
74242index 1f23a57..7180dfe 100644
74243--- a/net/ipv4/ip_fragment.c
74244+++ b/net/ipv4/ip_fragment.c
74245@@ -316,7 +316,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
74246 return 0;
74247
74248 start = qp->rid;
74249- end = atomic_inc_return(&peer->rid);
74250+ end = atomic_inc_return_unchecked(&peer->rid);
74251 qp->rid = end;
74252
74253 rc = qp->q.fragments && (end - start) > max;
74254diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
74255index 8aa87c1..35c3248 100644
74256--- a/net/ipv4/ip_sockglue.c
74257+++ b/net/ipv4/ip_sockglue.c
74258@@ -1112,7 +1112,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
74259 len = min_t(unsigned int, len, opt->optlen);
74260 if (put_user(len, optlen))
74261 return -EFAULT;
74262- if (copy_to_user(optval, opt->__data, len))
74263+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
74264+ copy_to_user(optval, opt->__data, len))
74265 return -EFAULT;
74266 return 0;
74267 }
74268@@ -1240,7 +1241,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
74269 if (sk->sk_type != SOCK_STREAM)
74270 return -ENOPROTOOPT;
74271
74272- msg.msg_control = optval;
74273+ msg.msg_control = (void __force_kernel *)optval;
74274 msg.msg_controllen = len;
74275 msg.msg_flags = flags;
74276
74277diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
74278index 6e412a6..6640538 100644
74279--- a/net/ipv4/ipconfig.c
74280+++ b/net/ipv4/ipconfig.c
74281@@ -318,7 +318,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
74282
74283 mm_segment_t oldfs = get_fs();
74284 set_fs(get_ds());
74285- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
74286+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
74287 set_fs(oldfs);
74288 return res;
74289 }
74290@@ -329,7 +329,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
74291
74292 mm_segment_t oldfs = get_fs();
74293 set_fs(get_ds());
74294- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
74295+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
74296 set_fs(oldfs);
74297 return res;
74298 }
74299@@ -340,7 +340,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
74300
74301 mm_segment_t oldfs = get_fs();
74302 set_fs(get_ds());
74303- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
74304+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
74305 set_fs(oldfs);
74306 return res;
74307 }
74308diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
74309index 2133c30..5c4b40b 100644
74310--- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
74311+++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
74312@@ -399,7 +399,7 @@ static unsigned char asn1_octets_decode(struct asn1_ctx *ctx,
74313
74314 *len = 0;
74315
74316- *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
74317+ *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
74318 if (*octets == NULL)
74319 return 0;
74320
74321diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
74322index b072386..abdebcf 100644
74323--- a/net/ipv4/ping.c
74324+++ b/net/ipv4/ping.c
74325@@ -838,7 +838,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
74326 sk_rmem_alloc_get(sp),
74327 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
74328 atomic_read(&sp->sk_refcnt), sp,
74329- atomic_read(&sp->sk_drops), len);
74330+ atomic_read_unchecked(&sp->sk_drops), len);
74331 }
74332
74333 static int ping_seq_show(struct seq_file *seq, void *v)
74334diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
74335index 3ccda5a..3c1e61d 100644
74336--- a/net/ipv4/raw.c
74337+++ b/net/ipv4/raw.c
74338@@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
74339 int raw_rcv(struct sock *sk, struct sk_buff *skb)
74340 {
74341 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
74342- atomic_inc(&sk->sk_drops);
74343+ atomic_inc_unchecked(&sk->sk_drops);
74344 kfree_skb(skb);
74345 return NET_RX_DROP;
74346 }
74347@@ -742,16 +742,20 @@ static int raw_init(struct sock *sk)
74348
74349 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
74350 {
74351+ struct icmp_filter filter;
74352+
74353 if (optlen > sizeof(struct icmp_filter))
74354 optlen = sizeof(struct icmp_filter);
74355- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
74356+ if (copy_from_user(&filter, optval, optlen))
74357 return -EFAULT;
74358+ raw_sk(sk)->filter = filter;
74359 return 0;
74360 }
74361
74362 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
74363 {
74364 int len, ret = -EFAULT;
74365+ struct icmp_filter filter;
74366
74367 if (get_user(len, optlen))
74368 goto out;
74369@@ -761,8 +765,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
74370 if (len > sizeof(struct icmp_filter))
74371 len = sizeof(struct icmp_filter);
74372 ret = -EFAULT;
74373- if (put_user(len, optlen) ||
74374- copy_to_user(optval, &raw_sk(sk)->filter, len))
74375+ filter = raw_sk(sk)->filter;
74376+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
74377 goto out;
74378 ret = 0;
74379 out: return ret;
74380@@ -990,7 +994,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
74381 sk_wmem_alloc_get(sp),
74382 sk_rmem_alloc_get(sp),
74383 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
74384- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
74385+ atomic_read(&sp->sk_refcnt),
74386+#ifdef CONFIG_GRKERNSEC_HIDESYM
74387+ NULL,
74388+#else
74389+ sp,
74390+#endif
74391+ atomic_read_unchecked(&sp->sk_drops));
74392 }
74393
74394 static int raw_seq_show(struct seq_file *seq, void *v)
74395diff --git a/net/ipv4/route.c b/net/ipv4/route.c
74396index 0197747..7adb0dc 100644
74397--- a/net/ipv4/route.c
74398+++ b/net/ipv4/route.c
74399@@ -311,7 +311,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
74400
74401 static inline int rt_genid(struct net *net)
74402 {
74403- return atomic_read(&net->ipv4.rt_genid);
74404+ return atomic_read_unchecked(&net->ipv4.rt_genid);
74405 }
74406
74407 #ifdef CONFIG_PROC_FS
74408@@ -935,7 +935,7 @@ static void rt_cache_invalidate(struct net *net)
74409 unsigned char shuffle;
74410
74411 get_random_bytes(&shuffle, sizeof(shuffle));
74412- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
74413+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
74414 inetpeer_invalidate_tree(AF_INET);
74415 }
74416
74417@@ -3010,7 +3010,7 @@ static int rt_fill_info(struct net *net,
74418 error = rt->dst.error;
74419 if (peer) {
74420 inet_peer_refcheck(rt->peer);
74421- id = atomic_read(&peer->ip_id_count) & 0xffff;
74422+ id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
74423 if (peer->tcp_ts_stamp) {
74424 ts = peer->tcp_ts;
74425 tsage = get_seconds() - peer->tcp_ts_stamp;
74426diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
74427index fd54c5f..96d6407 100644
74428--- a/net/ipv4/tcp_ipv4.c
74429+++ b/net/ipv4/tcp_ipv4.c
74430@@ -88,6 +88,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
74431 int sysctl_tcp_low_latency __read_mostly;
74432 EXPORT_SYMBOL(sysctl_tcp_low_latency);
74433
74434+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74435+extern int grsec_enable_blackhole;
74436+#endif
74437
74438 #ifdef CONFIG_TCP_MD5SIG
74439 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
74440@@ -1638,6 +1641,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
74441 return 0;
74442
74443 reset:
74444+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74445+ if (!grsec_enable_blackhole)
74446+#endif
74447 tcp_v4_send_reset(rsk, skb);
74448 discard:
74449 kfree_skb(skb);
74450@@ -1700,12 +1706,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
74451 TCP_SKB_CB(skb)->sacked = 0;
74452
74453 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
74454- if (!sk)
74455+ if (!sk) {
74456+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74457+ ret = 1;
74458+#endif
74459 goto no_tcp_socket;
74460-
74461+ }
74462 process:
74463- if (sk->sk_state == TCP_TIME_WAIT)
74464+ if (sk->sk_state == TCP_TIME_WAIT) {
74465+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74466+ ret = 2;
74467+#endif
74468 goto do_time_wait;
74469+ }
74470
74471 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
74472 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
74473@@ -1755,6 +1768,10 @@ no_tcp_socket:
74474 bad_packet:
74475 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
74476 } else {
74477+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74478+ if (!grsec_enable_blackhole || (ret == 1 &&
74479+ (skb->dev->flags & IFF_LOOPBACK)))
74480+#endif
74481 tcp_v4_send_reset(NULL, skb);
74482 }
74483
74484@@ -2417,7 +2434,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
74485 0, /* non standard timer */
74486 0, /* open_requests have no inode */
74487 atomic_read(&sk->sk_refcnt),
74488+#ifdef CONFIG_GRKERNSEC_HIDESYM
74489+ NULL,
74490+#else
74491 req,
74492+#endif
74493 len);
74494 }
74495
74496@@ -2467,7 +2488,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
74497 sock_i_uid(sk),
74498 icsk->icsk_probes_out,
74499 sock_i_ino(sk),
74500- atomic_read(&sk->sk_refcnt), sk,
74501+ atomic_read(&sk->sk_refcnt),
74502+#ifdef CONFIG_GRKERNSEC_HIDESYM
74503+ NULL,
74504+#else
74505+ sk,
74506+#endif
74507 jiffies_to_clock_t(icsk->icsk_rto),
74508 jiffies_to_clock_t(icsk->icsk_ack.ato),
74509 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
74510@@ -2495,7 +2521,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
74511 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
74512 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
74513 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
74514- atomic_read(&tw->tw_refcnt), tw, len);
74515+ atomic_read(&tw->tw_refcnt),
74516+#ifdef CONFIG_GRKERNSEC_HIDESYM
74517+ NULL,
74518+#else
74519+ tw,
74520+#endif
74521+ len);
74522 }
74523
74524 #define TMPSZ 150
74525diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
74526index 550e755..25721b3 100644
74527--- a/net/ipv4/tcp_minisocks.c
74528+++ b/net/ipv4/tcp_minisocks.c
74529@@ -27,6 +27,10 @@
74530 #include <net/inet_common.h>
74531 #include <net/xfrm.h>
74532
74533+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74534+extern int grsec_enable_blackhole;
74535+#endif
74536+
74537 int sysctl_tcp_syncookies __read_mostly = 1;
74538 EXPORT_SYMBOL(sysctl_tcp_syncookies);
74539
74540@@ -753,6 +757,10 @@ listen_overflow:
74541
74542 embryonic_reset:
74543 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
74544+
74545+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74546+ if (!grsec_enable_blackhole)
74547+#endif
74548 if (!(flg & TCP_FLAG_RST))
74549 req->rsk_ops->send_reset(sk, skb);
74550
74551diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
74552index 85ee7eb..53277ab 100644
74553--- a/net/ipv4/tcp_probe.c
74554+++ b/net/ipv4/tcp_probe.c
74555@@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
74556 if (cnt + width >= len)
74557 break;
74558
74559- if (copy_to_user(buf + cnt, tbuf, width))
74560+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
74561 return -EFAULT;
74562 cnt += width;
74563 }
74564diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
74565index cd2e072..1fffee2 100644
74566--- a/net/ipv4/tcp_timer.c
74567+++ b/net/ipv4/tcp_timer.c
74568@@ -22,6 +22,10 @@
74569 #include <linux/gfp.h>
74570 #include <net/tcp.h>
74571
74572+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74573+extern int grsec_lastack_retries;
74574+#endif
74575+
74576 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
74577 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
74578 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
74579@@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
74580 }
74581 }
74582
74583+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74584+ if ((sk->sk_state == TCP_LAST_ACK) &&
74585+ (grsec_lastack_retries > 0) &&
74586+ (grsec_lastack_retries < retry_until))
74587+ retry_until = grsec_lastack_retries;
74588+#endif
74589+
74590 if (retransmits_timed_out(sk, retry_until,
74591 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
74592 /* Has it gone just too far? */
74593diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
74594index 5d075b5..d907d5f 100644
74595--- a/net/ipv4/udp.c
74596+++ b/net/ipv4/udp.c
74597@@ -86,6 +86,7 @@
74598 #include <linux/types.h>
74599 #include <linux/fcntl.h>
74600 #include <linux/module.h>
74601+#include <linux/security.h>
74602 #include <linux/socket.h>
74603 #include <linux/sockios.h>
74604 #include <linux/igmp.h>
74605@@ -108,6 +109,10 @@
74606 #include <trace/events/udp.h>
74607 #include "udp_impl.h"
74608
74609+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74610+extern int grsec_enable_blackhole;
74611+#endif
74612+
74613 struct udp_table udp_table __read_mostly;
74614 EXPORT_SYMBOL(udp_table);
74615
74616@@ -566,6 +571,9 @@ found:
74617 return s;
74618 }
74619
74620+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
74621+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
74622+
74623 /*
74624 * This routine is called by the ICMP module when it gets some
74625 * sort of error condition. If err < 0 then the socket should
74626@@ -857,9 +865,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
74627 dport = usin->sin_port;
74628 if (dport == 0)
74629 return -EINVAL;
74630+
74631+ err = gr_search_udp_sendmsg(sk, usin);
74632+ if (err)
74633+ return err;
74634 } else {
74635 if (sk->sk_state != TCP_ESTABLISHED)
74636 return -EDESTADDRREQ;
74637+
74638+ err = gr_search_udp_sendmsg(sk, NULL);
74639+ if (err)
74640+ return err;
74641+
74642 daddr = inet->inet_daddr;
74643 dport = inet->inet_dport;
74644 /* Open fast path for connected socket.
74645@@ -1100,7 +1117,7 @@ static unsigned int first_packet_length(struct sock *sk)
74646 udp_lib_checksum_complete(skb)) {
74647 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
74648 IS_UDPLITE(sk));
74649- atomic_inc(&sk->sk_drops);
74650+ atomic_inc_unchecked(&sk->sk_drops);
74651 __skb_unlink(skb, rcvq);
74652 __skb_queue_tail(&list_kill, skb);
74653 }
74654@@ -1186,6 +1203,10 @@ try_again:
74655 if (!skb)
74656 goto out;
74657
74658+ err = gr_search_udp_recvmsg(sk, skb);
74659+ if (err)
74660+ goto out_free;
74661+
74662 ulen = skb->len - sizeof(struct udphdr);
74663 copied = len;
74664 if (copied > ulen)
74665@@ -1489,7 +1510,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74666
74667 drop:
74668 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
74669- atomic_inc(&sk->sk_drops);
74670+ atomic_inc_unchecked(&sk->sk_drops);
74671 kfree_skb(skb);
74672 return -1;
74673 }
74674@@ -1508,7 +1529,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
74675 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
74676
74677 if (!skb1) {
74678- atomic_inc(&sk->sk_drops);
74679+ atomic_inc_unchecked(&sk->sk_drops);
74680 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
74681 IS_UDPLITE(sk));
74682 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
74683@@ -1677,6 +1698,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
74684 goto csum_error;
74685
74686 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
74687+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74688+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
74689+#endif
74690 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
74691
74692 /*
74693@@ -2100,8 +2124,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
74694 sk_wmem_alloc_get(sp),
74695 sk_rmem_alloc_get(sp),
74696 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
74697- atomic_read(&sp->sk_refcnt), sp,
74698- atomic_read(&sp->sk_drops), len);
74699+ atomic_read(&sp->sk_refcnt),
74700+#ifdef CONFIG_GRKERNSEC_HIDESYM
74701+ NULL,
74702+#else
74703+ sp,
74704+#endif
74705+ atomic_read_unchecked(&sp->sk_drops), len);
74706 }
74707
74708 int udp4_seq_show(struct seq_file *seq, void *v)
74709diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
74710index 6b8ebc5..1d624f4 100644
74711--- a/net/ipv6/addrconf.c
74712+++ b/net/ipv6/addrconf.c
74713@@ -2145,7 +2145,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
74714 p.iph.ihl = 5;
74715 p.iph.protocol = IPPROTO_IPV6;
74716 p.iph.ttl = 64;
74717- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
74718+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
74719
74720 if (ops->ndo_do_ioctl) {
74721 mm_segment_t oldfs = get_fs();
74722diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
74723index 02dd203..e03fcc9 100644
74724--- a/net/ipv6/inet6_connection_sock.c
74725+++ b/net/ipv6/inet6_connection_sock.c
74726@@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
74727 #ifdef CONFIG_XFRM
74728 {
74729 struct rt6_info *rt = (struct rt6_info *)dst;
74730- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
74731+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
74732 }
74733 #endif
74734 }
74735@@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
74736 #ifdef CONFIG_XFRM
74737 if (dst) {
74738 struct rt6_info *rt = (struct rt6_info *)dst;
74739- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
74740+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
74741 __sk_dst_reset(sk);
74742 dst = NULL;
74743 }
74744diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
74745index 18a2719..779f36a 100644
74746--- a/net/ipv6/ipv6_sockglue.c
74747+++ b/net/ipv6/ipv6_sockglue.c
74748@@ -960,7 +960,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
74749 if (sk->sk_type != SOCK_STREAM)
74750 return -ENOPROTOOPT;
74751
74752- msg.msg_control = optval;
74753+ msg.msg_control = (void __force_kernel *)optval;
74754 msg.msg_controllen = len;
74755 msg.msg_flags = flags;
74756
74757diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
74758index d02f7e4..2d2a0f1 100644
74759--- a/net/ipv6/raw.c
74760+++ b/net/ipv6/raw.c
74761@@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
74762 {
74763 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
74764 skb_checksum_complete(skb)) {
74765- atomic_inc(&sk->sk_drops);
74766+ atomic_inc_unchecked(&sk->sk_drops);
74767 kfree_skb(skb);
74768 return NET_RX_DROP;
74769 }
74770@@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
74771 struct raw6_sock *rp = raw6_sk(sk);
74772
74773 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
74774- atomic_inc(&sk->sk_drops);
74775+ atomic_inc_unchecked(&sk->sk_drops);
74776 kfree_skb(skb);
74777 return NET_RX_DROP;
74778 }
74779@@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
74780
74781 if (inet->hdrincl) {
74782 if (skb_checksum_complete(skb)) {
74783- atomic_inc(&sk->sk_drops);
74784+ atomic_inc_unchecked(&sk->sk_drops);
74785 kfree_skb(skb);
74786 return NET_RX_DROP;
74787 }
74788@@ -602,7 +602,7 @@ out:
74789 return err;
74790 }
74791
74792-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
74793+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
74794 struct flowi6 *fl6, struct dst_entry **dstp,
74795 unsigned int flags)
74796 {
74797@@ -912,12 +912,15 @@ do_confirm:
74798 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
74799 char __user *optval, int optlen)
74800 {
74801+ struct icmp6_filter filter;
74802+
74803 switch (optname) {
74804 case ICMPV6_FILTER:
74805 if (optlen > sizeof(struct icmp6_filter))
74806 optlen = sizeof(struct icmp6_filter);
74807- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
74808+ if (copy_from_user(&filter, optval, optlen))
74809 return -EFAULT;
74810+ raw6_sk(sk)->filter = filter;
74811 return 0;
74812 default:
74813 return -ENOPROTOOPT;
74814@@ -930,6 +933,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
74815 char __user *optval, int __user *optlen)
74816 {
74817 int len;
74818+ struct icmp6_filter filter;
74819
74820 switch (optname) {
74821 case ICMPV6_FILTER:
74822@@ -941,7 +945,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
74823 len = sizeof(struct icmp6_filter);
74824 if (put_user(len, optlen))
74825 return -EFAULT;
74826- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
74827+ filter = raw6_sk(sk)->filter;
74828+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
74829 return -EFAULT;
74830 return 0;
74831 default:
74832@@ -1248,7 +1253,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
74833 0, 0L, 0,
74834 sock_i_uid(sp), 0,
74835 sock_i_ino(sp),
74836- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
74837+ atomic_read(&sp->sk_refcnt),
74838+#ifdef CONFIG_GRKERNSEC_HIDESYM
74839+ NULL,
74840+#else
74841+ sp,
74842+#endif
74843+ atomic_read_unchecked(&sp->sk_drops));
74844 }
74845
74846 static int raw6_seq_show(struct seq_file *seq, void *v)
74847diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
74848index 3edd05a..63aad01 100644
74849--- a/net/ipv6/tcp_ipv6.c
74850+++ b/net/ipv6/tcp_ipv6.c
74851@@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
74852 }
74853 #endif
74854
74855+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74856+extern int grsec_enable_blackhole;
74857+#endif
74858+
74859 static void tcp_v6_hash(struct sock *sk)
74860 {
74861 if (sk->sk_state != TCP_CLOSE) {
74862@@ -1650,6 +1654,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
74863 return 0;
74864
74865 reset:
74866+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74867+ if (!grsec_enable_blackhole)
74868+#endif
74869 tcp_v6_send_reset(sk, skb);
74870 discard:
74871 if (opt_skb)
74872@@ -1729,12 +1736,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
74873 TCP_SKB_CB(skb)->sacked = 0;
74874
74875 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
74876- if (!sk)
74877+ if (!sk) {
74878+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74879+ ret = 1;
74880+#endif
74881 goto no_tcp_socket;
74882+ }
74883
74884 process:
74885- if (sk->sk_state == TCP_TIME_WAIT)
74886+ if (sk->sk_state == TCP_TIME_WAIT) {
74887+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74888+ ret = 2;
74889+#endif
74890 goto do_time_wait;
74891+ }
74892
74893 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
74894 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
74895@@ -1782,6 +1797,10 @@ no_tcp_socket:
74896 bad_packet:
74897 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
74898 } else {
74899+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74900+ if (!grsec_enable_blackhole || (ret == 1 &&
74901+ (skb->dev->flags & IFF_LOOPBACK)))
74902+#endif
74903 tcp_v6_send_reset(NULL, skb);
74904 }
74905
74906@@ -2043,7 +2062,13 @@ static void get_openreq6(struct seq_file *seq,
74907 uid,
74908 0, /* non standard timer */
74909 0, /* open_requests have no inode */
74910- 0, req);
74911+ 0,
74912+#ifdef CONFIG_GRKERNSEC_HIDESYM
74913+ NULL
74914+#else
74915+ req
74916+#endif
74917+ );
74918 }
74919
74920 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
74921@@ -2093,7 +2118,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
74922 sock_i_uid(sp),
74923 icsk->icsk_probes_out,
74924 sock_i_ino(sp),
74925- atomic_read(&sp->sk_refcnt), sp,
74926+ atomic_read(&sp->sk_refcnt),
74927+#ifdef CONFIG_GRKERNSEC_HIDESYM
74928+ NULL,
74929+#else
74930+ sp,
74931+#endif
74932 jiffies_to_clock_t(icsk->icsk_rto),
74933 jiffies_to_clock_t(icsk->icsk_ack.ato),
74934 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
74935@@ -2128,7 +2158,13 @@ static void get_timewait6_sock(struct seq_file *seq,
74936 dest->s6_addr32[2], dest->s6_addr32[3], destp,
74937 tw->tw_substate, 0, 0,
74938 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
74939- atomic_read(&tw->tw_refcnt), tw);
74940+ atomic_read(&tw->tw_refcnt),
74941+#ifdef CONFIG_GRKERNSEC_HIDESYM
74942+ NULL
74943+#else
74944+ tw
74945+#endif
74946+ );
74947 }
74948
74949 static int tcp6_seq_show(struct seq_file *seq, void *v)
74950diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
74951index 4f96b5c..75543d7 100644
74952--- a/net/ipv6/udp.c
74953+++ b/net/ipv6/udp.c
74954@@ -50,6 +50,10 @@
74955 #include <linux/seq_file.h>
74956 #include "udp_impl.h"
74957
74958+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74959+extern int grsec_enable_blackhole;
74960+#endif
74961+
74962 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
74963 {
74964 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
74965@@ -551,7 +555,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
74966
74967 return 0;
74968 drop:
74969- atomic_inc(&sk->sk_drops);
74970+ atomic_inc_unchecked(&sk->sk_drops);
74971 drop_no_sk_drops_inc:
74972 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
74973 kfree_skb(skb);
74974@@ -627,7 +631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
74975 continue;
74976 }
74977 drop:
74978- atomic_inc(&sk->sk_drops);
74979+ atomic_inc_unchecked(&sk->sk_drops);
74980 UDP6_INC_STATS_BH(sock_net(sk),
74981 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
74982 UDP6_INC_STATS_BH(sock_net(sk),
74983@@ -782,6 +786,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
74984 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
74985 proto == IPPROTO_UDPLITE);
74986
74987+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74988+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
74989+#endif
74990 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
74991
74992 kfree_skb(skb);
74993@@ -798,7 +805,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
74994 if (!sock_owned_by_user(sk))
74995 udpv6_queue_rcv_skb(sk, skb);
74996 else if (sk_add_backlog(sk, skb)) {
74997- atomic_inc(&sk->sk_drops);
74998+ atomic_inc_unchecked(&sk->sk_drops);
74999 bh_unlock_sock(sk);
75000 sock_put(sk);
75001 goto discard;
75002@@ -1410,8 +1417,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
75003 0, 0L, 0,
75004 sock_i_uid(sp), 0,
75005 sock_i_ino(sp),
75006- atomic_read(&sp->sk_refcnt), sp,
75007- atomic_read(&sp->sk_drops));
75008+ atomic_read(&sp->sk_refcnt),
75009+#ifdef CONFIG_GRKERNSEC_HIDESYM
75010+ NULL,
75011+#else
75012+ sp,
75013+#endif
75014+ atomic_read_unchecked(&sp->sk_drops));
75015 }
75016
75017 int udp6_seq_show(struct seq_file *seq, void *v)
75018diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
75019index 253695d..9481ce8 100644
75020--- a/net/irda/ircomm/ircomm_tty.c
75021+++ b/net/irda/ircomm/ircomm_tty.c
75022@@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75023 add_wait_queue(&self->open_wait, &wait);
75024
75025 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
75026- __FILE__,__LINE__, tty->driver->name, self->open_count );
75027+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
75028
75029 /* As far as I can see, we protect open_count - Jean II */
75030 spin_lock_irqsave(&self->spinlock, flags);
75031 if (!tty_hung_up_p(filp)) {
75032 extra_count = 1;
75033- self->open_count--;
75034+ local_dec(&self->open_count);
75035 }
75036 spin_unlock_irqrestore(&self->spinlock, flags);
75037- self->blocked_open++;
75038+ local_inc(&self->blocked_open);
75039
75040 while (1) {
75041 if (tty->termios->c_cflag & CBAUD) {
75042@@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75043 }
75044
75045 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
75046- __FILE__,__LINE__, tty->driver->name, self->open_count );
75047+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
75048
75049 schedule();
75050 }
75051@@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75052 if (extra_count) {
75053 /* ++ is not atomic, so this should be protected - Jean II */
75054 spin_lock_irqsave(&self->spinlock, flags);
75055- self->open_count++;
75056+ local_inc(&self->open_count);
75057 spin_unlock_irqrestore(&self->spinlock, flags);
75058 }
75059- self->blocked_open--;
75060+ local_dec(&self->blocked_open);
75061
75062 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
75063- __FILE__,__LINE__, tty->driver->name, self->open_count);
75064+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
75065
75066 if (!retval)
75067 self->flags |= ASYNC_NORMAL_ACTIVE;
75068@@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
75069 }
75070 /* ++ is not atomic, so this should be protected - Jean II */
75071 spin_lock_irqsave(&self->spinlock, flags);
75072- self->open_count++;
75073+ local_inc(&self->open_count);
75074
75075 tty->driver_data = self;
75076 self->tty = tty;
75077 spin_unlock_irqrestore(&self->spinlock, flags);
75078
75079 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
75080- self->line, self->open_count);
75081+ self->line, local_read(&self->open_count));
75082
75083 /* Not really used by us, but lets do it anyway */
75084 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
75085@@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75086 return;
75087 }
75088
75089- if ((tty->count == 1) && (self->open_count != 1)) {
75090+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
75091 /*
75092 * Uh, oh. tty->count is 1, which means that the tty
75093 * structure will be freed. state->count should always
75094@@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75095 */
75096 IRDA_DEBUG(0, "%s(), bad serial port count; "
75097 "tty->count is 1, state->count is %d\n", __func__ ,
75098- self->open_count);
75099- self->open_count = 1;
75100+ local_read(&self->open_count));
75101+ local_set(&self->open_count, 1);
75102 }
75103
75104- if (--self->open_count < 0) {
75105+ if (local_dec_return(&self->open_count) < 0) {
75106 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
75107- __func__, self->line, self->open_count);
75108- self->open_count = 0;
75109+ __func__, self->line, local_read(&self->open_count));
75110+ local_set(&self->open_count, 0);
75111 }
75112- if (self->open_count) {
75113+ if (local_read(&self->open_count)) {
75114 spin_unlock_irqrestore(&self->spinlock, flags);
75115
75116 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
75117@@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75118 tty->closing = 0;
75119 self->tty = NULL;
75120
75121- if (self->blocked_open) {
75122+ if (local_read(&self->blocked_open)) {
75123 if (self->close_delay)
75124 schedule_timeout_interruptible(self->close_delay);
75125 wake_up_interruptible(&self->open_wait);
75126@@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
75127 spin_lock_irqsave(&self->spinlock, flags);
75128 self->flags &= ~ASYNC_NORMAL_ACTIVE;
75129 self->tty = NULL;
75130- self->open_count = 0;
75131+ local_set(&self->open_count, 0);
75132 spin_unlock_irqrestore(&self->spinlock, flags);
75133
75134 wake_up_interruptible(&self->open_wait);
75135@@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
75136 seq_putc(m, '\n');
75137
75138 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
75139- seq_printf(m, "Open count: %d\n", self->open_count);
75140+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
75141 seq_printf(m, "Max data size: %d\n", self->max_data_size);
75142 seq_printf(m, "Max header size: %d\n", self->max_header_size);
75143
75144diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
75145index d5c5b8f..33beff0 100644
75146--- a/net/iucv/af_iucv.c
75147+++ b/net/iucv/af_iucv.c
75148@@ -764,10 +764,10 @@ static int iucv_sock_autobind(struct sock *sk)
75149
75150 write_lock_bh(&iucv_sk_list.lock);
75151
75152- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
75153+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
75154 while (__iucv_get_sock_by_name(name)) {
75155 sprintf(name, "%08x",
75156- atomic_inc_return(&iucv_sk_list.autobind_name));
75157+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
75158 }
75159
75160 write_unlock_bh(&iucv_sk_list.lock);
75161diff --git a/net/key/af_key.c b/net/key/af_key.c
75162index 11dbb22..c20f667 100644
75163--- a/net/key/af_key.c
75164+++ b/net/key/af_key.c
75165@@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
75166 static u32 get_acqseq(void)
75167 {
75168 u32 res;
75169- static atomic_t acqseq;
75170+ static atomic_unchecked_t acqseq;
75171
75172 do {
75173- res = atomic_inc_return(&acqseq);
75174+ res = atomic_inc_return_unchecked(&acqseq);
75175 } while (!res);
75176 return res;
75177 }
75178diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
75179index 2f0642d..e5c6fba 100644
75180--- a/net/mac80211/ieee80211_i.h
75181+++ b/net/mac80211/ieee80211_i.h
75182@@ -28,6 +28,7 @@
75183 #include <net/ieee80211_radiotap.h>
75184 #include <net/cfg80211.h>
75185 #include <net/mac80211.h>
75186+#include <asm/local.h>
75187 #include "key.h"
75188 #include "sta_info.h"
75189
75190@@ -781,7 +782,7 @@ struct ieee80211_local {
75191 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
75192 spinlock_t queue_stop_reason_lock;
75193
75194- int open_count;
75195+ local_t open_count;
75196 int monitors, cooked_mntrs;
75197 /* number of interfaces with corresponding FIF_ flags */
75198 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
75199diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
75200index 8e2137b..2974283 100644
75201--- a/net/mac80211/iface.c
75202+++ b/net/mac80211/iface.c
75203@@ -222,7 +222,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75204 break;
75205 }
75206
75207- if (local->open_count == 0) {
75208+ if (local_read(&local->open_count) == 0) {
75209 res = drv_start(local);
75210 if (res)
75211 goto err_del_bss;
75212@@ -246,7 +246,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75213 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
75214
75215 if (!is_valid_ether_addr(dev->dev_addr)) {
75216- if (!local->open_count)
75217+ if (!local_read(&local->open_count))
75218 drv_stop(local);
75219 return -EADDRNOTAVAIL;
75220 }
75221@@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75222 mutex_unlock(&local->mtx);
75223
75224 if (coming_up)
75225- local->open_count++;
75226+ local_inc(&local->open_count);
75227
75228 if (hw_reconf_flags)
75229 ieee80211_hw_config(local, hw_reconf_flags);
75230@@ -360,7 +360,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75231 err_del_interface:
75232 drv_remove_interface(local, sdata);
75233 err_stop:
75234- if (!local->open_count)
75235+ if (!local_read(&local->open_count))
75236 drv_stop(local);
75237 err_del_bss:
75238 sdata->bss = NULL;
75239@@ -489,7 +489,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
75240 }
75241
75242 if (going_down)
75243- local->open_count--;
75244+ local_dec(&local->open_count);
75245
75246 switch (sdata->vif.type) {
75247 case NL80211_IFTYPE_AP_VLAN:
75248@@ -548,7 +548,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
75249
75250 ieee80211_recalc_ps(local, -1);
75251
75252- if (local->open_count == 0) {
75253+ if (local_read(&local->open_count) == 0) {
75254 if (local->ops->napi_poll)
75255 napi_disable(&local->napi);
75256 ieee80211_clear_tx_pending(local);
75257diff --git a/net/mac80211/main.c b/net/mac80211/main.c
75258index b142bd4..a651749 100644
75259--- a/net/mac80211/main.c
75260+++ b/net/mac80211/main.c
75261@@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
75262 local->hw.conf.power_level = power;
75263 }
75264
75265- if (changed && local->open_count) {
75266+ if (changed && local_read(&local->open_count)) {
75267 ret = drv_config(local, changed);
75268 /*
75269 * Goal:
75270diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
75271index 596efaf..8f1911f 100644
75272--- a/net/mac80211/pm.c
75273+++ b/net/mac80211/pm.c
75274@@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75275 struct ieee80211_sub_if_data *sdata;
75276 struct sta_info *sta;
75277
75278- if (!local->open_count)
75279+ if (!local_read(&local->open_count))
75280 goto suspend;
75281
75282 ieee80211_scan_cancel(local);
75283@@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75284 cancel_work_sync(&local->dynamic_ps_enable_work);
75285 del_timer_sync(&local->dynamic_ps_timer);
75286
75287- local->wowlan = wowlan && local->open_count;
75288+ local->wowlan = wowlan && local_read(&local->open_count);
75289 if (local->wowlan) {
75290 int err = drv_suspend(local, wowlan);
75291 if (err < 0) {
75292@@ -129,7 +129,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75293 }
75294
75295 /* stop hardware - this must stop RX */
75296- if (local->open_count)
75297+ if (local_read(&local->open_count))
75298 ieee80211_stop_device(local);
75299
75300 suspend:
75301diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
75302index f9b8e81..bb89b46 100644
75303--- a/net/mac80211/rate.c
75304+++ b/net/mac80211/rate.c
75305@@ -401,7 +401,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
75306
75307 ASSERT_RTNL();
75308
75309- if (local->open_count)
75310+ if (local_read(&local->open_count))
75311 return -EBUSY;
75312
75313 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
75314diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
75315index c97a065..ff61928 100644
75316--- a/net/mac80211/rc80211_pid_debugfs.c
75317+++ b/net/mac80211/rc80211_pid_debugfs.c
75318@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
75319
75320 spin_unlock_irqrestore(&events->lock, status);
75321
75322- if (copy_to_user(buf, pb, p))
75323+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
75324 return -EFAULT;
75325
75326 return p;
75327diff --git a/net/mac80211/util.c b/net/mac80211/util.c
75328index 9919892..8c49803 100644
75329--- a/net/mac80211/util.c
75330+++ b/net/mac80211/util.c
75331@@ -1143,7 +1143,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
75332 }
75333 #endif
75334 /* everything else happens only if HW was up & running */
75335- if (!local->open_count)
75336+ if (!local_read(&local->open_count))
75337 goto wake_up;
75338
75339 /*
75340diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
75341index f8ac4ef..b02560b 100644
75342--- a/net/netfilter/Kconfig
75343+++ b/net/netfilter/Kconfig
75344@@ -806,6 +806,16 @@ config NETFILTER_XT_MATCH_ESP
75345
75346 To compile it as a module, choose M here. If unsure, say N.
75347
75348+config NETFILTER_XT_MATCH_GRADM
75349+ tristate '"gradm" match support'
75350+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
75351+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
75352+ ---help---
75353+ The gradm match allows to match on grsecurity RBAC being enabled.
75354+ It is useful when iptables rules are applied early on bootup to
75355+ prevent connections to the machine (except from a trusted host)
75356+ while the RBAC system is disabled.
75357+
75358 config NETFILTER_XT_MATCH_HASHLIMIT
75359 tristate '"hashlimit" match support'
75360 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
75361diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
75362index 40f4c3d..0d5dd6b 100644
75363--- a/net/netfilter/Makefile
75364+++ b/net/netfilter/Makefile
75365@@ -83,6 +83,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
75366 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
75367 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
75368 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
75369+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
75370 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
75371 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
75372 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
75373diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
75374index 29fa5ba..8debc79 100644
75375--- a/net/netfilter/ipvs/ip_vs_conn.c
75376+++ b/net/netfilter/ipvs/ip_vs_conn.c
75377@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
75378 /* Increase the refcnt counter of the dest */
75379 atomic_inc(&dest->refcnt);
75380
75381- conn_flags = atomic_read(&dest->conn_flags);
75382+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
75383 if (cp->protocol != IPPROTO_UDP)
75384 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
75385 /* Bind with the destination and its corresponding transmitter */
75386@@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
75387 atomic_set(&cp->refcnt, 1);
75388
75389 atomic_set(&cp->n_control, 0);
75390- atomic_set(&cp->in_pkts, 0);
75391+ atomic_set_unchecked(&cp->in_pkts, 0);
75392
75393 atomic_inc(&ipvs->conn_count);
75394 if (flags & IP_VS_CONN_F_NO_CPORT)
75395@@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
75396
75397 /* Don't drop the entry if its number of incoming packets is not
75398 located in [0, 8] */
75399- i = atomic_read(&cp->in_pkts);
75400+ i = atomic_read_unchecked(&cp->in_pkts);
75401 if (i > 8 || i < 0) return 0;
75402
75403 if (!todrop_rate[i]) return 0;
75404diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
75405index 2555816..31492d9 100644
75406--- a/net/netfilter/ipvs/ip_vs_core.c
75407+++ b/net/netfilter/ipvs/ip_vs_core.c
75408@@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
75409 ret = cp->packet_xmit(skb, cp, pd->pp);
75410 /* do not touch skb anymore */
75411
75412- atomic_inc(&cp->in_pkts);
75413+ atomic_inc_unchecked(&cp->in_pkts);
75414 ip_vs_conn_put(cp);
75415 return ret;
75416 }
75417@@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
75418 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
75419 pkts = sysctl_sync_threshold(ipvs);
75420 else
75421- pkts = atomic_add_return(1, &cp->in_pkts);
75422+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
75423
75424 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
75425 cp->protocol == IPPROTO_SCTP) {
75426diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
75427index b3afe18..08ec940 100644
75428--- a/net/netfilter/ipvs/ip_vs_ctl.c
75429+++ b/net/netfilter/ipvs/ip_vs_ctl.c
75430@@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
75431 ip_vs_rs_hash(ipvs, dest);
75432 write_unlock_bh(&ipvs->rs_lock);
75433 }
75434- atomic_set(&dest->conn_flags, conn_flags);
75435+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
75436
75437 /* bind the service */
75438 if (!dest->svc) {
75439@@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
75440 " %-7s %-6d %-10d %-10d\n",
75441 &dest->addr.in6,
75442 ntohs(dest->port),
75443- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
75444+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
75445 atomic_read(&dest->weight),
75446 atomic_read(&dest->activeconns),
75447 atomic_read(&dest->inactconns));
75448@@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
75449 "%-7s %-6d %-10d %-10d\n",
75450 ntohl(dest->addr.ip),
75451 ntohs(dest->port),
75452- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
75453+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
75454 atomic_read(&dest->weight),
75455 atomic_read(&dest->activeconns),
75456 atomic_read(&dest->inactconns));
75457@@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
75458
75459 entry.addr = dest->addr.ip;
75460 entry.port = dest->port;
75461- entry.conn_flags = atomic_read(&dest->conn_flags);
75462+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
75463 entry.weight = atomic_read(&dest->weight);
75464 entry.u_threshold = dest->u_threshold;
75465 entry.l_threshold = dest->l_threshold;
75466@@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
75467 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
75468
75469 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
75470- atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
75471+ atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
75472 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
75473 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
75474 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
75475diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
75476index 8a0d6d6..90ec197 100644
75477--- a/net/netfilter/ipvs/ip_vs_sync.c
75478+++ b/net/netfilter/ipvs/ip_vs_sync.c
75479@@ -649,7 +649,7 @@ control:
75480 * i.e only increment in_pkts for Templates.
75481 */
75482 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
75483- int pkts = atomic_add_return(1, &cp->in_pkts);
75484+ int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
75485
75486 if (pkts % sysctl_sync_period(ipvs) != 1)
75487 return;
75488@@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
75489
75490 if (opt)
75491 memcpy(&cp->in_seq, opt, sizeof(*opt));
75492- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
75493+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
75494 cp->state = state;
75495 cp->old_state = cp->state;
75496 /*
75497diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
75498index 7fd66de..e6fb361 100644
75499--- a/net/netfilter/ipvs/ip_vs_xmit.c
75500+++ b/net/netfilter/ipvs/ip_vs_xmit.c
75501@@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
75502 else
75503 rc = NF_ACCEPT;
75504 /* do not touch skb anymore */
75505- atomic_inc(&cp->in_pkts);
75506+ atomic_inc_unchecked(&cp->in_pkts);
75507 goto out;
75508 }
75509
75510@@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
75511 else
75512 rc = NF_ACCEPT;
75513 /* do not touch skb anymore */
75514- atomic_inc(&cp->in_pkts);
75515+ atomic_inc_unchecked(&cp->in_pkts);
75516 goto out;
75517 }
75518
75519diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
75520index 66b2c54..c7884e3 100644
75521--- a/net/netfilter/nfnetlink_log.c
75522+++ b/net/netfilter/nfnetlink_log.c
75523@@ -70,7 +70,7 @@ struct nfulnl_instance {
75524 };
75525
75526 static DEFINE_SPINLOCK(instances_lock);
75527-static atomic_t global_seq;
75528+static atomic_unchecked_t global_seq;
75529
75530 #define INSTANCE_BUCKETS 16
75531 static struct hlist_head instance_table[INSTANCE_BUCKETS];
75532@@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
75533 /* global sequence number */
75534 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
75535 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
75536- htonl(atomic_inc_return(&global_seq)));
75537+ htonl(atomic_inc_return_unchecked(&global_seq)));
75538
75539 if (data_len) {
75540 struct nlattr *nla;
75541diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
75542new file mode 100644
75543index 0000000..6905327
75544--- /dev/null
75545+++ b/net/netfilter/xt_gradm.c
75546@@ -0,0 +1,51 @@
75547+/*
75548+ * gradm match for netfilter
75549