]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9-3.3.7-201206031033.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9-3.3.7-201206031033.patch
CommitLineData
8327ab99
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index 0c083c5..bf13011 100644
3--- a/Documentation/dontdiff
4+++ b/Documentation/dontdiff
5@@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9+*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13+*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17@@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21+*.gmo
22 *.grep
23 *.grp
24 *.gz
25@@ -48,9 +51,11 @@
26 *.tab.h
27 *.tex
28 *.ver
29+*.vim
30 *.xml
31 *.xz
32 *_MODULES
33+*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37@@ -69,6 +74,7 @@ Image
38 Module.markers
39 Module.symvers
40 PENDING
41+PERF*
42 SCCS
43 System.map*
44 TAGS
45@@ -92,19 +98,24 @@ bounds.h
46 bsetup
47 btfixupprep
48 build
49+builtin-policy.h
50 bvmlinux
51 bzImage*
52 capability_names.h
53 capflags.c
54 classlist.h*
55+clut_vga16.c
56+common-cmds.h
57 comp*.log
58 compile.h*
59 conf
60 config
61 config-*
62 config_data.h*
63+config.c
64 config.mak
65 config.mak.autogen
66+config.tmp
67 conmakehash
68 consolemap_deftbl.c*
69 cpustr.h
70@@ -115,9 +126,11 @@ devlist.h*
71 dnotify_test
72 docproc
73 dslm
74+dtc-lexer.lex.c
75 elf2ecoff
76 elfconfig.h*
77 evergreen_reg_safe.h
78+exception_policy.conf
79 fixdep
80 flask.h
81 fore200e_mkfirm
82@@ -125,12 +138,15 @@ fore200e_pca_fw.c*
83 gconf
84 gconf.glade.h
85 gen-devlist
86+gen-kdb_cmds.c
87 gen_crc32table
88 gen_init_cpio
89 generated
90 genheaders
91 genksyms
92 *_gray256.c
93+hash
94+hid-example
95 hpet_example
96 hugepage-mmap
97 hugepage-shm
98@@ -145,7 +161,7 @@ int32.c
99 int4.c
100 int8.c
101 kallsyms
102-kconfig
103+kern_constants.h
104 keywords.c
105 ksym.c*
106 ksym.h*
107@@ -153,7 +169,7 @@ kxgettext
108 lkc_defs.h
109 lex.c
110 lex.*.c
111-linux
112+lib1funcs.S
113 logo_*.c
114 logo_*_clut224.c
115 logo_*_mono.c
116@@ -165,14 +181,15 @@ machtypes.h
117 map
118 map_hugetlb
119 maui_boot.h
120-media
121 mconf
122+mdp
123 miboot*
124 mk_elfconfig
125 mkboot
126 mkbugboot
127 mkcpustr
128 mkdep
129+mkpiggy
130 mkprep
131 mkregtable
132 mktables
133@@ -208,6 +225,7 @@ r300_reg_safe.h
134 r420_reg_safe.h
135 r600_reg_safe.h
136 recordmcount
137+regdb.c
138 relocs
139 rlim_names.h
140 rn50_reg_safe.h
141@@ -218,6 +236,7 @@ setup
142 setup.bin
143 setup.elf
144 sImage
145+slabinfo
146 sm_tbl*
147 split-include
148 syscalltab.h
149@@ -228,6 +247,7 @@ tftpboot.img
150 timeconst.h
151 times.h*
152 trix_boot.h
153+user_constants.h
154 utsrelease.h*
155 vdso-syms.lds
156 vdso.lds
157@@ -245,7 +265,9 @@ vmlinux
158 vmlinux-*
159 vmlinux.aout
160 vmlinux.bin.all
161+vmlinux.bin.bz2
162 vmlinux.lds
163+vmlinux.relocs
164 vmlinuz
165 voffset.h
166 vsyscall.lds
167@@ -253,9 +275,11 @@ vsyscall_32.lds
168 wanxlfw.inc
169 uImage
170 unifdef
171+utsrelease.h
172 wakeup.bin
173 wakeup.elf
174 wakeup.lds
175 zImage*
176 zconf.hash.c
177+zconf.lex.c
178 zoffset.h
179diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
180index d99fd9c..8689fef 100644
181--- a/Documentation/kernel-parameters.txt
182+++ b/Documentation/kernel-parameters.txt
183@@ -1977,6 +1977,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
184 the specified number of seconds. This is to be used if
185 your oopses keep scrolling off the screen.
186
187+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
188+ virtualization environments that don't cope well with the
189+ expand down segment used by UDEREF on X86-32 or the frequent
190+ page table updates on X86-64.
191+
192+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
193+
194 pcbit= [HW,ISDN]
195
196 pcd. [PARIDE]
197diff --git a/Makefile b/Makefile
198index 073f74f..02aebe9 100644
199--- a/Makefile
200+++ b/Makefile
201@@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
202
203 HOSTCC = gcc
204 HOSTCXX = g++
205-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
206-HOSTCXXFLAGS = -O2
207+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
208+HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
209+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
210
211 # Decide whether to build built-in, modular, or both.
212 # Normally, just do built-in.
213@@ -407,8 +408,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exc
214 # Rules shared between *config targets and build targets
215
216 # Basic helpers built in scripts/
217-PHONY += scripts_basic
218-scripts_basic:
219+PHONY += scripts_basic gcc-plugins
220+scripts_basic: gcc-plugins
221 $(Q)$(MAKE) $(build)=scripts/basic
222 $(Q)rm -f .tmp_quiet_recordmcount
223
224@@ -564,6 +565,55 @@ else
225 KBUILD_CFLAGS += -O2
226 endif
227
228+ifndef DISABLE_PAX_PLUGINS
229+ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(CC)"), y)
230+ifndef DISABLE_PAX_CONSTIFY_PLUGIN
231+ifndef CONFIG_UML
232+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
233+endif
234+endif
235+ifdef CONFIG_PAX_MEMORY_STACKLEAK
236+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
237+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
238+endif
239+ifdef CONFIG_KALLOCSTAT_PLUGIN
240+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
241+endif
242+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
243+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
244+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
245+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
246+endif
247+ifdef CONFIG_CHECKER_PLUGIN
248+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
249+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
250+endif
251+endif
252+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
253+ifdef CONFIG_PAX_SIZE_OVERFLOW
254+SIZE_OVERFLOW_PLUGIN := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
255+endif
256+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
257+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS) $(SIZE_OVERFLOW_PLUGIN)
258+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
259+export CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN SIZE_OVERFLOW_PLUGIN
260+ifeq ($(KBUILD_EXTMOD),)
261+gcc-plugins:
262+ $(Q)$(MAKE) $(build)=tools/gcc
263+else
264+gcc-plugins: ;
265+endif
266+else
267+gcc-plugins:
268+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
269+ $(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.))
270+else
271+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
272+endif
273+ $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
274+endif
275+endif
276+
277 include $(srctree)/arch/$(SRCARCH)/Makefile
278
279 ifneq ($(CONFIG_FRAME_WARN),0)
280@@ -708,7 +758,7 @@ export mod_strip_cmd
281
282
283 ifeq ($(KBUILD_EXTMOD),)
284-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
285+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
286
287 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
288 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
289@@ -932,6 +982,8 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
290
291 # The actual objects are generated when descending,
292 # make sure no implicit rule kicks in
293+$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
294+$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
295 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
296
297 # Handle descending into subdirectories listed in $(vmlinux-dirs)
298@@ -941,7 +993,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
299 # Error messages still appears in the original language
300
301 PHONY += $(vmlinux-dirs)
302-$(vmlinux-dirs): prepare scripts
303+$(vmlinux-dirs): gcc-plugins prepare scripts
304 $(Q)$(MAKE) $(build)=$@
305
306 # Store (new) KERNELRELASE string in include/config/kernel.release
307@@ -985,6 +1037,7 @@ prepare0: archprepare FORCE
308 $(Q)$(MAKE) $(build)=.
309
310 # All the preparing..
311+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
312 prepare: prepare0
313
314 # Generate some files
315@@ -1089,6 +1142,8 @@ all: modules
316 # using awk while concatenating to the final file.
317
318 PHONY += modules
319+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
320+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
321 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
322 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
323 @$(kecho) ' Building modules, stage 2.';
324@@ -1104,7 +1159,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
325
326 # Target to prepare building external modules
327 PHONY += modules_prepare
328-modules_prepare: prepare scripts
329+modules_prepare: gcc-plugins prepare scripts
330
331 # Target to install modules
332 PHONY += modules_install
333@@ -1201,6 +1256,7 @@ distclean: mrproper
334 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
335 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
336 -o -name '.*.rej' \
337+ -o -name '.*.rej' -o -name '*.so' \
338 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
339 -type f -print | xargs rm -f
340
341@@ -1361,6 +1417,8 @@ PHONY += $(module-dirs) modules
342 $(module-dirs): crmodverdir $(objtree)/Module.symvers
343 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
344
345+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
346+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
347 modules: $(module-dirs)
348 @$(kecho) ' Building modules, stage 2.';
349 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
350@@ -1487,17 +1545,21 @@ else
351 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
352 endif
353
354-%.s: %.c prepare scripts FORCE
355+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
356+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
357+%.s: %.c gcc-plugins prepare scripts FORCE
358 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
359 %.i: %.c prepare scripts FORCE
360 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
361-%.o: %.c prepare scripts FORCE
362+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
363+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
364+%.o: %.c gcc-plugins prepare scripts FORCE
365 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
366 %.lst: %.c prepare scripts FORCE
367 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
368-%.s: %.S prepare scripts FORCE
369+%.s: %.S gcc-plugins prepare scripts FORCE
370 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
371-%.o: %.S prepare scripts FORCE
372+%.o: %.S gcc-plugins prepare scripts FORCE
373 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
374 %.symtypes: %.c prepare scripts FORCE
375 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
376@@ -1507,11 +1569,15 @@ endif
377 $(cmd_crmodverdir)
378 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
379 $(build)=$(build-dir)
380-%/: prepare scripts FORCE
381+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
382+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
383+%/: gcc-plugins prepare scripts FORCE
384 $(cmd_crmodverdir)
385 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
386 $(build)=$(build-dir)
387-%.ko: prepare scripts FORCE
388+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
389+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
390+%.ko: gcc-plugins prepare scripts FORCE
391 $(cmd_crmodverdir)
392 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
393 $(build)=$(build-dir) $(@:.ko=.o)
394diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
395index 640f909..48b6597 100644
396--- a/arch/alpha/include/asm/atomic.h
397+++ b/arch/alpha/include/asm/atomic.h
398@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
399 #define atomic_dec(v) atomic_sub(1,(v))
400 #define atomic64_dec(v) atomic64_sub(1,(v))
401
402+#define atomic64_read_unchecked(v) atomic64_read(v)
403+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
404+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
405+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
406+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
407+#define atomic64_inc_unchecked(v) atomic64_inc(v)
408+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
409+#define atomic64_dec_unchecked(v) atomic64_dec(v)
410+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
411+
412 #define smp_mb__before_atomic_dec() smp_mb()
413 #define smp_mb__after_atomic_dec() smp_mb()
414 #define smp_mb__before_atomic_inc() smp_mb()
415diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
416index ad368a9..fbe0f25 100644
417--- a/arch/alpha/include/asm/cache.h
418+++ b/arch/alpha/include/asm/cache.h
419@@ -4,19 +4,19 @@
420 #ifndef __ARCH_ALPHA_CACHE_H
421 #define __ARCH_ALPHA_CACHE_H
422
423+#include <linux/const.h>
424
425 /* Bytes per L1 (data) cache line. */
426 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
427-# define L1_CACHE_BYTES 64
428 # define L1_CACHE_SHIFT 6
429 #else
430 /* Both EV4 and EV5 are write-through, read-allocate,
431 direct-mapped, physical.
432 */
433-# define L1_CACHE_BYTES 32
434 # define L1_CACHE_SHIFT 5
435 #endif
436
437+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
438 #define SMP_CACHE_BYTES L1_CACHE_BYTES
439
440 #endif
441diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
442index da5449e..7418343 100644
443--- a/arch/alpha/include/asm/elf.h
444+++ b/arch/alpha/include/asm/elf.h
445@@ -90,6 +90,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
446
447 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
448
449+#ifdef CONFIG_PAX_ASLR
450+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
451+
452+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
453+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
454+#endif
455+
456 /* $0 is set by ld.so to a pointer to a function which might be
457 registered using atexit. This provides a mean for the dynamic
458 linker to call DT_FINI functions for shared libraries that have
459diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
460index bc2a0da..8ad11ee 100644
461--- a/arch/alpha/include/asm/pgalloc.h
462+++ b/arch/alpha/include/asm/pgalloc.h
463@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
464 pgd_set(pgd, pmd);
465 }
466
467+static inline void
468+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
469+{
470+ pgd_populate(mm, pgd, pmd);
471+}
472+
473 extern pgd_t *pgd_alloc(struct mm_struct *mm);
474
475 static inline void
476diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
477index de98a73..bd4f1f8 100644
478--- a/arch/alpha/include/asm/pgtable.h
479+++ b/arch/alpha/include/asm/pgtable.h
480@@ -101,6 +101,17 @@ struct vm_area_struct;
481 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
482 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
483 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
484+
485+#ifdef CONFIG_PAX_PAGEEXEC
486+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
487+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
488+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
489+#else
490+# define PAGE_SHARED_NOEXEC PAGE_SHARED
491+# define PAGE_COPY_NOEXEC PAGE_COPY
492+# define PAGE_READONLY_NOEXEC PAGE_READONLY
493+#endif
494+
495 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
496
497 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
498diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
499index 2fd00b7..cfd5069 100644
500--- a/arch/alpha/kernel/module.c
501+++ b/arch/alpha/kernel/module.c
502@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
503
504 /* The small sections were sorted to the end of the segment.
505 The following should definitely cover them. */
506- gp = (u64)me->module_core + me->core_size - 0x8000;
507+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
508 got = sechdrs[me->arch.gotsecindex].sh_addr;
509
510 for (i = 0; i < n; i++) {
511diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
512index 01e8715..be0e80f 100644
513--- a/arch/alpha/kernel/osf_sys.c
514+++ b/arch/alpha/kernel/osf_sys.c
515@@ -1147,7 +1147,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
516 /* At this point: (!vma || addr < vma->vm_end). */
517 if (limit - len < addr)
518 return -ENOMEM;
519- if (!vma || addr + len <= vma->vm_start)
520+ if (check_heap_stack_gap(vma, addr, len))
521 return addr;
522 addr = vma->vm_end;
523 vma = vma->vm_next;
524@@ -1183,6 +1183,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
525 merely specific addresses, but regions of memory -- perhaps
526 this feature should be incorporated into all ports? */
527
528+#ifdef CONFIG_PAX_RANDMMAP
529+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
530+#endif
531+
532 if (addr) {
533 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
534 if (addr != (unsigned long) -ENOMEM)
535@@ -1190,8 +1194,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
536 }
537
538 /* Next, try allocating at TASK_UNMAPPED_BASE. */
539- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
540- len, limit);
541+ addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
542+
543 if (addr != (unsigned long) -ENOMEM)
544 return addr;
545
546diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
547index fadd5f8..904e73a 100644
548--- a/arch/alpha/mm/fault.c
549+++ b/arch/alpha/mm/fault.c
550@@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
551 __reload_thread(pcb);
552 }
553
554+#ifdef CONFIG_PAX_PAGEEXEC
555+/*
556+ * PaX: decide what to do with offenders (regs->pc = fault address)
557+ *
558+ * returns 1 when task should be killed
559+ * 2 when patched PLT trampoline was detected
560+ * 3 when unpatched PLT trampoline was detected
561+ */
562+static int pax_handle_fetch_fault(struct pt_regs *regs)
563+{
564+
565+#ifdef CONFIG_PAX_EMUPLT
566+ int err;
567+
568+ do { /* PaX: patched PLT emulation #1 */
569+ unsigned int ldah, ldq, jmp;
570+
571+ err = get_user(ldah, (unsigned int *)regs->pc);
572+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
573+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
574+
575+ if (err)
576+ break;
577+
578+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
579+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
580+ jmp == 0x6BFB0000U)
581+ {
582+ unsigned long r27, addr;
583+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
584+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
585+
586+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
587+ err = get_user(r27, (unsigned long *)addr);
588+ if (err)
589+ break;
590+
591+ regs->r27 = r27;
592+ regs->pc = r27;
593+ return 2;
594+ }
595+ } while (0);
596+
597+ do { /* PaX: patched PLT emulation #2 */
598+ unsigned int ldah, lda, br;
599+
600+ err = get_user(ldah, (unsigned int *)regs->pc);
601+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
602+ err |= get_user(br, (unsigned int *)(regs->pc+8));
603+
604+ if (err)
605+ break;
606+
607+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
608+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
609+ (br & 0xFFE00000U) == 0xC3E00000U)
610+ {
611+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
612+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
613+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
614+
615+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
616+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
617+ return 2;
618+ }
619+ } while (0);
620+
621+ do { /* PaX: unpatched PLT emulation */
622+ unsigned int br;
623+
624+ err = get_user(br, (unsigned int *)regs->pc);
625+
626+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
627+ unsigned int br2, ldq, nop, jmp;
628+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
629+
630+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
631+ err = get_user(br2, (unsigned int *)addr);
632+ err |= get_user(ldq, (unsigned int *)(addr+4));
633+ err |= get_user(nop, (unsigned int *)(addr+8));
634+ err |= get_user(jmp, (unsigned int *)(addr+12));
635+ err |= get_user(resolver, (unsigned long *)(addr+16));
636+
637+ if (err)
638+ break;
639+
640+ if (br2 == 0xC3600000U &&
641+ ldq == 0xA77B000CU &&
642+ nop == 0x47FF041FU &&
643+ jmp == 0x6B7B0000U)
644+ {
645+ regs->r28 = regs->pc+4;
646+ regs->r27 = addr+16;
647+ regs->pc = resolver;
648+ return 3;
649+ }
650+ }
651+ } while (0);
652+#endif
653+
654+ return 1;
655+}
656+
657+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
658+{
659+ unsigned long i;
660+
661+ printk(KERN_ERR "PAX: bytes at PC: ");
662+ for (i = 0; i < 5; i++) {
663+ unsigned int c;
664+ if (get_user(c, (unsigned int *)pc+i))
665+ printk(KERN_CONT "???????? ");
666+ else
667+ printk(KERN_CONT "%08x ", c);
668+ }
669+ printk("\n");
670+}
671+#endif
672
673 /*
674 * This routine handles page faults. It determines the address,
675@@ -131,8 +249,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
676 good_area:
677 si_code = SEGV_ACCERR;
678 if (cause < 0) {
679- if (!(vma->vm_flags & VM_EXEC))
680+ if (!(vma->vm_flags & VM_EXEC)) {
681+
682+#ifdef CONFIG_PAX_PAGEEXEC
683+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
684+ goto bad_area;
685+
686+ up_read(&mm->mmap_sem);
687+ switch (pax_handle_fetch_fault(regs)) {
688+
689+#ifdef CONFIG_PAX_EMUPLT
690+ case 2:
691+ case 3:
692+ return;
693+#endif
694+
695+ }
696+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
697+ do_group_exit(SIGKILL);
698+#else
699 goto bad_area;
700+#endif
701+
702+ }
703 } else if (!cause) {
704 /* Allow reads even for write-only mappings */
705 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
706diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
707index 86976d0..c63ea6b 100644
708--- a/arch/arm/include/asm/atomic.h
709+++ b/arch/arm/include/asm/atomic.h
710@@ -15,6 +15,10 @@
711 #include <linux/types.h>
712 #include <asm/system.h>
713
714+#ifdef CONFIG_GENERIC_ATOMIC64
715+#include <asm-generic/atomic64.h>
716+#endif
717+
718 #define ATOMIC_INIT(i) { (i) }
719
720 #ifdef __KERNEL__
721@@ -25,7 +29,15 @@
722 * atomic_set() is the clrex or dummy strex done on every exception return.
723 */
724 #define atomic_read(v) (*(volatile int *)&(v)->counter)
725+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
726+{
727+ return v->counter;
728+}
729 #define atomic_set(v,i) (((v)->counter) = (i))
730+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
731+{
732+ v->counter = i;
733+}
734
735 #if __LINUX_ARM_ARCH__ >= 6
736
737@@ -40,6 +52,35 @@ static inline void atomic_add(int i, atomic_t *v)
738 int result;
739
740 __asm__ __volatile__("@ atomic_add\n"
741+"1: ldrex %1, [%3]\n"
742+" adds %0, %1, %4\n"
743+
744+#ifdef CONFIG_PAX_REFCOUNT
745+" bvc 3f\n"
746+"2: bkpt 0xf103\n"
747+"3:\n"
748+#endif
749+
750+" strex %1, %0, [%3]\n"
751+" teq %1, #0\n"
752+" bne 1b"
753+
754+#ifdef CONFIG_PAX_REFCOUNT
755+"\n4:\n"
756+ _ASM_EXTABLE(2b, 4b)
757+#endif
758+
759+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
760+ : "r" (&v->counter), "Ir" (i)
761+ : "cc");
762+}
763+
764+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
765+{
766+ unsigned long tmp;
767+ int result;
768+
769+ __asm__ __volatile__("@ atomic_add_unchecked\n"
770 "1: ldrex %0, [%3]\n"
771 " add %0, %0, %4\n"
772 " strex %1, %0, [%3]\n"
773@@ -58,6 +99,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
774 smp_mb();
775
776 __asm__ __volatile__("@ atomic_add_return\n"
777+"1: ldrex %1, [%3]\n"
778+" adds %0, %1, %4\n"
779+
780+#ifdef CONFIG_PAX_REFCOUNT
781+" bvc 3f\n"
782+" mov %0, %1\n"
783+"2: bkpt 0xf103\n"
784+"3:\n"
785+#endif
786+
787+" strex %1, %0, [%3]\n"
788+" teq %1, #0\n"
789+" bne 1b"
790+
791+#ifdef CONFIG_PAX_REFCOUNT
792+"\n4:\n"
793+ _ASM_EXTABLE(2b, 4b)
794+#endif
795+
796+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
797+ : "r" (&v->counter), "Ir" (i)
798+ : "cc");
799+
800+ smp_mb();
801+
802+ return result;
803+}
804+
805+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
806+{
807+ unsigned long tmp;
808+ int result;
809+
810+ smp_mb();
811+
812+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
813 "1: ldrex %0, [%3]\n"
814 " add %0, %0, %4\n"
815 " strex %1, %0, [%3]\n"
816@@ -78,6 +155,35 @@ static inline void atomic_sub(int i, atomic_t *v)
817 int result;
818
819 __asm__ __volatile__("@ atomic_sub\n"
820+"1: ldrex %1, [%3]\n"
821+" subs %0, %1, %4\n"
822+
823+#ifdef CONFIG_PAX_REFCOUNT
824+" bvc 3f\n"
825+"2: bkpt 0xf103\n"
826+"3:\n"
827+#endif
828+
829+" strex %1, %0, [%3]\n"
830+" teq %1, #0\n"
831+" bne 1b"
832+
833+#ifdef CONFIG_PAX_REFCOUNT
834+"\n4:\n"
835+ _ASM_EXTABLE(2b, 4b)
836+#endif
837+
838+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
839+ : "r" (&v->counter), "Ir" (i)
840+ : "cc");
841+}
842+
843+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
844+{
845+ unsigned long tmp;
846+ int result;
847+
848+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
849 "1: ldrex %0, [%3]\n"
850 " sub %0, %0, %4\n"
851 " strex %1, %0, [%3]\n"
852@@ -96,11 +202,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
853 smp_mb();
854
855 __asm__ __volatile__("@ atomic_sub_return\n"
856-"1: ldrex %0, [%3]\n"
857-" sub %0, %0, %4\n"
858+"1: ldrex %1, [%3]\n"
859+" sub %0, %1, %4\n"
860+
861+#ifdef CONFIG_PAX_REFCOUNT
862+" bvc 3f\n"
863+" mov %0, %1\n"
864+"2: bkpt 0xf103\n"
865+"3:\n"
866+#endif
867+
868 " strex %1, %0, [%3]\n"
869 " teq %1, #0\n"
870 " bne 1b"
871+
872+#ifdef CONFIG_PAX_REFCOUNT
873+"\n4:\n"
874+ _ASM_EXTABLE(2b, 4b)
875+#endif
876+
877 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
878 : "r" (&v->counter), "Ir" (i)
879 : "cc");
880@@ -132,6 +252,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
881 return oldval;
882 }
883
884+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
885+{
886+ unsigned long oldval, res;
887+
888+ smp_mb();
889+
890+ do {
891+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
892+ "ldrex %1, [%3]\n"
893+ "mov %0, #0\n"
894+ "teq %1, %4\n"
895+ "strexeq %0, %5, [%3]\n"
896+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
897+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
898+ : "cc");
899+ } while (res);
900+
901+ smp_mb();
902+
903+ return oldval;
904+}
905+
906 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
907 {
908 unsigned long tmp, tmp2;
909@@ -165,7 +307,9 @@ static inline int atomic_add_return(int i, atomic_t *v)
910
911 return val;
912 }
913+#define atomic_add_return_unchecked(i, v) atomic_add_return(i, v)
914 #define atomic_add(i, v) (void) atomic_add_return(i, v)
915+#define atomic_add_unchecked(i, v) (void) atomic_add_return_unchecked(i, v)
916
917 static inline int atomic_sub_return(int i, atomic_t *v)
918 {
919@@ -179,7 +323,9 @@ static inline int atomic_sub_return(int i, atomic_t *v)
920
921 return val;
922 }
923+#define atomic_sub_return_unchecked(i, v) atomic_sub_return(i, v)
924 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
925+#define atomic_sub_unchecked(i, v) (void) atomic_sub_return_unchecked(i, v)
926
927 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
928 {
929@@ -194,6 +340,7 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
930
931 return ret;
932 }
933+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg(v, o, n)
934
935 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
936 {
937@@ -207,6 +354,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
938 #endif /* __LINUX_ARM_ARCH__ */
939
940 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
941+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
942+{
943+ return xchg(&v->counter, new);
944+}
945
946 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
947 {
948@@ -219,11 +370,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
949 }
950
951 #define atomic_inc(v) atomic_add(1, v)
952+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
953+{
954+ atomic_add_unchecked(1, v);
955+}
956 #define atomic_dec(v) atomic_sub(1, v)
957+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
958+{
959+ atomic_sub_unchecked(1, v);
960+}
961
962 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
963+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
964+{
965+ return atomic_add_return_unchecked(1, v) == 0;
966+}
967 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
968 #define atomic_inc_return(v) (atomic_add_return(1, v))
969+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
970+{
971+ return atomic_add_return_unchecked(1, v);
972+}
973 #define atomic_dec_return(v) (atomic_sub_return(1, v))
974 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
975
976@@ -239,6 +406,14 @@ typedef struct {
977 u64 __aligned(8) counter;
978 } atomic64_t;
979
980+#ifdef CONFIG_PAX_REFCOUNT
981+typedef struct {
982+ u64 __aligned(8) counter;
983+} atomic64_unchecked_t;
984+#else
985+typedef atomic64_t atomic64_unchecked_t;
986+#endif
987+
988 #define ATOMIC64_INIT(i) { (i) }
989
990 static inline u64 atomic64_read(atomic64_t *v)
991@@ -254,6 +429,19 @@ static inline u64 atomic64_read(atomic64_t *v)
992 return result;
993 }
994
995+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
996+{
997+ u64 result;
998+
999+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1000+" ldrexd %0, %H0, [%1]"
1001+ : "=&r" (result)
1002+ : "r" (&v->counter), "Qo" (v->counter)
1003+ );
1004+
1005+ return result;
1006+}
1007+
1008 static inline void atomic64_set(atomic64_t *v, u64 i)
1009 {
1010 u64 tmp;
1011@@ -268,6 +456,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1012 : "cc");
1013 }
1014
1015+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1016+{
1017+ u64 tmp;
1018+
1019+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1020+"1: ldrexd %0, %H0, [%2]\n"
1021+" strexd %0, %3, %H3, [%2]\n"
1022+" teq %0, #0\n"
1023+" bne 1b"
1024+ : "=&r" (tmp), "=Qo" (v->counter)
1025+ : "r" (&v->counter), "r" (i)
1026+ : "cc");
1027+}
1028+
1029 static inline void atomic64_add(u64 i, atomic64_t *v)
1030 {
1031 u64 result;
1032@@ -276,6 +478,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1033 __asm__ __volatile__("@ atomic64_add\n"
1034 "1: ldrexd %0, %H0, [%3]\n"
1035 " adds %0, %0, %4\n"
1036+" adcs %H0, %H0, %H4\n"
1037+
1038+#ifdef CONFIG_PAX_REFCOUNT
1039+" bvc 3f\n"
1040+"2: bkpt 0xf103\n"
1041+"3:\n"
1042+#endif
1043+
1044+" strexd %1, %0, %H0, [%3]\n"
1045+" teq %1, #0\n"
1046+" bne 1b"
1047+
1048+#ifdef CONFIG_PAX_REFCOUNT
1049+"\n4:\n"
1050+ _ASM_EXTABLE(2b, 4b)
1051+#endif
1052+
1053+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1054+ : "r" (&v->counter), "r" (i)
1055+ : "cc");
1056+}
1057+
1058+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1059+{
1060+ u64 result;
1061+ unsigned long tmp;
1062+
1063+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1064+"1: ldrexd %0, %H0, [%3]\n"
1065+" adds %0, %0, %4\n"
1066 " adc %H0, %H0, %H4\n"
1067 " strexd %1, %0, %H0, [%3]\n"
1068 " teq %1, #0\n"
1069@@ -287,12 +519,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1070
1071 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1072 {
1073- u64 result;
1074- unsigned long tmp;
1075+ u64 result, tmp;
1076
1077 smp_mb();
1078
1079 __asm__ __volatile__("@ atomic64_add_return\n"
1080+"1: ldrexd %1, %H1, [%3]\n"
1081+" adds %0, %1, %4\n"
1082+" adcs %H0, %H1, %H4\n"
1083+
1084+#ifdef CONFIG_PAX_REFCOUNT
1085+" bvc 3f\n"
1086+" mov %0, %1\n"
1087+" mov %H0, %H1\n"
1088+"2: bkpt 0xf103\n"
1089+"3:\n"
1090+#endif
1091+
1092+" strexd %1, %0, %H0, [%3]\n"
1093+" teq %1, #0\n"
1094+" bne 1b"
1095+
1096+#ifdef CONFIG_PAX_REFCOUNT
1097+"\n4:\n"
1098+ _ASM_EXTABLE(2b, 4b)
1099+#endif
1100+
1101+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1102+ : "r" (&v->counter), "r" (i)
1103+ : "cc");
1104+
1105+ smp_mb();
1106+
1107+ return result;
1108+}
1109+
1110+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1111+{
1112+ u64 result;
1113+ unsigned long tmp;
1114+
1115+ smp_mb();
1116+
1117+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1118 "1: ldrexd %0, %H0, [%3]\n"
1119 " adds %0, %0, %4\n"
1120 " adc %H0, %H0, %H4\n"
1121@@ -316,6 +585,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1122 __asm__ __volatile__("@ atomic64_sub\n"
1123 "1: ldrexd %0, %H0, [%3]\n"
1124 " subs %0, %0, %4\n"
1125+" sbcs %H0, %H0, %H4\n"
1126+
1127+#ifdef CONFIG_PAX_REFCOUNT
1128+" bvc 3f\n"
1129+"2: bkpt 0xf103\n"
1130+"3:\n"
1131+#endif
1132+
1133+" strexd %1, %0, %H0, [%3]\n"
1134+" teq %1, #0\n"
1135+" bne 1b"
1136+
1137+#ifdef CONFIG_PAX_REFCOUNT
1138+"\n4:\n"
1139+ _ASM_EXTABLE(2b, 4b)
1140+#endif
1141+
1142+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1143+ : "r" (&v->counter), "r" (i)
1144+ : "cc");
1145+}
1146+
1147+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1148+{
1149+ u64 result;
1150+ unsigned long tmp;
1151+
1152+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1153+"1: ldrexd %0, %H0, [%3]\n"
1154+" subs %0, %0, %4\n"
1155 " sbc %H0, %H0, %H4\n"
1156 " strexd %1, %0, %H0, [%3]\n"
1157 " teq %1, #0\n"
1158@@ -327,18 +626,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1159
1160 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1161 {
1162- u64 result;
1163- unsigned long tmp;
1164+ u64 result, tmp;
1165
1166 smp_mb();
1167
1168 __asm__ __volatile__("@ atomic64_sub_return\n"
1169-"1: ldrexd %0, %H0, [%3]\n"
1170-" subs %0, %0, %4\n"
1171-" sbc %H0, %H0, %H4\n"
1172+"1: ldrexd %1, %H1, [%3]\n"
1173+" subs %0, %1, %4\n"
1174+" sbc %H0, %H1, %H4\n"
1175+
1176+#ifdef CONFIG_PAX_REFCOUNT
1177+" bvc 3f\n"
1178+" mov %0, %1\n"
1179+" mov %H0, %H1\n"
1180+"2: bkpt 0xf103\n"
1181+"3:\n"
1182+#endif
1183+
1184 " strexd %1, %0, %H0, [%3]\n"
1185 " teq %1, #0\n"
1186 " bne 1b"
1187+
1188+#ifdef CONFIG_PAX_REFCOUNT
1189+"\n4:\n"
1190+ _ASM_EXTABLE(2b, 4b)
1191+#endif
1192+
1193 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1194 : "r" (&v->counter), "r" (i)
1195 : "cc");
1196@@ -372,6 +685,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1197 return oldval;
1198 }
1199
1200+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1201+{
1202+ u64 oldval;
1203+ unsigned long res;
1204+
1205+ smp_mb();
1206+
1207+ do {
1208+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1209+ "ldrexd %1, %H1, [%3]\n"
1210+ "mov %0, #0\n"
1211+ "teq %1, %4\n"
1212+ "teqeq %H1, %H4\n"
1213+ "strexdeq %0, %5, %H5, [%3]"
1214+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1215+ : "r" (&ptr->counter), "r" (old), "r" (new)
1216+ : "cc");
1217+ } while (res);
1218+
1219+ smp_mb();
1220+
1221+ return oldval;
1222+}
1223+
1224 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1225 {
1226 u64 result;
1227@@ -395,21 +732,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1228
1229 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1230 {
1231- u64 result;
1232- unsigned long tmp;
1233+ u64 result, tmp;
1234
1235 smp_mb();
1236
1237 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1238-"1: ldrexd %0, %H0, [%3]\n"
1239-" subs %0, %0, #1\n"
1240-" sbc %H0, %H0, #0\n"
1241+"1: ldrexd %1, %H1, [%3]\n"
1242+" subs %0, %1, #1\n"
1243+" sbc %H0, %H1, #0\n"
1244+
1245+#ifdef CONFIG_PAX_REFCOUNT
1246+" bvc 3f\n"
1247+" mov %0, %1\n"
1248+" mov %H0, %H1\n"
1249+"2: bkpt 0xf103\n"
1250+"3:\n"
1251+#endif
1252+
1253 " teq %H0, #0\n"
1254-" bmi 2f\n"
1255+" bmi 4f\n"
1256 " strexd %1, %0, %H0, [%3]\n"
1257 " teq %1, #0\n"
1258 " bne 1b\n"
1259-"2:"
1260+"4:\n"
1261+
1262+#ifdef CONFIG_PAX_REFCOUNT
1263+ _ASM_EXTABLE(2b, 4b)
1264+#endif
1265+
1266 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1267 : "r" (&v->counter)
1268 : "cc");
1269@@ -432,13 +782,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1270 " teq %0, %5\n"
1271 " teqeq %H0, %H5\n"
1272 " moveq %1, #0\n"
1273-" beq 2f\n"
1274+" beq 4f\n"
1275 " adds %0, %0, %6\n"
1276 " adc %H0, %H0, %H6\n"
1277+
1278+#ifdef CONFIG_PAX_REFCOUNT
1279+" bvc 3f\n"
1280+"2: bkpt 0xf103\n"
1281+"3:\n"
1282+#endif
1283+
1284 " strexd %2, %0, %H0, [%4]\n"
1285 " teq %2, #0\n"
1286 " bne 1b\n"
1287-"2:"
1288+"4:\n"
1289+
1290+#ifdef CONFIG_PAX_REFCOUNT
1291+ _ASM_EXTABLE(2b, 4b)
1292+#endif
1293+
1294 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1295 : "r" (&v->counter), "r" (u), "r" (a)
1296 : "cc");
1297@@ -451,10 +813,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1298
1299 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1300 #define atomic64_inc(v) atomic64_add(1LL, (v))
1301+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1302 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1303+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1304 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1305 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1306 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1307+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1308 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1309 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1310 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1311diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1312index 75fe66b..2255c86 100644
1313--- a/arch/arm/include/asm/cache.h
1314+++ b/arch/arm/include/asm/cache.h
1315@@ -4,8 +4,10 @@
1316 #ifndef __ASMARM_CACHE_H
1317 #define __ASMARM_CACHE_H
1318
1319+#include <linux/const.h>
1320+
1321 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1322-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1323+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1324
1325 /*
1326 * Memory returned by kmalloc() may be used for DMA, so we must make
1327diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1328index d5d8d5c..ad92c96 100644
1329--- a/arch/arm/include/asm/cacheflush.h
1330+++ b/arch/arm/include/asm/cacheflush.h
1331@@ -108,7 +108,7 @@ struct cpu_cache_fns {
1332 void (*dma_unmap_area)(const void *, size_t, int);
1333
1334 void (*dma_flush_range)(const void *, const void *);
1335-};
1336+} __no_const;
1337
1338 /*
1339 * Select the calling method
1340diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1341index 0e9ce8d..6ef1e03 100644
1342--- a/arch/arm/include/asm/elf.h
1343+++ b/arch/arm/include/asm/elf.h
1344@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1345 the loader. We need to make sure that it is out of the way of the program
1346 that it will "exec", and that there is sufficient room for the brk. */
1347
1348-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1349+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1350+
1351+#ifdef CONFIG_PAX_ASLR
1352+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1353+
1354+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1355+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1356+#endif
1357
1358 /* When the program starts, a1 contains a pointer to a function to be
1359 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1360@@ -126,10 +133,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1361 extern void elf_set_personality(const struct elf32_hdr *);
1362 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1363
1364-struct mm_struct;
1365-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1366-#define arch_randomize_brk arch_randomize_brk
1367-
1368 extern int vectors_user_mapping(void);
1369 #define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
1370 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
1371diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1372index e51b1e8..32a3113 100644
1373--- a/arch/arm/include/asm/kmap_types.h
1374+++ b/arch/arm/include/asm/kmap_types.h
1375@@ -21,6 +21,7 @@ enum km_type {
1376 KM_L1_CACHE,
1377 KM_L2_CACHE,
1378 KM_KDB,
1379+ KM_CLEARPAGE,
1380 KM_TYPE_NR
1381 };
1382
1383diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1384index 53426c6..c7baff3 100644
1385--- a/arch/arm/include/asm/outercache.h
1386+++ b/arch/arm/include/asm/outercache.h
1387@@ -35,7 +35,7 @@ struct outer_cache_fns {
1388 #endif
1389 void (*set_debug)(unsigned long);
1390 void (*resume)(void);
1391-};
1392+} __no_const;
1393
1394 #ifdef CONFIG_OUTER_CACHE
1395
1396diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1397index 97b440c..b7ff179 100644
1398--- a/arch/arm/include/asm/page.h
1399+++ b/arch/arm/include/asm/page.h
1400@@ -123,7 +123,7 @@ struct cpu_user_fns {
1401 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1402 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1403 unsigned long vaddr, struct vm_area_struct *vma);
1404-};
1405+} __no_const;
1406
1407 #ifdef MULTI_USER
1408 extern struct cpu_user_fns cpu_user;
1409diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1410index 943504f..bf8d667 100644
1411--- a/arch/arm/include/asm/pgalloc.h
1412+++ b/arch/arm/include/asm/pgalloc.h
1413@@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1414 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1415 }
1416
1417+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1418+{
1419+ pud_populate(mm, pud, pmd);
1420+}
1421+
1422 #else /* !CONFIG_ARM_LPAE */
1423
1424 /*
1425@@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1426 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1427 #define pmd_free(mm, pmd) do { } while (0)
1428 #define pud_populate(mm,pmd,pte) BUG()
1429+#define pud_populate_kernel(mm,pmd,pte) BUG()
1430
1431 #endif /* CONFIG_ARM_LPAE */
1432
1433diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h
1434index e4c96cc..1145653 100644
1435--- a/arch/arm/include/asm/system.h
1436+++ b/arch/arm/include/asm/system.h
1437@@ -98,6 +98,8 @@ void hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int,
1438
1439 #define xchg(ptr,x) \
1440 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1441+#define xchg_unchecked(ptr,x) \
1442+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1443
1444 extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
1445
1446@@ -534,6 +536,13 @@ static inline unsigned long long __cmpxchg64_mb(volatile void *ptr,
1447
1448 #endif /* __LINUX_ARM_ARCH__ >= 6 */
1449
1450+#define _ASM_EXTABLE(from, to) \
1451+" .pushsection __ex_table,\"a\"\n"\
1452+" .align 3\n" \
1453+" .long " #from ", " #to"\n" \
1454+" .popsection"
1455+
1456+
1457 #endif /* __ASSEMBLY__ */
1458
1459 #define arch_align_stack(x) (x)
1460diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1461index d4c24d4..4ac53e8 100644
1462--- a/arch/arm/include/asm/thread_info.h
1463+++ b/arch/arm/include/asm/thread_info.h
1464@@ -141,6 +141,12 @@ extern void vfp_flush_hwstate(struct thread_info *);
1465 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1466 #define TIF_SYSCALL_TRACE 8
1467 #define TIF_SYSCALL_AUDIT 9
1468+
1469+/* within 8 bits of TIF_SYSCALL_TRACE
1470+ to meet flexible second operand requirements
1471+*/
1472+#define TIF_GRSEC_SETXID 10
1473+
1474 #define TIF_POLLING_NRFLAG 16
1475 #define TIF_USING_IWMMXT 17
1476 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1477@@ -156,9 +162,11 @@ extern void vfp_flush_hwstate(struct thread_info *);
1478 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1479 #define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
1480 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1481+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1482
1483 /* Checks for any syscall work in entry-common.S */
1484-#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1485+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1486+ _TIF_GRSEC_SETXID)
1487
1488 /*
1489 * Change these and you break ASM code in entry-common.S
1490diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1491index 2958976..12ccac4 100644
1492--- a/arch/arm/include/asm/uaccess.h
1493+++ b/arch/arm/include/asm/uaccess.h
1494@@ -22,6 +22,8 @@
1495 #define VERIFY_READ 0
1496 #define VERIFY_WRITE 1
1497
1498+extern void check_object_size(const void *ptr, unsigned long n, bool to);
1499+
1500 /*
1501 * The exception table consists of pairs of addresses: the first is the
1502 * address of an instruction that is allowed to fault, and the second is
1503@@ -387,8 +389,23 @@ do { \
1504
1505
1506 #ifdef CONFIG_MMU
1507-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1508-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1509+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1510+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1511+
1512+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1513+{
1514+ if (!__builtin_constant_p(n))
1515+ check_object_size(to, n, false);
1516+ return ___copy_from_user(to, from, n);
1517+}
1518+
1519+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1520+{
1521+ if (!__builtin_constant_p(n))
1522+ check_object_size(from, n, true);
1523+ return ___copy_to_user(to, from, n);
1524+}
1525+
1526 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1527 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1528 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1529@@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1530
1531 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1532 {
1533+ if ((long)n < 0)
1534+ return n;
1535+
1536 if (access_ok(VERIFY_READ, from, n))
1537 n = __copy_from_user(to, from, n);
1538 else /* security hole - plug it */
1539@@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1540
1541 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1542 {
1543+ if ((long)n < 0)
1544+ return n;
1545+
1546 if (access_ok(VERIFY_WRITE, to, n))
1547 n = __copy_to_user(to, from, n);
1548 return n;
1549diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1550index 5b0bce6..becd81c 100644
1551--- a/arch/arm/kernel/armksyms.c
1552+++ b/arch/arm/kernel/armksyms.c
1553@@ -95,8 +95,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1554 #ifdef CONFIG_MMU
1555 EXPORT_SYMBOL(copy_page);
1556
1557-EXPORT_SYMBOL(__copy_from_user);
1558-EXPORT_SYMBOL(__copy_to_user);
1559+EXPORT_SYMBOL(___copy_from_user);
1560+EXPORT_SYMBOL(___copy_to_user);
1561 EXPORT_SYMBOL(__clear_user);
1562
1563 EXPORT_SYMBOL(__get_user_1);
1564diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1565index 971d65c..cc936fb 100644
1566--- a/arch/arm/kernel/process.c
1567+++ b/arch/arm/kernel/process.c
1568@@ -28,7 +28,6 @@
1569 #include <linux/tick.h>
1570 #include <linux/utsname.h>
1571 #include <linux/uaccess.h>
1572-#include <linux/random.h>
1573 #include <linux/hw_breakpoint.h>
1574 #include <linux/cpuidle.h>
1575
1576@@ -273,9 +272,10 @@ void machine_power_off(void)
1577 machine_shutdown();
1578 if (pm_power_off)
1579 pm_power_off();
1580+ BUG();
1581 }
1582
1583-void machine_restart(char *cmd)
1584+__noreturn void machine_restart(char *cmd)
1585 {
1586 machine_shutdown();
1587
1588@@ -517,12 +517,6 @@ unsigned long get_wchan(struct task_struct *p)
1589 return 0;
1590 }
1591
1592-unsigned long arch_randomize_brk(struct mm_struct *mm)
1593-{
1594- unsigned long range_end = mm->brk + 0x02000000;
1595- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1596-}
1597-
1598 #ifdef CONFIG_MMU
1599 /*
1600 * The vectors page is always readable from user space for the
1601diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1602index f5ce8ab..4b73893 100644
1603--- a/arch/arm/kernel/ptrace.c
1604+++ b/arch/arm/kernel/ptrace.c
1605@@ -905,10 +905,19 @@ long arch_ptrace(struct task_struct *child, long request,
1606 return ret;
1607 }
1608
1609+#ifdef CONFIG_GRKERNSEC_SETXID
1610+extern void gr_delayed_cred_worker(void);
1611+#endif
1612+
1613 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
1614 {
1615 unsigned long ip;
1616
1617+#ifdef CONFIG_GRKERNSEC_SETXID
1618+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1619+ gr_delayed_cred_worker();
1620+#endif
1621+
1622 if (why)
1623 audit_syscall_exit(regs);
1624 else
1625diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1626index a255c39..4a19b25 100644
1627--- a/arch/arm/kernel/setup.c
1628+++ b/arch/arm/kernel/setup.c
1629@@ -109,13 +109,13 @@ struct processor processor __read_mostly;
1630 struct cpu_tlb_fns cpu_tlb __read_mostly;
1631 #endif
1632 #ifdef MULTI_USER
1633-struct cpu_user_fns cpu_user __read_mostly;
1634+struct cpu_user_fns cpu_user __read_only;
1635 #endif
1636 #ifdef MULTI_CACHE
1637-struct cpu_cache_fns cpu_cache __read_mostly;
1638+struct cpu_cache_fns cpu_cache __read_only;
1639 #endif
1640 #ifdef CONFIG_OUTER_CACHE
1641-struct outer_cache_fns outer_cache __read_mostly;
1642+struct outer_cache_fns outer_cache __read_only;
1643 EXPORT_SYMBOL(outer_cache);
1644 #endif
1645
1646diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1647index f84dfe6..13e94f7 100644
1648--- a/arch/arm/kernel/traps.c
1649+++ b/arch/arm/kernel/traps.c
1650@@ -259,6 +259,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1651
1652 static DEFINE_RAW_SPINLOCK(die_lock);
1653
1654+extern void gr_handle_kernel_exploit(void);
1655+
1656 /*
1657 * This function is protected against re-entrancy.
1658 */
1659@@ -291,6 +293,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1660 panic("Fatal exception in interrupt");
1661 if (panic_on_oops)
1662 panic("Fatal exception");
1663+
1664+ gr_handle_kernel_exploit();
1665+
1666 if (ret != NOTIFY_STOP)
1667 do_exit(SIGSEGV);
1668 }
1669diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1670index 66a477a..bee61d3 100644
1671--- a/arch/arm/lib/copy_from_user.S
1672+++ b/arch/arm/lib/copy_from_user.S
1673@@ -16,7 +16,7 @@
1674 /*
1675 * Prototype:
1676 *
1677- * size_t __copy_from_user(void *to, const void *from, size_t n)
1678+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
1679 *
1680 * Purpose:
1681 *
1682@@ -84,11 +84,11 @@
1683
1684 .text
1685
1686-ENTRY(__copy_from_user)
1687+ENTRY(___copy_from_user)
1688
1689 #include "copy_template.S"
1690
1691-ENDPROC(__copy_from_user)
1692+ENDPROC(___copy_from_user)
1693
1694 .pushsection .fixup,"ax"
1695 .align 0
1696diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1697index 6ee2f67..d1cce76 100644
1698--- a/arch/arm/lib/copy_page.S
1699+++ b/arch/arm/lib/copy_page.S
1700@@ -10,6 +10,7 @@
1701 * ASM optimised string functions
1702 */
1703 #include <linux/linkage.h>
1704+#include <linux/const.h>
1705 #include <asm/assembler.h>
1706 #include <asm/asm-offsets.h>
1707 #include <asm/cache.h>
1708diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1709index d066df6..df28194 100644
1710--- a/arch/arm/lib/copy_to_user.S
1711+++ b/arch/arm/lib/copy_to_user.S
1712@@ -16,7 +16,7 @@
1713 /*
1714 * Prototype:
1715 *
1716- * size_t __copy_to_user(void *to, const void *from, size_t n)
1717+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
1718 *
1719 * Purpose:
1720 *
1721@@ -88,11 +88,11 @@
1722 .text
1723
1724 ENTRY(__copy_to_user_std)
1725-WEAK(__copy_to_user)
1726+WEAK(___copy_to_user)
1727
1728 #include "copy_template.S"
1729
1730-ENDPROC(__copy_to_user)
1731+ENDPROC(___copy_to_user)
1732 ENDPROC(__copy_to_user_std)
1733
1734 .pushsection .fixup,"ax"
1735diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
1736index 5c908b1..e712687 100644
1737--- a/arch/arm/lib/uaccess.S
1738+++ b/arch/arm/lib/uaccess.S
1739@@ -20,7 +20,7 @@
1740
1741 #define PAGE_SHIFT 12
1742
1743-/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
1744+/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
1745 * Purpose : copy a block to user memory from kernel memory
1746 * Params : to - user memory
1747 * : from - kernel memory
1748@@ -40,7 +40,7 @@ USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1749 sub r2, r2, ip
1750 b .Lc2u_dest_aligned
1751
1752-ENTRY(__copy_to_user)
1753+ENTRY(___copy_to_user)
1754 stmfd sp!, {r2, r4 - r7, lr}
1755 cmp r2, #4
1756 blt .Lc2u_not_enough
1757@@ -278,14 +278,14 @@ USER( TUSER( strgeb) r3, [r0], #1) @ May fault
1758 ldrgtb r3, [r1], #0
1759 USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1760 b .Lc2u_finished
1761-ENDPROC(__copy_to_user)
1762+ENDPROC(___copy_to_user)
1763
1764 .pushsection .fixup,"ax"
1765 .align 0
1766 9001: ldmfd sp!, {r0, r4 - r7, pc}
1767 .popsection
1768
1769-/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
1770+/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
1771 * Purpose : copy a block from user memory to kernel memory
1772 * Params : to - kernel memory
1773 * : from - user memory
1774@@ -304,7 +304,7 @@ USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1775 sub r2, r2, ip
1776 b .Lcfu_dest_aligned
1777
1778-ENTRY(__copy_from_user)
1779+ENTRY(___copy_from_user)
1780 stmfd sp!, {r0, r2, r4 - r7, lr}
1781 cmp r2, #4
1782 blt .Lcfu_not_enough
1783@@ -544,7 +544,7 @@ USER( TUSER( ldrgeb) r3, [r1], #1) @ May fault
1784 USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1785 strgtb r3, [r0], #1
1786 b .Lcfu_finished
1787-ENDPROC(__copy_from_user)
1788+ENDPROC(___copy_from_user)
1789
1790 .pushsection .fixup,"ax"
1791 .align 0
1792diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1793index 025f742..8432b08 100644
1794--- a/arch/arm/lib/uaccess_with_memcpy.c
1795+++ b/arch/arm/lib/uaccess_with_memcpy.c
1796@@ -104,7 +104,7 @@ out:
1797 }
1798
1799 unsigned long
1800-__copy_to_user(void __user *to, const void *from, unsigned long n)
1801+___copy_to_user(void __user *to, const void *from, unsigned long n)
1802 {
1803 /*
1804 * This test is stubbed out of the main function above to keep
1805diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1806index 6722627..8f97548c 100644
1807--- a/arch/arm/mach-omap2/board-n8x0.c
1808+++ b/arch/arm/mach-omap2/board-n8x0.c
1809@@ -597,7 +597,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1810 }
1811 #endif
1812
1813-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1814+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1815 .late_init = n8x0_menelaus_late_init,
1816 };
1817
1818diff --git a/arch/arm/mach-ux500/mbox-db5500.c b/arch/arm/mach-ux500/mbox-db5500.c
1819index 2b2d51c..0127490 100644
1820--- a/arch/arm/mach-ux500/mbox-db5500.c
1821+++ b/arch/arm/mach-ux500/mbox-db5500.c
1822@@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct device *dev,
1823 return sprintf(buf, "0x%X\n", mbox_value);
1824 }
1825
1826-static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1827+static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1828
1829 static int mbox_show(struct seq_file *s, void *data)
1830 {
1831diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1832index 90e366a..1b92505 100644
1833--- a/arch/arm/mm/fault.c
1834+++ b/arch/arm/mm/fault.c
1835@@ -172,6 +172,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1836 }
1837 #endif
1838
1839+#ifdef CONFIG_PAX_PAGEEXEC
1840+ if (fsr & FSR_LNX_PF) {
1841+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1842+ do_group_exit(SIGKILL);
1843+ }
1844+#endif
1845+
1846 tsk->thread.address = addr;
1847 tsk->thread.error_code = fsr;
1848 tsk->thread.trap_no = 14;
1849@@ -395,6 +402,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1850 }
1851 #endif /* CONFIG_MMU */
1852
1853+#ifdef CONFIG_PAX_PAGEEXEC
1854+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1855+{
1856+ long i;
1857+
1858+ printk(KERN_ERR "PAX: bytes at PC: ");
1859+ for (i = 0; i < 20; i++) {
1860+ unsigned char c;
1861+ if (get_user(c, (__force unsigned char __user *)pc+i))
1862+ printk(KERN_CONT "?? ");
1863+ else
1864+ printk(KERN_CONT "%02x ", c);
1865+ }
1866+ printk("\n");
1867+
1868+ printk(KERN_ERR "PAX: bytes at SP-4: ");
1869+ for (i = -1; i < 20; i++) {
1870+ unsigned long c;
1871+ if (get_user(c, (__force unsigned long __user *)sp+i))
1872+ printk(KERN_CONT "???????? ");
1873+ else
1874+ printk(KERN_CONT "%08lx ", c);
1875+ }
1876+ printk("\n");
1877+}
1878+#endif
1879+
1880 /*
1881 * First Level Translation Fault Handler
1882 *
1883@@ -575,6 +609,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1884 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1885 struct siginfo info;
1886
1887+#ifdef CONFIG_PAX_REFCOUNT
1888+ if (fsr_fs(ifsr) == 2) {
1889+ unsigned int bkpt;
1890+
1891+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1892+ current->thread.error_code = ifsr;
1893+ current->thread.trap_no = 0;
1894+ pax_report_refcount_overflow(regs);
1895+ fixup_exception(regs);
1896+ return;
1897+ }
1898+ }
1899+#endif
1900+
1901 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1902 return;
1903
1904diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1905index ce8cb19..3ec539d 100644
1906--- a/arch/arm/mm/mmap.c
1907+++ b/arch/arm/mm/mmap.c
1908@@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1909 if (len > TASK_SIZE)
1910 return -ENOMEM;
1911
1912+#ifdef CONFIG_PAX_RANDMMAP
1913+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1914+#endif
1915+
1916 if (addr) {
1917 if (do_align)
1918 addr = COLOUR_ALIGN(addr, pgoff);
1919@@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1920 addr = PAGE_ALIGN(addr);
1921
1922 vma = find_vma(mm, addr);
1923- if (TASK_SIZE - len >= addr &&
1924- (!vma || addr + len <= vma->vm_start))
1925+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1926 return addr;
1927 }
1928 if (len > mm->cached_hole_size) {
1929- start_addr = addr = mm->free_area_cache;
1930+ start_addr = addr = mm->free_area_cache;
1931 } else {
1932- start_addr = addr = mm->mmap_base;
1933- mm->cached_hole_size = 0;
1934+ start_addr = addr = mm->mmap_base;
1935+ mm->cached_hole_size = 0;
1936 }
1937
1938 full_search:
1939@@ -124,14 +127,14 @@ full_search:
1940 * Start a new search - just in case we missed
1941 * some holes.
1942 */
1943- if (start_addr != TASK_UNMAPPED_BASE) {
1944- start_addr = addr = TASK_UNMAPPED_BASE;
1945+ if (start_addr != mm->mmap_base) {
1946+ start_addr = addr = mm->mmap_base;
1947 mm->cached_hole_size = 0;
1948 goto full_search;
1949 }
1950 return -ENOMEM;
1951 }
1952- if (!vma || addr + len <= vma->vm_start) {
1953+ if (check_heap_stack_gap(vma, addr, len)) {
1954 /*
1955 * Remember the place where we stopped the search:
1956 */
1957@@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1958
1959 if (mmap_is_legacy()) {
1960 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1961+
1962+#ifdef CONFIG_PAX_RANDMMAP
1963+ if (mm->pax_flags & MF_PAX_RANDMMAP)
1964+ mm->mmap_base += mm->delta_mmap;
1965+#endif
1966+
1967 mm->get_unmapped_area = arch_get_unmapped_area;
1968 mm->unmap_area = arch_unmap_area;
1969 } else {
1970 mm->mmap_base = mmap_base(random_factor);
1971+
1972+#ifdef CONFIG_PAX_RANDMMAP
1973+ if (mm->pax_flags & MF_PAX_RANDMMAP)
1974+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
1975+#endif
1976+
1977 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
1978 mm->unmap_area = arch_unmap_area_topdown;
1979 }
1980diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
1981index 71a6827..e7fbc23 100644
1982--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
1983+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
1984@@ -43,7 +43,7 @@ struct samsung_dma_ops {
1985 int (*started)(unsigned ch);
1986 int (*flush)(unsigned ch);
1987 int (*stop)(unsigned ch);
1988-};
1989+} __no_const;
1990
1991 extern void *samsung_dmadev_get_ops(void);
1992 extern void *s3c_dma_get_ops(void);
1993diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
1994index 5f28cae..3d23723 100644
1995--- a/arch/arm/plat-samsung/include/plat/ehci.h
1996+++ b/arch/arm/plat-samsung/include/plat/ehci.h
1997@@ -14,7 +14,7 @@
1998 struct s5p_ehci_platdata {
1999 int (*phy_init)(struct platform_device *pdev, int type);
2000 int (*phy_exit)(struct platform_device *pdev, int type);
2001-};
2002+} __no_const;
2003
2004 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2005
2006diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2007index c3a58a1..78fbf54 100644
2008--- a/arch/avr32/include/asm/cache.h
2009+++ b/arch/avr32/include/asm/cache.h
2010@@ -1,8 +1,10 @@
2011 #ifndef __ASM_AVR32_CACHE_H
2012 #define __ASM_AVR32_CACHE_H
2013
2014+#include <linux/const.h>
2015+
2016 #define L1_CACHE_SHIFT 5
2017-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2018+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2019
2020 /*
2021 * Memory returned by kmalloc() may be used for DMA, so we must make
2022diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2023index 3b3159b..425ea94 100644
2024--- a/arch/avr32/include/asm/elf.h
2025+++ b/arch/avr32/include/asm/elf.h
2026@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2027 the loader. We need to make sure that it is out of the way of the program
2028 that it will "exec", and that there is sufficient room for the brk. */
2029
2030-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2031+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2032
2033+#ifdef CONFIG_PAX_ASLR
2034+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2035+
2036+#define PAX_DELTA_MMAP_LEN 15
2037+#define PAX_DELTA_STACK_LEN 15
2038+#endif
2039
2040 /* This yields a mask that user programs can use to figure out what
2041 instruction set this CPU supports. This could be done in user space,
2042diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2043index b7f5c68..556135c 100644
2044--- a/arch/avr32/include/asm/kmap_types.h
2045+++ b/arch/avr32/include/asm/kmap_types.h
2046@@ -22,7 +22,8 @@ D(10) KM_IRQ0,
2047 D(11) KM_IRQ1,
2048 D(12) KM_SOFTIRQ0,
2049 D(13) KM_SOFTIRQ1,
2050-D(14) KM_TYPE_NR
2051+D(14) KM_CLEARPAGE,
2052+D(15) KM_TYPE_NR
2053 };
2054
2055 #undef D
2056diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2057index f7040a1..db9f300 100644
2058--- a/arch/avr32/mm/fault.c
2059+++ b/arch/avr32/mm/fault.c
2060@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2061
2062 int exception_trace = 1;
2063
2064+#ifdef CONFIG_PAX_PAGEEXEC
2065+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2066+{
2067+ unsigned long i;
2068+
2069+ printk(KERN_ERR "PAX: bytes at PC: ");
2070+ for (i = 0; i < 20; i++) {
2071+ unsigned char c;
2072+ if (get_user(c, (unsigned char *)pc+i))
2073+ printk(KERN_CONT "???????? ");
2074+ else
2075+ printk(KERN_CONT "%02x ", c);
2076+ }
2077+ printk("\n");
2078+}
2079+#endif
2080+
2081 /*
2082 * This routine handles page faults. It determines the address and the
2083 * problem, and then passes it off to one of the appropriate routines.
2084@@ -156,6 +173,16 @@ bad_area:
2085 up_read(&mm->mmap_sem);
2086
2087 if (user_mode(regs)) {
2088+
2089+#ifdef CONFIG_PAX_PAGEEXEC
2090+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2091+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2092+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2093+ do_group_exit(SIGKILL);
2094+ }
2095+ }
2096+#endif
2097+
2098 if (exception_trace && printk_ratelimit())
2099 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2100 "sp %08lx ecr %lu\n",
2101diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2102index 568885a..f8008df 100644
2103--- a/arch/blackfin/include/asm/cache.h
2104+++ b/arch/blackfin/include/asm/cache.h
2105@@ -7,6 +7,7 @@
2106 #ifndef __ARCH_BLACKFIN_CACHE_H
2107 #define __ARCH_BLACKFIN_CACHE_H
2108
2109+#include <linux/const.h>
2110 #include <linux/linkage.h> /* for asmlinkage */
2111
2112 /*
2113@@ -14,7 +15,7 @@
2114 * Blackfin loads 32 bytes for cache
2115 */
2116 #define L1_CACHE_SHIFT 5
2117-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2118+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2119 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2120
2121 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2122diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2123index aea2718..3639a60 100644
2124--- a/arch/cris/include/arch-v10/arch/cache.h
2125+++ b/arch/cris/include/arch-v10/arch/cache.h
2126@@ -1,8 +1,9 @@
2127 #ifndef _ASM_ARCH_CACHE_H
2128 #define _ASM_ARCH_CACHE_H
2129
2130+#include <linux/const.h>
2131 /* Etrax 100LX have 32-byte cache-lines. */
2132-#define L1_CACHE_BYTES 32
2133 #define L1_CACHE_SHIFT 5
2134+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2135
2136 #endif /* _ASM_ARCH_CACHE_H */
2137diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2138index 1de779f..336fad3 100644
2139--- a/arch/cris/include/arch-v32/arch/cache.h
2140+++ b/arch/cris/include/arch-v32/arch/cache.h
2141@@ -1,11 +1,12 @@
2142 #ifndef _ASM_CRIS_ARCH_CACHE_H
2143 #define _ASM_CRIS_ARCH_CACHE_H
2144
2145+#include <linux/const.h>
2146 #include <arch/hwregs/dma.h>
2147
2148 /* A cache-line is 32 bytes. */
2149-#define L1_CACHE_BYTES 32
2150 #define L1_CACHE_SHIFT 5
2151+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2152
2153 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
2154
2155diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2156index 0d8a7d6..d0c9ff5 100644
2157--- a/arch/frv/include/asm/atomic.h
2158+++ b/arch/frv/include/asm/atomic.h
2159@@ -241,6 +241,16 @@ extern uint32_t __xchg_32(uint32_t i, volatile void *v);
2160 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2161 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2162
2163+#define atomic64_read_unchecked(v) atomic64_read(v)
2164+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2165+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2166+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2167+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2168+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2169+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2170+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2171+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2172+
2173 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2174 {
2175 int c, old;
2176diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2177index 2797163..c2a401d 100644
2178--- a/arch/frv/include/asm/cache.h
2179+++ b/arch/frv/include/asm/cache.h
2180@@ -12,10 +12,11 @@
2181 #ifndef __ASM_CACHE_H
2182 #define __ASM_CACHE_H
2183
2184+#include <linux/const.h>
2185
2186 /* bytes per L1 cache line */
2187 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2188-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2189+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2190
2191 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2192 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2193diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2194index f8e16b2..c73ff79 100644
2195--- a/arch/frv/include/asm/kmap_types.h
2196+++ b/arch/frv/include/asm/kmap_types.h
2197@@ -23,6 +23,7 @@ enum km_type {
2198 KM_IRQ1,
2199 KM_SOFTIRQ0,
2200 KM_SOFTIRQ1,
2201+ KM_CLEARPAGE,
2202 KM_TYPE_NR
2203 };
2204
2205diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2206index 385fd30..6c3d97e 100644
2207--- a/arch/frv/mm/elf-fdpic.c
2208+++ b/arch/frv/mm/elf-fdpic.c
2209@@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2210 if (addr) {
2211 addr = PAGE_ALIGN(addr);
2212 vma = find_vma(current->mm, addr);
2213- if (TASK_SIZE - len >= addr &&
2214- (!vma || addr + len <= vma->vm_start))
2215+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2216 goto success;
2217 }
2218
2219@@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2220 for (; vma; vma = vma->vm_next) {
2221 if (addr > limit)
2222 break;
2223- if (addr + len <= vma->vm_start)
2224+ if (check_heap_stack_gap(vma, addr, len))
2225 goto success;
2226 addr = vma->vm_end;
2227 }
2228@@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2229 for (; vma; vma = vma->vm_next) {
2230 if (addr > limit)
2231 break;
2232- if (addr + len <= vma->vm_start)
2233+ if (check_heap_stack_gap(vma, addr, len))
2234 goto success;
2235 addr = vma->vm_end;
2236 }
2237diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2238index c635028..6d9445a 100644
2239--- a/arch/h8300/include/asm/cache.h
2240+++ b/arch/h8300/include/asm/cache.h
2241@@ -1,8 +1,10 @@
2242 #ifndef __ARCH_H8300_CACHE_H
2243 #define __ARCH_H8300_CACHE_H
2244
2245+#include <linux/const.h>
2246+
2247 /* bytes per L1 cache line */
2248-#define L1_CACHE_BYTES 4
2249+#define L1_CACHE_BYTES _AC(4,UL)
2250
2251 /* m68k-elf-gcc 2.95.2 doesn't like these */
2252
2253diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2254index 0f01de2..d37d309 100644
2255--- a/arch/hexagon/include/asm/cache.h
2256+++ b/arch/hexagon/include/asm/cache.h
2257@@ -21,9 +21,11 @@
2258 #ifndef __ASM_CACHE_H
2259 #define __ASM_CACHE_H
2260
2261+#include <linux/const.h>
2262+
2263 /* Bytes per L1 cache line */
2264-#define L1_CACHE_SHIFT (5)
2265-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2266+#define L1_CACHE_SHIFT 5
2267+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2268
2269 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2270 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2271diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2272index 3fad89e..3047da5 100644
2273--- a/arch/ia64/include/asm/atomic.h
2274+++ b/arch/ia64/include/asm/atomic.h
2275@@ -209,6 +209,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2276 #define atomic64_inc(v) atomic64_add(1, (v))
2277 #define atomic64_dec(v) atomic64_sub(1, (v))
2278
2279+#define atomic64_read_unchecked(v) atomic64_read(v)
2280+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2281+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2282+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2283+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2284+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2285+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2286+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2287+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2288+
2289 /* Atomic operations are already serializing */
2290 #define smp_mb__before_atomic_dec() barrier()
2291 #define smp_mb__after_atomic_dec() barrier()
2292diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2293index 988254a..e1ee885 100644
2294--- a/arch/ia64/include/asm/cache.h
2295+++ b/arch/ia64/include/asm/cache.h
2296@@ -1,6 +1,7 @@
2297 #ifndef _ASM_IA64_CACHE_H
2298 #define _ASM_IA64_CACHE_H
2299
2300+#include <linux/const.h>
2301
2302 /*
2303 * Copyright (C) 1998-2000 Hewlett-Packard Co
2304@@ -9,7 +10,7 @@
2305
2306 /* Bytes per L1 (data) cache line. */
2307 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2308-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2309+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2310
2311 #ifdef CONFIG_SMP
2312 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2313diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2314index b5298eb..67c6e62 100644
2315--- a/arch/ia64/include/asm/elf.h
2316+++ b/arch/ia64/include/asm/elf.h
2317@@ -42,6 +42,13 @@
2318 */
2319 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2320
2321+#ifdef CONFIG_PAX_ASLR
2322+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2323+
2324+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2325+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2326+#endif
2327+
2328 #define PT_IA_64_UNWIND 0x70000001
2329
2330 /* IA-64 relocations: */
2331diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2332index 96a8d92..617a1cf 100644
2333--- a/arch/ia64/include/asm/pgalloc.h
2334+++ b/arch/ia64/include/asm/pgalloc.h
2335@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2336 pgd_val(*pgd_entry) = __pa(pud);
2337 }
2338
2339+static inline void
2340+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2341+{
2342+ pgd_populate(mm, pgd_entry, pud);
2343+}
2344+
2345 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2346 {
2347 return quicklist_alloc(0, GFP_KERNEL, NULL);
2348@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2349 pud_val(*pud_entry) = __pa(pmd);
2350 }
2351
2352+static inline void
2353+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2354+{
2355+ pud_populate(mm, pud_entry, pmd);
2356+}
2357+
2358 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2359 {
2360 return quicklist_alloc(0, GFP_KERNEL, NULL);
2361diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2362index 1a97af3..7529d31 100644
2363--- a/arch/ia64/include/asm/pgtable.h
2364+++ b/arch/ia64/include/asm/pgtable.h
2365@@ -12,7 +12,7 @@
2366 * David Mosberger-Tang <davidm@hpl.hp.com>
2367 */
2368
2369-
2370+#include <linux/const.h>
2371 #include <asm/mman.h>
2372 #include <asm/page.h>
2373 #include <asm/processor.h>
2374@@ -143,6 +143,17 @@
2375 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2376 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2377 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2378+
2379+#ifdef CONFIG_PAX_PAGEEXEC
2380+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2381+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2382+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2383+#else
2384+# define PAGE_SHARED_NOEXEC PAGE_SHARED
2385+# define PAGE_READONLY_NOEXEC PAGE_READONLY
2386+# define PAGE_COPY_NOEXEC PAGE_COPY
2387+#endif
2388+
2389 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2390 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2391 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2392diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2393index b77768d..e0795eb 100644
2394--- a/arch/ia64/include/asm/spinlock.h
2395+++ b/arch/ia64/include/asm/spinlock.h
2396@@ -72,7 +72,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2397 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2398
2399 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2400- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2401+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2402 }
2403
2404 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2405diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2406index 449c8c0..432a3d2 100644
2407--- a/arch/ia64/include/asm/uaccess.h
2408+++ b/arch/ia64/include/asm/uaccess.h
2409@@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2410 const void *__cu_from = (from); \
2411 long __cu_len = (n); \
2412 \
2413- if (__access_ok(__cu_to, __cu_len, get_fs())) \
2414+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2415 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2416 __cu_len; \
2417 })
2418@@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2419 long __cu_len = (n); \
2420 \
2421 __chk_user_ptr(__cu_from); \
2422- if (__access_ok(__cu_from, __cu_len, get_fs())) \
2423+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2424 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2425 __cu_len; \
2426 })
2427diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2428index 24603be..948052d 100644
2429--- a/arch/ia64/kernel/module.c
2430+++ b/arch/ia64/kernel/module.c
2431@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2432 void
2433 module_free (struct module *mod, void *module_region)
2434 {
2435- if (mod && mod->arch.init_unw_table &&
2436- module_region == mod->module_init) {
2437+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2438 unw_remove_unwind_table(mod->arch.init_unw_table);
2439 mod->arch.init_unw_table = NULL;
2440 }
2441@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2442 }
2443
2444 static inline int
2445+in_init_rx (const struct module *mod, uint64_t addr)
2446+{
2447+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2448+}
2449+
2450+static inline int
2451+in_init_rw (const struct module *mod, uint64_t addr)
2452+{
2453+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2454+}
2455+
2456+static inline int
2457 in_init (const struct module *mod, uint64_t addr)
2458 {
2459- return addr - (uint64_t) mod->module_init < mod->init_size;
2460+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2461+}
2462+
2463+static inline int
2464+in_core_rx (const struct module *mod, uint64_t addr)
2465+{
2466+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2467+}
2468+
2469+static inline int
2470+in_core_rw (const struct module *mod, uint64_t addr)
2471+{
2472+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2473 }
2474
2475 static inline int
2476 in_core (const struct module *mod, uint64_t addr)
2477 {
2478- return addr - (uint64_t) mod->module_core < mod->core_size;
2479+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2480 }
2481
2482 static inline int
2483@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2484 break;
2485
2486 case RV_BDREL:
2487- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2488+ if (in_init_rx(mod, val))
2489+ val -= (uint64_t) mod->module_init_rx;
2490+ else if (in_init_rw(mod, val))
2491+ val -= (uint64_t) mod->module_init_rw;
2492+ else if (in_core_rx(mod, val))
2493+ val -= (uint64_t) mod->module_core_rx;
2494+ else if (in_core_rw(mod, val))
2495+ val -= (uint64_t) mod->module_core_rw;
2496 break;
2497
2498 case RV_LTV:
2499@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2500 * addresses have been selected...
2501 */
2502 uint64_t gp;
2503- if (mod->core_size > MAX_LTOFF)
2504+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2505 /*
2506 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2507 * at the end of the module.
2508 */
2509- gp = mod->core_size - MAX_LTOFF / 2;
2510+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2511 else
2512- gp = mod->core_size / 2;
2513- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2514+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2515+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2516 mod->arch.gp = gp;
2517 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2518 }
2519diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2520index 609d500..7dde2a8 100644
2521--- a/arch/ia64/kernel/sys_ia64.c
2522+++ b/arch/ia64/kernel/sys_ia64.c
2523@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2524 if (REGION_NUMBER(addr) == RGN_HPAGE)
2525 addr = 0;
2526 #endif
2527+
2528+#ifdef CONFIG_PAX_RANDMMAP
2529+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2530+ addr = mm->free_area_cache;
2531+ else
2532+#endif
2533+
2534 if (!addr)
2535 addr = mm->free_area_cache;
2536
2537@@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2538 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2539 /* At this point: (!vma || addr < vma->vm_end). */
2540 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2541- if (start_addr != TASK_UNMAPPED_BASE) {
2542+ if (start_addr != mm->mmap_base) {
2543 /* Start a new search --- just in case we missed some holes. */
2544- addr = TASK_UNMAPPED_BASE;
2545+ addr = mm->mmap_base;
2546 goto full_search;
2547 }
2548 return -ENOMEM;
2549 }
2550- if (!vma || addr + len <= vma->vm_start) {
2551+ if (check_heap_stack_gap(vma, addr, len)) {
2552 /* Remember the address where we stopped this search: */
2553 mm->free_area_cache = addr + len;
2554 return addr;
2555diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2556index 53c0ba0..2accdde 100644
2557--- a/arch/ia64/kernel/vmlinux.lds.S
2558+++ b/arch/ia64/kernel/vmlinux.lds.S
2559@@ -199,7 +199,7 @@ SECTIONS {
2560 /* Per-cpu data: */
2561 . = ALIGN(PERCPU_PAGE_SIZE);
2562 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2563- __phys_per_cpu_start = __per_cpu_load;
2564+ __phys_per_cpu_start = per_cpu_load;
2565 /*
2566 * ensure percpu data fits
2567 * into percpu page size
2568diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2569index 20b3593..1ce77f0 100644
2570--- a/arch/ia64/mm/fault.c
2571+++ b/arch/ia64/mm/fault.c
2572@@ -73,6 +73,23 @@ mapped_kernel_page_is_present (unsigned long address)
2573 return pte_present(pte);
2574 }
2575
2576+#ifdef CONFIG_PAX_PAGEEXEC
2577+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2578+{
2579+ unsigned long i;
2580+
2581+ printk(KERN_ERR "PAX: bytes at PC: ");
2582+ for (i = 0; i < 8; i++) {
2583+ unsigned int c;
2584+ if (get_user(c, (unsigned int *)pc+i))
2585+ printk(KERN_CONT "???????? ");
2586+ else
2587+ printk(KERN_CONT "%08x ", c);
2588+ }
2589+ printk("\n");
2590+}
2591+#endif
2592+
2593 void __kprobes
2594 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2595 {
2596@@ -146,9 +163,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2597 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2598 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2599
2600- if ((vma->vm_flags & mask) != mask)
2601+ if ((vma->vm_flags & mask) != mask) {
2602+
2603+#ifdef CONFIG_PAX_PAGEEXEC
2604+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2605+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2606+ goto bad_area;
2607+
2608+ up_read(&mm->mmap_sem);
2609+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2610+ do_group_exit(SIGKILL);
2611+ }
2612+#endif
2613+
2614 goto bad_area;
2615
2616+ }
2617+
2618 /*
2619 * If for any reason at all we couldn't handle the fault, make
2620 * sure we exit gracefully rather than endlessly redo the
2621diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2622index 5ca674b..e0e1b70 100644
2623--- a/arch/ia64/mm/hugetlbpage.c
2624+++ b/arch/ia64/mm/hugetlbpage.c
2625@@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2626 /* At this point: (!vmm || addr < vmm->vm_end). */
2627 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2628 return -ENOMEM;
2629- if (!vmm || (addr + len) <= vmm->vm_start)
2630+ if (check_heap_stack_gap(vmm, addr, len))
2631 return addr;
2632 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2633 }
2634diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2635index 13df239d..cb52116 100644
2636--- a/arch/ia64/mm/init.c
2637+++ b/arch/ia64/mm/init.c
2638@@ -121,6 +121,19 @@ ia64_init_addr_space (void)
2639 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2640 vma->vm_end = vma->vm_start + PAGE_SIZE;
2641 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2642+
2643+#ifdef CONFIG_PAX_PAGEEXEC
2644+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2645+ vma->vm_flags &= ~VM_EXEC;
2646+
2647+#ifdef CONFIG_PAX_MPROTECT
2648+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
2649+ vma->vm_flags &= ~VM_MAYEXEC;
2650+#endif
2651+
2652+ }
2653+#endif
2654+
2655 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2656 down_write(&current->mm->mmap_sem);
2657 if (insert_vm_struct(current->mm, vma)) {
2658diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2659index 40b3ee9..8c2c112 100644
2660--- a/arch/m32r/include/asm/cache.h
2661+++ b/arch/m32r/include/asm/cache.h
2662@@ -1,8 +1,10 @@
2663 #ifndef _ASM_M32R_CACHE_H
2664 #define _ASM_M32R_CACHE_H
2665
2666+#include <linux/const.h>
2667+
2668 /* L1 cache line size */
2669 #define L1_CACHE_SHIFT 4
2670-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2671+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2672
2673 #endif /* _ASM_M32R_CACHE_H */
2674diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2675index 82abd15..d95ae5d 100644
2676--- a/arch/m32r/lib/usercopy.c
2677+++ b/arch/m32r/lib/usercopy.c
2678@@ -14,6 +14,9 @@
2679 unsigned long
2680 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2681 {
2682+ if ((long)n < 0)
2683+ return n;
2684+
2685 prefetch(from);
2686 if (access_ok(VERIFY_WRITE, to, n))
2687 __copy_user(to,from,n);
2688@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2689 unsigned long
2690 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2691 {
2692+ if ((long)n < 0)
2693+ return n;
2694+
2695 prefetchw(to);
2696 if (access_ok(VERIFY_READ, from, n))
2697 __copy_user_zeroing(to,from,n);
2698diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2699index 0395c51..5f26031 100644
2700--- a/arch/m68k/include/asm/cache.h
2701+++ b/arch/m68k/include/asm/cache.h
2702@@ -4,9 +4,11 @@
2703 #ifndef __ARCH_M68K_CACHE_H
2704 #define __ARCH_M68K_CACHE_H
2705
2706+#include <linux/const.h>
2707+
2708 /* bytes per L1 cache line */
2709 #define L1_CACHE_SHIFT 4
2710-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2711+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2712
2713 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2714
2715diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2716index 4efe96a..60e8699 100644
2717--- a/arch/microblaze/include/asm/cache.h
2718+++ b/arch/microblaze/include/asm/cache.h
2719@@ -13,11 +13,12 @@
2720 #ifndef _ASM_MICROBLAZE_CACHE_H
2721 #define _ASM_MICROBLAZE_CACHE_H
2722
2723+#include <linux/const.h>
2724 #include <asm/registers.h>
2725
2726 #define L1_CACHE_SHIFT 5
2727 /* word-granular cache in microblaze */
2728-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2729+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2730
2731 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2732
2733diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2734index 1d93f81..67794d0 100644
2735--- a/arch/mips/include/asm/atomic.h
2736+++ b/arch/mips/include/asm/atomic.h
2737@@ -21,6 +21,10 @@
2738 #include <asm/war.h>
2739 #include <asm/system.h>
2740
2741+#ifdef CONFIG_GENERIC_ATOMIC64
2742+#include <asm-generic/atomic64.h>
2743+#endif
2744+
2745 #define ATOMIC_INIT(i) { (i) }
2746
2747 /*
2748@@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2749 */
2750 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2751
2752+#define atomic64_read_unchecked(v) atomic64_read(v)
2753+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2754+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2755+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2756+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2757+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2758+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2759+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2760+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2761+
2762 #endif /* CONFIG_64BIT */
2763
2764 /*
2765diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2766index b4db69f..8f3b093 100644
2767--- a/arch/mips/include/asm/cache.h
2768+++ b/arch/mips/include/asm/cache.h
2769@@ -9,10 +9,11 @@
2770 #ifndef _ASM_CACHE_H
2771 #define _ASM_CACHE_H
2772
2773+#include <linux/const.h>
2774 #include <kmalloc.h>
2775
2776 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2777-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2778+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2779
2780 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2781 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2782diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2783index 455c0ac..ad65fbe 100644
2784--- a/arch/mips/include/asm/elf.h
2785+++ b/arch/mips/include/asm/elf.h
2786@@ -372,13 +372,16 @@ extern const char *__elf_platform;
2787 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2788 #endif
2789
2790+#ifdef CONFIG_PAX_ASLR
2791+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2792+
2793+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2794+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2795+#endif
2796+
2797 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2798 struct linux_binprm;
2799 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2800 int uses_interp);
2801
2802-struct mm_struct;
2803-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2804-#define arch_randomize_brk arch_randomize_brk
2805-
2806 #endif /* _ASM_ELF_H */
2807diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2808index da9bd7d..91aa7ab 100644
2809--- a/arch/mips/include/asm/page.h
2810+++ b/arch/mips/include/asm/page.h
2811@@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2812 #ifdef CONFIG_CPU_MIPS32
2813 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2814 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2815- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2816+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2817 #else
2818 typedef struct { unsigned long long pte; } pte_t;
2819 #define pte_val(x) ((x).pte)
2820diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2821index 881d18b..cea38bc 100644
2822--- a/arch/mips/include/asm/pgalloc.h
2823+++ b/arch/mips/include/asm/pgalloc.h
2824@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2825 {
2826 set_pud(pud, __pud((unsigned long)pmd));
2827 }
2828+
2829+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2830+{
2831+ pud_populate(mm, pud, pmd);
2832+}
2833 #endif
2834
2835 /*
2836diff --git a/arch/mips/include/asm/system.h b/arch/mips/include/asm/system.h
2837index 6018c80..7c37203 100644
2838--- a/arch/mips/include/asm/system.h
2839+++ b/arch/mips/include/asm/system.h
2840@@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
2841 */
2842 #define __ARCH_WANT_UNLOCKED_CTXSW
2843
2844-extern unsigned long arch_align_stack(unsigned long sp);
2845+#define arch_align_stack(x) ((x) & ~0xfUL)
2846
2847 #endif /* _ASM_SYSTEM_H */
2848diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2849index 0d85d8e..ec71487 100644
2850--- a/arch/mips/include/asm/thread_info.h
2851+++ b/arch/mips/include/asm/thread_info.h
2852@@ -123,6 +123,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2853 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2854 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2855 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2856+/* li takes a 32bit immediate */
2857+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2858 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2859
2860 #ifdef CONFIG_MIPS32_O32
2861@@ -146,15 +148,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2862 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2863 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2864 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2865+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2866+
2867+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2868
2869 /* work to do in syscall_trace_leave() */
2870-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2871+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2872
2873 /* work to do on interrupt/exception return */
2874 #define _TIF_WORK_MASK (0x0000ffef & \
2875 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2876 /* work to do on any return to u-space */
2877-#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2878+#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2879
2880 #endif /* __KERNEL__ */
2881
2882diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2883index 9fdd8bc..4bd7f1a 100644
2884--- a/arch/mips/kernel/binfmt_elfn32.c
2885+++ b/arch/mips/kernel/binfmt_elfn32.c
2886@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2887 #undef ELF_ET_DYN_BASE
2888 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2889
2890+#ifdef CONFIG_PAX_ASLR
2891+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2892+
2893+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2894+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2895+#endif
2896+
2897 #include <asm/processor.h>
2898 #include <linux/module.h>
2899 #include <linux/elfcore.h>
2900diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2901index ff44823..97f8906 100644
2902--- a/arch/mips/kernel/binfmt_elfo32.c
2903+++ b/arch/mips/kernel/binfmt_elfo32.c
2904@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2905 #undef ELF_ET_DYN_BASE
2906 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2907
2908+#ifdef CONFIG_PAX_ASLR
2909+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2910+
2911+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2912+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2913+#endif
2914+
2915 #include <asm/processor.h>
2916
2917 /*
2918diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2919index 7955409..ceaea7c 100644
2920--- a/arch/mips/kernel/process.c
2921+++ b/arch/mips/kernel/process.c
2922@@ -483,15 +483,3 @@ unsigned long get_wchan(struct task_struct *task)
2923 out:
2924 return pc;
2925 }
2926-
2927-/*
2928- * Don't forget that the stack pointer must be aligned on a 8 bytes
2929- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2930- */
2931-unsigned long arch_align_stack(unsigned long sp)
2932-{
2933- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2934- sp -= get_random_int() & ~PAGE_MASK;
2935-
2936- return sp & ALMASK;
2937-}
2938diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2939index 7786b60..3e38c72 100644
2940--- a/arch/mips/kernel/ptrace.c
2941+++ b/arch/mips/kernel/ptrace.c
2942@@ -529,6 +529,10 @@ static inline int audit_arch(void)
2943 return arch;
2944 }
2945
2946+#ifdef CONFIG_GRKERNSEC_SETXID
2947+extern void gr_delayed_cred_worker(void);
2948+#endif
2949+
2950 /*
2951 * Notification of system call entry/exit
2952 * - triggered by current->work.syscall_trace
2953@@ -538,6 +542,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
2954 /* do the secure computing check first */
2955 secure_computing(regs->regs[2]);
2956
2957+#ifdef CONFIG_GRKERNSEC_SETXID
2958+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2959+ gr_delayed_cred_worker();
2960+#endif
2961+
2962 if (!(current->ptrace & PT_PTRACED))
2963 goto out;
2964
2965diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
2966index a632bc1..0b77c7c 100644
2967--- a/arch/mips/kernel/scall32-o32.S
2968+++ b/arch/mips/kernel/scall32-o32.S
2969@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
2970
2971 stack_done:
2972 lw t0, TI_FLAGS($28) # syscall tracing enabled?
2973- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
2974+ li t1, _TIF_SYSCALL_WORK
2975 and t0, t1
2976 bnez t0, syscall_trace_entry # -> yes
2977
2978diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
2979index 3b5a5e9..e1ee86d 100644
2980--- a/arch/mips/kernel/scall64-64.S
2981+++ b/arch/mips/kernel/scall64-64.S
2982@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
2983
2984 sd a3, PT_R26(sp) # save a3 for syscall restarting
2985
2986- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
2987+ li t1, _TIF_SYSCALL_WORK
2988 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
2989 and t0, t1, t0
2990 bnez t0, syscall_trace_entry
2991diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
2992index 6be6f70..1859577 100644
2993--- a/arch/mips/kernel/scall64-n32.S
2994+++ b/arch/mips/kernel/scall64-n32.S
2995@@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
2996
2997 sd a3, PT_R26(sp) # save a3 for syscall restarting
2998
2999- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3000+ li t1, _TIF_SYSCALL_WORK
3001 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3002 and t0, t1, t0
3003 bnez t0, n32_syscall_trace_entry
3004diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3005index 5422855..74e63a3 100644
3006--- a/arch/mips/kernel/scall64-o32.S
3007+++ b/arch/mips/kernel/scall64-o32.S
3008@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3009 PTR 4b, bad_stack
3010 .previous
3011
3012- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3013+ li t1, _TIF_SYSCALL_WORK
3014 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3015 and t0, t1, t0
3016 bnez t0, trace_a_syscall
3017diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3018index 69ebd58..e4bff83 100644
3019--- a/arch/mips/mm/fault.c
3020+++ b/arch/mips/mm/fault.c
3021@@ -28,6 +28,23 @@
3022 #include <asm/highmem.h> /* For VMALLOC_END */
3023 #include <linux/kdebug.h>
3024
3025+#ifdef CONFIG_PAX_PAGEEXEC
3026+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3027+{
3028+ unsigned long i;
3029+
3030+ printk(KERN_ERR "PAX: bytes at PC: ");
3031+ for (i = 0; i < 5; i++) {
3032+ unsigned int c;
3033+ if (get_user(c, (unsigned int *)pc+i))
3034+ printk(KERN_CONT "???????? ");
3035+ else
3036+ printk(KERN_CONT "%08x ", c);
3037+ }
3038+ printk("\n");
3039+}
3040+#endif
3041+
3042 /*
3043 * This routine handles page faults. It determines the address,
3044 * and the problem, and then passes it off to one of the appropriate
3045diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3046index 302d779..7d35bf8 100644
3047--- a/arch/mips/mm/mmap.c
3048+++ b/arch/mips/mm/mmap.c
3049@@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3050 do_color_align = 1;
3051
3052 /* requesting a specific address */
3053+
3054+#ifdef CONFIG_PAX_RANDMMAP
3055+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3056+#endif
3057+
3058 if (addr) {
3059 if (do_color_align)
3060 addr = COLOUR_ALIGN(addr, pgoff);
3061@@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3062 addr = PAGE_ALIGN(addr);
3063
3064 vma = find_vma(mm, addr);
3065- if (TASK_SIZE - len >= addr &&
3066- (!vma || addr + len <= vma->vm_start))
3067+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3068 return addr;
3069 }
3070
3071@@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3072 /* At this point: (!vma || addr < vma->vm_end). */
3073 if (TASK_SIZE - len < addr)
3074 return -ENOMEM;
3075- if (!vma || addr + len <= vma->vm_start)
3076+ if (check_heap_stack_gap(vmm, addr, len))
3077 return addr;
3078 addr = vma->vm_end;
3079 if (do_color_align)
3080@@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3081 /* make sure it can fit in the remaining address space */
3082 if (likely(addr > len)) {
3083 vma = find_vma(mm, addr - len);
3084- if (!vma || addr <= vma->vm_start) {
3085+ if (check_heap_stack_gap(vmm, addr - len, len))
3086 /* cache the address as a hint for next time */
3087 return mm->free_area_cache = addr - len;
3088 }
3089@@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3090 * return with success:
3091 */
3092 vma = find_vma(mm, addr);
3093- if (likely(!vma || addr + len <= vma->vm_start)) {
3094+ if (check_heap_stack_gap(vmm, addr, len)) {
3095 /* cache the address as a hint for next time */
3096 return mm->free_area_cache = addr;
3097 }
3098@@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3099 mm->unmap_area = arch_unmap_area_topdown;
3100 }
3101 }
3102-
3103-static inline unsigned long brk_rnd(void)
3104-{
3105- unsigned long rnd = get_random_int();
3106-
3107- rnd = rnd << PAGE_SHIFT;
3108- /* 8MB for 32bit, 256MB for 64bit */
3109- if (TASK_IS_32BIT_ADDR)
3110- rnd = rnd & 0x7ffffful;
3111- else
3112- rnd = rnd & 0xffffffful;
3113-
3114- return rnd;
3115-}
3116-
3117-unsigned long arch_randomize_brk(struct mm_struct *mm)
3118-{
3119- unsigned long base = mm->brk;
3120- unsigned long ret;
3121-
3122- ret = PAGE_ALIGN(base + brk_rnd());
3123-
3124- if (ret < mm->brk)
3125- return mm->brk;
3126-
3127- return ret;
3128-}
3129diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3130index 967d144..db12197 100644
3131--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3132+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3133@@ -11,12 +11,14 @@
3134 #ifndef _ASM_PROC_CACHE_H
3135 #define _ASM_PROC_CACHE_H
3136
3137+#include <linux/const.h>
3138+
3139 /* L1 cache */
3140
3141 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3142 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3143-#define L1_CACHE_BYTES 16 /* bytes per entry */
3144 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3145+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3146 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3147
3148 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3149diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3150index bcb5df2..84fabd2 100644
3151--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3152+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3153@@ -16,13 +16,15 @@
3154 #ifndef _ASM_PROC_CACHE_H
3155 #define _ASM_PROC_CACHE_H
3156
3157+#include <linux/const.h>
3158+
3159 /*
3160 * L1 cache
3161 */
3162 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3163 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3164-#define L1_CACHE_BYTES 32 /* bytes per entry */
3165 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3166+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3167 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3168
3169 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3170diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3171index 4ce7a01..449202a 100644
3172--- a/arch/openrisc/include/asm/cache.h
3173+++ b/arch/openrisc/include/asm/cache.h
3174@@ -19,11 +19,13 @@
3175 #ifndef __ASM_OPENRISC_CACHE_H
3176 #define __ASM_OPENRISC_CACHE_H
3177
3178+#include <linux/const.h>
3179+
3180 /* FIXME: How can we replace these with values from the CPU...
3181 * they shouldn't be hard-coded!
3182 */
3183
3184-#define L1_CACHE_BYTES 16
3185 #define L1_CACHE_SHIFT 4
3186+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3187
3188 #endif /* __ASM_OPENRISC_CACHE_H */
3189diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3190index 4054b31..a10c105 100644
3191--- a/arch/parisc/include/asm/atomic.h
3192+++ b/arch/parisc/include/asm/atomic.h
3193@@ -335,6 +335,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3194
3195 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3196
3197+#define atomic64_read_unchecked(v) atomic64_read(v)
3198+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3199+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3200+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3201+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3202+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3203+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3204+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3205+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3206+
3207 #endif /* !CONFIG_64BIT */
3208
3209
3210diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3211index 47f11c7..3420df2 100644
3212--- a/arch/parisc/include/asm/cache.h
3213+++ b/arch/parisc/include/asm/cache.h
3214@@ -5,6 +5,7 @@
3215 #ifndef __ARCH_PARISC_CACHE_H
3216 #define __ARCH_PARISC_CACHE_H
3217
3218+#include <linux/const.h>
3219
3220 /*
3221 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3222@@ -15,13 +16,13 @@
3223 * just ruin performance.
3224 */
3225 #ifdef CONFIG_PA20
3226-#define L1_CACHE_BYTES 64
3227 #define L1_CACHE_SHIFT 6
3228 #else
3229-#define L1_CACHE_BYTES 32
3230 #define L1_CACHE_SHIFT 5
3231 #endif
3232
3233+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3234+
3235 #ifndef __ASSEMBLY__
3236
3237 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3238diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3239index 19f6cb1..6c78cf2 100644
3240--- a/arch/parisc/include/asm/elf.h
3241+++ b/arch/parisc/include/asm/elf.h
3242@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3243
3244 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3245
3246+#ifdef CONFIG_PAX_ASLR
3247+#define PAX_ELF_ET_DYN_BASE 0x10000UL
3248+
3249+#define PAX_DELTA_MMAP_LEN 16
3250+#define PAX_DELTA_STACK_LEN 16
3251+#endif
3252+
3253 /* This yields a mask that user programs can use to figure out what
3254 instruction set this CPU supports. This could be done in user space,
3255 but it's not easy, and we've already done it here. */
3256diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3257index fc987a1..6e068ef 100644
3258--- a/arch/parisc/include/asm/pgalloc.h
3259+++ b/arch/parisc/include/asm/pgalloc.h
3260@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3261 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3262 }
3263
3264+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3265+{
3266+ pgd_populate(mm, pgd, pmd);
3267+}
3268+
3269 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3270 {
3271 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3272@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3273 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3274 #define pmd_free(mm, x) do { } while (0)
3275 #define pgd_populate(mm, pmd, pte) BUG()
3276+#define pgd_populate_kernel(mm, pmd, pte) BUG()
3277
3278 #endif
3279
3280diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3281index 22dadeb..f6c2be4 100644
3282--- a/arch/parisc/include/asm/pgtable.h
3283+++ b/arch/parisc/include/asm/pgtable.h
3284@@ -210,6 +210,17 @@ struct vm_area_struct;
3285 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3286 #define PAGE_COPY PAGE_EXECREAD
3287 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3288+
3289+#ifdef CONFIG_PAX_PAGEEXEC
3290+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3291+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3292+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3293+#else
3294+# define PAGE_SHARED_NOEXEC PAGE_SHARED
3295+# define PAGE_COPY_NOEXEC PAGE_COPY
3296+# define PAGE_READONLY_NOEXEC PAGE_READONLY
3297+#endif
3298+
3299 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3300 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3301 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3302diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3303index 5e34ccf..672bc9c 100644
3304--- a/arch/parisc/kernel/module.c
3305+++ b/arch/parisc/kernel/module.c
3306@@ -98,16 +98,38 @@
3307
3308 /* three functions to determine where in the module core
3309 * or init pieces the location is */
3310+static inline int in_init_rx(struct module *me, void *loc)
3311+{
3312+ return (loc >= me->module_init_rx &&
3313+ loc < (me->module_init_rx + me->init_size_rx));
3314+}
3315+
3316+static inline int in_init_rw(struct module *me, void *loc)
3317+{
3318+ return (loc >= me->module_init_rw &&
3319+ loc < (me->module_init_rw + me->init_size_rw));
3320+}
3321+
3322 static inline int in_init(struct module *me, void *loc)
3323 {
3324- return (loc >= me->module_init &&
3325- loc <= (me->module_init + me->init_size));
3326+ return in_init_rx(me, loc) || in_init_rw(me, loc);
3327+}
3328+
3329+static inline int in_core_rx(struct module *me, void *loc)
3330+{
3331+ return (loc >= me->module_core_rx &&
3332+ loc < (me->module_core_rx + me->core_size_rx));
3333+}
3334+
3335+static inline int in_core_rw(struct module *me, void *loc)
3336+{
3337+ return (loc >= me->module_core_rw &&
3338+ loc < (me->module_core_rw + me->core_size_rw));
3339 }
3340
3341 static inline int in_core(struct module *me, void *loc)
3342 {
3343- return (loc >= me->module_core &&
3344- loc <= (me->module_core + me->core_size));
3345+ return in_core_rx(me, loc) || in_core_rw(me, loc);
3346 }
3347
3348 static inline int in_local(struct module *me, void *loc)
3349@@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3350 }
3351
3352 /* align things a bit */
3353- me->core_size = ALIGN(me->core_size, 16);
3354- me->arch.got_offset = me->core_size;
3355- me->core_size += gots * sizeof(struct got_entry);
3356+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3357+ me->arch.got_offset = me->core_size_rw;
3358+ me->core_size_rw += gots * sizeof(struct got_entry);
3359
3360- me->core_size = ALIGN(me->core_size, 16);
3361- me->arch.fdesc_offset = me->core_size;
3362- me->core_size += fdescs * sizeof(Elf_Fdesc);
3363+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3364+ me->arch.fdesc_offset = me->core_size_rw;
3365+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3366
3367 me->arch.got_max = gots;
3368 me->arch.fdesc_max = fdescs;
3369@@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3370
3371 BUG_ON(value == 0);
3372
3373- got = me->module_core + me->arch.got_offset;
3374+ got = me->module_core_rw + me->arch.got_offset;
3375 for (i = 0; got[i].addr; i++)
3376 if (got[i].addr == value)
3377 goto out;
3378@@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3379 #ifdef CONFIG_64BIT
3380 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3381 {
3382- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3383+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3384
3385 if (!value) {
3386 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3387@@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3388
3389 /* Create new one */
3390 fdesc->addr = value;
3391- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3392+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3393 return (Elf_Addr)fdesc;
3394 }
3395 #endif /* CONFIG_64BIT */
3396@@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3397
3398 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3399 end = table + sechdrs[me->arch.unwind_section].sh_size;
3400- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3401+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3402
3403 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3404 me->arch.unwind_section, table, end, gp);
3405diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3406index c9b9322..02d8940 100644
3407--- a/arch/parisc/kernel/sys_parisc.c
3408+++ b/arch/parisc/kernel/sys_parisc.c
3409@@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3410 /* At this point: (!vma || addr < vma->vm_end). */
3411 if (TASK_SIZE - len < addr)
3412 return -ENOMEM;
3413- if (!vma || addr + len <= vma->vm_start)
3414+ if (check_heap_stack_gap(vma, addr, len))
3415 return addr;
3416 addr = vma->vm_end;
3417 }
3418@@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3419 /* At this point: (!vma || addr < vma->vm_end). */
3420 if (TASK_SIZE - len < addr)
3421 return -ENOMEM;
3422- if (!vma || addr + len <= vma->vm_start)
3423+ if (check_heap_stack_gap(vma, addr, len))
3424 return addr;
3425 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3426 if (addr < vma->vm_end) /* handle wraparound */
3427@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3428 if (flags & MAP_FIXED)
3429 return addr;
3430 if (!addr)
3431- addr = TASK_UNMAPPED_BASE;
3432+ addr = current->mm->mmap_base;
3433
3434 if (filp) {
3435 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3436diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3437index f19e660..414fe24 100644
3438--- a/arch/parisc/kernel/traps.c
3439+++ b/arch/parisc/kernel/traps.c
3440@@ -733,9 +733,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3441
3442 down_read(&current->mm->mmap_sem);
3443 vma = find_vma(current->mm,regs->iaoq[0]);
3444- if (vma && (regs->iaoq[0] >= vma->vm_start)
3445- && (vma->vm_flags & VM_EXEC)) {
3446-
3447+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3448 fault_address = regs->iaoq[0];
3449 fault_space = regs->iasq[0];
3450
3451diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3452index 18162ce..94de376 100644
3453--- a/arch/parisc/mm/fault.c
3454+++ b/arch/parisc/mm/fault.c
3455@@ -15,6 +15,7 @@
3456 #include <linux/sched.h>
3457 #include <linux/interrupt.h>
3458 #include <linux/module.h>
3459+#include <linux/unistd.h>
3460
3461 #include <asm/uaccess.h>
3462 #include <asm/traps.h>
3463@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3464 static unsigned long
3465 parisc_acctyp(unsigned long code, unsigned int inst)
3466 {
3467- if (code == 6 || code == 16)
3468+ if (code == 6 || code == 7 || code == 16)
3469 return VM_EXEC;
3470
3471 switch (inst & 0xf0000000) {
3472@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3473 }
3474 #endif
3475
3476+#ifdef CONFIG_PAX_PAGEEXEC
3477+/*
3478+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3479+ *
3480+ * returns 1 when task should be killed
3481+ * 2 when rt_sigreturn trampoline was detected
3482+ * 3 when unpatched PLT trampoline was detected
3483+ */
3484+static int pax_handle_fetch_fault(struct pt_regs *regs)
3485+{
3486+
3487+#ifdef CONFIG_PAX_EMUPLT
3488+ int err;
3489+
3490+ do { /* PaX: unpatched PLT emulation */
3491+ unsigned int bl, depwi;
3492+
3493+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3494+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3495+
3496+ if (err)
3497+ break;
3498+
3499+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3500+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3501+
3502+ err = get_user(ldw, (unsigned int *)addr);
3503+ err |= get_user(bv, (unsigned int *)(addr+4));
3504+ err |= get_user(ldw2, (unsigned int *)(addr+8));
3505+
3506+ if (err)
3507+ break;
3508+
3509+ if (ldw == 0x0E801096U &&
3510+ bv == 0xEAC0C000U &&
3511+ ldw2 == 0x0E881095U)
3512+ {
3513+ unsigned int resolver, map;
3514+
3515+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3516+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3517+ if (err)
3518+ break;
3519+
3520+ regs->gr[20] = instruction_pointer(regs)+8;
3521+ regs->gr[21] = map;
3522+ regs->gr[22] = resolver;
3523+ regs->iaoq[0] = resolver | 3UL;
3524+ regs->iaoq[1] = regs->iaoq[0] + 4;
3525+ return 3;
3526+ }
3527+ }
3528+ } while (0);
3529+#endif
3530+
3531+#ifdef CONFIG_PAX_EMUTRAMP
3532+
3533+#ifndef CONFIG_PAX_EMUSIGRT
3534+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3535+ return 1;
3536+#endif
3537+
3538+ do { /* PaX: rt_sigreturn emulation */
3539+ unsigned int ldi1, ldi2, bel, nop;
3540+
3541+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3542+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3543+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3544+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3545+
3546+ if (err)
3547+ break;
3548+
3549+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3550+ ldi2 == 0x3414015AU &&
3551+ bel == 0xE4008200U &&
3552+ nop == 0x08000240U)
3553+ {
3554+ regs->gr[25] = (ldi1 & 2) >> 1;
3555+ regs->gr[20] = __NR_rt_sigreturn;
3556+ regs->gr[31] = regs->iaoq[1] + 16;
3557+ regs->sr[0] = regs->iasq[1];
3558+ regs->iaoq[0] = 0x100UL;
3559+ regs->iaoq[1] = regs->iaoq[0] + 4;
3560+ regs->iasq[0] = regs->sr[2];
3561+ regs->iasq[1] = regs->sr[2];
3562+ return 2;
3563+ }
3564+ } while (0);
3565+#endif
3566+
3567+ return 1;
3568+}
3569+
3570+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3571+{
3572+ unsigned long i;
3573+
3574+ printk(KERN_ERR "PAX: bytes at PC: ");
3575+ for (i = 0; i < 5; i++) {
3576+ unsigned int c;
3577+ if (get_user(c, (unsigned int *)pc+i))
3578+ printk(KERN_CONT "???????? ");
3579+ else
3580+ printk(KERN_CONT "%08x ", c);
3581+ }
3582+ printk("\n");
3583+}
3584+#endif
3585+
3586 int fixup_exception(struct pt_regs *regs)
3587 {
3588 const struct exception_table_entry *fix;
3589@@ -192,8 +303,33 @@ good_area:
3590
3591 acc_type = parisc_acctyp(code,regs->iir);
3592
3593- if ((vma->vm_flags & acc_type) != acc_type)
3594+ if ((vma->vm_flags & acc_type) != acc_type) {
3595+
3596+#ifdef CONFIG_PAX_PAGEEXEC
3597+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3598+ (address & ~3UL) == instruction_pointer(regs))
3599+ {
3600+ up_read(&mm->mmap_sem);
3601+ switch (pax_handle_fetch_fault(regs)) {
3602+
3603+#ifdef CONFIG_PAX_EMUPLT
3604+ case 3:
3605+ return;
3606+#endif
3607+
3608+#ifdef CONFIG_PAX_EMUTRAMP
3609+ case 2:
3610+ return;
3611+#endif
3612+
3613+ }
3614+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3615+ do_group_exit(SIGKILL);
3616+ }
3617+#endif
3618+
3619 goto bad_area;
3620+ }
3621
3622 /*
3623 * If for any reason at all we couldn't handle the fault, make
3624diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3625index 02e41b5..ec6e26c 100644
3626--- a/arch/powerpc/include/asm/atomic.h
3627+++ b/arch/powerpc/include/asm/atomic.h
3628@@ -469,6 +469,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3629
3630 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3631
3632+#define atomic64_read_unchecked(v) atomic64_read(v)
3633+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3634+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3635+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3636+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3637+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3638+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3639+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3640+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3641+
3642 #endif /* __powerpc64__ */
3643
3644 #endif /* __KERNEL__ */
3645diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3646index 4b50941..5605819 100644
3647--- a/arch/powerpc/include/asm/cache.h
3648+++ b/arch/powerpc/include/asm/cache.h
3649@@ -3,6 +3,7 @@
3650
3651 #ifdef __KERNEL__
3652
3653+#include <linux/const.h>
3654
3655 /* bytes per L1 cache line */
3656 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3657@@ -22,7 +23,7 @@
3658 #define L1_CACHE_SHIFT 7
3659 #endif
3660
3661-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3662+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3663
3664 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3665
3666diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3667index 3bf9cca..e7457d0 100644
3668--- a/arch/powerpc/include/asm/elf.h
3669+++ b/arch/powerpc/include/asm/elf.h
3670@@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3671 the loader. We need to make sure that it is out of the way of the program
3672 that it will "exec", and that there is sufficient room for the brk. */
3673
3674-extern unsigned long randomize_et_dyn(unsigned long base);
3675-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3676+#define ELF_ET_DYN_BASE (0x20000000)
3677+
3678+#ifdef CONFIG_PAX_ASLR
3679+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3680+
3681+#ifdef __powerpc64__
3682+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3683+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3684+#else
3685+#define PAX_DELTA_MMAP_LEN 15
3686+#define PAX_DELTA_STACK_LEN 15
3687+#endif
3688+#endif
3689
3690 /*
3691 * Our registers are always unsigned longs, whether we're a 32 bit
3692@@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3693 (0x7ff >> (PAGE_SHIFT - 12)) : \
3694 (0x3ffff >> (PAGE_SHIFT - 12)))
3695
3696-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3697-#define arch_randomize_brk arch_randomize_brk
3698-
3699 #endif /* __KERNEL__ */
3700
3701 /*
3702diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3703index bca8fdc..61e9580 100644
3704--- a/arch/powerpc/include/asm/kmap_types.h
3705+++ b/arch/powerpc/include/asm/kmap_types.h
3706@@ -27,6 +27,7 @@ enum km_type {
3707 KM_PPC_SYNC_PAGE,
3708 KM_PPC_SYNC_ICACHE,
3709 KM_KDB,
3710+ KM_CLEARPAGE,
3711 KM_TYPE_NR
3712 };
3713
3714diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3715index d4a7f64..451de1c 100644
3716--- a/arch/powerpc/include/asm/mman.h
3717+++ b/arch/powerpc/include/asm/mman.h
3718@@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3719 }
3720 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3721
3722-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3723+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3724 {
3725 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3726 }
3727diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3728index f072e97..b436dee 100644
3729--- a/arch/powerpc/include/asm/page.h
3730+++ b/arch/powerpc/include/asm/page.h
3731@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3732 * and needs to be executable. This means the whole heap ends
3733 * up being executable.
3734 */
3735-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3736- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3737+#define VM_DATA_DEFAULT_FLAGS32 \
3738+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3739+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3740
3741 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3742 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3743@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3744 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3745 #endif
3746
3747+#define ktla_ktva(addr) (addr)
3748+#define ktva_ktla(addr) (addr)
3749+
3750 /*
3751 * Use the top bit of the higher-level page table entries to indicate whether
3752 * the entries we point to contain hugepages. This works because we know that
3753diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3754index fed85e6..da5c71b 100644
3755--- a/arch/powerpc/include/asm/page_64.h
3756+++ b/arch/powerpc/include/asm/page_64.h
3757@@ -146,15 +146,18 @@ do { \
3758 * stack by default, so in the absence of a PT_GNU_STACK program header
3759 * we turn execute permission off.
3760 */
3761-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3762- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3763+#define VM_STACK_DEFAULT_FLAGS32 \
3764+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3765+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3766
3767 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3768 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3769
3770+#ifndef CONFIG_PAX_PAGEEXEC
3771 #define VM_STACK_DEFAULT_FLAGS \
3772 (is_32bit_task() ? \
3773 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3774+#endif
3775
3776 #include <asm-generic/getorder.h>
3777
3778diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3779index 292725c..f87ae14 100644
3780--- a/arch/powerpc/include/asm/pgalloc-64.h
3781+++ b/arch/powerpc/include/asm/pgalloc-64.h
3782@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3783 #ifndef CONFIG_PPC_64K_PAGES
3784
3785 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3786+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3787
3788 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3789 {
3790@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3791 pud_set(pud, (unsigned long)pmd);
3792 }
3793
3794+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3795+{
3796+ pud_populate(mm, pud, pmd);
3797+}
3798+
3799 #define pmd_populate(mm, pmd, pte_page) \
3800 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3801 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3802@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3803 #else /* CONFIG_PPC_64K_PAGES */
3804
3805 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3806+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3807
3808 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3809 pte_t *pte)
3810diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3811index 2e0e411..7899c68 100644
3812--- a/arch/powerpc/include/asm/pgtable.h
3813+++ b/arch/powerpc/include/asm/pgtable.h
3814@@ -2,6 +2,7 @@
3815 #define _ASM_POWERPC_PGTABLE_H
3816 #ifdef __KERNEL__
3817
3818+#include <linux/const.h>
3819 #ifndef __ASSEMBLY__
3820 #include <asm/processor.h> /* For TASK_SIZE */
3821 #include <asm/mmu.h>
3822diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3823index 4aad413..85d86bf 100644
3824--- a/arch/powerpc/include/asm/pte-hash32.h
3825+++ b/arch/powerpc/include/asm/pte-hash32.h
3826@@ -21,6 +21,7 @@
3827 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3828 #define _PAGE_USER 0x004 /* usermode access allowed */
3829 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3830+#define _PAGE_EXEC _PAGE_GUARDED
3831 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3832 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3833 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3834diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3835index 7fdc2c0..e47a9b02d3 100644
3836--- a/arch/powerpc/include/asm/reg.h
3837+++ b/arch/powerpc/include/asm/reg.h
3838@@ -212,6 +212,7 @@
3839 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3840 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3841 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3842+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3843 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3844 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3845 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3846diff --git a/arch/powerpc/include/asm/system.h b/arch/powerpc/include/asm/system.h
3847index c377457..3c69fbc 100644
3848--- a/arch/powerpc/include/asm/system.h
3849+++ b/arch/powerpc/include/asm/system.h
3850@@ -539,7 +539,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
3851 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
3852 #endif
3853
3854-extern unsigned long arch_align_stack(unsigned long sp);
3855+#define arch_align_stack(x) ((x) & ~0xfUL)
3856
3857 /* Used in very early kernel initialization. */
3858 extern unsigned long reloc_offset(void);
3859diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3860index 96471494..60ed5a2 100644
3861--- a/arch/powerpc/include/asm/thread_info.h
3862+++ b/arch/powerpc/include/asm/thread_info.h
3863@@ -104,13 +104,15 @@ static inline struct thread_info *current_thread_info(void)
3864 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3865 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3866 #define TIF_SINGLESTEP 8 /* singlestepping active */
3867-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3868 #define TIF_SECCOMP 10 /* secure computing */
3869 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3870 #define TIF_NOERROR 12 /* Force successful syscall return */
3871 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3872 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3873 #define TIF_RUNLATCH 16 /* Is the runlatch enabled? */
3874+#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
3875+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3876+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3877
3878 /* as above, but as bit values */
3879 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3880@@ -128,8 +130,11 @@ static inline struct thread_info *current_thread_info(void)
3881 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3882 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3883 #define _TIF_RUNLATCH (1<<TIF_RUNLATCH)
3884+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3885+
3886 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3887- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3888+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT \
3889+ _TIF_GRSEC_SETXID)
3890
3891 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3892 _TIF_NOTIFY_RESUME)
3893diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3894index bd0fb84..a42a14b 100644
3895--- a/arch/powerpc/include/asm/uaccess.h
3896+++ b/arch/powerpc/include/asm/uaccess.h
3897@@ -13,6 +13,8 @@
3898 #define VERIFY_READ 0
3899 #define VERIFY_WRITE 1
3900
3901+extern void check_object_size(const void *ptr, unsigned long n, bool to);
3902+
3903 /*
3904 * The fs value determines whether argument validity checking should be
3905 * performed or not. If get_fs() == USER_DS, checking is performed, with
3906@@ -327,52 +329,6 @@ do { \
3907 extern unsigned long __copy_tofrom_user(void __user *to,
3908 const void __user *from, unsigned long size);
3909
3910-#ifndef __powerpc64__
3911-
3912-static inline unsigned long copy_from_user(void *to,
3913- const void __user *from, unsigned long n)
3914-{
3915- unsigned long over;
3916-
3917- if (access_ok(VERIFY_READ, from, n))
3918- return __copy_tofrom_user((__force void __user *)to, from, n);
3919- if ((unsigned long)from < TASK_SIZE) {
3920- over = (unsigned long)from + n - TASK_SIZE;
3921- return __copy_tofrom_user((__force void __user *)to, from,
3922- n - over) + over;
3923- }
3924- return n;
3925-}
3926-
3927-static inline unsigned long copy_to_user(void __user *to,
3928- const void *from, unsigned long n)
3929-{
3930- unsigned long over;
3931-
3932- if (access_ok(VERIFY_WRITE, to, n))
3933- return __copy_tofrom_user(to, (__force void __user *)from, n);
3934- if ((unsigned long)to < TASK_SIZE) {
3935- over = (unsigned long)to + n - TASK_SIZE;
3936- return __copy_tofrom_user(to, (__force void __user *)from,
3937- n - over) + over;
3938- }
3939- return n;
3940-}
3941-
3942-#else /* __powerpc64__ */
3943-
3944-#define __copy_in_user(to, from, size) \
3945- __copy_tofrom_user((to), (from), (size))
3946-
3947-extern unsigned long copy_from_user(void *to, const void __user *from,
3948- unsigned long n);
3949-extern unsigned long copy_to_user(void __user *to, const void *from,
3950- unsigned long n);
3951-extern unsigned long copy_in_user(void __user *to, const void __user *from,
3952- unsigned long n);
3953-
3954-#endif /* __powerpc64__ */
3955-
3956 static inline unsigned long __copy_from_user_inatomic(void *to,
3957 const void __user *from, unsigned long n)
3958 {
3959@@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
3960 if (ret == 0)
3961 return 0;
3962 }
3963+
3964+ if (!__builtin_constant_p(n))
3965+ check_object_size(to, n, false);
3966+
3967 return __copy_tofrom_user((__force void __user *)to, from, n);
3968 }
3969
3970@@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
3971 if (ret == 0)
3972 return 0;
3973 }
3974+
3975+ if (!__builtin_constant_p(n))
3976+ check_object_size(from, n, true);
3977+
3978 return __copy_tofrom_user(to, (__force const void __user *)from, n);
3979 }
3980
3981@@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
3982 return __copy_to_user_inatomic(to, from, size);
3983 }
3984
3985+#ifndef __powerpc64__
3986+
3987+static inline unsigned long __must_check copy_from_user(void *to,
3988+ const void __user *from, unsigned long n)
3989+{
3990+ unsigned long over;
3991+
3992+ if ((long)n < 0)
3993+ return n;
3994+
3995+ if (access_ok(VERIFY_READ, from, n)) {
3996+ if (!__builtin_constant_p(n))
3997+ check_object_size(to, n, false);
3998+ return __copy_tofrom_user((__force void __user *)to, from, n);
3999+ }
4000+ if ((unsigned long)from < TASK_SIZE) {
4001+ over = (unsigned long)from + n - TASK_SIZE;
4002+ if (!__builtin_constant_p(n - over))
4003+ check_object_size(to, n - over, false);
4004+ return __copy_tofrom_user((__force void __user *)to, from,
4005+ n - over) + over;
4006+ }
4007+ return n;
4008+}
4009+
4010+static inline unsigned long __must_check copy_to_user(void __user *to,
4011+ const void *from, unsigned long n)
4012+{
4013+ unsigned long over;
4014+
4015+ if ((long)n < 0)
4016+ return n;
4017+
4018+ if (access_ok(VERIFY_WRITE, to, n)) {
4019+ if (!__builtin_constant_p(n))
4020+ check_object_size(from, n, true);
4021+ return __copy_tofrom_user(to, (__force void __user *)from, n);
4022+ }
4023+ if ((unsigned long)to < TASK_SIZE) {
4024+ over = (unsigned long)to + n - TASK_SIZE;
4025+ if (!__builtin_constant_p(n))
4026+ check_object_size(from, n - over, true);
4027+ return __copy_tofrom_user(to, (__force void __user *)from,
4028+ n - over) + over;
4029+ }
4030+ return n;
4031+}
4032+
4033+#else /* __powerpc64__ */
4034+
4035+#define __copy_in_user(to, from, size) \
4036+ __copy_tofrom_user((to), (from), (size))
4037+
4038+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4039+{
4040+ if ((long)n < 0 || n > INT_MAX)
4041+ return n;
4042+
4043+ if (!__builtin_constant_p(n))
4044+ check_object_size(to, n, false);
4045+
4046+ if (likely(access_ok(VERIFY_READ, from, n)))
4047+ n = __copy_from_user(to, from, n);
4048+ else
4049+ memset(to, 0, n);
4050+ return n;
4051+}
4052+
4053+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4054+{
4055+ if ((long)n < 0 || n > INT_MAX)
4056+ return n;
4057+
4058+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
4059+ if (!__builtin_constant_p(n))
4060+ check_object_size(from, n, true);
4061+ n = __copy_to_user(to, from, n);
4062+ }
4063+ return n;
4064+}
4065+
4066+extern unsigned long copy_in_user(void __user *to, const void __user *from,
4067+ unsigned long n);
4068+
4069+#endif /* __powerpc64__ */
4070+
4071 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4072
4073 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4074diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4075index 429983c..7af363b 100644
4076--- a/arch/powerpc/kernel/exceptions-64e.S
4077+++ b/arch/powerpc/kernel/exceptions-64e.S
4078@@ -587,6 +587,7 @@ storage_fault_common:
4079 std r14,_DAR(r1)
4080 std r15,_DSISR(r1)
4081 addi r3,r1,STACK_FRAME_OVERHEAD
4082+ bl .save_nvgprs
4083 mr r4,r14
4084 mr r5,r15
4085 ld r14,PACA_EXGEN+EX_R14(r13)
4086@@ -596,8 +597,7 @@ storage_fault_common:
4087 cmpdi r3,0
4088 bne- 1f
4089 b .ret_from_except_lite
4090-1: bl .save_nvgprs
4091- mr r5,r3
4092+1: mr r5,r3
4093 addi r3,r1,STACK_FRAME_OVERHEAD
4094 ld r4,_DAR(r1)
4095 bl .bad_page_fault
4096diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4097index 15c5a4f..22a4000 100644
4098--- a/arch/powerpc/kernel/exceptions-64s.S
4099+++ b/arch/powerpc/kernel/exceptions-64s.S
4100@@ -1004,10 +1004,10 @@ handle_page_fault:
4101 11: ld r4,_DAR(r1)
4102 ld r5,_DSISR(r1)
4103 addi r3,r1,STACK_FRAME_OVERHEAD
4104+ bl .save_nvgprs
4105 bl .do_page_fault
4106 cmpdi r3,0
4107 beq+ 13f
4108- bl .save_nvgprs
4109 mr r5,r3
4110 addi r3,r1,STACK_FRAME_OVERHEAD
4111 lwz r4,_DAR(r1)
4112diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
4113index 01e2877..a1ba360 100644
4114--- a/arch/powerpc/kernel/irq.c
4115+++ b/arch/powerpc/kernel/irq.c
4116@@ -560,9 +560,6 @@ struct irq_host *irq_alloc_host(struct device_node *of_node,
4117 host->ops = ops;
4118 host->of_node = of_node_get(of_node);
4119
4120- if (host->ops->match == NULL)
4121- host->ops->match = default_irq_host_match;
4122-
4123 raw_spin_lock_irqsave(&irq_big_lock, flags);
4124
4125 /* If it's a legacy controller, check for duplicates and
4126@@ -635,7 +632,12 @@ struct irq_host *irq_find_host(struct device_node *node)
4127 */
4128 raw_spin_lock_irqsave(&irq_big_lock, flags);
4129 list_for_each_entry(h, &irq_hosts, link)
4130- if (h->ops->match(h, node)) {
4131+ if (h->ops->match) {
4132+ if (h->ops->match(h, node)) {
4133+ found = h;
4134+ break;
4135+ }
4136+ } else if (default_irq_host_match(h, node)) {
4137 found = h;
4138 break;
4139 }
4140diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4141index 0b6d796..d760ddb 100644
4142--- a/arch/powerpc/kernel/module_32.c
4143+++ b/arch/powerpc/kernel/module_32.c
4144@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4145 me->arch.core_plt_section = i;
4146 }
4147 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4148- printk("Module doesn't contain .plt or .init.plt sections.\n");
4149+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4150 return -ENOEXEC;
4151 }
4152
4153@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4154
4155 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4156 /* Init, or core PLT? */
4157- if (location >= mod->module_core
4158- && location < mod->module_core + mod->core_size)
4159+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4160+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4161 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4162- else
4163+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4164+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4165 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4166+ else {
4167+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4168+ return ~0UL;
4169+ }
4170
4171 /* Find this entry, or if that fails, the next avail. entry */
4172 while (entry->jump[0]) {
4173diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4174index d817ab0..b23b18e 100644
4175--- a/arch/powerpc/kernel/process.c
4176+++ b/arch/powerpc/kernel/process.c
4177@@ -676,8 +676,8 @@ void show_regs(struct pt_regs * regs)
4178 * Lookup NIP late so we have the best change of getting the
4179 * above info out without failing
4180 */
4181- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4182- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4183+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4184+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4185 #endif
4186 show_stack(current, (unsigned long *) regs->gpr[1]);
4187 if (!user_mode(regs))
4188@@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4189 newsp = stack[0];
4190 ip = stack[STACK_FRAME_LR_SAVE];
4191 if (!firstframe || ip != lr) {
4192- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4193+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4194 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4195 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4196- printk(" (%pS)",
4197+ printk(" (%pA)",
4198 (void *)current->ret_stack[curr_frame].ret);
4199 curr_frame--;
4200 }
4201@@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4202 struct pt_regs *regs = (struct pt_regs *)
4203 (sp + STACK_FRAME_OVERHEAD);
4204 lr = regs->link;
4205- printk("--- Exception: %lx at %pS\n LR = %pS\n",
4206+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
4207 regs->trap, (void *)regs->nip, (void *)lr);
4208 firstframe = 1;
4209 }
4210@@ -1279,58 +1279,3 @@ void thread_info_cache_init(void)
4211 }
4212
4213 #endif /* THREAD_SHIFT < PAGE_SHIFT */
4214-
4215-unsigned long arch_align_stack(unsigned long sp)
4216-{
4217- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4218- sp -= get_random_int() & ~PAGE_MASK;
4219- return sp & ~0xf;
4220-}
4221-
4222-static inline unsigned long brk_rnd(void)
4223-{
4224- unsigned long rnd = 0;
4225-
4226- /* 8MB for 32bit, 1GB for 64bit */
4227- if (is_32bit_task())
4228- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4229- else
4230- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4231-
4232- return rnd << PAGE_SHIFT;
4233-}
4234-
4235-unsigned long arch_randomize_brk(struct mm_struct *mm)
4236-{
4237- unsigned long base = mm->brk;
4238- unsigned long ret;
4239-
4240-#ifdef CONFIG_PPC_STD_MMU_64
4241- /*
4242- * If we are using 1TB segments and we are allowed to randomise
4243- * the heap, we can put it above 1TB so it is backed by a 1TB
4244- * segment. Otherwise the heap will be in the bottom 1TB
4245- * which always uses 256MB segments and this may result in a
4246- * performance penalty.
4247- */
4248- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4249- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4250-#endif
4251-
4252- ret = PAGE_ALIGN(base + brk_rnd());
4253-
4254- if (ret < mm->brk)
4255- return mm->brk;
4256-
4257- return ret;
4258-}
4259-
4260-unsigned long randomize_et_dyn(unsigned long base)
4261-{
4262- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4263-
4264- if (ret < base)
4265- return base;
4266-
4267- return ret;
4268-}
4269diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4270index 5b43325..94a5bb4 100644
4271--- a/arch/powerpc/kernel/ptrace.c
4272+++ b/arch/powerpc/kernel/ptrace.c
4273@@ -1702,6 +1702,10 @@ long arch_ptrace(struct task_struct *child, long request,
4274 return ret;
4275 }
4276
4277+#ifdef CONFIG_GRKERNSEC_SETXID
4278+extern void gr_delayed_cred_worker(void);
4279+#endif
4280+
4281 /*
4282 * We must return the syscall number to actually look up in the table.
4283 * This can be -1L to skip running any syscall at all.
4284@@ -1712,6 +1716,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4285
4286 secure_computing(regs->gpr[0]);
4287
4288+#ifdef CONFIG_GRKERNSEC_SETXID
4289+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4290+ gr_delayed_cred_worker();
4291+#endif
4292+
4293 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4294 tracehook_report_syscall_entry(regs))
4295 /*
4296@@ -1746,6 +1755,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4297 {
4298 int step;
4299
4300+#ifdef CONFIG_GRKERNSEC_SETXID
4301+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4302+ gr_delayed_cred_worker();
4303+#endif
4304+
4305 audit_syscall_exit(regs);
4306
4307 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4308diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4309index 836a5a1..27289a3 100644
4310--- a/arch/powerpc/kernel/signal_32.c
4311+++ b/arch/powerpc/kernel/signal_32.c
4312@@ -859,7 +859,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4313 /* Save user registers on the stack */
4314 frame = &rt_sf->uc.uc_mcontext;
4315 addr = frame;
4316- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4317+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4318 if (save_user_regs(regs, frame, 0, 1))
4319 goto badframe;
4320 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4321diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4322index a50b5ec..547078a 100644
4323--- a/arch/powerpc/kernel/signal_64.c
4324+++ b/arch/powerpc/kernel/signal_64.c
4325@@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4326 current->thread.fpscr.val = 0;
4327
4328 /* Set up to return from userspace. */
4329- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4330+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4331 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4332 } else {
4333 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4334diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4335index c091527..5592625 100644
4336--- a/arch/powerpc/kernel/traps.c
4337+++ b/arch/powerpc/kernel/traps.c
4338@@ -131,6 +131,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4339 return flags;
4340 }
4341
4342+extern void gr_handle_kernel_exploit(void);
4343+
4344 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4345 int signr)
4346 {
4347@@ -178,6 +180,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4348 panic("Fatal exception in interrupt");
4349 if (panic_on_oops)
4350 panic("Fatal exception");
4351+
4352+ gr_handle_kernel_exploit();
4353+
4354 do_exit(signr);
4355 }
4356
4357diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4358index 7d14bb6..1305601 100644
4359--- a/arch/powerpc/kernel/vdso.c
4360+++ b/arch/powerpc/kernel/vdso.c
4361@@ -35,6 +35,7 @@
4362 #include <asm/firmware.h>
4363 #include <asm/vdso.h>
4364 #include <asm/vdso_datapage.h>
4365+#include <asm/mman.h>
4366
4367 #include "setup.h"
4368
4369@@ -219,7 +220,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4370 vdso_base = VDSO32_MBASE;
4371 #endif
4372
4373- current->mm->context.vdso_base = 0;
4374+ current->mm->context.vdso_base = ~0UL;
4375
4376 /* vDSO has a problem and was disabled, just don't "enable" it for the
4377 * process
4378@@ -239,7 +240,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4379 vdso_base = get_unmapped_area(NULL, vdso_base,
4380 (vdso_pages << PAGE_SHIFT) +
4381 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4382- 0, 0);
4383+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
4384 if (IS_ERR_VALUE(vdso_base)) {
4385 rc = vdso_base;
4386 goto fail_mmapsem;
4387diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4388index 5eea6f3..5d10396 100644
4389--- a/arch/powerpc/lib/usercopy_64.c
4390+++ b/arch/powerpc/lib/usercopy_64.c
4391@@ -9,22 +9,6 @@
4392 #include <linux/module.h>
4393 #include <asm/uaccess.h>
4394
4395-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4396-{
4397- if (likely(access_ok(VERIFY_READ, from, n)))
4398- n = __copy_from_user(to, from, n);
4399- else
4400- memset(to, 0, n);
4401- return n;
4402-}
4403-
4404-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4405-{
4406- if (likely(access_ok(VERIFY_WRITE, to, n)))
4407- n = __copy_to_user(to, from, n);
4408- return n;
4409-}
4410-
4411 unsigned long copy_in_user(void __user *to, const void __user *from,
4412 unsigned long n)
4413 {
4414@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4415 return n;
4416 }
4417
4418-EXPORT_SYMBOL(copy_from_user);
4419-EXPORT_SYMBOL(copy_to_user);
4420 EXPORT_SYMBOL(copy_in_user);
4421
4422diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4423index 2f0d1b0..36fb5cc 100644
4424--- a/arch/powerpc/mm/fault.c
4425+++ b/arch/powerpc/mm/fault.c
4426@@ -32,6 +32,10 @@
4427 #include <linux/perf_event.h>
4428 #include <linux/magic.h>
4429 #include <linux/ratelimit.h>
4430+#include <linux/slab.h>
4431+#include <linux/pagemap.h>
4432+#include <linux/compiler.h>
4433+#include <linux/unistd.h>
4434
4435 #include <asm/firmware.h>
4436 #include <asm/page.h>
4437@@ -43,6 +47,7 @@
4438 #include <asm/tlbflush.h>
4439 #include <asm/siginfo.h>
4440 #include <mm/mmu_decl.h>
4441+#include <asm/ptrace.h>
4442
4443 #include "icswx.h"
4444
4445@@ -68,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4446 }
4447 #endif
4448
4449+#ifdef CONFIG_PAX_PAGEEXEC
4450+/*
4451+ * PaX: decide what to do with offenders (regs->nip = fault address)
4452+ *
4453+ * returns 1 when task should be killed
4454+ */
4455+static int pax_handle_fetch_fault(struct pt_regs *regs)
4456+{
4457+ return 1;
4458+}
4459+
4460+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4461+{
4462+ unsigned long i;
4463+
4464+ printk(KERN_ERR "PAX: bytes at PC: ");
4465+ for (i = 0; i < 5; i++) {
4466+ unsigned int c;
4467+ if (get_user(c, (unsigned int __user *)pc+i))
4468+ printk(KERN_CONT "???????? ");
4469+ else
4470+ printk(KERN_CONT "%08x ", c);
4471+ }
4472+ printk("\n");
4473+}
4474+#endif
4475+
4476 /*
4477 * Check whether the instruction at regs->nip is a store using
4478 * an update addressing form which will update r1.
4479@@ -138,7 +170,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4480 * indicate errors in DSISR but can validly be set in SRR1.
4481 */
4482 if (trap == 0x400)
4483- error_code &= 0x48200000;
4484+ error_code &= 0x58200000;
4485 else
4486 is_write = error_code & DSISR_ISSTORE;
4487 #else
4488@@ -276,7 +308,7 @@ good_area:
4489 * "undefined". Of those that can be set, this is the only
4490 * one which seems bad.
4491 */
4492- if (error_code & 0x10000000)
4493+ if (error_code & DSISR_GUARDED)
4494 /* Guarded storage error. */
4495 goto bad_area;
4496 #endif /* CONFIG_8xx */
4497@@ -291,7 +323,7 @@ good_area:
4498 * processors use the same I/D cache coherency mechanism
4499 * as embedded.
4500 */
4501- if (error_code & DSISR_PROTFAULT)
4502+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4503 goto bad_area;
4504 #endif /* CONFIG_PPC_STD_MMU */
4505
4506@@ -360,6 +392,23 @@ bad_area:
4507 bad_area_nosemaphore:
4508 /* User mode accesses cause a SIGSEGV */
4509 if (user_mode(regs)) {
4510+
4511+#ifdef CONFIG_PAX_PAGEEXEC
4512+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4513+#ifdef CONFIG_PPC_STD_MMU
4514+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4515+#else
4516+ if (is_exec && regs->nip == address) {
4517+#endif
4518+ switch (pax_handle_fetch_fault(regs)) {
4519+ }
4520+
4521+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4522+ do_group_exit(SIGKILL);
4523+ }
4524+ }
4525+#endif
4526+
4527 _exception(SIGSEGV, regs, code, address);
4528 return 0;
4529 }
4530diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4531index 67a42ed..1c7210c 100644
4532--- a/arch/powerpc/mm/mmap_64.c
4533+++ b/arch/powerpc/mm/mmap_64.c
4534@@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4535 */
4536 if (mmap_is_legacy()) {
4537 mm->mmap_base = TASK_UNMAPPED_BASE;
4538+
4539+#ifdef CONFIG_PAX_RANDMMAP
4540+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4541+ mm->mmap_base += mm->delta_mmap;
4542+#endif
4543+
4544 mm->get_unmapped_area = arch_get_unmapped_area;
4545 mm->unmap_area = arch_unmap_area;
4546 } else {
4547 mm->mmap_base = mmap_base();
4548+
4549+#ifdef CONFIG_PAX_RANDMMAP
4550+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4551+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4552+#endif
4553+
4554 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4555 mm->unmap_area = arch_unmap_area_topdown;
4556 }
4557diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4558index 73709f7..6b90313 100644
4559--- a/arch/powerpc/mm/slice.c
4560+++ b/arch/powerpc/mm/slice.c
4561@@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4562 if ((mm->task_size - len) < addr)
4563 return 0;
4564 vma = find_vma(mm, addr);
4565- return (!vma || (addr + len) <= vma->vm_start);
4566+ return check_heap_stack_gap(vma, addr, len);
4567 }
4568
4569 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4570@@ -256,7 +256,7 @@ full_search:
4571 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4572 continue;
4573 }
4574- if (!vma || addr + len <= vma->vm_start) {
4575+ if (check_heap_stack_gap(vma, addr, len)) {
4576 /*
4577 * Remember the place where we stopped the search:
4578 */
4579@@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4580 }
4581 }
4582
4583- addr = mm->mmap_base;
4584- while (addr > len) {
4585+ if (mm->mmap_base < len)
4586+ addr = -ENOMEM;
4587+ else
4588+ addr = mm->mmap_base - len;
4589+
4590+ while (!IS_ERR_VALUE(addr)) {
4591 /* Go down by chunk size */
4592- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4593+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
4594
4595 /* Check for hit with different page size */
4596 mask = slice_range_to_mask(addr, len);
4597@@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4598 * return with success:
4599 */
4600 vma = find_vma(mm, addr);
4601- if (!vma || (addr + len) <= vma->vm_start) {
4602+ if (check_heap_stack_gap(vma, addr, len)) {
4603 /* remember the address as a hint for next time */
4604 if (use_cache)
4605 mm->free_area_cache = addr;
4606@@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4607 mm->cached_hole_size = vma->vm_start - addr;
4608
4609 /* try just below the current vma->vm_start */
4610- addr = vma->vm_start;
4611+ addr = skip_heap_stack_gap(vma, len);
4612 }
4613
4614 /*
4615@@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4616 if (fixed && addr > (mm->task_size - len))
4617 return -EINVAL;
4618
4619+#ifdef CONFIG_PAX_RANDMMAP
4620+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4621+ addr = 0;
4622+#endif
4623+
4624 /* If hint, make sure it matches our alignment restrictions */
4625 if (!fixed && addr) {
4626 addr = _ALIGN_UP(addr, 1ul << pshift);
4627diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4628index 8517d2a..d2738d4 100644
4629--- a/arch/s390/include/asm/atomic.h
4630+++ b/arch/s390/include/asm/atomic.h
4631@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4632 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4633 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4634
4635+#define atomic64_read_unchecked(v) atomic64_read(v)
4636+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4637+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4638+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4639+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4640+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4641+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4642+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4643+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4644+
4645 #define smp_mb__before_atomic_dec() smp_mb()
4646 #define smp_mb__after_atomic_dec() smp_mb()
4647 #define smp_mb__before_atomic_inc() smp_mb()
4648diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4649index 2a30d5a..5e5586f 100644
4650--- a/arch/s390/include/asm/cache.h
4651+++ b/arch/s390/include/asm/cache.h
4652@@ -11,8 +11,10 @@
4653 #ifndef __ARCH_S390_CACHE_H
4654 #define __ARCH_S390_CACHE_H
4655
4656-#define L1_CACHE_BYTES 256
4657+#include <linux/const.h>
4658+
4659 #define L1_CACHE_SHIFT 8
4660+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4661 #define NET_SKB_PAD 32
4662
4663 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4664diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4665index 547f1a6..0b22b53 100644
4666--- a/arch/s390/include/asm/elf.h
4667+++ b/arch/s390/include/asm/elf.h
4668@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
4669 the loader. We need to make sure that it is out of the way of the program
4670 that it will "exec", and that there is sufficient room for the brk. */
4671
4672-extern unsigned long randomize_et_dyn(unsigned long base);
4673-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4674+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4675+
4676+#ifdef CONFIG_PAX_ASLR
4677+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4678+
4679+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4680+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4681+#endif
4682
4683 /* This yields a mask that user programs can use to figure out what
4684 instruction set this CPU supports. */
4685@@ -211,7 +217,4 @@ struct linux_binprm;
4686 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4687 int arch_setup_additional_pages(struct linux_binprm *, int);
4688
4689-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4690-#define arch_randomize_brk arch_randomize_brk
4691-
4692 #endif
4693diff --git a/arch/s390/include/asm/system.h b/arch/s390/include/asm/system.h
4694index d73cc6b..1a296ad 100644
4695--- a/arch/s390/include/asm/system.h
4696+++ b/arch/s390/include/asm/system.h
4697@@ -260,7 +260,7 @@ extern void (*_machine_restart)(char *command);
4698 extern void (*_machine_halt)(void);
4699 extern void (*_machine_power_off)(void);
4700
4701-extern unsigned long arch_align_stack(unsigned long sp);
4702+#define arch_align_stack(x) ((x) & ~0xfUL)
4703
4704 static inline int tprot(unsigned long addr)
4705 {
4706diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4707index 2b23885..e136e31 100644
4708--- a/arch/s390/include/asm/uaccess.h
4709+++ b/arch/s390/include/asm/uaccess.h
4710@@ -235,6 +235,10 @@ static inline unsigned long __must_check
4711 copy_to_user(void __user *to, const void *from, unsigned long n)
4712 {
4713 might_fault();
4714+
4715+ if ((long)n < 0)
4716+ return n;
4717+
4718 if (access_ok(VERIFY_WRITE, to, n))
4719 n = __copy_to_user(to, from, n);
4720 return n;
4721@@ -260,6 +264,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4722 static inline unsigned long __must_check
4723 __copy_from_user(void *to, const void __user *from, unsigned long n)
4724 {
4725+ if ((long)n < 0)
4726+ return n;
4727+
4728 if (__builtin_constant_p(n) && (n <= 256))
4729 return uaccess.copy_from_user_small(n, from, to);
4730 else
4731@@ -294,6 +301,10 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
4732 unsigned int sz = __compiletime_object_size(to);
4733
4734 might_fault();
4735+
4736+ if ((long)n < 0)
4737+ return n;
4738+
4739 if (unlikely(sz != -1 && sz < n)) {
4740 copy_from_user_overflow();
4741 return n;
4742diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4743index dfcb343..eda788a 100644
4744--- a/arch/s390/kernel/module.c
4745+++ b/arch/s390/kernel/module.c
4746@@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4747
4748 /* Increase core size by size of got & plt and set start
4749 offsets for got and plt. */
4750- me->core_size = ALIGN(me->core_size, 4);
4751- me->arch.got_offset = me->core_size;
4752- me->core_size += me->arch.got_size;
4753- me->arch.plt_offset = me->core_size;
4754- me->core_size += me->arch.plt_size;
4755+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
4756+ me->arch.got_offset = me->core_size_rw;
4757+ me->core_size_rw += me->arch.got_size;
4758+ me->arch.plt_offset = me->core_size_rx;
4759+ me->core_size_rx += me->arch.plt_size;
4760 return 0;
4761 }
4762
4763@@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4764 if (info->got_initialized == 0) {
4765 Elf_Addr *gotent;
4766
4767- gotent = me->module_core + me->arch.got_offset +
4768+ gotent = me->module_core_rw + me->arch.got_offset +
4769 info->got_offset;
4770 *gotent = val;
4771 info->got_initialized = 1;
4772@@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4773 else if (r_type == R_390_GOTENT ||
4774 r_type == R_390_GOTPLTENT)
4775 *(unsigned int *) loc =
4776- (val + (Elf_Addr) me->module_core - loc) >> 1;
4777+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4778 else if (r_type == R_390_GOT64 ||
4779 r_type == R_390_GOTPLT64)
4780 *(unsigned long *) loc = val;
4781@@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4782 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4783 if (info->plt_initialized == 0) {
4784 unsigned int *ip;
4785- ip = me->module_core + me->arch.plt_offset +
4786+ ip = me->module_core_rx + me->arch.plt_offset +
4787 info->plt_offset;
4788 #ifndef CONFIG_64BIT
4789 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4790@@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4791 val - loc + 0xffffUL < 0x1ffffeUL) ||
4792 (r_type == R_390_PLT32DBL &&
4793 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4794- val = (Elf_Addr) me->module_core +
4795+ val = (Elf_Addr) me->module_core_rx +
4796 me->arch.plt_offset +
4797 info->plt_offset;
4798 val += rela->r_addend - loc;
4799@@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4800 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4801 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4802 val = val + rela->r_addend -
4803- ((Elf_Addr) me->module_core + me->arch.got_offset);
4804+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4805 if (r_type == R_390_GOTOFF16)
4806 *(unsigned short *) loc = val;
4807 else if (r_type == R_390_GOTOFF32)
4808@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4809 break;
4810 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4811 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4812- val = (Elf_Addr) me->module_core + me->arch.got_offset +
4813+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4814 rela->r_addend - loc;
4815 if (r_type == R_390_GOTPC)
4816 *(unsigned int *) loc = val;
4817diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4818index e795933..b32563c 100644
4819--- a/arch/s390/kernel/process.c
4820+++ b/arch/s390/kernel/process.c
4821@@ -323,39 +323,3 @@ unsigned long get_wchan(struct task_struct *p)
4822 }
4823 return 0;
4824 }
4825-
4826-unsigned long arch_align_stack(unsigned long sp)
4827-{
4828- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4829- sp -= get_random_int() & ~PAGE_MASK;
4830- return sp & ~0xf;
4831-}
4832-
4833-static inline unsigned long brk_rnd(void)
4834-{
4835- /* 8MB for 32bit, 1GB for 64bit */
4836- if (is_32bit_task())
4837- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4838- else
4839- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4840-}
4841-
4842-unsigned long arch_randomize_brk(struct mm_struct *mm)
4843-{
4844- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4845-
4846- if (ret < mm->brk)
4847- return mm->brk;
4848- return ret;
4849-}
4850-
4851-unsigned long randomize_et_dyn(unsigned long base)
4852-{
4853- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4854-
4855- if (!(current->flags & PF_RANDOMIZE))
4856- return base;
4857- if (ret < base)
4858- return base;
4859- return ret;
4860-}
4861diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4862index a0155c0..34cc491 100644
4863--- a/arch/s390/mm/mmap.c
4864+++ b/arch/s390/mm/mmap.c
4865@@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4866 */
4867 if (mmap_is_legacy()) {
4868 mm->mmap_base = TASK_UNMAPPED_BASE;
4869+
4870+#ifdef CONFIG_PAX_RANDMMAP
4871+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4872+ mm->mmap_base += mm->delta_mmap;
4873+#endif
4874+
4875 mm->get_unmapped_area = arch_get_unmapped_area;
4876 mm->unmap_area = arch_unmap_area;
4877 } else {
4878 mm->mmap_base = mmap_base();
4879+
4880+#ifdef CONFIG_PAX_RANDMMAP
4881+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4882+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4883+#endif
4884+
4885 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4886 mm->unmap_area = arch_unmap_area_topdown;
4887 }
4888@@ -167,10 +179,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4889 */
4890 if (mmap_is_legacy()) {
4891 mm->mmap_base = TASK_UNMAPPED_BASE;
4892+
4893+#ifdef CONFIG_PAX_RANDMMAP
4894+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4895+ mm->mmap_base += mm->delta_mmap;
4896+#endif
4897+
4898 mm->get_unmapped_area = s390_get_unmapped_area;
4899 mm->unmap_area = arch_unmap_area;
4900 } else {
4901 mm->mmap_base = mmap_base();
4902+
4903+#ifdef CONFIG_PAX_RANDMMAP
4904+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4905+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4906+#endif
4907+
4908 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4909 mm->unmap_area = arch_unmap_area_topdown;
4910 }
4911diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4912index ae3d59f..f65f075 100644
4913--- a/arch/score/include/asm/cache.h
4914+++ b/arch/score/include/asm/cache.h
4915@@ -1,7 +1,9 @@
4916 #ifndef _ASM_SCORE_CACHE_H
4917 #define _ASM_SCORE_CACHE_H
4918
4919+#include <linux/const.h>
4920+
4921 #define L1_CACHE_SHIFT 4
4922-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4923+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4924
4925 #endif /* _ASM_SCORE_CACHE_H */
4926diff --git a/arch/score/include/asm/system.h b/arch/score/include/asm/system.h
4927index 589d5c7..669e274 100644
4928--- a/arch/score/include/asm/system.h
4929+++ b/arch/score/include/asm/system.h
4930@@ -17,7 +17,7 @@ do { \
4931 #define finish_arch_switch(prev) do {} while (0)
4932
4933 typedef void (*vi_handler_t)(void);
4934-extern unsigned long arch_align_stack(unsigned long sp);
4935+#define arch_align_stack(x) (x)
4936
4937 #define mb() barrier()
4938 #define rmb() barrier()
4939diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4940index 25d0803..d6c8e36 100644
4941--- a/arch/score/kernel/process.c
4942+++ b/arch/score/kernel/process.c
4943@@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4944
4945 return task_pt_regs(task)->cp0_epc;
4946 }
4947-
4948-unsigned long arch_align_stack(unsigned long sp)
4949-{
4950- return sp;
4951-}
4952diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4953index ef9e555..331bd29 100644
4954--- a/arch/sh/include/asm/cache.h
4955+++ b/arch/sh/include/asm/cache.h
4956@@ -9,10 +9,11 @@
4957 #define __ASM_SH_CACHE_H
4958 #ifdef __KERNEL__
4959
4960+#include <linux/const.h>
4961 #include <linux/init.h>
4962 #include <cpu/cache.h>
4963
4964-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4965+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4966
4967 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4968
4969diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4970index afeb710..d1d1289 100644
4971--- a/arch/sh/mm/mmap.c
4972+++ b/arch/sh/mm/mmap.c
4973@@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4974 addr = PAGE_ALIGN(addr);
4975
4976 vma = find_vma(mm, addr);
4977- if (TASK_SIZE - len >= addr &&
4978- (!vma || addr + len <= vma->vm_start))
4979+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4980 return addr;
4981 }
4982
4983@@ -106,7 +105,7 @@ full_search:
4984 }
4985 return -ENOMEM;
4986 }
4987- if (likely(!vma || addr + len <= vma->vm_start)) {
4988+ if (likely(check_heap_stack_gap(vma, addr, len))) {
4989 /*
4990 * Remember the place where we stopped the search:
4991 */
4992@@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4993 addr = PAGE_ALIGN(addr);
4994
4995 vma = find_vma(mm, addr);
4996- if (TASK_SIZE - len >= addr &&
4997- (!vma || addr + len <= vma->vm_start))
4998+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4999 return addr;
5000 }
5001
5002@@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5003 /* make sure it can fit in the remaining address space */
5004 if (likely(addr > len)) {
5005 vma = find_vma(mm, addr-len);
5006- if (!vma || addr <= vma->vm_start) {
5007+ if (check_heap_stack_gap(vma, addr - len, len)) {
5008 /* remember the address as a hint for next time */
5009 return (mm->free_area_cache = addr-len);
5010 }
5011@@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5012 if (unlikely(mm->mmap_base < len))
5013 goto bottomup;
5014
5015- addr = mm->mmap_base-len;
5016- if (do_colour_align)
5017- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5018+ addr = mm->mmap_base - len;
5019
5020 do {
5021+ if (do_colour_align)
5022+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5023 /*
5024 * Lookup failure means no vma is above this address,
5025 * else if new region fits below vma->vm_start,
5026 * return with success:
5027 */
5028 vma = find_vma(mm, addr);
5029- if (likely(!vma || addr+len <= vma->vm_start)) {
5030+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5031 /* remember the address as a hint for next time */
5032 return (mm->free_area_cache = addr);
5033 }
5034@@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5035 mm->cached_hole_size = vma->vm_start - addr;
5036
5037 /* try just below the current vma->vm_start */
5038- addr = vma->vm_start-len;
5039- if (do_colour_align)
5040- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5041- } while (likely(len < vma->vm_start));
5042+ addr = skip_heap_stack_gap(vma, len);
5043+ } while (!IS_ERR_VALUE(addr));
5044
5045 bottomup:
5046 /*
5047diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
5048index eddcfb3..b117d90 100644
5049--- a/arch/sparc/Makefile
5050+++ b/arch/sparc/Makefile
5051@@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
5052 # Export what is needed by arch/sparc/boot/Makefile
5053 export VMLINUX_INIT VMLINUX_MAIN
5054 VMLINUX_INIT := $(head-y) $(init-y)
5055-VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
5056+VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
5057 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
5058 VMLINUX_MAIN += $(drivers-y) $(net-y)
5059
5060diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5061index 9f421df..b81fc12 100644
5062--- a/arch/sparc/include/asm/atomic_64.h
5063+++ b/arch/sparc/include/asm/atomic_64.h
5064@@ -14,18 +14,40 @@
5065 #define ATOMIC64_INIT(i) { (i) }
5066
5067 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5068+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5069+{
5070+ return v->counter;
5071+}
5072 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5073+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5074+{
5075+ return v->counter;
5076+}
5077
5078 #define atomic_set(v, i) (((v)->counter) = i)
5079+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5080+{
5081+ v->counter = i;
5082+}
5083 #define atomic64_set(v, i) (((v)->counter) = i)
5084+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5085+{
5086+ v->counter = i;
5087+}
5088
5089 extern void atomic_add(int, atomic_t *);
5090+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5091 extern void atomic64_add(long, atomic64_t *);
5092+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5093 extern void atomic_sub(int, atomic_t *);
5094+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5095 extern void atomic64_sub(long, atomic64_t *);
5096+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5097
5098 extern int atomic_add_ret(int, atomic_t *);
5099+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5100 extern long atomic64_add_ret(long, atomic64_t *);
5101+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5102 extern int atomic_sub_ret(int, atomic_t *);
5103 extern long atomic64_sub_ret(long, atomic64_t *);
5104
5105@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5106 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5107
5108 #define atomic_inc_return(v) atomic_add_ret(1, v)
5109+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5110+{
5111+ return atomic_add_ret_unchecked(1, v);
5112+}
5113 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5114+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5115+{
5116+ return atomic64_add_ret_unchecked(1, v);
5117+}
5118
5119 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5120 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5121
5122 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5123+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5124+{
5125+ return atomic_add_ret_unchecked(i, v);
5126+}
5127 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5128+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5129+{
5130+ return atomic64_add_ret_unchecked(i, v);
5131+}
5132
5133 /*
5134 * atomic_inc_and_test - increment and test
5135@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5136 * other cases.
5137 */
5138 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5139+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5140+{
5141+ return atomic_inc_return_unchecked(v) == 0;
5142+}
5143 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5144
5145 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5146@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5147 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5148
5149 #define atomic_inc(v) atomic_add(1, v)
5150+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5151+{
5152+ atomic_add_unchecked(1, v);
5153+}
5154 #define atomic64_inc(v) atomic64_add(1, v)
5155+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5156+{
5157+ atomic64_add_unchecked(1, v);
5158+}
5159
5160 #define atomic_dec(v) atomic_sub(1, v)
5161+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5162+{
5163+ atomic_sub_unchecked(1, v);
5164+}
5165 #define atomic64_dec(v) atomic64_sub(1, v)
5166+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5167+{
5168+ atomic64_sub_unchecked(1, v);
5169+}
5170
5171 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5172 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5173
5174 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5175+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5176+{
5177+ return cmpxchg(&v->counter, old, new);
5178+}
5179 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5180+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5181+{
5182+ return xchg(&v->counter, new);
5183+}
5184
5185 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5186 {
5187- int c, old;
5188+ int c, old, new;
5189 c = atomic_read(v);
5190 for (;;) {
5191- if (unlikely(c == (u)))
5192+ if (unlikely(c == u))
5193 break;
5194- old = atomic_cmpxchg((v), c, c + (a));
5195+
5196+ asm volatile("addcc %2, %0, %0\n"
5197+
5198+#ifdef CONFIG_PAX_REFCOUNT
5199+ "tvs %%icc, 6\n"
5200+#endif
5201+
5202+ : "=r" (new)
5203+ : "0" (c), "ir" (a)
5204+ : "cc");
5205+
5206+ old = atomic_cmpxchg(v, c, new);
5207 if (likely(old == c))
5208 break;
5209 c = old;
5210@@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5211 #define atomic64_cmpxchg(v, o, n) \
5212 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5213 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5214+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5215+{
5216+ return xchg(&v->counter, new);
5217+}
5218
5219 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5220 {
5221- long c, old;
5222+ long c, old, new;
5223 c = atomic64_read(v);
5224 for (;;) {
5225- if (unlikely(c == (u)))
5226+ if (unlikely(c == u))
5227 break;
5228- old = atomic64_cmpxchg((v), c, c + (a));
5229+
5230+ asm volatile("addcc %2, %0, %0\n"
5231+
5232+#ifdef CONFIG_PAX_REFCOUNT
5233+ "tvs %%xcc, 6\n"
5234+#endif
5235+
5236+ : "=r" (new)
5237+ : "0" (c), "ir" (a)
5238+ : "cc");
5239+
5240+ old = atomic64_cmpxchg(v, c, new);
5241 if (likely(old == c))
5242 break;
5243 c = old;
5244 }
5245- return c != (u);
5246+ return c != u;
5247 }
5248
5249 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5250diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5251index 69358b5..9d0d492 100644
5252--- a/arch/sparc/include/asm/cache.h
5253+++ b/arch/sparc/include/asm/cache.h
5254@@ -7,10 +7,12 @@
5255 #ifndef _SPARC_CACHE_H
5256 #define _SPARC_CACHE_H
5257
5258+#include <linux/const.h>
5259+
5260 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5261
5262 #define L1_CACHE_SHIFT 5
5263-#define L1_CACHE_BYTES 32
5264+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5265
5266 #ifdef CONFIG_SPARC32
5267 #define SMP_CACHE_BYTES_SHIFT 5
5268diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5269index 4269ca6..e3da77f 100644
5270--- a/arch/sparc/include/asm/elf_32.h
5271+++ b/arch/sparc/include/asm/elf_32.h
5272@@ -114,6 +114,13 @@ typedef struct {
5273
5274 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5275
5276+#ifdef CONFIG_PAX_ASLR
5277+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5278+
5279+#define PAX_DELTA_MMAP_LEN 16
5280+#define PAX_DELTA_STACK_LEN 16
5281+#endif
5282+
5283 /* This yields a mask that user programs can use to figure out what
5284 instruction set this cpu supports. This can NOT be done in userspace
5285 on Sparc. */
5286diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5287index 7df8b7f..4946269 100644
5288--- a/arch/sparc/include/asm/elf_64.h
5289+++ b/arch/sparc/include/asm/elf_64.h
5290@@ -180,6 +180,13 @@ typedef struct {
5291 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5292 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5293
5294+#ifdef CONFIG_PAX_ASLR
5295+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5296+
5297+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5298+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5299+#endif
5300+
5301 extern unsigned long sparc64_elf_hwcap;
5302 #define ELF_HWCAP sparc64_elf_hwcap
5303
5304diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5305index ca2b344..c6084f89 100644
5306--- a/arch/sparc/include/asm/pgalloc_32.h
5307+++ b/arch/sparc/include/asm/pgalloc_32.h
5308@@ -37,6 +37,7 @@ BTFIXUPDEF_CALL(void, free_pgd_fast, pgd_t *)
5309 BTFIXUPDEF_CALL(void, pgd_set, pgd_t *, pmd_t *)
5310 #define pgd_set(pgdp,pmdp) BTFIXUP_CALL(pgd_set)(pgdp,pmdp)
5311 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5312+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5313
5314 BTFIXUPDEF_CALL(pmd_t *, pmd_alloc_one, struct mm_struct *, unsigned long)
5315 #define pmd_alloc_one(mm, address) BTFIXUP_CALL(pmd_alloc_one)(mm, address)
5316diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5317index 40b2d7a..22a665b 100644
5318--- a/arch/sparc/include/asm/pgalloc_64.h
5319+++ b/arch/sparc/include/asm/pgalloc_64.h
5320@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5321 }
5322
5323 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5324+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5325
5326 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5327 {
5328diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5329index a790cc6..091ed94 100644
5330--- a/arch/sparc/include/asm/pgtable_32.h
5331+++ b/arch/sparc/include/asm/pgtable_32.h
5332@@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
5333 BTFIXUPDEF_INT(page_none)
5334 BTFIXUPDEF_INT(page_copy)
5335 BTFIXUPDEF_INT(page_readonly)
5336+
5337+#ifdef CONFIG_PAX_PAGEEXEC
5338+BTFIXUPDEF_INT(page_shared_noexec)
5339+BTFIXUPDEF_INT(page_copy_noexec)
5340+BTFIXUPDEF_INT(page_readonly_noexec)
5341+#endif
5342+
5343 BTFIXUPDEF_INT(page_kernel)
5344
5345 #define PMD_SHIFT SUN4C_PMD_SHIFT
5346@@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
5347 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
5348 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
5349
5350+#ifdef CONFIG_PAX_PAGEEXEC
5351+extern pgprot_t PAGE_SHARED_NOEXEC;
5352+# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
5353+# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
5354+#else
5355+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5356+# define PAGE_COPY_NOEXEC PAGE_COPY
5357+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5358+#endif
5359+
5360 extern unsigned long page_kernel;
5361
5362 #ifdef MODULE
5363diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5364index f6ae2b2..b03ffc7 100644
5365--- a/arch/sparc/include/asm/pgtsrmmu.h
5366+++ b/arch/sparc/include/asm/pgtsrmmu.h
5367@@ -115,6 +115,13 @@
5368 SRMMU_EXEC | SRMMU_REF)
5369 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5370 SRMMU_EXEC | SRMMU_REF)
5371+
5372+#ifdef CONFIG_PAX_PAGEEXEC
5373+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5374+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5375+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5376+#endif
5377+
5378 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5379 SRMMU_DIRTY | SRMMU_REF)
5380
5381diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5382index 9689176..63c18ea 100644
5383--- a/arch/sparc/include/asm/spinlock_64.h
5384+++ b/arch/sparc/include/asm/spinlock_64.h
5385@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5386
5387 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5388
5389-static void inline arch_read_lock(arch_rwlock_t *lock)
5390+static inline void arch_read_lock(arch_rwlock_t *lock)
5391 {
5392 unsigned long tmp1, tmp2;
5393
5394 __asm__ __volatile__ (
5395 "1: ldsw [%2], %0\n"
5396 " brlz,pn %0, 2f\n"
5397-"4: add %0, 1, %1\n"
5398+"4: addcc %0, 1, %1\n"
5399+
5400+#ifdef CONFIG_PAX_REFCOUNT
5401+" tvs %%icc, 6\n"
5402+#endif
5403+
5404 " cas [%2], %0, %1\n"
5405 " cmp %0, %1\n"
5406 " bne,pn %%icc, 1b\n"
5407@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5408 " .previous"
5409 : "=&r" (tmp1), "=&r" (tmp2)
5410 : "r" (lock)
5411- : "memory");
5412+ : "memory", "cc");
5413 }
5414
5415-static int inline arch_read_trylock(arch_rwlock_t *lock)
5416+static inline int arch_read_trylock(arch_rwlock_t *lock)
5417 {
5418 int tmp1, tmp2;
5419
5420@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5421 "1: ldsw [%2], %0\n"
5422 " brlz,a,pn %0, 2f\n"
5423 " mov 0, %0\n"
5424-" add %0, 1, %1\n"
5425+" addcc %0, 1, %1\n"
5426+
5427+#ifdef CONFIG_PAX_REFCOUNT
5428+" tvs %%icc, 6\n"
5429+#endif
5430+
5431 " cas [%2], %0, %1\n"
5432 " cmp %0, %1\n"
5433 " bne,pn %%icc, 1b\n"
5434@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5435 return tmp1;
5436 }
5437
5438-static void inline arch_read_unlock(arch_rwlock_t *lock)
5439+static inline void arch_read_unlock(arch_rwlock_t *lock)
5440 {
5441 unsigned long tmp1, tmp2;
5442
5443 __asm__ __volatile__(
5444 "1: lduw [%2], %0\n"
5445-" sub %0, 1, %1\n"
5446+" subcc %0, 1, %1\n"
5447+
5448+#ifdef CONFIG_PAX_REFCOUNT
5449+" tvs %%icc, 6\n"
5450+#endif
5451+
5452 " cas [%2], %0, %1\n"
5453 " cmp %0, %1\n"
5454 " bne,pn %%xcc, 1b\n"
5455@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5456 : "memory");
5457 }
5458
5459-static void inline arch_write_lock(arch_rwlock_t *lock)
5460+static inline void arch_write_lock(arch_rwlock_t *lock)
5461 {
5462 unsigned long mask, tmp1, tmp2;
5463
5464@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5465 : "memory");
5466 }
5467
5468-static void inline arch_write_unlock(arch_rwlock_t *lock)
5469+static inline void arch_write_unlock(arch_rwlock_t *lock)
5470 {
5471 __asm__ __volatile__(
5472 " stw %%g0, [%0]"
5473@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5474 : "memory");
5475 }
5476
5477-static int inline arch_write_trylock(arch_rwlock_t *lock)
5478+static inline int arch_write_trylock(arch_rwlock_t *lock)
5479 {
5480 unsigned long mask, tmp1, tmp2, result;
5481
5482diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5483index c2a1080..21ed218 100644
5484--- a/arch/sparc/include/asm/thread_info_32.h
5485+++ b/arch/sparc/include/asm/thread_info_32.h
5486@@ -50,6 +50,8 @@ struct thread_info {
5487 unsigned long w_saved;
5488
5489 struct restart_block restart_block;
5490+
5491+ unsigned long lowest_stack;
5492 };
5493
5494 /*
5495diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5496index 01d057f..13a7d2f 100644
5497--- a/arch/sparc/include/asm/thread_info_64.h
5498+++ b/arch/sparc/include/asm/thread_info_64.h
5499@@ -63,6 +63,8 @@ struct thread_info {
5500 struct pt_regs *kern_una_regs;
5501 unsigned int kern_una_insn;
5502
5503+ unsigned long lowest_stack;
5504+
5505 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5506 };
5507
5508@@ -214,10 +216,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5509 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5510 /* flag bit 6 is available */
5511 #define TIF_32BIT 7 /* 32-bit binary */
5512-/* flag bit 8 is available */
5513+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5514 #define TIF_SECCOMP 9 /* secure computing */
5515 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5516 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5517+
5518 /* NOTE: Thread flags >= 12 should be ones we have no interest
5519 * in using in assembly, else we can't use the mask as
5520 * an immediate value in instructions such as andcc.
5521@@ -236,12 +239,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5522 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5523 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5524 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5525+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5526
5527 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5528 _TIF_DO_NOTIFY_RESUME_MASK | \
5529 _TIF_NEED_RESCHED)
5530 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5531
5532+#define _TIF_WORK_SYSCALL \
5533+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5534+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5535+
5536+
5537 /*
5538 * Thread-synchronous status.
5539 *
5540diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5541index e88fbe5..96b0ce5 100644
5542--- a/arch/sparc/include/asm/uaccess.h
5543+++ b/arch/sparc/include/asm/uaccess.h
5544@@ -1,5 +1,13 @@
5545 #ifndef ___ASM_SPARC_UACCESS_H
5546 #define ___ASM_SPARC_UACCESS_H
5547+
5548+#ifdef __KERNEL__
5549+#ifndef __ASSEMBLY__
5550+#include <linux/types.h>
5551+extern void check_object_size(const void *ptr, unsigned long n, bool to);
5552+#endif
5553+#endif
5554+
5555 #if defined(__sparc__) && defined(__arch64__)
5556 #include <asm/uaccess_64.h>
5557 #else
5558diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5559index 8303ac4..07f333d 100644
5560--- a/arch/sparc/include/asm/uaccess_32.h
5561+++ b/arch/sparc/include/asm/uaccess_32.h
5562@@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5563
5564 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5565 {
5566- if (n && __access_ok((unsigned long) to, n))
5567+ if ((long)n < 0)
5568+ return n;
5569+
5570+ if (n && __access_ok((unsigned long) to, n)) {
5571+ if (!__builtin_constant_p(n))
5572+ check_object_size(from, n, true);
5573 return __copy_user(to, (__force void __user *) from, n);
5574- else
5575+ } else
5576 return n;
5577 }
5578
5579 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5580 {
5581+ if ((long)n < 0)
5582+ return n;
5583+
5584+ if (!__builtin_constant_p(n))
5585+ check_object_size(from, n, true);
5586+
5587 return __copy_user(to, (__force void __user *) from, n);
5588 }
5589
5590 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5591 {
5592- if (n && __access_ok((unsigned long) from, n))
5593+ if ((long)n < 0)
5594+ return n;
5595+
5596+ if (n && __access_ok((unsigned long) from, n)) {
5597+ if (!__builtin_constant_p(n))
5598+ check_object_size(to, n, false);
5599 return __copy_user((__force void __user *) to, from, n);
5600- else
5601+ } else
5602 return n;
5603 }
5604
5605 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5606 {
5607+ if ((long)n < 0)
5608+ return n;
5609+
5610 return __copy_user((__force void __user *) to, from, n);
5611 }
5612
5613diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5614index 3e1449f..5293a0e 100644
5615--- a/arch/sparc/include/asm/uaccess_64.h
5616+++ b/arch/sparc/include/asm/uaccess_64.h
5617@@ -10,6 +10,7 @@
5618 #include <linux/compiler.h>
5619 #include <linux/string.h>
5620 #include <linux/thread_info.h>
5621+#include <linux/kernel.h>
5622 #include <asm/asi.h>
5623 #include <asm/system.h>
5624 #include <asm/spitfire.h>
5625@@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5626 static inline unsigned long __must_check
5627 copy_from_user(void *to, const void __user *from, unsigned long size)
5628 {
5629- unsigned long ret = ___copy_from_user(to, from, size);
5630+ unsigned long ret;
5631
5632+ if ((long)size < 0 || size > INT_MAX)
5633+ return size;
5634+
5635+ if (!__builtin_constant_p(size))
5636+ check_object_size(to, size, false);
5637+
5638+ ret = ___copy_from_user(to, from, size);
5639 if (unlikely(ret))
5640 ret = copy_from_user_fixup(to, from, size);
5641
5642@@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5643 static inline unsigned long __must_check
5644 copy_to_user(void __user *to, const void *from, unsigned long size)
5645 {
5646- unsigned long ret = ___copy_to_user(to, from, size);
5647+ unsigned long ret;
5648
5649+ if ((long)size < 0 || size > INT_MAX)
5650+ return size;
5651+
5652+ if (!__builtin_constant_p(size))
5653+ check_object_size(from, size, true);
5654+
5655+ ret = ___copy_to_user(to, from, size);
5656 if (unlikely(ret))
5657 ret = copy_to_user_fixup(to, from, size);
5658 return ret;
5659diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5660index cb85458..e063f17 100644
5661--- a/arch/sparc/kernel/Makefile
5662+++ b/arch/sparc/kernel/Makefile
5663@@ -3,7 +3,7 @@
5664 #
5665
5666 asflags-y := -ansi
5667-ccflags-y := -Werror
5668+#ccflags-y := -Werror
5669
5670 extra-y := head_$(BITS).o
5671 extra-y += init_task.o
5672diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5673index f793742..4d880af 100644
5674--- a/arch/sparc/kernel/process_32.c
5675+++ b/arch/sparc/kernel/process_32.c
5676@@ -204,7 +204,7 @@ void __show_backtrace(unsigned long fp)
5677 rw->ins[4], rw->ins[5],
5678 rw->ins[6],
5679 rw->ins[7]);
5680- printk("%pS\n", (void *) rw->ins[7]);
5681+ printk("%pA\n", (void *) rw->ins[7]);
5682 rw = (struct reg_window32 *) rw->ins[6];
5683 }
5684 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
5685@@ -271,14 +271,14 @@ void show_regs(struct pt_regs *r)
5686
5687 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5688 r->psr, r->pc, r->npc, r->y, print_tainted());
5689- printk("PC: <%pS>\n", (void *) r->pc);
5690+ printk("PC: <%pA>\n", (void *) r->pc);
5691 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5692 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5693 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5694 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5695 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5696 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5697- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5698+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5699
5700 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5701 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5702@@ -313,7 +313,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5703 rw = (struct reg_window32 *) fp;
5704 pc = rw->ins[7];
5705 printk("[%08lx : ", pc);
5706- printk("%pS ] ", (void *) pc);
5707+ printk("%pA ] ", (void *) pc);
5708 fp = rw->ins[6];
5709 } while (++count < 16);
5710 printk("\n");
5711diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5712index 39d8b05..d1a7d90 100644
5713--- a/arch/sparc/kernel/process_64.c
5714+++ b/arch/sparc/kernel/process_64.c
5715@@ -182,14 +182,14 @@ static void show_regwindow(struct pt_regs *regs)
5716 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5717 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5718 if (regs->tstate & TSTATE_PRIV)
5719- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5720+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5721 }
5722
5723 void show_regs(struct pt_regs *regs)
5724 {
5725 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5726 regs->tpc, regs->tnpc, regs->y, print_tainted());
5727- printk("TPC: <%pS>\n", (void *) regs->tpc);
5728+ printk("TPC: <%pA>\n", (void *) regs->tpc);
5729 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5730 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5731 regs->u_regs[3]);
5732@@ -202,7 +202,7 @@ void show_regs(struct pt_regs *regs)
5733 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5734 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5735 regs->u_regs[15]);
5736- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5737+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5738 show_regwindow(regs);
5739 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5740 }
5741@@ -287,7 +287,7 @@ void arch_trigger_all_cpu_backtrace(void)
5742 ((tp && tp->task) ? tp->task->pid : -1));
5743
5744 if (gp->tstate & TSTATE_PRIV) {
5745- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5746+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5747 (void *) gp->tpc,
5748 (void *) gp->o7,
5749 (void *) gp->i7,
5750diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5751index 9388844..0075fd2 100644
5752--- a/arch/sparc/kernel/ptrace_64.c
5753+++ b/arch/sparc/kernel/ptrace_64.c
5754@@ -1058,6 +1058,10 @@ long arch_ptrace(struct task_struct *child, long request,
5755 return ret;
5756 }
5757
5758+#ifdef CONFIG_GRKERNSEC_SETXID
5759+extern void gr_delayed_cred_worker(void);
5760+#endif
5761+
5762 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5763 {
5764 int ret = 0;
5765@@ -1065,6 +1069,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5766 /* do the secure computing check first */
5767 secure_computing(regs->u_regs[UREG_G1]);
5768
5769+#ifdef CONFIG_GRKERNSEC_SETXID
5770+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5771+ gr_delayed_cred_worker();
5772+#endif
5773+
5774 if (test_thread_flag(TIF_SYSCALL_TRACE))
5775 ret = tracehook_report_syscall_entry(regs);
5776
5777@@ -1085,6 +1094,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5778
5779 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5780 {
5781+#ifdef CONFIG_GRKERNSEC_SETXID
5782+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5783+ gr_delayed_cred_worker();
5784+#endif
5785+
5786 audit_syscall_exit(regs);
5787
5788 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5789diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5790index 42b282f..28ce9f2 100644
5791--- a/arch/sparc/kernel/sys_sparc_32.c
5792+++ b/arch/sparc/kernel/sys_sparc_32.c
5793@@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5794 if (ARCH_SUN4C && len > 0x20000000)
5795 return -ENOMEM;
5796 if (!addr)
5797- addr = TASK_UNMAPPED_BASE;
5798+ addr = current->mm->mmap_base;
5799
5800 if (flags & MAP_SHARED)
5801 addr = COLOUR_ALIGN(addr);
5802@@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5803 }
5804 if (TASK_SIZE - PAGE_SIZE - len < addr)
5805 return -ENOMEM;
5806- if (!vmm || addr + len <= vmm->vm_start)
5807+ if (check_heap_stack_gap(vmm, addr, len))
5808 return addr;
5809 addr = vmm->vm_end;
5810 if (flags & MAP_SHARED)
5811diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5812index 232df99..cee1f9c 100644
5813--- a/arch/sparc/kernel/sys_sparc_64.c
5814+++ b/arch/sparc/kernel/sys_sparc_64.c
5815@@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5816 /* We do not accept a shared mapping if it would violate
5817 * cache aliasing constraints.
5818 */
5819- if ((flags & MAP_SHARED) &&
5820+ if ((filp || (flags & MAP_SHARED)) &&
5821 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5822 return -EINVAL;
5823 return addr;
5824@@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5825 if (filp || (flags & MAP_SHARED))
5826 do_color_align = 1;
5827
5828+#ifdef CONFIG_PAX_RANDMMAP
5829+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5830+#endif
5831+
5832 if (addr) {
5833 if (do_color_align)
5834 addr = COLOUR_ALIGN(addr, pgoff);
5835@@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5836 addr = PAGE_ALIGN(addr);
5837
5838 vma = find_vma(mm, addr);
5839- if (task_size - len >= addr &&
5840- (!vma || addr + len <= vma->vm_start))
5841+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5842 return addr;
5843 }
5844
5845 if (len > mm->cached_hole_size) {
5846- start_addr = addr = mm->free_area_cache;
5847+ start_addr = addr = mm->free_area_cache;
5848 } else {
5849- start_addr = addr = TASK_UNMAPPED_BASE;
5850+ start_addr = addr = mm->mmap_base;
5851 mm->cached_hole_size = 0;
5852 }
5853
5854@@ -174,14 +177,14 @@ full_search:
5855 vma = find_vma(mm, VA_EXCLUDE_END);
5856 }
5857 if (unlikely(task_size < addr)) {
5858- if (start_addr != TASK_UNMAPPED_BASE) {
5859- start_addr = addr = TASK_UNMAPPED_BASE;
5860+ if (start_addr != mm->mmap_base) {
5861+ start_addr = addr = mm->mmap_base;
5862 mm->cached_hole_size = 0;
5863 goto full_search;
5864 }
5865 return -ENOMEM;
5866 }
5867- if (likely(!vma || addr + len <= vma->vm_start)) {
5868+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5869 /*
5870 * Remember the place where we stopped the search:
5871 */
5872@@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5873 /* We do not accept a shared mapping if it would violate
5874 * cache aliasing constraints.
5875 */
5876- if ((flags & MAP_SHARED) &&
5877+ if ((filp || (flags & MAP_SHARED)) &&
5878 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5879 return -EINVAL;
5880 return addr;
5881@@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5882 addr = PAGE_ALIGN(addr);
5883
5884 vma = find_vma(mm, addr);
5885- if (task_size - len >= addr &&
5886- (!vma || addr + len <= vma->vm_start))
5887+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5888 return addr;
5889 }
5890
5891@@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5892 /* make sure it can fit in the remaining address space */
5893 if (likely(addr > len)) {
5894 vma = find_vma(mm, addr-len);
5895- if (!vma || addr <= vma->vm_start) {
5896+ if (check_heap_stack_gap(vma, addr - len, len)) {
5897 /* remember the address as a hint for next time */
5898 return (mm->free_area_cache = addr-len);
5899 }
5900@@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5901 if (unlikely(mm->mmap_base < len))
5902 goto bottomup;
5903
5904- addr = mm->mmap_base-len;
5905- if (do_color_align)
5906- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5907+ addr = mm->mmap_base - len;
5908
5909 do {
5910+ if (do_color_align)
5911+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5912 /*
5913 * Lookup failure means no vma is above this address,
5914 * else if new region fits below vma->vm_start,
5915 * return with success:
5916 */
5917 vma = find_vma(mm, addr);
5918- if (likely(!vma || addr+len <= vma->vm_start)) {
5919+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5920 /* remember the address as a hint for next time */
5921 return (mm->free_area_cache = addr);
5922 }
5923@@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5924 mm->cached_hole_size = vma->vm_start - addr;
5925
5926 /* try just below the current vma->vm_start */
5927- addr = vma->vm_start-len;
5928- if (do_color_align)
5929- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5930- } while (likely(len < vma->vm_start));
5931+ addr = skip_heap_stack_gap(vma, len);
5932+ } while (!IS_ERR_VALUE(addr));
5933
5934 bottomup:
5935 /*
5936@@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5937 gap == RLIM_INFINITY ||
5938 sysctl_legacy_va_layout) {
5939 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5940+
5941+#ifdef CONFIG_PAX_RANDMMAP
5942+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5943+ mm->mmap_base += mm->delta_mmap;
5944+#endif
5945+
5946 mm->get_unmapped_area = arch_get_unmapped_area;
5947 mm->unmap_area = arch_unmap_area;
5948 } else {
5949@@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5950 gap = (task_size / 6 * 5);
5951
5952 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5953+
5954+#ifdef CONFIG_PAX_RANDMMAP
5955+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5956+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5957+#endif
5958+
5959 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5960 mm->unmap_area = arch_unmap_area_topdown;
5961 }
5962diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5963index 1d7e274..b39c527 100644
5964--- a/arch/sparc/kernel/syscalls.S
5965+++ b/arch/sparc/kernel/syscalls.S
5966@@ -62,7 +62,7 @@ sys32_rt_sigreturn:
5967 #endif
5968 .align 32
5969 1: ldx [%g6 + TI_FLAGS], %l5
5970- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5971+ andcc %l5, _TIF_WORK_SYSCALL, %g0
5972 be,pt %icc, rtrap
5973 nop
5974 call syscall_trace_leave
5975@@ -179,7 +179,7 @@ linux_sparc_syscall32:
5976
5977 srl %i5, 0, %o5 ! IEU1
5978 srl %i2, 0, %o2 ! IEU0 Group
5979- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5980+ andcc %l0, _TIF_WORK_SYSCALL, %g0
5981 bne,pn %icc, linux_syscall_trace32 ! CTI
5982 mov %i0, %l5 ! IEU1
5983 call %l7 ! CTI Group brk forced
5984@@ -202,7 +202,7 @@ linux_sparc_syscall:
5985
5986 mov %i3, %o3 ! IEU1
5987 mov %i4, %o4 ! IEU0 Group
5988- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5989+ andcc %l0, _TIF_WORK_SYSCALL, %g0
5990 bne,pn %icc, linux_syscall_trace ! CTI Group
5991 mov %i0, %l5 ! IEU0
5992 2: call %l7 ! CTI Group brk forced
5993@@ -226,7 +226,7 @@ ret_sys_call:
5994
5995 cmp %o0, -ERESTART_RESTARTBLOCK
5996 bgeu,pn %xcc, 1f
5997- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
5998+ andcc %l0, _TIF_WORK_SYSCALL, %l6
5999 80:
6000 /* System call success, clear Carry condition code. */
6001 andn %g3, %g2, %g3
6002@@ -241,7 +241,7 @@ ret_sys_call:
6003 /* System call failure, set Carry condition code.
6004 * Also, get abs(errno) to return to the process.
6005 */
6006- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6007+ andcc %l0, _TIF_WORK_SYSCALL, %l6
6008 sub %g0, %o0, %o0
6009 or %g3, %g2, %g3
6010 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6011diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6012index 591f20c..0f1b925 100644
6013--- a/arch/sparc/kernel/traps_32.c
6014+++ b/arch/sparc/kernel/traps_32.c
6015@@ -45,6 +45,8 @@ static void instruction_dump(unsigned long *pc)
6016 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6017 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6018
6019+extern void gr_handle_kernel_exploit(void);
6020+
6021 void die_if_kernel(char *str, struct pt_regs *regs)
6022 {
6023 static int die_counter;
6024@@ -77,15 +79,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6025 count++ < 30 &&
6026 (((unsigned long) rw) >= PAGE_OFFSET) &&
6027 !(((unsigned long) rw) & 0x7)) {
6028- printk("Caller[%08lx]: %pS\n", rw->ins[7],
6029+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
6030 (void *) rw->ins[7]);
6031 rw = (struct reg_window32 *)rw->ins[6];
6032 }
6033 }
6034 printk("Instruction DUMP:");
6035 instruction_dump ((unsigned long *) regs->pc);
6036- if(regs->psr & PSR_PS)
6037+ if(regs->psr & PSR_PS) {
6038+ gr_handle_kernel_exploit();
6039 do_exit(SIGKILL);
6040+ }
6041 do_exit(SIGSEGV);
6042 }
6043
6044diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6045index 0cbdaa4..438e4c9 100644
6046--- a/arch/sparc/kernel/traps_64.c
6047+++ b/arch/sparc/kernel/traps_64.c
6048@@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6049 i + 1,
6050 p->trapstack[i].tstate, p->trapstack[i].tpc,
6051 p->trapstack[i].tnpc, p->trapstack[i].tt);
6052- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6053+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6054 }
6055 }
6056
6057@@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6058
6059 lvl -= 0x100;
6060 if (regs->tstate & TSTATE_PRIV) {
6061+
6062+#ifdef CONFIG_PAX_REFCOUNT
6063+ if (lvl == 6)
6064+ pax_report_refcount_overflow(regs);
6065+#endif
6066+
6067 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6068 die_if_kernel(buffer, regs);
6069 }
6070@@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6071 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6072 {
6073 char buffer[32];
6074-
6075+
6076 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6077 0, lvl, SIGTRAP) == NOTIFY_STOP)
6078 return;
6079
6080+#ifdef CONFIG_PAX_REFCOUNT
6081+ if (lvl == 6)
6082+ pax_report_refcount_overflow(regs);
6083+#endif
6084+
6085 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6086
6087 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6088@@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6089 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6090 printk("%s" "ERROR(%d): ",
6091 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6092- printk("TPC<%pS>\n", (void *) regs->tpc);
6093+ printk("TPC<%pA>\n", (void *) regs->tpc);
6094 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6095 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6096 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6097@@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6098 smp_processor_id(),
6099 (type & 0x1) ? 'I' : 'D',
6100 regs->tpc);
6101- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6102+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6103 panic("Irrecoverable Cheetah+ parity error.");
6104 }
6105
6106@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6107 smp_processor_id(),
6108 (type & 0x1) ? 'I' : 'D',
6109 regs->tpc);
6110- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6111+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6112 }
6113
6114 struct sun4v_error_entry {
6115@@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6116
6117 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6118 regs->tpc, tl);
6119- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6120+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6121 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6122- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6123+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6124 (void *) regs->u_regs[UREG_I7]);
6125 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6126 "pte[%lx] error[%lx]\n",
6127@@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6128
6129 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6130 regs->tpc, tl);
6131- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6132+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6133 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6134- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6135+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6136 (void *) regs->u_regs[UREG_I7]);
6137 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6138 "pte[%lx] error[%lx]\n",
6139@@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6140 fp = (unsigned long)sf->fp + STACK_BIAS;
6141 }
6142
6143- printk(" [%016lx] %pS\n", pc, (void *) pc);
6144+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6145 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6146 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6147 int index = tsk->curr_ret_stack;
6148 if (tsk->ret_stack && index >= graph) {
6149 pc = tsk->ret_stack[index - graph].ret;
6150- printk(" [%016lx] %pS\n", pc, (void *) pc);
6151+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6152 graph++;
6153 }
6154 }
6155@@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6156 return (struct reg_window *) (fp + STACK_BIAS);
6157 }
6158
6159+extern void gr_handle_kernel_exploit(void);
6160+
6161 void die_if_kernel(char *str, struct pt_regs *regs)
6162 {
6163 static int die_counter;
6164@@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6165 while (rw &&
6166 count++ < 30 &&
6167 kstack_valid(tp, (unsigned long) rw)) {
6168- printk("Caller[%016lx]: %pS\n", rw->ins[7],
6169+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
6170 (void *) rw->ins[7]);
6171
6172 rw = kernel_stack_up(rw);
6173@@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6174 }
6175 user_instruction_dump ((unsigned int __user *) regs->tpc);
6176 }
6177- if (regs->tstate & TSTATE_PRIV)
6178+ if (regs->tstate & TSTATE_PRIV) {
6179+ gr_handle_kernel_exploit();
6180 do_exit(SIGKILL);
6181+ }
6182 do_exit(SIGSEGV);
6183 }
6184 EXPORT_SYMBOL(die_if_kernel);
6185diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6186index 76e4ac1..78f8bb1 100644
6187--- a/arch/sparc/kernel/unaligned_64.c
6188+++ b/arch/sparc/kernel/unaligned_64.c
6189@@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs *regs)
6190 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6191
6192 if (__ratelimit(&ratelimit)) {
6193- printk("Kernel unaligned access at TPC[%lx] %pS\n",
6194+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
6195 regs->tpc, (void *) regs->tpc);
6196 }
6197 }
6198diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6199index a3fc437..fea9957 100644
6200--- a/arch/sparc/lib/Makefile
6201+++ b/arch/sparc/lib/Makefile
6202@@ -2,7 +2,7 @@
6203 #
6204
6205 asflags-y := -ansi -DST_DIV0=0x02
6206-ccflags-y := -Werror
6207+#ccflags-y := -Werror
6208
6209 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
6210 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6211diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6212index 59186e0..f747d7a 100644
6213--- a/arch/sparc/lib/atomic_64.S
6214+++ b/arch/sparc/lib/atomic_64.S
6215@@ -18,7 +18,12 @@
6216 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6217 BACKOFF_SETUP(%o2)
6218 1: lduw [%o1], %g1
6219- add %g1, %o0, %g7
6220+ addcc %g1, %o0, %g7
6221+
6222+#ifdef CONFIG_PAX_REFCOUNT
6223+ tvs %icc, 6
6224+#endif
6225+
6226 cas [%o1], %g1, %g7
6227 cmp %g1, %g7
6228 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6229@@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6230 2: BACKOFF_SPIN(%o2, %o3, 1b)
6231 .size atomic_add, .-atomic_add
6232
6233+ .globl atomic_add_unchecked
6234+ .type atomic_add_unchecked,#function
6235+atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6236+ BACKOFF_SETUP(%o2)
6237+1: lduw [%o1], %g1
6238+ add %g1, %o0, %g7
6239+ cas [%o1], %g1, %g7
6240+ cmp %g1, %g7
6241+ bne,pn %icc, 2f
6242+ nop
6243+ retl
6244+ nop
6245+2: BACKOFF_SPIN(%o2, %o3, 1b)
6246+ .size atomic_add_unchecked, .-atomic_add_unchecked
6247+
6248 .globl atomic_sub
6249 .type atomic_sub,#function
6250 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6251 BACKOFF_SETUP(%o2)
6252 1: lduw [%o1], %g1
6253- sub %g1, %o0, %g7
6254+ subcc %g1, %o0, %g7
6255+
6256+#ifdef CONFIG_PAX_REFCOUNT
6257+ tvs %icc, 6
6258+#endif
6259+
6260 cas [%o1], %g1, %g7
6261 cmp %g1, %g7
6262 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6263@@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6264 2: BACKOFF_SPIN(%o2, %o3, 1b)
6265 .size atomic_sub, .-atomic_sub
6266
6267+ .globl atomic_sub_unchecked
6268+ .type atomic_sub_unchecked,#function
6269+atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6270+ BACKOFF_SETUP(%o2)
6271+1: lduw [%o1], %g1
6272+ sub %g1, %o0, %g7
6273+ cas [%o1], %g1, %g7
6274+ cmp %g1, %g7
6275+ bne,pn %icc, 2f
6276+ nop
6277+ retl
6278+ nop
6279+2: BACKOFF_SPIN(%o2, %o3, 1b)
6280+ .size atomic_sub_unchecked, .-atomic_sub_unchecked
6281+
6282 .globl atomic_add_ret
6283 .type atomic_add_ret,#function
6284 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6285 BACKOFF_SETUP(%o2)
6286 1: lduw [%o1], %g1
6287- add %g1, %o0, %g7
6288+ addcc %g1, %o0, %g7
6289+
6290+#ifdef CONFIG_PAX_REFCOUNT
6291+ tvs %icc, 6
6292+#endif
6293+
6294 cas [%o1], %g1, %g7
6295 cmp %g1, %g7
6296 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6297@@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6298 2: BACKOFF_SPIN(%o2, %o3, 1b)
6299 .size atomic_add_ret, .-atomic_add_ret
6300
6301+ .globl atomic_add_ret_unchecked
6302+ .type atomic_add_ret_unchecked,#function
6303+atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6304+ BACKOFF_SETUP(%o2)
6305+1: lduw [%o1], %g1
6306+ addcc %g1, %o0, %g7
6307+ cas [%o1], %g1, %g7
6308+ cmp %g1, %g7
6309+ bne,pn %icc, 2f
6310+ add %g7, %o0, %g7
6311+ sra %g7, 0, %o0
6312+ retl
6313+ nop
6314+2: BACKOFF_SPIN(%o2, %o3, 1b)
6315+ .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
6316+
6317 .globl atomic_sub_ret
6318 .type atomic_sub_ret,#function
6319 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6320 BACKOFF_SETUP(%o2)
6321 1: lduw [%o1], %g1
6322- sub %g1, %o0, %g7
6323+ subcc %g1, %o0, %g7
6324+
6325+#ifdef CONFIG_PAX_REFCOUNT
6326+ tvs %icc, 6
6327+#endif
6328+
6329 cas [%o1], %g1, %g7
6330 cmp %g1, %g7
6331 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6332@@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6333 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6334 BACKOFF_SETUP(%o2)
6335 1: ldx [%o1], %g1
6336- add %g1, %o0, %g7
6337+ addcc %g1, %o0, %g7
6338+
6339+#ifdef CONFIG_PAX_REFCOUNT
6340+ tvs %xcc, 6
6341+#endif
6342+
6343 casx [%o1], %g1, %g7
6344 cmp %g1, %g7
6345 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6346@@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6347 2: BACKOFF_SPIN(%o2, %o3, 1b)
6348 .size atomic64_add, .-atomic64_add
6349
6350+ .globl atomic64_add_unchecked
6351+ .type atomic64_add_unchecked,#function
6352+atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6353+ BACKOFF_SETUP(%o2)
6354+1: ldx [%o1], %g1
6355+ addcc %g1, %o0, %g7
6356+ casx [%o1], %g1, %g7
6357+ cmp %g1, %g7
6358+ bne,pn %xcc, 2f
6359+ nop
6360+ retl
6361+ nop
6362+2: BACKOFF_SPIN(%o2, %o3, 1b)
6363+ .size atomic64_add_unchecked, .-atomic64_add_unchecked
6364+
6365 .globl atomic64_sub
6366 .type atomic64_sub,#function
6367 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6368 BACKOFF_SETUP(%o2)
6369 1: ldx [%o1], %g1
6370- sub %g1, %o0, %g7
6371+ subcc %g1, %o0, %g7
6372+
6373+#ifdef CONFIG_PAX_REFCOUNT
6374+ tvs %xcc, 6
6375+#endif
6376+
6377 casx [%o1], %g1, %g7
6378 cmp %g1, %g7
6379 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6380@@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6381 2: BACKOFF_SPIN(%o2, %o3, 1b)
6382 .size atomic64_sub, .-atomic64_sub
6383
6384+ .globl atomic64_sub_unchecked
6385+ .type atomic64_sub_unchecked,#function
6386+atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6387+ BACKOFF_SETUP(%o2)
6388+1: ldx [%o1], %g1
6389+ subcc %g1, %o0, %g7
6390+ casx [%o1], %g1, %g7
6391+ cmp %g1, %g7
6392+ bne,pn %xcc, 2f
6393+ nop
6394+ retl
6395+ nop
6396+2: BACKOFF_SPIN(%o2, %o3, 1b)
6397+ .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
6398+
6399 .globl atomic64_add_ret
6400 .type atomic64_add_ret,#function
6401 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6402 BACKOFF_SETUP(%o2)
6403 1: ldx [%o1], %g1
6404- add %g1, %o0, %g7
6405+ addcc %g1, %o0, %g7
6406+
6407+#ifdef CONFIG_PAX_REFCOUNT
6408+ tvs %xcc, 6
6409+#endif
6410+
6411 casx [%o1], %g1, %g7
6412 cmp %g1, %g7
6413 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6414@@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6415 2: BACKOFF_SPIN(%o2, %o3, 1b)
6416 .size atomic64_add_ret, .-atomic64_add_ret
6417
6418+ .globl atomic64_add_ret_unchecked
6419+ .type atomic64_add_ret_unchecked,#function
6420+atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6421+ BACKOFF_SETUP(%o2)
6422+1: ldx [%o1], %g1
6423+ addcc %g1, %o0, %g7
6424+ casx [%o1], %g1, %g7
6425+ cmp %g1, %g7
6426+ bne,pn %xcc, 2f
6427+ add %g7, %o0, %g7
6428+ mov %g7, %o0
6429+ retl
6430+ nop
6431+2: BACKOFF_SPIN(%o2, %o3, 1b)
6432+ .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
6433+
6434 .globl atomic64_sub_ret
6435 .type atomic64_sub_ret,#function
6436 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6437 BACKOFF_SETUP(%o2)
6438 1: ldx [%o1], %g1
6439- sub %g1, %o0, %g7
6440+ subcc %g1, %o0, %g7
6441+
6442+#ifdef CONFIG_PAX_REFCOUNT
6443+ tvs %xcc, 6
6444+#endif
6445+
6446 casx [%o1], %g1, %g7
6447 cmp %g1, %g7
6448 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6449diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6450index f73c224..662af10 100644
6451--- a/arch/sparc/lib/ksyms.c
6452+++ b/arch/sparc/lib/ksyms.c
6453@@ -136,12 +136,18 @@ EXPORT_SYMBOL(__downgrade_write);
6454
6455 /* Atomic counter implementation. */
6456 EXPORT_SYMBOL(atomic_add);
6457+EXPORT_SYMBOL(atomic_add_unchecked);
6458 EXPORT_SYMBOL(atomic_add_ret);
6459+EXPORT_SYMBOL(atomic_add_ret_unchecked);
6460 EXPORT_SYMBOL(atomic_sub);
6461+EXPORT_SYMBOL(atomic_sub_unchecked);
6462 EXPORT_SYMBOL(atomic_sub_ret);
6463 EXPORT_SYMBOL(atomic64_add);
6464+EXPORT_SYMBOL(atomic64_add_unchecked);
6465 EXPORT_SYMBOL(atomic64_add_ret);
6466+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6467 EXPORT_SYMBOL(atomic64_sub);
6468+EXPORT_SYMBOL(atomic64_sub_unchecked);
6469 EXPORT_SYMBOL(atomic64_sub_ret);
6470
6471 /* Atomic bit operations. */
6472diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6473index 301421c..e2535d1 100644
6474--- a/arch/sparc/mm/Makefile
6475+++ b/arch/sparc/mm/Makefile
6476@@ -2,7 +2,7 @@
6477 #
6478
6479 asflags-y := -ansi
6480-ccflags-y := -Werror
6481+#ccflags-y := -Werror
6482
6483 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6484 obj-y += fault_$(BITS).o
6485diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6486index 8023fd7..c8e89e9 100644
6487--- a/arch/sparc/mm/fault_32.c
6488+++ b/arch/sparc/mm/fault_32.c
6489@@ -21,6 +21,9 @@
6490 #include <linux/perf_event.h>
6491 #include <linux/interrupt.h>
6492 #include <linux/kdebug.h>
6493+#include <linux/slab.h>
6494+#include <linux/pagemap.h>
6495+#include <linux/compiler.h>
6496
6497 #include <asm/system.h>
6498 #include <asm/page.h>
6499@@ -208,6 +211,268 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6500 return safe_compute_effective_address(regs, insn);
6501 }
6502
6503+#ifdef CONFIG_PAX_PAGEEXEC
6504+#ifdef CONFIG_PAX_DLRESOLVE
6505+static void pax_emuplt_close(struct vm_area_struct *vma)
6506+{
6507+ vma->vm_mm->call_dl_resolve = 0UL;
6508+}
6509+
6510+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6511+{
6512+ unsigned int *kaddr;
6513+
6514+ vmf->page = alloc_page(GFP_HIGHUSER);
6515+ if (!vmf->page)
6516+ return VM_FAULT_OOM;
6517+
6518+ kaddr = kmap(vmf->page);
6519+ memset(kaddr, 0, PAGE_SIZE);
6520+ kaddr[0] = 0x9DE3BFA8U; /* save */
6521+ flush_dcache_page(vmf->page);
6522+ kunmap(vmf->page);
6523+ return VM_FAULT_MAJOR;
6524+}
6525+
6526+static const struct vm_operations_struct pax_vm_ops = {
6527+ .close = pax_emuplt_close,
6528+ .fault = pax_emuplt_fault
6529+};
6530+
6531+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6532+{
6533+ int ret;
6534+
6535+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6536+ vma->vm_mm = current->mm;
6537+ vma->vm_start = addr;
6538+ vma->vm_end = addr + PAGE_SIZE;
6539+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6540+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6541+ vma->vm_ops = &pax_vm_ops;
6542+
6543+ ret = insert_vm_struct(current->mm, vma);
6544+ if (ret)
6545+ return ret;
6546+
6547+ ++current->mm->total_vm;
6548+ return 0;
6549+}
6550+#endif
6551+
6552+/*
6553+ * PaX: decide what to do with offenders (regs->pc = fault address)
6554+ *
6555+ * returns 1 when task should be killed
6556+ * 2 when patched PLT trampoline was detected
6557+ * 3 when unpatched PLT trampoline was detected
6558+ */
6559+static int pax_handle_fetch_fault(struct pt_regs *regs)
6560+{
6561+
6562+#ifdef CONFIG_PAX_EMUPLT
6563+ int err;
6564+
6565+ do { /* PaX: patched PLT emulation #1 */
6566+ unsigned int sethi1, sethi2, jmpl;
6567+
6568+ err = get_user(sethi1, (unsigned int *)regs->pc);
6569+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6570+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6571+
6572+ if (err)
6573+ break;
6574+
6575+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6576+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6577+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6578+ {
6579+ unsigned int addr;
6580+
6581+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6582+ addr = regs->u_regs[UREG_G1];
6583+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6584+ regs->pc = addr;
6585+ regs->npc = addr+4;
6586+ return 2;
6587+ }
6588+ } while (0);
6589+
6590+ { /* PaX: patched PLT emulation #2 */
6591+ unsigned int ba;
6592+
6593+ err = get_user(ba, (unsigned int *)regs->pc);
6594+
6595+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6596+ unsigned int addr;
6597+
6598+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6599+ regs->pc = addr;
6600+ regs->npc = addr+4;
6601+ return 2;
6602+ }
6603+ }
6604+
6605+ do { /* PaX: patched PLT emulation #3 */
6606+ unsigned int sethi, jmpl, nop;
6607+
6608+ err = get_user(sethi, (unsigned int *)regs->pc);
6609+ err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
6610+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6611+
6612+ if (err)
6613+ break;
6614+
6615+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6616+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6617+ nop == 0x01000000U)
6618+ {
6619+ unsigned int addr;
6620+
6621+ addr = (sethi & 0x003FFFFFU) << 10;
6622+ regs->u_regs[UREG_G1] = addr;
6623+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6624+ regs->pc = addr;
6625+ regs->npc = addr+4;
6626+ return 2;
6627+ }
6628+ } while (0);
6629+
6630+ do { /* PaX: unpatched PLT emulation step 1 */
6631+ unsigned int sethi, ba, nop;
6632+
6633+ err = get_user(sethi, (unsigned int *)regs->pc);
6634+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
6635+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6636+
6637+ if (err)
6638+ break;
6639+
6640+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6641+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6642+ nop == 0x01000000U)
6643+ {
6644+ unsigned int addr, save, call;
6645+
6646+ if ((ba & 0xFFC00000U) == 0x30800000U)
6647+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6648+ else
6649+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6650+
6651+ err = get_user(save, (unsigned int *)addr);
6652+ err |= get_user(call, (unsigned int *)(addr+4));
6653+ err |= get_user(nop, (unsigned int *)(addr+8));
6654+ if (err)
6655+ break;
6656+
6657+#ifdef CONFIG_PAX_DLRESOLVE
6658+ if (save == 0x9DE3BFA8U &&
6659+ (call & 0xC0000000U) == 0x40000000U &&
6660+ nop == 0x01000000U)
6661+ {
6662+ struct vm_area_struct *vma;
6663+ unsigned long call_dl_resolve;
6664+
6665+ down_read(&current->mm->mmap_sem);
6666+ call_dl_resolve = current->mm->call_dl_resolve;
6667+ up_read(&current->mm->mmap_sem);
6668+ if (likely(call_dl_resolve))
6669+ goto emulate;
6670+
6671+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6672+
6673+ down_write(&current->mm->mmap_sem);
6674+ if (current->mm->call_dl_resolve) {
6675+ call_dl_resolve = current->mm->call_dl_resolve;
6676+ up_write(&current->mm->mmap_sem);
6677+ if (vma)
6678+ kmem_cache_free(vm_area_cachep, vma);
6679+ goto emulate;
6680+ }
6681+
6682+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6683+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6684+ up_write(&current->mm->mmap_sem);
6685+ if (vma)
6686+ kmem_cache_free(vm_area_cachep, vma);
6687+ return 1;
6688+ }
6689+
6690+ if (pax_insert_vma(vma, call_dl_resolve)) {
6691+ up_write(&current->mm->mmap_sem);
6692+ kmem_cache_free(vm_area_cachep, vma);
6693+ return 1;
6694+ }
6695+
6696+ current->mm->call_dl_resolve = call_dl_resolve;
6697+ up_write(&current->mm->mmap_sem);
6698+
6699+emulate:
6700+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6701+ regs->pc = call_dl_resolve;
6702+ regs->npc = addr+4;
6703+ return 3;
6704+ }
6705+#endif
6706+
6707+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6708+ if ((save & 0xFFC00000U) == 0x05000000U &&
6709+ (call & 0xFFFFE000U) == 0x85C0A000U &&
6710+ nop == 0x01000000U)
6711+ {
6712+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6713+ regs->u_regs[UREG_G2] = addr + 4;
6714+ addr = (save & 0x003FFFFFU) << 10;
6715+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6716+ regs->pc = addr;
6717+ regs->npc = addr+4;
6718+ return 3;
6719+ }
6720+ }
6721+ } while (0);
6722+
6723+ do { /* PaX: unpatched PLT emulation step 2 */
6724+ unsigned int save, call, nop;
6725+
6726+ err = get_user(save, (unsigned int *)(regs->pc-4));
6727+ err |= get_user(call, (unsigned int *)regs->pc);
6728+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
6729+ if (err)
6730+ break;
6731+
6732+ if (save == 0x9DE3BFA8U &&
6733+ (call & 0xC0000000U) == 0x40000000U &&
6734+ nop == 0x01000000U)
6735+ {
6736+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6737+
6738+ regs->u_regs[UREG_RETPC] = regs->pc;
6739+ regs->pc = dl_resolve;
6740+ regs->npc = dl_resolve+4;
6741+ return 3;
6742+ }
6743+ } while (0);
6744+#endif
6745+
6746+ return 1;
6747+}
6748+
6749+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6750+{
6751+ unsigned long i;
6752+
6753+ printk(KERN_ERR "PAX: bytes at PC: ");
6754+ for (i = 0; i < 8; i++) {
6755+ unsigned int c;
6756+ if (get_user(c, (unsigned int *)pc+i))
6757+ printk(KERN_CONT "???????? ");
6758+ else
6759+ printk(KERN_CONT "%08x ", c);
6760+ }
6761+ printk("\n");
6762+}
6763+#endif
6764+
6765 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6766 int text_fault)
6767 {
6768@@ -280,6 +545,24 @@ good_area:
6769 if(!(vma->vm_flags & VM_WRITE))
6770 goto bad_area;
6771 } else {
6772+
6773+#ifdef CONFIG_PAX_PAGEEXEC
6774+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6775+ up_read(&mm->mmap_sem);
6776+ switch (pax_handle_fetch_fault(regs)) {
6777+
6778+#ifdef CONFIG_PAX_EMUPLT
6779+ case 2:
6780+ case 3:
6781+ return;
6782+#endif
6783+
6784+ }
6785+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6786+ do_group_exit(SIGKILL);
6787+ }
6788+#endif
6789+
6790 /* Allow reads even for write-only mappings */
6791 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6792 goto bad_area;
6793diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6794index 504c062..6fcb9c6 100644
6795--- a/arch/sparc/mm/fault_64.c
6796+++ b/arch/sparc/mm/fault_64.c
6797@@ -21,6 +21,9 @@
6798 #include <linux/kprobes.h>
6799 #include <linux/kdebug.h>
6800 #include <linux/percpu.h>
6801+#include <linux/slab.h>
6802+#include <linux/pagemap.h>
6803+#include <linux/compiler.h>
6804
6805 #include <asm/page.h>
6806 #include <asm/pgtable.h>
6807@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6808 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6809 regs->tpc);
6810 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6811- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6812+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6813 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6814 dump_stack();
6815 unhandled_fault(regs->tpc, current, regs);
6816@@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6817 show_regs(regs);
6818 }
6819
6820+#ifdef CONFIG_PAX_PAGEEXEC
6821+#ifdef CONFIG_PAX_DLRESOLVE
6822+static void pax_emuplt_close(struct vm_area_struct *vma)
6823+{
6824+ vma->vm_mm->call_dl_resolve = 0UL;
6825+}
6826+
6827+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6828+{
6829+ unsigned int *kaddr;
6830+
6831+ vmf->page = alloc_page(GFP_HIGHUSER);
6832+ if (!vmf->page)
6833+ return VM_FAULT_OOM;
6834+
6835+ kaddr = kmap(vmf->page);
6836+ memset(kaddr, 0, PAGE_SIZE);
6837+ kaddr[0] = 0x9DE3BFA8U; /* save */
6838+ flush_dcache_page(vmf->page);
6839+ kunmap(vmf->page);
6840+ return VM_FAULT_MAJOR;
6841+}
6842+
6843+static const struct vm_operations_struct pax_vm_ops = {
6844+ .close = pax_emuplt_close,
6845+ .fault = pax_emuplt_fault
6846+};
6847+
6848+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6849+{
6850+ int ret;
6851+
6852+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6853+ vma->vm_mm = current->mm;
6854+ vma->vm_start = addr;
6855+ vma->vm_end = addr + PAGE_SIZE;
6856+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6857+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6858+ vma->vm_ops = &pax_vm_ops;
6859+
6860+ ret = insert_vm_struct(current->mm, vma);
6861+ if (ret)
6862+ return ret;
6863+
6864+ ++current->mm->total_vm;
6865+ return 0;
6866+}
6867+#endif
6868+
6869+/*
6870+ * PaX: decide what to do with offenders (regs->tpc = fault address)
6871+ *
6872+ * returns 1 when task should be killed
6873+ * 2 when patched PLT trampoline was detected
6874+ * 3 when unpatched PLT trampoline was detected
6875+ */
6876+static int pax_handle_fetch_fault(struct pt_regs *regs)
6877+{
6878+
6879+#ifdef CONFIG_PAX_EMUPLT
6880+ int err;
6881+
6882+ do { /* PaX: patched PLT emulation #1 */
6883+ unsigned int sethi1, sethi2, jmpl;
6884+
6885+ err = get_user(sethi1, (unsigned int *)regs->tpc);
6886+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6887+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6888+
6889+ if (err)
6890+ break;
6891+
6892+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6893+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6894+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6895+ {
6896+ unsigned long addr;
6897+
6898+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6899+ addr = regs->u_regs[UREG_G1];
6900+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6901+
6902+ if (test_thread_flag(TIF_32BIT))
6903+ addr &= 0xFFFFFFFFUL;
6904+
6905+ regs->tpc = addr;
6906+ regs->tnpc = addr+4;
6907+ return 2;
6908+ }
6909+ } while (0);
6910+
6911+ { /* PaX: patched PLT emulation #2 */
6912+ unsigned int ba;
6913+
6914+ err = get_user(ba, (unsigned int *)regs->tpc);
6915+
6916+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6917+ unsigned long addr;
6918+
6919+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6920+
6921+ if (test_thread_flag(TIF_32BIT))
6922+ addr &= 0xFFFFFFFFUL;
6923+
6924+ regs->tpc = addr;
6925+ regs->tnpc = addr+4;
6926+ return 2;
6927+ }
6928+ }
6929+
6930+ do { /* PaX: patched PLT emulation #3 */
6931+ unsigned int sethi, jmpl, nop;
6932+
6933+ err = get_user(sethi, (unsigned int *)regs->tpc);
6934+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
6935+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6936+
6937+ if (err)
6938+ break;
6939+
6940+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6941+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6942+ nop == 0x01000000U)
6943+ {
6944+ unsigned long addr;
6945+
6946+ addr = (sethi & 0x003FFFFFU) << 10;
6947+ regs->u_regs[UREG_G1] = addr;
6948+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6949+
6950+ if (test_thread_flag(TIF_32BIT))
6951+ addr &= 0xFFFFFFFFUL;
6952+
6953+ regs->tpc = addr;
6954+ regs->tnpc = addr+4;
6955+ return 2;
6956+ }
6957+ } while (0);
6958+
6959+ do { /* PaX: patched PLT emulation #4 */
6960+ unsigned int sethi, mov1, call, mov2;
6961+
6962+ err = get_user(sethi, (unsigned int *)regs->tpc);
6963+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6964+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
6965+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6966+
6967+ if (err)
6968+ break;
6969+
6970+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6971+ mov1 == 0x8210000FU &&
6972+ (call & 0xC0000000U) == 0x40000000U &&
6973+ mov2 == 0x9E100001U)
6974+ {
6975+ unsigned long addr;
6976+
6977+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6978+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6979+
6980+ if (test_thread_flag(TIF_32BIT))
6981+ addr &= 0xFFFFFFFFUL;
6982+
6983+ regs->tpc = addr;
6984+ regs->tnpc = addr+4;
6985+ return 2;
6986+ }
6987+ } while (0);
6988+
6989+ do { /* PaX: patched PLT emulation #5 */
6990+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6991+
6992+ err = get_user(sethi, (unsigned int *)regs->tpc);
6993+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6994+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6995+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6996+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6997+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6998+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6999+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7000+
7001+ if (err)
7002+ break;
7003+
7004+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7005+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7006+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7007+ (or1 & 0xFFFFE000U) == 0x82106000U &&
7008+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7009+ sllx == 0x83287020U &&
7010+ jmpl == 0x81C04005U &&
7011+ nop == 0x01000000U)
7012+ {
7013+ unsigned long addr;
7014+
7015+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7016+ regs->u_regs[UREG_G1] <<= 32;
7017+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7018+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7019+ regs->tpc = addr;
7020+ regs->tnpc = addr+4;
7021+ return 2;
7022+ }
7023+ } while (0);
7024+
7025+ do { /* PaX: patched PLT emulation #6 */
7026+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7027+
7028+ err = get_user(sethi, (unsigned int *)regs->tpc);
7029+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7030+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7031+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7032+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
7033+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7034+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7035+
7036+ if (err)
7037+ break;
7038+
7039+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7040+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7041+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7042+ sllx == 0x83287020U &&
7043+ (or & 0xFFFFE000U) == 0x8A116000U &&
7044+ jmpl == 0x81C04005U &&
7045+ nop == 0x01000000U)
7046+ {
7047+ unsigned long addr;
7048+
7049+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7050+ regs->u_regs[UREG_G1] <<= 32;
7051+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7052+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7053+ regs->tpc = addr;
7054+ regs->tnpc = addr+4;
7055+ return 2;
7056+ }
7057+ } while (0);
7058+
7059+ do { /* PaX: unpatched PLT emulation step 1 */
7060+ unsigned int sethi, ba, nop;
7061+
7062+ err = get_user(sethi, (unsigned int *)regs->tpc);
7063+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7064+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7065+
7066+ if (err)
7067+ break;
7068+
7069+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7070+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7071+ nop == 0x01000000U)
7072+ {
7073+ unsigned long addr;
7074+ unsigned int save, call;
7075+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7076+
7077+ if ((ba & 0xFFC00000U) == 0x30800000U)
7078+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7079+ else
7080+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7081+
7082+ if (test_thread_flag(TIF_32BIT))
7083+ addr &= 0xFFFFFFFFUL;
7084+
7085+ err = get_user(save, (unsigned int *)addr);
7086+ err |= get_user(call, (unsigned int *)(addr+4));
7087+ err |= get_user(nop, (unsigned int *)(addr+8));
7088+ if (err)
7089+ break;
7090+
7091+#ifdef CONFIG_PAX_DLRESOLVE
7092+ if (save == 0x9DE3BFA8U &&
7093+ (call & 0xC0000000U) == 0x40000000U &&
7094+ nop == 0x01000000U)
7095+ {
7096+ struct vm_area_struct *vma;
7097+ unsigned long call_dl_resolve;
7098+
7099+ down_read(&current->mm->mmap_sem);
7100+ call_dl_resolve = current->mm->call_dl_resolve;
7101+ up_read(&current->mm->mmap_sem);
7102+ if (likely(call_dl_resolve))
7103+ goto emulate;
7104+
7105+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7106+
7107+ down_write(&current->mm->mmap_sem);
7108+ if (current->mm->call_dl_resolve) {
7109+ call_dl_resolve = current->mm->call_dl_resolve;
7110+ up_write(&current->mm->mmap_sem);
7111+ if (vma)
7112+ kmem_cache_free(vm_area_cachep, vma);
7113+ goto emulate;
7114+ }
7115+
7116+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7117+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7118+ up_write(&current->mm->mmap_sem);
7119+ if (vma)
7120+ kmem_cache_free(vm_area_cachep, vma);
7121+ return 1;
7122+ }
7123+
7124+ if (pax_insert_vma(vma, call_dl_resolve)) {
7125+ up_write(&current->mm->mmap_sem);
7126+ kmem_cache_free(vm_area_cachep, vma);
7127+ return 1;
7128+ }
7129+
7130+ current->mm->call_dl_resolve = call_dl_resolve;
7131+ up_write(&current->mm->mmap_sem);
7132+
7133+emulate:
7134+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7135+ regs->tpc = call_dl_resolve;
7136+ regs->tnpc = addr+4;
7137+ return 3;
7138+ }
7139+#endif
7140+
7141+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7142+ if ((save & 0xFFC00000U) == 0x05000000U &&
7143+ (call & 0xFFFFE000U) == 0x85C0A000U &&
7144+ nop == 0x01000000U)
7145+ {
7146+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7147+ regs->u_regs[UREG_G2] = addr + 4;
7148+ addr = (save & 0x003FFFFFU) << 10;
7149+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7150+
7151+ if (test_thread_flag(TIF_32BIT))
7152+ addr &= 0xFFFFFFFFUL;
7153+
7154+ regs->tpc = addr;
7155+ regs->tnpc = addr+4;
7156+ return 3;
7157+ }
7158+
7159+ /* PaX: 64-bit PLT stub */
7160+ err = get_user(sethi1, (unsigned int *)addr);
7161+ err |= get_user(sethi2, (unsigned int *)(addr+4));
7162+ err |= get_user(or1, (unsigned int *)(addr+8));
7163+ err |= get_user(or2, (unsigned int *)(addr+12));
7164+ err |= get_user(sllx, (unsigned int *)(addr+16));
7165+ err |= get_user(add, (unsigned int *)(addr+20));
7166+ err |= get_user(jmpl, (unsigned int *)(addr+24));
7167+ err |= get_user(nop, (unsigned int *)(addr+28));
7168+ if (err)
7169+ break;
7170+
7171+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7172+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7173+ (or1 & 0xFFFFE000U) == 0x88112000U &&
7174+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7175+ sllx == 0x89293020U &&
7176+ add == 0x8A010005U &&
7177+ jmpl == 0x89C14000U &&
7178+ nop == 0x01000000U)
7179+ {
7180+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7181+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7182+ regs->u_regs[UREG_G4] <<= 32;
7183+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7184+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7185+ regs->u_regs[UREG_G4] = addr + 24;
7186+ addr = regs->u_regs[UREG_G5];
7187+ regs->tpc = addr;
7188+ regs->tnpc = addr+4;
7189+ return 3;
7190+ }
7191+ }
7192+ } while (0);
7193+
7194+#ifdef CONFIG_PAX_DLRESOLVE
7195+ do { /* PaX: unpatched PLT emulation step 2 */
7196+ unsigned int save, call, nop;
7197+
7198+ err = get_user(save, (unsigned int *)(regs->tpc-4));
7199+ err |= get_user(call, (unsigned int *)regs->tpc);
7200+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7201+ if (err)
7202+ break;
7203+
7204+ if (save == 0x9DE3BFA8U &&
7205+ (call & 0xC0000000U) == 0x40000000U &&
7206+ nop == 0x01000000U)
7207+ {
7208+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7209+
7210+ if (test_thread_flag(TIF_32BIT))
7211+ dl_resolve &= 0xFFFFFFFFUL;
7212+
7213+ regs->u_regs[UREG_RETPC] = regs->tpc;
7214+ regs->tpc = dl_resolve;
7215+ regs->tnpc = dl_resolve+4;
7216+ return 3;
7217+ }
7218+ } while (0);
7219+#endif
7220+
7221+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7222+ unsigned int sethi, ba, nop;
7223+
7224+ err = get_user(sethi, (unsigned int *)regs->tpc);
7225+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7226+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7227+
7228+ if (err)
7229+ break;
7230+
7231+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7232+ (ba & 0xFFF00000U) == 0x30600000U &&
7233+ nop == 0x01000000U)
7234+ {
7235+ unsigned long addr;
7236+
7237+ addr = (sethi & 0x003FFFFFU) << 10;
7238+ regs->u_regs[UREG_G1] = addr;
7239+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7240+
7241+ if (test_thread_flag(TIF_32BIT))
7242+ addr &= 0xFFFFFFFFUL;
7243+
7244+ regs->tpc = addr;
7245+ regs->tnpc = addr+4;
7246+ return 2;
7247+ }
7248+ } while (0);
7249+
7250+#endif
7251+
7252+ return 1;
7253+}
7254+
7255+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7256+{
7257+ unsigned long i;
7258+
7259+ printk(KERN_ERR "PAX: bytes at PC: ");
7260+ for (i = 0; i < 8; i++) {
7261+ unsigned int c;
7262+ if (get_user(c, (unsigned int *)pc+i))
7263+ printk(KERN_CONT "???????? ");
7264+ else
7265+ printk(KERN_CONT "%08x ", c);
7266+ }
7267+ printk("\n");
7268+}
7269+#endif
7270+
7271 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7272 {
7273 struct mm_struct *mm = current->mm;
7274@@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7275 if (!vma)
7276 goto bad_area;
7277
7278+#ifdef CONFIG_PAX_PAGEEXEC
7279+ /* PaX: detect ITLB misses on non-exec pages */
7280+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7281+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7282+ {
7283+ if (address != regs->tpc)
7284+ goto good_area;
7285+
7286+ up_read(&mm->mmap_sem);
7287+ switch (pax_handle_fetch_fault(regs)) {
7288+
7289+#ifdef CONFIG_PAX_EMUPLT
7290+ case 2:
7291+ case 3:
7292+ return;
7293+#endif
7294+
7295+ }
7296+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7297+ do_group_exit(SIGKILL);
7298+ }
7299+#endif
7300+
7301 /* Pure DTLB misses do not tell us whether the fault causing
7302 * load/store/atomic was a write or not, it only says that there
7303 * was no match. So in such a case we (carefully) read the
7304diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7305index 07e1453..0a7d9e9 100644
7306--- a/arch/sparc/mm/hugetlbpage.c
7307+++ b/arch/sparc/mm/hugetlbpage.c
7308@@ -67,7 +67,7 @@ full_search:
7309 }
7310 return -ENOMEM;
7311 }
7312- if (likely(!vma || addr + len <= vma->vm_start)) {
7313+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7314 /*
7315 * Remember the place where we stopped the search:
7316 */
7317@@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7318 /* make sure it can fit in the remaining address space */
7319 if (likely(addr > len)) {
7320 vma = find_vma(mm, addr-len);
7321- if (!vma || addr <= vma->vm_start) {
7322+ if (check_heap_stack_gap(vma, addr - len, len)) {
7323 /* remember the address as a hint for next time */
7324 return (mm->free_area_cache = addr-len);
7325 }
7326@@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7327 if (unlikely(mm->mmap_base < len))
7328 goto bottomup;
7329
7330- addr = (mm->mmap_base-len) & HPAGE_MASK;
7331+ addr = mm->mmap_base - len;
7332
7333 do {
7334+ addr &= HPAGE_MASK;
7335 /*
7336 * Lookup failure means no vma is above this address,
7337 * else if new region fits below vma->vm_start,
7338 * return with success:
7339 */
7340 vma = find_vma(mm, addr);
7341- if (likely(!vma || addr+len <= vma->vm_start)) {
7342+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7343 /* remember the address as a hint for next time */
7344 return (mm->free_area_cache = addr);
7345 }
7346@@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7347 mm->cached_hole_size = vma->vm_start - addr;
7348
7349 /* try just below the current vma->vm_start */
7350- addr = (vma->vm_start-len) & HPAGE_MASK;
7351- } while (likely(len < vma->vm_start));
7352+ addr = skip_heap_stack_gap(vma, len);
7353+ } while (!IS_ERR_VALUE(addr));
7354
7355 bottomup:
7356 /*
7357@@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7358 if (addr) {
7359 addr = ALIGN(addr, HPAGE_SIZE);
7360 vma = find_vma(mm, addr);
7361- if (task_size - len >= addr &&
7362- (!vma || addr + len <= vma->vm_start))
7363+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7364 return addr;
7365 }
7366 if (mm->get_unmapped_area == arch_get_unmapped_area)
7367diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
7368index 7b00de6..78239f4 100644
7369--- a/arch/sparc/mm/init_32.c
7370+++ b/arch/sparc/mm/init_32.c
7371@@ -316,6 +316,9 @@ extern void device_scan(void);
7372 pgprot_t PAGE_SHARED __read_mostly;
7373 EXPORT_SYMBOL(PAGE_SHARED);
7374
7375+pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
7376+EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
7377+
7378 void __init paging_init(void)
7379 {
7380 switch(sparc_cpu_model) {
7381@@ -344,17 +347,17 @@ void __init paging_init(void)
7382
7383 /* Initialize the protection map with non-constant, MMU dependent values. */
7384 protection_map[0] = PAGE_NONE;
7385- protection_map[1] = PAGE_READONLY;
7386- protection_map[2] = PAGE_COPY;
7387- protection_map[3] = PAGE_COPY;
7388+ protection_map[1] = PAGE_READONLY_NOEXEC;
7389+ protection_map[2] = PAGE_COPY_NOEXEC;
7390+ protection_map[3] = PAGE_COPY_NOEXEC;
7391 protection_map[4] = PAGE_READONLY;
7392 protection_map[5] = PAGE_READONLY;
7393 protection_map[6] = PAGE_COPY;
7394 protection_map[7] = PAGE_COPY;
7395 protection_map[8] = PAGE_NONE;
7396- protection_map[9] = PAGE_READONLY;
7397- protection_map[10] = PAGE_SHARED;
7398- protection_map[11] = PAGE_SHARED;
7399+ protection_map[9] = PAGE_READONLY_NOEXEC;
7400+ protection_map[10] = PAGE_SHARED_NOEXEC;
7401+ protection_map[11] = PAGE_SHARED_NOEXEC;
7402 protection_map[12] = PAGE_READONLY;
7403 protection_map[13] = PAGE_READONLY;
7404 protection_map[14] = PAGE_SHARED;
7405diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
7406index cbef74e..c38fead 100644
7407--- a/arch/sparc/mm/srmmu.c
7408+++ b/arch/sparc/mm/srmmu.c
7409@@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
7410 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
7411 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
7412 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
7413+
7414+#ifdef CONFIG_PAX_PAGEEXEC
7415+ PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
7416+ BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
7417+ BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
7418+#endif
7419+
7420 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
7421 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
7422
7423diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7424index 27fe667..36d474c 100644
7425--- a/arch/tile/include/asm/atomic_64.h
7426+++ b/arch/tile/include/asm/atomic_64.h
7427@@ -142,6 +142,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7428
7429 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7430
7431+#define atomic64_read_unchecked(v) atomic64_read(v)
7432+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7433+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7434+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7435+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7436+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7437+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7438+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7439+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7440+
7441 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7442 #define smp_mb__before_atomic_dec() smp_mb()
7443 #define smp_mb__after_atomic_dec() smp_mb()
7444diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7445index 392e533..536b092 100644
7446--- a/arch/tile/include/asm/cache.h
7447+++ b/arch/tile/include/asm/cache.h
7448@@ -15,11 +15,12 @@
7449 #ifndef _ASM_TILE_CACHE_H
7450 #define _ASM_TILE_CACHE_H
7451
7452+#include <linux/const.h>
7453 #include <arch/chip.h>
7454
7455 /* bytes per L1 data cache line */
7456 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7457-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7458+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7459
7460 /* bytes per L2 cache line */
7461 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7462diff --git a/arch/um/Makefile b/arch/um/Makefile
7463index 28688e6..4c0aa1c 100644
7464--- a/arch/um/Makefile
7465+++ b/arch/um/Makefile
7466@@ -61,6 +61,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7467 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7468 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7469
7470+ifdef CONSTIFY_PLUGIN
7471+USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7472+endif
7473+
7474 #This will adjust *FLAGS accordingly to the platform.
7475 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7476
7477diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7478index 19e1bdd..3665b77 100644
7479--- a/arch/um/include/asm/cache.h
7480+++ b/arch/um/include/asm/cache.h
7481@@ -1,6 +1,7 @@
7482 #ifndef __UM_CACHE_H
7483 #define __UM_CACHE_H
7484
7485+#include <linux/const.h>
7486
7487 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7488 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7489@@ -12,6 +13,6 @@
7490 # define L1_CACHE_SHIFT 5
7491 #endif
7492
7493-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7494+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7495
7496 #endif
7497diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7498index 6c03acd..a5e0215 100644
7499--- a/arch/um/include/asm/kmap_types.h
7500+++ b/arch/um/include/asm/kmap_types.h
7501@@ -23,6 +23,7 @@ enum km_type {
7502 KM_IRQ1,
7503 KM_SOFTIRQ0,
7504 KM_SOFTIRQ1,
7505+ KM_CLEARPAGE,
7506 KM_TYPE_NR
7507 };
7508
7509diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7510index 7cfc3ce..cbd1a58 100644
7511--- a/arch/um/include/asm/page.h
7512+++ b/arch/um/include/asm/page.h
7513@@ -14,6 +14,9 @@
7514 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7515 #define PAGE_MASK (~(PAGE_SIZE-1))
7516
7517+#define ktla_ktva(addr) (addr)
7518+#define ktva_ktla(addr) (addr)
7519+
7520 #ifndef __ASSEMBLY__
7521
7522 struct page;
7523diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7524index 0032f92..cd151e0 100644
7525--- a/arch/um/include/asm/pgtable-3level.h
7526+++ b/arch/um/include/asm/pgtable-3level.h
7527@@ -58,6 +58,7 @@
7528 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7529 #define pud_populate(mm, pud, pmd) \
7530 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7531+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7532
7533 #ifdef CONFIG_64BIT
7534 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7535diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7536index 69f2490..2634831 100644
7537--- a/arch/um/kernel/process.c
7538+++ b/arch/um/kernel/process.c
7539@@ -408,22 +408,6 @@ int singlestepping(void * t)
7540 return 2;
7541 }
7542
7543-/*
7544- * Only x86 and x86_64 have an arch_align_stack().
7545- * All other arches have "#define arch_align_stack(x) (x)"
7546- * in their asm/system.h
7547- * As this is included in UML from asm-um/system-generic.h,
7548- * we can use it to behave as the subarch does.
7549- */
7550-#ifndef arch_align_stack
7551-unsigned long arch_align_stack(unsigned long sp)
7552-{
7553- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7554- sp -= get_random_int() % 8192;
7555- return sp & ~0xf;
7556-}
7557-#endif
7558-
7559 unsigned long get_wchan(struct task_struct *p)
7560 {
7561 unsigned long stack_page, sp, ip;
7562diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7563index ad8f795..2c7eec6 100644
7564--- a/arch/unicore32/include/asm/cache.h
7565+++ b/arch/unicore32/include/asm/cache.h
7566@@ -12,8 +12,10 @@
7567 #ifndef __UNICORE_CACHE_H__
7568 #define __UNICORE_CACHE_H__
7569
7570-#define L1_CACHE_SHIFT (5)
7571-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7572+#include <linux/const.h>
7573+
7574+#define L1_CACHE_SHIFT 5
7575+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7576
7577 /*
7578 * Memory returned by kmalloc() may be used for DMA, so we must make
7579diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7580index 5bed94e..fbcf200 100644
7581--- a/arch/x86/Kconfig
7582+++ b/arch/x86/Kconfig
7583@@ -226,7 +226,7 @@ config X86_HT
7584
7585 config X86_32_LAZY_GS
7586 def_bool y
7587- depends on X86_32 && !CC_STACKPROTECTOR
7588+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7589
7590 config ARCH_HWEIGHT_CFLAGS
7591 string
7592@@ -1058,7 +1058,7 @@ choice
7593
7594 config NOHIGHMEM
7595 bool "off"
7596- depends on !X86_NUMAQ
7597+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7598 ---help---
7599 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7600 However, the address space of 32-bit x86 processors is only 4
7601@@ -1095,7 +1095,7 @@ config NOHIGHMEM
7602
7603 config HIGHMEM4G
7604 bool "4GB"
7605- depends on !X86_NUMAQ
7606+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7607 ---help---
7608 Select this if you have a 32-bit processor and between 1 and 4
7609 gigabytes of physical RAM.
7610@@ -1149,7 +1149,7 @@ config PAGE_OFFSET
7611 hex
7612 default 0xB0000000 if VMSPLIT_3G_OPT
7613 default 0x80000000 if VMSPLIT_2G
7614- default 0x78000000 if VMSPLIT_2G_OPT
7615+ default 0x70000000 if VMSPLIT_2G_OPT
7616 default 0x40000000 if VMSPLIT_1G
7617 default 0xC0000000
7618 depends on X86_32
7619@@ -1539,6 +1539,7 @@ config SECCOMP
7620
7621 config CC_STACKPROTECTOR
7622 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7623+ depends on X86_64 || !PAX_MEMORY_UDEREF
7624 ---help---
7625 This option turns on the -fstack-protector GCC feature. This
7626 feature puts, at the beginning of functions, a canary value on
7627@@ -1596,6 +1597,7 @@ config KEXEC_JUMP
7628 config PHYSICAL_START
7629 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7630 default "0x1000000"
7631+ range 0x400000 0x40000000
7632 ---help---
7633 This gives the physical address where the kernel is loaded.
7634
7635@@ -1659,6 +1661,7 @@ config X86_NEED_RELOCS
7636 config PHYSICAL_ALIGN
7637 hex "Alignment value to which kernel should be aligned" if X86_32
7638 default "0x1000000"
7639+ range 0x400000 0x1000000 if PAX_KERNEXEC
7640 range 0x2000 0x1000000
7641 ---help---
7642 This value puts the alignment restrictions on physical address
7643@@ -1690,9 +1693,10 @@ config HOTPLUG_CPU
7644 Say N if you want to disable CPU hotplug.
7645
7646 config COMPAT_VDSO
7647- def_bool y
7648+ def_bool n
7649 prompt "Compat VDSO support"
7650 depends on X86_32 || IA32_EMULATION
7651+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7652 ---help---
7653 Map the 32-bit VDSO to the predictable old-style address too.
7654
7655diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7656index 3c57033..22d44aa 100644
7657--- a/arch/x86/Kconfig.cpu
7658+++ b/arch/x86/Kconfig.cpu
7659@@ -335,7 +335,7 @@ config X86_PPRO_FENCE
7660
7661 config X86_F00F_BUG
7662 def_bool y
7663- depends on M586MMX || M586TSC || M586 || M486 || M386
7664+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7665
7666 config X86_INVD_BUG
7667 def_bool y
7668@@ -359,7 +359,7 @@ config X86_POPAD_OK
7669
7670 config X86_ALIGNMENT_16
7671 def_bool y
7672- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7673+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7674
7675 config X86_INTEL_USERCOPY
7676 def_bool y
7677@@ -405,7 +405,7 @@ config X86_CMPXCHG64
7678 # generates cmov.
7679 config X86_CMOV
7680 def_bool y
7681- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7682+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7683
7684 config X86_MINIMUM_CPU_FAMILY
7685 int
7686diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7687index e46c214..7c72b55 100644
7688--- a/arch/x86/Kconfig.debug
7689+++ b/arch/x86/Kconfig.debug
7690@@ -84,7 +84,7 @@ config X86_PTDUMP
7691 config DEBUG_RODATA
7692 bool "Write protect kernel read-only data structures"
7693 default y
7694- depends on DEBUG_KERNEL
7695+ depends on DEBUG_KERNEL && BROKEN
7696 ---help---
7697 Mark the kernel read-only data as write-protected in the pagetables,
7698 in order to catch accidental (and incorrect) writes to such const
7699@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7700
7701 config DEBUG_SET_MODULE_RONX
7702 bool "Set loadable kernel module data as NX and text as RO"
7703- depends on MODULES
7704+ depends on MODULES && BROKEN
7705 ---help---
7706 This option helps catch unintended modifications to loadable
7707 kernel module's text and read-only data. It also prevents execution
7708diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7709index 209ba12..15140db 100644
7710--- a/arch/x86/Makefile
7711+++ b/arch/x86/Makefile
7712@@ -46,6 +46,7 @@ else
7713 UTS_MACHINE := x86_64
7714 CHECKFLAGS += -D__x86_64__ -m64
7715
7716+ biarch := $(call cc-option,-m64)
7717 KBUILD_AFLAGS += -m64
7718 KBUILD_CFLAGS += -m64
7719
7720@@ -201,3 +202,12 @@ define archhelp
7721 echo ' FDARGS="..." arguments for the booted kernel'
7722 echo ' FDINITRD=file initrd for the booted kernel'
7723 endef
7724+
7725+define OLD_LD
7726+
7727+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7728+*** Please upgrade your binutils to 2.18 or newer
7729+endef
7730+
7731+archprepare:
7732+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7733diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7734index 5a747dd..ff7b12c 100644
7735--- a/arch/x86/boot/Makefile
7736+++ b/arch/x86/boot/Makefile
7737@@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7738 $(call cc-option, -fno-stack-protector) \
7739 $(call cc-option, -mpreferred-stack-boundary=2)
7740 KBUILD_CFLAGS += $(call cc-option, -m32)
7741+ifdef CONSTIFY_PLUGIN
7742+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7743+endif
7744 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7745 GCOV_PROFILE := n
7746
7747diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7748index 878e4b9..20537ab 100644
7749--- a/arch/x86/boot/bitops.h
7750+++ b/arch/x86/boot/bitops.h
7751@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7752 u8 v;
7753 const u32 *p = (const u32 *)addr;
7754
7755- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7756+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7757 return v;
7758 }
7759
7760@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7761
7762 static inline void set_bit(int nr, void *addr)
7763 {
7764- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7765+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7766 }
7767
7768 #endif /* BOOT_BITOPS_H */
7769diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7770index c7093bd..d4247ffe0 100644
7771--- a/arch/x86/boot/boot.h
7772+++ b/arch/x86/boot/boot.h
7773@@ -85,7 +85,7 @@ static inline void io_delay(void)
7774 static inline u16 ds(void)
7775 {
7776 u16 seg;
7777- asm("movw %%ds,%0" : "=rm" (seg));
7778+ asm volatile("movw %%ds,%0" : "=rm" (seg));
7779 return seg;
7780 }
7781
7782@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7783 static inline int memcmp(const void *s1, const void *s2, size_t len)
7784 {
7785 u8 diff;
7786- asm("repe; cmpsb; setnz %0"
7787+ asm volatile("repe; cmpsb; setnz %0"
7788 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7789 return diff;
7790 }
7791diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7792index fd55a2f..217b501 100644
7793--- a/arch/x86/boot/compressed/Makefile
7794+++ b/arch/x86/boot/compressed/Makefile
7795@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7796 KBUILD_CFLAGS += $(cflags-y)
7797 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7798 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7799+ifdef CONSTIFY_PLUGIN
7800+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7801+endif
7802
7803 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7804 GCOV_PROFILE := n
7805diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7806index 0cdfc0d..6e79437 100644
7807--- a/arch/x86/boot/compressed/eboot.c
7808+++ b/arch/x86/boot/compressed/eboot.c
7809@@ -122,7 +122,6 @@ again:
7810 *addr = max_addr;
7811 }
7812
7813-free_pool:
7814 efi_call_phys1(sys_table->boottime->free_pool, map);
7815
7816 fail:
7817@@ -186,7 +185,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7818 if (i == map_size / desc_size)
7819 status = EFI_NOT_FOUND;
7820
7821-free_pool:
7822 efi_call_phys1(sys_table->boottime->free_pool, map);
7823 fail:
7824 return status;
7825diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7826index c85e3ac..6f5aa80 100644
7827--- a/arch/x86/boot/compressed/head_32.S
7828+++ b/arch/x86/boot/compressed/head_32.S
7829@@ -106,7 +106,7 @@ preferred_addr:
7830 notl %eax
7831 andl %eax, %ebx
7832 #else
7833- movl $LOAD_PHYSICAL_ADDR, %ebx
7834+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7835 #endif
7836
7837 /* Target address to relocate to for decompression */
7838@@ -192,7 +192,7 @@ relocated:
7839 * and where it was actually loaded.
7840 */
7841 movl %ebp, %ebx
7842- subl $LOAD_PHYSICAL_ADDR, %ebx
7843+ subl $____LOAD_PHYSICAL_ADDR, %ebx
7844 jz 2f /* Nothing to be done if loaded at compiled addr. */
7845 /*
7846 * Process relocations.
7847@@ -200,8 +200,7 @@ relocated:
7848
7849 1: subl $4, %edi
7850 movl (%edi), %ecx
7851- testl %ecx, %ecx
7852- jz 2f
7853+ jecxz 2f
7854 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7855 jmp 1b
7856 2:
7857diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7858index 87e03a1..0d94c76 100644
7859--- a/arch/x86/boot/compressed/head_64.S
7860+++ b/arch/x86/boot/compressed/head_64.S
7861@@ -91,7 +91,7 @@ ENTRY(startup_32)
7862 notl %eax
7863 andl %eax, %ebx
7864 #else
7865- movl $LOAD_PHYSICAL_ADDR, %ebx
7866+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7867 #endif
7868
7869 /* Target address to relocate to for decompression */
7870@@ -263,7 +263,7 @@ preferred_addr:
7871 notq %rax
7872 andq %rax, %rbp
7873 #else
7874- movq $LOAD_PHYSICAL_ADDR, %rbp
7875+ movq $____LOAD_PHYSICAL_ADDR, %rbp
7876 #endif
7877
7878 /* Target address to relocate to for decompression */
7879diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7880index 7116dcb..d9ae1d7 100644
7881--- a/arch/x86/boot/compressed/misc.c
7882+++ b/arch/x86/boot/compressed/misc.c
7883@@ -310,7 +310,7 @@ static void parse_elf(void *output)
7884 case PT_LOAD:
7885 #ifdef CONFIG_RELOCATABLE
7886 dest = output;
7887- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7888+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7889 #else
7890 dest = (void *)(phdr->p_paddr);
7891 #endif
7892@@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7893 error("Destination address too large");
7894 #endif
7895 #ifndef CONFIG_RELOCATABLE
7896- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7897+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7898 error("Wrong destination address");
7899 #endif
7900
7901diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
7902index e77f4e4..17e511f 100644
7903--- a/arch/x86/boot/compressed/relocs.c
7904+++ b/arch/x86/boot/compressed/relocs.c
7905@@ -13,8 +13,11 @@
7906
7907 static void die(char *fmt, ...);
7908
7909+#include "../../../../include/generated/autoconf.h"
7910+
7911 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
7912 static Elf32_Ehdr ehdr;
7913+static Elf32_Phdr *phdr;
7914 static unsigned long reloc_count, reloc_idx;
7915 static unsigned long *relocs;
7916
7917@@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
7918 }
7919 }
7920
7921+static void read_phdrs(FILE *fp)
7922+{
7923+ unsigned int i;
7924+
7925+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
7926+ if (!phdr) {
7927+ die("Unable to allocate %d program headers\n",
7928+ ehdr.e_phnum);
7929+ }
7930+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
7931+ die("Seek to %d failed: %s\n",
7932+ ehdr.e_phoff, strerror(errno));
7933+ }
7934+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
7935+ die("Cannot read ELF program headers: %s\n",
7936+ strerror(errno));
7937+ }
7938+ for(i = 0; i < ehdr.e_phnum; i++) {
7939+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
7940+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
7941+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
7942+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
7943+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
7944+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
7945+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
7946+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
7947+ }
7948+
7949+}
7950+
7951 static void read_shdrs(FILE *fp)
7952 {
7953- int i;
7954+ unsigned int i;
7955 Elf32_Shdr shdr;
7956
7957 secs = calloc(ehdr.e_shnum, sizeof(struct section));
7958@@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
7959
7960 static void read_strtabs(FILE *fp)
7961 {
7962- int i;
7963+ unsigned int i;
7964 for (i = 0; i < ehdr.e_shnum; i++) {
7965 struct section *sec = &secs[i];
7966 if (sec->shdr.sh_type != SHT_STRTAB) {
7967@@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
7968
7969 static void read_symtabs(FILE *fp)
7970 {
7971- int i,j;
7972+ unsigned int i,j;
7973 for (i = 0; i < ehdr.e_shnum; i++) {
7974 struct section *sec = &secs[i];
7975 if (sec->shdr.sh_type != SHT_SYMTAB) {
7976@@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
7977
7978 static void read_relocs(FILE *fp)
7979 {
7980- int i,j;
7981+ unsigned int i,j;
7982+ uint32_t base;
7983+
7984 for (i = 0; i < ehdr.e_shnum; i++) {
7985 struct section *sec = &secs[i];
7986 if (sec->shdr.sh_type != SHT_REL) {
7987@@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
7988 die("Cannot read symbol table: %s\n",
7989 strerror(errno));
7990 }
7991+ base = 0;
7992+ for (j = 0; j < ehdr.e_phnum; j++) {
7993+ if (phdr[j].p_type != PT_LOAD )
7994+ continue;
7995+ 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)
7996+ continue;
7997+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
7998+ break;
7999+ }
8000 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
8001 Elf32_Rel *rel = &sec->reltab[j];
8002- rel->r_offset = elf32_to_cpu(rel->r_offset);
8003+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
8004 rel->r_info = elf32_to_cpu(rel->r_info);
8005 }
8006 }
8007@@ -396,13 +440,13 @@ static void read_relocs(FILE *fp)
8008
8009 static void print_absolute_symbols(void)
8010 {
8011- int i;
8012+ unsigned int i;
8013 printf("Absolute symbols\n");
8014 printf(" Num: Value Size Type Bind Visibility Name\n");
8015 for (i = 0; i < ehdr.e_shnum; i++) {
8016 struct section *sec = &secs[i];
8017 char *sym_strtab;
8018- int j;
8019+ unsigned int j;
8020
8021 if (sec->shdr.sh_type != SHT_SYMTAB) {
8022 continue;
8023@@ -429,14 +473,14 @@ static void print_absolute_symbols(void)
8024
8025 static void print_absolute_relocs(void)
8026 {
8027- int i, printed = 0;
8028+ unsigned int i, printed = 0;
8029
8030 for (i = 0; i < ehdr.e_shnum; i++) {
8031 struct section *sec = &secs[i];
8032 struct section *sec_applies, *sec_symtab;
8033 char *sym_strtab;
8034 Elf32_Sym *sh_symtab;
8035- int j;
8036+ unsigned int j;
8037 if (sec->shdr.sh_type != SHT_REL) {
8038 continue;
8039 }
8040@@ -497,13 +541,13 @@ static void print_absolute_relocs(void)
8041
8042 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
8043 {
8044- int i;
8045+ unsigned int i;
8046 /* Walk through the relocations */
8047 for (i = 0; i < ehdr.e_shnum; i++) {
8048 char *sym_strtab;
8049 Elf32_Sym *sh_symtab;
8050 struct section *sec_applies, *sec_symtab;
8051- int j;
8052+ unsigned int j;
8053 struct section *sec = &secs[i];
8054
8055 if (sec->shdr.sh_type != SHT_REL) {
8056@@ -528,6 +572,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
8057 !is_rel_reloc(sym_name(sym_strtab, sym))) {
8058 continue;
8059 }
8060+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
8061+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
8062+ continue;
8063+
8064+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
8065+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
8066+ if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
8067+ continue;
8068+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
8069+ continue;
8070+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
8071+ continue;
8072+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
8073+ continue;
8074+#endif
8075+
8076 switch (r_type) {
8077 case R_386_NONE:
8078 case R_386_PC32:
8079@@ -569,7 +629,7 @@ static int cmp_relocs(const void *va, const void *vb)
8080
8081 static void emit_relocs(int as_text)
8082 {
8083- int i;
8084+ unsigned int i;
8085 /* Count how many relocations I have and allocate space for them. */
8086 reloc_count = 0;
8087 walk_relocs(count_reloc);
8088@@ -663,6 +723,7 @@ int main(int argc, char **argv)
8089 fname, strerror(errno));
8090 }
8091 read_ehdr(fp);
8092+ read_phdrs(fp);
8093 read_shdrs(fp);
8094 read_strtabs(fp);
8095 read_symtabs(fp);
8096diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
8097index 4d3ff03..e4972ff 100644
8098--- a/arch/x86/boot/cpucheck.c
8099+++ b/arch/x86/boot/cpucheck.c
8100@@ -74,7 +74,7 @@ static int has_fpu(void)
8101 u16 fcw = -1, fsw = -1;
8102 u32 cr0;
8103
8104- asm("movl %%cr0,%0" : "=r" (cr0));
8105+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
8106 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
8107 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
8108 asm volatile("movl %0,%%cr0" : : "r" (cr0));
8109@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
8110 {
8111 u32 f0, f1;
8112
8113- asm("pushfl ; "
8114+ asm volatile("pushfl ; "
8115 "pushfl ; "
8116 "popl %0 ; "
8117 "movl %0,%1 ; "
8118@@ -115,7 +115,7 @@ static void get_flags(void)
8119 set_bit(X86_FEATURE_FPU, cpu.flags);
8120
8121 if (has_eflag(X86_EFLAGS_ID)) {
8122- asm("cpuid"
8123+ asm volatile("cpuid"
8124 : "=a" (max_intel_level),
8125 "=b" (cpu_vendor[0]),
8126 "=d" (cpu_vendor[1]),
8127@@ -124,7 +124,7 @@ static void get_flags(void)
8128
8129 if (max_intel_level >= 0x00000001 &&
8130 max_intel_level <= 0x0000ffff) {
8131- asm("cpuid"
8132+ asm volatile("cpuid"
8133 : "=a" (tfms),
8134 "=c" (cpu.flags[4]),
8135 "=d" (cpu.flags[0])
8136@@ -136,7 +136,7 @@ static void get_flags(void)
8137 cpu.model += ((tfms >> 16) & 0xf) << 4;
8138 }
8139
8140- asm("cpuid"
8141+ asm volatile("cpuid"
8142 : "=a" (max_amd_level)
8143 : "a" (0x80000000)
8144 : "ebx", "ecx", "edx");
8145@@ -144,7 +144,7 @@ static void get_flags(void)
8146 if (max_amd_level >= 0x80000001 &&
8147 max_amd_level <= 0x8000ffff) {
8148 u32 eax = 0x80000001;
8149- asm("cpuid"
8150+ asm volatile("cpuid"
8151 : "+a" (eax),
8152 "=c" (cpu.flags[6]),
8153 "=d" (cpu.flags[1])
8154@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8155 u32 ecx = MSR_K7_HWCR;
8156 u32 eax, edx;
8157
8158- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8159+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8160 eax &= ~(1 << 15);
8161- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8162+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8163
8164 get_flags(); /* Make sure it really did something */
8165 err = check_flags();
8166@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8167 u32 ecx = MSR_VIA_FCR;
8168 u32 eax, edx;
8169
8170- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8171+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8172 eax |= (1<<1)|(1<<7);
8173- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8174+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8175
8176 set_bit(X86_FEATURE_CX8, cpu.flags);
8177 err = check_flags();
8178@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8179 u32 eax, edx;
8180 u32 level = 1;
8181
8182- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8183- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8184- asm("cpuid"
8185+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8186+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8187+ asm volatile("cpuid"
8188 : "+a" (level), "=d" (cpu.flags[0])
8189 : : "ecx", "ebx");
8190- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8191+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8192
8193 err = check_flags();
8194 }
8195diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
8196index f1bbeeb..aff09cb 100644
8197--- a/arch/x86/boot/header.S
8198+++ b/arch/x86/boot/header.S
8199@@ -372,7 +372,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
8200 # single linked list of
8201 # struct setup_data
8202
8203-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
8204+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
8205
8206 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8207 #define VO_INIT_SIZE (VO__end - VO__text)
8208diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8209index db75d07..8e6d0af 100644
8210--- a/arch/x86/boot/memory.c
8211+++ b/arch/x86/boot/memory.c
8212@@ -19,7 +19,7 @@
8213
8214 static int detect_memory_e820(void)
8215 {
8216- int count = 0;
8217+ unsigned int count = 0;
8218 struct biosregs ireg, oreg;
8219 struct e820entry *desc = boot_params.e820_map;
8220 static struct e820entry buf; /* static so it is zeroed */
8221diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8222index 11e8c6e..fdbb1ed 100644
8223--- a/arch/x86/boot/video-vesa.c
8224+++ b/arch/x86/boot/video-vesa.c
8225@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8226
8227 boot_params.screen_info.vesapm_seg = oreg.es;
8228 boot_params.screen_info.vesapm_off = oreg.di;
8229+ boot_params.screen_info.vesapm_size = oreg.cx;
8230 }
8231
8232 /*
8233diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8234index 43eda28..5ab5fdb 100644
8235--- a/arch/x86/boot/video.c
8236+++ b/arch/x86/boot/video.c
8237@@ -96,7 +96,7 @@ static void store_mode_params(void)
8238 static unsigned int get_entry(void)
8239 {
8240 char entry_buf[4];
8241- int i, len = 0;
8242+ unsigned int i, len = 0;
8243 int key;
8244 unsigned int v;
8245
8246diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8247index 5b577d5..3c1fed4 100644
8248--- a/arch/x86/crypto/aes-x86_64-asm_64.S
8249+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8250@@ -8,6 +8,8 @@
8251 * including this sentence is retained in full.
8252 */
8253
8254+#include <asm/alternative-asm.h>
8255+
8256 .extern crypto_ft_tab
8257 .extern crypto_it_tab
8258 .extern crypto_fl_tab
8259@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8260 je B192; \
8261 leaq 32(r9),r9;
8262
8263+#define ret pax_force_retaddr 0, 1; ret
8264+
8265 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8266 movq r1,r2; \
8267 movq r3,r4; \
8268diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8269index be6d9e3..21fbbca 100644
8270--- a/arch/x86/crypto/aesni-intel_asm.S
8271+++ b/arch/x86/crypto/aesni-intel_asm.S
8272@@ -31,6 +31,7 @@
8273
8274 #include <linux/linkage.h>
8275 #include <asm/inst.h>
8276+#include <asm/alternative-asm.h>
8277
8278 #ifdef __x86_64__
8279 .data
8280@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8281 pop %r14
8282 pop %r13
8283 pop %r12
8284+ pax_force_retaddr 0, 1
8285 ret
8286+ENDPROC(aesni_gcm_dec)
8287
8288
8289 /*****************************************************************************
8290@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8291 pop %r14
8292 pop %r13
8293 pop %r12
8294+ pax_force_retaddr 0, 1
8295 ret
8296+ENDPROC(aesni_gcm_enc)
8297
8298 #endif
8299
8300@@ -1714,6 +1719,7 @@ _key_expansion_256a:
8301 pxor %xmm1, %xmm0
8302 movaps %xmm0, (TKEYP)
8303 add $0x10, TKEYP
8304+ pax_force_retaddr_bts
8305 ret
8306
8307 .align 4
8308@@ -1738,6 +1744,7 @@ _key_expansion_192a:
8309 shufps $0b01001110, %xmm2, %xmm1
8310 movaps %xmm1, 0x10(TKEYP)
8311 add $0x20, TKEYP
8312+ pax_force_retaddr_bts
8313 ret
8314
8315 .align 4
8316@@ -1757,6 +1764,7 @@ _key_expansion_192b:
8317
8318 movaps %xmm0, (TKEYP)
8319 add $0x10, TKEYP
8320+ pax_force_retaddr_bts
8321 ret
8322
8323 .align 4
8324@@ -1769,6 +1777,7 @@ _key_expansion_256b:
8325 pxor %xmm1, %xmm2
8326 movaps %xmm2, (TKEYP)
8327 add $0x10, TKEYP
8328+ pax_force_retaddr_bts
8329 ret
8330
8331 /*
8332@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8333 #ifndef __x86_64__
8334 popl KEYP
8335 #endif
8336+ pax_force_retaddr 0, 1
8337 ret
8338+ENDPROC(aesni_set_key)
8339
8340 /*
8341 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8342@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8343 popl KLEN
8344 popl KEYP
8345 #endif
8346+ pax_force_retaddr 0, 1
8347 ret
8348+ENDPROC(aesni_enc)
8349
8350 /*
8351 * _aesni_enc1: internal ABI
8352@@ -1959,6 +1972,7 @@ _aesni_enc1:
8353 AESENC KEY STATE
8354 movaps 0x70(TKEYP), KEY
8355 AESENCLAST KEY STATE
8356+ pax_force_retaddr_bts
8357 ret
8358
8359 /*
8360@@ -2067,6 +2081,7 @@ _aesni_enc4:
8361 AESENCLAST KEY STATE2
8362 AESENCLAST KEY STATE3
8363 AESENCLAST KEY STATE4
8364+ pax_force_retaddr_bts
8365 ret
8366
8367 /*
8368@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8369 popl KLEN
8370 popl KEYP
8371 #endif
8372+ pax_force_retaddr 0, 1
8373 ret
8374+ENDPROC(aesni_dec)
8375
8376 /*
8377 * _aesni_dec1: internal ABI
8378@@ -2146,6 +2163,7 @@ _aesni_dec1:
8379 AESDEC KEY STATE
8380 movaps 0x70(TKEYP), KEY
8381 AESDECLAST KEY STATE
8382+ pax_force_retaddr_bts
8383 ret
8384
8385 /*
8386@@ -2254,6 +2272,7 @@ _aesni_dec4:
8387 AESDECLAST KEY STATE2
8388 AESDECLAST KEY STATE3
8389 AESDECLAST KEY STATE4
8390+ pax_force_retaddr_bts
8391 ret
8392
8393 /*
8394@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8395 popl KEYP
8396 popl LEN
8397 #endif
8398+ pax_force_retaddr 0, 1
8399 ret
8400+ENDPROC(aesni_ecb_enc)
8401
8402 /*
8403 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8404@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8405 popl KEYP
8406 popl LEN
8407 #endif
8408+ pax_force_retaddr 0, 1
8409 ret
8410+ENDPROC(aesni_ecb_dec)
8411
8412 /*
8413 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8414@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8415 popl LEN
8416 popl IVP
8417 #endif
8418+ pax_force_retaddr 0, 1
8419 ret
8420+ENDPROC(aesni_cbc_enc)
8421
8422 /*
8423 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8424@@ -2498,7 +2523,9 @@ ENTRY(aesni_cbc_dec)
8425 popl LEN
8426 popl IVP
8427 #endif
8428+ pax_force_retaddr 0, 1
8429 ret
8430+ENDPROC(aesni_cbc_dec)
8431
8432 #ifdef __x86_64__
8433 .align 16
8434@@ -2524,6 +2551,7 @@ _aesni_inc_init:
8435 mov $1, TCTR_LOW
8436 MOVQ_R64_XMM TCTR_LOW INC
8437 MOVQ_R64_XMM CTR TCTR_LOW
8438+ pax_force_retaddr_bts
8439 ret
8440
8441 /*
8442@@ -2552,6 +2580,7 @@ _aesni_inc:
8443 .Linc_low:
8444 movaps CTR, IV
8445 PSHUFB_XMM BSWAP_MASK IV
8446+ pax_force_retaddr_bts
8447 ret
8448
8449 /*
8450@@ -2612,5 +2641,7 @@ ENTRY(aesni_ctr_enc)
8451 .Lctr_enc_ret:
8452 movups IV, (IVP)
8453 .Lctr_enc_just_ret:
8454+ pax_force_retaddr 0, 1
8455 ret
8456+ENDPROC(aesni_ctr_enc)
8457 #endif
8458diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8459index 391d245..67f35c2 100644
8460--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8461+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8462@@ -20,6 +20,8 @@
8463 *
8464 */
8465
8466+#include <asm/alternative-asm.h>
8467+
8468 .file "blowfish-x86_64-asm.S"
8469 .text
8470
8471@@ -151,9 +153,11 @@ __blowfish_enc_blk:
8472 jnz __enc_xor;
8473
8474 write_block();
8475+ pax_force_retaddr 0, 1
8476 ret;
8477 __enc_xor:
8478 xor_block();
8479+ pax_force_retaddr 0, 1
8480 ret;
8481
8482 .align 8
8483@@ -188,6 +192,7 @@ blowfish_dec_blk:
8484
8485 movq %r11, %rbp;
8486
8487+ pax_force_retaddr 0, 1
8488 ret;
8489
8490 /**********************************************************************
8491@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8492
8493 popq %rbx;
8494 popq %rbp;
8495+ pax_force_retaddr 0, 1
8496 ret;
8497
8498 __enc_xor4:
8499@@ -349,6 +355,7 @@ __enc_xor4:
8500
8501 popq %rbx;
8502 popq %rbp;
8503+ pax_force_retaddr 0, 1
8504 ret;
8505
8506 .align 8
8507@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8508 popq %rbx;
8509 popq %rbp;
8510
8511+ pax_force_retaddr 0, 1
8512 ret;
8513
8514diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8515index 6214a9b..1f4fc9a 100644
8516--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8517+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8518@@ -1,3 +1,5 @@
8519+#include <asm/alternative-asm.h>
8520+
8521 # enter ECRYPT_encrypt_bytes
8522 .text
8523 .p2align 5
8524@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8525 add %r11,%rsp
8526 mov %rdi,%rax
8527 mov %rsi,%rdx
8528+ pax_force_retaddr 0, 1
8529 ret
8530 # bytesatleast65:
8531 ._bytesatleast65:
8532@@ -891,6 +894,7 @@ ECRYPT_keysetup:
8533 add %r11,%rsp
8534 mov %rdi,%rax
8535 mov %rsi,%rdx
8536+ pax_force_retaddr
8537 ret
8538 # enter ECRYPT_ivsetup
8539 .text
8540@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8541 add %r11,%rsp
8542 mov %rdi,%rax
8543 mov %rsi,%rdx
8544+ pax_force_retaddr
8545 ret
8546diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8547index 7f24a15..9cd3ffe 100644
8548--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8549+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8550@@ -24,6 +24,8 @@
8551 *
8552 */
8553
8554+#include <asm/alternative-asm.h>
8555+
8556 .file "serpent-sse2-x86_64-asm_64.S"
8557 .text
8558
8559@@ -695,12 +697,14 @@ __serpent_enc_blk_8way:
8560 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8561 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8562
8563+ pax_force_retaddr
8564 ret;
8565
8566 __enc_xor8:
8567 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8568 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8569
8570+ pax_force_retaddr
8571 ret;
8572
8573 .align 8
8574@@ -758,4 +762,5 @@ serpent_dec_blk_8way:
8575 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8576 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8577
8578+ pax_force_retaddr
8579 ret;
8580diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8581index b2c2f57..8470cab 100644
8582--- a/arch/x86/crypto/sha1_ssse3_asm.S
8583+++ b/arch/x86/crypto/sha1_ssse3_asm.S
8584@@ -28,6 +28,8 @@
8585 * (at your option) any later version.
8586 */
8587
8588+#include <asm/alternative-asm.h>
8589+
8590 #define CTX %rdi // arg1
8591 #define BUF %rsi // arg2
8592 #define CNT %rdx // arg3
8593@@ -104,6 +106,7 @@
8594 pop %r12
8595 pop %rbp
8596 pop %rbx
8597+ pax_force_retaddr 0, 1
8598 ret
8599
8600 .size \name, .-\name
8601diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8602index 5b012a2..36d5364 100644
8603--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8604+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8605@@ -20,6 +20,8 @@
8606 *
8607 */
8608
8609+#include <asm/alternative-asm.h>
8610+
8611 .file "twofish-x86_64-asm-3way.S"
8612 .text
8613
8614@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8615 popq %r13;
8616 popq %r14;
8617 popq %r15;
8618+ pax_force_retaddr 0, 1
8619 ret;
8620
8621 __enc_xor3:
8622@@ -271,6 +274,7 @@ __enc_xor3:
8623 popq %r13;
8624 popq %r14;
8625 popq %r15;
8626+ pax_force_retaddr 0, 1
8627 ret;
8628
8629 .global twofish_dec_blk_3way
8630@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8631 popq %r13;
8632 popq %r14;
8633 popq %r15;
8634+ pax_force_retaddr 0, 1
8635 ret;
8636
8637diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8638index 7bcf3fc..f53832f 100644
8639--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8640+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8641@@ -21,6 +21,7 @@
8642 .text
8643
8644 #include <asm/asm-offsets.h>
8645+#include <asm/alternative-asm.h>
8646
8647 #define a_offset 0
8648 #define b_offset 4
8649@@ -268,6 +269,7 @@ twofish_enc_blk:
8650
8651 popq R1
8652 movq $1,%rax
8653+ pax_force_retaddr 0, 1
8654 ret
8655
8656 twofish_dec_blk:
8657@@ -319,4 +321,5 @@ twofish_dec_blk:
8658
8659 popq R1
8660 movq $1,%rax
8661+ pax_force_retaddr 0, 1
8662 ret
8663diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8664index 39e4909..887aa7e 100644
8665--- a/arch/x86/ia32/ia32_aout.c
8666+++ b/arch/x86/ia32/ia32_aout.c
8667@@ -162,6 +162,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8668 unsigned long dump_start, dump_size;
8669 struct user32 dump;
8670
8671+ memset(&dump, 0, sizeof(dump));
8672+
8673 fs = get_fs();
8674 set_fs(KERNEL_DS);
8675 has_dumped = 1;
8676diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8677index 6557769..ef6ae89 100644
8678--- a/arch/x86/ia32/ia32_signal.c
8679+++ b/arch/x86/ia32/ia32_signal.c
8680@@ -169,7 +169,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8681 }
8682 seg = get_fs();
8683 set_fs(KERNEL_DS);
8684- ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8685+ ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8686 set_fs(seg);
8687 if (ret >= 0 && uoss_ptr) {
8688 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8689@@ -370,7 +370,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8690 */
8691 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8692 size_t frame_size,
8693- void **fpstate)
8694+ void __user **fpstate)
8695 {
8696 unsigned long sp;
8697
8698@@ -391,7 +391,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8699
8700 if (used_math()) {
8701 sp = sp - sig_xstate_ia32_size;
8702- *fpstate = (struct _fpstate_ia32 *) sp;
8703+ *fpstate = (struct _fpstate_ia32 __user *) sp;
8704 if (save_i387_xstate_ia32(*fpstate) < 0)
8705 return (void __user *) -1L;
8706 }
8707@@ -399,7 +399,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8708 sp -= frame_size;
8709 /* Align the stack pointer according to the i386 ABI,
8710 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8711- sp = ((sp + 4) & -16ul) - 4;
8712+ sp = ((sp - 12) & -16ul) - 4;
8713 return (void __user *) sp;
8714 }
8715
8716@@ -457,7 +457,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8717 * These are actually not used anymore, but left because some
8718 * gdb versions depend on them as a marker.
8719 */
8720- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8721+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8722 } put_user_catch(err);
8723
8724 if (err)
8725@@ -499,7 +499,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8726 0xb8,
8727 __NR_ia32_rt_sigreturn,
8728 0x80cd,
8729- 0,
8730+ 0
8731 };
8732
8733 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8734@@ -529,16 +529,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8735
8736 if (ka->sa.sa_flags & SA_RESTORER)
8737 restorer = ka->sa.sa_restorer;
8738+ else if (current->mm->context.vdso)
8739+ /* Return stub is in 32bit vsyscall page */
8740+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8741 else
8742- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8743- rt_sigreturn);
8744+ restorer = &frame->retcode;
8745 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8746
8747 /*
8748 * Not actually used anymore, but left because some gdb
8749 * versions need it.
8750 */
8751- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8752+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8753 } put_user_catch(err);
8754
8755 if (err)
8756diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8757index e3e7340..05ed805 100644
8758--- a/arch/x86/ia32/ia32entry.S
8759+++ b/arch/x86/ia32/ia32entry.S
8760@@ -13,8 +13,10 @@
8761 #include <asm/thread_info.h>
8762 #include <asm/segment.h>
8763 #include <asm/irqflags.h>
8764+#include <asm/pgtable.h>
8765 #include <linux/linkage.h>
8766 #include <linux/err.h>
8767+#include <asm/alternative-asm.h>
8768
8769 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8770 #include <linux/elf-em.h>
8771@@ -94,6 +96,32 @@ ENTRY(native_irq_enable_sysexit)
8772 ENDPROC(native_irq_enable_sysexit)
8773 #endif
8774
8775+ .macro pax_enter_kernel_user
8776+ pax_set_fptr_mask
8777+#ifdef CONFIG_PAX_MEMORY_UDEREF
8778+ call pax_enter_kernel_user
8779+#endif
8780+ .endm
8781+
8782+ .macro pax_exit_kernel_user
8783+#ifdef CONFIG_PAX_MEMORY_UDEREF
8784+ call pax_exit_kernel_user
8785+#endif
8786+#ifdef CONFIG_PAX_RANDKSTACK
8787+ pushq %rax
8788+ pushq %r11
8789+ call pax_randomize_kstack
8790+ popq %r11
8791+ popq %rax
8792+#endif
8793+ .endm
8794+
8795+.macro pax_erase_kstack
8796+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8797+ call pax_erase_kstack
8798+#endif
8799+.endm
8800+
8801 /*
8802 * 32bit SYSENTER instruction entry.
8803 *
8804@@ -120,12 +148,6 @@ ENTRY(ia32_sysenter_target)
8805 CFI_REGISTER rsp,rbp
8806 SWAPGS_UNSAFE_STACK
8807 movq PER_CPU_VAR(kernel_stack), %rsp
8808- addq $(KERNEL_STACK_OFFSET),%rsp
8809- /*
8810- * No need to follow this irqs on/off section: the syscall
8811- * disabled irqs, here we enable it straight after entry:
8812- */
8813- ENABLE_INTERRUPTS(CLBR_NONE)
8814 movl %ebp,%ebp /* zero extension */
8815 pushq_cfi $__USER32_DS
8816 /*CFI_REL_OFFSET ss,0*/
8817@@ -133,24 +155,39 @@ ENTRY(ia32_sysenter_target)
8818 CFI_REL_OFFSET rsp,0
8819 pushfq_cfi
8820 /*CFI_REL_OFFSET rflags,0*/
8821- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8822- CFI_REGISTER rip,r10
8823+ orl $X86_EFLAGS_IF,(%rsp)
8824+ GET_THREAD_INFO(%r11)
8825+ movl TI_sysenter_return(%r11), %r11d
8826+ CFI_REGISTER rip,r11
8827 pushq_cfi $__USER32_CS
8828 /*CFI_REL_OFFSET cs,0*/
8829 movl %eax, %eax
8830- pushq_cfi %r10
8831+ pushq_cfi %r11
8832 CFI_REL_OFFSET rip,0
8833 pushq_cfi %rax
8834 cld
8835 SAVE_ARGS 0,1,0
8836+ pax_enter_kernel_user
8837+ /*
8838+ * No need to follow this irqs on/off section: the syscall
8839+ * disabled irqs, here we enable it straight after entry:
8840+ */
8841+ ENABLE_INTERRUPTS(CLBR_NONE)
8842 /* no need to do an access_ok check here because rbp has been
8843 32bit zero extended */
8844+
8845+#ifdef CONFIG_PAX_MEMORY_UDEREF
8846+ mov $PAX_USER_SHADOW_BASE,%r11
8847+ add %r11,%rbp
8848+#endif
8849+
8850 1: movl (%rbp),%ebp
8851 .section __ex_table,"a"
8852 .quad 1b,ia32_badarg
8853 .previous
8854- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8855- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8856+ GET_THREAD_INFO(%r11)
8857+ orl $TS_COMPAT,TI_status(%r11)
8858+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8859 CFI_REMEMBER_STATE
8860 jnz sysenter_tracesys
8861 cmpq $(IA32_NR_syscalls-1),%rax
8862@@ -160,12 +197,15 @@ sysenter_do_call:
8863 sysenter_dispatch:
8864 call *ia32_sys_call_table(,%rax,8)
8865 movq %rax,RAX-ARGOFFSET(%rsp)
8866+ GET_THREAD_INFO(%r11)
8867 DISABLE_INTERRUPTS(CLBR_NONE)
8868 TRACE_IRQS_OFF
8869- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8870+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8871 jnz sysexit_audit
8872 sysexit_from_sys_call:
8873- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8874+ pax_exit_kernel_user
8875+ pax_erase_kstack
8876+ andl $~TS_COMPAT,TI_status(%r11)
8877 /* clear IF, that popfq doesn't enable interrupts early */
8878 andl $~0x200,EFLAGS-R11(%rsp)
8879 movl RIP-R11(%rsp),%edx /* User %eip */
8880@@ -191,6 +231,9 @@ sysexit_from_sys_call:
8881 movl %eax,%esi /* 2nd arg: syscall number */
8882 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8883 call __audit_syscall_entry
8884+
8885+ pax_erase_kstack
8886+
8887 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8888 cmpq $(IA32_NR_syscalls-1),%rax
8889 ja ia32_badsys
8890@@ -202,7 +245,7 @@ sysexit_from_sys_call:
8891 .endm
8892
8893 .macro auditsys_exit exit
8894- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8895+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8896 jnz ia32_ret_from_sys_call
8897 TRACE_IRQS_ON
8898 sti
8899@@ -213,11 +256,12 @@ sysexit_from_sys_call:
8900 1: setbe %al /* 1 if error, 0 if not */
8901 movzbl %al,%edi /* zero-extend that into %edi */
8902 call __audit_syscall_exit
8903+ GET_THREAD_INFO(%r11)
8904 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8905 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8906 cli
8907 TRACE_IRQS_OFF
8908- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8909+ testl %edi,TI_flags(%r11)
8910 jz \exit
8911 CLEAR_RREGS -ARGOFFSET
8912 jmp int_with_check
8913@@ -235,7 +279,7 @@ sysexit_audit:
8914
8915 sysenter_tracesys:
8916 #ifdef CONFIG_AUDITSYSCALL
8917- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8918+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8919 jz sysenter_auditsys
8920 #endif
8921 SAVE_REST
8922@@ -243,6 +287,9 @@ sysenter_tracesys:
8923 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8924 movq %rsp,%rdi /* &pt_regs -> arg1 */
8925 call syscall_trace_enter
8926+
8927+ pax_erase_kstack
8928+
8929 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8930 RESTORE_REST
8931 cmpq $(IA32_NR_syscalls-1),%rax
8932@@ -274,19 +321,20 @@ ENDPROC(ia32_sysenter_target)
8933 ENTRY(ia32_cstar_target)
8934 CFI_STARTPROC32 simple
8935 CFI_SIGNAL_FRAME
8936- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8937+ CFI_DEF_CFA rsp,0
8938 CFI_REGISTER rip,rcx
8939 /*CFI_REGISTER rflags,r11*/
8940 SWAPGS_UNSAFE_STACK
8941 movl %esp,%r8d
8942 CFI_REGISTER rsp,r8
8943 movq PER_CPU_VAR(kernel_stack),%rsp
8944+ SAVE_ARGS 8*6,0,0
8945+ pax_enter_kernel_user
8946 /*
8947 * No need to follow this irqs on/off section: the syscall
8948 * disabled irqs and here we enable it straight after entry:
8949 */
8950 ENABLE_INTERRUPTS(CLBR_NONE)
8951- SAVE_ARGS 8,0,0
8952 movl %eax,%eax /* zero extension */
8953 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8954 movq %rcx,RIP-ARGOFFSET(%rsp)
8955@@ -302,12 +350,19 @@ ENTRY(ia32_cstar_target)
8956 /* no need to do an access_ok check here because r8 has been
8957 32bit zero extended */
8958 /* hardware stack frame is complete now */
8959+
8960+#ifdef CONFIG_PAX_MEMORY_UDEREF
8961+ mov $PAX_USER_SHADOW_BASE,%r11
8962+ add %r11,%r8
8963+#endif
8964+
8965 1: movl (%r8),%r9d
8966 .section __ex_table,"a"
8967 .quad 1b,ia32_badarg
8968 .previous
8969- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8970- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8971+ GET_THREAD_INFO(%r11)
8972+ orl $TS_COMPAT,TI_status(%r11)
8973+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8974 CFI_REMEMBER_STATE
8975 jnz cstar_tracesys
8976 cmpq $IA32_NR_syscalls-1,%rax
8977@@ -317,12 +372,15 @@ cstar_do_call:
8978 cstar_dispatch:
8979 call *ia32_sys_call_table(,%rax,8)
8980 movq %rax,RAX-ARGOFFSET(%rsp)
8981+ GET_THREAD_INFO(%r11)
8982 DISABLE_INTERRUPTS(CLBR_NONE)
8983 TRACE_IRQS_OFF
8984- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8985+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8986 jnz sysretl_audit
8987 sysretl_from_sys_call:
8988- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8989+ pax_exit_kernel_user
8990+ pax_erase_kstack
8991+ andl $~TS_COMPAT,TI_status(%r11)
8992 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8993 movl RIP-ARGOFFSET(%rsp),%ecx
8994 CFI_REGISTER rip,rcx
8995@@ -350,7 +408,7 @@ sysretl_audit:
8996
8997 cstar_tracesys:
8998 #ifdef CONFIG_AUDITSYSCALL
8999- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9000+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
9001 jz cstar_auditsys
9002 #endif
9003 xchgl %r9d,%ebp
9004@@ -359,6 +417,9 @@ cstar_tracesys:
9005 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
9006 movq %rsp,%rdi /* &pt_regs -> arg1 */
9007 call syscall_trace_enter
9008+
9009+ pax_erase_kstack
9010+
9011 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
9012 RESTORE_REST
9013 xchgl %ebp,%r9d
9014@@ -404,19 +465,21 @@ ENTRY(ia32_syscall)
9015 CFI_REL_OFFSET rip,RIP-RIP
9016 PARAVIRT_ADJUST_EXCEPTION_FRAME
9017 SWAPGS
9018- /*
9019- * No need to follow this irqs on/off section: the syscall
9020- * disabled irqs and here we enable it straight after entry:
9021- */
9022- ENABLE_INTERRUPTS(CLBR_NONE)
9023 movl %eax,%eax
9024 pushq_cfi %rax
9025 cld
9026 /* note the registers are not zero extended to the sf.
9027 this could be a problem. */
9028 SAVE_ARGS 0,1,0
9029- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9030- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9031+ pax_enter_kernel_user
9032+ /*
9033+ * No need to follow this irqs on/off section: the syscall
9034+ * disabled irqs and here we enable it straight after entry:
9035+ */
9036+ ENABLE_INTERRUPTS(CLBR_NONE)
9037+ GET_THREAD_INFO(%r11)
9038+ orl $TS_COMPAT,TI_status(%r11)
9039+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9040 jnz ia32_tracesys
9041 cmpq $(IA32_NR_syscalls-1),%rax
9042 ja ia32_badsys
9043@@ -435,6 +498,9 @@ ia32_tracesys:
9044 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
9045 movq %rsp,%rdi /* &pt_regs -> arg1 */
9046 call syscall_trace_enter
9047+
9048+ pax_erase_kstack
9049+
9050 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
9051 RESTORE_REST
9052 cmpq $(IA32_NR_syscalls-1),%rax
9053diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
9054index f6f5c53..b358b28 100644
9055--- a/arch/x86/ia32/sys_ia32.c
9056+++ b/arch/x86/ia32/sys_ia32.c
9057@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
9058 */
9059 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
9060 {
9061- typeof(ubuf->st_uid) uid = 0;
9062- typeof(ubuf->st_gid) gid = 0;
9063+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
9064+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
9065 SET_UID(uid, stat->uid);
9066 SET_GID(gid, stat->gid);
9067 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
9068@@ -308,8 +308,8 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
9069 }
9070 set_fs(KERNEL_DS);
9071 ret = sys_rt_sigprocmask(how,
9072- set ? (sigset_t __user *)&s : NULL,
9073- oset ? (sigset_t __user *)&s : NULL,
9074+ set ? (sigset_t __force_user *)&s : NULL,
9075+ oset ? (sigset_t __force_user *)&s : NULL,
9076 sigsetsize);
9077 set_fs(old_fs);
9078 if (ret)
9079@@ -332,7 +332,7 @@ asmlinkage long sys32_alarm(unsigned int seconds)
9080 return alarm_setitimer(seconds);
9081 }
9082
9083-asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
9084+asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
9085 int options)
9086 {
9087 return compat_sys_wait4(pid, stat_addr, options, NULL);
9088@@ -353,7 +353,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
9089 mm_segment_t old_fs = get_fs();
9090
9091 set_fs(KERNEL_DS);
9092- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
9093+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
9094 set_fs(old_fs);
9095 if (put_compat_timespec(&t, interval))
9096 return -EFAULT;
9097@@ -369,7 +369,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
9098 mm_segment_t old_fs = get_fs();
9099
9100 set_fs(KERNEL_DS);
9101- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9102+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9103 set_fs(old_fs);
9104 if (!ret) {
9105 switch (_NSIG_WORDS) {
9106@@ -394,7 +394,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9107 if (copy_siginfo_from_user32(&info, uinfo))
9108 return -EFAULT;
9109 set_fs(KERNEL_DS);
9110- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9111+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9112 set_fs(old_fs);
9113 return ret;
9114 }
9115@@ -439,7 +439,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9116 return -EFAULT;
9117
9118 set_fs(KERNEL_DS);
9119- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9120+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9121 count);
9122 set_fs(old_fs);
9123
9124diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9125index 952bd01..7692c6f 100644
9126--- a/arch/x86/include/asm/alternative-asm.h
9127+++ b/arch/x86/include/asm/alternative-asm.h
9128@@ -15,6 +15,45 @@
9129 .endm
9130 #endif
9131
9132+#ifdef KERNEXEC_PLUGIN
9133+ .macro pax_force_retaddr_bts rip=0
9134+ btsq $63,\rip(%rsp)
9135+ .endm
9136+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9137+ .macro pax_force_retaddr rip=0, reload=0
9138+ btsq $63,\rip(%rsp)
9139+ .endm
9140+ .macro pax_force_fptr ptr
9141+ btsq $63,\ptr
9142+ .endm
9143+ .macro pax_set_fptr_mask
9144+ .endm
9145+#endif
9146+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9147+ .macro pax_force_retaddr rip=0, reload=0
9148+ .if \reload
9149+ pax_set_fptr_mask
9150+ .endif
9151+ orq %r10,\rip(%rsp)
9152+ .endm
9153+ .macro pax_force_fptr ptr
9154+ orq %r10,\ptr
9155+ .endm
9156+ .macro pax_set_fptr_mask
9157+ movabs $0x8000000000000000,%r10
9158+ .endm
9159+#endif
9160+#else
9161+ .macro pax_force_retaddr rip=0, reload=0
9162+ .endm
9163+ .macro pax_force_fptr ptr
9164+ .endm
9165+ .macro pax_force_retaddr_bts rip=0
9166+ .endm
9167+ .macro pax_set_fptr_mask
9168+ .endm
9169+#endif
9170+
9171 .macro altinstruction_entry orig alt feature orig_len alt_len
9172 .long \orig - .
9173 .long \alt - .
9174diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9175index 37ad100..7d47faa 100644
9176--- a/arch/x86/include/asm/alternative.h
9177+++ b/arch/x86/include/asm/alternative.h
9178@@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9179 ".section .discard,\"aw\",@progbits\n" \
9180 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
9181 ".previous\n" \
9182- ".section .altinstr_replacement, \"ax\"\n" \
9183+ ".section .altinstr_replacement, \"a\"\n" \
9184 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
9185 ".previous"
9186
9187diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9188index 3ab9bdd..238033e 100644
9189--- a/arch/x86/include/asm/apic.h
9190+++ b/arch/x86/include/asm/apic.h
9191@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
9192
9193 #ifdef CONFIG_X86_LOCAL_APIC
9194
9195-extern unsigned int apic_verbosity;
9196+extern int apic_verbosity;
9197 extern int local_apic_timer_c2_ok;
9198
9199 extern int disable_apic;
9200diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9201index 20370c6..a2eb9b0 100644
9202--- a/arch/x86/include/asm/apm.h
9203+++ b/arch/x86/include/asm/apm.h
9204@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9205 __asm__ __volatile__(APM_DO_ZERO_SEGS
9206 "pushl %%edi\n\t"
9207 "pushl %%ebp\n\t"
9208- "lcall *%%cs:apm_bios_entry\n\t"
9209+ "lcall *%%ss:apm_bios_entry\n\t"
9210 "setc %%al\n\t"
9211 "popl %%ebp\n\t"
9212 "popl %%edi\n\t"
9213@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9214 __asm__ __volatile__(APM_DO_ZERO_SEGS
9215 "pushl %%edi\n\t"
9216 "pushl %%ebp\n\t"
9217- "lcall *%%cs:apm_bios_entry\n\t"
9218+ "lcall *%%ss:apm_bios_entry\n\t"
9219 "setc %%bl\n\t"
9220 "popl %%ebp\n\t"
9221 "popl %%edi\n\t"
9222diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9223index 58cb6d4..ca9010d 100644
9224--- a/arch/x86/include/asm/atomic.h
9225+++ b/arch/x86/include/asm/atomic.h
9226@@ -22,7 +22,18 @@
9227 */
9228 static inline int atomic_read(const atomic_t *v)
9229 {
9230- return (*(volatile int *)&(v)->counter);
9231+ return (*(volatile const int *)&(v)->counter);
9232+}
9233+
9234+/**
9235+ * atomic_read_unchecked - read atomic variable
9236+ * @v: pointer of type atomic_unchecked_t
9237+ *
9238+ * Atomically reads the value of @v.
9239+ */
9240+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9241+{
9242+ return (*(volatile const int *)&(v)->counter);
9243 }
9244
9245 /**
9246@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9247 }
9248
9249 /**
9250+ * atomic_set_unchecked - set atomic variable
9251+ * @v: pointer of type atomic_unchecked_t
9252+ * @i: required value
9253+ *
9254+ * Atomically sets the value of @v to @i.
9255+ */
9256+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9257+{
9258+ v->counter = i;
9259+}
9260+
9261+/**
9262 * atomic_add - add integer to atomic variable
9263 * @i: integer value to add
9264 * @v: pointer of type atomic_t
9265@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9266 */
9267 static inline void atomic_add(int i, atomic_t *v)
9268 {
9269- asm volatile(LOCK_PREFIX "addl %1,%0"
9270+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9271+
9272+#ifdef CONFIG_PAX_REFCOUNT
9273+ "jno 0f\n"
9274+ LOCK_PREFIX "subl %1,%0\n"
9275+ "int $4\n0:\n"
9276+ _ASM_EXTABLE(0b, 0b)
9277+#endif
9278+
9279+ : "+m" (v->counter)
9280+ : "ir" (i));
9281+}
9282+
9283+/**
9284+ * atomic_add_unchecked - add integer to atomic variable
9285+ * @i: integer value to add
9286+ * @v: pointer of type atomic_unchecked_t
9287+ *
9288+ * Atomically adds @i to @v.
9289+ */
9290+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9291+{
9292+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9293 : "+m" (v->counter)
9294 : "ir" (i));
9295 }
9296@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9297 */
9298 static inline void atomic_sub(int i, atomic_t *v)
9299 {
9300- asm volatile(LOCK_PREFIX "subl %1,%0"
9301+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9302+
9303+#ifdef CONFIG_PAX_REFCOUNT
9304+ "jno 0f\n"
9305+ LOCK_PREFIX "addl %1,%0\n"
9306+ "int $4\n0:\n"
9307+ _ASM_EXTABLE(0b, 0b)
9308+#endif
9309+
9310+ : "+m" (v->counter)
9311+ : "ir" (i));
9312+}
9313+
9314+/**
9315+ * atomic_sub_unchecked - subtract integer from atomic variable
9316+ * @i: integer value to subtract
9317+ * @v: pointer of type atomic_unchecked_t
9318+ *
9319+ * Atomically subtracts @i from @v.
9320+ */
9321+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9322+{
9323+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9324 : "+m" (v->counter)
9325 : "ir" (i));
9326 }
9327@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9328 {
9329 unsigned char c;
9330
9331- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9332+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
9333+
9334+#ifdef CONFIG_PAX_REFCOUNT
9335+ "jno 0f\n"
9336+ LOCK_PREFIX "addl %2,%0\n"
9337+ "int $4\n0:\n"
9338+ _ASM_EXTABLE(0b, 0b)
9339+#endif
9340+
9341+ "sete %1\n"
9342 : "+m" (v->counter), "=qm" (c)
9343 : "ir" (i) : "memory");
9344 return c;
9345@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9346 */
9347 static inline void atomic_inc(atomic_t *v)
9348 {
9349- asm volatile(LOCK_PREFIX "incl %0"
9350+ asm volatile(LOCK_PREFIX "incl %0\n"
9351+
9352+#ifdef CONFIG_PAX_REFCOUNT
9353+ "jno 0f\n"
9354+ LOCK_PREFIX "decl %0\n"
9355+ "int $4\n0:\n"
9356+ _ASM_EXTABLE(0b, 0b)
9357+#endif
9358+
9359+ : "+m" (v->counter));
9360+}
9361+
9362+/**
9363+ * atomic_inc_unchecked - increment atomic variable
9364+ * @v: pointer of type atomic_unchecked_t
9365+ *
9366+ * Atomically increments @v by 1.
9367+ */
9368+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9369+{
9370+ asm volatile(LOCK_PREFIX "incl %0\n"
9371 : "+m" (v->counter));
9372 }
9373
9374@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9375 */
9376 static inline void atomic_dec(atomic_t *v)
9377 {
9378- asm volatile(LOCK_PREFIX "decl %0"
9379+ asm volatile(LOCK_PREFIX "decl %0\n"
9380+
9381+#ifdef CONFIG_PAX_REFCOUNT
9382+ "jno 0f\n"
9383+ LOCK_PREFIX "incl %0\n"
9384+ "int $4\n0:\n"
9385+ _ASM_EXTABLE(0b, 0b)
9386+#endif
9387+
9388+ : "+m" (v->counter));
9389+}
9390+
9391+/**
9392+ * atomic_dec_unchecked - decrement atomic variable
9393+ * @v: pointer of type atomic_unchecked_t
9394+ *
9395+ * Atomically decrements @v by 1.
9396+ */
9397+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9398+{
9399+ asm volatile(LOCK_PREFIX "decl %0\n"
9400 : "+m" (v->counter));
9401 }
9402
9403@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9404 {
9405 unsigned char c;
9406
9407- asm volatile(LOCK_PREFIX "decl %0; sete %1"
9408+ asm volatile(LOCK_PREFIX "decl %0\n"
9409+
9410+#ifdef CONFIG_PAX_REFCOUNT
9411+ "jno 0f\n"
9412+ LOCK_PREFIX "incl %0\n"
9413+ "int $4\n0:\n"
9414+ _ASM_EXTABLE(0b, 0b)
9415+#endif
9416+
9417+ "sete %1\n"
9418 : "+m" (v->counter), "=qm" (c)
9419 : : "memory");
9420 return c != 0;
9421@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9422 {
9423 unsigned char c;
9424
9425- asm volatile(LOCK_PREFIX "incl %0; sete %1"
9426+ asm volatile(LOCK_PREFIX "incl %0\n"
9427+
9428+#ifdef CONFIG_PAX_REFCOUNT
9429+ "jno 0f\n"
9430+ LOCK_PREFIX "decl %0\n"
9431+ "int $4\n0:\n"
9432+ _ASM_EXTABLE(0b, 0b)
9433+#endif
9434+
9435+ "sete %1\n"
9436+ : "+m" (v->counter), "=qm" (c)
9437+ : : "memory");
9438+ return c != 0;
9439+}
9440+
9441+/**
9442+ * atomic_inc_and_test_unchecked - increment and test
9443+ * @v: pointer of type atomic_unchecked_t
9444+ *
9445+ * Atomically increments @v by 1
9446+ * and returns true if the result is zero, or false for all
9447+ * other cases.
9448+ */
9449+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9450+{
9451+ unsigned char c;
9452+
9453+ asm volatile(LOCK_PREFIX "incl %0\n"
9454+ "sete %1\n"
9455 : "+m" (v->counter), "=qm" (c)
9456 : : "memory");
9457 return c != 0;
9458@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9459 {
9460 unsigned char c;
9461
9462- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9463+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
9464+
9465+#ifdef CONFIG_PAX_REFCOUNT
9466+ "jno 0f\n"
9467+ LOCK_PREFIX "subl %2,%0\n"
9468+ "int $4\n0:\n"
9469+ _ASM_EXTABLE(0b, 0b)
9470+#endif
9471+
9472+ "sets %1\n"
9473 : "+m" (v->counter), "=qm" (c)
9474 : "ir" (i) : "memory");
9475 return c;
9476@@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9477 goto no_xadd;
9478 #endif
9479 /* Modern 486+ processor */
9480- return i + xadd(&v->counter, i);
9481+ return i + xadd_check_overflow(&v->counter, i);
9482
9483 #ifdef CONFIG_M386
9484 no_xadd: /* Legacy 386 processor */
9485@@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9486 }
9487
9488 /**
9489+ * atomic_add_return_unchecked - add integer and return
9490+ * @i: integer value to add
9491+ * @v: pointer of type atomic_unchecked_t
9492+ *
9493+ * Atomically adds @i to @v and returns @i + @v
9494+ */
9495+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9496+{
9497+#ifdef CONFIG_M386
9498+ int __i;
9499+ unsigned long flags;
9500+ if (unlikely(boot_cpu_data.x86 <= 3))
9501+ goto no_xadd;
9502+#endif
9503+ /* Modern 486+ processor */
9504+ return i + xadd(&v->counter, i);
9505+
9506+#ifdef CONFIG_M386
9507+no_xadd: /* Legacy 386 processor */
9508+ raw_local_irq_save(flags);
9509+ __i = atomic_read_unchecked(v);
9510+ atomic_set_unchecked(v, i + __i);
9511+ raw_local_irq_restore(flags);
9512+ return i + __i;
9513+#endif
9514+}
9515+
9516+/**
9517 * atomic_sub_return - subtract integer and return
9518 * @v: pointer of type atomic_t
9519 * @i: integer value to subtract
9520@@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9521 }
9522
9523 #define atomic_inc_return(v) (atomic_add_return(1, v))
9524+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9525+{
9526+ return atomic_add_return_unchecked(1, v);
9527+}
9528 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9529
9530 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9531@@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9532 return cmpxchg(&v->counter, old, new);
9533 }
9534
9535+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9536+{
9537+ return cmpxchg(&v->counter, old, new);
9538+}
9539+
9540 static inline int atomic_xchg(atomic_t *v, int new)
9541 {
9542 return xchg(&v->counter, new);
9543 }
9544
9545+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9546+{
9547+ return xchg(&v->counter, new);
9548+}
9549+
9550 /**
9551 * __atomic_add_unless - add unless the number is already a given value
9552 * @v: pointer of type atomic_t
9553@@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9554 */
9555 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9556 {
9557- int c, old;
9558+ int c, old, new;
9559 c = atomic_read(v);
9560 for (;;) {
9561- if (unlikely(c == (u)))
9562+ if (unlikely(c == u))
9563 break;
9564- old = atomic_cmpxchg((v), c, c + (a));
9565+
9566+ asm volatile("addl %2,%0\n"
9567+
9568+#ifdef CONFIG_PAX_REFCOUNT
9569+ "jno 0f\n"
9570+ "subl %2,%0\n"
9571+ "int $4\n0:\n"
9572+ _ASM_EXTABLE(0b, 0b)
9573+#endif
9574+
9575+ : "=r" (new)
9576+ : "0" (c), "ir" (a));
9577+
9578+ old = atomic_cmpxchg(v, c, new);
9579 if (likely(old == c))
9580 break;
9581 c = old;
9582@@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9583 return c;
9584 }
9585
9586+/**
9587+ * atomic_inc_not_zero_hint - increment if not null
9588+ * @v: pointer of type atomic_t
9589+ * @hint: probable value of the atomic before the increment
9590+ *
9591+ * This version of atomic_inc_not_zero() gives a hint of probable
9592+ * value of the atomic. This helps processor to not read the memory
9593+ * before doing the atomic read/modify/write cycle, lowering
9594+ * number of bus transactions on some arches.
9595+ *
9596+ * Returns: 0 if increment was not done, 1 otherwise.
9597+ */
9598+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9599+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9600+{
9601+ int val, c = hint, new;
9602+
9603+ /* sanity test, should be removed by compiler if hint is a constant */
9604+ if (!hint)
9605+ return __atomic_add_unless(v, 1, 0);
9606+
9607+ do {
9608+ asm volatile("incl %0\n"
9609+
9610+#ifdef CONFIG_PAX_REFCOUNT
9611+ "jno 0f\n"
9612+ "decl %0\n"
9613+ "int $4\n0:\n"
9614+ _ASM_EXTABLE(0b, 0b)
9615+#endif
9616+
9617+ : "=r" (new)
9618+ : "0" (c));
9619+
9620+ val = atomic_cmpxchg(v, c, new);
9621+ if (val == c)
9622+ return 1;
9623+ c = val;
9624+ } while (c);
9625+
9626+ return 0;
9627+}
9628
9629 /*
9630 * atomic_dec_if_positive - decrement by 1 if old value positive
9631diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9632index fa13f0e..27c2e08 100644
9633--- a/arch/x86/include/asm/atomic64_32.h
9634+++ b/arch/x86/include/asm/atomic64_32.h
9635@@ -12,6 +12,14 @@ typedef struct {
9636 u64 __aligned(8) counter;
9637 } atomic64_t;
9638
9639+#ifdef CONFIG_PAX_REFCOUNT
9640+typedef struct {
9641+ u64 __aligned(8) counter;
9642+} atomic64_unchecked_t;
9643+#else
9644+typedef atomic64_t atomic64_unchecked_t;
9645+#endif
9646+
9647 #define ATOMIC64_INIT(val) { (val) }
9648
9649 #ifdef CONFIG_X86_CMPXCHG64
9650@@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9651 }
9652
9653 /**
9654+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9655+ * @p: pointer to type atomic64_unchecked_t
9656+ * @o: expected value
9657+ * @n: new value
9658+ *
9659+ * Atomically sets @v to @n if it was equal to @o and returns
9660+ * the old value.
9661+ */
9662+
9663+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9664+{
9665+ return cmpxchg64(&v->counter, o, n);
9666+}
9667+
9668+/**
9669 * atomic64_xchg - xchg atomic64 variable
9670 * @v: pointer to type atomic64_t
9671 * @n: value to assign
9672@@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9673 }
9674
9675 /**
9676+ * atomic64_set_unchecked - set atomic64 variable
9677+ * @v: pointer to type atomic64_unchecked_t
9678+ * @n: value to assign
9679+ *
9680+ * Atomically sets the value of @v to @n.
9681+ */
9682+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9683+{
9684+ unsigned high = (unsigned)(i >> 32);
9685+ unsigned low = (unsigned)i;
9686+ asm volatile(ATOMIC64_ALTERNATIVE(set)
9687+ : "+b" (low), "+c" (high)
9688+ : "S" (v)
9689+ : "eax", "edx", "memory"
9690+ );
9691+}
9692+
9693+/**
9694 * atomic64_read - read atomic64 variable
9695 * @v: pointer to type atomic64_t
9696 *
9697@@ -93,6 +134,22 @@ static inline long long atomic64_read(const atomic64_t *v)
9698 }
9699
9700 /**
9701+ * atomic64_read_unchecked - read atomic64 variable
9702+ * @v: pointer to type atomic64_unchecked_t
9703+ *
9704+ * Atomically reads the value of @v and returns it.
9705+ */
9706+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9707+{
9708+ long long r;
9709+ asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
9710+ : "=A" (r), "+c" (v)
9711+ : : "memory"
9712+ );
9713+ return r;
9714+ }
9715+
9716+/**
9717 * atomic64_add_return - add and return
9718 * @i: integer value to add
9719 * @v: pointer to type atomic64_t
9720@@ -108,6 +165,22 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9721 return i;
9722 }
9723
9724+/**
9725+ * atomic64_add_return_unchecked - add and return
9726+ * @i: integer value to add
9727+ * @v: pointer to type atomic64_unchecked_t
9728+ *
9729+ * Atomically adds @i to @v and returns @i + *@v
9730+ */
9731+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9732+{
9733+ asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
9734+ : "+A" (i), "+c" (v)
9735+ : : "memory"
9736+ );
9737+ return i;
9738+}
9739+
9740 /*
9741 * Other variants with different arithmetic operators:
9742 */
9743@@ -131,6 +204,17 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9744 return a;
9745 }
9746
9747+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9748+{
9749+ long long a;
9750+ asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
9751+ : "=A" (a)
9752+ : "S" (v)
9753+ : "memory", "ecx"
9754+ );
9755+ return a;
9756+}
9757+
9758 static inline long long atomic64_dec_return(atomic64_t *v)
9759 {
9760 long long a;
9761@@ -159,6 +243,22 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9762 }
9763
9764 /**
9765+ * atomic64_add_unchecked - add integer to atomic64 variable
9766+ * @i: integer value to add
9767+ * @v: pointer to type atomic64_unchecked_t
9768+ *
9769+ * Atomically adds @i to @v.
9770+ */
9771+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9772+{
9773+ asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
9774+ : "+A" (i), "+c" (v)
9775+ : : "memory"
9776+ );
9777+ return i;
9778+}
9779+
9780+/**
9781 * atomic64_sub - subtract the atomic64 variable
9782 * @i: integer value to subtract
9783 * @v: pointer to type atomic64_t
9784diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9785index 0e1cbfc..5623683 100644
9786--- a/arch/x86/include/asm/atomic64_64.h
9787+++ b/arch/x86/include/asm/atomic64_64.h
9788@@ -18,7 +18,19 @@
9789 */
9790 static inline long atomic64_read(const atomic64_t *v)
9791 {
9792- return (*(volatile long *)&(v)->counter);
9793+ return (*(volatile const long *)&(v)->counter);
9794+}
9795+
9796+/**
9797+ * atomic64_read_unchecked - read atomic64 variable
9798+ * @v: pointer of type atomic64_unchecked_t
9799+ *
9800+ * Atomically reads the value of @v.
9801+ * Doesn't imply a read memory barrier.
9802+ */
9803+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9804+{
9805+ return (*(volatile const long *)&(v)->counter);
9806 }
9807
9808 /**
9809@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9810 }
9811
9812 /**
9813+ * atomic64_set_unchecked - set atomic64 variable
9814+ * @v: pointer to type atomic64_unchecked_t
9815+ * @i: required value
9816+ *
9817+ * Atomically sets the value of @v to @i.
9818+ */
9819+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9820+{
9821+ v->counter = i;
9822+}
9823+
9824+/**
9825 * atomic64_add - add integer to atomic64 variable
9826 * @i: integer value to add
9827 * @v: pointer to type atomic64_t
9828@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9829 */
9830 static inline void atomic64_add(long i, atomic64_t *v)
9831 {
9832+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
9833+
9834+#ifdef CONFIG_PAX_REFCOUNT
9835+ "jno 0f\n"
9836+ LOCK_PREFIX "subq %1,%0\n"
9837+ "int $4\n0:\n"
9838+ _ASM_EXTABLE(0b, 0b)
9839+#endif
9840+
9841+ : "=m" (v->counter)
9842+ : "er" (i), "m" (v->counter));
9843+}
9844+
9845+/**
9846+ * atomic64_add_unchecked - add integer to atomic64 variable
9847+ * @i: integer value to add
9848+ * @v: pointer to type atomic64_unchecked_t
9849+ *
9850+ * Atomically adds @i to @v.
9851+ */
9852+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9853+{
9854 asm volatile(LOCK_PREFIX "addq %1,%0"
9855 : "=m" (v->counter)
9856 : "er" (i), "m" (v->counter));
9857@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9858 */
9859 static inline void atomic64_sub(long i, atomic64_t *v)
9860 {
9861- asm volatile(LOCK_PREFIX "subq %1,%0"
9862+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9863+
9864+#ifdef CONFIG_PAX_REFCOUNT
9865+ "jno 0f\n"
9866+ LOCK_PREFIX "addq %1,%0\n"
9867+ "int $4\n0:\n"
9868+ _ASM_EXTABLE(0b, 0b)
9869+#endif
9870+
9871+ : "=m" (v->counter)
9872+ : "er" (i), "m" (v->counter));
9873+}
9874+
9875+/**
9876+ * atomic64_sub_unchecked - subtract the atomic64 variable
9877+ * @i: integer value to subtract
9878+ * @v: pointer to type atomic64_unchecked_t
9879+ *
9880+ * Atomically subtracts @i from @v.
9881+ */
9882+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9883+{
9884+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9885 : "=m" (v->counter)
9886 : "er" (i), "m" (v->counter));
9887 }
9888@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9889 {
9890 unsigned char c;
9891
9892- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9893+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
9894+
9895+#ifdef CONFIG_PAX_REFCOUNT
9896+ "jno 0f\n"
9897+ LOCK_PREFIX "addq %2,%0\n"
9898+ "int $4\n0:\n"
9899+ _ASM_EXTABLE(0b, 0b)
9900+#endif
9901+
9902+ "sete %1\n"
9903 : "=m" (v->counter), "=qm" (c)
9904 : "er" (i), "m" (v->counter) : "memory");
9905 return c;
9906@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9907 */
9908 static inline void atomic64_inc(atomic64_t *v)
9909 {
9910+ asm volatile(LOCK_PREFIX "incq %0\n"
9911+
9912+#ifdef CONFIG_PAX_REFCOUNT
9913+ "jno 0f\n"
9914+ LOCK_PREFIX "decq %0\n"
9915+ "int $4\n0:\n"
9916+ _ASM_EXTABLE(0b, 0b)
9917+#endif
9918+
9919+ : "=m" (v->counter)
9920+ : "m" (v->counter));
9921+}
9922+
9923+/**
9924+ * atomic64_inc_unchecked - increment atomic64 variable
9925+ * @v: pointer to type atomic64_unchecked_t
9926+ *
9927+ * Atomically increments @v by 1.
9928+ */
9929+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9930+{
9931 asm volatile(LOCK_PREFIX "incq %0"
9932 : "=m" (v->counter)
9933 : "m" (v->counter));
9934@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9935 */
9936 static inline void atomic64_dec(atomic64_t *v)
9937 {
9938- asm volatile(LOCK_PREFIX "decq %0"
9939+ asm volatile(LOCK_PREFIX "decq %0\n"
9940+
9941+#ifdef CONFIG_PAX_REFCOUNT
9942+ "jno 0f\n"
9943+ LOCK_PREFIX "incq %0\n"
9944+ "int $4\n0:\n"
9945+ _ASM_EXTABLE(0b, 0b)
9946+#endif
9947+
9948+ : "=m" (v->counter)
9949+ : "m" (v->counter));
9950+}
9951+
9952+/**
9953+ * atomic64_dec_unchecked - decrement atomic64 variable
9954+ * @v: pointer to type atomic64_t
9955+ *
9956+ * Atomically decrements @v by 1.
9957+ */
9958+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9959+{
9960+ asm volatile(LOCK_PREFIX "decq %0\n"
9961 : "=m" (v->counter)
9962 : "m" (v->counter));
9963 }
9964@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9965 {
9966 unsigned char c;
9967
9968- asm volatile(LOCK_PREFIX "decq %0; sete %1"
9969+ asm volatile(LOCK_PREFIX "decq %0\n"
9970+
9971+#ifdef CONFIG_PAX_REFCOUNT
9972+ "jno 0f\n"
9973+ LOCK_PREFIX "incq %0\n"
9974+ "int $4\n0:\n"
9975+ _ASM_EXTABLE(0b, 0b)
9976+#endif
9977+
9978+ "sete %1\n"
9979 : "=m" (v->counter), "=qm" (c)
9980 : "m" (v->counter) : "memory");
9981 return c != 0;
9982@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9983 {
9984 unsigned char c;
9985
9986- asm volatile(LOCK_PREFIX "incq %0; sete %1"
9987+ asm volatile(LOCK_PREFIX "incq %0\n"
9988+
9989+#ifdef CONFIG_PAX_REFCOUNT
9990+ "jno 0f\n"
9991+ LOCK_PREFIX "decq %0\n"
9992+ "int $4\n0:\n"
9993+ _ASM_EXTABLE(0b, 0b)
9994+#endif
9995+
9996+ "sete %1\n"
9997 : "=m" (v->counter), "=qm" (c)
9998 : "m" (v->counter) : "memory");
9999 return c != 0;
10000@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10001 {
10002 unsigned char c;
10003
10004- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
10005+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
10006+
10007+#ifdef CONFIG_PAX_REFCOUNT
10008+ "jno 0f\n"
10009+ LOCK_PREFIX "subq %2,%0\n"
10010+ "int $4\n0:\n"
10011+ _ASM_EXTABLE(0b, 0b)
10012+#endif
10013+
10014+ "sets %1\n"
10015 : "=m" (v->counter), "=qm" (c)
10016 : "er" (i), "m" (v->counter) : "memory");
10017 return c;
10018@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10019 */
10020 static inline long atomic64_add_return(long i, atomic64_t *v)
10021 {
10022+ return i + xadd_check_overflow(&v->counter, i);
10023+}
10024+
10025+/**
10026+ * atomic64_add_return_unchecked - add and return
10027+ * @i: integer value to add
10028+ * @v: pointer to type atomic64_unchecked_t
10029+ *
10030+ * Atomically adds @i to @v and returns @i + @v
10031+ */
10032+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10033+{
10034 return i + xadd(&v->counter, i);
10035 }
10036
10037@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10038 }
10039
10040 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10041+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10042+{
10043+ return atomic64_add_return_unchecked(1, v);
10044+}
10045 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10046
10047 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10048@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10049 return cmpxchg(&v->counter, old, new);
10050 }
10051
10052+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10053+{
10054+ return cmpxchg(&v->counter, old, new);
10055+}
10056+
10057 static inline long atomic64_xchg(atomic64_t *v, long new)
10058 {
10059 return xchg(&v->counter, new);
10060@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10061 */
10062 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10063 {
10064- long c, old;
10065+ long c, old, new;
10066 c = atomic64_read(v);
10067 for (;;) {
10068- if (unlikely(c == (u)))
10069+ if (unlikely(c == u))
10070 break;
10071- old = atomic64_cmpxchg((v), c, c + (a));
10072+
10073+ asm volatile("add %2,%0\n"
10074+
10075+#ifdef CONFIG_PAX_REFCOUNT
10076+ "jno 0f\n"
10077+ "sub %2,%0\n"
10078+ "int $4\n0:\n"
10079+ _ASM_EXTABLE(0b, 0b)
10080+#endif
10081+
10082+ : "=r" (new)
10083+ : "0" (c), "ir" (a));
10084+
10085+ old = atomic64_cmpxchg(v, c, new);
10086 if (likely(old == c))
10087 break;
10088 c = old;
10089 }
10090- return c != (u);
10091+ return c != u;
10092 }
10093
10094 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10095diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10096index b97596e..9bd48b06 100644
10097--- a/arch/x86/include/asm/bitops.h
10098+++ b/arch/x86/include/asm/bitops.h
10099@@ -38,7 +38,7 @@
10100 * a mask operation on a byte.
10101 */
10102 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10103-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10104+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10105 #define CONST_MASK(nr) (1 << ((nr) & 7))
10106
10107 /**
10108diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10109index 5e1a2ee..c9f9533 100644
10110--- a/arch/x86/include/asm/boot.h
10111+++ b/arch/x86/include/asm/boot.h
10112@@ -11,10 +11,15 @@
10113 #include <asm/pgtable_types.h>
10114
10115 /* Physical address where kernel should be loaded. */
10116-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10117+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10118 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10119 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10120
10121+#ifndef __ASSEMBLY__
10122+extern unsigned char __LOAD_PHYSICAL_ADDR[];
10123+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10124+#endif
10125+
10126 /* Minimum kernel alignment, as a power of two */
10127 #ifdef CONFIG_X86_64
10128 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10129diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10130index 48f99f1..d78ebf9 100644
10131--- a/arch/x86/include/asm/cache.h
10132+++ b/arch/x86/include/asm/cache.h
10133@@ -5,12 +5,13 @@
10134
10135 /* L1 cache line size */
10136 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10137-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10138+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10139
10140 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10141+#define __read_only __attribute__((__section__(".data..read_only")))
10142
10143 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10144-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10145+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10146
10147 #ifdef CONFIG_X86_VSMP
10148 #ifdef CONFIG_SMP
10149diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10150index 4e12668..501d239 100644
10151--- a/arch/x86/include/asm/cacheflush.h
10152+++ b/arch/x86/include/asm/cacheflush.h
10153@@ -26,7 +26,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10154 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10155
10156 if (pg_flags == _PGMT_DEFAULT)
10157- return -1;
10158+ return ~0UL;
10159 else if (pg_flags == _PGMT_WC)
10160 return _PAGE_CACHE_WC;
10161 else if (pg_flags == _PGMT_UC_MINUS)
10162diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10163index 46fc474..b02b0f9 100644
10164--- a/arch/x86/include/asm/checksum_32.h
10165+++ b/arch/x86/include/asm/checksum_32.h
10166@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10167 int len, __wsum sum,
10168 int *src_err_ptr, int *dst_err_ptr);
10169
10170+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10171+ int len, __wsum sum,
10172+ int *src_err_ptr, int *dst_err_ptr);
10173+
10174+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10175+ int len, __wsum sum,
10176+ int *src_err_ptr, int *dst_err_ptr);
10177+
10178 /*
10179 * Note: when you get a NULL pointer exception here this means someone
10180 * passed in an incorrect kernel address to one of these functions.
10181@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10182 int *err_ptr)
10183 {
10184 might_sleep();
10185- return csum_partial_copy_generic((__force void *)src, dst,
10186+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
10187 len, sum, err_ptr, NULL);
10188 }
10189
10190@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10191 {
10192 might_sleep();
10193 if (access_ok(VERIFY_WRITE, dst, len))
10194- return csum_partial_copy_generic(src, (__force void *)dst,
10195+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10196 len, sum, NULL, err_ptr);
10197
10198 if (len)
10199diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10200index 99480e5..d81165b 100644
10201--- a/arch/x86/include/asm/cmpxchg.h
10202+++ b/arch/x86/include/asm/cmpxchg.h
10203@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10204 __compiletime_error("Bad argument size for cmpxchg");
10205 extern void __xadd_wrong_size(void)
10206 __compiletime_error("Bad argument size for xadd");
10207+extern void __xadd_check_overflow_wrong_size(void)
10208+ __compiletime_error("Bad argument size for xadd_check_overflow");
10209 extern void __add_wrong_size(void)
10210 __compiletime_error("Bad argument size for add");
10211+extern void __add_check_overflow_wrong_size(void)
10212+ __compiletime_error("Bad argument size for add_check_overflow");
10213
10214 /*
10215 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10216@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10217 __ret; \
10218 })
10219
10220+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10221+ ({ \
10222+ __typeof__ (*(ptr)) __ret = (arg); \
10223+ switch (sizeof(*(ptr))) { \
10224+ case __X86_CASE_L: \
10225+ asm volatile (lock #op "l %0, %1\n" \
10226+ "jno 0f\n" \
10227+ "mov %0,%1\n" \
10228+ "int $4\n0:\n" \
10229+ _ASM_EXTABLE(0b, 0b) \
10230+ : "+r" (__ret), "+m" (*(ptr)) \
10231+ : : "memory", "cc"); \
10232+ break; \
10233+ case __X86_CASE_Q: \
10234+ asm volatile (lock #op "q %q0, %1\n" \
10235+ "jno 0f\n" \
10236+ "mov %0,%1\n" \
10237+ "int $4\n0:\n" \
10238+ _ASM_EXTABLE(0b, 0b) \
10239+ : "+r" (__ret), "+m" (*(ptr)) \
10240+ : : "memory", "cc"); \
10241+ break; \
10242+ default: \
10243+ __ ## op ## _check_overflow_wrong_size(); \
10244+ } \
10245+ __ret; \
10246+ })
10247+
10248 /*
10249 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10250 * Since this is generally used to protect other memory information, we
10251@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10252 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10253 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10254
10255+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10256+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10257+
10258 #define __add(ptr, inc, lock) \
10259 ({ \
10260 __typeof__ (*(ptr)) __ret = (inc); \
10261diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10262index 8d67d42..183d0eb 100644
10263--- a/arch/x86/include/asm/cpufeature.h
10264+++ b/arch/x86/include/asm/cpufeature.h
10265@@ -367,7 +367,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10266 ".section .discard,\"aw\",@progbits\n"
10267 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10268 ".previous\n"
10269- ".section .altinstr_replacement,\"ax\"\n"
10270+ ".section .altinstr_replacement,\"a\"\n"
10271 "3: movb $1,%0\n"
10272 "4:\n"
10273 ".previous\n"
10274diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10275index e95822d..a90010e 100644
10276--- a/arch/x86/include/asm/desc.h
10277+++ b/arch/x86/include/asm/desc.h
10278@@ -4,6 +4,7 @@
10279 #include <asm/desc_defs.h>
10280 #include <asm/ldt.h>
10281 #include <asm/mmu.h>
10282+#include <asm/pgtable.h>
10283
10284 #include <linux/smp.h>
10285
10286@@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10287
10288 desc->type = (info->read_exec_only ^ 1) << 1;
10289 desc->type |= info->contents << 2;
10290+ desc->type |= info->seg_not_present ^ 1;
10291
10292 desc->s = 1;
10293 desc->dpl = 0x3;
10294@@ -34,19 +36,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10295 }
10296
10297 extern struct desc_ptr idt_descr;
10298-extern gate_desc idt_table[];
10299 extern struct desc_ptr nmi_idt_descr;
10300-extern gate_desc nmi_idt_table[];
10301-
10302-struct gdt_page {
10303- struct desc_struct gdt[GDT_ENTRIES];
10304-} __attribute__((aligned(PAGE_SIZE)));
10305-
10306-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10307+extern gate_desc idt_table[256];
10308+extern gate_desc nmi_idt_table[256];
10309
10310+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10311 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10312 {
10313- return per_cpu(gdt_page, cpu).gdt;
10314+ return cpu_gdt_table[cpu];
10315 }
10316
10317 #ifdef CONFIG_X86_64
10318@@ -71,8 +68,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10319 unsigned long base, unsigned dpl, unsigned flags,
10320 unsigned short seg)
10321 {
10322- gate->a = (seg << 16) | (base & 0xffff);
10323- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10324+ gate->gate.offset_low = base;
10325+ gate->gate.seg = seg;
10326+ gate->gate.reserved = 0;
10327+ gate->gate.type = type;
10328+ gate->gate.s = 0;
10329+ gate->gate.dpl = dpl;
10330+ gate->gate.p = 1;
10331+ gate->gate.offset_high = base >> 16;
10332 }
10333
10334 #endif
10335@@ -117,12 +120,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10336
10337 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10338 {
10339+ pax_open_kernel();
10340 memcpy(&idt[entry], gate, sizeof(*gate));
10341+ pax_close_kernel();
10342 }
10343
10344 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10345 {
10346+ pax_open_kernel();
10347 memcpy(&ldt[entry], desc, 8);
10348+ pax_close_kernel();
10349 }
10350
10351 static inline void
10352@@ -136,7 +143,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10353 default: size = sizeof(*gdt); break;
10354 }
10355
10356+ pax_open_kernel();
10357 memcpy(&gdt[entry], desc, size);
10358+ pax_close_kernel();
10359 }
10360
10361 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10362@@ -209,7 +218,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10363
10364 static inline void native_load_tr_desc(void)
10365 {
10366+ pax_open_kernel();
10367 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10368+ pax_close_kernel();
10369 }
10370
10371 static inline void native_load_gdt(const struct desc_ptr *dtr)
10372@@ -246,8 +257,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10373 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10374 unsigned int i;
10375
10376+ pax_open_kernel();
10377 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10378 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10379+ pax_close_kernel();
10380 }
10381
10382 #define _LDT_empty(info) \
10383@@ -310,7 +323,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10384 }
10385
10386 #ifdef CONFIG_X86_64
10387-static inline void set_nmi_gate(int gate, void *addr)
10388+static inline void set_nmi_gate(int gate, const void *addr)
10389 {
10390 gate_desc s;
10391
10392@@ -319,7 +332,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10393 }
10394 #endif
10395
10396-static inline void _set_gate(int gate, unsigned type, void *addr,
10397+static inline void _set_gate(int gate, unsigned type, const void *addr,
10398 unsigned dpl, unsigned ist, unsigned seg)
10399 {
10400 gate_desc s;
10401@@ -338,7 +351,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10402 * Pentium F0 0F bugfix can have resulted in the mapped
10403 * IDT being write-protected.
10404 */
10405-static inline void set_intr_gate(unsigned int n, void *addr)
10406+static inline void set_intr_gate(unsigned int n, const void *addr)
10407 {
10408 BUG_ON((unsigned)n > 0xFF);
10409 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10410@@ -368,19 +381,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10411 /*
10412 * This routine sets up an interrupt gate at directory privilege level 3.
10413 */
10414-static inline void set_system_intr_gate(unsigned int n, void *addr)
10415+static inline void set_system_intr_gate(unsigned int n, const void *addr)
10416 {
10417 BUG_ON((unsigned)n > 0xFF);
10418 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10419 }
10420
10421-static inline void set_system_trap_gate(unsigned int n, void *addr)
10422+static inline void set_system_trap_gate(unsigned int n, const void *addr)
10423 {
10424 BUG_ON((unsigned)n > 0xFF);
10425 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10426 }
10427
10428-static inline void set_trap_gate(unsigned int n, void *addr)
10429+static inline void set_trap_gate(unsigned int n, const void *addr)
10430 {
10431 BUG_ON((unsigned)n > 0xFF);
10432 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10433@@ -389,19 +402,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10434 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10435 {
10436 BUG_ON((unsigned)n > 0xFF);
10437- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10438+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10439 }
10440
10441-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10442+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10443 {
10444 BUG_ON((unsigned)n > 0xFF);
10445 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10446 }
10447
10448-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10449+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10450 {
10451 BUG_ON((unsigned)n > 0xFF);
10452 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10453 }
10454
10455+#ifdef CONFIG_X86_32
10456+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10457+{
10458+ struct desc_struct d;
10459+
10460+ if (likely(limit))
10461+ limit = (limit - 1UL) >> PAGE_SHIFT;
10462+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
10463+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10464+}
10465+#endif
10466+
10467 #endif /* _ASM_X86_DESC_H */
10468diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10469index 278441f..b95a174 100644
10470--- a/arch/x86/include/asm/desc_defs.h
10471+++ b/arch/x86/include/asm/desc_defs.h
10472@@ -31,6 +31,12 @@ struct desc_struct {
10473 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10474 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10475 };
10476+ struct {
10477+ u16 offset_low;
10478+ u16 seg;
10479+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10480+ unsigned offset_high: 16;
10481+ } gate;
10482 };
10483 } __attribute__((packed));
10484
10485diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10486index 3778256..c5d4fce 100644
10487--- a/arch/x86/include/asm/e820.h
10488+++ b/arch/x86/include/asm/e820.h
10489@@ -69,7 +69,7 @@ struct e820map {
10490 #define ISA_START_ADDRESS 0xa0000
10491 #define ISA_END_ADDRESS 0x100000
10492
10493-#define BIOS_BEGIN 0x000a0000
10494+#define BIOS_BEGIN 0x000c0000
10495 #define BIOS_END 0x00100000
10496
10497 #define BIOS_ROM_BASE 0xffe00000
10498diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10499index 5f962df..7289f09 100644
10500--- a/arch/x86/include/asm/elf.h
10501+++ b/arch/x86/include/asm/elf.h
10502@@ -238,7 +238,25 @@ extern int force_personality32;
10503 the loader. We need to make sure that it is out of the way of the program
10504 that it will "exec", and that there is sufficient room for the brk. */
10505
10506+#ifdef CONFIG_PAX_SEGMEXEC
10507+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10508+#else
10509 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10510+#endif
10511+
10512+#ifdef CONFIG_PAX_ASLR
10513+#ifdef CONFIG_X86_32
10514+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10515+
10516+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10517+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10518+#else
10519+#define PAX_ELF_ET_DYN_BASE 0x400000UL
10520+
10521+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10522+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10523+#endif
10524+#endif
10525
10526 /* This yields a mask that user programs can use to figure out what
10527 instruction set this CPU supports. This could be done in user space,
10528@@ -291,9 +309,7 @@ do { \
10529
10530 #define ARCH_DLINFO \
10531 do { \
10532- if (vdso_enabled) \
10533- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10534- (unsigned long)current->mm->context.vdso); \
10535+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10536 } while (0)
10537
10538 #define AT_SYSINFO 32
10539@@ -304,7 +320,7 @@ do { \
10540
10541 #endif /* !CONFIG_X86_32 */
10542
10543-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10544+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10545
10546 #define VDSO_ENTRY \
10547 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10548@@ -318,9 +334,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
10549 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10550 #define compat_arch_setup_additional_pages syscall32_setup_pages
10551
10552-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10553-#define arch_randomize_brk arch_randomize_brk
10554-
10555 /*
10556 * True on X86_32 or when emulating IA32 on X86_64
10557 */
10558diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10559index cc70c1c..d96d011 100644
10560--- a/arch/x86/include/asm/emergency-restart.h
10561+++ b/arch/x86/include/asm/emergency-restart.h
10562@@ -15,6 +15,6 @@ enum reboot_type {
10563
10564 extern enum reboot_type reboot_type;
10565
10566-extern void machine_emergency_restart(void);
10567+extern void machine_emergency_restart(void) __noreturn;
10568
10569 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10570diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10571index d09bb03..4ea4194 100644
10572--- a/arch/x86/include/asm/futex.h
10573+++ b/arch/x86/include/asm/futex.h
10574@@ -12,16 +12,18 @@
10575 #include <asm/system.h>
10576
10577 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10578+ typecheck(u32 __user *, uaddr); \
10579 asm volatile("1:\t" insn "\n" \
10580 "2:\t.section .fixup,\"ax\"\n" \
10581 "3:\tmov\t%3, %1\n" \
10582 "\tjmp\t2b\n" \
10583 "\t.previous\n" \
10584 _ASM_EXTABLE(1b, 3b) \
10585- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10586+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10587 : "i" (-EFAULT), "0" (oparg), "1" (0))
10588
10589 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10590+ typecheck(u32 __user *, uaddr); \
10591 asm volatile("1:\tmovl %2, %0\n" \
10592 "\tmovl\t%0, %3\n" \
10593 "\t" insn "\n" \
10594@@ -34,7 +36,7 @@
10595 _ASM_EXTABLE(1b, 4b) \
10596 _ASM_EXTABLE(2b, 4b) \
10597 : "=&a" (oldval), "=&r" (ret), \
10598- "+m" (*uaddr), "=&r" (tem) \
10599+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10600 : "r" (oparg), "i" (-EFAULT), "1" (0))
10601
10602 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10603@@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10604
10605 switch (op) {
10606 case FUTEX_OP_SET:
10607- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10608+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10609 break;
10610 case FUTEX_OP_ADD:
10611- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10612+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10613 uaddr, oparg);
10614 break;
10615 case FUTEX_OP_OR:
10616@@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10617 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10618 return -EFAULT;
10619
10620- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10621+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10622 "2:\t.section .fixup, \"ax\"\n"
10623 "3:\tmov %3, %0\n"
10624 "\tjmp 2b\n"
10625 "\t.previous\n"
10626 _ASM_EXTABLE(1b, 3b)
10627- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10628+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10629 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10630 : "memory"
10631 );
10632diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10633index eb92a6e..b98b2f4 100644
10634--- a/arch/x86/include/asm/hw_irq.h
10635+++ b/arch/x86/include/asm/hw_irq.h
10636@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10637 extern void enable_IO_APIC(void);
10638
10639 /* Statistics */
10640-extern atomic_t irq_err_count;
10641-extern atomic_t irq_mis_count;
10642+extern atomic_unchecked_t irq_err_count;
10643+extern atomic_unchecked_t irq_mis_count;
10644
10645 /* EISA */
10646 extern void eisa_set_level_irq(unsigned int irq);
10647diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
10648index 2479049..3fb9795 100644
10649--- a/arch/x86/include/asm/i387.h
10650+++ b/arch/x86/include/asm/i387.h
10651@@ -93,6 +93,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10652 {
10653 int err;
10654
10655+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10656+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10657+ fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10658+#endif
10659+
10660 /* See comment in fxsave() below. */
10661 #ifdef CONFIG_AS_FXSAVEQ
10662 asm volatile("1: fxrstorq %[fx]\n\t"
10663@@ -122,6 +127,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10664 {
10665 int err;
10666
10667+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10668+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10669+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10670+#endif
10671+
10672 /*
10673 * Clear the bytes not touched by the fxsave and reserved
10674 * for the SW usage.
10675@@ -278,7 +288,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10676 "emms\n\t" /* clear stack tags */
10677 "fildl %P[addr]", /* set F?P to defined value */
10678 X86_FEATURE_FXSAVE_LEAK,
10679- [addr] "m" (tsk->thread.fpu.has_fpu));
10680+ [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10681
10682 return fpu_restore_checking(&tsk->thread.fpu);
10683 }
10684@@ -445,7 +455,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
10685 static inline bool interrupted_user_mode(void)
10686 {
10687 struct pt_regs *regs = get_irq_regs();
10688- return regs && user_mode_vm(regs);
10689+ return regs && user_mode(regs);
10690 }
10691
10692 /*
10693diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10694index d8e8eef..99f81ae 100644
10695--- a/arch/x86/include/asm/io.h
10696+++ b/arch/x86/include/asm/io.h
10697@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10698
10699 #include <linux/vmalloc.h>
10700
10701+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10702+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10703+{
10704+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10705+}
10706+
10707+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10708+{
10709+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10710+}
10711+
10712 /*
10713 * Convert a virtual cached pointer to an uncached pointer
10714 */
10715diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10716index bba3cf8..06bc8da 100644
10717--- a/arch/x86/include/asm/irqflags.h
10718+++ b/arch/x86/include/asm/irqflags.h
10719@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10720 sti; \
10721 sysexit
10722
10723+#define GET_CR0_INTO_RDI mov %cr0, %rdi
10724+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10725+#define GET_CR3_INTO_RDI mov %cr3, %rdi
10726+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10727+
10728 #else
10729 #define INTERRUPT_RETURN iret
10730 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10731diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10732index 5478825..839e88c 100644
10733--- a/arch/x86/include/asm/kprobes.h
10734+++ b/arch/x86/include/asm/kprobes.h
10735@@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10736 #define RELATIVEJUMP_SIZE 5
10737 #define RELATIVECALL_OPCODE 0xe8
10738 #define RELATIVE_ADDR_SIZE 4
10739-#define MAX_STACK_SIZE 64
10740-#define MIN_STACK_SIZE(ADDR) \
10741- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10742- THREAD_SIZE - (unsigned long)(ADDR))) \
10743- ? (MAX_STACK_SIZE) \
10744- : (((unsigned long)current_thread_info()) + \
10745- THREAD_SIZE - (unsigned long)(ADDR)))
10746+#define MAX_STACK_SIZE 64UL
10747+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10748
10749 #define flush_insn_slot(p) do { } while (0)
10750
10751diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10752index 52d6640..a013b87 100644
10753--- a/arch/x86/include/asm/kvm_host.h
10754+++ b/arch/x86/include/asm/kvm_host.h
10755@@ -663,7 +663,7 @@ struct kvm_x86_ops {
10756 int (*check_intercept)(struct kvm_vcpu *vcpu,
10757 struct x86_instruction_info *info,
10758 enum x86_intercept_stage stage);
10759-};
10760+} __do_const;
10761
10762 struct kvm_arch_async_pf {
10763 u32 token;
10764diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10765index 9cdae5d..300d20f 100644
10766--- a/arch/x86/include/asm/local.h
10767+++ b/arch/x86/include/asm/local.h
10768@@ -18,26 +18,58 @@ typedef struct {
10769
10770 static inline void local_inc(local_t *l)
10771 {
10772- asm volatile(_ASM_INC "%0"
10773+ asm volatile(_ASM_INC "%0\n"
10774+
10775+#ifdef CONFIG_PAX_REFCOUNT
10776+ "jno 0f\n"
10777+ _ASM_DEC "%0\n"
10778+ "int $4\n0:\n"
10779+ _ASM_EXTABLE(0b, 0b)
10780+#endif
10781+
10782 : "+m" (l->a.counter));
10783 }
10784
10785 static inline void local_dec(local_t *l)
10786 {
10787- asm volatile(_ASM_DEC "%0"
10788+ asm volatile(_ASM_DEC "%0\n"
10789+
10790+#ifdef CONFIG_PAX_REFCOUNT
10791+ "jno 0f\n"
10792+ _ASM_INC "%0\n"
10793+ "int $4\n0:\n"
10794+ _ASM_EXTABLE(0b, 0b)
10795+#endif
10796+
10797 : "+m" (l->a.counter));
10798 }
10799
10800 static inline void local_add(long i, local_t *l)
10801 {
10802- asm volatile(_ASM_ADD "%1,%0"
10803+ asm volatile(_ASM_ADD "%1,%0\n"
10804+
10805+#ifdef CONFIG_PAX_REFCOUNT
10806+ "jno 0f\n"
10807+ _ASM_SUB "%1,%0\n"
10808+ "int $4\n0:\n"
10809+ _ASM_EXTABLE(0b, 0b)
10810+#endif
10811+
10812 : "+m" (l->a.counter)
10813 : "ir" (i));
10814 }
10815
10816 static inline void local_sub(long i, local_t *l)
10817 {
10818- asm volatile(_ASM_SUB "%1,%0"
10819+ asm volatile(_ASM_SUB "%1,%0\n"
10820+
10821+#ifdef CONFIG_PAX_REFCOUNT
10822+ "jno 0f\n"
10823+ _ASM_ADD "%1,%0\n"
10824+ "int $4\n0:\n"
10825+ _ASM_EXTABLE(0b, 0b)
10826+#endif
10827+
10828 : "+m" (l->a.counter)
10829 : "ir" (i));
10830 }
10831@@ -55,7 +87,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10832 {
10833 unsigned char c;
10834
10835- asm volatile(_ASM_SUB "%2,%0; sete %1"
10836+ asm volatile(_ASM_SUB "%2,%0\n"
10837+
10838+#ifdef CONFIG_PAX_REFCOUNT
10839+ "jno 0f\n"
10840+ _ASM_ADD "%2,%0\n"
10841+ "int $4\n0:\n"
10842+ _ASM_EXTABLE(0b, 0b)
10843+#endif
10844+
10845+ "sete %1\n"
10846 : "+m" (l->a.counter), "=qm" (c)
10847 : "ir" (i) : "memory");
10848 return c;
10849@@ -73,7 +114,16 @@ static inline int local_dec_and_test(local_t *l)
10850 {
10851 unsigned char c;
10852
10853- asm volatile(_ASM_DEC "%0; sete %1"
10854+ asm volatile(_ASM_DEC "%0\n"
10855+
10856+#ifdef CONFIG_PAX_REFCOUNT
10857+ "jno 0f\n"
10858+ _ASM_INC "%0\n"
10859+ "int $4\n0:\n"
10860+ _ASM_EXTABLE(0b, 0b)
10861+#endif
10862+
10863+ "sete %1\n"
10864 : "+m" (l->a.counter), "=qm" (c)
10865 : : "memory");
10866 return c != 0;
10867@@ -91,7 +141,16 @@ static inline int local_inc_and_test(local_t *l)
10868 {
10869 unsigned char c;
10870
10871- asm volatile(_ASM_INC "%0; sete %1"
10872+ asm volatile(_ASM_INC "%0\n"
10873+
10874+#ifdef CONFIG_PAX_REFCOUNT
10875+ "jno 0f\n"
10876+ _ASM_DEC "%0\n"
10877+ "int $4\n0:\n"
10878+ _ASM_EXTABLE(0b, 0b)
10879+#endif
10880+
10881+ "sete %1\n"
10882 : "+m" (l->a.counter), "=qm" (c)
10883 : : "memory");
10884 return c != 0;
10885@@ -110,7 +169,16 @@ static inline int local_add_negative(long i, local_t *l)
10886 {
10887 unsigned char c;
10888
10889- asm volatile(_ASM_ADD "%2,%0; sets %1"
10890+ asm volatile(_ASM_ADD "%2,%0\n"
10891+
10892+#ifdef CONFIG_PAX_REFCOUNT
10893+ "jno 0f\n"
10894+ _ASM_SUB "%2,%0\n"
10895+ "int $4\n0:\n"
10896+ _ASM_EXTABLE(0b, 0b)
10897+#endif
10898+
10899+ "sets %1\n"
10900 : "+m" (l->a.counter), "=qm" (c)
10901 : "ir" (i) : "memory");
10902 return c;
10903@@ -133,7 +201,15 @@ static inline long local_add_return(long i, local_t *l)
10904 #endif
10905 /* Modern 486+ processor */
10906 __i = i;
10907- asm volatile(_ASM_XADD "%0, %1;"
10908+ asm volatile(_ASM_XADD "%0, %1\n"
10909+
10910+#ifdef CONFIG_PAX_REFCOUNT
10911+ "jno 0f\n"
10912+ _ASM_MOV "%0,%1\n"
10913+ "int $4\n0:\n"
10914+ _ASM_EXTABLE(0b, 0b)
10915+#endif
10916+
10917 : "+r" (i), "+m" (l->a.counter)
10918 : : "memory");
10919 return i + __i;
10920diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10921index 593e51d..fa69c9a 100644
10922--- a/arch/x86/include/asm/mman.h
10923+++ b/arch/x86/include/asm/mman.h
10924@@ -5,4 +5,14 @@
10925
10926 #include <asm-generic/mman.h>
10927
10928+#ifdef __KERNEL__
10929+#ifndef __ASSEMBLY__
10930+#ifdef CONFIG_X86_32
10931+#define arch_mmap_check i386_mmap_check
10932+int i386_mmap_check(unsigned long addr, unsigned long len,
10933+ unsigned long flags);
10934+#endif
10935+#endif
10936+#endif
10937+
10938 #endif /* _ASM_X86_MMAN_H */
10939diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10940index 5f55e69..e20bfb1 100644
10941--- a/arch/x86/include/asm/mmu.h
10942+++ b/arch/x86/include/asm/mmu.h
10943@@ -9,7 +9,7 @@
10944 * we put the segment information here.
10945 */
10946 typedef struct {
10947- void *ldt;
10948+ struct desc_struct *ldt;
10949 int size;
10950
10951 #ifdef CONFIG_X86_64
10952@@ -18,7 +18,19 @@ typedef struct {
10953 #endif
10954
10955 struct mutex lock;
10956- void *vdso;
10957+ unsigned long vdso;
10958+
10959+#ifdef CONFIG_X86_32
10960+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10961+ unsigned long user_cs_base;
10962+ unsigned long user_cs_limit;
10963+
10964+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10965+ cpumask_t cpu_user_cs_mask;
10966+#endif
10967+
10968+#endif
10969+#endif
10970 } mm_context_t;
10971
10972 #ifdef CONFIG_SMP
10973diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10974index 6902152..da4283a 100644
10975--- a/arch/x86/include/asm/mmu_context.h
10976+++ b/arch/x86/include/asm/mmu_context.h
10977@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10978
10979 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10980 {
10981+
10982+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10983+ unsigned int i;
10984+ pgd_t *pgd;
10985+
10986+ pax_open_kernel();
10987+ pgd = get_cpu_pgd(smp_processor_id());
10988+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10989+ set_pgd_batched(pgd+i, native_make_pgd(0));
10990+ pax_close_kernel();
10991+#endif
10992+
10993 #ifdef CONFIG_SMP
10994 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10995 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10996@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10997 struct task_struct *tsk)
10998 {
10999 unsigned cpu = smp_processor_id();
11000+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11001+ int tlbstate = TLBSTATE_OK;
11002+#endif
11003
11004 if (likely(prev != next)) {
11005 #ifdef CONFIG_SMP
11006+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11007+ tlbstate = percpu_read(cpu_tlbstate.state);
11008+#endif
11009 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11010 percpu_write(cpu_tlbstate.active_mm, next);
11011 #endif
11012 cpumask_set_cpu(cpu, mm_cpumask(next));
11013
11014 /* Re-load page tables */
11015+#ifdef CONFIG_PAX_PER_CPU_PGD
11016+ pax_open_kernel();
11017+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11018+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11019+ pax_close_kernel();
11020+ load_cr3(get_cpu_pgd(cpu));
11021+#else
11022 load_cr3(next->pgd);
11023+#endif
11024
11025 /* stop flush ipis for the previous mm */
11026 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11027@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11028 */
11029 if (unlikely(prev->context.ldt != next->context.ldt))
11030 load_LDT_nolock(&next->context);
11031- }
11032+
11033+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11034+ if (!(__supported_pte_mask & _PAGE_NX)) {
11035+ smp_mb__before_clear_bit();
11036+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11037+ smp_mb__after_clear_bit();
11038+ cpu_set(cpu, next->context.cpu_user_cs_mask);
11039+ }
11040+#endif
11041+
11042+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11043+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11044+ prev->context.user_cs_limit != next->context.user_cs_limit))
11045+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11046 #ifdef CONFIG_SMP
11047+ else if (unlikely(tlbstate != TLBSTATE_OK))
11048+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11049+#endif
11050+#endif
11051+
11052+ }
11053 else {
11054+
11055+#ifdef CONFIG_PAX_PER_CPU_PGD
11056+ pax_open_kernel();
11057+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11058+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11059+ pax_close_kernel();
11060+ load_cr3(get_cpu_pgd(cpu));
11061+#endif
11062+
11063+#ifdef CONFIG_SMP
11064 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11065 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
11066
11067@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11068 * tlb flush IPI delivery. We must reload CR3
11069 * to make sure to use no freed page tables.
11070 */
11071+
11072+#ifndef CONFIG_PAX_PER_CPU_PGD
11073 load_cr3(next->pgd);
11074+#endif
11075+
11076 load_LDT_nolock(&next->context);
11077+
11078+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11079+ if (!(__supported_pte_mask & _PAGE_NX))
11080+ cpu_set(cpu, next->context.cpu_user_cs_mask);
11081+#endif
11082+
11083+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11084+#ifdef CONFIG_PAX_PAGEEXEC
11085+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11086+#endif
11087+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11088+#endif
11089+
11090 }
11091+#endif
11092 }
11093-#endif
11094 }
11095
11096 #define activate_mm(prev, next) \
11097diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11098index 9eae775..c914fea 100644
11099--- a/arch/x86/include/asm/module.h
11100+++ b/arch/x86/include/asm/module.h
11101@@ -5,6 +5,7 @@
11102
11103 #ifdef CONFIG_X86_64
11104 /* X86_64 does not define MODULE_PROC_FAMILY */
11105+#define MODULE_PROC_FAMILY ""
11106 #elif defined CONFIG_M386
11107 #define MODULE_PROC_FAMILY "386 "
11108 #elif defined CONFIG_M486
11109@@ -59,8 +60,20 @@
11110 #error unknown processor family
11111 #endif
11112
11113-#ifdef CONFIG_X86_32
11114-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11115+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11116+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11117+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11118+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11119+#else
11120+#define MODULE_PAX_KERNEXEC ""
11121 #endif
11122
11123+#ifdef CONFIG_PAX_MEMORY_UDEREF
11124+#define MODULE_PAX_UDEREF "UDEREF "
11125+#else
11126+#define MODULE_PAX_UDEREF ""
11127+#endif
11128+
11129+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11130+
11131 #endif /* _ASM_X86_MODULE_H */
11132diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11133index 7639dbf..e08a58c 100644
11134--- a/arch/x86/include/asm/page_64_types.h
11135+++ b/arch/x86/include/asm/page_64_types.h
11136@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11137
11138 /* duplicated to the one in bootmem.h */
11139 extern unsigned long max_pfn;
11140-extern unsigned long phys_base;
11141+extern const unsigned long phys_base;
11142
11143 extern unsigned long __phys_addr(unsigned long);
11144 #define __phys_reloc_hide(x) (x)
11145diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11146index a7d2db9..edb023e 100644
11147--- a/arch/x86/include/asm/paravirt.h
11148+++ b/arch/x86/include/asm/paravirt.h
11149@@ -667,6 +667,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11150 val);
11151 }
11152
11153+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11154+{
11155+ pgdval_t val = native_pgd_val(pgd);
11156+
11157+ if (sizeof(pgdval_t) > sizeof(long))
11158+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11159+ val, (u64)val >> 32);
11160+ else
11161+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11162+ val);
11163+}
11164+
11165 static inline void pgd_clear(pgd_t *pgdp)
11166 {
11167 set_pgd(pgdp, __pgd(0));
11168@@ -748,6 +760,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11169 pv_mmu_ops.set_fixmap(idx, phys, flags);
11170 }
11171
11172+#ifdef CONFIG_PAX_KERNEXEC
11173+static inline unsigned long pax_open_kernel(void)
11174+{
11175+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11176+}
11177+
11178+static inline unsigned long pax_close_kernel(void)
11179+{
11180+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11181+}
11182+#else
11183+static inline unsigned long pax_open_kernel(void) { return 0; }
11184+static inline unsigned long pax_close_kernel(void) { return 0; }
11185+#endif
11186+
11187 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11188
11189 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11190@@ -964,7 +991,7 @@ extern void default_banner(void);
11191
11192 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11193 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11194-#define PARA_INDIRECT(addr) *%cs:addr
11195+#define PARA_INDIRECT(addr) *%ss:addr
11196 #endif
11197
11198 #define INTERRUPT_RETURN \
11199@@ -1041,6 +1068,21 @@ extern void default_banner(void);
11200 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11201 CLBR_NONE, \
11202 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11203+
11204+#define GET_CR0_INTO_RDI \
11205+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11206+ mov %rax,%rdi
11207+
11208+#define SET_RDI_INTO_CR0 \
11209+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11210+
11211+#define GET_CR3_INTO_RDI \
11212+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11213+ mov %rax,%rdi
11214+
11215+#define SET_RDI_INTO_CR3 \
11216+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11217+
11218 #endif /* CONFIG_X86_32 */
11219
11220 #endif /* __ASSEMBLY__ */
11221diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11222index 8e8b9a4..f07d725 100644
11223--- a/arch/x86/include/asm/paravirt_types.h
11224+++ b/arch/x86/include/asm/paravirt_types.h
11225@@ -84,20 +84,20 @@ struct pv_init_ops {
11226 */
11227 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11228 unsigned long addr, unsigned len);
11229-};
11230+} __no_const;
11231
11232
11233 struct pv_lazy_ops {
11234 /* Set deferred update mode, used for batching operations. */
11235 void (*enter)(void);
11236 void (*leave)(void);
11237-};
11238+} __no_const;
11239
11240 struct pv_time_ops {
11241 unsigned long long (*sched_clock)(void);
11242 unsigned long long (*steal_clock)(int cpu);
11243 unsigned long (*get_tsc_khz)(void);
11244-};
11245+} __no_const;
11246
11247 struct pv_cpu_ops {
11248 /* hooks for various privileged instructions */
11249@@ -193,7 +193,7 @@ struct pv_cpu_ops {
11250
11251 void (*start_context_switch)(struct task_struct *prev);
11252 void (*end_context_switch)(struct task_struct *next);
11253-};
11254+} __no_const;
11255
11256 struct pv_irq_ops {
11257 /*
11258@@ -224,7 +224,7 @@ struct pv_apic_ops {
11259 unsigned long start_eip,
11260 unsigned long start_esp);
11261 #endif
11262-};
11263+} __no_const;
11264
11265 struct pv_mmu_ops {
11266 unsigned long (*read_cr2)(void);
11267@@ -313,6 +313,7 @@ struct pv_mmu_ops {
11268 struct paravirt_callee_save make_pud;
11269
11270 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11271+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11272 #endif /* PAGETABLE_LEVELS == 4 */
11273 #endif /* PAGETABLE_LEVELS >= 3 */
11274
11275@@ -324,6 +325,12 @@ struct pv_mmu_ops {
11276 an mfn. We can tell which is which from the index. */
11277 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11278 phys_addr_t phys, pgprot_t flags);
11279+
11280+#ifdef CONFIG_PAX_KERNEXEC
11281+ unsigned long (*pax_open_kernel)(void);
11282+ unsigned long (*pax_close_kernel)(void);
11283+#endif
11284+
11285 };
11286
11287 struct arch_spinlock;
11288@@ -334,7 +341,7 @@ struct pv_lock_ops {
11289 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11290 int (*spin_trylock)(struct arch_spinlock *lock);
11291 void (*spin_unlock)(struct arch_spinlock *lock);
11292-};
11293+} __no_const;
11294
11295 /* This contains all the paravirt structures: we get a convenient
11296 * number for each function using the offset which we use to indicate
11297diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11298index b4389a4..7024269 100644
11299--- a/arch/x86/include/asm/pgalloc.h
11300+++ b/arch/x86/include/asm/pgalloc.h
11301@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11302 pmd_t *pmd, pte_t *pte)
11303 {
11304 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11305+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11306+}
11307+
11308+static inline void pmd_populate_user(struct mm_struct *mm,
11309+ pmd_t *pmd, pte_t *pte)
11310+{
11311+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11312 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11313 }
11314
11315@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11316
11317 #ifdef CONFIG_X86_PAE
11318 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11319+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11320+{
11321+ pud_populate(mm, pudp, pmd);
11322+}
11323 #else /* !CONFIG_X86_PAE */
11324 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11325 {
11326 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11327 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11328 }
11329+
11330+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11331+{
11332+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11333+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11334+}
11335 #endif /* CONFIG_X86_PAE */
11336
11337 #if PAGETABLE_LEVELS > 3
11338@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11339 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11340 }
11341
11342+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11343+{
11344+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11345+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11346+}
11347+
11348 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11349 {
11350 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11351diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11352index 98391db..8f6984e 100644
11353--- a/arch/x86/include/asm/pgtable-2level.h
11354+++ b/arch/x86/include/asm/pgtable-2level.h
11355@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11356
11357 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11358 {
11359+ pax_open_kernel();
11360 *pmdp = pmd;
11361+ pax_close_kernel();
11362 }
11363
11364 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11365diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11366index effff47..bbb8295 100644
11367--- a/arch/x86/include/asm/pgtable-3level.h
11368+++ b/arch/x86/include/asm/pgtable-3level.h
11369@@ -31,6 +31,56 @@ static inline void native_set_pte(pte_t *ptep, pte_t pte)
11370 ptep->pte_low = pte.pte_low;
11371 }
11372
11373+#define __HAVE_ARCH_READ_PMD_ATOMIC
11374+/*
11375+ * pte_offset_map_lock on 32bit PAE kernels was reading the pmd_t with
11376+ * a "*pmdp" dereference done by gcc. Problem is, in certain places
11377+ * where pte_offset_map_lock is called, concurrent page faults are
11378+ * allowed, if the mmap_sem is hold for reading. An example is mincore
11379+ * vs page faults vs MADV_DONTNEED. On the page fault side
11380+ * pmd_populate rightfully does a set_64bit, but if we're reading the
11381+ * pmd_t with a "*pmdp" on the mincore side, a SMP race can happen
11382+ * because gcc will not read the 64bit of the pmd atomically. To fix
11383+ * this all places running pmd_offset_map_lock() while holding the
11384+ * mmap_sem in read mode, shall read the pmdp pointer using this
11385+ * function to know if the pmd is null nor not, and in turn to know if
11386+ * they can run pmd_offset_map_lock or pmd_trans_huge or other pmd
11387+ * operations.
11388+ *
11389+ * Without THP if the mmap_sem is hold for reading, the
11390+ * pmd can only transition from null to not null while read_pmd_atomic runs.
11391+ * So there's no need of literally reading it atomically.
11392+ *
11393+ * With THP if the mmap_sem is hold for reading, the pmd can become
11394+ * THP or null or point to a pte (and in turn become "stable") at any
11395+ * time under read_pmd_atomic, so it's mandatory to read it atomically
11396+ * with cmpxchg8b.
11397+ */
11398+#ifndef CONFIG_TRANSPARENT_HUGEPAGE
11399+static inline pmd_t read_pmd_atomic(pmd_t *pmdp)
11400+{
11401+ pmdval_t ret;
11402+ u32 *tmp = (u32 *)pmdp;
11403+
11404+ ret = (pmdval_t) (*tmp);
11405+ if (ret) {
11406+ /*
11407+ * If the low part is null, we must not read the high part
11408+ * or we can end up with a partial pmd.
11409+ */
11410+ smp_rmb();
11411+ ret |= ((pmdval_t)*(tmp + 1)) << 32;
11412+ }
11413+
11414+ return __pmd(ret);
11415+}
11416+#else /* CONFIG_TRANSPARENT_HUGEPAGE */
11417+static inline pmd_t read_pmd_atomic(pmd_t *pmdp)
11418+{
11419+ return __pmd(atomic64_read((atomic64_t *)pmdp));
11420+}
11421+#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
11422+
11423 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11424 {
11425 set_64bit((unsigned long long *)(ptep), native_pte_val(pte));
11426@@ -38,12 +88,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11427
11428 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11429 {
11430+ pax_open_kernel();
11431 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11432+ pax_close_kernel();
11433 }
11434
11435 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11436 {
11437+ pax_open_kernel();
11438 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11439+ pax_close_kernel();
11440 }
11441
11442 /*
11443diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11444index 49afb3f..91a8c63 100644
11445--- a/arch/x86/include/asm/pgtable.h
11446+++ b/arch/x86/include/asm/pgtable.h
11447@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11448
11449 #ifndef __PAGETABLE_PUD_FOLDED
11450 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11451+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11452 #define pgd_clear(pgd) native_pgd_clear(pgd)
11453 #endif
11454
11455@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11456
11457 #define arch_end_context_switch(prev) do {} while(0)
11458
11459+#define pax_open_kernel() native_pax_open_kernel()
11460+#define pax_close_kernel() native_pax_close_kernel()
11461 #endif /* CONFIG_PARAVIRT */
11462
11463+#define __HAVE_ARCH_PAX_OPEN_KERNEL
11464+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11465+
11466+#ifdef CONFIG_PAX_KERNEXEC
11467+static inline unsigned long native_pax_open_kernel(void)
11468+{
11469+ unsigned long cr0;
11470+
11471+ preempt_disable();
11472+ barrier();
11473+ cr0 = read_cr0() ^ X86_CR0_WP;
11474+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
11475+ write_cr0(cr0);
11476+ return cr0 ^ X86_CR0_WP;
11477+}
11478+
11479+static inline unsigned long native_pax_close_kernel(void)
11480+{
11481+ unsigned long cr0;
11482+
11483+ cr0 = read_cr0() ^ X86_CR0_WP;
11484+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11485+ write_cr0(cr0);
11486+ barrier();
11487+ preempt_enable_no_resched();
11488+ return cr0 ^ X86_CR0_WP;
11489+}
11490+#else
11491+static inline unsigned long native_pax_open_kernel(void) { return 0; }
11492+static inline unsigned long native_pax_close_kernel(void) { return 0; }
11493+#endif
11494+
11495 /*
11496 * The following only work if pte_present() is true.
11497 * Undefined behaviour if not..
11498 */
11499+static inline int pte_user(pte_t pte)
11500+{
11501+ return pte_val(pte) & _PAGE_USER;
11502+}
11503+
11504 static inline int pte_dirty(pte_t pte)
11505 {
11506 return pte_flags(pte) & _PAGE_DIRTY;
11507@@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11508 return pte_clear_flags(pte, _PAGE_RW);
11509 }
11510
11511+static inline pte_t pte_mkread(pte_t pte)
11512+{
11513+ return __pte(pte_val(pte) | _PAGE_USER);
11514+}
11515+
11516 static inline pte_t pte_mkexec(pte_t pte)
11517 {
11518- return pte_clear_flags(pte, _PAGE_NX);
11519+#ifdef CONFIG_X86_PAE
11520+ if (__supported_pte_mask & _PAGE_NX)
11521+ return pte_clear_flags(pte, _PAGE_NX);
11522+ else
11523+#endif
11524+ return pte_set_flags(pte, _PAGE_USER);
11525+}
11526+
11527+static inline pte_t pte_exprotect(pte_t pte)
11528+{
11529+#ifdef CONFIG_X86_PAE
11530+ if (__supported_pte_mask & _PAGE_NX)
11531+ return pte_set_flags(pte, _PAGE_NX);
11532+ else
11533+#endif
11534+ return pte_clear_flags(pte, _PAGE_USER);
11535 }
11536
11537 static inline pte_t pte_mkdirty(pte_t pte)
11538@@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11539 #endif
11540
11541 #ifndef __ASSEMBLY__
11542+
11543+#ifdef CONFIG_PAX_PER_CPU_PGD
11544+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11545+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11546+{
11547+ return cpu_pgd[cpu];
11548+}
11549+#endif
11550+
11551 #include <linux/mm_types.h>
11552
11553 static inline int pte_none(pte_t pte)
11554@@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11555
11556 static inline int pgd_bad(pgd_t pgd)
11557 {
11558- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11559+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11560 }
11561
11562 static inline int pgd_none(pgd_t pgd)
11563@@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11564 * pgd_offset() returns a (pgd_t *)
11565 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11566 */
11567-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11568+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11569+
11570+#ifdef CONFIG_PAX_PER_CPU_PGD
11571+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11572+#endif
11573+
11574 /*
11575 * a shortcut which implies the use of the kernel's pgd, instead
11576 * of a process's
11577@@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11578 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11579 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11580
11581+#ifdef CONFIG_X86_32
11582+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11583+#else
11584+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11585+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11586+
11587+#ifdef CONFIG_PAX_MEMORY_UDEREF
11588+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11589+#else
11590+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11591+#endif
11592+
11593+#endif
11594+
11595 #ifndef __ASSEMBLY__
11596
11597 extern int direct_gbpages;
11598@@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11599 * dst and src can be on the same page, but the range must not overlap,
11600 * and must not cross a page boundary.
11601 */
11602-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11603+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11604 {
11605- memcpy(dst, src, count * sizeof(pgd_t));
11606+ pax_open_kernel();
11607+ while (count--)
11608+ *dst++ = *src++;
11609+ pax_close_kernel();
11610 }
11611
11612+#ifdef CONFIG_PAX_PER_CPU_PGD
11613+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11614+#endif
11615+
11616+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11617+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11618+#else
11619+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11620+#endif
11621
11622 #include <asm-generic/pgtable.h>
11623 #endif /* __ASSEMBLY__ */
11624diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11625index 0c92113..34a77c6 100644
11626--- a/arch/x86/include/asm/pgtable_32.h
11627+++ b/arch/x86/include/asm/pgtable_32.h
11628@@ -25,9 +25,6 @@
11629 struct mm_struct;
11630 struct vm_area_struct;
11631
11632-extern pgd_t swapper_pg_dir[1024];
11633-extern pgd_t initial_page_table[1024];
11634-
11635 static inline void pgtable_cache_init(void) { }
11636 static inline void check_pgt_cache(void) { }
11637 void paging_init(void);
11638@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11639 # include <asm/pgtable-2level.h>
11640 #endif
11641
11642+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11643+extern pgd_t initial_page_table[PTRS_PER_PGD];
11644+#ifdef CONFIG_X86_PAE
11645+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11646+#endif
11647+
11648 #if defined(CONFIG_HIGHPTE)
11649 #define pte_offset_map(dir, address) \
11650 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11651@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11652 /* Clear a kernel PTE and flush it from the TLB */
11653 #define kpte_clear_flush(ptep, vaddr) \
11654 do { \
11655+ pax_open_kernel(); \
11656 pte_clear(&init_mm, (vaddr), (ptep)); \
11657+ pax_close_kernel(); \
11658 __flush_tlb_one((vaddr)); \
11659 } while (0)
11660
11661@@ -74,6 +79,9 @@ do { \
11662
11663 #endif /* !__ASSEMBLY__ */
11664
11665+#define HAVE_ARCH_UNMAPPED_AREA
11666+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11667+
11668 /*
11669 * kern_addr_valid() is (1) for FLATMEM and (0) for
11670 * SPARSEMEM and DISCONTIGMEM
11671diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11672index ed5903b..c7fe163 100644
11673--- a/arch/x86/include/asm/pgtable_32_types.h
11674+++ b/arch/x86/include/asm/pgtable_32_types.h
11675@@ -8,7 +8,7 @@
11676 */
11677 #ifdef CONFIG_X86_PAE
11678 # include <asm/pgtable-3level_types.h>
11679-# define PMD_SIZE (1UL << PMD_SHIFT)
11680+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11681 # define PMD_MASK (~(PMD_SIZE - 1))
11682 #else
11683 # include <asm/pgtable-2level_types.h>
11684@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11685 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11686 #endif
11687
11688+#ifdef CONFIG_PAX_KERNEXEC
11689+#ifndef __ASSEMBLY__
11690+extern unsigned char MODULES_EXEC_VADDR[];
11691+extern unsigned char MODULES_EXEC_END[];
11692+#endif
11693+#include <asm/boot.h>
11694+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11695+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11696+#else
11697+#define ktla_ktva(addr) (addr)
11698+#define ktva_ktla(addr) (addr)
11699+#endif
11700+
11701 #define MODULES_VADDR VMALLOC_START
11702 #define MODULES_END VMALLOC_END
11703 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11704diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11705index 975f709..9f779c9 100644
11706--- a/arch/x86/include/asm/pgtable_64.h
11707+++ b/arch/x86/include/asm/pgtable_64.h
11708@@ -16,10 +16,14 @@
11709
11710 extern pud_t level3_kernel_pgt[512];
11711 extern pud_t level3_ident_pgt[512];
11712+extern pud_t level3_vmalloc_start_pgt[512];
11713+extern pud_t level3_vmalloc_end_pgt[512];
11714+extern pud_t level3_vmemmap_pgt[512];
11715+extern pud_t level2_vmemmap_pgt[512];
11716 extern pmd_t level2_kernel_pgt[512];
11717 extern pmd_t level2_fixmap_pgt[512];
11718-extern pmd_t level2_ident_pgt[512];
11719-extern pgd_t init_level4_pgt[];
11720+extern pmd_t level2_ident_pgt[512*2];
11721+extern pgd_t init_level4_pgt[512];
11722
11723 #define swapper_pg_dir init_level4_pgt
11724
11725@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11726
11727 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11728 {
11729+ pax_open_kernel();
11730 *pmdp = pmd;
11731+ pax_close_kernel();
11732 }
11733
11734 static inline void native_pmd_clear(pmd_t *pmd)
11735@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11736
11737 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11738 {
11739+ pax_open_kernel();
11740 *pudp = pud;
11741+ pax_close_kernel();
11742 }
11743
11744 static inline void native_pud_clear(pud_t *pud)
11745@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11746
11747 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11748 {
11749+ pax_open_kernel();
11750+ *pgdp = pgd;
11751+ pax_close_kernel();
11752+}
11753+
11754+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11755+{
11756 *pgdp = pgd;
11757 }
11758
11759diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11760index 766ea16..5b96cb3 100644
11761--- a/arch/x86/include/asm/pgtable_64_types.h
11762+++ b/arch/x86/include/asm/pgtable_64_types.h
11763@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11764 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11765 #define MODULES_END _AC(0xffffffffff000000, UL)
11766 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11767+#define MODULES_EXEC_VADDR MODULES_VADDR
11768+#define MODULES_EXEC_END MODULES_END
11769+
11770+#define ktla_ktva(addr) (addr)
11771+#define ktva_ktla(addr) (addr)
11772
11773 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11774diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11775index 013286a..8b42f4f 100644
11776--- a/arch/x86/include/asm/pgtable_types.h
11777+++ b/arch/x86/include/asm/pgtable_types.h
11778@@ -16,13 +16,12 @@
11779 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11780 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11781 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11782-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11783+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11784 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11785 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11786 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11787-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11788-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11789-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11790+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11791+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11792 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11793
11794 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11795@@ -40,7 +39,6 @@
11796 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11797 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11798 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11799-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11800 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11801 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11802 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11803@@ -57,8 +55,10 @@
11804
11805 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11806 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11807-#else
11808+#elif defined(CONFIG_KMEMCHECK)
11809 #define _PAGE_NX (_AT(pteval_t, 0))
11810+#else
11811+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11812 #endif
11813
11814 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11815@@ -96,6 +96,9 @@
11816 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11817 _PAGE_ACCESSED)
11818
11819+#define PAGE_READONLY_NOEXEC PAGE_READONLY
11820+#define PAGE_SHARED_NOEXEC PAGE_SHARED
11821+
11822 #define __PAGE_KERNEL_EXEC \
11823 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11824 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11825@@ -106,7 +109,7 @@
11826 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11827 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11828 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11829-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11830+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11831 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11832 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11833 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11834@@ -168,8 +171,8 @@
11835 * bits are combined, this will alow user to access the high address mapped
11836 * VDSO in the presence of CONFIG_COMPAT_VDSO
11837 */
11838-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11839-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11840+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11841+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11842 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11843 #endif
11844
11845@@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11846 {
11847 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11848 }
11849+#endif
11850
11851+#if PAGETABLE_LEVELS == 3
11852+#include <asm-generic/pgtable-nopud.h>
11853+#endif
11854+
11855+#if PAGETABLE_LEVELS == 2
11856+#include <asm-generic/pgtable-nopmd.h>
11857+#endif
11858+
11859+#ifndef __ASSEMBLY__
11860 #if PAGETABLE_LEVELS > 3
11861 typedef struct { pudval_t pud; } pud_t;
11862
11863@@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11864 return pud.pud;
11865 }
11866 #else
11867-#include <asm-generic/pgtable-nopud.h>
11868-
11869 static inline pudval_t native_pud_val(pud_t pud)
11870 {
11871 return native_pgd_val(pud.pgd);
11872@@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11873 return pmd.pmd;
11874 }
11875 #else
11876-#include <asm-generic/pgtable-nopmd.h>
11877-
11878 static inline pmdval_t native_pmd_val(pmd_t pmd)
11879 {
11880 return native_pgd_val(pmd.pud.pgd);
11881@@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11882
11883 extern pteval_t __supported_pte_mask;
11884 extern void set_nx(void);
11885-extern int nx_enabled;
11886
11887 #define pgprot_writecombine pgprot_writecombine
11888 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11889diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11890index 58545c9..fe6fc38e 100644
11891--- a/arch/x86/include/asm/processor.h
11892+++ b/arch/x86/include/asm/processor.h
11893@@ -266,7 +266,7 @@ struct tss_struct {
11894
11895 } ____cacheline_aligned;
11896
11897-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11898+extern struct tss_struct init_tss[NR_CPUS];
11899
11900 /*
11901 * Save the original ist values for checking stack pointers during debugging
11902@@ -860,11 +860,18 @@ static inline void spin_lock_prefetch(const void *x)
11903 */
11904 #define TASK_SIZE PAGE_OFFSET
11905 #define TASK_SIZE_MAX TASK_SIZE
11906+
11907+#ifdef CONFIG_PAX_SEGMEXEC
11908+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11909+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11910+#else
11911 #define STACK_TOP TASK_SIZE
11912-#define STACK_TOP_MAX STACK_TOP
11913+#endif
11914+
11915+#define STACK_TOP_MAX TASK_SIZE
11916
11917 #define INIT_THREAD { \
11918- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11919+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11920 .vm86_info = NULL, \
11921 .sysenter_cs = __KERNEL_CS, \
11922 .io_bitmap_ptr = NULL, \
11923@@ -878,7 +885,7 @@ static inline void spin_lock_prefetch(const void *x)
11924 */
11925 #define INIT_TSS { \
11926 .x86_tss = { \
11927- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11928+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11929 .ss0 = __KERNEL_DS, \
11930 .ss1 = __KERNEL_CS, \
11931 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11932@@ -889,11 +896,7 @@ static inline void spin_lock_prefetch(const void *x)
11933 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11934
11935 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11936-#define KSTK_TOP(info) \
11937-({ \
11938- unsigned long *__ptr = (unsigned long *)(info); \
11939- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11940-})
11941+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11942
11943 /*
11944 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11945@@ -908,7 +911,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11946 #define task_pt_regs(task) \
11947 ({ \
11948 struct pt_regs *__regs__; \
11949- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11950+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11951 __regs__ - 1; \
11952 })
11953
11954@@ -918,13 +921,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11955 /*
11956 * User space process size. 47bits minus one guard page.
11957 */
11958-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11959+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11960
11961 /* This decides where the kernel will search for a free chunk of vm
11962 * space during mmap's.
11963 */
11964 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11965- 0xc0000000 : 0xFFFFe000)
11966+ 0xc0000000 : 0xFFFFf000)
11967
11968 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
11969 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11970@@ -935,11 +938,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11971 #define STACK_TOP_MAX TASK_SIZE_MAX
11972
11973 #define INIT_THREAD { \
11974- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11975+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11976 }
11977
11978 #define INIT_TSS { \
11979- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11980+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11981 }
11982
11983 /*
11984@@ -961,6 +964,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11985 */
11986 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11987
11988+#ifdef CONFIG_PAX_SEGMEXEC
11989+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11990+#endif
11991+
11992 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11993
11994 /* Get/set a process' ability to use the timestamp counter instruction */
11995diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11996index 3566454..4bdfb8c 100644
11997--- a/arch/x86/include/asm/ptrace.h
11998+++ b/arch/x86/include/asm/ptrace.h
11999@@ -156,28 +156,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
12000 }
12001
12002 /*
12003- * user_mode_vm(regs) determines whether a register set came from user mode.
12004+ * user_mode(regs) determines whether a register set came from user mode.
12005 * This is true if V8086 mode was enabled OR if the register set was from
12006 * protected mode with RPL-3 CS value. This tricky test checks that with
12007 * one comparison. Many places in the kernel can bypass this full check
12008- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
12009+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
12010+ * be used.
12011 */
12012-static inline int user_mode(struct pt_regs *regs)
12013+static inline int user_mode_novm(struct pt_regs *regs)
12014 {
12015 #ifdef CONFIG_X86_32
12016 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
12017 #else
12018- return !!(regs->cs & 3);
12019+ return !!(regs->cs & SEGMENT_RPL_MASK);
12020 #endif
12021 }
12022
12023-static inline int user_mode_vm(struct pt_regs *regs)
12024+static inline int user_mode(struct pt_regs *regs)
12025 {
12026 #ifdef CONFIG_X86_32
12027 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
12028 USER_RPL;
12029 #else
12030- return user_mode(regs);
12031+ return user_mode_novm(regs);
12032 #endif
12033 }
12034
12035@@ -193,15 +194,16 @@ static inline int v8086_mode(struct pt_regs *regs)
12036 #ifdef CONFIG_X86_64
12037 static inline bool user_64bit_mode(struct pt_regs *regs)
12038 {
12039+ unsigned long cs = regs->cs & 0xffff;
12040 #ifndef CONFIG_PARAVIRT
12041 /*
12042 * On non-paravirt systems, this is the only long mode CPL 3
12043 * selector. We do not allow long mode selectors in the LDT.
12044 */
12045- return regs->cs == __USER_CS;
12046+ return cs == __USER_CS;
12047 #else
12048 /* Headers are too twisted for this to go in paravirt.h. */
12049- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12050+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12051 #endif
12052 }
12053 #endif
12054diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12055index 92f29706..a79cbbb 100644
12056--- a/arch/x86/include/asm/reboot.h
12057+++ b/arch/x86/include/asm/reboot.h
12058@@ -6,19 +6,19 @@
12059 struct pt_regs;
12060
12061 struct machine_ops {
12062- void (*restart)(char *cmd);
12063- void (*halt)(void);
12064- void (*power_off)(void);
12065+ void (* __noreturn restart)(char *cmd);
12066+ void (* __noreturn halt)(void);
12067+ void (* __noreturn power_off)(void);
12068 void (*shutdown)(void);
12069 void (*crash_shutdown)(struct pt_regs *);
12070- void (*emergency_restart)(void);
12071-};
12072+ void (* __noreturn emergency_restart)(void);
12073+} __no_const;
12074
12075 extern struct machine_ops machine_ops;
12076
12077 void native_machine_crash_shutdown(struct pt_regs *regs);
12078 void native_machine_shutdown(void);
12079-void machine_real_restart(unsigned int type);
12080+void machine_real_restart(unsigned int type) __noreturn;
12081 /* These must match dispatch_table in reboot_32.S */
12082 #define MRR_BIOS 0
12083 #define MRR_APM 1
12084diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12085index 2dbe4a7..ce1db00 100644
12086--- a/arch/x86/include/asm/rwsem.h
12087+++ b/arch/x86/include/asm/rwsem.h
12088@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12089 {
12090 asm volatile("# beginning down_read\n\t"
12091 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12092+
12093+#ifdef CONFIG_PAX_REFCOUNT
12094+ "jno 0f\n"
12095+ LOCK_PREFIX _ASM_DEC "(%1)\n"
12096+ "int $4\n0:\n"
12097+ _ASM_EXTABLE(0b, 0b)
12098+#endif
12099+
12100 /* adds 0x00000001 */
12101 " jns 1f\n"
12102 " call call_rwsem_down_read_failed\n"
12103@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12104 "1:\n\t"
12105 " mov %1,%2\n\t"
12106 " add %3,%2\n\t"
12107+
12108+#ifdef CONFIG_PAX_REFCOUNT
12109+ "jno 0f\n"
12110+ "sub %3,%2\n"
12111+ "int $4\n0:\n"
12112+ _ASM_EXTABLE(0b, 0b)
12113+#endif
12114+
12115 " jle 2f\n\t"
12116 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12117 " jnz 1b\n\t"
12118@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12119 long tmp;
12120 asm volatile("# beginning down_write\n\t"
12121 LOCK_PREFIX " xadd %1,(%2)\n\t"
12122+
12123+#ifdef CONFIG_PAX_REFCOUNT
12124+ "jno 0f\n"
12125+ "mov %1,(%2)\n"
12126+ "int $4\n0:\n"
12127+ _ASM_EXTABLE(0b, 0b)
12128+#endif
12129+
12130 /* adds 0xffff0001, returns the old value */
12131 " test %1,%1\n\t"
12132 /* was the count 0 before? */
12133@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12134 long tmp;
12135 asm volatile("# beginning __up_read\n\t"
12136 LOCK_PREFIX " xadd %1,(%2)\n\t"
12137+
12138+#ifdef CONFIG_PAX_REFCOUNT
12139+ "jno 0f\n"
12140+ "mov %1,(%2)\n"
12141+ "int $4\n0:\n"
12142+ _ASM_EXTABLE(0b, 0b)
12143+#endif
12144+
12145 /* subtracts 1, returns the old value */
12146 " jns 1f\n\t"
12147 " call call_rwsem_wake\n" /* expects old value in %edx */
12148@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12149 long tmp;
12150 asm volatile("# beginning __up_write\n\t"
12151 LOCK_PREFIX " xadd %1,(%2)\n\t"
12152+
12153+#ifdef CONFIG_PAX_REFCOUNT
12154+ "jno 0f\n"
12155+ "mov %1,(%2)\n"
12156+ "int $4\n0:\n"
12157+ _ASM_EXTABLE(0b, 0b)
12158+#endif
12159+
12160 /* subtracts 0xffff0001, returns the old value */
12161 " jns 1f\n\t"
12162 " call call_rwsem_wake\n" /* expects old value in %edx */
12163@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12164 {
12165 asm volatile("# beginning __downgrade_write\n\t"
12166 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12167+
12168+#ifdef CONFIG_PAX_REFCOUNT
12169+ "jno 0f\n"
12170+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12171+ "int $4\n0:\n"
12172+ _ASM_EXTABLE(0b, 0b)
12173+#endif
12174+
12175 /*
12176 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12177 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12178@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12179 */
12180 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12181 {
12182- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12183+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12184+
12185+#ifdef CONFIG_PAX_REFCOUNT
12186+ "jno 0f\n"
12187+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
12188+ "int $4\n0:\n"
12189+ _ASM_EXTABLE(0b, 0b)
12190+#endif
12191+
12192 : "+m" (sem->count)
12193 : "er" (delta));
12194 }
12195@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12196 */
12197 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12198 {
12199- return delta + xadd(&sem->count, delta);
12200+ return delta + xadd_check_overflow(&sem->count, delta);
12201 }
12202
12203 #endif /* __KERNEL__ */
12204diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12205index 5e64171..f58957e 100644
12206--- a/arch/x86/include/asm/segment.h
12207+++ b/arch/x86/include/asm/segment.h
12208@@ -64,10 +64,15 @@
12209 * 26 - ESPFIX small SS
12210 * 27 - per-cpu [ offset to per-cpu data area ]
12211 * 28 - stack_canary-20 [ for stack protector ]
12212- * 29 - unused
12213- * 30 - unused
12214+ * 29 - PCI BIOS CS
12215+ * 30 - PCI BIOS DS
12216 * 31 - TSS for double fault handler
12217 */
12218+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12219+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12220+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12221+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12222+
12223 #define GDT_ENTRY_TLS_MIN 6
12224 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12225
12226@@ -79,6 +84,8 @@
12227
12228 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12229
12230+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12231+
12232 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12233
12234 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12235@@ -104,6 +111,12 @@
12236 #define __KERNEL_STACK_CANARY 0
12237 #endif
12238
12239+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12240+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12241+
12242+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12243+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12244+
12245 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12246
12247 /*
12248@@ -141,7 +154,7 @@
12249 */
12250
12251 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12252-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12253+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12254
12255
12256 #else
12257@@ -165,6 +178,8 @@
12258 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12259 #define __USER32_DS __USER_DS
12260
12261+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12262+
12263 #define GDT_ENTRY_TSS 8 /* needs two entries */
12264 #define GDT_ENTRY_LDT 10 /* needs two entries */
12265 #define GDT_ENTRY_TLS_MIN 12
12266@@ -185,6 +200,7 @@
12267 #endif
12268
12269 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12270+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12271 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12272 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12273 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12274diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12275index 0434c40..1714bf0 100644
12276--- a/arch/x86/include/asm/smp.h
12277+++ b/arch/x86/include/asm/smp.h
12278@@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
12279 /* cpus sharing the last level cache: */
12280 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
12281 DECLARE_PER_CPU(u16, cpu_llc_id);
12282-DECLARE_PER_CPU(int, cpu_number);
12283+DECLARE_PER_CPU(unsigned int, cpu_number);
12284
12285 static inline struct cpumask *cpu_sibling_mask(int cpu)
12286 {
12287@@ -77,7 +77,7 @@ struct smp_ops {
12288
12289 void (*send_call_func_ipi)(const struct cpumask *mask);
12290 void (*send_call_func_single_ipi)(int cpu);
12291-};
12292+} __no_const;
12293
12294 /* Globals due to paravirt */
12295 extern void set_cpu_sibling_map(int cpu);
12296@@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12297 extern int safe_smp_processor_id(void);
12298
12299 #elif defined(CONFIG_X86_64_SMP)
12300-#define raw_smp_processor_id() (percpu_read(cpu_number))
12301-
12302-#define stack_smp_processor_id() \
12303-({ \
12304- struct thread_info *ti; \
12305- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12306- ti->cpu; \
12307-})
12308+#define raw_smp_processor_id() (percpu_read(cpu_number))
12309+#define stack_smp_processor_id() raw_smp_processor_id()
12310 #define safe_smp_processor_id() smp_processor_id()
12311
12312 #endif
12313diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12314index a82c2bf..2198f61 100644
12315--- a/arch/x86/include/asm/spinlock.h
12316+++ b/arch/x86/include/asm/spinlock.h
12317@@ -175,6 +175,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12318 static inline void arch_read_lock(arch_rwlock_t *rw)
12319 {
12320 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12321+
12322+#ifdef CONFIG_PAX_REFCOUNT
12323+ "jno 0f\n"
12324+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12325+ "int $4\n0:\n"
12326+ _ASM_EXTABLE(0b, 0b)
12327+#endif
12328+
12329 "jns 1f\n"
12330 "call __read_lock_failed\n\t"
12331 "1:\n"
12332@@ -184,6 +192,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12333 static inline void arch_write_lock(arch_rwlock_t *rw)
12334 {
12335 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12336+
12337+#ifdef CONFIG_PAX_REFCOUNT
12338+ "jno 0f\n"
12339+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12340+ "int $4\n0:\n"
12341+ _ASM_EXTABLE(0b, 0b)
12342+#endif
12343+
12344 "jz 1f\n"
12345 "call __write_lock_failed\n\t"
12346 "1:\n"
12347@@ -213,13 +229,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12348
12349 static inline void arch_read_unlock(arch_rwlock_t *rw)
12350 {
12351- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12352+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12353+
12354+#ifdef CONFIG_PAX_REFCOUNT
12355+ "jno 0f\n"
12356+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12357+ "int $4\n0:\n"
12358+ _ASM_EXTABLE(0b, 0b)
12359+#endif
12360+
12361 :"+m" (rw->lock) : : "memory");
12362 }
12363
12364 static inline void arch_write_unlock(arch_rwlock_t *rw)
12365 {
12366- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12367+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12368+
12369+#ifdef CONFIG_PAX_REFCOUNT
12370+ "jno 0f\n"
12371+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12372+ "int $4\n0:\n"
12373+ _ASM_EXTABLE(0b, 0b)
12374+#endif
12375+
12376 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12377 }
12378
12379diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12380index 1575177..cb23f52 100644
12381--- a/arch/x86/include/asm/stackprotector.h
12382+++ b/arch/x86/include/asm/stackprotector.h
12383@@ -48,7 +48,7 @@
12384 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12385 */
12386 #define GDT_STACK_CANARY_INIT \
12387- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12388+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12389
12390 /*
12391 * Initialize the stackprotector canary value.
12392@@ -113,7 +113,7 @@ static inline void setup_stack_canary_segment(int cpu)
12393
12394 static inline void load_stack_canary_segment(void)
12395 {
12396-#ifdef CONFIG_X86_32
12397+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12398 asm volatile ("mov %0, %%gs" : : "r" (0));
12399 #endif
12400 }
12401diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12402index 70bbe39..4ae2bd4 100644
12403--- a/arch/x86/include/asm/stacktrace.h
12404+++ b/arch/x86/include/asm/stacktrace.h
12405@@ -11,28 +11,20 @@
12406
12407 extern int kstack_depth_to_print;
12408
12409-struct thread_info;
12410+struct task_struct;
12411 struct stacktrace_ops;
12412
12413-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12414- unsigned long *stack,
12415- unsigned long bp,
12416- const struct stacktrace_ops *ops,
12417- void *data,
12418- unsigned long *end,
12419- int *graph);
12420+typedef unsigned long walk_stack_t(struct task_struct *task,
12421+ void *stack_start,
12422+ unsigned long *stack,
12423+ unsigned long bp,
12424+ const struct stacktrace_ops *ops,
12425+ void *data,
12426+ unsigned long *end,
12427+ int *graph);
12428
12429-extern unsigned long
12430-print_context_stack(struct thread_info *tinfo,
12431- unsigned long *stack, unsigned long bp,
12432- const struct stacktrace_ops *ops, void *data,
12433- unsigned long *end, int *graph);
12434-
12435-extern unsigned long
12436-print_context_stack_bp(struct thread_info *tinfo,
12437- unsigned long *stack, unsigned long bp,
12438- const struct stacktrace_ops *ops, void *data,
12439- unsigned long *end, int *graph);
12440+extern walk_stack_t print_context_stack;
12441+extern walk_stack_t print_context_stack_bp;
12442
12443 /* Generic stack tracer with callbacks */
12444
12445@@ -40,7 +32,7 @@ struct stacktrace_ops {
12446 void (*address)(void *data, unsigned long address, int reliable);
12447 /* On negative return stop dumping */
12448 int (*stack)(void *data, char *name);
12449- walk_stack_t walk_stack;
12450+ walk_stack_t *walk_stack;
12451 };
12452
12453 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12454diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12455index cb23852..2dde194 100644
12456--- a/arch/x86/include/asm/sys_ia32.h
12457+++ b/arch/x86/include/asm/sys_ia32.h
12458@@ -40,7 +40,7 @@ asmlinkage long sys32_rt_sigprocmask(int, compat_sigset_t __user *,
12459 compat_sigset_t __user *, unsigned int);
12460 asmlinkage long sys32_alarm(unsigned int);
12461
12462-asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12463+asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12464 asmlinkage long sys32_sysfs(int, u32, u32);
12465
12466 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12467diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
12468index 2d2f01c..f985723 100644
12469--- a/arch/x86/include/asm/system.h
12470+++ b/arch/x86/include/asm/system.h
12471@@ -129,7 +129,7 @@ do { \
12472 "call __switch_to\n\t" \
12473 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12474 __switch_canary \
12475- "movq %P[thread_info](%%rsi),%%r8\n\t" \
12476+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12477 "movq %%rax,%%rdi\n\t" \
12478 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12479 "jnz ret_from_fork\n\t" \
12480@@ -140,7 +140,7 @@ do { \
12481 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12482 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12483 [_tif_fork] "i" (_TIF_FORK), \
12484- [thread_info] "i" (offsetof(struct task_struct, stack)), \
12485+ [thread_info] "m" (current_tinfo), \
12486 [current_task] "m" (current_task) \
12487 __switch_canary_iparam \
12488 : "memory", "cc" __EXTRA_CLOBBER)
12489@@ -200,7 +200,7 @@ static inline unsigned long get_limit(unsigned long segment)
12490 {
12491 unsigned long __limit;
12492 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12493- return __limit + 1;
12494+ return __limit;
12495 }
12496
12497 static inline void native_clts(void)
12498@@ -397,13 +397,13 @@ void enable_hlt(void);
12499
12500 void cpu_idle_wait(void);
12501
12502-extern unsigned long arch_align_stack(unsigned long sp);
12503+#define arch_align_stack(x) ((x) & ~0xfUL)
12504 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
12505
12506 void default_idle(void);
12507 bool set_pm_idle_to_default(void);
12508
12509-void stop_this_cpu(void *dummy);
12510+void stop_this_cpu(void *dummy) __noreturn;
12511
12512 /*
12513 * Force strict CPU ordering.
12514diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12515index cfd8144..664ac89 100644
12516--- a/arch/x86/include/asm/thread_info.h
12517+++ b/arch/x86/include/asm/thread_info.h
12518@@ -10,6 +10,7 @@
12519 #include <linux/compiler.h>
12520 #include <asm/page.h>
12521 #include <asm/types.h>
12522+#include <asm/percpu.h>
12523
12524 /*
12525 * low level task data that entry.S needs immediate access to
12526@@ -24,7 +25,6 @@ struct exec_domain;
12527 #include <linux/atomic.h>
12528
12529 struct thread_info {
12530- struct task_struct *task; /* main task structure */
12531 struct exec_domain *exec_domain; /* execution domain */
12532 __u32 flags; /* low level flags */
12533 __u32 status; /* thread synchronous flags */
12534@@ -34,19 +34,13 @@ struct thread_info {
12535 mm_segment_t addr_limit;
12536 struct restart_block restart_block;
12537 void __user *sysenter_return;
12538-#ifdef CONFIG_X86_32
12539- unsigned long previous_esp; /* ESP of the previous stack in
12540- case of nested (IRQ) stacks
12541- */
12542- __u8 supervisor_stack[0];
12543-#endif
12544+ unsigned long lowest_stack;
12545 unsigned int sig_on_uaccess_error:1;
12546 unsigned int uaccess_err:1; /* uaccess failed */
12547 };
12548
12549-#define INIT_THREAD_INFO(tsk) \
12550+#define INIT_THREAD_INFO \
12551 { \
12552- .task = &tsk, \
12553 .exec_domain = &default_exec_domain, \
12554 .flags = 0, \
12555 .cpu = 0, \
12556@@ -57,7 +51,7 @@ struct thread_info {
12557 }, \
12558 }
12559
12560-#define init_thread_info (init_thread_union.thread_info)
12561+#define init_thread_info (init_thread_union.stack)
12562 #define init_stack (init_thread_union.stack)
12563
12564 #else /* !__ASSEMBLY__ */
12565@@ -95,6 +89,7 @@ struct thread_info {
12566 #define TIF_BLOCKSTEP 25 /* set when we want DEBUGCTLMSR_BTF */
12567 #define TIF_LAZY_MMU_UPDATES 27 /* task is updating the mmu lazily */
12568 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12569+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
12570
12571 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12572 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12573@@ -116,16 +111,17 @@ struct thread_info {
12574 #define _TIF_BLOCKSTEP (1 << TIF_BLOCKSTEP)
12575 #define _TIF_LAZY_MMU_UPDATES (1 << TIF_LAZY_MMU_UPDATES)
12576 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12577+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12578
12579 /* work to do in syscall_trace_enter() */
12580 #define _TIF_WORK_SYSCALL_ENTRY \
12581 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12582- _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12583+ _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12584
12585 /* work to do in syscall_trace_leave() */
12586 #define _TIF_WORK_SYSCALL_EXIT \
12587 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12588- _TIF_SYSCALL_TRACEPOINT)
12589+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12590
12591 /* work to do on interrupt/exception return */
12592 #define _TIF_WORK_MASK \
12593@@ -135,7 +131,8 @@ struct thread_info {
12594
12595 /* work to do on any return to user space */
12596 #define _TIF_ALLWORK_MASK \
12597- ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12598+ ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12599+ _TIF_GRSEC_SETXID)
12600
12601 /* Only used for 64 bit */
12602 #define _TIF_DO_NOTIFY_MASK \
12603@@ -169,45 +166,40 @@ struct thread_info {
12604 ret; \
12605 })
12606
12607-#ifdef CONFIG_X86_32
12608-
12609-#define STACK_WARN (THREAD_SIZE/8)
12610-/*
12611- * macros/functions for gaining access to the thread information structure
12612- *
12613- * preempt_count needs to be 1 initially, until the scheduler is functional.
12614- */
12615-#ifndef __ASSEMBLY__
12616-
12617-
12618-/* how to get the current stack pointer from C */
12619-register unsigned long current_stack_pointer asm("esp") __used;
12620-
12621-/* how to get the thread information struct from C */
12622-static inline struct thread_info *current_thread_info(void)
12623-{
12624- return (struct thread_info *)
12625- (current_stack_pointer & ~(THREAD_SIZE - 1));
12626-}
12627-
12628-#else /* !__ASSEMBLY__ */
12629-
12630+#ifdef __ASSEMBLY__
12631 /* how to get the thread information struct from ASM */
12632 #define GET_THREAD_INFO(reg) \
12633- movl $-THREAD_SIZE, reg; \
12634- andl %esp, reg
12635+ mov PER_CPU_VAR(current_tinfo), reg
12636
12637 /* use this one if reg already contains %esp */
12638-#define GET_THREAD_INFO_WITH_ESP(reg) \
12639- andl $-THREAD_SIZE, reg
12640+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12641+#else
12642+/* how to get the thread information struct from C */
12643+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12644+
12645+static __always_inline struct thread_info *current_thread_info(void)
12646+{
12647+ return percpu_read_stable(current_tinfo);
12648+}
12649+#endif
12650+
12651+#ifdef CONFIG_X86_32
12652+
12653+#define STACK_WARN (THREAD_SIZE/8)
12654+/*
12655+ * macros/functions for gaining access to the thread information structure
12656+ *
12657+ * preempt_count needs to be 1 initially, until the scheduler is functional.
12658+ */
12659+#ifndef __ASSEMBLY__
12660+
12661+/* how to get the current stack pointer from C */
12662+register unsigned long current_stack_pointer asm("esp") __used;
12663
12664 #endif
12665
12666 #else /* X86_32 */
12667
12668-#include <asm/percpu.h>
12669-#define KERNEL_STACK_OFFSET (5*8)
12670-
12671 /*
12672 * macros/functions for gaining access to the thread information structure
12673 * preempt_count needs to be 1 initially, until the scheduler is functional.
12674@@ -215,27 +207,8 @@ static inline struct thread_info *current_thread_info(void)
12675 #ifndef __ASSEMBLY__
12676 DECLARE_PER_CPU(unsigned long, kernel_stack);
12677
12678-static inline struct thread_info *current_thread_info(void)
12679-{
12680- struct thread_info *ti;
12681- ti = (void *)(percpu_read_stable(kernel_stack) +
12682- KERNEL_STACK_OFFSET - THREAD_SIZE);
12683- return ti;
12684-}
12685-
12686-#else /* !__ASSEMBLY__ */
12687-
12688-/* how to get the thread information struct from ASM */
12689-#define GET_THREAD_INFO(reg) \
12690- movq PER_CPU_VAR(kernel_stack),reg ; \
12691- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12692-
12693-/*
12694- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12695- * a certain register (to be used in assembler memory operands).
12696- */
12697-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12698-
12699+/* how to get the current stack pointer from C */
12700+register unsigned long current_stack_pointer asm("rsp") __used;
12701 #endif
12702
12703 #endif /* !X86_32 */
12704@@ -269,5 +242,16 @@ extern void arch_task_cache_init(void);
12705 extern void free_thread_info(struct thread_info *ti);
12706 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12707 #define arch_task_cache_init arch_task_cache_init
12708+
12709+#define __HAVE_THREAD_FUNCTIONS
12710+#define task_thread_info(task) (&(task)->tinfo)
12711+#define task_stack_page(task) ((task)->stack)
12712+#define setup_thread_stack(p, org) do {} while (0)
12713+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12714+
12715+#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12716+extern struct task_struct *alloc_task_struct_node(int node);
12717+extern void free_task_struct(struct task_struct *);
12718+
12719 #endif
12720 #endif /* _ASM_X86_THREAD_INFO_H */
12721diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12722index 8be5f54..7ae826d 100644
12723--- a/arch/x86/include/asm/uaccess.h
12724+++ b/arch/x86/include/asm/uaccess.h
12725@@ -7,12 +7,15 @@
12726 #include <linux/compiler.h>
12727 #include <linux/thread_info.h>
12728 #include <linux/string.h>
12729+#include <linux/sched.h>
12730 #include <asm/asm.h>
12731 #include <asm/page.h>
12732
12733 #define VERIFY_READ 0
12734 #define VERIFY_WRITE 1
12735
12736+extern void check_object_size(const void *ptr, unsigned long n, bool to);
12737+
12738 /*
12739 * The fs value determines whether argument validity checking should be
12740 * performed or not. If get_fs() == USER_DS, checking is performed, with
12741@@ -28,7 +31,12 @@
12742
12743 #define get_ds() (KERNEL_DS)
12744 #define get_fs() (current_thread_info()->addr_limit)
12745+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12746+void __set_fs(mm_segment_t x);
12747+void set_fs(mm_segment_t x);
12748+#else
12749 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12750+#endif
12751
12752 #define segment_eq(a, b) ((a).seg == (b).seg)
12753
12754@@ -76,7 +84,33 @@
12755 * checks that the pointer is in the user space range - after calling
12756 * this function, memory access functions may still return -EFAULT.
12757 */
12758-#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12759+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12760+#define access_ok(type, addr, size) \
12761+({ \
12762+ long __size = size; \
12763+ unsigned long __addr = (unsigned long)addr; \
12764+ unsigned long __addr_ao = __addr & PAGE_MASK; \
12765+ unsigned long __end_ao = __addr + __size - 1; \
12766+ bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12767+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12768+ while(__addr_ao <= __end_ao) { \
12769+ char __c_ao; \
12770+ __addr_ao += PAGE_SIZE; \
12771+ if (__size > PAGE_SIZE) \
12772+ cond_resched(); \
12773+ if (__get_user(__c_ao, (char __user *)__addr)) \
12774+ break; \
12775+ if (type != VERIFY_WRITE) { \
12776+ __addr = __addr_ao; \
12777+ continue; \
12778+ } \
12779+ if (__put_user(__c_ao, (char __user *)__addr)) \
12780+ break; \
12781+ __addr = __addr_ao; \
12782+ } \
12783+ } \
12784+ __ret_ao; \
12785+})
12786
12787 /*
12788 * The exception table consists of pairs of addresses: the first is the
12789@@ -182,12 +216,20 @@ extern int __get_user_bad(void);
12790 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12791 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12792
12793-
12794+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12795+#define __copyuser_seg "gs;"
12796+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12797+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12798+#else
12799+#define __copyuser_seg
12800+#define __COPYUSER_SET_ES
12801+#define __COPYUSER_RESTORE_ES
12802+#endif
12803
12804 #ifdef CONFIG_X86_32
12805 #define __put_user_asm_u64(x, addr, err, errret) \
12806- asm volatile("1: movl %%eax,0(%2)\n" \
12807- "2: movl %%edx,4(%2)\n" \
12808+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12809+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12810 "3:\n" \
12811 ".section .fixup,\"ax\"\n" \
12812 "4: movl %3,%0\n" \
12813@@ -199,8 +241,8 @@ extern int __get_user_bad(void);
12814 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12815
12816 #define __put_user_asm_ex_u64(x, addr) \
12817- asm volatile("1: movl %%eax,0(%1)\n" \
12818- "2: movl %%edx,4(%1)\n" \
12819+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12820+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12821 "3:\n" \
12822 _ASM_EXTABLE(1b, 2b - 1b) \
12823 _ASM_EXTABLE(2b, 3b - 2b) \
12824@@ -252,7 +294,7 @@ extern void __put_user_8(void);
12825 __typeof__(*(ptr)) __pu_val; \
12826 __chk_user_ptr(ptr); \
12827 might_fault(); \
12828- __pu_val = x; \
12829+ __pu_val = (x); \
12830 switch (sizeof(*(ptr))) { \
12831 case 1: \
12832 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12833@@ -373,7 +415,7 @@ do { \
12834 } while (0)
12835
12836 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12837- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12838+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12839 "2:\n" \
12840 ".section .fixup,\"ax\"\n" \
12841 "3: mov %3,%0\n" \
12842@@ -381,7 +423,7 @@ do { \
12843 " jmp 2b\n" \
12844 ".previous\n" \
12845 _ASM_EXTABLE(1b, 3b) \
12846- : "=r" (err), ltype(x) \
12847+ : "=r" (err), ltype (x) \
12848 : "m" (__m(addr)), "i" (errret), "0" (err))
12849
12850 #define __get_user_size_ex(x, ptr, size) \
12851@@ -406,7 +448,7 @@ do { \
12852 } while (0)
12853
12854 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12855- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12856+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12857 "2:\n" \
12858 _ASM_EXTABLE(1b, 2b - 1b) \
12859 : ltype(x) : "m" (__m(addr)))
12860@@ -423,13 +465,24 @@ do { \
12861 int __gu_err; \
12862 unsigned long __gu_val; \
12863 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12864- (x) = (__force __typeof__(*(ptr)))__gu_val; \
12865+ (x) = (__typeof__(*(ptr)))__gu_val; \
12866 __gu_err; \
12867 })
12868
12869 /* FIXME: this hack is definitely wrong -AK */
12870 struct __large_struct { unsigned long buf[100]; };
12871-#define __m(x) (*(struct __large_struct __user *)(x))
12872+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12873+#define ____m(x) \
12874+({ \
12875+ unsigned long ____x = (unsigned long)(x); \
12876+ if (____x < PAX_USER_SHADOW_BASE) \
12877+ ____x += PAX_USER_SHADOW_BASE; \
12878+ (void __user *)____x; \
12879+})
12880+#else
12881+#define ____m(x) (x)
12882+#endif
12883+#define __m(x) (*(struct __large_struct __user *)____m(x))
12884
12885 /*
12886 * Tell gcc we read from memory instead of writing: this is because
12887@@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
12888 * aliasing issues.
12889 */
12890 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12891- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12892+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12893 "2:\n" \
12894 ".section .fixup,\"ax\"\n" \
12895 "3: mov %3,%0\n" \
12896@@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
12897 ".previous\n" \
12898 _ASM_EXTABLE(1b, 3b) \
12899 : "=r"(err) \
12900- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12901+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12902
12903 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12904- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12905+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12906 "2:\n" \
12907 _ASM_EXTABLE(1b, 2b - 1b) \
12908 : : ltype(x), "m" (__m(addr)))
12909@@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
12910 * On error, the variable @x is set to zero.
12911 */
12912
12913+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12914+#define __get_user(x, ptr) get_user((x), (ptr))
12915+#else
12916 #define __get_user(x, ptr) \
12917 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12918+#endif
12919
12920 /**
12921 * __put_user: - Write a simple value into user space, with less checking.
12922@@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
12923 * Returns zero on success, or -EFAULT on error.
12924 */
12925
12926+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12927+#define __put_user(x, ptr) put_user((x), (ptr))
12928+#else
12929 #define __put_user(x, ptr) \
12930 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12931+#endif
12932
12933 #define __get_user_unaligned __get_user
12934 #define __put_user_unaligned __put_user
12935@@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
12936 #define get_user_ex(x, ptr) do { \
12937 unsigned long __gue_val; \
12938 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12939- (x) = (__force __typeof__(*(ptr)))__gue_val; \
12940+ (x) = (__typeof__(*(ptr)))__gue_val; \
12941 } while (0)
12942
12943 #ifdef CONFIG_X86_WP_WORKS_OK
12944diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12945index 566e803..1230707 100644
12946--- a/arch/x86/include/asm/uaccess_32.h
12947+++ b/arch/x86/include/asm/uaccess_32.h
12948@@ -11,15 +11,15 @@
12949 #include <asm/page.h>
12950
12951 unsigned long __must_check __copy_to_user_ll
12952- (void __user *to, const void *from, unsigned long n);
12953+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12954 unsigned long __must_check __copy_from_user_ll
12955- (void *to, const void __user *from, unsigned long n);
12956+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12957 unsigned long __must_check __copy_from_user_ll_nozero
12958- (void *to, const void __user *from, unsigned long n);
12959+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12960 unsigned long __must_check __copy_from_user_ll_nocache
12961- (void *to, const void __user *from, unsigned long n);
12962+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12963 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12964- (void *to, const void __user *from, unsigned long n);
12965+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12966
12967 /**
12968 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12969@@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12970 static __always_inline unsigned long __must_check
12971 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12972 {
12973+ if ((long)n < 0)
12974+ return n;
12975+
12976 if (__builtin_constant_p(n)) {
12977 unsigned long ret;
12978
12979@@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12980 return ret;
12981 }
12982 }
12983+ if (!__builtin_constant_p(n))
12984+ check_object_size(from, n, true);
12985 return __copy_to_user_ll(to, from, n);
12986 }
12987
12988@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12989 __copy_to_user(void __user *to, const void *from, unsigned long n)
12990 {
12991 might_fault();
12992+
12993 return __copy_to_user_inatomic(to, from, n);
12994 }
12995
12996 static __always_inline unsigned long
12997 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12998 {
12999+ if ((long)n < 0)
13000+ return n;
13001+
13002 /* Avoid zeroing the tail if the copy fails..
13003 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
13004 * but as the zeroing behaviour is only significant when n is not
13005@@ -137,6 +146,10 @@ static __always_inline unsigned long
13006 __copy_from_user(void *to, const void __user *from, unsigned long n)
13007 {
13008 might_fault();
13009+
13010+ if ((long)n < 0)
13011+ return n;
13012+
13013 if (__builtin_constant_p(n)) {
13014 unsigned long ret;
13015
13016@@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
13017 return ret;
13018 }
13019 }
13020+ if (!__builtin_constant_p(n))
13021+ check_object_size(to, n, false);
13022 return __copy_from_user_ll(to, from, n);
13023 }
13024
13025@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
13026 const void __user *from, unsigned long n)
13027 {
13028 might_fault();
13029+
13030+ if ((long)n < 0)
13031+ return n;
13032+
13033 if (__builtin_constant_p(n)) {
13034 unsigned long ret;
13035
13036@@ -181,15 +200,19 @@ static __always_inline unsigned long
13037 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
13038 unsigned long n)
13039 {
13040- return __copy_from_user_ll_nocache_nozero(to, from, n);
13041+ if ((long)n < 0)
13042+ return n;
13043+
13044+ return __copy_from_user_ll_nocache_nozero(to, from, n);
13045 }
13046
13047-unsigned long __must_check copy_to_user(void __user *to,
13048- const void *from, unsigned long n);
13049-unsigned long __must_check _copy_from_user(void *to,
13050- const void __user *from,
13051- unsigned long n);
13052-
13053+extern void copy_to_user_overflow(void)
13054+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13055+ __compiletime_error("copy_to_user() buffer size is not provably correct")
13056+#else
13057+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
13058+#endif
13059+;
13060
13061 extern void copy_from_user_overflow(void)
13062 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13063@@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
13064 #endif
13065 ;
13066
13067-static inline unsigned long __must_check copy_from_user(void *to,
13068- const void __user *from,
13069- unsigned long n)
13070+/**
13071+ * copy_to_user: - Copy a block of data into user space.
13072+ * @to: Destination address, in user space.
13073+ * @from: Source address, in kernel space.
13074+ * @n: Number of bytes to copy.
13075+ *
13076+ * Context: User context only. This function may sleep.
13077+ *
13078+ * Copy data from kernel space to user space.
13079+ *
13080+ * Returns number of bytes that could not be copied.
13081+ * On success, this will be zero.
13082+ */
13083+static inline unsigned long __must_check
13084+copy_to_user(void __user *to, const void *from, unsigned long n)
13085+{
13086+ int sz = __compiletime_object_size(from);
13087+
13088+ if (unlikely(sz != -1 && sz < n))
13089+ copy_to_user_overflow();
13090+ else if (access_ok(VERIFY_WRITE, to, n))
13091+ n = __copy_to_user(to, from, n);
13092+ return n;
13093+}
13094+
13095+/**
13096+ * copy_from_user: - Copy a block of data from user space.
13097+ * @to: Destination address, in kernel space.
13098+ * @from: Source address, in user space.
13099+ * @n: Number of bytes to copy.
13100+ *
13101+ * Context: User context only. This function may sleep.
13102+ *
13103+ * Copy data from user space to kernel space.
13104+ *
13105+ * Returns number of bytes that could not be copied.
13106+ * On success, this will be zero.
13107+ *
13108+ * If some data could not be copied, this function will pad the copied
13109+ * data to the requested size using zero bytes.
13110+ */
13111+static inline unsigned long __must_check
13112+copy_from_user(void *to, const void __user *from, unsigned long n)
13113 {
13114 int sz = __compiletime_object_size(to);
13115
13116- if (likely(sz == -1 || sz >= n))
13117- n = _copy_from_user(to, from, n);
13118- else
13119+ if (unlikely(sz != -1 && sz < n))
13120 copy_from_user_overflow();
13121-
13122+ else if (access_ok(VERIFY_READ, from, n))
13123+ n = __copy_from_user(to, from, n);
13124+ else if ((long)n > 0) {
13125+ if (!__builtin_constant_p(n))
13126+ check_object_size(to, n, false);
13127+ memset(to, 0, n);
13128+ }
13129 return n;
13130 }
13131
13132@@ -235,7 +302,7 @@ long __must_check __strncpy_from_user(char *dst,
13133 #define strlen_user(str) strnlen_user(str, LONG_MAX)
13134
13135 long strnlen_user(const char __user *str, long n);
13136-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13137-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13138+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13139+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13140
13141 #endif /* _ASM_X86_UACCESS_32_H */
13142diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13143index 1c66d30..bf1a2cc 100644
13144--- a/arch/x86/include/asm/uaccess_64.h
13145+++ b/arch/x86/include/asm/uaccess_64.h
13146@@ -10,6 +10,9 @@
13147 #include <asm/alternative.h>
13148 #include <asm/cpufeature.h>
13149 #include <asm/page.h>
13150+#include <asm/pgtable.h>
13151+
13152+#define set_fs(x) (current_thread_info()->addr_limit = (x))
13153
13154 /*
13155 * Copy To/From Userspace
13156@@ -17,12 +20,14 @@
13157
13158 /* Handles exceptions in both to and from, but doesn't do access_ok */
13159 __must_check unsigned long
13160-copy_user_generic_string(void *to, const void *from, unsigned len);
13161+copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
13162 __must_check unsigned long
13163-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13164+copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
13165
13166 static __always_inline __must_check unsigned long
13167-copy_user_generic(void *to, const void *from, unsigned len)
13168+copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
13169+static __always_inline __must_check unsigned long
13170+copy_user_generic(void *to, const void *from, unsigned long len)
13171 {
13172 unsigned ret;
13173
13174@@ -32,142 +37,226 @@ copy_user_generic(void *to, const void *from, unsigned len)
13175 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13176 "=d" (len)),
13177 "1" (to), "2" (from), "3" (len)
13178- : "memory", "rcx", "r8", "r9", "r10", "r11");
13179+ : "memory", "rcx", "r8", "r9", "r11");
13180 return ret;
13181 }
13182
13183+static __always_inline __must_check unsigned long
13184+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13185+static __always_inline __must_check unsigned long
13186+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13187 __must_check unsigned long
13188-_copy_to_user(void __user *to, const void *from, unsigned len);
13189-__must_check unsigned long
13190-_copy_from_user(void *to, const void __user *from, unsigned len);
13191-__must_check unsigned long
13192-copy_in_user(void __user *to, const void __user *from, unsigned len);
13193+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13194
13195 static inline unsigned long __must_check copy_from_user(void *to,
13196 const void __user *from,
13197 unsigned long n)
13198 {
13199- int sz = __compiletime_object_size(to);
13200-
13201 might_fault();
13202- if (likely(sz == -1 || sz >= n))
13203- n = _copy_from_user(to, from, n);
13204-#ifdef CONFIG_DEBUG_VM
13205- else
13206- WARN(1, "Buffer overflow detected!\n");
13207-#endif
13208+
13209+ if (access_ok(VERIFY_READ, from, n))
13210+ n = __copy_from_user(to, from, n);
13211+ else if (n < INT_MAX) {
13212+ if (!__builtin_constant_p(n))
13213+ check_object_size(to, n, false);
13214+ memset(to, 0, n);
13215+ }
13216 return n;
13217 }
13218
13219 static __always_inline __must_check
13220-int copy_to_user(void __user *dst, const void *src, unsigned size)
13221+int copy_to_user(void __user *dst, const void *src, unsigned long size)
13222 {
13223 might_fault();
13224
13225- return _copy_to_user(dst, src, size);
13226+ if (access_ok(VERIFY_WRITE, dst, size))
13227+ size = __copy_to_user(dst, src, size);
13228+ return size;
13229 }
13230
13231 static __always_inline __must_check
13232-int __copy_from_user(void *dst, const void __user *src, unsigned size)
13233+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13234 {
13235- int ret = 0;
13236+ int sz = __compiletime_object_size(dst);
13237+ unsigned ret = 0;
13238
13239 might_fault();
13240- if (!__builtin_constant_p(size))
13241- return copy_user_generic(dst, (__force void *)src, size);
13242+
13243+ if (size > INT_MAX)
13244+ return size;
13245+
13246+#ifdef CONFIG_PAX_MEMORY_UDEREF
13247+ if (!__access_ok(VERIFY_READ, src, size))
13248+ return size;
13249+#endif
13250+
13251+ if (unlikely(sz != -1 && sz < size)) {
13252+#ifdef CONFIG_DEBUG_VM
13253+ WARN(1, "Buffer overflow detected!\n");
13254+#endif
13255+ return size;
13256+ }
13257+
13258+ if (!__builtin_constant_p(size)) {
13259+ check_object_size(dst, size, false);
13260+
13261+#ifdef CONFIG_PAX_MEMORY_UDEREF
13262+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13263+ src += PAX_USER_SHADOW_BASE;
13264+#endif
13265+
13266+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13267+ }
13268 switch (size) {
13269- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13270+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13271 ret, "b", "b", "=q", 1);
13272 return ret;
13273- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13274+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13275 ret, "w", "w", "=r", 2);
13276 return ret;
13277- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13278+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13279 ret, "l", "k", "=r", 4);
13280 return ret;
13281- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13282+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13283 ret, "q", "", "=r", 8);
13284 return ret;
13285 case 10:
13286- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13287+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13288 ret, "q", "", "=r", 10);
13289 if (unlikely(ret))
13290 return ret;
13291 __get_user_asm(*(u16 *)(8 + (char *)dst),
13292- (u16 __user *)(8 + (char __user *)src),
13293+ (const u16 __user *)(8 + (const char __user *)src),
13294 ret, "w", "w", "=r", 2);
13295 return ret;
13296 case 16:
13297- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13298+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13299 ret, "q", "", "=r", 16);
13300 if (unlikely(ret))
13301 return ret;
13302 __get_user_asm(*(u64 *)(8 + (char *)dst),
13303- (u64 __user *)(8 + (char __user *)src),
13304+ (const u64 __user *)(8 + (const char __user *)src),
13305 ret, "q", "", "=r", 8);
13306 return ret;
13307 default:
13308- return copy_user_generic(dst, (__force void *)src, size);
13309+
13310+#ifdef CONFIG_PAX_MEMORY_UDEREF
13311+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13312+ src += PAX_USER_SHADOW_BASE;
13313+#endif
13314+
13315+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13316 }
13317 }
13318
13319 static __always_inline __must_check
13320-int __copy_to_user(void __user *dst, const void *src, unsigned size)
13321+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13322 {
13323- int ret = 0;
13324+ int sz = __compiletime_object_size(src);
13325+ unsigned ret = 0;
13326
13327 might_fault();
13328- if (!__builtin_constant_p(size))
13329- return copy_user_generic((__force void *)dst, src, size);
13330+
13331+ if (size > INT_MAX)
13332+ return size;
13333+
13334+#ifdef CONFIG_PAX_MEMORY_UDEREF
13335+ if (!__access_ok(VERIFY_WRITE, dst, size))
13336+ return size;
13337+#endif
13338+
13339+ if (unlikely(sz != -1 && sz < size)) {
13340+#ifdef CONFIG_DEBUG_VM
13341+ WARN(1, "Buffer overflow detected!\n");
13342+#endif
13343+ return size;
13344+ }
13345+
13346+ if (!__builtin_constant_p(size)) {
13347+ check_object_size(src, size, true);
13348+
13349+#ifdef CONFIG_PAX_MEMORY_UDEREF
13350+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13351+ dst += PAX_USER_SHADOW_BASE;
13352+#endif
13353+
13354+ return copy_user_generic((__force_kernel void *)dst, src, size);
13355+ }
13356 switch (size) {
13357- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13358+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13359 ret, "b", "b", "iq", 1);
13360 return ret;
13361- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13362+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13363 ret, "w", "w", "ir", 2);
13364 return ret;
13365- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13366+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13367 ret, "l", "k", "ir", 4);
13368 return ret;
13369- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13370+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13371 ret, "q", "", "er", 8);
13372 return ret;
13373 case 10:
13374- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13375+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13376 ret, "q", "", "er", 10);
13377 if (unlikely(ret))
13378 return ret;
13379 asm("":::"memory");
13380- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13381+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13382 ret, "w", "w", "ir", 2);
13383 return ret;
13384 case 16:
13385- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13386+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13387 ret, "q", "", "er", 16);
13388 if (unlikely(ret))
13389 return ret;
13390 asm("":::"memory");
13391- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13392+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13393 ret, "q", "", "er", 8);
13394 return ret;
13395 default:
13396- return copy_user_generic((__force void *)dst, src, size);
13397+
13398+#ifdef CONFIG_PAX_MEMORY_UDEREF
13399+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13400+ dst += PAX_USER_SHADOW_BASE;
13401+#endif
13402+
13403+ return copy_user_generic((__force_kernel void *)dst, src, size);
13404 }
13405 }
13406
13407 static __always_inline __must_check
13408-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13409+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13410 {
13411- int ret = 0;
13412+ unsigned ret = 0;
13413
13414 might_fault();
13415- if (!__builtin_constant_p(size))
13416- return copy_user_generic((__force void *)dst,
13417- (__force void *)src, size);
13418+
13419+ if (size > INT_MAX)
13420+ return size;
13421+
13422+#ifdef CONFIG_PAX_MEMORY_UDEREF
13423+ if (!__access_ok(VERIFY_READ, src, size))
13424+ return size;
13425+ if (!__access_ok(VERIFY_WRITE, dst, size))
13426+ return size;
13427+#endif
13428+
13429+ if (!__builtin_constant_p(size)) {
13430+
13431+#ifdef CONFIG_PAX_MEMORY_UDEREF
13432+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13433+ src += PAX_USER_SHADOW_BASE;
13434+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13435+ dst += PAX_USER_SHADOW_BASE;
13436+#endif
13437+
13438+ return copy_user_generic((__force_kernel void *)dst,
13439+ (__force_kernel const void *)src, size);
13440+ }
13441 switch (size) {
13442 case 1: {
13443 u8 tmp;
13444- __get_user_asm(tmp, (u8 __user *)src,
13445+ __get_user_asm(tmp, (const u8 __user *)src,
13446 ret, "b", "b", "=q", 1);
13447 if (likely(!ret))
13448 __put_user_asm(tmp, (u8 __user *)dst,
13449@@ -176,7 +265,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13450 }
13451 case 2: {
13452 u16 tmp;
13453- __get_user_asm(tmp, (u16 __user *)src,
13454+ __get_user_asm(tmp, (const u16 __user *)src,
13455 ret, "w", "w", "=r", 2);
13456 if (likely(!ret))
13457 __put_user_asm(tmp, (u16 __user *)dst,
13458@@ -186,7 +275,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13459
13460 case 4: {
13461 u32 tmp;
13462- __get_user_asm(tmp, (u32 __user *)src,
13463+ __get_user_asm(tmp, (const u32 __user *)src,
13464 ret, "l", "k", "=r", 4);
13465 if (likely(!ret))
13466 __put_user_asm(tmp, (u32 __user *)dst,
13467@@ -195,7 +284,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13468 }
13469 case 8: {
13470 u64 tmp;
13471- __get_user_asm(tmp, (u64 __user *)src,
13472+ __get_user_asm(tmp, (const u64 __user *)src,
13473 ret, "q", "", "=r", 8);
13474 if (likely(!ret))
13475 __put_user_asm(tmp, (u64 __user *)dst,
13476@@ -203,8 +292,16 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13477 return ret;
13478 }
13479 default:
13480- return copy_user_generic((__force void *)dst,
13481- (__force void *)src, size);
13482+
13483+#ifdef CONFIG_PAX_MEMORY_UDEREF
13484+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13485+ src += PAX_USER_SHADOW_BASE;
13486+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13487+ dst += PAX_USER_SHADOW_BASE;
13488+#endif
13489+
13490+ return copy_user_generic((__force_kernel void *)dst,
13491+ (__force_kernel const void *)src, size);
13492 }
13493 }
13494
13495@@ -215,39 +312,76 @@ __strncpy_from_user(char *dst, const char __user *src, long count);
13496 __must_check long strnlen_user(const char __user *str, long n);
13497 __must_check long __strnlen_user(const char __user *str, long n);
13498 __must_check long strlen_user(const char __user *str);
13499-__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13500-__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13501+__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13502+__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13503
13504 static __must_check __always_inline int
13505-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13506+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13507 {
13508- return copy_user_generic(dst, (__force const void *)src, size);
13509+ if (size > INT_MAX)
13510+ return size;
13511+
13512+#ifdef CONFIG_PAX_MEMORY_UDEREF
13513+ if (!__access_ok(VERIFY_READ, src, size))
13514+ return size;
13515+
13516+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13517+ src += PAX_USER_SHADOW_BASE;
13518+#endif
13519+
13520+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13521 }
13522
13523-static __must_check __always_inline int
13524-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13525+static __must_check __always_inline unsigned long
13526+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13527 {
13528- return copy_user_generic((__force void *)dst, src, size);
13529+ if (size > INT_MAX)
13530+ return size;
13531+
13532+#ifdef CONFIG_PAX_MEMORY_UDEREF
13533+ if (!__access_ok(VERIFY_WRITE, dst, size))
13534+ return size;
13535+
13536+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13537+ dst += PAX_USER_SHADOW_BASE;
13538+#endif
13539+
13540+ return copy_user_generic((__force_kernel void *)dst, src, size);
13541 }
13542
13543-extern long __copy_user_nocache(void *dst, const void __user *src,
13544- unsigned size, int zerorest);
13545+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13546+ unsigned long size, int zerorest) __size_overflow(3);
13547
13548-static inline int
13549-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13550+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13551 {
13552 might_sleep();
13553+
13554+ if (size > INT_MAX)
13555+ return size;
13556+
13557+#ifdef CONFIG_PAX_MEMORY_UDEREF
13558+ if (!__access_ok(VERIFY_READ, src, size))
13559+ return size;
13560+#endif
13561+
13562 return __copy_user_nocache(dst, src, size, 1);
13563 }
13564
13565-static inline int
13566-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13567- unsigned size)
13568+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13569+ unsigned long size)
13570 {
13571+ if (size > INT_MAX)
13572+ return size;
13573+
13574+#ifdef CONFIG_PAX_MEMORY_UDEREF
13575+ if (!__access_ok(VERIFY_READ, src, size))
13576+ return size;
13577+#endif
13578+
13579 return __copy_user_nocache(dst, src, size, 0);
13580 }
13581
13582-unsigned long
13583-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13584+extern unsigned long
13585+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13586
13587 #endif /* _ASM_X86_UACCESS_64_H */
13588diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13589index bb05228..d763d5b 100644
13590--- a/arch/x86/include/asm/vdso.h
13591+++ b/arch/x86/include/asm/vdso.h
13592@@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13593 #define VDSO32_SYMBOL(base, name) \
13594 ({ \
13595 extern const char VDSO32_##name[]; \
13596- (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13597+ (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13598 })
13599 #endif
13600
13601diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13602index a609c39..7a68dc7 100644
13603--- a/arch/x86/include/asm/x86_init.h
13604+++ b/arch/x86/include/asm/x86_init.h
13605@@ -29,7 +29,7 @@ struct x86_init_mpparse {
13606 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13607 void (*find_smp_config)(void);
13608 void (*get_smp_config)(unsigned int early);
13609-};
13610+} __no_const;
13611
13612 /**
13613 * struct x86_init_resources - platform specific resource related ops
13614@@ -43,7 +43,7 @@ struct x86_init_resources {
13615 void (*probe_roms)(void);
13616 void (*reserve_resources)(void);
13617 char *(*memory_setup)(void);
13618-};
13619+} __no_const;
13620
13621 /**
13622 * struct x86_init_irqs - platform specific interrupt setup
13623@@ -56,7 +56,7 @@ struct x86_init_irqs {
13624 void (*pre_vector_init)(void);
13625 void (*intr_init)(void);
13626 void (*trap_init)(void);
13627-};
13628+} __no_const;
13629
13630 /**
13631 * struct x86_init_oem - oem platform specific customizing functions
13632@@ -66,7 +66,7 @@ struct x86_init_irqs {
13633 struct x86_init_oem {
13634 void (*arch_setup)(void);
13635 void (*banner)(void);
13636-};
13637+} __no_const;
13638
13639 /**
13640 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13641@@ -77,7 +77,7 @@ struct x86_init_oem {
13642 */
13643 struct x86_init_mapping {
13644 void (*pagetable_reserve)(u64 start, u64 end);
13645-};
13646+} __no_const;
13647
13648 /**
13649 * struct x86_init_paging - platform specific paging functions
13650@@ -87,7 +87,7 @@ struct x86_init_mapping {
13651 struct x86_init_paging {
13652 void (*pagetable_setup_start)(pgd_t *base);
13653 void (*pagetable_setup_done)(pgd_t *base);
13654-};
13655+} __no_const;
13656
13657 /**
13658 * struct x86_init_timers - platform specific timer setup
13659@@ -102,7 +102,7 @@ struct x86_init_timers {
13660 void (*tsc_pre_init)(void);
13661 void (*timer_init)(void);
13662 void (*wallclock_init)(void);
13663-};
13664+} __no_const;
13665
13666 /**
13667 * struct x86_init_iommu - platform specific iommu setup
13668@@ -110,7 +110,7 @@ struct x86_init_timers {
13669 */
13670 struct x86_init_iommu {
13671 int (*iommu_init)(void);
13672-};
13673+} __no_const;
13674
13675 /**
13676 * struct x86_init_pci - platform specific pci init functions
13677@@ -124,7 +124,7 @@ struct x86_init_pci {
13678 int (*init)(void);
13679 void (*init_irq)(void);
13680 void (*fixup_irqs)(void);
13681-};
13682+} __no_const;
13683
13684 /**
13685 * struct x86_init_ops - functions for platform specific setup
13686@@ -140,7 +140,7 @@ struct x86_init_ops {
13687 struct x86_init_timers timers;
13688 struct x86_init_iommu iommu;
13689 struct x86_init_pci pci;
13690-};
13691+} __no_const;
13692
13693 /**
13694 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13695@@ -149,7 +149,7 @@ struct x86_init_ops {
13696 struct x86_cpuinit_ops {
13697 void (*setup_percpu_clockev)(void);
13698 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13699-};
13700+} __no_const;
13701
13702 /**
13703 * struct x86_platform_ops - platform specific runtime functions
13704@@ -171,7 +171,7 @@ struct x86_platform_ops {
13705 void (*nmi_init)(void);
13706 unsigned char (*get_nmi_reason)(void);
13707 int (*i8042_detect)(void);
13708-};
13709+} __no_const;
13710
13711 struct pci_dev;
13712
13713@@ -180,7 +180,7 @@ struct x86_msi_ops {
13714 void (*teardown_msi_irq)(unsigned int irq);
13715 void (*teardown_msi_irqs)(struct pci_dev *dev);
13716 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13717-};
13718+} __no_const;
13719
13720 extern struct x86_init_ops x86_init;
13721 extern struct x86_cpuinit_ops x86_cpuinit;
13722diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13723index c6ce245..ffbdab7 100644
13724--- a/arch/x86/include/asm/xsave.h
13725+++ b/arch/x86/include/asm/xsave.h
13726@@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13727 {
13728 int err;
13729
13730+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13731+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13732+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13733+#endif
13734+
13735 /*
13736 * Clear the xsave header first, so that reserved fields are
13737 * initialized to zero.
13738@@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13739 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13740 {
13741 int err;
13742- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13743+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13744 u32 lmask = mask;
13745 u32 hmask = mask >> 32;
13746
13747+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13748+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13749+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13750+#endif
13751+
13752 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13753 "2:\n"
13754 ".section .fixup,\"ax\"\n"
13755diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13756index 6a564ac..9b1340c 100644
13757--- a/arch/x86/kernel/acpi/realmode/Makefile
13758+++ b/arch/x86/kernel/acpi/realmode/Makefile
13759@@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13760 $(call cc-option, -fno-stack-protector) \
13761 $(call cc-option, -mpreferred-stack-boundary=2)
13762 KBUILD_CFLAGS += $(call cc-option, -m32)
13763+ifdef CONSTIFY_PLUGIN
13764+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13765+endif
13766 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13767 GCOV_PROFILE := n
13768
13769diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13770index b4fd836..4358fe3 100644
13771--- a/arch/x86/kernel/acpi/realmode/wakeup.S
13772+++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13773@@ -108,6 +108,9 @@ wakeup_code:
13774 /* Do any other stuff... */
13775
13776 #ifndef CONFIG_64BIT
13777+ /* Recheck NX bit overrides (64bit path does this in trampoline */
13778+ call verify_cpu
13779+
13780 /* This could also be done in C code... */
13781 movl pmode_cr3, %eax
13782 movl %eax, %cr3
13783@@ -131,6 +134,7 @@ wakeup_code:
13784 movl pmode_cr0, %eax
13785 movl %eax, %cr0
13786 jmp pmode_return
13787+# include "../../verify_cpu.S"
13788 #else
13789 pushw $0
13790 pushw trampoline_segment
13791diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13792index 103b6ab..2004d0a 100644
13793--- a/arch/x86/kernel/acpi/sleep.c
13794+++ b/arch/x86/kernel/acpi/sleep.c
13795@@ -94,8 +94,12 @@ int acpi_suspend_lowlevel(void)
13796 header->trampoline_segment = trampoline_address() >> 4;
13797 #ifdef CONFIG_SMP
13798 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13799+
13800+ pax_open_kernel();
13801 early_gdt_descr.address =
13802 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13803+ pax_close_kernel();
13804+
13805 initial_gs = per_cpu_offset(smp_processor_id());
13806 #endif
13807 initial_code = (unsigned long)wakeup_long64;
13808diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13809index 13ab720..95d5442 100644
13810--- a/arch/x86/kernel/acpi/wakeup_32.S
13811+++ b/arch/x86/kernel/acpi/wakeup_32.S
13812@@ -30,13 +30,11 @@ wakeup_pmode_return:
13813 # and restore the stack ... but you need gdt for this to work
13814 movl saved_context_esp, %esp
13815
13816- movl %cs:saved_magic, %eax
13817- cmpl $0x12345678, %eax
13818+ cmpl $0x12345678, saved_magic
13819 jne bogus_magic
13820
13821 # jump to place where we left off
13822- movl saved_eip, %eax
13823- jmp *%eax
13824+ jmp *(saved_eip)
13825
13826 bogus_magic:
13827 jmp bogus_magic
13828diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13829index 1f84794..e23f862 100644
13830--- a/arch/x86/kernel/alternative.c
13831+++ b/arch/x86/kernel/alternative.c
13832@@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13833 */
13834 for (a = start; a < end; a++) {
13835 instr = (u8 *)&a->instr_offset + a->instr_offset;
13836+
13837+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13838+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13839+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13840+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13841+#endif
13842+
13843 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13844 BUG_ON(a->replacementlen > a->instrlen);
13845 BUG_ON(a->instrlen > sizeof(insnbuf));
13846@@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13847 for (poff = start; poff < end; poff++) {
13848 u8 *ptr = (u8 *)poff + *poff;
13849
13850+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13851+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13852+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13853+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13854+#endif
13855+
13856 if (!*poff || ptr < text || ptr >= text_end)
13857 continue;
13858 /* turn DS segment override prefix into lock prefix */
13859- if (*ptr == 0x3e)
13860+ if (*ktla_ktva(ptr) == 0x3e)
13861 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13862 };
13863 mutex_unlock(&text_mutex);
13864@@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13865 for (poff = start; poff < end; poff++) {
13866 u8 *ptr = (u8 *)poff + *poff;
13867
13868+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13869+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13870+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13871+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13872+#endif
13873+
13874 if (!*poff || ptr < text || ptr >= text_end)
13875 continue;
13876 /* turn lock prefix into DS segment override prefix */
13877- if (*ptr == 0xf0)
13878+ if (*ktla_ktva(ptr) == 0xf0)
13879 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13880 };
13881 mutex_unlock(&text_mutex);
13882@@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13883
13884 BUG_ON(p->len > MAX_PATCH_LEN);
13885 /* prep the buffer with the original instructions */
13886- memcpy(insnbuf, p->instr, p->len);
13887+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13888 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13889 (unsigned long)p->instr, p->len);
13890
13891@@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13892 if (smp_alt_once)
13893 free_init_pages("SMP alternatives",
13894 (unsigned long)__smp_locks,
13895- (unsigned long)__smp_locks_end);
13896+ PAGE_ALIGN((unsigned long)__smp_locks_end));
13897
13898 restart_nmi();
13899 }
13900@@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13901 * instructions. And on the local CPU you need to be protected again NMI or MCE
13902 * handlers seeing an inconsistent instruction while you patch.
13903 */
13904-void *__init_or_module text_poke_early(void *addr, const void *opcode,
13905+void *__kprobes text_poke_early(void *addr, const void *opcode,
13906 size_t len)
13907 {
13908 unsigned long flags;
13909 local_irq_save(flags);
13910- memcpy(addr, opcode, len);
13911+
13912+ pax_open_kernel();
13913+ memcpy(ktla_ktva(addr), opcode, len);
13914 sync_core();
13915+ pax_close_kernel();
13916+
13917 local_irq_restore(flags);
13918 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13919 that causes hangs on some VIA CPUs. */
13920@@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13921 */
13922 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13923 {
13924- unsigned long flags;
13925- char *vaddr;
13926+ unsigned char *vaddr = ktla_ktva(addr);
13927 struct page *pages[2];
13928- int i;
13929+ size_t i;
13930
13931 if (!core_kernel_text((unsigned long)addr)) {
13932- pages[0] = vmalloc_to_page(addr);
13933- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13934+ pages[0] = vmalloc_to_page(vaddr);
13935+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13936 } else {
13937- pages[0] = virt_to_page(addr);
13938+ pages[0] = virt_to_page(vaddr);
13939 WARN_ON(!PageReserved(pages[0]));
13940- pages[1] = virt_to_page(addr + PAGE_SIZE);
13941+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13942 }
13943 BUG_ON(!pages[0]);
13944- local_irq_save(flags);
13945- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13946- if (pages[1])
13947- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13948- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13949- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13950- clear_fixmap(FIX_TEXT_POKE0);
13951- if (pages[1])
13952- clear_fixmap(FIX_TEXT_POKE1);
13953- local_flush_tlb();
13954- sync_core();
13955- /* Could also do a CLFLUSH here to speed up CPU recovery; but
13956- that causes hangs on some VIA CPUs. */
13957+ text_poke_early(addr, opcode, len);
13958 for (i = 0; i < len; i++)
13959- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13960- local_irq_restore(flags);
13961+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13962 return addr;
13963 }
13964
13965diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13966index 5b3f88e..61232b4 100644
13967--- a/arch/x86/kernel/apic/apic.c
13968+++ b/arch/x86/kernel/apic/apic.c
13969@@ -184,7 +184,7 @@ int first_system_vector = 0xfe;
13970 /*
13971 * Debug level, exported for io_apic.c
13972 */
13973-unsigned int apic_verbosity;
13974+int apic_verbosity;
13975
13976 int pic_mode;
13977
13978@@ -1912,7 +1912,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13979 apic_write(APIC_ESR, 0);
13980 v1 = apic_read(APIC_ESR);
13981 ack_APIC_irq();
13982- atomic_inc(&irq_err_count);
13983+ atomic_inc_unchecked(&irq_err_count);
13984
13985 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13986 smp_processor_id(), v0 , v1);
13987diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13988index fb07275..e06bb59 100644
13989--- a/arch/x86/kernel/apic/io_apic.c
13990+++ b/arch/x86/kernel/apic/io_apic.c
13991@@ -1096,7 +1096,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13992 }
13993 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13994
13995-void lock_vector_lock(void)
13996+void lock_vector_lock(void) __acquires(vector_lock)
13997 {
13998 /* Used to the online set of cpus does not change
13999 * during assign_irq_vector.
14000@@ -1104,7 +1104,7 @@ void lock_vector_lock(void)
14001 raw_spin_lock(&vector_lock);
14002 }
14003
14004-void unlock_vector_lock(void)
14005+void unlock_vector_lock(void) __releases(vector_lock)
14006 {
14007 raw_spin_unlock(&vector_lock);
14008 }
14009@@ -2510,7 +2510,7 @@ static void ack_apic_edge(struct irq_data *data)
14010 ack_APIC_irq();
14011 }
14012
14013-atomic_t irq_mis_count;
14014+atomic_unchecked_t irq_mis_count;
14015
14016 static void ack_apic_level(struct irq_data *data)
14017 {
14018@@ -2576,7 +2576,7 @@ static void ack_apic_level(struct irq_data *data)
14019 * at the cpu.
14020 */
14021 if (!(v & (1 << (i & 0x1f)))) {
14022- atomic_inc(&irq_mis_count);
14023+ atomic_inc_unchecked(&irq_mis_count);
14024
14025 eoi_ioapic_irq(irq, cfg);
14026 }
14027diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
14028index f76623c..aab694f 100644
14029--- a/arch/x86/kernel/apm_32.c
14030+++ b/arch/x86/kernel/apm_32.c
14031@@ -411,7 +411,7 @@ static DEFINE_MUTEX(apm_mutex);
14032 * This is for buggy BIOS's that refer to (real mode) segment 0x40
14033 * even though they are called in protected mode.
14034 */
14035-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
14036+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
14037 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
14038
14039 static const char driver_version[] = "1.16ac"; /* no spaces */
14040@@ -589,7 +589,10 @@ static long __apm_bios_call(void *_call)
14041 BUG_ON(cpu != 0);
14042 gdt = get_cpu_gdt_table(cpu);
14043 save_desc_40 = gdt[0x40 / 8];
14044+
14045+ pax_open_kernel();
14046 gdt[0x40 / 8] = bad_bios_desc;
14047+ pax_close_kernel();
14048
14049 apm_irq_save(flags);
14050 APM_DO_SAVE_SEGS;
14051@@ -598,7 +601,11 @@ static long __apm_bios_call(void *_call)
14052 &call->esi);
14053 APM_DO_RESTORE_SEGS;
14054 apm_irq_restore(flags);
14055+
14056+ pax_open_kernel();
14057 gdt[0x40 / 8] = save_desc_40;
14058+ pax_close_kernel();
14059+
14060 put_cpu();
14061
14062 return call->eax & 0xff;
14063@@ -665,7 +672,10 @@ static long __apm_bios_call_simple(void *_call)
14064 BUG_ON(cpu != 0);
14065 gdt = get_cpu_gdt_table(cpu);
14066 save_desc_40 = gdt[0x40 / 8];
14067+
14068+ pax_open_kernel();
14069 gdt[0x40 / 8] = bad_bios_desc;
14070+ pax_close_kernel();
14071
14072 apm_irq_save(flags);
14073 APM_DO_SAVE_SEGS;
14074@@ -673,7 +683,11 @@ static long __apm_bios_call_simple(void *_call)
14075 &call->eax);
14076 APM_DO_RESTORE_SEGS;
14077 apm_irq_restore(flags);
14078+
14079+ pax_open_kernel();
14080 gdt[0x40 / 8] = save_desc_40;
14081+ pax_close_kernel();
14082+
14083 put_cpu();
14084 return error;
14085 }
14086@@ -2347,12 +2361,15 @@ static int __init apm_init(void)
14087 * code to that CPU.
14088 */
14089 gdt = get_cpu_gdt_table(0);
14090+
14091+ pax_open_kernel();
14092 set_desc_base(&gdt[APM_CS >> 3],
14093 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14094 set_desc_base(&gdt[APM_CS_16 >> 3],
14095 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14096 set_desc_base(&gdt[APM_DS >> 3],
14097 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14098+ pax_close_kernel();
14099
14100 proc_create("apm", 0, NULL, &apm_file_ops);
14101
14102diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14103index 68de2dc..1f3c720 100644
14104--- a/arch/x86/kernel/asm-offsets.c
14105+++ b/arch/x86/kernel/asm-offsets.c
14106@@ -33,6 +33,8 @@ void common(void) {
14107 OFFSET(TI_status, thread_info, status);
14108 OFFSET(TI_addr_limit, thread_info, addr_limit);
14109 OFFSET(TI_preempt_count, thread_info, preempt_count);
14110+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14111+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14112
14113 BLANK();
14114 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14115@@ -53,8 +55,26 @@ void common(void) {
14116 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14117 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14118 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14119+
14120+#ifdef CONFIG_PAX_KERNEXEC
14121+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14122 #endif
14123
14124+#ifdef CONFIG_PAX_MEMORY_UDEREF
14125+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14126+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14127+#ifdef CONFIG_X86_64
14128+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14129+#endif
14130+#endif
14131+
14132+#endif
14133+
14134+ BLANK();
14135+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14136+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14137+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14138+
14139 #ifdef CONFIG_XEN
14140 BLANK();
14141 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14142diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14143index 834e897..dacddc8 100644
14144--- a/arch/x86/kernel/asm-offsets_64.c
14145+++ b/arch/x86/kernel/asm-offsets_64.c
14146@@ -70,6 +70,7 @@ int main(void)
14147 BLANK();
14148 #undef ENTRY
14149
14150+ DEFINE(TSS_size, sizeof(struct tss_struct));
14151 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14152 BLANK();
14153
14154diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14155index 25f24dc..4094a7f 100644
14156--- a/arch/x86/kernel/cpu/Makefile
14157+++ b/arch/x86/kernel/cpu/Makefile
14158@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14159 CFLAGS_REMOVE_perf_event.o = -pg
14160 endif
14161
14162-# Make sure load_percpu_segment has no stackprotector
14163-nostackp := $(call cc-option, -fno-stack-protector)
14164-CFLAGS_common.o := $(nostackp)
14165-
14166 obj-y := intel_cacheinfo.o scattered.o topology.o
14167 obj-y += proc.o capflags.o powerflags.o common.o
14168 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
14169diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14170index 80ab83d..0a7b34e 100644
14171--- a/arch/x86/kernel/cpu/amd.c
14172+++ b/arch/x86/kernel/cpu/amd.c
14173@@ -670,7 +670,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14174 unsigned int size)
14175 {
14176 /* AMD errata T13 (order #21922) */
14177- if ((c->x86 == 6)) {
14178+ if (c->x86 == 6) {
14179 /* Duron Rev A0 */
14180 if (c->x86_model == 3 && c->x86_mask == 0)
14181 size = 64;
14182diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14183index 1a810e4..9fa8201 100644
14184--- a/arch/x86/kernel/cpu/common.c
14185+++ b/arch/x86/kernel/cpu/common.c
14186@@ -84,60 +84,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14187
14188 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14189
14190-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14191-#ifdef CONFIG_X86_64
14192- /*
14193- * We need valid kernel segments for data and code in long mode too
14194- * IRET will check the segment types kkeil 2000/10/28
14195- * Also sysret mandates a special GDT layout
14196- *
14197- * TLS descriptors are currently at a different place compared to i386.
14198- * Hopefully nobody expects them at a fixed place (Wine?)
14199- */
14200- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14201- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14202- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14203- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14204- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14205- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14206-#else
14207- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14208- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14209- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14210- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14211- /*
14212- * Segments used for calling PnP BIOS have byte granularity.
14213- * They code segments and data segments have fixed 64k limits,
14214- * the transfer segment sizes are set at run time.
14215- */
14216- /* 32-bit code */
14217- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14218- /* 16-bit code */
14219- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14220- /* 16-bit data */
14221- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14222- /* 16-bit data */
14223- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14224- /* 16-bit data */
14225- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14226- /*
14227- * The APM segments have byte granularity and their bases
14228- * are set at run time. All have 64k limits.
14229- */
14230- /* 32-bit code */
14231- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14232- /* 16-bit code */
14233- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14234- /* data */
14235- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14236-
14237- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14238- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14239- GDT_STACK_CANARY_INIT
14240-#endif
14241-} };
14242-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14243-
14244 static int __init x86_xsave_setup(char *s)
14245 {
14246 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14247@@ -372,7 +318,7 @@ void switch_to_new_gdt(int cpu)
14248 {
14249 struct desc_ptr gdt_descr;
14250
14251- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14252+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14253 gdt_descr.size = GDT_SIZE - 1;
14254 load_gdt(&gdt_descr);
14255 /* Reload the per-cpu base */
14256@@ -839,6 +785,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14257 /* Filter out anything that depends on CPUID levels we don't have */
14258 filter_cpuid_features(c, true);
14259
14260+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14261+ setup_clear_cpu_cap(X86_FEATURE_SEP);
14262+#endif
14263+
14264 /* If the model name is still unset, do table lookup. */
14265 if (!c->x86_model_id[0]) {
14266 const char *p;
14267@@ -1019,10 +969,12 @@ static __init int setup_disablecpuid(char *arg)
14268 }
14269 __setup("clearcpuid=", setup_disablecpuid);
14270
14271+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14272+EXPORT_PER_CPU_SYMBOL(current_tinfo);
14273+
14274 #ifdef CONFIG_X86_64
14275 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14276-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14277- (unsigned long) nmi_idt_table };
14278+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14279
14280 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14281 irq_stack_union) __aligned(PAGE_SIZE);
14282@@ -1036,7 +988,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14283 EXPORT_PER_CPU_SYMBOL(current_task);
14284
14285 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14286- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14287+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14288 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14289
14290 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14291@@ -1126,7 +1078,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14292 {
14293 memset(regs, 0, sizeof(struct pt_regs));
14294 regs->fs = __KERNEL_PERCPU;
14295- regs->gs = __KERNEL_STACK_CANARY;
14296+ savesegment(gs, regs->gs);
14297
14298 return regs;
14299 }
14300@@ -1181,7 +1133,7 @@ void __cpuinit cpu_init(void)
14301 int i;
14302
14303 cpu = stack_smp_processor_id();
14304- t = &per_cpu(init_tss, cpu);
14305+ t = init_tss + cpu;
14306 oist = &per_cpu(orig_ist, cpu);
14307
14308 #ifdef CONFIG_NUMA
14309@@ -1207,7 +1159,7 @@ void __cpuinit cpu_init(void)
14310 switch_to_new_gdt(cpu);
14311 loadsegment(fs, 0);
14312
14313- load_idt((const struct desc_ptr *)&idt_descr);
14314+ load_idt(&idt_descr);
14315
14316 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14317 syscall_init();
14318@@ -1216,7 +1168,6 @@ void __cpuinit cpu_init(void)
14319 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14320 barrier();
14321
14322- x86_configure_nx();
14323 if (cpu != 0)
14324 enable_x2apic();
14325
14326@@ -1272,7 +1223,7 @@ void __cpuinit cpu_init(void)
14327 {
14328 int cpu = smp_processor_id();
14329 struct task_struct *curr = current;
14330- struct tss_struct *t = &per_cpu(init_tss, cpu);
14331+ struct tss_struct *t = init_tss + cpu;
14332 struct thread_struct *thread = &curr->thread;
14333
14334 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14335diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14336index 3e6ff6c..54b4992 100644
14337--- a/arch/x86/kernel/cpu/intel.c
14338+++ b/arch/x86/kernel/cpu/intel.c
14339@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14340 * Update the IDT descriptor and reload the IDT so that
14341 * it uses the read-only mapped virtual address.
14342 */
14343- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14344+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14345 load_idt(&idt_descr);
14346 }
14347 #endif
14348diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14349index 5a11ae2..a1a1c8a 100644
14350--- a/arch/x86/kernel/cpu/mcheck/mce.c
14351+++ b/arch/x86/kernel/cpu/mcheck/mce.c
14352@@ -42,6 +42,7 @@
14353 #include <asm/processor.h>
14354 #include <asm/mce.h>
14355 #include <asm/msr.h>
14356+#include <asm/local.h>
14357
14358 #include "mce-internal.h"
14359
14360@@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14361 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14362 m->cs, m->ip);
14363
14364- if (m->cs == __KERNEL_CS)
14365+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14366 print_symbol("{%s}", m->ip);
14367 pr_cont("\n");
14368 }
14369@@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14370
14371 #define PANIC_TIMEOUT 5 /* 5 seconds */
14372
14373-static atomic_t mce_paniced;
14374+static atomic_unchecked_t mce_paniced;
14375
14376 static int fake_panic;
14377-static atomic_t mce_fake_paniced;
14378+static atomic_unchecked_t mce_fake_paniced;
14379
14380 /* Panic in progress. Enable interrupts and wait for final IPI */
14381 static void wait_for_panic(void)
14382@@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14383 /*
14384 * Make sure only one CPU runs in machine check panic
14385 */
14386- if (atomic_inc_return(&mce_paniced) > 1)
14387+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14388 wait_for_panic();
14389 barrier();
14390
14391@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14392 console_verbose();
14393 } else {
14394 /* Don't log too much for fake panic */
14395- if (atomic_inc_return(&mce_fake_paniced) > 1)
14396+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14397 return;
14398 }
14399 /* First print corrected ones that are still unlogged */
14400@@ -658,7 +659,7 @@ static int mce_timed_out(u64 *t)
14401 * might have been modified by someone else.
14402 */
14403 rmb();
14404- if (atomic_read(&mce_paniced))
14405+ if (atomic_read_unchecked(&mce_paniced))
14406 wait_for_panic();
14407 if (!monarch_timeout)
14408 goto out;
14409@@ -1446,7 +1447,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14410 }
14411
14412 /* Call the installed machine check handler for this CPU setup. */
14413-void (*machine_check_vector)(struct pt_regs *, long error_code) =
14414+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14415 unexpected_machine_check;
14416
14417 /*
14418@@ -1469,7 +1470,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14419 return;
14420 }
14421
14422+ pax_open_kernel();
14423 machine_check_vector = do_machine_check;
14424+ pax_close_kernel();
14425
14426 __mcheck_cpu_init_generic();
14427 __mcheck_cpu_init_vendor(c);
14428@@ -1483,7 +1486,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14429 */
14430
14431 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14432-static int mce_chrdev_open_count; /* #times opened */
14433+static local_t mce_chrdev_open_count; /* #times opened */
14434 static int mce_chrdev_open_exclu; /* already open exclusive? */
14435
14436 static int mce_chrdev_open(struct inode *inode, struct file *file)
14437@@ -1491,7 +1494,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14438 spin_lock(&mce_chrdev_state_lock);
14439
14440 if (mce_chrdev_open_exclu ||
14441- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14442+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14443 spin_unlock(&mce_chrdev_state_lock);
14444
14445 return -EBUSY;
14446@@ -1499,7 +1502,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14447
14448 if (file->f_flags & O_EXCL)
14449 mce_chrdev_open_exclu = 1;
14450- mce_chrdev_open_count++;
14451+ local_inc(&mce_chrdev_open_count);
14452
14453 spin_unlock(&mce_chrdev_state_lock);
14454
14455@@ -1510,7 +1513,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14456 {
14457 spin_lock(&mce_chrdev_state_lock);
14458
14459- mce_chrdev_open_count--;
14460+ local_dec(&mce_chrdev_open_count);
14461 mce_chrdev_open_exclu = 0;
14462
14463 spin_unlock(&mce_chrdev_state_lock);
14464@@ -2229,7 +2232,7 @@ struct dentry *mce_get_debugfs_dir(void)
14465 static void mce_reset(void)
14466 {
14467 cpu_missing = 0;
14468- atomic_set(&mce_fake_paniced, 0);
14469+ atomic_set_unchecked(&mce_fake_paniced, 0);
14470 atomic_set(&mce_executing, 0);
14471 atomic_set(&mce_callin, 0);
14472 atomic_set(&global_nwo, 0);
14473diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14474index 5c0e653..0882b0a 100644
14475--- a/arch/x86/kernel/cpu/mcheck/p5.c
14476+++ b/arch/x86/kernel/cpu/mcheck/p5.c
14477@@ -12,6 +12,7 @@
14478 #include <asm/system.h>
14479 #include <asm/mce.h>
14480 #include <asm/msr.h>
14481+#include <asm/pgtable.h>
14482
14483 /* By default disabled */
14484 int mce_p5_enabled __read_mostly;
14485@@ -50,7 +51,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14486 if (!cpu_has(c, X86_FEATURE_MCE))
14487 return;
14488
14489+ pax_open_kernel();
14490 machine_check_vector = pentium_machine_check;
14491+ pax_close_kernel();
14492 /* Make sure the vector pointer is visible before we enable MCEs: */
14493 wmb();
14494
14495diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14496index 54060f5..c1a7577 100644
14497--- a/arch/x86/kernel/cpu/mcheck/winchip.c
14498+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14499@@ -11,6 +11,7 @@
14500 #include <asm/system.h>
14501 #include <asm/mce.h>
14502 #include <asm/msr.h>
14503+#include <asm/pgtable.h>
14504
14505 /* Machine check handler for WinChip C6: */
14506 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14507@@ -24,7 +25,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14508 {
14509 u32 lo, hi;
14510
14511+ pax_open_kernel();
14512 machine_check_vector = winchip_machine_check;
14513+ pax_close_kernel();
14514 /* Make sure the vector pointer is visible before we enable MCEs: */
14515 wmb();
14516
14517diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14518index 6b96110..0da73eb 100644
14519--- a/arch/x86/kernel/cpu/mtrr/main.c
14520+++ b/arch/x86/kernel/cpu/mtrr/main.c
14521@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14522 u64 size_or_mask, size_and_mask;
14523 static bool mtrr_aps_delayed_init;
14524
14525-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14526+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14527
14528 const struct mtrr_ops *mtrr_if;
14529
14530diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14531index df5e41f..816c719 100644
14532--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14533+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14534@@ -25,7 +25,7 @@ struct mtrr_ops {
14535 int (*validate_add_page)(unsigned long base, unsigned long size,
14536 unsigned int type);
14537 int (*have_wrcomb)(void);
14538-};
14539+} __do_const;
14540
14541 extern int generic_get_free_region(unsigned long base, unsigned long size,
14542 int replace_reg);
14543diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14544index 5adce10..99284ec 100644
14545--- a/arch/x86/kernel/cpu/perf_event.c
14546+++ b/arch/x86/kernel/cpu/perf_event.c
14547@@ -1665,7 +1665,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14548 break;
14549
14550 perf_callchain_store(entry, frame.return_address);
14551- fp = frame.next_frame;
14552+ fp = (const void __force_user *)frame.next_frame;
14553 }
14554 }
14555
14556diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14557index 13ad899..f642b9a 100644
14558--- a/arch/x86/kernel/crash.c
14559+++ b/arch/x86/kernel/crash.c
14560@@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14561 {
14562 #ifdef CONFIG_X86_32
14563 struct pt_regs fixed_regs;
14564-#endif
14565
14566-#ifdef CONFIG_X86_32
14567- if (!user_mode_vm(regs)) {
14568+ if (!user_mode(regs)) {
14569 crash_fixup_ss_esp(&fixed_regs, regs);
14570 regs = &fixed_regs;
14571 }
14572diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14573index 37250fe..bf2ec74 100644
14574--- a/arch/x86/kernel/doublefault_32.c
14575+++ b/arch/x86/kernel/doublefault_32.c
14576@@ -11,7 +11,7 @@
14577
14578 #define DOUBLEFAULT_STACKSIZE (1024)
14579 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14580-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14581+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14582
14583 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14584
14585@@ -21,7 +21,7 @@ static void doublefault_fn(void)
14586 unsigned long gdt, tss;
14587
14588 store_gdt(&gdt_desc);
14589- gdt = gdt_desc.address;
14590+ gdt = (unsigned long)gdt_desc.address;
14591
14592 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14593
14594@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14595 /* 0x2 bit is always set */
14596 .flags = X86_EFLAGS_SF | 0x2,
14597 .sp = STACK_START,
14598- .es = __USER_DS,
14599+ .es = __KERNEL_DS,
14600 .cs = __KERNEL_CS,
14601 .ss = __KERNEL_DS,
14602- .ds = __USER_DS,
14603+ .ds = __KERNEL_DS,
14604 .fs = __KERNEL_PERCPU,
14605
14606 .__cr3 = __pa_nodebug(swapper_pg_dir),
14607diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14608index 4025fe4..d8451c6 100644
14609--- a/arch/x86/kernel/dumpstack.c
14610+++ b/arch/x86/kernel/dumpstack.c
14611@@ -2,6 +2,9 @@
14612 * Copyright (C) 1991, 1992 Linus Torvalds
14613 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14614 */
14615+#ifdef CONFIG_GRKERNSEC_HIDESYM
14616+#define __INCLUDED_BY_HIDESYM 1
14617+#endif
14618 #include <linux/kallsyms.h>
14619 #include <linux/kprobes.h>
14620 #include <linux/uaccess.h>
14621@@ -35,9 +38,8 @@ void printk_address(unsigned long address, int reliable)
14622 static void
14623 print_ftrace_graph_addr(unsigned long addr, void *data,
14624 const struct stacktrace_ops *ops,
14625- struct thread_info *tinfo, int *graph)
14626+ struct task_struct *task, int *graph)
14627 {
14628- struct task_struct *task = tinfo->task;
14629 unsigned long ret_addr;
14630 int index = task->curr_ret_stack;
14631
14632@@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14633 static inline void
14634 print_ftrace_graph_addr(unsigned long addr, void *data,
14635 const struct stacktrace_ops *ops,
14636- struct thread_info *tinfo, int *graph)
14637+ struct task_struct *task, int *graph)
14638 { }
14639 #endif
14640
14641@@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14642 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14643 */
14644
14645-static inline int valid_stack_ptr(struct thread_info *tinfo,
14646- void *p, unsigned int size, void *end)
14647+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14648 {
14649- void *t = tinfo;
14650 if (end) {
14651 if (p < end && p >= (end-THREAD_SIZE))
14652 return 1;
14653@@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14654 }
14655
14656 unsigned long
14657-print_context_stack(struct thread_info *tinfo,
14658+print_context_stack(struct task_struct *task, void *stack_start,
14659 unsigned long *stack, unsigned long bp,
14660 const struct stacktrace_ops *ops, void *data,
14661 unsigned long *end, int *graph)
14662 {
14663 struct stack_frame *frame = (struct stack_frame *)bp;
14664
14665- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14666+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14667 unsigned long addr;
14668
14669 addr = *stack;
14670@@ -102,7 +102,7 @@ print_context_stack(struct thread_info *tinfo,
14671 } else {
14672 ops->address(data, addr, 0);
14673 }
14674- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14675+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14676 }
14677 stack++;
14678 }
14679@@ -111,7 +111,7 @@ print_context_stack(struct thread_info *tinfo,
14680 EXPORT_SYMBOL_GPL(print_context_stack);
14681
14682 unsigned long
14683-print_context_stack_bp(struct thread_info *tinfo,
14684+print_context_stack_bp(struct task_struct *task, void *stack_start,
14685 unsigned long *stack, unsigned long bp,
14686 const struct stacktrace_ops *ops, void *data,
14687 unsigned long *end, int *graph)
14688@@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14689 struct stack_frame *frame = (struct stack_frame *)bp;
14690 unsigned long *ret_addr = &frame->return_address;
14691
14692- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14693+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14694 unsigned long addr = *ret_addr;
14695
14696 if (!__kernel_text_address(addr))
14697@@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14698 ops->address(data, addr, 1);
14699 frame = frame->next_frame;
14700 ret_addr = &frame->return_address;
14701- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14702+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14703 }
14704
14705 return (unsigned long)frame;
14706@@ -186,7 +186,7 @@ void dump_stack(void)
14707
14708 bp = stack_frame(current, NULL);
14709 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14710- current->pid, current->comm, print_tainted(),
14711+ task_pid_nr(current), current->comm, print_tainted(),
14712 init_utsname()->release,
14713 (int)strcspn(init_utsname()->version, " "),
14714 init_utsname()->version);
14715@@ -222,6 +222,8 @@ unsigned __kprobes long oops_begin(void)
14716 }
14717 EXPORT_SYMBOL_GPL(oops_begin);
14718
14719+extern void gr_handle_kernel_exploit(void);
14720+
14721 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14722 {
14723 if (regs && kexec_should_crash(current))
14724@@ -243,7 +245,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14725 panic("Fatal exception in interrupt");
14726 if (panic_on_oops)
14727 panic("Fatal exception");
14728- do_exit(signr);
14729+
14730+ gr_handle_kernel_exploit();
14731+
14732+ do_group_exit(signr);
14733 }
14734
14735 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14736@@ -270,7 +275,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14737
14738 show_registers(regs);
14739 #ifdef CONFIG_X86_32
14740- if (user_mode_vm(regs)) {
14741+ if (user_mode(regs)) {
14742 sp = regs->sp;
14743 ss = regs->ss & 0xffff;
14744 } else {
14745@@ -298,7 +303,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14746 unsigned long flags = oops_begin();
14747 int sig = SIGSEGV;
14748
14749- if (!user_mode_vm(regs))
14750+ if (!user_mode(regs))
14751 report_bug(regs->ip, regs);
14752
14753 if (__die(str, regs, err))
14754diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14755index c99f9ed..2a15d80 100644
14756--- a/arch/x86/kernel/dumpstack_32.c
14757+++ b/arch/x86/kernel/dumpstack_32.c
14758@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14759 bp = stack_frame(task, regs);
14760
14761 for (;;) {
14762- struct thread_info *context;
14763+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14764
14765- context = (struct thread_info *)
14766- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14767- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14768+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14769
14770- stack = (unsigned long *)context->previous_esp;
14771- if (!stack)
14772+ if (stack_start == task_stack_page(task))
14773 break;
14774+ stack = *(unsigned long **)stack_start;
14775 if (ops->stack(data, "IRQ") < 0)
14776 break;
14777 touch_nmi_watchdog();
14778@@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
14779 * When in-kernel, we also print out the stack and code at the
14780 * time of the fault..
14781 */
14782- if (!user_mode_vm(regs)) {
14783+ if (!user_mode(regs)) {
14784 unsigned int code_prologue = code_bytes * 43 / 64;
14785 unsigned int code_len = code_bytes;
14786 unsigned char c;
14787 u8 *ip;
14788+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14789
14790 printk(KERN_EMERG "Stack:\n");
14791 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14792
14793 printk(KERN_EMERG "Code: ");
14794
14795- ip = (u8 *)regs->ip - code_prologue;
14796+ ip = (u8 *)regs->ip - code_prologue + cs_base;
14797 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14798 /* try starting at IP */
14799- ip = (u8 *)regs->ip;
14800+ ip = (u8 *)regs->ip + cs_base;
14801 code_len = code_len - code_prologue + 1;
14802 }
14803 for (i = 0; i < code_len; i++, ip++) {
14804@@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
14805 printk(KERN_CONT " Bad EIP value.");
14806 break;
14807 }
14808- if (ip == (u8 *)regs->ip)
14809+ if (ip == (u8 *)regs->ip + cs_base)
14810 printk(KERN_CONT "<%02x> ", c);
14811 else
14812 printk(KERN_CONT "%02x ", c);
14813@@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14814 {
14815 unsigned short ud2;
14816
14817+ ip = ktla_ktva(ip);
14818 if (ip < PAGE_OFFSET)
14819 return 0;
14820 if (probe_kernel_address((unsigned short *)ip, ud2))
14821@@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14822
14823 return ud2 == 0x0b0f;
14824 }
14825+
14826+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14827+void pax_check_alloca(unsigned long size)
14828+{
14829+ unsigned long sp = (unsigned long)&sp, stack_left;
14830+
14831+ /* all kernel stacks are of the same size */
14832+ stack_left = sp & (THREAD_SIZE - 1);
14833+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14834+}
14835+EXPORT_SYMBOL(pax_check_alloca);
14836+#endif
14837diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14838index 17107bd..9623722 100644
14839--- a/arch/x86/kernel/dumpstack_64.c
14840+++ b/arch/x86/kernel/dumpstack_64.c
14841@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14842 unsigned long *irq_stack_end =
14843 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14844 unsigned used = 0;
14845- struct thread_info *tinfo;
14846 int graph = 0;
14847 unsigned long dummy;
14848+ void *stack_start;
14849
14850 if (!task)
14851 task = current;
14852@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14853 * current stack address. If the stacks consist of nested
14854 * exceptions
14855 */
14856- tinfo = task_thread_info(task);
14857 for (;;) {
14858 char *id;
14859 unsigned long *estack_end;
14860+
14861 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14862 &used, &id);
14863
14864@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14865 if (ops->stack(data, id) < 0)
14866 break;
14867
14868- bp = ops->walk_stack(tinfo, stack, bp, ops,
14869+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14870 data, estack_end, &graph);
14871 ops->stack(data, "<EOE>");
14872 /*
14873@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14874 * second-to-last pointer (index -2 to end) in the
14875 * exception stack:
14876 */
14877+ if ((u16)estack_end[-1] != __KERNEL_DS)
14878+ goto out;
14879 stack = (unsigned long *) estack_end[-2];
14880 continue;
14881 }
14882@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14883 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14884 if (ops->stack(data, "IRQ") < 0)
14885 break;
14886- bp = ops->walk_stack(tinfo, stack, bp,
14887+ bp = ops->walk_stack(task, irq_stack, stack, bp,
14888 ops, data, irq_stack_end, &graph);
14889 /*
14890 * We link to the next stack (which would be
14891@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14892 /*
14893 * This handles the process stack:
14894 */
14895- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14896+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14897+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14898+out:
14899 put_cpu();
14900 }
14901 EXPORT_SYMBOL(dump_trace);
14902@@ -305,3 +309,50 @@ int is_valid_bugaddr(unsigned long ip)
14903
14904 return ud2 == 0x0b0f;
14905 }
14906+
14907+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14908+void pax_check_alloca(unsigned long size)
14909+{
14910+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14911+ unsigned cpu, used;
14912+ char *id;
14913+
14914+ /* check the process stack first */
14915+ stack_start = (unsigned long)task_stack_page(current);
14916+ stack_end = stack_start + THREAD_SIZE;
14917+ if (likely(stack_start <= sp && sp < stack_end)) {
14918+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
14919+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14920+ return;
14921+ }
14922+
14923+ cpu = get_cpu();
14924+
14925+ /* check the irq stacks */
14926+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14927+ stack_start = stack_end - IRQ_STACK_SIZE;
14928+ if (stack_start <= sp && sp < stack_end) {
14929+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14930+ put_cpu();
14931+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14932+ return;
14933+ }
14934+
14935+ /* check the exception stacks */
14936+ used = 0;
14937+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14938+ stack_start = stack_end - EXCEPTION_STKSZ;
14939+ if (stack_end && stack_start <= sp && sp < stack_end) {
14940+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14941+ put_cpu();
14942+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14943+ return;
14944+ }
14945+
14946+ put_cpu();
14947+
14948+ /* unknown stack */
14949+ BUG();
14950+}
14951+EXPORT_SYMBOL(pax_check_alloca);
14952+#endif
14953diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14954index 9b9f18b..9fcaa04 100644
14955--- a/arch/x86/kernel/early_printk.c
14956+++ b/arch/x86/kernel/early_printk.c
14957@@ -7,6 +7,7 @@
14958 #include <linux/pci_regs.h>
14959 #include <linux/pci_ids.h>
14960 #include <linux/errno.h>
14961+#include <linux/sched.h>
14962 #include <asm/io.h>
14963 #include <asm/processor.h>
14964 #include <asm/fcntl.h>
14965diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14966index 7b784f4..db6b628 100644
14967--- a/arch/x86/kernel/entry_32.S
14968+++ b/arch/x86/kernel/entry_32.S
14969@@ -179,13 +179,146 @@
14970 /*CFI_REL_OFFSET gs, PT_GS*/
14971 .endm
14972 .macro SET_KERNEL_GS reg
14973+
14974+#ifdef CONFIG_CC_STACKPROTECTOR
14975 movl $(__KERNEL_STACK_CANARY), \reg
14976+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14977+ movl $(__USER_DS), \reg
14978+#else
14979+ xorl \reg, \reg
14980+#endif
14981+
14982 movl \reg, %gs
14983 .endm
14984
14985 #endif /* CONFIG_X86_32_LAZY_GS */
14986
14987-.macro SAVE_ALL
14988+.macro pax_enter_kernel
14989+#ifdef CONFIG_PAX_KERNEXEC
14990+ call pax_enter_kernel
14991+#endif
14992+.endm
14993+
14994+.macro pax_exit_kernel
14995+#ifdef CONFIG_PAX_KERNEXEC
14996+ call pax_exit_kernel
14997+#endif
14998+.endm
14999+
15000+#ifdef CONFIG_PAX_KERNEXEC
15001+ENTRY(pax_enter_kernel)
15002+#ifdef CONFIG_PARAVIRT
15003+ pushl %eax
15004+ pushl %ecx
15005+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15006+ mov %eax, %esi
15007+#else
15008+ mov %cr0, %esi
15009+#endif
15010+ bts $16, %esi
15011+ jnc 1f
15012+ mov %cs, %esi
15013+ cmp $__KERNEL_CS, %esi
15014+ jz 3f
15015+ ljmp $__KERNEL_CS, $3f
15016+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15017+2:
15018+#ifdef CONFIG_PARAVIRT
15019+ mov %esi, %eax
15020+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15021+#else
15022+ mov %esi, %cr0
15023+#endif
15024+3:
15025+#ifdef CONFIG_PARAVIRT
15026+ popl %ecx
15027+ popl %eax
15028+#endif
15029+ ret
15030+ENDPROC(pax_enter_kernel)
15031+
15032+ENTRY(pax_exit_kernel)
15033+#ifdef CONFIG_PARAVIRT
15034+ pushl %eax
15035+ pushl %ecx
15036+#endif
15037+ mov %cs, %esi
15038+ cmp $__KERNEXEC_KERNEL_CS, %esi
15039+ jnz 2f
15040+#ifdef CONFIG_PARAVIRT
15041+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15042+ mov %eax, %esi
15043+#else
15044+ mov %cr0, %esi
15045+#endif
15046+ btr $16, %esi
15047+ ljmp $__KERNEL_CS, $1f
15048+1:
15049+#ifdef CONFIG_PARAVIRT
15050+ mov %esi, %eax
15051+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15052+#else
15053+ mov %esi, %cr0
15054+#endif
15055+2:
15056+#ifdef CONFIG_PARAVIRT
15057+ popl %ecx
15058+ popl %eax
15059+#endif
15060+ ret
15061+ENDPROC(pax_exit_kernel)
15062+#endif
15063+
15064+.macro pax_erase_kstack
15065+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15066+ call pax_erase_kstack
15067+#endif
15068+.endm
15069+
15070+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15071+/*
15072+ * ebp: thread_info
15073+ * ecx, edx: can be clobbered
15074+ */
15075+ENTRY(pax_erase_kstack)
15076+ pushl %edi
15077+ pushl %eax
15078+
15079+ mov TI_lowest_stack(%ebp), %edi
15080+ mov $-0xBEEF, %eax
15081+ std
15082+
15083+1: mov %edi, %ecx
15084+ and $THREAD_SIZE_asm - 1, %ecx
15085+ shr $2, %ecx
15086+ repne scasl
15087+ jecxz 2f
15088+
15089+ cmp $2*16, %ecx
15090+ jc 2f
15091+
15092+ mov $2*16, %ecx
15093+ repe scasl
15094+ jecxz 2f
15095+ jne 1b
15096+
15097+2: cld
15098+ mov %esp, %ecx
15099+ sub %edi, %ecx
15100+ shr $2, %ecx
15101+ rep stosl
15102+
15103+ mov TI_task_thread_sp0(%ebp), %edi
15104+ sub $128, %edi
15105+ mov %edi, TI_lowest_stack(%ebp)
15106+
15107+ popl %eax
15108+ popl %edi
15109+ ret
15110+ENDPROC(pax_erase_kstack)
15111+#endif
15112+
15113+.macro __SAVE_ALL _DS
15114 cld
15115 PUSH_GS
15116 pushl_cfi %fs
15117@@ -208,7 +341,7 @@
15118 CFI_REL_OFFSET ecx, 0
15119 pushl_cfi %ebx
15120 CFI_REL_OFFSET ebx, 0
15121- movl $(__USER_DS), %edx
15122+ movl $\_DS, %edx
15123 movl %edx, %ds
15124 movl %edx, %es
15125 movl $(__KERNEL_PERCPU), %edx
15126@@ -216,6 +349,15 @@
15127 SET_KERNEL_GS %edx
15128 .endm
15129
15130+.macro SAVE_ALL
15131+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15132+ __SAVE_ALL __KERNEL_DS
15133+ pax_enter_kernel
15134+#else
15135+ __SAVE_ALL __USER_DS
15136+#endif
15137+.endm
15138+
15139 .macro RESTORE_INT_REGS
15140 popl_cfi %ebx
15141 CFI_RESTORE ebx
15142@@ -301,7 +443,7 @@ ENTRY(ret_from_fork)
15143 popfl_cfi
15144 jmp syscall_exit
15145 CFI_ENDPROC
15146-END(ret_from_fork)
15147+ENDPROC(ret_from_fork)
15148
15149 /*
15150 * Interrupt exit functions should be protected against kprobes
15151@@ -335,7 +477,15 @@ resume_userspace_sig:
15152 andl $SEGMENT_RPL_MASK, %eax
15153 #endif
15154 cmpl $USER_RPL, %eax
15155+
15156+#ifdef CONFIG_PAX_KERNEXEC
15157+ jae resume_userspace
15158+
15159+ pax_exit_kernel
15160+ jmp resume_kernel
15161+#else
15162 jb resume_kernel # not returning to v8086 or userspace
15163+#endif
15164
15165 ENTRY(resume_userspace)
15166 LOCKDEP_SYS_EXIT
15167@@ -347,8 +497,8 @@ ENTRY(resume_userspace)
15168 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15169 # int/exception return?
15170 jne work_pending
15171- jmp restore_all
15172-END(ret_from_exception)
15173+ jmp restore_all_pax
15174+ENDPROC(ret_from_exception)
15175
15176 #ifdef CONFIG_PREEMPT
15177 ENTRY(resume_kernel)
15178@@ -363,7 +513,7 @@ need_resched:
15179 jz restore_all
15180 call preempt_schedule_irq
15181 jmp need_resched
15182-END(resume_kernel)
15183+ENDPROC(resume_kernel)
15184 #endif
15185 CFI_ENDPROC
15186 /*
15187@@ -397,23 +547,34 @@ sysenter_past_esp:
15188 /*CFI_REL_OFFSET cs, 0*/
15189 /*
15190 * Push current_thread_info()->sysenter_return to the stack.
15191- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15192- * pushed above; +8 corresponds to copy_thread's esp0 setting.
15193 */
15194- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15195+ pushl_cfi $0
15196 CFI_REL_OFFSET eip, 0
15197
15198 pushl_cfi %eax
15199 SAVE_ALL
15200+ GET_THREAD_INFO(%ebp)
15201+ movl TI_sysenter_return(%ebp),%ebp
15202+ movl %ebp,PT_EIP(%esp)
15203 ENABLE_INTERRUPTS(CLBR_NONE)
15204
15205 /*
15206 * Load the potential sixth argument from user stack.
15207 * Careful about security.
15208 */
15209+ movl PT_OLDESP(%esp),%ebp
15210+
15211+#ifdef CONFIG_PAX_MEMORY_UDEREF
15212+ mov PT_OLDSS(%esp),%ds
15213+1: movl %ds:(%ebp),%ebp
15214+ push %ss
15215+ pop %ds
15216+#else
15217 cmpl $__PAGE_OFFSET-3,%ebp
15218 jae syscall_fault
15219 1: movl (%ebp),%ebp
15220+#endif
15221+
15222 movl %ebp,PT_EBP(%esp)
15223 .section __ex_table,"a"
15224 .align 4
15225@@ -436,12 +597,24 @@ sysenter_do_call:
15226 testl $_TIF_ALLWORK_MASK, %ecx
15227 jne sysexit_audit
15228 sysenter_exit:
15229+
15230+#ifdef CONFIG_PAX_RANDKSTACK
15231+ pushl_cfi %eax
15232+ movl %esp, %eax
15233+ call pax_randomize_kstack
15234+ popl_cfi %eax
15235+#endif
15236+
15237+ pax_erase_kstack
15238+
15239 /* if something modifies registers it must also disable sysexit */
15240 movl PT_EIP(%esp), %edx
15241 movl PT_OLDESP(%esp), %ecx
15242 xorl %ebp,%ebp
15243 TRACE_IRQS_ON
15244 1: mov PT_FS(%esp), %fs
15245+2: mov PT_DS(%esp), %ds
15246+3: mov PT_ES(%esp), %es
15247 PTGS_TO_GS
15248 ENABLE_INTERRUPTS_SYSEXIT
15249
15250@@ -458,6 +631,9 @@ sysenter_audit:
15251 movl %eax,%edx /* 2nd arg: syscall number */
15252 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15253 call __audit_syscall_entry
15254+
15255+ pax_erase_kstack
15256+
15257 pushl_cfi %ebx
15258 movl PT_EAX(%esp),%eax /* reload syscall number */
15259 jmp sysenter_do_call
15260@@ -483,11 +659,17 @@ sysexit_audit:
15261
15262 CFI_ENDPROC
15263 .pushsection .fixup,"ax"
15264-2: movl $0,PT_FS(%esp)
15265+4: movl $0,PT_FS(%esp)
15266+ jmp 1b
15267+5: movl $0,PT_DS(%esp)
15268+ jmp 1b
15269+6: movl $0,PT_ES(%esp)
15270 jmp 1b
15271 .section __ex_table,"a"
15272 .align 4
15273- .long 1b,2b
15274+ .long 1b,4b
15275+ .long 2b,5b
15276+ .long 3b,6b
15277 .popsection
15278 PTGS_TO_GS_EX
15279 ENDPROC(ia32_sysenter_target)
15280@@ -520,6 +702,15 @@ syscall_exit:
15281 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15282 jne syscall_exit_work
15283
15284+restore_all_pax:
15285+
15286+#ifdef CONFIG_PAX_RANDKSTACK
15287+ movl %esp, %eax
15288+ call pax_randomize_kstack
15289+#endif
15290+
15291+ pax_erase_kstack
15292+
15293 restore_all:
15294 TRACE_IRQS_IRET
15295 restore_all_notrace:
15296@@ -579,14 +770,34 @@ ldt_ss:
15297 * compensating for the offset by changing to the ESPFIX segment with
15298 * a base address that matches for the difference.
15299 */
15300-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15301+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15302 mov %esp, %edx /* load kernel esp */
15303 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15304 mov %dx, %ax /* eax: new kernel esp */
15305 sub %eax, %edx /* offset (low word is 0) */
15306+#ifdef CONFIG_SMP
15307+ movl PER_CPU_VAR(cpu_number), %ebx
15308+ shll $PAGE_SHIFT_asm, %ebx
15309+ addl $cpu_gdt_table, %ebx
15310+#else
15311+ movl $cpu_gdt_table, %ebx
15312+#endif
15313 shr $16, %edx
15314- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15315- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15316+
15317+#ifdef CONFIG_PAX_KERNEXEC
15318+ mov %cr0, %esi
15319+ btr $16, %esi
15320+ mov %esi, %cr0
15321+#endif
15322+
15323+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15324+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15325+
15326+#ifdef CONFIG_PAX_KERNEXEC
15327+ bts $16, %esi
15328+ mov %esi, %cr0
15329+#endif
15330+
15331 pushl_cfi $__ESPFIX_SS
15332 pushl_cfi %eax /* new kernel esp */
15333 /* Disable interrupts, but do not irqtrace this section: we
15334@@ -615,38 +826,30 @@ work_resched:
15335 movl TI_flags(%ebp), %ecx
15336 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15337 # than syscall tracing?
15338- jz restore_all
15339+ jz restore_all_pax
15340 testb $_TIF_NEED_RESCHED, %cl
15341 jnz work_resched
15342
15343 work_notifysig: # deal with pending signals and
15344 # notify-resume requests
15345+ movl %esp, %eax
15346 #ifdef CONFIG_VM86
15347 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15348- movl %esp, %eax
15349- jne work_notifysig_v86 # returning to kernel-space or
15350+ jz 1f # returning to kernel-space or
15351 # vm86-space
15352- TRACE_IRQS_ON
15353- ENABLE_INTERRUPTS(CLBR_NONE)
15354- xorl %edx, %edx
15355- call do_notify_resume
15356- jmp resume_userspace_sig
15357
15358- ALIGN
15359-work_notifysig_v86:
15360 pushl_cfi %ecx # save ti_flags for do_notify_resume
15361 call save_v86_state # %eax contains pt_regs pointer
15362 popl_cfi %ecx
15363 movl %eax, %esp
15364-#else
15365- movl %esp, %eax
15366+1:
15367 #endif
15368 TRACE_IRQS_ON
15369 ENABLE_INTERRUPTS(CLBR_NONE)
15370 xorl %edx, %edx
15371 call do_notify_resume
15372 jmp resume_userspace_sig
15373-END(work_pending)
15374+ENDPROC(work_pending)
15375
15376 # perform syscall exit tracing
15377 ALIGN
15378@@ -654,11 +857,14 @@ syscall_trace_entry:
15379 movl $-ENOSYS,PT_EAX(%esp)
15380 movl %esp, %eax
15381 call syscall_trace_enter
15382+
15383+ pax_erase_kstack
15384+
15385 /* What it returned is what we'll actually use. */
15386 cmpl $(NR_syscalls), %eax
15387 jnae syscall_call
15388 jmp syscall_exit
15389-END(syscall_trace_entry)
15390+ENDPROC(syscall_trace_entry)
15391
15392 # perform syscall exit tracing
15393 ALIGN
15394@@ -671,20 +877,24 @@ syscall_exit_work:
15395 movl %esp, %eax
15396 call syscall_trace_leave
15397 jmp resume_userspace
15398-END(syscall_exit_work)
15399+ENDPROC(syscall_exit_work)
15400 CFI_ENDPROC
15401
15402 RING0_INT_FRAME # can't unwind into user space anyway
15403 syscall_fault:
15404+#ifdef CONFIG_PAX_MEMORY_UDEREF
15405+ push %ss
15406+ pop %ds
15407+#endif
15408 GET_THREAD_INFO(%ebp)
15409 movl $-EFAULT,PT_EAX(%esp)
15410 jmp resume_userspace
15411-END(syscall_fault)
15412+ENDPROC(syscall_fault)
15413
15414 syscall_badsys:
15415 movl $-ENOSYS,PT_EAX(%esp)
15416 jmp resume_userspace
15417-END(syscall_badsys)
15418+ENDPROC(syscall_badsys)
15419 CFI_ENDPROC
15420 /*
15421 * End of kprobes section
15422@@ -756,6 +966,36 @@ ENTRY(ptregs_clone)
15423 CFI_ENDPROC
15424 ENDPROC(ptregs_clone)
15425
15426+ ALIGN;
15427+ENTRY(kernel_execve)
15428+ CFI_STARTPROC
15429+ pushl_cfi %ebp
15430+ sub $PT_OLDSS+4,%esp
15431+ pushl_cfi %edi
15432+ pushl_cfi %ecx
15433+ pushl_cfi %eax
15434+ lea 3*4(%esp),%edi
15435+ mov $PT_OLDSS/4+1,%ecx
15436+ xorl %eax,%eax
15437+ rep stosl
15438+ popl_cfi %eax
15439+ popl_cfi %ecx
15440+ popl_cfi %edi
15441+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15442+ pushl_cfi %esp
15443+ call sys_execve
15444+ add $4,%esp
15445+ CFI_ADJUST_CFA_OFFSET -4
15446+ GET_THREAD_INFO(%ebp)
15447+ test %eax,%eax
15448+ jz syscall_exit
15449+ add $PT_OLDSS+4,%esp
15450+ CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15451+ popl_cfi %ebp
15452+ ret
15453+ CFI_ENDPROC
15454+ENDPROC(kernel_execve)
15455+
15456 .macro FIXUP_ESPFIX_STACK
15457 /*
15458 * Switch back for ESPFIX stack to the normal zerobased stack
15459@@ -765,8 +1005,15 @@ ENDPROC(ptregs_clone)
15460 * normal stack and adjusts ESP with the matching offset.
15461 */
15462 /* fixup the stack */
15463- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15464- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15465+#ifdef CONFIG_SMP
15466+ movl PER_CPU_VAR(cpu_number), %ebx
15467+ shll $PAGE_SHIFT_asm, %ebx
15468+ addl $cpu_gdt_table, %ebx
15469+#else
15470+ movl $cpu_gdt_table, %ebx
15471+#endif
15472+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15473+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15474 shl $16, %eax
15475 addl %esp, %eax /* the adjusted stack pointer */
15476 pushl_cfi $__KERNEL_DS
15477@@ -819,7 +1066,7 @@ vector=vector+1
15478 .endr
15479 2: jmp common_interrupt
15480 .endr
15481-END(irq_entries_start)
15482+ENDPROC(irq_entries_start)
15483
15484 .previous
15485 END(interrupt)
15486@@ -867,7 +1114,7 @@ ENTRY(coprocessor_error)
15487 pushl_cfi $do_coprocessor_error
15488 jmp error_code
15489 CFI_ENDPROC
15490-END(coprocessor_error)
15491+ENDPROC(coprocessor_error)
15492
15493 ENTRY(simd_coprocessor_error)
15494 RING0_INT_FRAME
15495@@ -888,7 +1135,7 @@ ENTRY(simd_coprocessor_error)
15496 #endif
15497 jmp error_code
15498 CFI_ENDPROC
15499-END(simd_coprocessor_error)
15500+ENDPROC(simd_coprocessor_error)
15501
15502 ENTRY(device_not_available)
15503 RING0_INT_FRAME
15504@@ -896,7 +1143,7 @@ ENTRY(device_not_available)
15505 pushl_cfi $do_device_not_available
15506 jmp error_code
15507 CFI_ENDPROC
15508-END(device_not_available)
15509+ENDPROC(device_not_available)
15510
15511 #ifdef CONFIG_PARAVIRT
15512 ENTRY(native_iret)
15513@@ -905,12 +1152,12 @@ ENTRY(native_iret)
15514 .align 4
15515 .long native_iret, iret_exc
15516 .previous
15517-END(native_iret)
15518+ENDPROC(native_iret)
15519
15520 ENTRY(native_irq_enable_sysexit)
15521 sti
15522 sysexit
15523-END(native_irq_enable_sysexit)
15524+ENDPROC(native_irq_enable_sysexit)
15525 #endif
15526
15527 ENTRY(overflow)
15528@@ -919,7 +1166,7 @@ ENTRY(overflow)
15529 pushl_cfi $do_overflow
15530 jmp error_code
15531 CFI_ENDPROC
15532-END(overflow)
15533+ENDPROC(overflow)
15534
15535 ENTRY(bounds)
15536 RING0_INT_FRAME
15537@@ -927,7 +1174,7 @@ ENTRY(bounds)
15538 pushl_cfi $do_bounds
15539 jmp error_code
15540 CFI_ENDPROC
15541-END(bounds)
15542+ENDPROC(bounds)
15543
15544 ENTRY(invalid_op)
15545 RING0_INT_FRAME
15546@@ -935,7 +1182,7 @@ ENTRY(invalid_op)
15547 pushl_cfi $do_invalid_op
15548 jmp error_code
15549 CFI_ENDPROC
15550-END(invalid_op)
15551+ENDPROC(invalid_op)
15552
15553 ENTRY(coprocessor_segment_overrun)
15554 RING0_INT_FRAME
15555@@ -943,35 +1190,35 @@ ENTRY(coprocessor_segment_overrun)
15556 pushl_cfi $do_coprocessor_segment_overrun
15557 jmp error_code
15558 CFI_ENDPROC
15559-END(coprocessor_segment_overrun)
15560+ENDPROC(coprocessor_segment_overrun)
15561
15562 ENTRY(invalid_TSS)
15563 RING0_EC_FRAME
15564 pushl_cfi $do_invalid_TSS
15565 jmp error_code
15566 CFI_ENDPROC
15567-END(invalid_TSS)
15568+ENDPROC(invalid_TSS)
15569
15570 ENTRY(segment_not_present)
15571 RING0_EC_FRAME
15572 pushl_cfi $do_segment_not_present
15573 jmp error_code
15574 CFI_ENDPROC
15575-END(segment_not_present)
15576+ENDPROC(segment_not_present)
15577
15578 ENTRY(stack_segment)
15579 RING0_EC_FRAME
15580 pushl_cfi $do_stack_segment
15581 jmp error_code
15582 CFI_ENDPROC
15583-END(stack_segment)
15584+ENDPROC(stack_segment)
15585
15586 ENTRY(alignment_check)
15587 RING0_EC_FRAME
15588 pushl_cfi $do_alignment_check
15589 jmp error_code
15590 CFI_ENDPROC
15591-END(alignment_check)
15592+ENDPROC(alignment_check)
15593
15594 ENTRY(divide_error)
15595 RING0_INT_FRAME
15596@@ -979,7 +1226,7 @@ ENTRY(divide_error)
15597 pushl_cfi $do_divide_error
15598 jmp error_code
15599 CFI_ENDPROC
15600-END(divide_error)
15601+ENDPROC(divide_error)
15602
15603 #ifdef CONFIG_X86_MCE
15604 ENTRY(machine_check)
15605@@ -988,7 +1235,7 @@ ENTRY(machine_check)
15606 pushl_cfi machine_check_vector
15607 jmp error_code
15608 CFI_ENDPROC
15609-END(machine_check)
15610+ENDPROC(machine_check)
15611 #endif
15612
15613 ENTRY(spurious_interrupt_bug)
15614@@ -997,7 +1244,7 @@ ENTRY(spurious_interrupt_bug)
15615 pushl_cfi $do_spurious_interrupt_bug
15616 jmp error_code
15617 CFI_ENDPROC
15618-END(spurious_interrupt_bug)
15619+ENDPROC(spurious_interrupt_bug)
15620 /*
15621 * End of kprobes section
15622 */
15623@@ -1112,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15624
15625 ENTRY(mcount)
15626 ret
15627-END(mcount)
15628+ENDPROC(mcount)
15629
15630 ENTRY(ftrace_caller)
15631 cmpl $0, function_trace_stop
15632@@ -1141,7 +1388,7 @@ ftrace_graph_call:
15633 .globl ftrace_stub
15634 ftrace_stub:
15635 ret
15636-END(ftrace_caller)
15637+ENDPROC(ftrace_caller)
15638
15639 #else /* ! CONFIG_DYNAMIC_FTRACE */
15640
15641@@ -1177,7 +1424,7 @@ trace:
15642 popl %ecx
15643 popl %eax
15644 jmp ftrace_stub
15645-END(mcount)
15646+ENDPROC(mcount)
15647 #endif /* CONFIG_DYNAMIC_FTRACE */
15648 #endif /* CONFIG_FUNCTION_TRACER */
15649
15650@@ -1198,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15651 popl %ecx
15652 popl %eax
15653 ret
15654-END(ftrace_graph_caller)
15655+ENDPROC(ftrace_graph_caller)
15656
15657 .globl return_to_handler
15658 return_to_handler:
15659@@ -1253,15 +1500,18 @@ error_code:
15660 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15661 REG_TO_PTGS %ecx
15662 SET_KERNEL_GS %ecx
15663- movl $(__USER_DS), %ecx
15664+ movl $(__KERNEL_DS), %ecx
15665 movl %ecx, %ds
15666 movl %ecx, %es
15667+
15668+ pax_enter_kernel
15669+
15670 TRACE_IRQS_OFF
15671 movl %esp,%eax # pt_regs pointer
15672 call *%edi
15673 jmp ret_from_exception
15674 CFI_ENDPROC
15675-END(page_fault)
15676+ENDPROC(page_fault)
15677
15678 /*
15679 * Debug traps and NMI can happen at the one SYSENTER instruction
15680@@ -1303,7 +1553,7 @@ debug_stack_correct:
15681 call do_debug
15682 jmp ret_from_exception
15683 CFI_ENDPROC
15684-END(debug)
15685+ENDPROC(debug)
15686
15687 /*
15688 * NMI is doubly nasty. It can happen _while_ we're handling
15689@@ -1340,6 +1590,9 @@ nmi_stack_correct:
15690 xorl %edx,%edx # zero error code
15691 movl %esp,%eax # pt_regs pointer
15692 call do_nmi
15693+
15694+ pax_exit_kernel
15695+
15696 jmp restore_all_notrace
15697 CFI_ENDPROC
15698
15699@@ -1376,12 +1629,15 @@ nmi_espfix_stack:
15700 FIXUP_ESPFIX_STACK # %eax == %esp
15701 xorl %edx,%edx # zero error code
15702 call do_nmi
15703+
15704+ pax_exit_kernel
15705+
15706 RESTORE_REGS
15707 lss 12+4(%esp), %esp # back to espfix stack
15708 CFI_ADJUST_CFA_OFFSET -24
15709 jmp irq_return
15710 CFI_ENDPROC
15711-END(nmi)
15712+ENDPROC(nmi)
15713
15714 ENTRY(int3)
15715 RING0_INT_FRAME
15716@@ -1393,14 +1649,14 @@ ENTRY(int3)
15717 call do_int3
15718 jmp ret_from_exception
15719 CFI_ENDPROC
15720-END(int3)
15721+ENDPROC(int3)
15722
15723 ENTRY(general_protection)
15724 RING0_EC_FRAME
15725 pushl_cfi $do_general_protection
15726 jmp error_code
15727 CFI_ENDPROC
15728-END(general_protection)
15729+ENDPROC(general_protection)
15730
15731 #ifdef CONFIG_KVM_GUEST
15732 ENTRY(async_page_fault)
15733@@ -1408,7 +1664,7 @@ ENTRY(async_page_fault)
15734 pushl_cfi $do_async_page_fault
15735 jmp error_code
15736 CFI_ENDPROC
15737-END(async_page_fault)
15738+ENDPROC(async_page_fault)
15739 #endif
15740
15741 /*
15742diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15743index 1333d98..b340ca2 100644
15744--- a/arch/x86/kernel/entry_64.S
15745+++ b/arch/x86/kernel/entry_64.S
15746@@ -56,6 +56,8 @@
15747 #include <asm/ftrace.h>
15748 #include <asm/percpu.h>
15749 #include <linux/err.h>
15750+#include <asm/pgtable.h>
15751+#include <asm/alternative-asm.h>
15752
15753 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15754 #include <linux/elf-em.h>
15755@@ -69,8 +71,9 @@
15756 #ifdef CONFIG_FUNCTION_TRACER
15757 #ifdef CONFIG_DYNAMIC_FTRACE
15758 ENTRY(mcount)
15759+ pax_force_retaddr
15760 retq
15761-END(mcount)
15762+ENDPROC(mcount)
15763
15764 ENTRY(ftrace_caller)
15765 cmpl $0, function_trace_stop
15766@@ -93,8 +96,9 @@ GLOBAL(ftrace_graph_call)
15767 #endif
15768
15769 GLOBAL(ftrace_stub)
15770+ pax_force_retaddr
15771 retq
15772-END(ftrace_caller)
15773+ENDPROC(ftrace_caller)
15774
15775 #else /* ! CONFIG_DYNAMIC_FTRACE */
15776 ENTRY(mcount)
15777@@ -113,6 +117,7 @@ ENTRY(mcount)
15778 #endif
15779
15780 GLOBAL(ftrace_stub)
15781+ pax_force_retaddr
15782 retq
15783
15784 trace:
15785@@ -122,12 +127,13 @@ trace:
15786 movq 8(%rbp), %rsi
15787 subq $MCOUNT_INSN_SIZE, %rdi
15788
15789+ pax_force_fptr ftrace_trace_function
15790 call *ftrace_trace_function
15791
15792 MCOUNT_RESTORE_FRAME
15793
15794 jmp ftrace_stub
15795-END(mcount)
15796+ENDPROC(mcount)
15797 #endif /* CONFIG_DYNAMIC_FTRACE */
15798 #endif /* CONFIG_FUNCTION_TRACER */
15799
15800@@ -147,8 +153,9 @@ ENTRY(ftrace_graph_caller)
15801
15802 MCOUNT_RESTORE_FRAME
15803
15804+ pax_force_retaddr
15805 retq
15806-END(ftrace_graph_caller)
15807+ENDPROC(ftrace_graph_caller)
15808
15809 GLOBAL(return_to_handler)
15810 subq $24, %rsp
15811@@ -164,6 +171,7 @@ GLOBAL(return_to_handler)
15812 movq 8(%rsp), %rdx
15813 movq (%rsp), %rax
15814 addq $24, %rsp
15815+ pax_force_fptr %rdi
15816 jmp *%rdi
15817 #endif
15818
15819@@ -179,6 +187,282 @@ ENTRY(native_usergs_sysret64)
15820 ENDPROC(native_usergs_sysret64)
15821 #endif /* CONFIG_PARAVIRT */
15822
15823+ .macro ljmpq sel, off
15824+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15825+ .byte 0x48; ljmp *1234f(%rip)
15826+ .pushsection .rodata
15827+ .align 16
15828+ 1234: .quad \off; .word \sel
15829+ .popsection
15830+#else
15831+ pushq $\sel
15832+ pushq $\off
15833+ lretq
15834+#endif
15835+ .endm
15836+
15837+ .macro pax_enter_kernel
15838+ pax_set_fptr_mask
15839+#ifdef CONFIG_PAX_KERNEXEC
15840+ call pax_enter_kernel
15841+#endif
15842+ .endm
15843+
15844+ .macro pax_exit_kernel
15845+#ifdef CONFIG_PAX_KERNEXEC
15846+ call pax_exit_kernel
15847+#endif
15848+ .endm
15849+
15850+#ifdef CONFIG_PAX_KERNEXEC
15851+ENTRY(pax_enter_kernel)
15852+ pushq %rdi
15853+
15854+#ifdef CONFIG_PARAVIRT
15855+ PV_SAVE_REGS(CLBR_RDI)
15856+#endif
15857+
15858+ GET_CR0_INTO_RDI
15859+ bts $16,%rdi
15860+ jnc 3f
15861+ mov %cs,%edi
15862+ cmp $__KERNEL_CS,%edi
15863+ jnz 2f
15864+1:
15865+
15866+#ifdef CONFIG_PARAVIRT
15867+ PV_RESTORE_REGS(CLBR_RDI)
15868+#endif
15869+
15870+ popq %rdi
15871+ pax_force_retaddr
15872+ retq
15873+
15874+2: ljmpq __KERNEL_CS,1f
15875+3: ljmpq __KERNEXEC_KERNEL_CS,4f
15876+4: SET_RDI_INTO_CR0
15877+ jmp 1b
15878+ENDPROC(pax_enter_kernel)
15879+
15880+ENTRY(pax_exit_kernel)
15881+ pushq %rdi
15882+
15883+#ifdef CONFIG_PARAVIRT
15884+ PV_SAVE_REGS(CLBR_RDI)
15885+#endif
15886+
15887+ mov %cs,%rdi
15888+ cmp $__KERNEXEC_KERNEL_CS,%edi
15889+ jz 2f
15890+1:
15891+
15892+#ifdef CONFIG_PARAVIRT
15893+ PV_RESTORE_REGS(CLBR_RDI);
15894+#endif
15895+
15896+ popq %rdi
15897+ pax_force_retaddr
15898+ retq
15899+
15900+2: GET_CR0_INTO_RDI
15901+ btr $16,%rdi
15902+ ljmpq __KERNEL_CS,3f
15903+3: SET_RDI_INTO_CR0
15904+ jmp 1b
15905+#ifdef CONFIG_PARAVIRT
15906+ PV_RESTORE_REGS(CLBR_RDI);
15907+#endif
15908+
15909+ popq %rdi
15910+ pax_force_retaddr
15911+ retq
15912+ENDPROC(pax_exit_kernel)
15913+#endif
15914+
15915+ .macro pax_enter_kernel_user
15916+ pax_set_fptr_mask
15917+#ifdef CONFIG_PAX_MEMORY_UDEREF
15918+ call pax_enter_kernel_user
15919+#endif
15920+ .endm
15921+
15922+ .macro pax_exit_kernel_user
15923+#ifdef CONFIG_PAX_MEMORY_UDEREF
15924+ call pax_exit_kernel_user
15925+#endif
15926+#ifdef CONFIG_PAX_RANDKSTACK
15927+ pushq %rax
15928+ call pax_randomize_kstack
15929+ popq %rax
15930+#endif
15931+ .endm
15932+
15933+#ifdef CONFIG_PAX_MEMORY_UDEREF
15934+ENTRY(pax_enter_kernel_user)
15935+ pushq %rdi
15936+ pushq %rbx
15937+
15938+#ifdef CONFIG_PARAVIRT
15939+ PV_SAVE_REGS(CLBR_RDI)
15940+#endif
15941+
15942+ GET_CR3_INTO_RDI
15943+ mov %rdi,%rbx
15944+ add $__START_KERNEL_map,%rbx
15945+ sub phys_base(%rip),%rbx
15946+
15947+#ifdef CONFIG_PARAVIRT
15948+ pushq %rdi
15949+ cmpl $0, pv_info+PARAVIRT_enabled
15950+ jz 1f
15951+ i = 0
15952+ .rept USER_PGD_PTRS
15953+ mov i*8(%rbx),%rsi
15954+ mov $0,%sil
15955+ lea i*8(%rbx),%rdi
15956+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15957+ i = i + 1
15958+ .endr
15959+ jmp 2f
15960+1:
15961+#endif
15962+
15963+ i = 0
15964+ .rept USER_PGD_PTRS
15965+ movb $0,i*8(%rbx)
15966+ i = i + 1
15967+ .endr
15968+
15969+#ifdef CONFIG_PARAVIRT
15970+2: popq %rdi
15971+#endif
15972+ SET_RDI_INTO_CR3
15973+
15974+#ifdef CONFIG_PAX_KERNEXEC
15975+ GET_CR0_INTO_RDI
15976+ bts $16,%rdi
15977+ SET_RDI_INTO_CR0
15978+#endif
15979+
15980+#ifdef CONFIG_PARAVIRT
15981+ PV_RESTORE_REGS(CLBR_RDI)
15982+#endif
15983+
15984+ popq %rbx
15985+ popq %rdi
15986+ pax_force_retaddr
15987+ retq
15988+ENDPROC(pax_enter_kernel_user)
15989+
15990+ENTRY(pax_exit_kernel_user)
15991+ push %rdi
15992+
15993+#ifdef CONFIG_PARAVIRT
15994+ pushq %rbx
15995+ PV_SAVE_REGS(CLBR_RDI)
15996+#endif
15997+
15998+#ifdef CONFIG_PAX_KERNEXEC
15999+ GET_CR0_INTO_RDI
16000+ btr $16,%rdi
16001+ SET_RDI_INTO_CR0
16002+#endif
16003+
16004+ GET_CR3_INTO_RDI
16005+ add $__START_KERNEL_map,%rdi
16006+ sub phys_base(%rip),%rdi
16007+
16008+#ifdef CONFIG_PARAVIRT
16009+ cmpl $0, pv_info+PARAVIRT_enabled
16010+ jz 1f
16011+ mov %rdi,%rbx
16012+ i = 0
16013+ .rept USER_PGD_PTRS
16014+ mov i*8(%rbx),%rsi
16015+ mov $0x67,%sil
16016+ lea i*8(%rbx),%rdi
16017+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16018+ i = i + 1
16019+ .endr
16020+ jmp 2f
16021+1:
16022+#endif
16023+
16024+ i = 0
16025+ .rept USER_PGD_PTRS
16026+ movb $0x67,i*8(%rdi)
16027+ i = i + 1
16028+ .endr
16029+
16030+#ifdef CONFIG_PARAVIRT
16031+2: PV_RESTORE_REGS(CLBR_RDI)
16032+ popq %rbx
16033+#endif
16034+
16035+ popq %rdi
16036+ pax_force_retaddr
16037+ retq
16038+ENDPROC(pax_exit_kernel_user)
16039+#endif
16040+
16041+.macro pax_erase_kstack
16042+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16043+ call pax_erase_kstack
16044+#endif
16045+.endm
16046+
16047+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16048+/*
16049+ * r11: thread_info
16050+ * rcx, rdx: can be clobbered
16051+ */
16052+ENTRY(pax_erase_kstack)
16053+ pushq %rdi
16054+ pushq %rax
16055+ pushq %r11
16056+
16057+ GET_THREAD_INFO(%r11)
16058+ mov TI_lowest_stack(%r11), %rdi
16059+ mov $-0xBEEF, %rax
16060+ std
16061+
16062+1: mov %edi, %ecx
16063+ and $THREAD_SIZE_asm - 1, %ecx
16064+ shr $3, %ecx
16065+ repne scasq
16066+ jecxz 2f
16067+
16068+ cmp $2*8, %ecx
16069+ jc 2f
16070+
16071+ mov $2*8, %ecx
16072+ repe scasq
16073+ jecxz 2f
16074+ jne 1b
16075+
16076+2: cld
16077+ mov %esp, %ecx
16078+ sub %edi, %ecx
16079+
16080+ cmp $THREAD_SIZE_asm, %rcx
16081+ jb 3f
16082+ ud2
16083+3:
16084+
16085+ shr $3, %ecx
16086+ rep stosq
16087+
16088+ mov TI_task_thread_sp0(%r11), %rdi
16089+ sub $256, %rdi
16090+ mov %rdi, TI_lowest_stack(%r11)
16091+
16092+ popq %r11
16093+ popq %rax
16094+ popq %rdi
16095+ pax_force_retaddr
16096+ ret
16097+ENDPROC(pax_erase_kstack)
16098+#endif
16099
16100 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16101 #ifdef CONFIG_TRACE_IRQFLAGS
16102@@ -232,8 +516,8 @@ ENDPROC(native_usergs_sysret64)
16103 .endm
16104
16105 .macro UNFAKE_STACK_FRAME
16106- addq $8*6, %rsp
16107- CFI_ADJUST_CFA_OFFSET -(6*8)
16108+ addq $8*6 + ARG_SKIP, %rsp
16109+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16110 .endm
16111
16112 /*
16113@@ -320,7 +604,7 @@ ENDPROC(native_usergs_sysret64)
16114 movq %rsp, %rsi
16115
16116 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16117- testl $3, CS(%rdi)
16118+ testb $3, CS(%rdi)
16119 je 1f
16120 SWAPGS
16121 /*
16122@@ -356,9 +640,10 @@ ENTRY(save_rest)
16123 movq_cfi r15, R15+16
16124 movq %r11, 8(%rsp) /* return address */
16125 FIXUP_TOP_OF_STACK %r11, 16
16126+ pax_force_retaddr
16127 ret
16128 CFI_ENDPROC
16129-END(save_rest)
16130+ENDPROC(save_rest)
16131
16132 /* save complete stack frame */
16133 .pushsection .kprobes.text, "ax"
16134@@ -387,9 +672,10 @@ ENTRY(save_paranoid)
16135 js 1f /* negative -> in kernel */
16136 SWAPGS
16137 xorl %ebx,%ebx
16138-1: ret
16139+1: pax_force_retaddr_bts
16140+ ret
16141 CFI_ENDPROC
16142-END(save_paranoid)
16143+ENDPROC(save_paranoid)
16144 .popsection
16145
16146 /*
16147@@ -411,7 +697,7 @@ ENTRY(ret_from_fork)
16148
16149 RESTORE_REST
16150
16151- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16152+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16153 jz retint_restore_args
16154
16155 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16156@@ -421,7 +707,7 @@ ENTRY(ret_from_fork)
16157 jmp ret_from_sys_call # go to the SYSRET fastpath
16158
16159 CFI_ENDPROC
16160-END(ret_from_fork)
16161+ENDPROC(ret_from_fork)
16162
16163 /*
16164 * System call entry. Up to 6 arguments in registers are supported.
16165@@ -457,7 +743,7 @@ END(ret_from_fork)
16166 ENTRY(system_call)
16167 CFI_STARTPROC simple
16168 CFI_SIGNAL_FRAME
16169- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16170+ CFI_DEF_CFA rsp,0
16171 CFI_REGISTER rip,rcx
16172 /*CFI_REGISTER rflags,r11*/
16173 SWAPGS_UNSAFE_STACK
16174@@ -470,21 +756,23 @@ GLOBAL(system_call_after_swapgs)
16175
16176 movq %rsp,PER_CPU_VAR(old_rsp)
16177 movq PER_CPU_VAR(kernel_stack),%rsp
16178+ SAVE_ARGS 8*6,0
16179+ pax_enter_kernel_user
16180 /*
16181 * No need to follow this irqs off/on section - it's straight
16182 * and short:
16183 */
16184 ENABLE_INTERRUPTS(CLBR_NONE)
16185- SAVE_ARGS 8,0
16186 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16187 movq %rcx,RIP-ARGOFFSET(%rsp)
16188 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16189- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16190+ GET_THREAD_INFO(%rcx)
16191+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16192 jnz tracesys
16193 system_call_fastpath:
16194 cmpq $__NR_syscall_max,%rax
16195 ja badsys
16196- movq %r10,%rcx
16197+ movq R10-ARGOFFSET(%rsp),%rcx
16198 call *sys_call_table(,%rax,8) # XXX: rip relative
16199 movq %rax,RAX-ARGOFFSET(%rsp)
16200 /*
16201@@ -498,10 +786,13 @@ sysret_check:
16202 LOCKDEP_SYS_EXIT
16203 DISABLE_INTERRUPTS(CLBR_NONE)
16204 TRACE_IRQS_OFF
16205- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16206+ GET_THREAD_INFO(%rcx)
16207+ movl TI_flags(%rcx),%edx
16208 andl %edi,%edx
16209 jnz sysret_careful
16210 CFI_REMEMBER_STATE
16211+ pax_exit_kernel_user
16212+ pax_erase_kstack
16213 /*
16214 * sysretq will re-enable interrupts:
16215 */
16216@@ -553,14 +844,18 @@ badsys:
16217 * jump back to the normal fast path.
16218 */
16219 auditsys:
16220- movq %r10,%r9 /* 6th arg: 4th syscall arg */
16221+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16222 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16223 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16224 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16225 movq %rax,%rsi /* 2nd arg: syscall number */
16226 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16227 call __audit_syscall_entry
16228+
16229+ pax_erase_kstack
16230+
16231 LOAD_ARGS 0 /* reload call-clobbered registers */
16232+ pax_set_fptr_mask
16233 jmp system_call_fastpath
16234
16235 /*
16236@@ -581,7 +876,7 @@ sysret_audit:
16237 /* Do syscall tracing */
16238 tracesys:
16239 #ifdef CONFIG_AUDITSYSCALL
16240- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16241+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16242 jz auditsys
16243 #endif
16244 SAVE_REST
16245@@ -589,16 +884,20 @@ tracesys:
16246 FIXUP_TOP_OF_STACK %rdi
16247 movq %rsp,%rdi
16248 call syscall_trace_enter
16249+
16250+ pax_erase_kstack
16251+
16252 /*
16253 * Reload arg registers from stack in case ptrace changed them.
16254 * We don't reload %rax because syscall_trace_enter() returned
16255 * the value it wants us to use in the table lookup.
16256 */
16257 LOAD_ARGS ARGOFFSET, 1
16258+ pax_set_fptr_mask
16259 RESTORE_REST
16260 cmpq $__NR_syscall_max,%rax
16261 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16262- movq %r10,%rcx /* fixup for C */
16263+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16264 call *sys_call_table(,%rax,8)
16265 movq %rax,RAX-ARGOFFSET(%rsp)
16266 /* Use IRET because user could have changed frame */
16267@@ -619,6 +918,7 @@ GLOBAL(int_with_check)
16268 andl %edi,%edx
16269 jnz int_careful
16270 andl $~TS_COMPAT,TI_status(%rcx)
16271+ pax_erase_kstack
16272 jmp retint_swapgs
16273
16274 /* Either reschedule or signal or syscall exit tracking needed. */
16275@@ -665,7 +965,7 @@ int_restore_rest:
16276 TRACE_IRQS_OFF
16277 jmp int_with_check
16278 CFI_ENDPROC
16279-END(system_call)
16280+ENDPROC(system_call)
16281
16282 /*
16283 * Certain special system calls that need to save a complete full stack frame.
16284@@ -681,7 +981,7 @@ ENTRY(\label)
16285 call \func
16286 jmp ptregscall_common
16287 CFI_ENDPROC
16288-END(\label)
16289+ENDPROC(\label)
16290 .endm
16291
16292 PTREGSCALL stub_clone, sys_clone, %r8
16293@@ -699,9 +999,10 @@ ENTRY(ptregscall_common)
16294 movq_cfi_restore R12+8, r12
16295 movq_cfi_restore RBP+8, rbp
16296 movq_cfi_restore RBX+8, rbx
16297+ pax_force_retaddr
16298 ret $REST_SKIP /* pop extended registers */
16299 CFI_ENDPROC
16300-END(ptregscall_common)
16301+ENDPROC(ptregscall_common)
16302
16303 ENTRY(stub_execve)
16304 CFI_STARTPROC
16305@@ -716,7 +1017,7 @@ ENTRY(stub_execve)
16306 RESTORE_REST
16307 jmp int_ret_from_sys_call
16308 CFI_ENDPROC
16309-END(stub_execve)
16310+ENDPROC(stub_execve)
16311
16312 /*
16313 * sigreturn is special because it needs to restore all registers on return.
16314@@ -734,7 +1035,7 @@ ENTRY(stub_rt_sigreturn)
16315 RESTORE_REST
16316 jmp int_ret_from_sys_call
16317 CFI_ENDPROC
16318-END(stub_rt_sigreturn)
16319+ENDPROC(stub_rt_sigreturn)
16320
16321 /*
16322 * Build the entry stubs and pointer table with some assembler magic.
16323@@ -769,7 +1070,7 @@ vector=vector+1
16324 2: jmp common_interrupt
16325 .endr
16326 CFI_ENDPROC
16327-END(irq_entries_start)
16328+ENDPROC(irq_entries_start)
16329
16330 .previous
16331 END(interrupt)
16332@@ -789,6 +1090,16 @@ END(interrupt)
16333 subq $ORIG_RAX-RBP, %rsp
16334 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16335 SAVE_ARGS_IRQ
16336+#ifdef CONFIG_PAX_MEMORY_UDEREF
16337+ testb $3, CS(%rdi)
16338+ jnz 1f
16339+ pax_enter_kernel
16340+ jmp 2f
16341+1: pax_enter_kernel_user
16342+2:
16343+#else
16344+ pax_enter_kernel
16345+#endif
16346 call \func
16347 .endm
16348
16349@@ -820,7 +1131,7 @@ ret_from_intr:
16350
16351 exit_intr:
16352 GET_THREAD_INFO(%rcx)
16353- testl $3,CS-ARGOFFSET(%rsp)
16354+ testb $3,CS-ARGOFFSET(%rsp)
16355 je retint_kernel
16356
16357 /* Interrupt came from user space */
16358@@ -842,12 +1153,15 @@ retint_swapgs: /* return to user-space */
16359 * The iretq could re-enable interrupts:
16360 */
16361 DISABLE_INTERRUPTS(CLBR_ANY)
16362+ pax_exit_kernel_user
16363 TRACE_IRQS_IRETQ
16364 SWAPGS
16365 jmp restore_args
16366
16367 retint_restore_args: /* return to kernel space */
16368 DISABLE_INTERRUPTS(CLBR_ANY)
16369+ pax_exit_kernel
16370+ pax_force_retaddr RIP-ARGOFFSET
16371 /*
16372 * The iretq could re-enable interrupts:
16373 */
16374@@ -936,7 +1250,7 @@ ENTRY(retint_kernel)
16375 #endif
16376
16377 CFI_ENDPROC
16378-END(common_interrupt)
16379+ENDPROC(common_interrupt)
16380 /*
16381 * End of kprobes section
16382 */
16383@@ -953,7 +1267,7 @@ ENTRY(\sym)
16384 interrupt \do_sym
16385 jmp ret_from_intr
16386 CFI_ENDPROC
16387-END(\sym)
16388+ENDPROC(\sym)
16389 .endm
16390
16391 #ifdef CONFIG_SMP
16392@@ -1026,12 +1340,22 @@ ENTRY(\sym)
16393 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16394 call error_entry
16395 DEFAULT_FRAME 0
16396+#ifdef CONFIG_PAX_MEMORY_UDEREF
16397+ testb $3, CS(%rsp)
16398+ jnz 1f
16399+ pax_enter_kernel
16400+ jmp 2f
16401+1: pax_enter_kernel_user
16402+2:
16403+#else
16404+ pax_enter_kernel
16405+#endif
16406 movq %rsp,%rdi /* pt_regs pointer */
16407 xorl %esi,%esi /* no error code */
16408 call \do_sym
16409 jmp error_exit /* %ebx: no swapgs flag */
16410 CFI_ENDPROC
16411-END(\sym)
16412+ENDPROC(\sym)
16413 .endm
16414
16415 .macro paranoidzeroentry sym do_sym
16416@@ -1043,15 +1367,25 @@ ENTRY(\sym)
16417 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16418 call save_paranoid
16419 TRACE_IRQS_OFF
16420+#ifdef CONFIG_PAX_MEMORY_UDEREF
16421+ testb $3, CS(%rsp)
16422+ jnz 1f
16423+ pax_enter_kernel
16424+ jmp 2f
16425+1: pax_enter_kernel_user
16426+2:
16427+#else
16428+ pax_enter_kernel
16429+#endif
16430 movq %rsp,%rdi /* pt_regs pointer */
16431 xorl %esi,%esi /* no error code */
16432 call \do_sym
16433 jmp paranoid_exit /* %ebx: no swapgs flag */
16434 CFI_ENDPROC
16435-END(\sym)
16436+ENDPROC(\sym)
16437 .endm
16438
16439-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16440+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16441 .macro paranoidzeroentry_ist sym do_sym ist
16442 ENTRY(\sym)
16443 INTR_FRAME
16444@@ -1061,14 +1395,30 @@ ENTRY(\sym)
16445 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16446 call save_paranoid
16447 TRACE_IRQS_OFF
16448+#ifdef CONFIG_PAX_MEMORY_UDEREF
16449+ testb $3, CS(%rsp)
16450+ jnz 1f
16451+ pax_enter_kernel
16452+ jmp 2f
16453+1: pax_enter_kernel_user
16454+2:
16455+#else
16456+ pax_enter_kernel
16457+#endif
16458 movq %rsp,%rdi /* pt_regs pointer */
16459 xorl %esi,%esi /* no error code */
16460+#ifdef CONFIG_SMP
16461+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16462+ lea init_tss(%r12), %r12
16463+#else
16464+ lea init_tss(%rip), %r12
16465+#endif
16466 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16467 call \do_sym
16468 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16469 jmp paranoid_exit /* %ebx: no swapgs flag */
16470 CFI_ENDPROC
16471-END(\sym)
16472+ENDPROC(\sym)
16473 .endm
16474
16475 .macro errorentry sym do_sym
16476@@ -1079,13 +1429,23 @@ ENTRY(\sym)
16477 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16478 call error_entry
16479 DEFAULT_FRAME 0
16480+#ifdef CONFIG_PAX_MEMORY_UDEREF
16481+ testb $3, CS(%rsp)
16482+ jnz 1f
16483+ pax_enter_kernel
16484+ jmp 2f
16485+1: pax_enter_kernel_user
16486+2:
16487+#else
16488+ pax_enter_kernel
16489+#endif
16490 movq %rsp,%rdi /* pt_regs pointer */
16491 movq ORIG_RAX(%rsp),%rsi /* get error code */
16492 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16493 call \do_sym
16494 jmp error_exit /* %ebx: no swapgs flag */
16495 CFI_ENDPROC
16496-END(\sym)
16497+ENDPROC(\sym)
16498 .endm
16499
16500 /* error code is on the stack already */
16501@@ -1098,13 +1458,23 @@ ENTRY(\sym)
16502 call save_paranoid
16503 DEFAULT_FRAME 0
16504 TRACE_IRQS_OFF
16505+#ifdef CONFIG_PAX_MEMORY_UDEREF
16506+ testb $3, CS(%rsp)
16507+ jnz 1f
16508+ pax_enter_kernel
16509+ jmp 2f
16510+1: pax_enter_kernel_user
16511+2:
16512+#else
16513+ pax_enter_kernel
16514+#endif
16515 movq %rsp,%rdi /* pt_regs pointer */
16516 movq ORIG_RAX(%rsp),%rsi /* get error code */
16517 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16518 call \do_sym
16519 jmp paranoid_exit /* %ebx: no swapgs flag */
16520 CFI_ENDPROC
16521-END(\sym)
16522+ENDPROC(\sym)
16523 .endm
16524
16525 zeroentry divide_error do_divide_error
16526@@ -1134,9 +1504,10 @@ gs_change:
16527 2: mfence /* workaround */
16528 SWAPGS
16529 popfq_cfi
16530+ pax_force_retaddr
16531 ret
16532 CFI_ENDPROC
16533-END(native_load_gs_index)
16534+ENDPROC(native_load_gs_index)
16535
16536 .section __ex_table,"a"
16537 .align 8
16538@@ -1158,13 +1529,14 @@ ENTRY(kernel_thread_helper)
16539 * Here we are in the child and the registers are set as they were
16540 * at kernel_thread() invocation in the parent.
16541 */
16542+ pax_force_fptr %rsi
16543 call *%rsi
16544 # exit
16545 mov %eax, %edi
16546 call do_exit
16547 ud2 # padding for call trace
16548 CFI_ENDPROC
16549-END(kernel_thread_helper)
16550+ENDPROC(kernel_thread_helper)
16551
16552 /*
16553 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16554@@ -1191,11 +1563,11 @@ ENTRY(kernel_execve)
16555 RESTORE_REST
16556 testq %rax,%rax
16557 je int_ret_from_sys_call
16558- RESTORE_ARGS
16559 UNFAKE_STACK_FRAME
16560+ pax_force_retaddr
16561 ret
16562 CFI_ENDPROC
16563-END(kernel_execve)
16564+ENDPROC(kernel_execve)
16565
16566 /* Call softirq on interrupt stack. Interrupts are off. */
16567 ENTRY(call_softirq)
16568@@ -1213,9 +1585,10 @@ ENTRY(call_softirq)
16569 CFI_DEF_CFA_REGISTER rsp
16570 CFI_ADJUST_CFA_OFFSET -8
16571 decl PER_CPU_VAR(irq_count)
16572+ pax_force_retaddr
16573 ret
16574 CFI_ENDPROC
16575-END(call_softirq)
16576+ENDPROC(call_softirq)
16577
16578 #ifdef CONFIG_XEN
16579 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16580@@ -1253,7 +1626,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16581 decl PER_CPU_VAR(irq_count)
16582 jmp error_exit
16583 CFI_ENDPROC
16584-END(xen_do_hypervisor_callback)
16585+ENDPROC(xen_do_hypervisor_callback)
16586
16587 /*
16588 * Hypervisor uses this for application faults while it executes.
16589@@ -1312,7 +1685,7 @@ ENTRY(xen_failsafe_callback)
16590 SAVE_ALL
16591 jmp error_exit
16592 CFI_ENDPROC
16593-END(xen_failsafe_callback)
16594+ENDPROC(xen_failsafe_callback)
16595
16596 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16597 xen_hvm_callback_vector xen_evtchn_do_upcall
16598@@ -1361,16 +1734,31 @@ ENTRY(paranoid_exit)
16599 TRACE_IRQS_OFF
16600 testl %ebx,%ebx /* swapgs needed? */
16601 jnz paranoid_restore
16602- testl $3,CS(%rsp)
16603+ testb $3,CS(%rsp)
16604 jnz paranoid_userspace
16605+#ifdef CONFIG_PAX_MEMORY_UDEREF
16606+ pax_exit_kernel
16607+ TRACE_IRQS_IRETQ 0
16608+ SWAPGS_UNSAFE_STACK
16609+ RESTORE_ALL 8
16610+ pax_force_retaddr_bts
16611+ jmp irq_return
16612+#endif
16613 paranoid_swapgs:
16614+#ifdef CONFIG_PAX_MEMORY_UDEREF
16615+ pax_exit_kernel_user
16616+#else
16617+ pax_exit_kernel
16618+#endif
16619 TRACE_IRQS_IRETQ 0
16620 SWAPGS_UNSAFE_STACK
16621 RESTORE_ALL 8
16622 jmp irq_return
16623 paranoid_restore:
16624+ pax_exit_kernel
16625 TRACE_IRQS_IRETQ 0
16626 RESTORE_ALL 8
16627+ pax_force_retaddr_bts
16628 jmp irq_return
16629 paranoid_userspace:
16630 GET_THREAD_INFO(%rcx)
16631@@ -1399,7 +1787,7 @@ paranoid_schedule:
16632 TRACE_IRQS_OFF
16633 jmp paranoid_userspace
16634 CFI_ENDPROC
16635-END(paranoid_exit)
16636+ENDPROC(paranoid_exit)
16637
16638 /*
16639 * Exception entry point. This expects an error code/orig_rax on the stack.
16640@@ -1426,12 +1814,13 @@ ENTRY(error_entry)
16641 movq_cfi r14, R14+8
16642 movq_cfi r15, R15+8
16643 xorl %ebx,%ebx
16644- testl $3,CS+8(%rsp)
16645+ testb $3,CS+8(%rsp)
16646 je error_kernelspace
16647 error_swapgs:
16648 SWAPGS
16649 error_sti:
16650 TRACE_IRQS_OFF
16651+ pax_force_retaddr_bts
16652 ret
16653
16654 /*
16655@@ -1458,7 +1847,7 @@ bstep_iret:
16656 movq %rcx,RIP+8(%rsp)
16657 jmp error_swapgs
16658 CFI_ENDPROC
16659-END(error_entry)
16660+ENDPROC(error_entry)
16661
16662
16663 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16664@@ -1478,7 +1867,7 @@ ENTRY(error_exit)
16665 jnz retint_careful
16666 jmp retint_swapgs
16667 CFI_ENDPROC
16668-END(error_exit)
16669+ENDPROC(error_exit)
16670
16671 /*
16672 * Test if a given stack is an NMI stack or not.
16673@@ -1535,9 +1924,11 @@ ENTRY(nmi)
16674 * If %cs was not the kernel segment, then the NMI triggered in user
16675 * space, which means it is definitely not nested.
16676 */
16677+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16678+ je 1f
16679 cmpl $__KERNEL_CS, 16(%rsp)
16680 jne first_nmi
16681-
16682+1:
16683 /*
16684 * Check the special variable on the stack to see if NMIs are
16685 * executing.
16686@@ -1659,6 +2050,16 @@ restart_nmi:
16687 */
16688 call save_paranoid
16689 DEFAULT_FRAME 0
16690+#ifdef CONFIG_PAX_MEMORY_UDEREF
16691+ testb $3, CS(%rsp)
16692+ jnz 1f
16693+ pax_enter_kernel
16694+ jmp 2f
16695+1: pax_enter_kernel_user
16696+2:
16697+#else
16698+ pax_enter_kernel
16699+#endif
16700 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16701 movq %rsp,%rdi
16702 movq $-1,%rsi
16703@@ -1666,14 +2067,25 @@ restart_nmi:
16704 testl %ebx,%ebx /* swapgs needed? */
16705 jnz nmi_restore
16706 nmi_swapgs:
16707+#ifdef CONFIG_PAX_MEMORY_UDEREF
16708+ pax_exit_kernel_user
16709+#else
16710+ pax_exit_kernel
16711+#endif
16712 SWAPGS_UNSAFE_STACK
16713+ RESTORE_ALL 8
16714+ /* Clear the NMI executing stack variable */
16715+ movq $0, 10*8(%rsp)
16716+ jmp irq_return
16717 nmi_restore:
16718+ pax_exit_kernel
16719 RESTORE_ALL 8
16720+ pax_force_retaddr_bts
16721 /* Clear the NMI executing stack variable */
16722 movq $0, 10*8(%rsp)
16723 jmp irq_return
16724 CFI_ENDPROC
16725-END(nmi)
16726+ENDPROC(nmi)
16727
16728 /*
16729 * If an NMI hit an iret because of an exception or breakpoint,
16730@@ -1700,7 +2112,7 @@ ENTRY(ignore_sysret)
16731 mov $-ENOSYS,%eax
16732 sysret
16733 CFI_ENDPROC
16734-END(ignore_sysret)
16735+ENDPROC(ignore_sysret)
16736
16737 /*
16738 * End of kprobes section
16739diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16740index c9a281f..ce2f317 100644
16741--- a/arch/x86/kernel/ftrace.c
16742+++ b/arch/x86/kernel/ftrace.c
16743@@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
16744 static const void *mod_code_newcode; /* holds the text to write to the IP */
16745
16746 static unsigned nmi_wait_count;
16747-static atomic_t nmi_update_count = ATOMIC_INIT(0);
16748+static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
16749
16750 int ftrace_arch_read_dyn_info(char *buf, int size)
16751 {
16752@@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
16753
16754 r = snprintf(buf, size, "%u %u",
16755 nmi_wait_count,
16756- atomic_read(&nmi_update_count));
16757+ atomic_read_unchecked(&nmi_update_count));
16758 return r;
16759 }
16760
16761@@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
16762
16763 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
16764 smp_rmb();
16765+ pax_open_kernel();
16766 ftrace_mod_code();
16767- atomic_inc(&nmi_update_count);
16768+ pax_close_kernel();
16769+ atomic_inc_unchecked(&nmi_update_count);
16770 }
16771 /* Must have previous changes seen before executions */
16772 smp_mb();
16773@@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
16774 {
16775 unsigned char replaced[MCOUNT_INSN_SIZE];
16776
16777+ ip = ktla_ktva(ip);
16778+
16779 /*
16780 * Note: Due to modules and __init, code can
16781 * disappear and change, we need to protect against faulting
16782@@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16783 unsigned char old[MCOUNT_INSN_SIZE], *new;
16784 int ret;
16785
16786- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16787+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16788 new = ftrace_call_replace(ip, (unsigned long)func);
16789 ret = ftrace_modify_code(ip, old, new);
16790
16791@@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16792 {
16793 unsigned char code[MCOUNT_INSN_SIZE];
16794
16795+ ip = ktla_ktva(ip);
16796+
16797 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16798 return -EFAULT;
16799
16800diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16801index 51ff186..9e77418 100644
16802--- a/arch/x86/kernel/head32.c
16803+++ b/arch/x86/kernel/head32.c
16804@@ -19,6 +19,7 @@
16805 #include <asm/io_apic.h>
16806 #include <asm/bios_ebda.h>
16807 #include <asm/tlbflush.h>
16808+#include <asm/boot.h>
16809
16810 static void __init i386_default_early_setup(void)
16811 {
16812@@ -31,8 +32,7 @@ static void __init i386_default_early_setup(void)
16813
16814 void __init i386_start_kernel(void)
16815 {
16816- memblock_reserve(__pa_symbol(&_text),
16817- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16818+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16819
16820 #ifdef CONFIG_BLK_DEV_INITRD
16821 /* Reserve INITRD */
16822diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16823index ce0be7c..c41476e 100644
16824--- a/arch/x86/kernel/head_32.S
16825+++ b/arch/x86/kernel/head_32.S
16826@@ -25,6 +25,12 @@
16827 /* Physical address */
16828 #define pa(X) ((X) - __PAGE_OFFSET)
16829
16830+#ifdef CONFIG_PAX_KERNEXEC
16831+#define ta(X) (X)
16832+#else
16833+#define ta(X) ((X) - __PAGE_OFFSET)
16834+#endif
16835+
16836 /*
16837 * References to members of the new_cpu_data structure.
16838 */
16839@@ -54,11 +60,7 @@
16840 * and small than max_low_pfn, otherwise will waste some page table entries
16841 */
16842
16843-#if PTRS_PER_PMD > 1
16844-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16845-#else
16846-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16847-#endif
16848+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16849
16850 /* Number of possible pages in the lowmem region */
16851 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16852@@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16853 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16854
16855 /*
16856+ * Real beginning of normal "text" segment
16857+ */
16858+ENTRY(stext)
16859+ENTRY(_stext)
16860+
16861+/*
16862 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16863 * %esi points to the real-mode code as a 32-bit pointer.
16864 * CS and DS must be 4 GB flat segments, but we don't depend on
16865@@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16866 * can.
16867 */
16868 __HEAD
16869+
16870+#ifdef CONFIG_PAX_KERNEXEC
16871+ jmp startup_32
16872+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16873+.fill PAGE_SIZE-5,1,0xcc
16874+#endif
16875+
16876 ENTRY(startup_32)
16877 movl pa(stack_start),%ecx
16878
16879@@ -105,6 +120,57 @@ ENTRY(startup_32)
16880 2:
16881 leal -__PAGE_OFFSET(%ecx),%esp
16882
16883+#ifdef CONFIG_SMP
16884+ movl $pa(cpu_gdt_table),%edi
16885+ movl $__per_cpu_load,%eax
16886+ movw %ax,__KERNEL_PERCPU + 2(%edi)
16887+ rorl $16,%eax
16888+ movb %al,__KERNEL_PERCPU + 4(%edi)
16889+ movb %ah,__KERNEL_PERCPU + 7(%edi)
16890+ movl $__per_cpu_end - 1,%eax
16891+ subl $__per_cpu_start,%eax
16892+ movw %ax,__KERNEL_PERCPU + 0(%edi)
16893+#endif
16894+
16895+#ifdef CONFIG_PAX_MEMORY_UDEREF
16896+ movl $NR_CPUS,%ecx
16897+ movl $pa(cpu_gdt_table),%edi
16898+1:
16899+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16900+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16901+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16902+ addl $PAGE_SIZE_asm,%edi
16903+ loop 1b
16904+#endif
16905+
16906+#ifdef CONFIG_PAX_KERNEXEC
16907+ movl $pa(boot_gdt),%edi
16908+ movl $__LOAD_PHYSICAL_ADDR,%eax
16909+ movw %ax,__BOOT_CS + 2(%edi)
16910+ rorl $16,%eax
16911+ movb %al,__BOOT_CS + 4(%edi)
16912+ movb %ah,__BOOT_CS + 7(%edi)
16913+ rorl $16,%eax
16914+
16915+ ljmp $(__BOOT_CS),$1f
16916+1:
16917+
16918+ movl $NR_CPUS,%ecx
16919+ movl $pa(cpu_gdt_table),%edi
16920+ addl $__PAGE_OFFSET,%eax
16921+1:
16922+ movw %ax,__KERNEL_CS + 2(%edi)
16923+ movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16924+ rorl $16,%eax
16925+ movb %al,__KERNEL_CS + 4(%edi)
16926+ movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16927+ movb %ah,__KERNEL_CS + 7(%edi)
16928+ movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16929+ rorl $16,%eax
16930+ addl $PAGE_SIZE_asm,%edi
16931+ loop 1b
16932+#endif
16933+
16934 /*
16935 * Clear BSS first so that there are no surprises...
16936 */
16937@@ -195,8 +261,11 @@ ENTRY(startup_32)
16938 movl %eax, pa(max_pfn_mapped)
16939
16940 /* Do early initialization of the fixmap area */
16941- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16942- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16943+#ifdef CONFIG_COMPAT_VDSO
16944+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16945+#else
16946+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16947+#endif
16948 #else /* Not PAE */
16949
16950 page_pde_offset = (__PAGE_OFFSET >> 20);
16951@@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16952 movl %eax, pa(max_pfn_mapped)
16953
16954 /* Do early initialization of the fixmap area */
16955- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16956- movl %eax,pa(initial_page_table+0xffc)
16957+#ifdef CONFIG_COMPAT_VDSO
16958+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16959+#else
16960+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16961+#endif
16962 #endif
16963
16964 #ifdef CONFIG_PARAVIRT
16965@@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16966 cmpl $num_subarch_entries, %eax
16967 jae bad_subarch
16968
16969- movl pa(subarch_entries)(,%eax,4), %eax
16970- subl $__PAGE_OFFSET, %eax
16971- jmp *%eax
16972+ jmp *pa(subarch_entries)(,%eax,4)
16973
16974 bad_subarch:
16975 WEAK(lguest_entry)
16976@@ -255,10 +325,10 @@ WEAK(xen_entry)
16977 __INITDATA
16978
16979 subarch_entries:
16980- .long default_entry /* normal x86/PC */
16981- .long lguest_entry /* lguest hypervisor */
16982- .long xen_entry /* Xen hypervisor */
16983- .long default_entry /* Moorestown MID */
16984+ .long ta(default_entry) /* normal x86/PC */
16985+ .long ta(lguest_entry) /* lguest hypervisor */
16986+ .long ta(xen_entry) /* Xen hypervisor */
16987+ .long ta(default_entry) /* Moorestown MID */
16988 num_subarch_entries = (. - subarch_entries) / 4
16989 .previous
16990 #else
16991@@ -312,6 +382,7 @@ default_entry:
16992 orl %edx,%eax
16993 movl %eax,%cr4
16994
16995+#ifdef CONFIG_X86_PAE
16996 testb $X86_CR4_PAE, %al # check if PAE is enabled
16997 jz 6f
16998
16999@@ -340,6 +411,9 @@ default_entry:
17000 /* Make changes effective */
17001 wrmsr
17002
17003+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17004+#endif
17005+
17006 6:
17007
17008 /*
17009@@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
17010 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17011 movl %eax,%ss # after changing gdt.
17012
17013- movl $(__USER_DS),%eax # DS/ES contains default USER segment
17014+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17015 movl %eax,%ds
17016 movl %eax,%es
17017
17018@@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
17019 */
17020 cmpb $0,ready
17021 jne 1f
17022- movl $gdt_page,%eax
17023+ movl $cpu_gdt_table,%eax
17024 movl $stack_canary,%ecx
17025+#ifdef CONFIG_SMP
17026+ addl $__per_cpu_load,%ecx
17027+#endif
17028 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17029 shrl $16, %ecx
17030 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17031 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
17032 1:
17033-#endif
17034 movl $(__KERNEL_STACK_CANARY),%eax
17035+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17036+ movl $(__USER_DS),%eax
17037+#else
17038+ xorl %eax,%eax
17039+#endif
17040 movl %eax,%gs
17041
17042 xorl %eax,%eax # Clear LDT
17043@@ -558,22 +639,22 @@ early_page_fault:
17044 jmp early_fault
17045
17046 early_fault:
17047- cld
17048 #ifdef CONFIG_PRINTK
17049+ cmpl $1,%ss:early_recursion_flag
17050+ je hlt_loop
17051+ incl %ss:early_recursion_flag
17052+ cld
17053 pusha
17054 movl $(__KERNEL_DS),%eax
17055 movl %eax,%ds
17056 movl %eax,%es
17057- cmpl $2,early_recursion_flag
17058- je hlt_loop
17059- incl early_recursion_flag
17060 movl %cr2,%eax
17061 pushl %eax
17062 pushl %edx /* trapno */
17063 pushl $fault_msg
17064 call printk
17065+; call dump_stack
17066 #endif
17067- call dump_stack
17068 hlt_loop:
17069 hlt
17070 jmp hlt_loop
17071@@ -581,8 +662,11 @@ hlt_loop:
17072 /* This is the default interrupt "handler" :-) */
17073 ALIGN
17074 ignore_int:
17075- cld
17076 #ifdef CONFIG_PRINTK
17077+ cmpl $2,%ss:early_recursion_flag
17078+ je hlt_loop
17079+ incl %ss:early_recursion_flag
17080+ cld
17081 pushl %eax
17082 pushl %ecx
17083 pushl %edx
17084@@ -591,9 +675,6 @@ ignore_int:
17085 movl $(__KERNEL_DS),%eax
17086 movl %eax,%ds
17087 movl %eax,%es
17088- cmpl $2,early_recursion_flag
17089- je hlt_loop
17090- incl early_recursion_flag
17091 pushl 16(%esp)
17092 pushl 24(%esp)
17093 pushl 32(%esp)
17094@@ -622,29 +703,43 @@ ENTRY(initial_code)
17095 /*
17096 * BSS section
17097 */
17098-__PAGE_ALIGNED_BSS
17099- .align PAGE_SIZE
17100 #ifdef CONFIG_X86_PAE
17101+.section .initial_pg_pmd,"a",@progbits
17102 initial_pg_pmd:
17103 .fill 1024*KPMDS,4,0
17104 #else
17105+.section .initial_page_table,"a",@progbits
17106 ENTRY(initial_page_table)
17107 .fill 1024,4,0
17108 #endif
17109+.section .initial_pg_fixmap,"a",@progbits
17110 initial_pg_fixmap:
17111 .fill 1024,4,0
17112+.section .empty_zero_page,"a",@progbits
17113 ENTRY(empty_zero_page)
17114 .fill 4096,1,0
17115+.section .swapper_pg_dir,"a",@progbits
17116 ENTRY(swapper_pg_dir)
17117+#ifdef CONFIG_X86_PAE
17118+ .fill 4,8,0
17119+#else
17120 .fill 1024,4,0
17121+#endif
17122+
17123+/*
17124+ * The IDT has to be page-aligned to simplify the Pentium
17125+ * F0 0F bug workaround.. We have a special link segment
17126+ * for this.
17127+ */
17128+.section .idt,"a",@progbits
17129+ENTRY(idt_table)
17130+ .fill 256,8,0
17131
17132 /*
17133 * This starts the data section.
17134 */
17135 #ifdef CONFIG_X86_PAE
17136-__PAGE_ALIGNED_DATA
17137- /* Page-aligned for the benefit of paravirt? */
17138- .align PAGE_SIZE
17139+.section .initial_page_table,"a",@progbits
17140 ENTRY(initial_page_table)
17141 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17142 # if KPMDS == 3
17143@@ -663,18 +758,27 @@ ENTRY(initial_page_table)
17144 # error "Kernel PMDs should be 1, 2 or 3"
17145 # endif
17146 .align PAGE_SIZE /* needs to be page-sized too */
17147+
17148+#ifdef CONFIG_PAX_PER_CPU_PGD
17149+ENTRY(cpu_pgd)
17150+ .rept NR_CPUS
17151+ .fill 4,8,0
17152+ .endr
17153+#endif
17154+
17155 #endif
17156
17157 .data
17158 .balign 4
17159 ENTRY(stack_start)
17160- .long init_thread_union+THREAD_SIZE
17161+ .long init_thread_union+THREAD_SIZE-8
17162
17163+ready: .byte 0
17164+
17165+.section .rodata,"a",@progbits
17166 early_recursion_flag:
17167 .long 0
17168
17169-ready: .byte 0
17170-
17171 int_msg:
17172 .asciz "Unknown interrupt or fault at: %p %p %p\n"
17173
17174@@ -707,7 +811,7 @@ fault_msg:
17175 .word 0 # 32 bit align gdt_desc.address
17176 boot_gdt_descr:
17177 .word __BOOT_DS+7
17178- .long boot_gdt - __PAGE_OFFSET
17179+ .long pa(boot_gdt)
17180
17181 .word 0 # 32-bit align idt_desc.address
17182 idt_descr:
17183@@ -718,7 +822,7 @@ idt_descr:
17184 .word 0 # 32 bit align gdt_desc.address
17185 ENTRY(early_gdt_descr)
17186 .word GDT_ENTRIES*8-1
17187- .long gdt_page /* Overwritten for secondary CPUs */
17188+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
17189
17190 /*
17191 * The boot_gdt must mirror the equivalent in setup.S and is
17192@@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
17193 .align L1_CACHE_BYTES
17194 ENTRY(boot_gdt)
17195 .fill GDT_ENTRY_BOOT_CS,8,0
17196- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17197- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17198+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17199+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17200+
17201+ .align PAGE_SIZE_asm
17202+ENTRY(cpu_gdt_table)
17203+ .rept NR_CPUS
17204+ .quad 0x0000000000000000 /* NULL descriptor */
17205+ .quad 0x0000000000000000 /* 0x0b reserved */
17206+ .quad 0x0000000000000000 /* 0x13 reserved */
17207+ .quad 0x0000000000000000 /* 0x1b reserved */
17208+
17209+#ifdef CONFIG_PAX_KERNEXEC
17210+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17211+#else
17212+ .quad 0x0000000000000000 /* 0x20 unused */
17213+#endif
17214+
17215+ .quad 0x0000000000000000 /* 0x28 unused */
17216+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17217+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17218+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17219+ .quad 0x0000000000000000 /* 0x4b reserved */
17220+ .quad 0x0000000000000000 /* 0x53 reserved */
17221+ .quad 0x0000000000000000 /* 0x5b reserved */
17222+
17223+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17224+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17225+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17226+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17227+
17228+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17229+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17230+
17231+ /*
17232+ * Segments used for calling PnP BIOS have byte granularity.
17233+ * The code segments and data segments have fixed 64k limits,
17234+ * the transfer segment sizes are set at run time.
17235+ */
17236+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
17237+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
17238+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
17239+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
17240+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
17241+
17242+ /*
17243+ * The APM segments have byte granularity and their bases
17244+ * are set at run time. All have 64k limits.
17245+ */
17246+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17247+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17248+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
17249+
17250+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17251+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17252+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17253+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17254+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17255+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17256+
17257+ /* Be sure this is zeroed to avoid false validations in Xen */
17258+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17259+ .endr
17260diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17261index 40f4eb3..6d24d9d 100644
17262--- a/arch/x86/kernel/head_64.S
17263+++ b/arch/x86/kernel/head_64.S
17264@@ -19,6 +19,8 @@
17265 #include <asm/cache.h>
17266 #include <asm/processor-flags.h>
17267 #include <asm/percpu.h>
17268+#include <asm/cpufeature.h>
17269+#include <asm/alternative-asm.h>
17270
17271 #ifdef CONFIG_PARAVIRT
17272 #include <asm/asm-offsets.h>
17273@@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17274 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17275 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17276 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17277+L4_VMALLOC_START = pgd_index(VMALLOC_START)
17278+L3_VMALLOC_START = pud_index(VMALLOC_START)
17279+L4_VMALLOC_END = pgd_index(VMALLOC_END)
17280+L3_VMALLOC_END = pud_index(VMALLOC_END)
17281+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17282+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17283
17284 .text
17285 __HEAD
17286@@ -85,35 +93,23 @@ startup_64:
17287 */
17288 addq %rbp, init_level4_pgt + 0(%rip)
17289 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17290+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17291+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17292+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17293 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17294
17295 addq %rbp, level3_ident_pgt + 0(%rip)
17296+#ifndef CONFIG_XEN
17297+ addq %rbp, level3_ident_pgt + 8(%rip)
17298+#endif
17299
17300- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17301- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17302+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17303+
17304+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17305+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17306
17307 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17308-
17309- /* Add an Identity mapping if I am above 1G */
17310- leaq _text(%rip), %rdi
17311- andq $PMD_PAGE_MASK, %rdi
17312-
17313- movq %rdi, %rax
17314- shrq $PUD_SHIFT, %rax
17315- andq $(PTRS_PER_PUD - 1), %rax
17316- jz ident_complete
17317-
17318- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17319- leaq level3_ident_pgt(%rip), %rbx
17320- movq %rdx, 0(%rbx, %rax, 8)
17321-
17322- movq %rdi, %rax
17323- shrq $PMD_SHIFT, %rax
17324- andq $(PTRS_PER_PMD - 1), %rax
17325- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17326- leaq level2_spare_pgt(%rip), %rbx
17327- movq %rdx, 0(%rbx, %rax, 8)
17328-ident_complete:
17329+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17330
17331 /*
17332 * Fixup the kernel text+data virtual addresses. Note that
17333@@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
17334 * after the boot processor executes this code.
17335 */
17336
17337- /* Enable PAE mode and PGE */
17338- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17339+ /* Enable PAE mode and PSE/PGE */
17340+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17341 movq %rax, %cr4
17342
17343 /* Setup early boot stage 4 level pagetables. */
17344@@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
17345 movl $MSR_EFER, %ecx
17346 rdmsr
17347 btsl $_EFER_SCE, %eax /* Enable System Call */
17348- btl $20,%edi /* No Execute supported? */
17349+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17350 jnc 1f
17351 btsl $_EFER_NX, %eax
17352+ leaq init_level4_pgt(%rip), %rdi
17353+#ifndef CONFIG_EFI
17354+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17355+#endif
17356+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17357+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17358+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17359+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17360 1: wrmsr /* Make changes effective */
17361
17362 /* Setup cr0 */
17363@@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
17364 * jump. In addition we need to ensure %cs is set so we make this
17365 * a far return.
17366 */
17367+ pax_set_fptr_mask
17368 movq initial_code(%rip),%rax
17369 pushq $0 # fake return address to stop unwinder
17370 pushq $__KERNEL_CS # set correct cs
17371@@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
17372 bad_address:
17373 jmp bad_address
17374
17375- .section ".init.text","ax"
17376+ __INIT
17377 #ifdef CONFIG_EARLY_PRINTK
17378 .globl early_idt_handlers
17379 early_idt_handlers:
17380@@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
17381 #endif /* EARLY_PRINTK */
17382 1: hlt
17383 jmp 1b
17384+ .previous
17385
17386 #ifdef CONFIG_EARLY_PRINTK
17387+ __INITDATA
17388 early_recursion_flag:
17389 .long 0
17390+ .previous
17391
17392+ .section .rodata,"a",@progbits
17393 early_idt_msg:
17394 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17395 early_idt_ripmsg:
17396 .asciz "RIP %s\n"
17397+ .previous
17398 #endif /* CONFIG_EARLY_PRINTK */
17399- .previous
17400
17401+ .section .rodata,"a",@progbits
17402 #define NEXT_PAGE(name) \
17403 .balign PAGE_SIZE; \
17404 ENTRY(name)
17405@@ -338,7 +348,6 @@ ENTRY(name)
17406 i = i + 1 ; \
17407 .endr
17408
17409- .data
17410 /*
17411 * This default setting generates an ident mapping at address 0x100000
17412 * and a mapping for the kernel that precisely maps virtual address
17413@@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
17414 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17415 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17416 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17417+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
17418+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17419+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
17420+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17421+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17422+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17423 .org init_level4_pgt + L4_START_KERNEL*8, 0
17424 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17425 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17426
17427+#ifdef CONFIG_PAX_PER_CPU_PGD
17428+NEXT_PAGE(cpu_pgd)
17429+ .rept NR_CPUS
17430+ .fill 512,8,0
17431+ .endr
17432+#endif
17433+
17434 NEXT_PAGE(level3_ident_pgt)
17435 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17436+#ifdef CONFIG_XEN
17437 .fill 511,8,0
17438+#else
17439+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17440+ .fill 510,8,0
17441+#endif
17442+
17443+NEXT_PAGE(level3_vmalloc_start_pgt)
17444+ .fill 512,8,0
17445+
17446+NEXT_PAGE(level3_vmalloc_end_pgt)
17447+ .fill 512,8,0
17448+
17449+NEXT_PAGE(level3_vmemmap_pgt)
17450+ .fill L3_VMEMMAP_START,8,0
17451+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17452
17453 NEXT_PAGE(level3_kernel_pgt)
17454 .fill L3_START_KERNEL,8,0
17455@@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
17456 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17457 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17458
17459+NEXT_PAGE(level2_vmemmap_pgt)
17460+ .fill 512,8,0
17461+
17462 NEXT_PAGE(level2_fixmap_pgt)
17463- .fill 506,8,0
17464- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17465- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17466- .fill 5,8,0
17467+ .fill 507,8,0
17468+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17469+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17470+ .fill 4,8,0
17471
17472-NEXT_PAGE(level1_fixmap_pgt)
17473+NEXT_PAGE(level1_vsyscall_pgt)
17474 .fill 512,8,0
17475
17476-NEXT_PAGE(level2_ident_pgt)
17477- /* Since I easily can, map the first 1G.
17478+ /* Since I easily can, map the first 2G.
17479 * Don't set NX because code runs from these pages.
17480 */
17481- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17482+NEXT_PAGE(level2_ident_pgt)
17483+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17484
17485 NEXT_PAGE(level2_kernel_pgt)
17486 /*
17487@@ -389,37 +429,59 @@ NEXT_PAGE(level2_kernel_pgt)
17488 * If you want to increase this then increase MODULES_VADDR
17489 * too.)
17490 */
17491- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17492- KERNEL_IMAGE_SIZE/PMD_SIZE)
17493-
17494-NEXT_PAGE(level2_spare_pgt)
17495- .fill 512, 8, 0
17496+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17497
17498 #undef PMDS
17499 #undef NEXT_PAGE
17500
17501- .data
17502+ .align PAGE_SIZE
17503+ENTRY(cpu_gdt_table)
17504+ .rept NR_CPUS
17505+ .quad 0x0000000000000000 /* NULL descriptor */
17506+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17507+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
17508+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
17509+ .quad 0x00cffb000000ffff /* __USER32_CS */
17510+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17511+ .quad 0x00affb000000ffff /* __USER_CS */
17512+
17513+#ifdef CONFIG_PAX_KERNEXEC
17514+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17515+#else
17516+ .quad 0x0 /* unused */
17517+#endif
17518+
17519+ .quad 0,0 /* TSS */
17520+ .quad 0,0 /* LDT */
17521+ .quad 0,0,0 /* three TLS descriptors */
17522+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
17523+ /* asm/segment.h:GDT_ENTRIES must match this */
17524+
17525+ /* zero the remaining page */
17526+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17527+ .endr
17528+
17529 .align 16
17530 .globl early_gdt_descr
17531 early_gdt_descr:
17532 .word GDT_ENTRIES*8-1
17533 early_gdt_descr_base:
17534- .quad INIT_PER_CPU_VAR(gdt_page)
17535+ .quad cpu_gdt_table
17536
17537 ENTRY(phys_base)
17538 /* This must match the first entry in level2_kernel_pgt */
17539 .quad 0x0000000000000000
17540
17541 #include "../../x86/xen/xen-head.S"
17542-
17543- .section .bss, "aw", @nobits
17544+
17545+ .section .rodata,"a",@progbits
17546 .align L1_CACHE_BYTES
17547 ENTRY(idt_table)
17548- .skip IDT_ENTRIES * 16
17549+ .fill 512,8,0
17550
17551 .align L1_CACHE_BYTES
17552 ENTRY(nmi_idt_table)
17553- .skip IDT_ENTRIES * 16
17554+ .fill 512,8,0
17555
17556 __PAGE_ALIGNED_BSS
17557 .align PAGE_SIZE
17558diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17559index 9c3bd4a..e1d9b35 100644
17560--- a/arch/x86/kernel/i386_ksyms_32.c
17561+++ b/arch/x86/kernel/i386_ksyms_32.c
17562@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17563 EXPORT_SYMBOL(cmpxchg8b_emu);
17564 #endif
17565
17566+EXPORT_SYMBOL_GPL(cpu_gdt_table);
17567+
17568 /* Networking helper routines. */
17569 EXPORT_SYMBOL(csum_partial_copy_generic);
17570+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17571+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17572
17573 EXPORT_SYMBOL(__get_user_1);
17574 EXPORT_SYMBOL(__get_user_2);
17575@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17576
17577 EXPORT_SYMBOL(csum_partial);
17578 EXPORT_SYMBOL(empty_zero_page);
17579+
17580+#ifdef CONFIG_PAX_KERNEXEC
17581+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17582+#endif
17583diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17584index 6104852..6114160 100644
17585--- a/arch/x86/kernel/i8259.c
17586+++ b/arch/x86/kernel/i8259.c
17587@@ -210,7 +210,7 @@ spurious_8259A_irq:
17588 "spurious 8259A interrupt: IRQ%d.\n", irq);
17589 spurious_irq_mask |= irqmask;
17590 }
17591- atomic_inc(&irq_err_count);
17592+ atomic_inc_unchecked(&irq_err_count);
17593 /*
17594 * Theoretically we do not have to handle this IRQ,
17595 * but in Linux this does not cause problems and is
17596diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
17597index 43e9ccf..44ccf6f 100644
17598--- a/arch/x86/kernel/init_task.c
17599+++ b/arch/x86/kernel/init_task.c
17600@@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
17601 * way process stacks are handled. This is done by having a special
17602 * "init_task" linker map entry..
17603 */
17604-union thread_union init_thread_union __init_task_data =
17605- { INIT_THREAD_INFO(init_task) };
17606+union thread_union init_thread_union __init_task_data;
17607
17608 /*
17609 * Initial task structure.
17610@@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
17611 * section. Since TSS's are completely CPU-local, we want them
17612 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
17613 */
17614-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
17615-
17616+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
17617+EXPORT_SYMBOL(init_tss);
17618diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17619index 8c96897..be66bfa 100644
17620--- a/arch/x86/kernel/ioport.c
17621+++ b/arch/x86/kernel/ioport.c
17622@@ -6,6 +6,7 @@
17623 #include <linux/sched.h>
17624 #include <linux/kernel.h>
17625 #include <linux/capability.h>
17626+#include <linux/security.h>
17627 #include <linux/errno.h>
17628 #include <linux/types.h>
17629 #include <linux/ioport.h>
17630@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17631
17632 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17633 return -EINVAL;
17634+#ifdef CONFIG_GRKERNSEC_IO
17635+ if (turn_on && grsec_disable_privio) {
17636+ gr_handle_ioperm();
17637+ return -EPERM;
17638+ }
17639+#endif
17640 if (turn_on && !capable(CAP_SYS_RAWIO))
17641 return -EPERM;
17642
17643@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17644 * because the ->io_bitmap_max value must match the bitmap
17645 * contents:
17646 */
17647- tss = &per_cpu(init_tss, get_cpu());
17648+ tss = init_tss + get_cpu();
17649
17650 if (turn_on)
17651 bitmap_clear(t->io_bitmap_ptr, from, num);
17652@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17653 return -EINVAL;
17654 /* Trying to gain more privileges? */
17655 if (level > old) {
17656+#ifdef CONFIG_GRKERNSEC_IO
17657+ if (grsec_disable_privio) {
17658+ gr_handle_iopl();
17659+ return -EPERM;
17660+ }
17661+#endif
17662 if (!capable(CAP_SYS_RAWIO))
17663 return -EPERM;
17664 }
17665diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17666index 7943e0c..dd32c5c 100644
17667--- a/arch/x86/kernel/irq.c
17668+++ b/arch/x86/kernel/irq.c
17669@@ -18,7 +18,7 @@
17670 #include <asm/mce.h>
17671 #include <asm/hw_irq.h>
17672
17673-atomic_t irq_err_count;
17674+atomic_unchecked_t irq_err_count;
17675
17676 /* Function pointer for generic interrupt vector handling */
17677 void (*x86_platform_ipi_callback)(void) = NULL;
17678@@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17679 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17680 seq_printf(p, " Machine check polls\n");
17681 #endif
17682- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17683+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17684 #if defined(CONFIG_X86_IO_APIC)
17685- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17686+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17687 #endif
17688 return 0;
17689 }
17690@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17691
17692 u64 arch_irq_stat(void)
17693 {
17694- u64 sum = atomic_read(&irq_err_count);
17695+ u64 sum = atomic_read_unchecked(&irq_err_count);
17696
17697 #ifdef CONFIG_X86_IO_APIC
17698- sum += atomic_read(&irq_mis_count);
17699+ sum += atomic_read_unchecked(&irq_mis_count);
17700 #endif
17701 return sum;
17702 }
17703diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17704index 40fc861..9b8739b 100644
17705--- a/arch/x86/kernel/irq_32.c
17706+++ b/arch/x86/kernel/irq_32.c
17707@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17708 __asm__ __volatile__("andl %%esp,%0" :
17709 "=r" (sp) : "0" (THREAD_SIZE - 1));
17710
17711- return sp < (sizeof(struct thread_info) + STACK_WARN);
17712+ return sp < STACK_WARN;
17713 }
17714
17715 static void print_stack_overflow(void)
17716@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17717 * per-CPU IRQ handling contexts (thread information and stack)
17718 */
17719 union irq_ctx {
17720- struct thread_info tinfo;
17721- u32 stack[THREAD_SIZE/sizeof(u32)];
17722+ unsigned long previous_esp;
17723+ u32 stack[THREAD_SIZE/sizeof(u32)];
17724 } __attribute__((aligned(THREAD_SIZE)));
17725
17726 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17727@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17728 static inline int
17729 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17730 {
17731- union irq_ctx *curctx, *irqctx;
17732+ union irq_ctx *irqctx;
17733 u32 *isp, arg1, arg2;
17734
17735- curctx = (union irq_ctx *) current_thread_info();
17736 irqctx = __this_cpu_read(hardirq_ctx);
17737
17738 /*
17739@@ -92,21 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17740 * handler) we can't do that and just have to keep using the
17741 * current stack (which is the irq stack already after all)
17742 */
17743- if (unlikely(curctx == irqctx))
17744+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17745 return 0;
17746
17747 /* build the stack frame on the IRQ stack */
17748- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17749- irqctx->tinfo.task = curctx->tinfo.task;
17750- irqctx->tinfo.previous_esp = current_stack_pointer;
17751+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17752+ irqctx->previous_esp = current_stack_pointer;
17753
17754- /*
17755- * Copy the softirq bits in preempt_count so that the
17756- * softirq checks work in the hardirq context.
17757- */
17758- irqctx->tinfo.preempt_count =
17759- (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
17760- (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
17761+#ifdef CONFIG_PAX_MEMORY_UDEREF
17762+ __set_fs(MAKE_MM_SEG(0));
17763+#endif
17764
17765 if (unlikely(overflow))
17766 call_on_stack(print_stack_overflow, isp);
17767@@ -118,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17768 : "0" (irq), "1" (desc), "2" (isp),
17769 "D" (desc->handle_irq)
17770 : "memory", "cc", "ecx");
17771+
17772+#ifdef CONFIG_PAX_MEMORY_UDEREF
17773+ __set_fs(current_thread_info()->addr_limit);
17774+#endif
17775+
17776 return 1;
17777 }
17778
17779@@ -126,29 +125,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17780 */
17781 void __cpuinit irq_ctx_init(int cpu)
17782 {
17783- union irq_ctx *irqctx;
17784-
17785 if (per_cpu(hardirq_ctx, cpu))
17786 return;
17787
17788- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17789- THREAD_FLAGS,
17790- THREAD_ORDER));
17791- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17792- irqctx->tinfo.cpu = cpu;
17793- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17794- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17795-
17796- per_cpu(hardirq_ctx, cpu) = irqctx;
17797-
17798- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17799- THREAD_FLAGS,
17800- THREAD_ORDER));
17801- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17802- irqctx->tinfo.cpu = cpu;
17803- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17804-
17805- per_cpu(softirq_ctx, cpu) = irqctx;
17806+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17807+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17808
17809 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17810 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17811@@ -157,7 +138,6 @@ void __cpuinit irq_ctx_init(int cpu)
17812 asmlinkage void do_softirq(void)
17813 {
17814 unsigned long flags;
17815- struct thread_info *curctx;
17816 union irq_ctx *irqctx;
17817 u32 *isp;
17818
17819@@ -167,15 +147,22 @@ asmlinkage void do_softirq(void)
17820 local_irq_save(flags);
17821
17822 if (local_softirq_pending()) {
17823- curctx = current_thread_info();
17824 irqctx = __this_cpu_read(softirq_ctx);
17825- irqctx->tinfo.task = curctx->task;
17826- irqctx->tinfo.previous_esp = current_stack_pointer;
17827+ irqctx->previous_esp = current_stack_pointer;
17828
17829 /* build the stack frame on the softirq stack */
17830- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17831+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17832+
17833+#ifdef CONFIG_PAX_MEMORY_UDEREF
17834+ __set_fs(MAKE_MM_SEG(0));
17835+#endif
17836
17837 call_on_stack(__do_softirq, isp);
17838+
17839+#ifdef CONFIG_PAX_MEMORY_UDEREF
17840+ __set_fs(current_thread_info()->addr_limit);
17841+#endif
17842+
17843 /*
17844 * Shouldn't happen, we returned above if in_interrupt():
17845 */
17846diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17847index d04d3ec..ea4b374 100644
17848--- a/arch/x86/kernel/irq_64.c
17849+++ b/arch/x86/kernel/irq_64.c
17850@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17851 u64 estack_top, estack_bottom;
17852 u64 curbase = (u64)task_stack_page(current);
17853
17854- if (user_mode_vm(regs))
17855+ if (user_mode(regs))
17856 return;
17857
17858 if (regs->sp >= curbase + sizeof(struct thread_info) +
17859diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17860index 90fcf62..e682cdd 100644
17861--- a/arch/x86/kernel/kdebugfs.c
17862+++ b/arch/x86/kernel/kdebugfs.c
17863@@ -28,6 +28,8 @@ struct setup_data_node {
17864 };
17865
17866 static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17867+ size_t count, loff_t *ppos) __size_overflow(3);
17868+static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17869 size_t count, loff_t *ppos)
17870 {
17871 struct setup_data_node *node = file->private_data;
17872diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17873index 2f45c4c..d95504f 100644
17874--- a/arch/x86/kernel/kgdb.c
17875+++ b/arch/x86/kernel/kgdb.c
17876@@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17877 #ifdef CONFIG_X86_32
17878 switch (regno) {
17879 case GDB_SS:
17880- if (!user_mode_vm(regs))
17881+ if (!user_mode(regs))
17882 *(unsigned long *)mem = __KERNEL_DS;
17883 break;
17884 case GDB_SP:
17885- if (!user_mode_vm(regs))
17886+ if (!user_mode(regs))
17887 *(unsigned long *)mem = kernel_stack_pointer(regs);
17888 break;
17889 case GDB_GS:
17890@@ -475,12 +475,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17891 case 'k':
17892 /* clear the trace bit */
17893 linux_regs->flags &= ~X86_EFLAGS_TF;
17894- atomic_set(&kgdb_cpu_doing_single_step, -1);
17895+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17896
17897 /* set the trace bit if we're stepping */
17898 if (remcomInBuffer[0] == 's') {
17899 linux_regs->flags |= X86_EFLAGS_TF;
17900- atomic_set(&kgdb_cpu_doing_single_step,
17901+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17902 raw_smp_processor_id());
17903 }
17904
17905@@ -545,7 +545,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17906
17907 switch (cmd) {
17908 case DIE_DEBUG:
17909- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17910+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17911 if (user_mode(regs))
17912 return single_step_cont(regs, args);
17913 break;
17914diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17915index 7da647d..56fe348 100644
17916--- a/arch/x86/kernel/kprobes.c
17917+++ b/arch/x86/kernel/kprobes.c
17918@@ -118,8 +118,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17919 } __attribute__((packed)) *insn;
17920
17921 insn = (struct __arch_relative_insn *)from;
17922+
17923+ pax_open_kernel();
17924 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17925 insn->op = op;
17926+ pax_close_kernel();
17927 }
17928
17929 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17930@@ -156,7 +159,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
17931 kprobe_opcode_t opcode;
17932 kprobe_opcode_t *orig_opcodes = opcodes;
17933
17934- if (search_exception_tables((unsigned long)opcodes))
17935+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17936 return 0; /* Page fault may occur on this address. */
17937
17938 retry:
17939@@ -317,7 +320,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17940 }
17941 }
17942 insn_get_length(&insn);
17943+ pax_open_kernel();
17944 memcpy(dest, insn.kaddr, insn.length);
17945+ pax_close_kernel();
17946
17947 #ifdef CONFIG_X86_64
17948 if (insn_rip_relative(&insn)) {
17949@@ -341,7 +346,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17950 (u8 *) dest;
17951 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17952 disp = (u8 *) dest + insn_offset_displacement(&insn);
17953+ pax_open_kernel();
17954 *(s32 *) disp = (s32) newdisp;
17955+ pax_close_kernel();
17956 }
17957 #endif
17958 return insn.length;
17959@@ -355,12 +362,12 @@ static void __kprobes arch_copy_kprobe(struct kprobe *p)
17960 */
17961 __copy_instruction(p->ainsn.insn, p->addr, 0);
17962
17963- if (can_boost(p->addr))
17964+ if (can_boost(ktla_ktva(p->addr)))
17965 p->ainsn.boostable = 0;
17966 else
17967 p->ainsn.boostable = -1;
17968
17969- p->opcode = *p->addr;
17970+ p->opcode = *(ktla_ktva(p->addr));
17971 }
17972
17973 int __kprobes arch_prepare_kprobe(struct kprobe *p)
17974@@ -477,7 +484,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17975 * nor set current_kprobe, because it doesn't use single
17976 * stepping.
17977 */
17978- regs->ip = (unsigned long)p->ainsn.insn;
17979+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17980 preempt_enable_no_resched();
17981 return;
17982 }
17983@@ -496,7 +503,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17984 if (p->opcode == BREAKPOINT_INSTRUCTION)
17985 regs->ip = (unsigned long)p->addr;
17986 else
17987- regs->ip = (unsigned long)p->ainsn.insn;
17988+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17989 }
17990
17991 /*
17992@@ -575,7 +582,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17993 setup_singlestep(p, regs, kcb, 0);
17994 return 1;
17995 }
17996- } else if (*addr != BREAKPOINT_INSTRUCTION) {
17997+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17998 /*
17999 * The breakpoint instruction was removed right
18000 * after we hit it. Another cpu has removed
18001@@ -683,6 +690,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18002 " movq %rax, 152(%rsp)\n"
18003 RESTORE_REGS_STRING
18004 " popfq\n"
18005+#ifdef KERNEXEC_PLUGIN
18006+ " btsq $63,(%rsp)\n"
18007+#endif
18008 #else
18009 " pushf\n"
18010 SAVE_REGS_STRING
18011@@ -820,7 +830,7 @@ static void __kprobes resume_execution(struct kprobe *p,
18012 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18013 {
18014 unsigned long *tos = stack_addr(regs);
18015- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18016+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18017 unsigned long orig_ip = (unsigned long)p->addr;
18018 kprobe_opcode_t *insn = p->ainsn.insn;
18019
18020@@ -1002,7 +1012,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
18021 struct die_args *args = data;
18022 int ret = NOTIFY_DONE;
18023
18024- if (args->regs && user_mode_vm(args->regs))
18025+ if (args->regs && user_mode(args->regs))
18026 return ret;
18027
18028 switch (val) {
18029@@ -1384,7 +1394,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
18030 * Verify if the address gap is in 2GB range, because this uses
18031 * a relative jump.
18032 */
18033- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
18034+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
18035 if (abs(rel) > 0x7fffffff)
18036 return -ERANGE;
18037
18038@@ -1405,11 +1415,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
18039 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
18040
18041 /* Set probe function call */
18042- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
18043+ synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
18044
18045 /* Set returning jmp instruction at the tail of out-of-line buffer */
18046 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
18047- (u8 *)op->kp.addr + op->optinsn.size);
18048+ (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
18049
18050 flush_icache_range((unsigned long) buf,
18051 (unsigned long) buf + TMPL_END_IDX +
18052@@ -1431,7 +1441,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
18053 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
18054
18055 /* Backup instructions which will be replaced by jump address */
18056- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
18057+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
18058 RELATIVE_ADDR_SIZE);
18059
18060 insn_buf[0] = RELATIVEJUMP_OPCODE;
18061diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18062index ea69726..604d066 100644
18063--- a/arch/x86/kernel/ldt.c
18064+++ b/arch/x86/kernel/ldt.c
18065@@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18066 if (reload) {
18067 #ifdef CONFIG_SMP
18068 preempt_disable();
18069- load_LDT(pc);
18070+ load_LDT_nolock(pc);
18071 if (!cpumask_equal(mm_cpumask(current->mm),
18072 cpumask_of(smp_processor_id())))
18073 smp_call_function(flush_ldt, current->mm, 1);
18074 preempt_enable();
18075 #else
18076- load_LDT(pc);
18077+ load_LDT_nolock(pc);
18078 #endif
18079 }
18080 if (oldsize) {
18081@@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18082 return err;
18083
18084 for (i = 0; i < old->size; i++)
18085- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18086+ write_ldt_entry(new->ldt, i, old->ldt + i);
18087 return 0;
18088 }
18089
18090@@ -116,6 +116,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18091 retval = copy_ldt(&mm->context, &old_mm->context);
18092 mutex_unlock(&old_mm->context.lock);
18093 }
18094+
18095+ if (tsk == current) {
18096+ mm->context.vdso = 0;
18097+
18098+#ifdef CONFIG_X86_32
18099+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18100+ mm->context.user_cs_base = 0UL;
18101+ mm->context.user_cs_limit = ~0UL;
18102+
18103+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18104+ cpus_clear(mm->context.cpu_user_cs_mask);
18105+#endif
18106+
18107+#endif
18108+#endif
18109+
18110+ }
18111+
18112 return retval;
18113 }
18114
18115@@ -230,6 +248,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18116 }
18117 }
18118
18119+#ifdef CONFIG_PAX_SEGMEXEC
18120+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18121+ error = -EINVAL;
18122+ goto out_unlock;
18123+ }
18124+#endif
18125+
18126 fill_ldt(&ldt, &ldt_info);
18127 if (oldmode)
18128 ldt.avl = 0;
18129diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18130index a3fa43b..8966f4c 100644
18131--- a/arch/x86/kernel/machine_kexec_32.c
18132+++ b/arch/x86/kernel/machine_kexec_32.c
18133@@ -27,7 +27,7 @@
18134 #include <asm/cacheflush.h>
18135 #include <asm/debugreg.h>
18136
18137-static void set_idt(void *newidt, __u16 limit)
18138+static void set_idt(struct desc_struct *newidt, __u16 limit)
18139 {
18140 struct desc_ptr curidt;
18141
18142@@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16 limit)
18143 }
18144
18145
18146-static void set_gdt(void *newgdt, __u16 limit)
18147+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18148 {
18149 struct desc_ptr curgdt;
18150
18151@@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
18152 }
18153
18154 control_page = page_address(image->control_code_page);
18155- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18156+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18157
18158 relocate_kernel_ptr = control_page;
18159 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18160diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18161index 3ca42d0..7cff8cc 100644
18162--- a/arch/x86/kernel/microcode_intel.c
18163+++ b/arch/x86/kernel/microcode_intel.c
18164@@ -436,13 +436,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18165
18166 static int get_ucode_user(void *to, const void *from, size_t n)
18167 {
18168- return copy_from_user(to, from, n);
18169+ return copy_from_user(to, (const void __force_user *)from, n);
18170 }
18171
18172 static enum ucode_state
18173 request_microcode_user(int cpu, const void __user *buf, size_t size)
18174 {
18175- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18176+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18177 }
18178
18179 static void microcode_fini_cpu(int cpu)
18180diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18181index 925179f..267ac7a 100644
18182--- a/arch/x86/kernel/module.c
18183+++ b/arch/x86/kernel/module.c
18184@@ -36,15 +36,60 @@
18185 #define DEBUGP(fmt...)
18186 #endif
18187
18188-void *module_alloc(unsigned long size)
18189+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18190 {
18191- if (PAGE_ALIGN(size) > MODULES_LEN)
18192+ if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18193 return NULL;
18194 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18195- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18196+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18197 -1, __builtin_return_address(0));
18198 }
18199
18200+void *module_alloc(unsigned long size)
18201+{
18202+
18203+#ifdef CONFIG_PAX_KERNEXEC
18204+ return __module_alloc(size, PAGE_KERNEL);
18205+#else
18206+ return __module_alloc(size, PAGE_KERNEL_EXEC);
18207+#endif
18208+
18209+}
18210+
18211+#ifdef CONFIG_PAX_KERNEXEC
18212+#ifdef CONFIG_X86_32
18213+void *module_alloc_exec(unsigned long size)
18214+{
18215+ struct vm_struct *area;
18216+
18217+ if (size == 0)
18218+ return NULL;
18219+
18220+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18221+ return area ? area->addr : NULL;
18222+}
18223+EXPORT_SYMBOL(module_alloc_exec);
18224+
18225+void module_free_exec(struct module *mod, void *module_region)
18226+{
18227+ vunmap(module_region);
18228+}
18229+EXPORT_SYMBOL(module_free_exec);
18230+#else
18231+void module_free_exec(struct module *mod, void *module_region)
18232+{
18233+ module_free(mod, module_region);
18234+}
18235+EXPORT_SYMBOL(module_free_exec);
18236+
18237+void *module_alloc_exec(unsigned long size)
18238+{
18239+ return __module_alloc(size, PAGE_KERNEL_RX);
18240+}
18241+EXPORT_SYMBOL(module_alloc_exec);
18242+#endif
18243+#endif
18244+
18245 #ifdef CONFIG_X86_32
18246 int apply_relocate(Elf32_Shdr *sechdrs,
18247 const char *strtab,
18248@@ -55,14 +100,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18249 unsigned int i;
18250 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18251 Elf32_Sym *sym;
18252- uint32_t *location;
18253+ uint32_t *plocation, location;
18254
18255 DEBUGP("Applying relocate section %u to %u\n", relsec,
18256 sechdrs[relsec].sh_info);
18257 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18258 /* This is where to make the change */
18259- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18260- + rel[i].r_offset;
18261+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18262+ location = (uint32_t)plocation;
18263+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18264+ plocation = ktla_ktva((void *)plocation);
18265 /* This is the symbol it is referring to. Note that all
18266 undefined symbols have been resolved. */
18267 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18268@@ -71,11 +118,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18269 switch (ELF32_R_TYPE(rel[i].r_info)) {
18270 case R_386_32:
18271 /* We add the value into the location given */
18272- *location += sym->st_value;
18273+ pax_open_kernel();
18274+ *plocation += sym->st_value;
18275+ pax_close_kernel();
18276 break;
18277 case R_386_PC32:
18278 /* Add the value, subtract its postition */
18279- *location += sym->st_value - (uint32_t)location;
18280+ pax_open_kernel();
18281+ *plocation += sym->st_value - location;
18282+ pax_close_kernel();
18283 break;
18284 default:
18285 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18286@@ -120,21 +171,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18287 case R_X86_64_NONE:
18288 break;
18289 case R_X86_64_64:
18290+ pax_open_kernel();
18291 *(u64 *)loc = val;
18292+ pax_close_kernel();
18293 break;
18294 case R_X86_64_32:
18295+ pax_open_kernel();
18296 *(u32 *)loc = val;
18297+ pax_close_kernel();
18298 if (val != *(u32 *)loc)
18299 goto overflow;
18300 break;
18301 case R_X86_64_32S:
18302+ pax_open_kernel();
18303 *(s32 *)loc = val;
18304+ pax_close_kernel();
18305 if ((s64)val != *(s32 *)loc)
18306 goto overflow;
18307 break;
18308 case R_X86_64_PC32:
18309 val -= (u64)loc;
18310+ pax_open_kernel();
18311 *(u32 *)loc = val;
18312+ pax_close_kernel();
18313+
18314 #if 0
18315 if ((s64)val != *(s32 *)loc)
18316 goto overflow;
18317diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18318index 47acaf3..ec48ab6 100644
18319--- a/arch/x86/kernel/nmi.c
18320+++ b/arch/x86/kernel/nmi.c
18321@@ -505,6 +505,17 @@ static inline void nmi_nesting_postprocess(void)
18322 dotraplinkage notrace __kprobes void
18323 do_nmi(struct pt_regs *regs, long error_code)
18324 {
18325+
18326+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18327+ if (!user_mode(regs)) {
18328+ unsigned long cs = regs->cs & 0xFFFF;
18329+ unsigned long ip = ktva_ktla(regs->ip);
18330+
18331+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18332+ regs->ip = ip;
18333+ }
18334+#endif
18335+
18336 nmi_nesting_preprocess(regs);
18337
18338 nmi_enter();
18339diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18340index 676b8c7..870ba04 100644
18341--- a/arch/x86/kernel/paravirt-spinlocks.c
18342+++ b/arch/x86/kernel/paravirt-spinlocks.c
18343@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18344 arch_spin_lock(lock);
18345 }
18346
18347-struct pv_lock_ops pv_lock_ops = {
18348+struct pv_lock_ops pv_lock_ops __read_only = {
18349 #ifdef CONFIG_SMP
18350 .spin_is_locked = __ticket_spin_is_locked,
18351 .spin_is_contended = __ticket_spin_is_contended,
18352diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18353index d90272e..6bb013b 100644
18354--- a/arch/x86/kernel/paravirt.c
18355+++ b/arch/x86/kernel/paravirt.c
18356@@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
18357 {
18358 return x;
18359 }
18360+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18361+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18362+#endif
18363
18364 void __init default_banner(void)
18365 {
18366@@ -145,15 +148,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18367 if (opfunc == NULL)
18368 /* If there's no function, patch it with a ud2a (BUG) */
18369 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18370- else if (opfunc == _paravirt_nop)
18371+ else if (opfunc == (void *)_paravirt_nop)
18372 /* If the operation is a nop, then nop the callsite */
18373 ret = paravirt_patch_nop();
18374
18375 /* identity functions just return their single argument */
18376- else if (opfunc == _paravirt_ident_32)
18377+ else if (opfunc == (void *)_paravirt_ident_32)
18378 ret = paravirt_patch_ident_32(insnbuf, len);
18379- else if (opfunc == _paravirt_ident_64)
18380+ else if (opfunc == (void *)_paravirt_ident_64)
18381 ret = paravirt_patch_ident_64(insnbuf, len);
18382+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18383+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18384+ ret = paravirt_patch_ident_64(insnbuf, len);
18385+#endif
18386
18387 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18388 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18389@@ -178,7 +185,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18390 if (insn_len > len || start == NULL)
18391 insn_len = len;
18392 else
18393- memcpy(insnbuf, start, insn_len);
18394+ memcpy(insnbuf, ktla_ktva(start), insn_len);
18395
18396 return insn_len;
18397 }
18398@@ -302,7 +309,7 @@ void arch_flush_lazy_mmu_mode(void)
18399 preempt_enable();
18400 }
18401
18402-struct pv_info pv_info = {
18403+struct pv_info pv_info __read_only = {
18404 .name = "bare hardware",
18405 .paravirt_enabled = 0,
18406 .kernel_rpl = 0,
18407@@ -313,16 +320,16 @@ struct pv_info pv_info = {
18408 #endif
18409 };
18410
18411-struct pv_init_ops pv_init_ops = {
18412+struct pv_init_ops pv_init_ops __read_only = {
18413 .patch = native_patch,
18414 };
18415
18416-struct pv_time_ops pv_time_ops = {
18417+struct pv_time_ops pv_time_ops __read_only = {
18418 .sched_clock = native_sched_clock,
18419 .steal_clock = native_steal_clock,
18420 };
18421
18422-struct pv_irq_ops pv_irq_ops = {
18423+struct pv_irq_ops pv_irq_ops __read_only = {
18424 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18425 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18426 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18427@@ -334,7 +341,7 @@ struct pv_irq_ops pv_irq_ops = {
18428 #endif
18429 };
18430
18431-struct pv_cpu_ops pv_cpu_ops = {
18432+struct pv_cpu_ops pv_cpu_ops __read_only = {
18433 .cpuid = native_cpuid,
18434 .get_debugreg = native_get_debugreg,
18435 .set_debugreg = native_set_debugreg,
18436@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18437 .end_context_switch = paravirt_nop,
18438 };
18439
18440-struct pv_apic_ops pv_apic_ops = {
18441+struct pv_apic_ops pv_apic_ops __read_only = {
18442 #ifdef CONFIG_X86_LOCAL_APIC
18443 .startup_ipi_hook = paravirt_nop,
18444 #endif
18445 };
18446
18447-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18448+#ifdef CONFIG_X86_32
18449+#ifdef CONFIG_X86_PAE
18450+/* 64-bit pagetable entries */
18451+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18452+#else
18453 /* 32-bit pagetable entries */
18454 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18455+#endif
18456 #else
18457 /* 64-bit pagetable entries */
18458 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18459 #endif
18460
18461-struct pv_mmu_ops pv_mmu_ops = {
18462+struct pv_mmu_ops pv_mmu_ops __read_only = {
18463
18464 .read_cr2 = native_read_cr2,
18465 .write_cr2 = native_write_cr2,
18466@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18467 .make_pud = PTE_IDENT,
18468
18469 .set_pgd = native_set_pgd,
18470+ .set_pgd_batched = native_set_pgd_batched,
18471 #endif
18472 #endif /* PAGETABLE_LEVELS >= 3 */
18473
18474@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18475 },
18476
18477 .set_fixmap = native_set_fixmap,
18478+
18479+#ifdef CONFIG_PAX_KERNEXEC
18480+ .pax_open_kernel = native_pax_open_kernel,
18481+ .pax_close_kernel = native_pax_close_kernel,
18482+#endif
18483+
18484 };
18485
18486 EXPORT_SYMBOL_GPL(pv_time_ops);
18487diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18488index 35ccf75..7a15747 100644
18489--- a/arch/x86/kernel/pci-iommu_table.c
18490+++ b/arch/x86/kernel/pci-iommu_table.c
18491@@ -2,7 +2,7 @@
18492 #include <asm/iommu_table.h>
18493 #include <linux/string.h>
18494 #include <linux/kallsyms.h>
18495-
18496+#include <linux/sched.h>
18497
18498 #define DEBUG 1
18499
18500diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18501index 15763af..da59ada 100644
18502--- a/arch/x86/kernel/process.c
18503+++ b/arch/x86/kernel/process.c
18504@@ -48,16 +48,33 @@ void free_thread_xstate(struct task_struct *tsk)
18505
18506 void free_thread_info(struct thread_info *ti)
18507 {
18508- free_thread_xstate(ti->task);
18509 free_pages((unsigned long)ti, THREAD_ORDER);
18510 }
18511
18512+static struct kmem_cache *task_struct_cachep;
18513+
18514 void arch_task_cache_init(void)
18515 {
18516- task_xstate_cachep =
18517- kmem_cache_create("task_xstate", xstate_size,
18518+ /* create a slab on which task_structs can be allocated */
18519+ task_struct_cachep =
18520+ kmem_cache_create("task_struct", sizeof(struct task_struct),
18521+ ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
18522+
18523+ task_xstate_cachep =
18524+ kmem_cache_create("task_xstate", xstate_size,
18525 __alignof__(union thread_xstate),
18526- SLAB_PANIC | SLAB_NOTRACK, NULL);
18527+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18528+}
18529+
18530+struct task_struct *alloc_task_struct_node(int node)
18531+{
18532+ return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
18533+}
18534+
18535+void free_task_struct(struct task_struct *task)
18536+{
18537+ free_thread_xstate(task);
18538+ kmem_cache_free(task_struct_cachep, task);
18539 }
18540
18541 /*
18542@@ -70,7 +87,7 @@ void exit_thread(void)
18543 unsigned long *bp = t->io_bitmap_ptr;
18544
18545 if (bp) {
18546- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18547+ struct tss_struct *tss = init_tss + get_cpu();
18548
18549 t->io_bitmap_ptr = NULL;
18550 clear_thread_flag(TIF_IO_BITMAP);
18551@@ -106,7 +123,7 @@ void show_regs_common(void)
18552
18553 printk(KERN_CONT "\n");
18554 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18555- current->pid, current->comm, print_tainted(),
18556+ task_pid_nr(current), current->comm, print_tainted(),
18557 init_utsname()->release,
18558 (int)strcspn(init_utsname()->version, " "),
18559 init_utsname()->version);
18560@@ -120,6 +137,9 @@ void flush_thread(void)
18561 {
18562 struct task_struct *tsk = current;
18563
18564+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18565+ loadsegment(gs, 0);
18566+#endif
18567 flush_ptrace_hw_breakpoint(tsk);
18568 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18569 /*
18570@@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18571 regs.di = (unsigned long) arg;
18572
18573 #ifdef CONFIG_X86_32
18574- regs.ds = __USER_DS;
18575- regs.es = __USER_DS;
18576+ regs.ds = __KERNEL_DS;
18577+ regs.es = __KERNEL_DS;
18578 regs.fs = __KERNEL_PERCPU;
18579- regs.gs = __KERNEL_STACK_CANARY;
18580+ savesegment(gs, regs.gs);
18581 #else
18582 regs.ss = __KERNEL_DS;
18583 #endif
18584@@ -411,7 +431,7 @@ bool set_pm_idle_to_default(void)
18585
18586 return ret;
18587 }
18588-void stop_this_cpu(void *dummy)
18589+__noreturn void stop_this_cpu(void *dummy)
18590 {
18591 local_irq_disable();
18592 /*
18593@@ -653,16 +673,37 @@ static int __init idle_setup(char *str)
18594 }
18595 early_param("idle", idle_setup);
18596
18597-unsigned long arch_align_stack(unsigned long sp)
18598+#ifdef CONFIG_PAX_RANDKSTACK
18599+void pax_randomize_kstack(struct pt_regs *regs)
18600 {
18601- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18602- sp -= get_random_int() % 8192;
18603- return sp & ~0xf;
18604-}
18605+ struct thread_struct *thread = &current->thread;
18606+ unsigned long time;
18607
18608-unsigned long arch_randomize_brk(struct mm_struct *mm)
18609-{
18610- unsigned long range_end = mm->brk + 0x02000000;
18611- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18612-}
18613+ if (!randomize_va_space)
18614+ return;
18615+
18616+ if (v8086_mode(regs))
18617+ return;
18618
18619+ rdtscl(time);
18620+
18621+ /* P4 seems to return a 0 LSB, ignore it */
18622+#ifdef CONFIG_MPENTIUM4
18623+ time &= 0x3EUL;
18624+ time <<= 2;
18625+#elif defined(CONFIG_X86_64)
18626+ time &= 0xFUL;
18627+ time <<= 4;
18628+#else
18629+ time &= 0x1FUL;
18630+ time <<= 3;
18631+#endif
18632+
18633+ thread->sp0 ^= time;
18634+ load_sp0(init_tss + smp_processor_id(), thread);
18635+
18636+#ifdef CONFIG_X86_64
18637+ percpu_write(kernel_stack, thread->sp0);
18638+#endif
18639+}
18640+#endif
18641diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18642index c08d1ff..6ae1c81 100644
18643--- a/arch/x86/kernel/process_32.c
18644+++ b/arch/x86/kernel/process_32.c
18645@@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18646 unsigned long thread_saved_pc(struct task_struct *tsk)
18647 {
18648 return ((unsigned long *)tsk->thread.sp)[3];
18649+//XXX return tsk->thread.eip;
18650 }
18651
18652 #ifndef CONFIG_SMP
18653@@ -132,15 +133,14 @@ void __show_regs(struct pt_regs *regs, int all)
18654 unsigned long sp;
18655 unsigned short ss, gs;
18656
18657- if (user_mode_vm(regs)) {
18658+ if (user_mode(regs)) {
18659 sp = regs->sp;
18660 ss = regs->ss & 0xffff;
18661- gs = get_user_gs(regs);
18662 } else {
18663 sp = kernel_stack_pointer(regs);
18664 savesegment(ss, ss);
18665- savesegment(gs, gs);
18666 }
18667+ gs = get_user_gs(regs);
18668
18669 show_regs_common();
18670
18671@@ -202,13 +202,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18672 struct task_struct *tsk;
18673 int err;
18674
18675- childregs = task_pt_regs(p);
18676+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18677 *childregs = *regs;
18678 childregs->ax = 0;
18679 childregs->sp = sp;
18680
18681 p->thread.sp = (unsigned long) childregs;
18682 p->thread.sp0 = (unsigned long) (childregs+1);
18683+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18684
18685 p->thread.ip = (unsigned long) ret_from_fork;
18686
18687@@ -299,7 +300,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18688 struct thread_struct *prev = &prev_p->thread,
18689 *next = &next_p->thread;
18690 int cpu = smp_processor_id();
18691- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18692+ struct tss_struct *tss = init_tss + cpu;
18693 fpu_switch_t fpu;
18694
18695 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18696@@ -323,6 +324,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18697 */
18698 lazy_save_gs(prev->gs);
18699
18700+#ifdef CONFIG_PAX_MEMORY_UDEREF
18701+ __set_fs(task_thread_info(next_p)->addr_limit);
18702+#endif
18703+
18704 /*
18705 * Load the per-thread Thread-Local Storage descriptor.
18706 */
18707@@ -353,6 +358,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18708 */
18709 arch_end_context_switch(next_p);
18710
18711+ percpu_write(current_task, next_p);
18712+ percpu_write(current_tinfo, &next_p->tinfo);
18713+
18714 /*
18715 * Restore %gs if needed (which is common)
18716 */
18717@@ -361,8 +369,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18718
18719 switch_fpu_finish(next_p, fpu);
18720
18721- percpu_write(current_task, next_p);
18722-
18723 return prev_p;
18724 }
18725
18726@@ -392,4 +398,3 @@ unsigned long get_wchan(struct task_struct *p)
18727 } while (count++ < 16);
18728 return 0;
18729 }
18730-
18731diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18732index cfa5c90..4facd28 100644
18733--- a/arch/x86/kernel/process_64.c
18734+++ b/arch/x86/kernel/process_64.c
18735@@ -89,7 +89,7 @@ static void __exit_idle(void)
18736 void exit_idle(void)
18737 {
18738 /* idle loop has pid 0 */
18739- if (current->pid)
18740+ if (task_pid_nr(current))
18741 return;
18742 __exit_idle();
18743 }
18744@@ -270,8 +270,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18745 struct pt_regs *childregs;
18746 struct task_struct *me = current;
18747
18748- childregs = ((struct pt_regs *)
18749- (THREAD_SIZE + task_stack_page(p))) - 1;
18750+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18751 *childregs = *regs;
18752
18753 childregs->ax = 0;
18754@@ -283,6 +282,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18755 p->thread.sp = (unsigned long) childregs;
18756 p->thread.sp0 = (unsigned long) (childregs+1);
18757 p->thread.usersp = me->thread.usersp;
18758+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18759
18760 set_tsk_thread_flag(p, TIF_FORK);
18761
18762@@ -385,7 +385,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18763 struct thread_struct *prev = &prev_p->thread;
18764 struct thread_struct *next = &next_p->thread;
18765 int cpu = smp_processor_id();
18766- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18767+ struct tss_struct *tss = init_tss + cpu;
18768 unsigned fsindex, gsindex;
18769 fpu_switch_t fpu;
18770
18771@@ -467,10 +467,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18772 prev->usersp = percpu_read(old_rsp);
18773 percpu_write(old_rsp, next->usersp);
18774 percpu_write(current_task, next_p);
18775+ percpu_write(current_tinfo, &next_p->tinfo);
18776
18777- percpu_write(kernel_stack,
18778- (unsigned long)task_stack_page(next_p) +
18779- THREAD_SIZE - KERNEL_STACK_OFFSET);
18780+ percpu_write(kernel_stack, next->sp0);
18781
18782 /*
18783 * Now maybe reload the debug registers and handle I/O bitmaps
18784@@ -525,12 +524,11 @@ unsigned long get_wchan(struct task_struct *p)
18785 if (!p || p == current || p->state == TASK_RUNNING)
18786 return 0;
18787 stack = (unsigned long)task_stack_page(p);
18788- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18789+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18790 return 0;
18791 fp = *(u64 *)(p->thread.sp);
18792 do {
18793- if (fp < (unsigned long)stack ||
18794- fp >= (unsigned long)stack+THREAD_SIZE)
18795+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18796 return 0;
18797 ip = *(u64 *)(fp+8);
18798 if (!in_sched_functions(ip))
18799diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18800index 5026738..c5925c0 100644
18801--- a/arch/x86/kernel/ptrace.c
18802+++ b/arch/x86/kernel/ptrace.c
18803@@ -823,7 +823,7 @@ long arch_ptrace(struct task_struct *child, long request,
18804 unsigned long addr, unsigned long data)
18805 {
18806 int ret;
18807- unsigned long __user *datap = (unsigned long __user *)data;
18808+ unsigned long __user *datap = (__force unsigned long __user *)data;
18809
18810 switch (request) {
18811 /* read the word at location addr in the USER area. */
18812@@ -908,14 +908,14 @@ long arch_ptrace(struct task_struct *child, long request,
18813 if ((int) addr < 0)
18814 return -EIO;
18815 ret = do_get_thread_area(child, addr,
18816- (struct user_desc __user *)data);
18817+ (__force struct user_desc __user *) data);
18818 break;
18819
18820 case PTRACE_SET_THREAD_AREA:
18821 if ((int) addr < 0)
18822 return -EIO;
18823 ret = do_set_thread_area(child, addr,
18824- (struct user_desc __user *)data, 0);
18825+ (__force struct user_desc __user *) data, 0);
18826 break;
18827 #endif
18828
18829@@ -1332,7 +1332,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18830 memset(info, 0, sizeof(*info));
18831 info->si_signo = SIGTRAP;
18832 info->si_code = si_code;
18833- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18834+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18835 }
18836
18837 void user_single_step_siginfo(struct task_struct *tsk,
18838@@ -1361,6 +1361,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18839 # define IS_IA32 0
18840 #endif
18841
18842+#ifdef CONFIG_GRKERNSEC_SETXID
18843+extern void gr_delayed_cred_worker(void);
18844+#endif
18845+
18846 /*
18847 * We must return the syscall number to actually look up in the table.
18848 * This can be -1L to skip running any syscall at all.
18849@@ -1369,6 +1373,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18850 {
18851 long ret = 0;
18852
18853+#ifdef CONFIG_GRKERNSEC_SETXID
18854+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18855+ gr_delayed_cred_worker();
18856+#endif
18857+
18858 /*
18859 * If we stepped into a sysenter/syscall insn, it trapped in
18860 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18861@@ -1412,6 +1421,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18862 {
18863 bool step;
18864
18865+#ifdef CONFIG_GRKERNSEC_SETXID
18866+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18867+ gr_delayed_cred_worker();
18868+#endif
18869+
18870 audit_syscall_exit(regs);
18871
18872 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18873diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18874index 42eb330..139955c 100644
18875--- a/arch/x86/kernel/pvclock.c
18876+++ b/arch/x86/kernel/pvclock.c
18877@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18878 return pv_tsc_khz;
18879 }
18880
18881-static atomic64_t last_value = ATOMIC64_INIT(0);
18882+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18883
18884 void pvclock_resume(void)
18885 {
18886- atomic64_set(&last_value, 0);
18887+ atomic64_set_unchecked(&last_value, 0);
18888 }
18889
18890 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18891@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18892 * updating at the same time, and one of them could be slightly behind,
18893 * making the assumption that last_value always go forward fail to hold.
18894 */
18895- last = atomic64_read(&last_value);
18896+ last = atomic64_read_unchecked(&last_value);
18897 do {
18898 if (ret < last)
18899 return last;
18900- last = atomic64_cmpxchg(&last_value, last, ret);
18901+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18902 } while (unlikely(last != ret));
18903
18904 return ret;
18905diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18906index d840e69..98e9581 100644
18907--- a/arch/x86/kernel/reboot.c
18908+++ b/arch/x86/kernel/reboot.c
18909@@ -35,7 +35,7 @@ void (*pm_power_off)(void);
18910 EXPORT_SYMBOL(pm_power_off);
18911
18912 static const struct desc_ptr no_idt = {};
18913-static int reboot_mode;
18914+static unsigned short reboot_mode;
18915 enum reboot_type reboot_type = BOOT_ACPI;
18916 int reboot_force;
18917
18918@@ -335,13 +335,17 @@ core_initcall(reboot_init);
18919 extern const unsigned char machine_real_restart_asm[];
18920 extern const u64 machine_real_restart_gdt[3];
18921
18922-void machine_real_restart(unsigned int type)
18923+__noreturn void machine_real_restart(unsigned int type)
18924 {
18925 void *restart_va;
18926 unsigned long restart_pa;
18927- void (*restart_lowmem)(unsigned int);
18928+ void (* __noreturn restart_lowmem)(unsigned int);
18929 u64 *lowmem_gdt;
18930
18931+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18932+ struct desc_struct *gdt;
18933+#endif
18934+
18935 local_irq_disable();
18936
18937 /* Write zero to CMOS register number 0x0f, which the BIOS POST
18938@@ -367,14 +371,14 @@ void machine_real_restart(unsigned int type)
18939 boot)". This seems like a fairly standard thing that gets set by
18940 REBOOT.COM programs, and the previous reset routine did this
18941 too. */
18942- *((unsigned short *)0x472) = reboot_mode;
18943+ *(unsigned short *)(__va(0x472)) = reboot_mode;
18944
18945 /* Patch the GDT in the low memory trampoline */
18946 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
18947
18948 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
18949 restart_pa = virt_to_phys(restart_va);
18950- restart_lowmem = (void (*)(unsigned int))restart_pa;
18951+ restart_lowmem = (void *)restart_pa;
18952
18953 /* GDT[0]: GDT self-pointer */
18954 lowmem_gdt[0] =
18955@@ -385,7 +389,33 @@ void machine_real_restart(unsigned int type)
18956 GDT_ENTRY(0x009b, restart_pa, 0xffff);
18957
18958 /* Jump to the identity-mapped low memory code */
18959+
18960+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18961+ gdt = get_cpu_gdt_table(smp_processor_id());
18962+ pax_open_kernel();
18963+#ifdef CONFIG_PAX_MEMORY_UDEREF
18964+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18965+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18966+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18967+#endif
18968+#ifdef CONFIG_PAX_KERNEXEC
18969+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18970+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18971+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18972+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18973+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18974+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18975+#endif
18976+ pax_close_kernel();
18977+#endif
18978+
18979+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18980+ asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18981+ unreachable();
18982+#else
18983 restart_lowmem(type);
18984+#endif
18985+
18986 }
18987 #ifdef CONFIG_APM_MODULE
18988 EXPORT_SYMBOL(machine_real_restart);
18989@@ -556,7 +586,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18990 * try to force a triple fault and then cycle between hitting the keyboard
18991 * controller and doing that
18992 */
18993-static void native_machine_emergency_restart(void)
18994+__noreturn static void native_machine_emergency_restart(void)
18995 {
18996 int i;
18997 int attempt = 0;
18998@@ -680,13 +710,13 @@ void native_machine_shutdown(void)
18999 #endif
19000 }
19001
19002-static void __machine_emergency_restart(int emergency)
19003+static __noreturn void __machine_emergency_restart(int emergency)
19004 {
19005 reboot_emergency = emergency;
19006 machine_ops.emergency_restart();
19007 }
19008
19009-static void native_machine_restart(char *__unused)
19010+static __noreturn void native_machine_restart(char *__unused)
19011 {
19012 printk("machine restart\n");
19013
19014@@ -695,7 +725,7 @@ static void native_machine_restart(char *__unused)
19015 __machine_emergency_restart(0);
19016 }
19017
19018-static void native_machine_halt(void)
19019+static __noreturn void native_machine_halt(void)
19020 {
19021 /* stop other cpus and apics */
19022 machine_shutdown();
19023@@ -706,7 +736,7 @@ static void native_machine_halt(void)
19024 stop_this_cpu(NULL);
19025 }
19026
19027-static void native_machine_power_off(void)
19028+__noreturn static void native_machine_power_off(void)
19029 {
19030 if (pm_power_off) {
19031 if (!reboot_force)
19032@@ -715,6 +745,7 @@ static void native_machine_power_off(void)
19033 }
19034 /* a fallback in case there is no PM info available */
19035 tboot_shutdown(TB_SHUTDOWN_HALT);
19036+ unreachable();
19037 }
19038
19039 struct machine_ops machine_ops = {
19040diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
19041index 7a6f3b3..bed145d7 100644
19042--- a/arch/x86/kernel/relocate_kernel_64.S
19043+++ b/arch/x86/kernel/relocate_kernel_64.S
19044@@ -11,6 +11,7 @@
19045 #include <asm/kexec.h>
19046 #include <asm/processor-flags.h>
19047 #include <asm/pgtable_types.h>
19048+#include <asm/alternative-asm.h>
19049
19050 /*
19051 * Must be relocatable PIC code callable as a C function
19052@@ -160,13 +161,14 @@ identity_mapped:
19053 xorq %rbp, %rbp
19054 xorq %r8, %r8
19055 xorq %r9, %r9
19056- xorq %r10, %r9
19057+ xorq %r10, %r10
19058 xorq %r11, %r11
19059 xorq %r12, %r12
19060 xorq %r13, %r13
19061 xorq %r14, %r14
19062 xorq %r15, %r15
19063
19064+ pax_force_retaddr 0, 1
19065 ret
19066
19067 1:
19068diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19069index d7d5099..28555d0 100644
19070--- a/arch/x86/kernel/setup.c
19071+++ b/arch/x86/kernel/setup.c
19072@@ -448,7 +448,7 @@ static void __init parse_setup_data(void)
19073
19074 switch (data->type) {
19075 case SETUP_E820_EXT:
19076- parse_e820_ext(data);
19077+ parse_e820_ext((struct setup_data __force_kernel *)data);
19078 break;
19079 case SETUP_DTB:
19080 add_dtb(pa_data);
19081@@ -649,7 +649,7 @@ static void __init trim_bios_range(void)
19082 * area (640->1Mb) as ram even though it is not.
19083 * take them out.
19084 */
19085- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19086+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19087 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19088 }
19089
19090@@ -767,14 +767,14 @@ void __init setup_arch(char **cmdline_p)
19091
19092 if (!boot_params.hdr.root_flags)
19093 root_mountflags &= ~MS_RDONLY;
19094- init_mm.start_code = (unsigned long) _text;
19095- init_mm.end_code = (unsigned long) _etext;
19096+ init_mm.start_code = ktla_ktva((unsigned long) _text);
19097+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
19098 init_mm.end_data = (unsigned long) _edata;
19099 init_mm.brk = _brk_end;
19100
19101- code_resource.start = virt_to_phys(_text);
19102- code_resource.end = virt_to_phys(_etext)-1;
19103- data_resource.start = virt_to_phys(_etext);
19104+ code_resource.start = virt_to_phys(ktla_ktva(_text));
19105+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19106+ data_resource.start = virt_to_phys(_sdata);
19107 data_resource.end = virt_to_phys(_edata)-1;
19108 bss_resource.start = virt_to_phys(&__bss_start);
19109 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19110diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19111index 5a98aa2..2f9288d 100644
19112--- a/arch/x86/kernel/setup_percpu.c
19113+++ b/arch/x86/kernel/setup_percpu.c
19114@@ -21,19 +21,17 @@
19115 #include <asm/cpu.h>
19116 #include <asm/stackprotector.h>
19117
19118-DEFINE_PER_CPU(int, cpu_number);
19119+#ifdef CONFIG_SMP
19120+DEFINE_PER_CPU(unsigned int, cpu_number);
19121 EXPORT_PER_CPU_SYMBOL(cpu_number);
19122+#endif
19123
19124-#ifdef CONFIG_X86_64
19125 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19126-#else
19127-#define BOOT_PERCPU_OFFSET 0
19128-#endif
19129
19130 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19131 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19132
19133-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19134+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19135 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19136 };
19137 EXPORT_SYMBOL(__per_cpu_offset);
19138@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19139 {
19140 #ifdef CONFIG_X86_32
19141 struct desc_struct gdt;
19142+ unsigned long base = per_cpu_offset(cpu);
19143
19144- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19145- 0x2 | DESCTYPE_S, 0x8);
19146- gdt.s = 1;
19147+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19148+ 0x83 | DESCTYPE_S, 0xC);
19149 write_gdt_entry(get_cpu_gdt_table(cpu),
19150 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19151 #endif
19152@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19153 /* alrighty, percpu areas up and running */
19154 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19155 for_each_possible_cpu(cpu) {
19156+#ifdef CONFIG_CC_STACKPROTECTOR
19157+#ifdef CONFIG_X86_32
19158+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
19159+#endif
19160+#endif
19161 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19162 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19163 per_cpu(cpu_number, cpu) = cpu;
19164@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19165 */
19166 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19167 #endif
19168+#ifdef CONFIG_CC_STACKPROTECTOR
19169+#ifdef CONFIG_X86_32
19170+ if (!cpu)
19171+ per_cpu(stack_canary.canary, cpu) = canary;
19172+#endif
19173+#endif
19174 /*
19175 * Up to this point, the boot CPU has been using .init.data
19176 * area. Reload any changed state for the boot CPU.
19177diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19178index 46a01bd..2e88e6d 100644
19179--- a/arch/x86/kernel/signal.c
19180+++ b/arch/x86/kernel/signal.c
19181@@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsigned long sp)
19182 * Align the stack pointer according to the i386 ABI,
19183 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19184 */
19185- sp = ((sp + 4) & -16ul) - 4;
19186+ sp = ((sp - 12) & -16ul) - 4;
19187 #else /* !CONFIG_X86_32 */
19188 sp = round_down(sp, 16) - 8;
19189 #endif
19190@@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19191 * Return an always-bogus address instead so we will die with SIGSEGV.
19192 */
19193 if (onsigstack && !likely(on_sig_stack(sp)))
19194- return (void __user *)-1L;
19195+ return (__force void __user *)-1L;
19196
19197 /* save i387 state */
19198 if (used_math() && save_i387_xstate(*fpstate) < 0)
19199- return (void __user *)-1L;
19200+ return (__force void __user *)-1L;
19201
19202 return (void __user *)sp;
19203 }
19204@@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19205 }
19206
19207 if (current->mm->context.vdso)
19208- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19209+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19210 else
19211- restorer = &frame->retcode;
19212+ restorer = (void __user *)&frame->retcode;
19213 if (ka->sa.sa_flags & SA_RESTORER)
19214 restorer = ka->sa.sa_restorer;
19215
19216@@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19217 * reasons and because gdb uses it as a signature to notice
19218 * signal handler stack frames.
19219 */
19220- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19221+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19222
19223 if (err)
19224 return -EFAULT;
19225@@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19226 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19227
19228 /* Set up to return from userspace. */
19229- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19230+ if (current->mm->context.vdso)
19231+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19232+ else
19233+ restorer = (void __user *)&frame->retcode;
19234 if (ka->sa.sa_flags & SA_RESTORER)
19235 restorer = ka->sa.sa_restorer;
19236 put_user_ex(restorer, &frame->pretcode);
19237@@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19238 * reasons and because gdb uses it as a signature to notice
19239 * signal handler stack frames.
19240 */
19241- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19242+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19243 } put_user_catch(err);
19244
19245 if (err)
19246@@ -765,7 +768,7 @@ static void do_signal(struct pt_regs *regs)
19247 * X86_32: vm86 regs switched out by assembly code before reaching
19248 * here, so testing against kernel CS suffices.
19249 */
19250- if (!user_mode(regs))
19251+ if (!user_mode_novm(regs))
19252 return;
19253
19254 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
19255diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19256index 66d250c..f1b10bd 100644
19257--- a/arch/x86/kernel/smpboot.c
19258+++ b/arch/x86/kernel/smpboot.c
19259@@ -715,17 +715,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
19260 set_idle_for_cpu(cpu, c_idle.idle);
19261 do_rest:
19262 per_cpu(current_task, cpu) = c_idle.idle;
19263+ per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
19264 #ifdef CONFIG_X86_32
19265 /* Stack for startup_32 can be just as for start_secondary onwards */
19266 irq_ctx_init(cpu);
19267 #else
19268 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
19269 initial_gs = per_cpu_offset(cpu);
19270- per_cpu(kernel_stack, cpu) =
19271- (unsigned long)task_stack_page(c_idle.idle) -
19272- KERNEL_STACK_OFFSET + THREAD_SIZE;
19273+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
19274 #endif
19275+
19276+ pax_open_kernel();
19277 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19278+ pax_close_kernel();
19279+
19280 initial_code = (unsigned long)start_secondary;
19281 stack_start = c_idle.idle->thread.sp;
19282
19283@@ -868,6 +871,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
19284
19285 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19286
19287+#ifdef CONFIG_PAX_PER_CPU_PGD
19288+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19289+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19290+ KERNEL_PGD_PTRS);
19291+#endif
19292+
19293 err = do_boot_cpu(apicid, cpu);
19294 if (err) {
19295 pr_debug("do_boot_cpu failed %d\n", err);
19296diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19297index c346d11..d43b163 100644
19298--- a/arch/x86/kernel/step.c
19299+++ b/arch/x86/kernel/step.c
19300@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19301 struct desc_struct *desc;
19302 unsigned long base;
19303
19304- seg &= ~7UL;
19305+ seg >>= 3;
19306
19307 mutex_lock(&child->mm->context.lock);
19308- if (unlikely((seg >> 3) >= child->mm->context.size))
19309+ if (unlikely(seg >= child->mm->context.size))
19310 addr = -1L; /* bogus selector, access would fault */
19311 else {
19312 desc = child->mm->context.ldt + seg;
19313@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19314 addr += base;
19315 }
19316 mutex_unlock(&child->mm->context.lock);
19317- }
19318+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19319+ addr = ktla_ktva(addr);
19320
19321 return addr;
19322 }
19323@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19324 unsigned char opcode[15];
19325 unsigned long addr = convert_ip_to_linear(child, regs);
19326
19327+ if (addr == -EINVAL)
19328+ return 0;
19329+
19330 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19331 for (i = 0; i < copied; i++) {
19332 switch (opcode[i]) {
19333diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19334index 0b0cb5f..db6b9ed 100644
19335--- a/arch/x86/kernel/sys_i386_32.c
19336+++ b/arch/x86/kernel/sys_i386_32.c
19337@@ -24,17 +24,224 @@
19338
19339 #include <asm/syscalls.h>
19340
19341-/*
19342- * Do a system call from kernel instead of calling sys_execve so we
19343- * end up with proper pt_regs.
19344- */
19345-int kernel_execve(const char *filename,
19346- const char *const argv[],
19347- const char *const envp[])
19348+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19349 {
19350- long __res;
19351- asm volatile ("int $0x80"
19352- : "=a" (__res)
19353- : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19354- return __res;
19355+ unsigned long pax_task_size = TASK_SIZE;
19356+
19357+#ifdef CONFIG_PAX_SEGMEXEC
19358+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19359+ pax_task_size = SEGMEXEC_TASK_SIZE;
19360+#endif
19361+
19362+ if (len > pax_task_size || addr > pax_task_size - len)
19363+ return -EINVAL;
19364+
19365+ return 0;
19366+}
19367+
19368+unsigned long
19369+arch_get_unmapped_area(struct file *filp, unsigned long addr,
19370+ unsigned long len, unsigned long pgoff, unsigned long flags)
19371+{
19372+ struct mm_struct *mm = current->mm;
19373+ struct vm_area_struct *vma;
19374+ unsigned long start_addr, pax_task_size = TASK_SIZE;
19375+
19376+#ifdef CONFIG_PAX_SEGMEXEC
19377+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19378+ pax_task_size = SEGMEXEC_TASK_SIZE;
19379+#endif
19380+
19381+ pax_task_size -= PAGE_SIZE;
19382+
19383+ if (len > pax_task_size)
19384+ return -ENOMEM;
19385+
19386+ if (flags & MAP_FIXED)
19387+ return addr;
19388+
19389+#ifdef CONFIG_PAX_RANDMMAP
19390+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19391+#endif
19392+
19393+ if (addr) {
19394+ addr = PAGE_ALIGN(addr);
19395+ if (pax_task_size - len >= addr) {
19396+ vma = find_vma(mm, addr);
19397+ if (check_heap_stack_gap(vma, addr, len))
19398+ return addr;
19399+ }
19400+ }
19401+ if (len > mm->cached_hole_size) {
19402+ start_addr = addr = mm->free_area_cache;
19403+ } else {
19404+ start_addr = addr = mm->mmap_base;
19405+ mm->cached_hole_size = 0;
19406+ }
19407+
19408+#ifdef CONFIG_PAX_PAGEEXEC
19409+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19410+ start_addr = 0x00110000UL;
19411+
19412+#ifdef CONFIG_PAX_RANDMMAP
19413+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19414+ start_addr += mm->delta_mmap & 0x03FFF000UL;
19415+#endif
19416+
19417+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19418+ start_addr = addr = mm->mmap_base;
19419+ else
19420+ addr = start_addr;
19421+ }
19422+#endif
19423+
19424+full_search:
19425+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19426+ /* At this point: (!vma || addr < vma->vm_end). */
19427+ if (pax_task_size - len < addr) {
19428+ /*
19429+ * Start a new search - just in case we missed
19430+ * some holes.
19431+ */
19432+ if (start_addr != mm->mmap_base) {
19433+ start_addr = addr = mm->mmap_base;
19434+ mm->cached_hole_size = 0;
19435+ goto full_search;
19436+ }
19437+ return -ENOMEM;
19438+ }
19439+ if (check_heap_stack_gap(vma, addr, len))
19440+ break;
19441+ if (addr + mm->cached_hole_size < vma->vm_start)
19442+ mm->cached_hole_size = vma->vm_start - addr;
19443+ addr = vma->vm_end;
19444+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
19445+ start_addr = addr = mm->mmap_base;
19446+ mm->cached_hole_size = 0;
19447+ goto full_search;
19448+ }
19449+ }
19450+
19451+ /*
19452+ * Remember the place where we stopped the search:
19453+ */
19454+ mm->free_area_cache = addr + len;
19455+ return addr;
19456+}
19457+
19458+unsigned long
19459+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19460+ const unsigned long len, const unsigned long pgoff,
19461+ const unsigned long flags)
19462+{
19463+ struct vm_area_struct *vma;
19464+ struct mm_struct *mm = current->mm;
19465+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19466+
19467+#ifdef CONFIG_PAX_SEGMEXEC
19468+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19469+ pax_task_size = SEGMEXEC_TASK_SIZE;
19470+#endif
19471+
19472+ pax_task_size -= PAGE_SIZE;
19473+
19474+ /* requested length too big for entire address space */
19475+ if (len > pax_task_size)
19476+ return -ENOMEM;
19477+
19478+ if (flags & MAP_FIXED)
19479+ return addr;
19480+
19481+#ifdef CONFIG_PAX_PAGEEXEC
19482+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19483+ goto bottomup;
19484+#endif
19485+
19486+#ifdef CONFIG_PAX_RANDMMAP
19487+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19488+#endif
19489+
19490+ /* requesting a specific address */
19491+ if (addr) {
19492+ addr = PAGE_ALIGN(addr);
19493+ if (pax_task_size - len >= addr) {
19494+ vma = find_vma(mm, addr);
19495+ if (check_heap_stack_gap(vma, addr, len))
19496+ return addr;
19497+ }
19498+ }
19499+
19500+ /* check if free_area_cache is useful for us */
19501+ if (len <= mm->cached_hole_size) {
19502+ mm->cached_hole_size = 0;
19503+ mm->free_area_cache = mm->mmap_base;
19504+ }
19505+
19506+ /* either no address requested or can't fit in requested address hole */
19507+ addr = mm->free_area_cache;
19508+
19509+ /* make sure it can fit in the remaining address space */
19510+ if (addr > len) {
19511+ vma = find_vma(mm, addr-len);
19512+ if (check_heap_stack_gap(vma, addr - len, len))
19513+ /* remember the address as a hint for next time */
19514+ return (mm->free_area_cache = addr-len);
19515+ }
19516+
19517+ if (mm->mmap_base < len)
19518+ goto bottomup;
19519+
19520+ addr = mm->mmap_base-len;
19521+
19522+ do {
19523+ /*
19524+ * Lookup failure means no vma is above this address,
19525+ * else if new region fits below vma->vm_start,
19526+ * return with success:
19527+ */
19528+ vma = find_vma(mm, addr);
19529+ if (check_heap_stack_gap(vma, addr, len))
19530+ /* remember the address as a hint for next time */
19531+ return (mm->free_area_cache = addr);
19532+
19533+ /* remember the largest hole we saw so far */
19534+ if (addr + mm->cached_hole_size < vma->vm_start)
19535+ mm->cached_hole_size = vma->vm_start - addr;
19536+
19537+ /* try just below the current vma->vm_start */
19538+ addr = skip_heap_stack_gap(vma, len);
19539+ } while (!IS_ERR_VALUE(addr));
19540+
19541+bottomup:
19542+ /*
19543+ * A failed mmap() very likely causes application failure,
19544+ * so fall back to the bottom-up function here. This scenario
19545+ * can happen with large stack limits and large mmap()
19546+ * allocations.
19547+ */
19548+
19549+#ifdef CONFIG_PAX_SEGMEXEC
19550+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19551+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19552+ else
19553+#endif
19554+
19555+ mm->mmap_base = TASK_UNMAPPED_BASE;
19556+
19557+#ifdef CONFIG_PAX_RANDMMAP
19558+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19559+ mm->mmap_base += mm->delta_mmap;
19560+#endif
19561+
19562+ mm->free_area_cache = mm->mmap_base;
19563+ mm->cached_hole_size = ~0UL;
19564+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19565+ /*
19566+ * Restore the topdown base:
19567+ */
19568+ mm->mmap_base = base;
19569+ mm->free_area_cache = base;
19570+ mm->cached_hole_size = ~0UL;
19571+
19572+ return addr;
19573 }
19574diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19575index 0514890..3dbebce 100644
19576--- a/arch/x86/kernel/sys_x86_64.c
19577+++ b/arch/x86/kernel/sys_x86_64.c
19578@@ -95,8 +95,8 @@ out:
19579 return error;
19580 }
19581
19582-static void find_start_end(unsigned long flags, unsigned long *begin,
19583- unsigned long *end)
19584+static void find_start_end(struct mm_struct *mm, unsigned long flags,
19585+ unsigned long *begin, unsigned long *end)
19586 {
19587 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
19588 unsigned long new_begin;
19589@@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19590 *begin = new_begin;
19591 }
19592 } else {
19593- *begin = TASK_UNMAPPED_BASE;
19594+ *begin = mm->mmap_base;
19595 *end = TASK_SIZE;
19596 }
19597 }
19598@@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19599 if (flags & MAP_FIXED)
19600 return addr;
19601
19602- find_start_end(flags, &begin, &end);
19603+ find_start_end(mm, flags, &begin, &end);
19604
19605 if (len > end)
19606 return -ENOMEM;
19607
19608+#ifdef CONFIG_PAX_RANDMMAP
19609+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19610+#endif
19611+
19612 if (addr) {
19613 addr = PAGE_ALIGN(addr);
19614 vma = find_vma(mm, addr);
19615- if (end - len >= addr &&
19616- (!vma || addr + len <= vma->vm_start))
19617+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19618 return addr;
19619 }
19620 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
19621@@ -172,7 +175,7 @@ full_search:
19622 }
19623 return -ENOMEM;
19624 }
19625- if (!vma || addr + len <= vma->vm_start) {
19626+ if (check_heap_stack_gap(vma, addr, len)) {
19627 /*
19628 * Remember the place where we stopped the search:
19629 */
19630@@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19631 {
19632 struct vm_area_struct *vma;
19633 struct mm_struct *mm = current->mm;
19634- unsigned long addr = addr0;
19635+ unsigned long base = mm->mmap_base, addr = addr0;
19636
19637 /* requested length too big for entire address space */
19638 if (len > TASK_SIZE)
19639@@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19640 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
19641 goto bottomup;
19642
19643+#ifdef CONFIG_PAX_RANDMMAP
19644+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19645+#endif
19646+
19647 /* requesting a specific address */
19648 if (addr) {
19649 addr = PAGE_ALIGN(addr);
19650- vma = find_vma(mm, addr);
19651- if (TASK_SIZE - len >= addr &&
19652- (!vma || addr + len <= vma->vm_start))
19653- return addr;
19654+ if (TASK_SIZE - len >= addr) {
19655+ vma = find_vma(mm, addr);
19656+ if (check_heap_stack_gap(vma, addr, len))
19657+ return addr;
19658+ }
19659 }
19660
19661 /* check if free_area_cache is useful for us */
19662@@ -232,7 +240,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19663 ALIGN_TOPDOWN);
19664
19665 vma = find_vma(mm, tmp_addr);
19666- if (!vma || tmp_addr + len <= vma->vm_start)
19667+ if (check_heap_stack_gap(vma, tmp_addr, len))
19668 /* remember the address as a hint for next time */
19669 return mm->free_area_cache = tmp_addr;
19670 }
19671@@ -251,7 +259,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19672 * return with success:
19673 */
19674 vma = find_vma(mm, addr);
19675- if (!vma || addr+len <= vma->vm_start)
19676+ if (check_heap_stack_gap(vma, addr, len))
19677 /* remember the address as a hint for next time */
19678 return mm->free_area_cache = addr;
19679
19680@@ -260,8 +268,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19681 mm->cached_hole_size = vma->vm_start - addr;
19682
19683 /* try just below the current vma->vm_start */
19684- addr = vma->vm_start-len;
19685- } while (len < vma->vm_start);
19686+ addr = skip_heap_stack_gap(vma, len);
19687+ } while (!IS_ERR_VALUE(addr));
19688
19689 bottomup:
19690 /*
19691@@ -270,13 +278,21 @@ bottomup:
19692 * can happen with large stack limits and large mmap()
19693 * allocations.
19694 */
19695+ mm->mmap_base = TASK_UNMAPPED_BASE;
19696+
19697+#ifdef CONFIG_PAX_RANDMMAP
19698+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19699+ mm->mmap_base += mm->delta_mmap;
19700+#endif
19701+
19702+ mm->free_area_cache = mm->mmap_base;
19703 mm->cached_hole_size = ~0UL;
19704- mm->free_area_cache = TASK_UNMAPPED_BASE;
19705 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19706 /*
19707 * Restore the topdown base:
19708 */
19709- mm->free_area_cache = mm->mmap_base;
19710+ mm->mmap_base = base;
19711+ mm->free_area_cache = base;
19712 mm->cached_hole_size = ~0UL;
19713
19714 return addr;
19715diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19716index e2410e2..4fe3fbc 100644
19717--- a/arch/x86/kernel/tboot.c
19718+++ b/arch/x86/kernel/tboot.c
19719@@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
19720
19721 void tboot_shutdown(u32 shutdown_type)
19722 {
19723- void (*shutdown)(void);
19724+ void (* __noreturn shutdown)(void);
19725
19726 if (!tboot_enabled())
19727 return;
19728@@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
19729
19730 switch_to_tboot_pt();
19731
19732- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19733+ shutdown = (void *)tboot->shutdown_entry;
19734 shutdown();
19735
19736 /* should not reach here */
19737@@ -298,7 +298,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19738 tboot_shutdown(acpi_shutdown_map[sleep_state]);
19739 }
19740
19741-static atomic_t ap_wfs_count;
19742+static atomic_unchecked_t ap_wfs_count;
19743
19744 static int tboot_wait_for_aps(int num_aps)
19745 {
19746@@ -322,9 +322,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19747 {
19748 switch (action) {
19749 case CPU_DYING:
19750- atomic_inc(&ap_wfs_count);
19751+ atomic_inc_unchecked(&ap_wfs_count);
19752 if (num_online_cpus() == 1)
19753- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19754+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19755 return NOTIFY_BAD;
19756 break;
19757 }
19758@@ -343,7 +343,7 @@ static __init int tboot_late_init(void)
19759
19760 tboot_create_trampoline();
19761
19762- atomic_set(&ap_wfs_count, 0);
19763+ atomic_set_unchecked(&ap_wfs_count, 0);
19764 register_hotcpu_notifier(&tboot_cpu_notifier);
19765 return 0;
19766 }
19767diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19768index dd5fbf4..b7f2232 100644
19769--- a/arch/x86/kernel/time.c
19770+++ b/arch/x86/kernel/time.c
19771@@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19772 {
19773 unsigned long pc = instruction_pointer(regs);
19774
19775- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19776+ if (!user_mode(regs) && in_lock_functions(pc)) {
19777 #ifdef CONFIG_FRAME_POINTER
19778- return *(unsigned long *)(regs->bp + sizeof(long));
19779+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19780 #else
19781 unsigned long *sp =
19782 (unsigned long *)kernel_stack_pointer(regs);
19783@@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19784 * or above a saved flags. Eflags has bits 22-31 zero,
19785 * kernel addresses don't.
19786 */
19787+
19788+#ifdef CONFIG_PAX_KERNEXEC
19789+ return ktla_ktva(sp[0]);
19790+#else
19791 if (sp[0] >> 22)
19792 return sp[0];
19793 if (sp[1] >> 22)
19794 return sp[1];
19795 #endif
19796+
19797+#endif
19798 }
19799 return pc;
19800 }
19801diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19802index bcfec2d..8f88b4a 100644
19803--- a/arch/x86/kernel/tls.c
19804+++ b/arch/x86/kernel/tls.c
19805@@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19806 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19807 return -EINVAL;
19808
19809+#ifdef CONFIG_PAX_SEGMEXEC
19810+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19811+ return -EINVAL;
19812+#endif
19813+
19814 set_tls_desc(p, idx, &info, 1);
19815
19816 return 0;
19817diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19818index 451c0a7..e57f551 100644
19819--- a/arch/x86/kernel/trampoline_32.S
19820+++ b/arch/x86/kernel/trampoline_32.S
19821@@ -32,6 +32,12 @@
19822 #include <asm/segment.h>
19823 #include <asm/page_types.h>
19824
19825+#ifdef CONFIG_PAX_KERNEXEC
19826+#define ta(X) (X)
19827+#else
19828+#define ta(X) ((X) - __PAGE_OFFSET)
19829+#endif
19830+
19831 #ifdef CONFIG_SMP
19832
19833 .section ".x86_trampoline","a"
19834@@ -62,7 +68,7 @@ r_base = .
19835 inc %ax # protected mode (PE) bit
19836 lmsw %ax # into protected mode
19837 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
19838- ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
19839+ ljmpl $__BOOT_CS, $ta(startup_32_smp)
19840
19841 # These need to be in the same 64K segment as the above;
19842 # hence we don't use the boot_gdt_descr defined in head.S
19843diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19844index 09ff517..df19fbff 100644
19845--- a/arch/x86/kernel/trampoline_64.S
19846+++ b/arch/x86/kernel/trampoline_64.S
19847@@ -90,7 +90,7 @@ startup_32:
19848 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
19849 movl %eax, %ds
19850
19851- movl $X86_CR4_PAE, %eax
19852+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19853 movl %eax, %cr4 # Enable PAE mode
19854
19855 # Setup trampoline 4 level pagetables
19856@@ -138,7 +138,7 @@ tidt:
19857 # so the kernel can live anywhere
19858 .balign 4
19859 tgdt:
19860- .short tgdt_end - tgdt # gdt limit
19861+ .short tgdt_end - tgdt - 1 # gdt limit
19862 .long tgdt - r_base
19863 .short 0
19864 .quad 0x00cf9b000000ffff # __KERNEL32_CS
19865diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19866index 4bbe04d..41d0943 100644
19867--- a/arch/x86/kernel/traps.c
19868+++ b/arch/x86/kernel/traps.c
19869@@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19870
19871 /* Do we ignore FPU interrupts ? */
19872 char ignore_fpu_irq;
19873-
19874-/*
19875- * The IDT has to be page-aligned to simplify the Pentium
19876- * F0 0F bug workaround.
19877- */
19878-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19879 #endif
19880
19881 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19882@@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19883 }
19884
19885 static void __kprobes
19886-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19887+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19888 long error_code, siginfo_t *info)
19889 {
19890 struct task_struct *tsk = current;
19891
19892 #ifdef CONFIG_X86_32
19893- if (regs->flags & X86_VM_MASK) {
19894+ if (v8086_mode(regs)) {
19895 /*
19896 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19897 * On nmi (interrupt 2), do_trap should not be called.
19898@@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19899 }
19900 #endif
19901
19902- if (!user_mode(regs))
19903+ if (!user_mode_novm(regs))
19904 goto kernel_trap;
19905
19906 #ifdef CONFIG_X86_32
19907@@ -148,7 +142,7 @@ trap_signal:
19908 printk_ratelimit()) {
19909 printk(KERN_INFO
19910 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19911- tsk->comm, tsk->pid, str,
19912+ tsk->comm, task_pid_nr(tsk), str,
19913 regs->ip, regs->sp, error_code);
19914 print_vma_addr(" in ", regs->ip);
19915 printk("\n");
19916@@ -165,8 +159,20 @@ kernel_trap:
19917 if (!fixup_exception(regs)) {
19918 tsk->thread.error_code = error_code;
19919 tsk->thread.trap_no = trapnr;
19920+
19921+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19922+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19923+ str = "PAX: suspicious stack segment fault";
19924+#endif
19925+
19926 die(str, regs, error_code);
19927 }
19928+
19929+#ifdef CONFIG_PAX_REFCOUNT
19930+ if (trapnr == 4)
19931+ pax_report_refcount_overflow(regs);
19932+#endif
19933+
19934 return;
19935
19936 #ifdef CONFIG_X86_32
19937@@ -255,14 +261,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19938 conditional_sti(regs);
19939
19940 #ifdef CONFIG_X86_32
19941- if (regs->flags & X86_VM_MASK)
19942+ if (v8086_mode(regs))
19943 goto gp_in_vm86;
19944 #endif
19945
19946 tsk = current;
19947- if (!user_mode(regs))
19948+ if (!user_mode_novm(regs))
19949 goto gp_in_kernel;
19950
19951+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19952+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19953+ struct mm_struct *mm = tsk->mm;
19954+ unsigned long limit;
19955+
19956+ down_write(&mm->mmap_sem);
19957+ limit = mm->context.user_cs_limit;
19958+ if (limit < TASK_SIZE) {
19959+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19960+ up_write(&mm->mmap_sem);
19961+ return;
19962+ }
19963+ up_write(&mm->mmap_sem);
19964+ }
19965+#endif
19966+
19967 tsk->thread.error_code = error_code;
19968 tsk->thread.trap_no = 13;
19969
19970@@ -295,6 +317,13 @@ gp_in_kernel:
19971 if (notify_die(DIE_GPF, "general protection fault", regs,
19972 error_code, 13, SIGSEGV) == NOTIFY_STOP)
19973 return;
19974+
19975+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19976+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19977+ die("PAX: suspicious general protection fault", regs, error_code);
19978+ else
19979+#endif
19980+
19981 die("general protection fault", regs, error_code);
19982 }
19983
19984@@ -421,7 +450,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19985 /* It's safe to allow irq's after DR6 has been saved */
19986 preempt_conditional_sti(regs);
19987
19988- if (regs->flags & X86_VM_MASK) {
19989+ if (v8086_mode(regs)) {
19990 handle_vm86_trap((struct kernel_vm86_regs *) regs,
19991 error_code, 1);
19992 preempt_conditional_cli(regs);
19993@@ -436,7 +465,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19994 * We already checked v86 mode above, so we can check for kernel mode
19995 * by just checking the CPL of CS.
19996 */
19997- if ((dr6 & DR_STEP) && !user_mode(regs)) {
19998+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19999 tsk->thread.debugreg6 &= ~DR_STEP;
20000 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
20001 regs->flags &= ~X86_EFLAGS_TF;
20002@@ -466,7 +495,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
20003 return;
20004 conditional_sti(regs);
20005
20006- if (!user_mode_vm(regs))
20007+ if (!user_mode(regs))
20008 {
20009 if (!fixup_exception(regs)) {
20010 task->thread.error_code = error_code;
20011diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
20012index b9242ba..50c5edd 100644
20013--- a/arch/x86/kernel/verify_cpu.S
20014+++ b/arch/x86/kernel/verify_cpu.S
20015@@ -20,6 +20,7 @@
20016 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
20017 * arch/x86/kernel/trampoline_64.S: secondary processor verification
20018 * arch/x86/kernel/head_32.S: processor startup
20019+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
20020 *
20021 * verify_cpu, returns the status of longmode and SSE in register %eax.
20022 * 0: Success 1: Failure
20023diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
20024index 328cb37..56556b4 100644
20025--- a/arch/x86/kernel/vm86_32.c
20026+++ b/arch/x86/kernel/vm86_32.c
20027@@ -41,6 +41,7 @@
20028 #include <linux/ptrace.h>
20029 #include <linux/audit.h>
20030 #include <linux/stddef.h>
20031+#include <linux/grsecurity.h>
20032
20033 #include <asm/uaccess.h>
20034 #include <asm/io.h>
20035@@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
20036 do_exit(SIGSEGV);
20037 }
20038
20039- tss = &per_cpu(init_tss, get_cpu());
20040+ tss = init_tss + get_cpu();
20041 current->thread.sp0 = current->thread.saved_sp0;
20042 current->thread.sysenter_cs = __KERNEL_CS;
20043 load_sp0(tss, &current->thread);
20044@@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
20045 struct task_struct *tsk;
20046 int tmp, ret = -EPERM;
20047
20048+#ifdef CONFIG_GRKERNSEC_VM86
20049+ if (!capable(CAP_SYS_RAWIO)) {
20050+ gr_handle_vm86();
20051+ goto out;
20052+ }
20053+#endif
20054+
20055 tsk = current;
20056 if (tsk->thread.saved_sp0)
20057 goto out;
20058@@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
20059 int tmp, ret;
20060 struct vm86plus_struct __user *v86;
20061
20062+#ifdef CONFIG_GRKERNSEC_VM86
20063+ if (!capable(CAP_SYS_RAWIO)) {
20064+ gr_handle_vm86();
20065+ ret = -EPERM;
20066+ goto out;
20067+ }
20068+#endif
20069+
20070 tsk = current;
20071 switch (cmd) {
20072 case VM86_REQUEST_IRQ:
20073@@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
20074 tsk->thread.saved_fs = info->regs32->fs;
20075 tsk->thread.saved_gs = get_user_gs(info->regs32);
20076
20077- tss = &per_cpu(init_tss, get_cpu());
20078+ tss = init_tss + get_cpu();
20079 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
20080 if (cpu_has_sep)
20081 tsk->thread.sysenter_cs = 0;
20082@@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
20083 goto cannot_handle;
20084 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20085 goto cannot_handle;
20086- intr_ptr = (unsigned long __user *) (i << 2);
20087+ intr_ptr = (__force unsigned long __user *) (i << 2);
20088 if (get_user(segoffs, intr_ptr))
20089 goto cannot_handle;
20090 if ((segoffs >> 16) == BIOSSEG)
20091diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20092index 0f703f1..9e15f64 100644
20093--- a/arch/x86/kernel/vmlinux.lds.S
20094+++ b/arch/x86/kernel/vmlinux.lds.S
20095@@ -26,6 +26,13 @@
20096 #include <asm/page_types.h>
20097 #include <asm/cache.h>
20098 #include <asm/boot.h>
20099+#include <asm/segment.h>
20100+
20101+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20102+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20103+#else
20104+#define __KERNEL_TEXT_OFFSET 0
20105+#endif
20106
20107 #undef i386 /* in case the preprocessor is a 32bit one */
20108
20109@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20110
20111 PHDRS {
20112 text PT_LOAD FLAGS(5); /* R_E */
20113+#ifdef CONFIG_X86_32
20114+ module PT_LOAD FLAGS(5); /* R_E */
20115+#endif
20116+#ifdef CONFIG_XEN
20117+ rodata PT_LOAD FLAGS(5); /* R_E */
20118+#else
20119+ rodata PT_LOAD FLAGS(4); /* R__ */
20120+#endif
20121 data PT_LOAD FLAGS(6); /* RW_ */
20122-#ifdef CONFIG_X86_64
20123+ init.begin PT_LOAD FLAGS(6); /* RW_ */
20124 #ifdef CONFIG_SMP
20125 percpu PT_LOAD FLAGS(6); /* RW_ */
20126 #endif
20127+ text.init PT_LOAD FLAGS(5); /* R_E */
20128+ text.exit PT_LOAD FLAGS(5); /* R_E */
20129 init PT_LOAD FLAGS(7); /* RWE */
20130-#endif
20131 note PT_NOTE FLAGS(0); /* ___ */
20132 }
20133
20134 SECTIONS
20135 {
20136 #ifdef CONFIG_X86_32
20137- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20138- phys_startup_32 = startup_32 - LOAD_OFFSET;
20139+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20140 #else
20141- . = __START_KERNEL;
20142- phys_startup_64 = startup_64 - LOAD_OFFSET;
20143+ . = __START_KERNEL;
20144 #endif
20145
20146 /* Text and read-only data */
20147- .text : AT(ADDR(.text) - LOAD_OFFSET) {
20148- _text = .;
20149+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20150 /* bootstrapping code */
20151+#ifdef CONFIG_X86_32
20152+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20153+#else
20154+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20155+#endif
20156+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20157+ _text = .;
20158 HEAD_TEXT
20159 #ifdef CONFIG_X86_32
20160 . = ALIGN(PAGE_SIZE);
20161@@ -108,13 +128,47 @@ SECTIONS
20162 IRQENTRY_TEXT
20163 *(.fixup)
20164 *(.gnu.warning)
20165- /* End of text section */
20166- _etext = .;
20167 } :text = 0x9090
20168
20169- NOTES :text :note
20170+ . += __KERNEL_TEXT_OFFSET;
20171
20172- EXCEPTION_TABLE(16) :text = 0x9090
20173+#ifdef CONFIG_X86_32
20174+ . = ALIGN(PAGE_SIZE);
20175+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20176+
20177+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20178+ MODULES_EXEC_VADDR = .;
20179+ BYTE(0)
20180+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20181+ . = ALIGN(HPAGE_SIZE);
20182+ MODULES_EXEC_END = . - 1;
20183+#endif
20184+
20185+ } :module
20186+#endif
20187+
20188+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20189+ /* End of text section */
20190+ _etext = . - __KERNEL_TEXT_OFFSET;
20191+ }
20192+
20193+#ifdef CONFIG_X86_32
20194+ . = ALIGN(PAGE_SIZE);
20195+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20196+ *(.idt)
20197+ . = ALIGN(PAGE_SIZE);
20198+ *(.empty_zero_page)
20199+ *(.initial_pg_fixmap)
20200+ *(.initial_pg_pmd)
20201+ *(.initial_page_table)
20202+ *(.swapper_pg_dir)
20203+ } :rodata
20204+#endif
20205+
20206+ . = ALIGN(PAGE_SIZE);
20207+ NOTES :rodata :note
20208+
20209+ EXCEPTION_TABLE(16) :rodata
20210
20211 #if defined(CONFIG_DEBUG_RODATA)
20212 /* .text should occupy whole number of pages */
20213@@ -126,16 +180,20 @@ SECTIONS
20214
20215 /* Data */
20216 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20217+
20218+#ifdef CONFIG_PAX_KERNEXEC
20219+ . = ALIGN(HPAGE_SIZE);
20220+#else
20221+ . = ALIGN(PAGE_SIZE);
20222+#endif
20223+
20224 /* Start of data section */
20225 _sdata = .;
20226
20227 /* init_task */
20228 INIT_TASK_DATA(THREAD_SIZE)
20229
20230-#ifdef CONFIG_X86_32
20231- /* 32 bit has nosave before _edata */
20232 NOSAVE_DATA
20233-#endif
20234
20235 PAGE_ALIGNED_DATA(PAGE_SIZE)
20236
20237@@ -176,12 +234,19 @@ SECTIONS
20238 #endif /* CONFIG_X86_64 */
20239
20240 /* Init code and data - will be freed after init */
20241- . = ALIGN(PAGE_SIZE);
20242 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20243+ BYTE(0)
20244+
20245+#ifdef CONFIG_PAX_KERNEXEC
20246+ . = ALIGN(HPAGE_SIZE);
20247+#else
20248+ . = ALIGN(PAGE_SIZE);
20249+#endif
20250+
20251 __init_begin = .; /* paired with __init_end */
20252- }
20253+ } :init.begin
20254
20255-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20256+#ifdef CONFIG_SMP
20257 /*
20258 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20259 * output PHDR, so the next output section - .init.text - should
20260@@ -190,12 +255,27 @@ SECTIONS
20261 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20262 #endif
20263
20264- INIT_TEXT_SECTION(PAGE_SIZE)
20265-#ifdef CONFIG_X86_64
20266- :init
20267-#endif
20268+ . = ALIGN(PAGE_SIZE);
20269+ init_begin = .;
20270+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20271+ VMLINUX_SYMBOL(_sinittext) = .;
20272+ INIT_TEXT
20273+ VMLINUX_SYMBOL(_einittext) = .;
20274+ . = ALIGN(PAGE_SIZE);
20275+ } :text.init
20276
20277- INIT_DATA_SECTION(16)
20278+ /*
20279+ * .exit.text is discard at runtime, not link time, to deal with
20280+ * references from .altinstructions and .eh_frame
20281+ */
20282+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20283+ EXIT_TEXT
20284+ . = ALIGN(16);
20285+ } :text.exit
20286+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20287+
20288+ . = ALIGN(PAGE_SIZE);
20289+ INIT_DATA_SECTION(16) :init
20290
20291 /*
20292 * Code and data for a variety of lowlevel trampolines, to be
20293@@ -269,19 +349,12 @@ SECTIONS
20294 }
20295
20296 . = ALIGN(8);
20297- /*
20298- * .exit.text is discard at runtime, not link time, to deal with
20299- * references from .altinstructions and .eh_frame
20300- */
20301- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20302- EXIT_TEXT
20303- }
20304
20305 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20306 EXIT_DATA
20307 }
20308
20309-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20310+#ifndef CONFIG_SMP
20311 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20312 #endif
20313
20314@@ -300,16 +373,10 @@ SECTIONS
20315 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20316 __smp_locks = .;
20317 *(.smp_locks)
20318- . = ALIGN(PAGE_SIZE);
20319 __smp_locks_end = .;
20320+ . = ALIGN(PAGE_SIZE);
20321 }
20322
20323-#ifdef CONFIG_X86_64
20324- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20325- NOSAVE_DATA
20326- }
20327-#endif
20328-
20329 /* BSS */
20330 . = ALIGN(PAGE_SIZE);
20331 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20332@@ -325,6 +392,7 @@ SECTIONS
20333 __brk_base = .;
20334 . += 64 * 1024; /* 64k alignment slop space */
20335 *(.brk_reservation) /* areas brk users have reserved */
20336+ . = ALIGN(HPAGE_SIZE);
20337 __brk_limit = .;
20338 }
20339
20340@@ -351,13 +419,12 @@ SECTIONS
20341 * for the boot processor.
20342 */
20343 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20344-INIT_PER_CPU(gdt_page);
20345 INIT_PER_CPU(irq_stack_union);
20346
20347 /*
20348 * Build-time check on the image size:
20349 */
20350-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20351+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20352 "kernel image bigger than KERNEL_IMAGE_SIZE");
20353
20354 #ifdef CONFIG_SMP
20355diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20356index b07ba93..a212969 100644
20357--- a/arch/x86/kernel/vsyscall_64.c
20358+++ b/arch/x86/kernel/vsyscall_64.c
20359@@ -57,15 +57,13 @@ DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data) =
20360 .lock = __SEQLOCK_UNLOCKED(__vsyscall_gtod_data.lock),
20361 };
20362
20363-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20364+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20365
20366 static int __init vsyscall_setup(char *str)
20367 {
20368 if (str) {
20369 if (!strcmp("emulate", str))
20370 vsyscall_mode = EMULATE;
20371- else if (!strcmp("native", str))
20372- vsyscall_mode = NATIVE;
20373 else if (!strcmp("none", str))
20374 vsyscall_mode = NONE;
20375 else
20376@@ -207,7 +205,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20377
20378 tsk = current;
20379 if (seccomp_mode(&tsk->seccomp))
20380- do_exit(SIGKILL);
20381+ do_group_exit(SIGKILL);
20382
20383 /*
20384 * With a real vsyscall, page faults cause SIGSEGV. We want to
20385@@ -279,8 +277,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20386 return true;
20387
20388 sigsegv:
20389- force_sig(SIGSEGV, current);
20390- return true;
20391+ do_group_exit(SIGKILL);
20392 }
20393
20394 /*
20395@@ -333,10 +330,7 @@ void __init map_vsyscall(void)
20396 extern char __vvar_page;
20397 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20398
20399- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20400- vsyscall_mode == NATIVE
20401- ? PAGE_KERNEL_VSYSCALL
20402- : PAGE_KERNEL_VVAR);
20403+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20404 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20405 (unsigned long)VSYSCALL_START);
20406
20407diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20408index 9796c2f..f686fbf 100644
20409--- a/arch/x86/kernel/x8664_ksyms_64.c
20410+++ b/arch/x86/kernel/x8664_ksyms_64.c
20411@@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20412 EXPORT_SYMBOL(copy_user_generic_string);
20413 EXPORT_SYMBOL(copy_user_generic_unrolled);
20414 EXPORT_SYMBOL(__copy_user_nocache);
20415-EXPORT_SYMBOL(_copy_from_user);
20416-EXPORT_SYMBOL(_copy_to_user);
20417
20418 EXPORT_SYMBOL(copy_page);
20419 EXPORT_SYMBOL(clear_page);
20420diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20421index 7110911..e8cdee5 100644
20422--- a/arch/x86/kernel/xsave.c
20423+++ b/arch/x86/kernel/xsave.c
20424@@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20425 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20426 return -EINVAL;
20427
20428- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20429+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20430 fx_sw_user->extended_size -
20431 FP_XSTATE_MAGIC2_SIZE));
20432 if (err)
20433@@ -266,7 +266,7 @@ fx_only:
20434 * the other extended state.
20435 */
20436 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20437- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20438+ return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20439 }
20440
20441 /*
20442@@ -295,7 +295,7 @@ int restore_i387_xstate(void __user *buf)
20443 if (use_xsave())
20444 err = restore_user_xstate(buf);
20445 else
20446- err = fxrstor_checking((__force struct i387_fxsave_struct *)
20447+ err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20448 buf);
20449 if (unlikely(err)) {
20450 /*
20451diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20452index 89b02bf..0f6511d 100644
20453--- a/arch/x86/kvm/cpuid.c
20454+++ b/arch/x86/kvm/cpuid.c
20455@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20456 struct kvm_cpuid2 *cpuid,
20457 struct kvm_cpuid_entry2 __user *entries)
20458 {
20459- int r;
20460+ int r, i;
20461
20462 r = -E2BIG;
20463 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20464 goto out;
20465 r = -EFAULT;
20466- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20467- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20468+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20469 goto out;
20470+ for (i = 0; i < cpuid->nent; ++i) {
20471+ struct kvm_cpuid_entry2 cpuid_entry;
20472+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20473+ goto out;
20474+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
20475+ }
20476 vcpu->arch.cpuid_nent = cpuid->nent;
20477 kvm_apic_set_version(vcpu);
20478 kvm_x86_ops->cpuid_update(vcpu);
20479@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20480 struct kvm_cpuid2 *cpuid,
20481 struct kvm_cpuid_entry2 __user *entries)
20482 {
20483- int r;
20484+ int r, i;
20485
20486 r = -E2BIG;
20487 if (cpuid->nent < vcpu->arch.cpuid_nent)
20488 goto out;
20489 r = -EFAULT;
20490- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20491- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20492+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20493 goto out;
20494+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20495+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20496+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20497+ goto out;
20498+ }
20499 return 0;
20500
20501 out:
20502diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20503index 0982507..7f6d72f 100644
20504--- a/arch/x86/kvm/emulate.c
20505+++ b/arch/x86/kvm/emulate.c
20506@@ -250,6 +250,7 @@ struct gprefix {
20507
20508 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20509 do { \
20510+ unsigned long _tmp; \
20511 __asm__ __volatile__ ( \
20512 _PRE_EFLAGS("0", "4", "2") \
20513 _op _suffix " %"_x"3,%1; " \
20514@@ -264,8 +265,6 @@ struct gprefix {
20515 /* Raw emulation: instruction has two explicit operands. */
20516 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20517 do { \
20518- unsigned long _tmp; \
20519- \
20520 switch ((ctxt)->dst.bytes) { \
20521 case 2: \
20522 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20523@@ -281,7 +280,6 @@ struct gprefix {
20524
20525 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20526 do { \
20527- unsigned long _tmp; \
20528 switch ((ctxt)->dst.bytes) { \
20529 case 1: \
20530 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20531diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20532index cfdc6e0..ab92e84 100644
20533--- a/arch/x86/kvm/lapic.c
20534+++ b/arch/x86/kvm/lapic.c
20535@@ -54,7 +54,7 @@
20536 #define APIC_BUS_CYCLE_NS 1
20537
20538 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20539-#define apic_debug(fmt, arg...)
20540+#define apic_debug(fmt, arg...) do {} while (0)
20541
20542 #define APIC_LVT_NUM 6
20543 /* 14 is the version for Xeon and Pentium 8.4.8*/
20544diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20545index 1561028..0ed7f14 100644
20546--- a/arch/x86/kvm/paging_tmpl.h
20547+++ b/arch/x86/kvm/paging_tmpl.h
20548@@ -197,7 +197,7 @@ retry_walk:
20549 if (unlikely(kvm_is_error_hva(host_addr)))
20550 goto error;
20551
20552- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20553+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20554 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20555 goto error;
20556
20557diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20558index e385214..f8df033 100644
20559--- a/arch/x86/kvm/svm.c
20560+++ b/arch/x86/kvm/svm.c
20561@@ -3420,7 +3420,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20562 int cpu = raw_smp_processor_id();
20563
20564 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20565+
20566+ pax_open_kernel();
20567 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20568+ pax_close_kernel();
20569+
20570 load_TR_desc();
20571 }
20572
20573@@ -3798,6 +3802,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20574 #endif
20575 #endif
20576
20577+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20578+ __set_fs(current_thread_info()->addr_limit);
20579+#endif
20580+
20581 reload_tss(vcpu);
20582
20583 local_irq_disable();
20584diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20585index a7a6f60..04b745a 100644
20586--- a/arch/x86/kvm/vmx.c
20587+++ b/arch/x86/kvm/vmx.c
20588@@ -1306,7 +1306,11 @@ static void reload_tss(void)
20589 struct desc_struct *descs;
20590
20591 descs = (void *)gdt->address;
20592+
20593+ pax_open_kernel();
20594 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20595+ pax_close_kernel();
20596+
20597 load_TR_desc();
20598 }
20599
20600@@ -2637,8 +2641,11 @@ static __init int hardware_setup(void)
20601 if (!cpu_has_vmx_flexpriority())
20602 flexpriority_enabled = 0;
20603
20604- if (!cpu_has_vmx_tpr_shadow())
20605- kvm_x86_ops->update_cr8_intercept = NULL;
20606+ if (!cpu_has_vmx_tpr_shadow()) {
20607+ pax_open_kernel();
20608+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20609+ pax_close_kernel();
20610+ }
20611
20612 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20613 kvm_disable_largepages();
20614@@ -3654,7 +3661,7 @@ static void vmx_set_constant_host_state(void)
20615 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20616
20617 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20618- vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20619+ vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20620
20621 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20622 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20623@@ -6192,6 +6199,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20624 "jmp .Lkvm_vmx_return \n\t"
20625 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20626 ".Lkvm_vmx_return: "
20627+
20628+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20629+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20630+ ".Lkvm_vmx_return2: "
20631+#endif
20632+
20633 /* Save guest registers, load host registers, keep flags */
20634 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20635 "pop %0 \n\t"
20636@@ -6240,6 +6253,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20637 #endif
20638 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20639 [wordsize]"i"(sizeof(ulong))
20640+
20641+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20642+ ,[cs]"i"(__KERNEL_CS)
20643+#endif
20644+
20645 : "cc", "memory"
20646 , R"ax", R"bx", R"di", R"si"
20647 #ifdef CONFIG_X86_64
20648@@ -6268,7 +6286,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20649 }
20650 }
20651
20652- asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
20653+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20654+
20655+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20656+ loadsegment(fs, __KERNEL_PERCPU);
20657+#endif
20658+
20659+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20660+ __set_fs(current_thread_info()->addr_limit);
20661+#endif
20662+
20663 vmx->loaded_vmcs->launched = 1;
20664
20665 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20666diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20667index 8d1c6c6..99c2d5f 100644
20668--- a/arch/x86/kvm/x86.c
20669+++ b/arch/x86/kvm/x86.c
20670@@ -1311,8 +1311,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20671 {
20672 struct kvm *kvm = vcpu->kvm;
20673 int lm = is_long_mode(vcpu);
20674- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20675- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20676+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20677+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20678 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20679 : kvm->arch.xen_hvm_config.blob_size_32;
20680 u32 page_num = data & ~PAGE_MASK;
20681@@ -2145,6 +2145,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20682 if (n < msr_list.nmsrs)
20683 goto out;
20684 r = -EFAULT;
20685+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20686+ goto out;
20687 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20688 num_msrs_to_save * sizeof(u32)))
20689 goto out;
20690@@ -2266,7 +2268,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20691 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20692 struct kvm_interrupt *irq)
20693 {
20694- if (irq->irq < 0 || irq->irq >= 256)
20695+ if (irq->irq >= 256)
20696 return -EINVAL;
20697 if (irqchip_in_kernel(vcpu->kvm))
20698 return -ENXIO;
20699@@ -4782,7 +4784,7 @@ static void kvm_set_mmio_spte_mask(void)
20700 kvm_mmu_set_mmio_spte_mask(mask);
20701 }
20702
20703-int kvm_arch_init(void *opaque)
20704+int kvm_arch_init(const void *opaque)
20705 {
20706 int r;
20707 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20708diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20709index 642d880..44e0f3f 100644
20710--- a/arch/x86/lguest/boot.c
20711+++ b/arch/x86/lguest/boot.c
20712@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20713 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20714 * Launcher to reboot us.
20715 */
20716-static void lguest_restart(char *reason)
20717+static __noreturn void lguest_restart(char *reason)
20718 {
20719 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20720+ BUG();
20721 }
20722
20723 /*G:050
20724diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
20725index 042f682..c92afb6 100644
20726--- a/arch/x86/lib/atomic64_32.c
20727+++ b/arch/x86/lib/atomic64_32.c
20728@@ -8,18 +8,30 @@
20729
20730 long long atomic64_read_cx8(long long, const atomic64_t *v);
20731 EXPORT_SYMBOL(atomic64_read_cx8);
20732+long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
20733+EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
20734 long long atomic64_set_cx8(long long, const atomic64_t *v);
20735 EXPORT_SYMBOL(atomic64_set_cx8);
20736+long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
20737+EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
20738 long long atomic64_xchg_cx8(long long, unsigned high);
20739 EXPORT_SYMBOL(atomic64_xchg_cx8);
20740 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
20741 EXPORT_SYMBOL(atomic64_add_return_cx8);
20742+long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20743+EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
20744 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
20745 EXPORT_SYMBOL(atomic64_sub_return_cx8);
20746+long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20747+EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
20748 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
20749 EXPORT_SYMBOL(atomic64_inc_return_cx8);
20750+long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20751+EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
20752 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
20753 EXPORT_SYMBOL(atomic64_dec_return_cx8);
20754+long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20755+EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
20756 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
20757 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
20758 int atomic64_inc_not_zero_cx8(atomic64_t *v);
20759@@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
20760 #ifndef CONFIG_X86_CMPXCHG64
20761 long long atomic64_read_386(long long, const atomic64_t *v);
20762 EXPORT_SYMBOL(atomic64_read_386);
20763+long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
20764+EXPORT_SYMBOL(atomic64_read_unchecked_386);
20765 long long atomic64_set_386(long long, const atomic64_t *v);
20766 EXPORT_SYMBOL(atomic64_set_386);
20767+long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
20768+EXPORT_SYMBOL(atomic64_set_unchecked_386);
20769 long long atomic64_xchg_386(long long, unsigned high);
20770 EXPORT_SYMBOL(atomic64_xchg_386);
20771 long long atomic64_add_return_386(long long a, atomic64_t *v);
20772 EXPORT_SYMBOL(atomic64_add_return_386);
20773+long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20774+EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
20775 long long atomic64_sub_return_386(long long a, atomic64_t *v);
20776 EXPORT_SYMBOL(atomic64_sub_return_386);
20777+long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20778+EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
20779 long long atomic64_inc_return_386(long long a, atomic64_t *v);
20780 EXPORT_SYMBOL(atomic64_inc_return_386);
20781+long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20782+EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
20783 long long atomic64_dec_return_386(long long a, atomic64_t *v);
20784 EXPORT_SYMBOL(atomic64_dec_return_386);
20785+long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20786+EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
20787 long long atomic64_add_386(long long a, atomic64_t *v);
20788 EXPORT_SYMBOL(atomic64_add_386);
20789+long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
20790+EXPORT_SYMBOL(atomic64_add_unchecked_386);
20791 long long atomic64_sub_386(long long a, atomic64_t *v);
20792 EXPORT_SYMBOL(atomic64_sub_386);
20793+long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
20794+EXPORT_SYMBOL(atomic64_sub_unchecked_386);
20795 long long atomic64_inc_386(long long a, atomic64_t *v);
20796 EXPORT_SYMBOL(atomic64_inc_386);
20797+long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
20798+EXPORT_SYMBOL(atomic64_inc_unchecked_386);
20799 long long atomic64_dec_386(long long a, atomic64_t *v);
20800 EXPORT_SYMBOL(atomic64_dec_386);
20801+long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
20802+EXPORT_SYMBOL(atomic64_dec_unchecked_386);
20803 long long atomic64_dec_if_positive_386(atomic64_t *v);
20804 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
20805 int atomic64_inc_not_zero_386(atomic64_t *v);
20806diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20807index e8e7e0d..56fd1b0 100644
20808--- a/arch/x86/lib/atomic64_386_32.S
20809+++ b/arch/x86/lib/atomic64_386_32.S
20810@@ -48,6 +48,10 @@ BEGIN(read)
20811 movl (v), %eax
20812 movl 4(v), %edx
20813 RET_ENDP
20814+BEGIN(read_unchecked)
20815+ movl (v), %eax
20816+ movl 4(v), %edx
20817+RET_ENDP
20818 #undef v
20819
20820 #define v %esi
20821@@ -55,6 +59,10 @@ BEGIN(set)
20822 movl %ebx, (v)
20823 movl %ecx, 4(v)
20824 RET_ENDP
20825+BEGIN(set_unchecked)
20826+ movl %ebx, (v)
20827+ movl %ecx, 4(v)
20828+RET_ENDP
20829 #undef v
20830
20831 #define v %esi
20832@@ -70,6 +78,20 @@ RET_ENDP
20833 BEGIN(add)
20834 addl %eax, (v)
20835 adcl %edx, 4(v)
20836+
20837+#ifdef CONFIG_PAX_REFCOUNT
20838+ jno 0f
20839+ subl %eax, (v)
20840+ sbbl %edx, 4(v)
20841+ int $4
20842+0:
20843+ _ASM_EXTABLE(0b, 0b)
20844+#endif
20845+
20846+RET_ENDP
20847+BEGIN(add_unchecked)
20848+ addl %eax, (v)
20849+ adcl %edx, 4(v)
20850 RET_ENDP
20851 #undef v
20852
20853@@ -77,6 +99,24 @@ RET_ENDP
20854 BEGIN(add_return)
20855 addl (v), %eax
20856 adcl 4(v), %edx
20857+
20858+#ifdef CONFIG_PAX_REFCOUNT
20859+ into
20860+1234:
20861+ _ASM_EXTABLE(1234b, 2f)
20862+#endif
20863+
20864+ movl %eax, (v)
20865+ movl %edx, 4(v)
20866+
20867+#ifdef CONFIG_PAX_REFCOUNT
20868+2:
20869+#endif
20870+
20871+RET_ENDP
20872+BEGIN(add_return_unchecked)
20873+ addl (v), %eax
20874+ adcl 4(v), %edx
20875 movl %eax, (v)
20876 movl %edx, 4(v)
20877 RET_ENDP
20878@@ -86,6 +126,20 @@ RET_ENDP
20879 BEGIN(sub)
20880 subl %eax, (v)
20881 sbbl %edx, 4(v)
20882+
20883+#ifdef CONFIG_PAX_REFCOUNT
20884+ jno 0f
20885+ addl %eax, (v)
20886+ adcl %edx, 4(v)
20887+ int $4
20888+0:
20889+ _ASM_EXTABLE(0b, 0b)
20890+#endif
20891+
20892+RET_ENDP
20893+BEGIN(sub_unchecked)
20894+ subl %eax, (v)
20895+ sbbl %edx, 4(v)
20896 RET_ENDP
20897 #undef v
20898
20899@@ -96,6 +150,27 @@ BEGIN(sub_return)
20900 sbbl $0, %edx
20901 addl (v), %eax
20902 adcl 4(v), %edx
20903+
20904+#ifdef CONFIG_PAX_REFCOUNT
20905+ into
20906+1234:
20907+ _ASM_EXTABLE(1234b, 2f)
20908+#endif
20909+
20910+ movl %eax, (v)
20911+ movl %edx, 4(v)
20912+
20913+#ifdef CONFIG_PAX_REFCOUNT
20914+2:
20915+#endif
20916+
20917+RET_ENDP
20918+BEGIN(sub_return_unchecked)
20919+ negl %edx
20920+ negl %eax
20921+ sbbl $0, %edx
20922+ addl (v), %eax
20923+ adcl 4(v), %edx
20924 movl %eax, (v)
20925 movl %edx, 4(v)
20926 RET_ENDP
20927@@ -105,6 +180,20 @@ RET_ENDP
20928 BEGIN(inc)
20929 addl $1, (v)
20930 adcl $0, 4(v)
20931+
20932+#ifdef CONFIG_PAX_REFCOUNT
20933+ jno 0f
20934+ subl $1, (v)
20935+ sbbl $0, 4(v)
20936+ int $4
20937+0:
20938+ _ASM_EXTABLE(0b, 0b)
20939+#endif
20940+
20941+RET_ENDP
20942+BEGIN(inc_unchecked)
20943+ addl $1, (v)
20944+ adcl $0, 4(v)
20945 RET_ENDP
20946 #undef v
20947
20948@@ -114,6 +203,26 @@ BEGIN(inc_return)
20949 movl 4(v), %edx
20950 addl $1, %eax
20951 adcl $0, %edx
20952+
20953+#ifdef CONFIG_PAX_REFCOUNT
20954+ into
20955+1234:
20956+ _ASM_EXTABLE(1234b, 2f)
20957+#endif
20958+
20959+ movl %eax, (v)
20960+ movl %edx, 4(v)
20961+
20962+#ifdef CONFIG_PAX_REFCOUNT
20963+2:
20964+#endif
20965+
20966+RET_ENDP
20967+BEGIN(inc_return_unchecked)
20968+ movl (v), %eax
20969+ movl 4(v), %edx
20970+ addl $1, %eax
20971+ adcl $0, %edx
20972 movl %eax, (v)
20973 movl %edx, 4(v)
20974 RET_ENDP
20975@@ -123,6 +232,20 @@ RET_ENDP
20976 BEGIN(dec)
20977 subl $1, (v)
20978 sbbl $0, 4(v)
20979+
20980+#ifdef CONFIG_PAX_REFCOUNT
20981+ jno 0f
20982+ addl $1, (v)
20983+ adcl $0, 4(v)
20984+ int $4
20985+0:
20986+ _ASM_EXTABLE(0b, 0b)
20987+#endif
20988+
20989+RET_ENDP
20990+BEGIN(dec_unchecked)
20991+ subl $1, (v)
20992+ sbbl $0, 4(v)
20993 RET_ENDP
20994 #undef v
20995
20996@@ -132,6 +255,26 @@ BEGIN(dec_return)
20997 movl 4(v), %edx
20998 subl $1, %eax
20999 sbbl $0, %edx
21000+
21001+#ifdef CONFIG_PAX_REFCOUNT
21002+ into
21003+1234:
21004+ _ASM_EXTABLE(1234b, 2f)
21005+#endif
21006+
21007+ movl %eax, (v)
21008+ movl %edx, 4(v)
21009+
21010+#ifdef CONFIG_PAX_REFCOUNT
21011+2:
21012+#endif
21013+
21014+RET_ENDP
21015+BEGIN(dec_return_unchecked)
21016+ movl (v), %eax
21017+ movl 4(v), %edx
21018+ subl $1, %eax
21019+ sbbl $0, %edx
21020 movl %eax, (v)
21021 movl %edx, 4(v)
21022 RET_ENDP
21023@@ -143,6 +286,13 @@ BEGIN(add_unless)
21024 adcl %edx, %edi
21025 addl (v), %eax
21026 adcl 4(v), %edx
21027+
21028+#ifdef CONFIG_PAX_REFCOUNT
21029+ into
21030+1234:
21031+ _ASM_EXTABLE(1234b, 2f)
21032+#endif
21033+
21034 cmpl %eax, %esi
21035 je 3f
21036 1:
21037@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
21038 1:
21039 addl $1, %eax
21040 adcl $0, %edx
21041+
21042+#ifdef CONFIG_PAX_REFCOUNT
21043+ into
21044+1234:
21045+ _ASM_EXTABLE(1234b, 2f)
21046+#endif
21047+
21048 movl %eax, (v)
21049 movl %edx, 4(v)
21050 movl $1, %eax
21051@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
21052 movl 4(v), %edx
21053 subl $1, %eax
21054 sbbl $0, %edx
21055+
21056+#ifdef CONFIG_PAX_REFCOUNT
21057+ into
21058+1234:
21059+ _ASM_EXTABLE(1234b, 1f)
21060+#endif
21061+
21062 js 1f
21063 movl %eax, (v)
21064 movl %edx, 4(v)
21065diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
21066index 391a083..3a2cf39 100644
21067--- a/arch/x86/lib/atomic64_cx8_32.S
21068+++ b/arch/x86/lib/atomic64_cx8_32.S
21069@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
21070 CFI_STARTPROC
21071
21072 read64 %ecx
21073+ pax_force_retaddr
21074 ret
21075 CFI_ENDPROC
21076 ENDPROC(atomic64_read_cx8)
21077
21078+ENTRY(atomic64_read_unchecked_cx8)
21079+ CFI_STARTPROC
21080+
21081+ read64 %ecx
21082+ pax_force_retaddr
21083+ ret
21084+ CFI_ENDPROC
21085+ENDPROC(atomic64_read_unchecked_cx8)
21086+
21087 ENTRY(atomic64_set_cx8)
21088 CFI_STARTPROC
21089
21090@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
21091 cmpxchg8b (%esi)
21092 jne 1b
21093
21094+ pax_force_retaddr
21095 ret
21096 CFI_ENDPROC
21097 ENDPROC(atomic64_set_cx8)
21098
21099+ENTRY(atomic64_set_unchecked_cx8)
21100+ CFI_STARTPROC
21101+
21102+1:
21103+/* we don't need LOCK_PREFIX since aligned 64-bit writes
21104+ * are atomic on 586 and newer */
21105+ cmpxchg8b (%esi)
21106+ jne 1b
21107+
21108+ pax_force_retaddr
21109+ ret
21110+ CFI_ENDPROC
21111+ENDPROC(atomic64_set_unchecked_cx8)
21112+
21113 ENTRY(atomic64_xchg_cx8)
21114 CFI_STARTPROC
21115
21116@@ -62,12 +87,13 @@ ENTRY(atomic64_xchg_cx8)
21117 cmpxchg8b (%esi)
21118 jne 1b
21119
21120+ pax_force_retaddr
21121 ret
21122 CFI_ENDPROC
21123 ENDPROC(atomic64_xchg_cx8)
21124
21125-.macro addsub_return func ins insc
21126-ENTRY(atomic64_\func\()_return_cx8)
21127+.macro addsub_return func ins insc unchecked=""
21128+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21129 CFI_STARTPROC
21130 SAVE ebp
21131 SAVE ebx
21132@@ -84,27 +110,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21133 movl %edx, %ecx
21134 \ins\()l %esi, %ebx
21135 \insc\()l %edi, %ecx
21136+
21137+.ifb \unchecked
21138+#ifdef CONFIG_PAX_REFCOUNT
21139+ into
21140+2:
21141+ _ASM_EXTABLE(2b, 3f)
21142+#endif
21143+.endif
21144+
21145 LOCK_PREFIX
21146 cmpxchg8b (%ebp)
21147 jne 1b
21148-
21149-10:
21150 movl %ebx, %eax
21151 movl %ecx, %edx
21152+
21153+.ifb \unchecked
21154+#ifdef CONFIG_PAX_REFCOUNT
21155+3:
21156+#endif
21157+.endif
21158+
21159 RESTORE edi
21160 RESTORE esi
21161 RESTORE ebx
21162 RESTORE ebp
21163+ pax_force_retaddr
21164 ret
21165 CFI_ENDPROC
21166-ENDPROC(atomic64_\func\()_return_cx8)
21167+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21168 .endm
21169
21170 addsub_return add add adc
21171 addsub_return sub sub sbb
21172+addsub_return add add adc _unchecked
21173+addsub_return sub sub sbb _unchecked
21174
21175-.macro incdec_return func ins insc
21176-ENTRY(atomic64_\func\()_return_cx8)
21177+.macro incdec_return func ins insc unchecked=""
21178+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21179 CFI_STARTPROC
21180 SAVE ebx
21181
21182@@ -114,21 +157,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21183 movl %edx, %ecx
21184 \ins\()l $1, %ebx
21185 \insc\()l $0, %ecx
21186+
21187+.ifb \unchecked
21188+#ifdef CONFIG_PAX_REFCOUNT
21189+ into
21190+2:
21191+ _ASM_EXTABLE(2b, 3f)
21192+#endif
21193+.endif
21194+
21195 LOCK_PREFIX
21196 cmpxchg8b (%esi)
21197 jne 1b
21198
21199-10:
21200 movl %ebx, %eax
21201 movl %ecx, %edx
21202+
21203+.ifb \unchecked
21204+#ifdef CONFIG_PAX_REFCOUNT
21205+3:
21206+#endif
21207+.endif
21208+
21209 RESTORE ebx
21210+ pax_force_retaddr
21211 ret
21212 CFI_ENDPROC
21213-ENDPROC(atomic64_\func\()_return_cx8)
21214+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21215 .endm
21216
21217 incdec_return inc add adc
21218 incdec_return dec sub sbb
21219+incdec_return inc add adc _unchecked
21220+incdec_return dec sub sbb _unchecked
21221
21222 ENTRY(atomic64_dec_if_positive_cx8)
21223 CFI_STARTPROC
21224@@ -140,6 +201,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21225 movl %edx, %ecx
21226 subl $1, %ebx
21227 sbb $0, %ecx
21228+
21229+#ifdef CONFIG_PAX_REFCOUNT
21230+ into
21231+1234:
21232+ _ASM_EXTABLE(1234b, 2f)
21233+#endif
21234+
21235 js 2f
21236 LOCK_PREFIX
21237 cmpxchg8b (%esi)
21238@@ -149,6 +217,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21239 movl %ebx, %eax
21240 movl %ecx, %edx
21241 RESTORE ebx
21242+ pax_force_retaddr
21243 ret
21244 CFI_ENDPROC
21245 ENDPROC(atomic64_dec_if_positive_cx8)
21246@@ -174,6 +243,13 @@ ENTRY(atomic64_add_unless_cx8)
21247 movl %edx, %ecx
21248 addl %esi, %ebx
21249 adcl %edi, %ecx
21250+
21251+#ifdef CONFIG_PAX_REFCOUNT
21252+ into
21253+1234:
21254+ _ASM_EXTABLE(1234b, 3f)
21255+#endif
21256+
21257 LOCK_PREFIX
21258 cmpxchg8b (%ebp)
21259 jne 1b
21260@@ -184,6 +260,7 @@ ENTRY(atomic64_add_unless_cx8)
21261 CFI_ADJUST_CFA_OFFSET -8
21262 RESTORE ebx
21263 RESTORE ebp
21264+ pax_force_retaddr
21265 ret
21266 4:
21267 cmpl %edx, 4(%esp)
21268@@ -206,6 +283,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21269 movl %edx, %ecx
21270 addl $1, %ebx
21271 adcl $0, %ecx
21272+
21273+#ifdef CONFIG_PAX_REFCOUNT
21274+ into
21275+1234:
21276+ _ASM_EXTABLE(1234b, 3f)
21277+#endif
21278+
21279 LOCK_PREFIX
21280 cmpxchg8b (%esi)
21281 jne 1b
21282@@ -213,6 +297,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21283 movl $1, %eax
21284 3:
21285 RESTORE ebx
21286+ pax_force_retaddr
21287 ret
21288 4:
21289 testl %edx, %edx
21290diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21291index 78d16a5..fbcf666 100644
21292--- a/arch/x86/lib/checksum_32.S
21293+++ b/arch/x86/lib/checksum_32.S
21294@@ -28,7 +28,8 @@
21295 #include <linux/linkage.h>
21296 #include <asm/dwarf2.h>
21297 #include <asm/errno.h>
21298-
21299+#include <asm/segment.h>
21300+
21301 /*
21302 * computes a partial checksum, e.g. for TCP/UDP fragments
21303 */
21304@@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21305
21306 #define ARGBASE 16
21307 #define FP 12
21308-
21309-ENTRY(csum_partial_copy_generic)
21310+
21311+ENTRY(csum_partial_copy_generic_to_user)
21312 CFI_STARTPROC
21313+
21314+#ifdef CONFIG_PAX_MEMORY_UDEREF
21315+ pushl_cfi %gs
21316+ popl_cfi %es
21317+ jmp csum_partial_copy_generic
21318+#endif
21319+
21320+ENTRY(csum_partial_copy_generic_from_user)
21321+
21322+#ifdef CONFIG_PAX_MEMORY_UDEREF
21323+ pushl_cfi %gs
21324+ popl_cfi %ds
21325+#endif
21326+
21327+ENTRY(csum_partial_copy_generic)
21328 subl $4,%esp
21329 CFI_ADJUST_CFA_OFFSET 4
21330 pushl_cfi %edi
21331@@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
21332 jmp 4f
21333 SRC(1: movw (%esi), %bx )
21334 addl $2, %esi
21335-DST( movw %bx, (%edi) )
21336+DST( movw %bx, %es:(%edi) )
21337 addl $2, %edi
21338 addw %bx, %ax
21339 adcl $0, %eax
21340@@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
21341 SRC(1: movl (%esi), %ebx )
21342 SRC( movl 4(%esi), %edx )
21343 adcl %ebx, %eax
21344-DST( movl %ebx, (%edi) )
21345+DST( movl %ebx, %es:(%edi) )
21346 adcl %edx, %eax
21347-DST( movl %edx, 4(%edi) )
21348+DST( movl %edx, %es:4(%edi) )
21349
21350 SRC( movl 8(%esi), %ebx )
21351 SRC( movl 12(%esi), %edx )
21352 adcl %ebx, %eax
21353-DST( movl %ebx, 8(%edi) )
21354+DST( movl %ebx, %es:8(%edi) )
21355 adcl %edx, %eax
21356-DST( movl %edx, 12(%edi) )
21357+DST( movl %edx, %es:12(%edi) )
21358
21359 SRC( movl 16(%esi), %ebx )
21360 SRC( movl 20(%esi), %edx )
21361 adcl %ebx, %eax
21362-DST( movl %ebx, 16(%edi) )
21363+DST( movl %ebx, %es:16(%edi) )
21364 adcl %edx, %eax
21365-DST( movl %edx, 20(%edi) )
21366+DST( movl %edx, %es:20(%edi) )
21367
21368 SRC( movl 24(%esi), %ebx )
21369 SRC( movl 28(%esi), %edx )
21370 adcl %ebx, %eax
21371-DST( movl %ebx, 24(%edi) )
21372+DST( movl %ebx, %es:24(%edi) )
21373 adcl %edx, %eax
21374-DST( movl %edx, 28(%edi) )
21375+DST( movl %edx, %es:28(%edi) )
21376
21377 lea 32(%esi), %esi
21378 lea 32(%edi), %edi
21379@@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
21380 shrl $2, %edx # This clears CF
21381 SRC(3: movl (%esi), %ebx )
21382 adcl %ebx, %eax
21383-DST( movl %ebx, (%edi) )
21384+DST( movl %ebx, %es:(%edi) )
21385 lea 4(%esi), %esi
21386 lea 4(%edi), %edi
21387 dec %edx
21388@@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
21389 jb 5f
21390 SRC( movw (%esi), %cx )
21391 leal 2(%esi), %esi
21392-DST( movw %cx, (%edi) )
21393+DST( movw %cx, %es:(%edi) )
21394 leal 2(%edi), %edi
21395 je 6f
21396 shll $16,%ecx
21397 SRC(5: movb (%esi), %cl )
21398-DST( movb %cl, (%edi) )
21399+DST( movb %cl, %es:(%edi) )
21400 6: addl %ecx, %eax
21401 adcl $0, %eax
21402 7:
21403@@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
21404
21405 6001:
21406 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21407- movl $-EFAULT, (%ebx)
21408+ movl $-EFAULT, %ss:(%ebx)
21409
21410 # zero the complete destination - computing the rest
21411 # is too much work
21412@@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
21413
21414 6002:
21415 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21416- movl $-EFAULT,(%ebx)
21417+ movl $-EFAULT,%ss:(%ebx)
21418 jmp 5000b
21419
21420 .previous
21421
21422+ pushl_cfi %ss
21423+ popl_cfi %ds
21424+ pushl_cfi %ss
21425+ popl_cfi %es
21426 popl_cfi %ebx
21427 CFI_RESTORE ebx
21428 popl_cfi %esi
21429@@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
21430 popl_cfi %ecx # equivalent to addl $4,%esp
21431 ret
21432 CFI_ENDPROC
21433-ENDPROC(csum_partial_copy_generic)
21434+ENDPROC(csum_partial_copy_generic_to_user)
21435
21436 #else
21437
21438 /* Version for PentiumII/PPro */
21439
21440 #define ROUND1(x) \
21441+ nop; nop; nop; \
21442 SRC(movl x(%esi), %ebx ) ; \
21443 addl %ebx, %eax ; \
21444- DST(movl %ebx, x(%edi) ) ;
21445+ DST(movl %ebx, %es:x(%edi)) ;
21446
21447 #define ROUND(x) \
21448+ nop; nop; nop; \
21449 SRC(movl x(%esi), %ebx ) ; \
21450 adcl %ebx, %eax ; \
21451- DST(movl %ebx, x(%edi) ) ;
21452+ DST(movl %ebx, %es:x(%edi)) ;
21453
21454 #define ARGBASE 12
21455-
21456-ENTRY(csum_partial_copy_generic)
21457+
21458+ENTRY(csum_partial_copy_generic_to_user)
21459 CFI_STARTPROC
21460+
21461+#ifdef CONFIG_PAX_MEMORY_UDEREF
21462+ pushl_cfi %gs
21463+ popl_cfi %es
21464+ jmp csum_partial_copy_generic
21465+#endif
21466+
21467+ENTRY(csum_partial_copy_generic_from_user)
21468+
21469+#ifdef CONFIG_PAX_MEMORY_UDEREF
21470+ pushl_cfi %gs
21471+ popl_cfi %ds
21472+#endif
21473+
21474+ENTRY(csum_partial_copy_generic)
21475 pushl_cfi %ebx
21476 CFI_REL_OFFSET ebx, 0
21477 pushl_cfi %edi
21478@@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
21479 subl %ebx, %edi
21480 lea -1(%esi),%edx
21481 andl $-32,%edx
21482- lea 3f(%ebx,%ebx), %ebx
21483+ lea 3f(%ebx,%ebx,2), %ebx
21484 testl %esi, %esi
21485 jmp *%ebx
21486 1: addl $64,%esi
21487@@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
21488 jb 5f
21489 SRC( movw (%esi), %dx )
21490 leal 2(%esi), %esi
21491-DST( movw %dx, (%edi) )
21492+DST( movw %dx, %es:(%edi) )
21493 leal 2(%edi), %edi
21494 je 6f
21495 shll $16,%edx
21496 5:
21497 SRC( movb (%esi), %dl )
21498-DST( movb %dl, (%edi) )
21499+DST( movb %dl, %es:(%edi) )
21500 6: addl %edx, %eax
21501 adcl $0, %eax
21502 7:
21503 .section .fixup, "ax"
21504 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21505- movl $-EFAULT, (%ebx)
21506+ movl $-EFAULT, %ss:(%ebx)
21507 # zero the complete destination (computing the rest is too much work)
21508 movl ARGBASE+8(%esp),%edi # dst
21509 movl ARGBASE+12(%esp),%ecx # len
21510@@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
21511 rep; stosb
21512 jmp 7b
21513 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21514- movl $-EFAULT, (%ebx)
21515+ movl $-EFAULT, %ss:(%ebx)
21516 jmp 7b
21517 .previous
21518
21519+#ifdef CONFIG_PAX_MEMORY_UDEREF
21520+ pushl_cfi %ss
21521+ popl_cfi %ds
21522+ pushl_cfi %ss
21523+ popl_cfi %es
21524+#endif
21525+
21526 popl_cfi %esi
21527 CFI_RESTORE esi
21528 popl_cfi %edi
21529@@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
21530 CFI_RESTORE ebx
21531 ret
21532 CFI_ENDPROC
21533-ENDPROC(csum_partial_copy_generic)
21534+ENDPROC(csum_partial_copy_generic_to_user)
21535
21536 #undef ROUND
21537 #undef ROUND1
21538diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21539index f2145cf..cea889d 100644
21540--- a/arch/x86/lib/clear_page_64.S
21541+++ b/arch/x86/lib/clear_page_64.S
21542@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21543 movl $4096/8,%ecx
21544 xorl %eax,%eax
21545 rep stosq
21546+ pax_force_retaddr
21547 ret
21548 CFI_ENDPROC
21549 ENDPROC(clear_page_c)
21550@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21551 movl $4096,%ecx
21552 xorl %eax,%eax
21553 rep stosb
21554+ pax_force_retaddr
21555 ret
21556 CFI_ENDPROC
21557 ENDPROC(clear_page_c_e)
21558@@ -43,6 +45,7 @@ ENTRY(clear_page)
21559 leaq 64(%rdi),%rdi
21560 jnz .Lloop
21561 nop
21562+ pax_force_retaddr
21563 ret
21564 CFI_ENDPROC
21565 .Lclear_page_end:
21566@@ -58,7 +61,7 @@ ENDPROC(clear_page)
21567
21568 #include <asm/cpufeature.h>
21569
21570- .section .altinstr_replacement,"ax"
21571+ .section .altinstr_replacement,"a"
21572 1: .byte 0xeb /* jmp <disp8> */
21573 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21574 2: .byte 0xeb /* jmp <disp8> */
21575diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21576index 1e572c5..2a162cd 100644
21577--- a/arch/x86/lib/cmpxchg16b_emu.S
21578+++ b/arch/x86/lib/cmpxchg16b_emu.S
21579@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21580
21581 popf
21582 mov $1, %al
21583+ pax_force_retaddr
21584 ret
21585
21586 not_same:
21587 popf
21588 xor %al,%al
21589+ pax_force_retaddr
21590 ret
21591
21592 CFI_ENDPROC
21593diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21594index 01c805b..dccb07f 100644
21595--- a/arch/x86/lib/copy_page_64.S
21596+++ b/arch/x86/lib/copy_page_64.S
21597@@ -9,6 +9,7 @@ copy_page_c:
21598 CFI_STARTPROC
21599 movl $4096/8,%ecx
21600 rep movsq
21601+ pax_force_retaddr
21602 ret
21603 CFI_ENDPROC
21604 ENDPROC(copy_page_c)
21605@@ -39,7 +40,7 @@ ENTRY(copy_page)
21606 movq 16 (%rsi), %rdx
21607 movq 24 (%rsi), %r8
21608 movq 32 (%rsi), %r9
21609- movq 40 (%rsi), %r10
21610+ movq 40 (%rsi), %r13
21611 movq 48 (%rsi), %r11
21612 movq 56 (%rsi), %r12
21613
21614@@ -50,7 +51,7 @@ ENTRY(copy_page)
21615 movq %rdx, 16 (%rdi)
21616 movq %r8, 24 (%rdi)
21617 movq %r9, 32 (%rdi)
21618- movq %r10, 40 (%rdi)
21619+ movq %r13, 40 (%rdi)
21620 movq %r11, 48 (%rdi)
21621 movq %r12, 56 (%rdi)
21622
21623@@ -69,7 +70,7 @@ ENTRY(copy_page)
21624 movq 16 (%rsi), %rdx
21625 movq 24 (%rsi), %r8
21626 movq 32 (%rsi), %r9
21627- movq 40 (%rsi), %r10
21628+ movq 40 (%rsi), %r13
21629 movq 48 (%rsi), %r11
21630 movq 56 (%rsi), %r12
21631
21632@@ -78,7 +79,7 @@ ENTRY(copy_page)
21633 movq %rdx, 16 (%rdi)
21634 movq %r8, 24 (%rdi)
21635 movq %r9, 32 (%rdi)
21636- movq %r10, 40 (%rdi)
21637+ movq %r13, 40 (%rdi)
21638 movq %r11, 48 (%rdi)
21639 movq %r12, 56 (%rdi)
21640
21641@@ -95,6 +96,7 @@ ENTRY(copy_page)
21642 CFI_RESTORE r13
21643 addq $3*8,%rsp
21644 CFI_ADJUST_CFA_OFFSET -3*8
21645+ pax_force_retaddr
21646 ret
21647 .Lcopy_page_end:
21648 CFI_ENDPROC
21649@@ -105,7 +107,7 @@ ENDPROC(copy_page)
21650
21651 #include <asm/cpufeature.h>
21652
21653- .section .altinstr_replacement,"ax"
21654+ .section .altinstr_replacement,"a"
21655 1: .byte 0xeb /* jmp <disp8> */
21656 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21657 2:
21658diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21659index 0248402..821c786 100644
21660--- a/arch/x86/lib/copy_user_64.S
21661+++ b/arch/x86/lib/copy_user_64.S
21662@@ -16,6 +16,7 @@
21663 #include <asm/thread_info.h>
21664 #include <asm/cpufeature.h>
21665 #include <asm/alternative-asm.h>
21666+#include <asm/pgtable.h>
21667
21668 /*
21669 * By placing feature2 after feature1 in altinstructions section, we logically
21670@@ -29,7 +30,7 @@
21671 .byte 0xe9 /* 32bit jump */
21672 .long \orig-1f /* by default jump to orig */
21673 1:
21674- .section .altinstr_replacement,"ax"
21675+ .section .altinstr_replacement,"a"
21676 2: .byte 0xe9 /* near jump with 32bit immediate */
21677 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21678 3: .byte 0xe9 /* near jump with 32bit immediate */
21679@@ -71,47 +72,20 @@
21680 #endif
21681 .endm
21682
21683-/* Standard copy_to_user with segment limit checking */
21684-ENTRY(_copy_to_user)
21685- CFI_STARTPROC
21686- GET_THREAD_INFO(%rax)
21687- movq %rdi,%rcx
21688- addq %rdx,%rcx
21689- jc bad_to_user
21690- cmpq TI_addr_limit(%rax),%rcx
21691- ja bad_to_user
21692- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21693- copy_user_generic_unrolled,copy_user_generic_string, \
21694- copy_user_enhanced_fast_string
21695- CFI_ENDPROC
21696-ENDPROC(_copy_to_user)
21697-
21698-/* Standard copy_from_user with segment limit checking */
21699-ENTRY(_copy_from_user)
21700- CFI_STARTPROC
21701- GET_THREAD_INFO(%rax)
21702- movq %rsi,%rcx
21703- addq %rdx,%rcx
21704- jc bad_from_user
21705- cmpq TI_addr_limit(%rax),%rcx
21706- ja bad_from_user
21707- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21708- copy_user_generic_unrolled,copy_user_generic_string, \
21709- copy_user_enhanced_fast_string
21710- CFI_ENDPROC
21711-ENDPROC(_copy_from_user)
21712-
21713 .section .fixup,"ax"
21714 /* must zero dest */
21715 ENTRY(bad_from_user)
21716 bad_from_user:
21717 CFI_STARTPROC
21718+ testl %edx,%edx
21719+ js bad_to_user
21720 movl %edx,%ecx
21721 xorl %eax,%eax
21722 rep
21723 stosb
21724 bad_to_user:
21725 movl %edx,%eax
21726+ pax_force_retaddr
21727 ret
21728 CFI_ENDPROC
21729 ENDPROC(bad_from_user)
21730@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
21731 jz 17f
21732 1: movq (%rsi),%r8
21733 2: movq 1*8(%rsi),%r9
21734-3: movq 2*8(%rsi),%r10
21735+3: movq 2*8(%rsi),%rax
21736 4: movq 3*8(%rsi),%r11
21737 5: movq %r8,(%rdi)
21738 6: movq %r9,1*8(%rdi)
21739-7: movq %r10,2*8(%rdi)
21740+7: movq %rax,2*8(%rdi)
21741 8: movq %r11,3*8(%rdi)
21742 9: movq 4*8(%rsi),%r8
21743 10: movq 5*8(%rsi),%r9
21744-11: movq 6*8(%rsi),%r10
21745+11: movq 6*8(%rsi),%rax
21746 12: movq 7*8(%rsi),%r11
21747 13: movq %r8,4*8(%rdi)
21748 14: movq %r9,5*8(%rdi)
21749-15: movq %r10,6*8(%rdi)
21750+15: movq %rax,6*8(%rdi)
21751 16: movq %r11,7*8(%rdi)
21752 leaq 64(%rsi),%rsi
21753 leaq 64(%rdi),%rdi
21754@@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
21755 decl %ecx
21756 jnz 21b
21757 23: xor %eax,%eax
21758+ pax_force_retaddr
21759 ret
21760
21761 .section .fixup,"ax"
21762@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
21763 3: rep
21764 movsb
21765 4: xorl %eax,%eax
21766+ pax_force_retaddr
21767 ret
21768
21769 .section .fixup,"ax"
21770@@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
21771 1: rep
21772 movsb
21773 2: xorl %eax,%eax
21774+ pax_force_retaddr
21775 ret
21776
21777 .section .fixup,"ax"
21778diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21779index cb0c112..e3a6895 100644
21780--- a/arch/x86/lib/copy_user_nocache_64.S
21781+++ b/arch/x86/lib/copy_user_nocache_64.S
21782@@ -8,12 +8,14 @@
21783
21784 #include <linux/linkage.h>
21785 #include <asm/dwarf2.h>
21786+#include <asm/alternative-asm.h>
21787
21788 #define FIX_ALIGNMENT 1
21789
21790 #include <asm/current.h>
21791 #include <asm/asm-offsets.h>
21792 #include <asm/thread_info.h>
21793+#include <asm/pgtable.h>
21794
21795 .macro ALIGN_DESTINATION
21796 #ifdef FIX_ALIGNMENT
21797@@ -50,6 +52,15 @@
21798 */
21799 ENTRY(__copy_user_nocache)
21800 CFI_STARTPROC
21801+
21802+#ifdef CONFIG_PAX_MEMORY_UDEREF
21803+ mov $PAX_USER_SHADOW_BASE,%rcx
21804+ cmp %rcx,%rsi
21805+ jae 1f
21806+ add %rcx,%rsi
21807+1:
21808+#endif
21809+
21810 cmpl $8,%edx
21811 jb 20f /* less then 8 bytes, go to byte copy loop */
21812 ALIGN_DESTINATION
21813@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
21814 jz 17f
21815 1: movq (%rsi),%r8
21816 2: movq 1*8(%rsi),%r9
21817-3: movq 2*8(%rsi),%r10
21818+3: movq 2*8(%rsi),%rax
21819 4: movq 3*8(%rsi),%r11
21820 5: movnti %r8,(%rdi)
21821 6: movnti %r9,1*8(%rdi)
21822-7: movnti %r10,2*8(%rdi)
21823+7: movnti %rax,2*8(%rdi)
21824 8: movnti %r11,3*8(%rdi)
21825 9: movq 4*8(%rsi),%r8
21826 10: movq 5*8(%rsi),%r9
21827-11: movq 6*8(%rsi),%r10
21828+11: movq 6*8(%rsi),%rax
21829 12: movq 7*8(%rsi),%r11
21830 13: movnti %r8,4*8(%rdi)
21831 14: movnti %r9,5*8(%rdi)
21832-15: movnti %r10,6*8(%rdi)
21833+15: movnti %rax,6*8(%rdi)
21834 16: movnti %r11,7*8(%rdi)
21835 leaq 64(%rsi),%rsi
21836 leaq 64(%rdi),%rdi
21837@@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
21838 jnz 21b
21839 23: xorl %eax,%eax
21840 sfence
21841+ pax_force_retaddr
21842 ret
21843
21844 .section .fixup,"ax"
21845diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21846index fb903b7..c92b7f7 100644
21847--- a/arch/x86/lib/csum-copy_64.S
21848+++ b/arch/x86/lib/csum-copy_64.S
21849@@ -8,6 +8,7 @@
21850 #include <linux/linkage.h>
21851 #include <asm/dwarf2.h>
21852 #include <asm/errno.h>
21853+#include <asm/alternative-asm.h>
21854
21855 /*
21856 * Checksum copy with exception handling.
21857@@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
21858 CFI_RESTORE rbp
21859 addq $7*8, %rsp
21860 CFI_ADJUST_CFA_OFFSET -7*8
21861+ pax_force_retaddr 0, 1
21862 ret
21863 CFI_RESTORE_STATE
21864
21865diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21866index 459b58a..9570bc7 100644
21867--- a/arch/x86/lib/csum-wrappers_64.c
21868+++ b/arch/x86/lib/csum-wrappers_64.c
21869@@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21870 len -= 2;
21871 }
21872 }
21873- isum = csum_partial_copy_generic((__force const void *)src,
21874+
21875+#ifdef CONFIG_PAX_MEMORY_UDEREF
21876+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21877+ src += PAX_USER_SHADOW_BASE;
21878+#endif
21879+
21880+ isum = csum_partial_copy_generic((const void __force_kernel *)src,
21881 dst, len, isum, errp, NULL);
21882 if (unlikely(*errp))
21883 goto out_err;
21884@@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21885 }
21886
21887 *errp = 0;
21888- return csum_partial_copy_generic(src, (void __force *)dst,
21889+
21890+#ifdef CONFIG_PAX_MEMORY_UDEREF
21891+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21892+ dst += PAX_USER_SHADOW_BASE;
21893+#endif
21894+
21895+ return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21896 len, isum, NULL, errp);
21897 }
21898 EXPORT_SYMBOL(csum_partial_copy_to_user);
21899diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21900index 51f1504..ddac4c1 100644
21901--- a/arch/x86/lib/getuser.S
21902+++ b/arch/x86/lib/getuser.S
21903@@ -33,15 +33,38 @@
21904 #include <asm/asm-offsets.h>
21905 #include <asm/thread_info.h>
21906 #include <asm/asm.h>
21907+#include <asm/segment.h>
21908+#include <asm/pgtable.h>
21909+#include <asm/alternative-asm.h>
21910+
21911+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21912+#define __copyuser_seg gs;
21913+#else
21914+#define __copyuser_seg
21915+#endif
21916
21917 .text
21918 ENTRY(__get_user_1)
21919 CFI_STARTPROC
21920+
21921+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21922 GET_THREAD_INFO(%_ASM_DX)
21923 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21924 jae bad_get_user
21925-1: movzb (%_ASM_AX),%edx
21926+
21927+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21928+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21929+ cmp %_ASM_DX,%_ASM_AX
21930+ jae 1234f
21931+ add %_ASM_DX,%_ASM_AX
21932+1234:
21933+#endif
21934+
21935+#endif
21936+
21937+1: __copyuser_seg movzb (%_ASM_AX),%edx
21938 xor %eax,%eax
21939+ pax_force_retaddr
21940 ret
21941 CFI_ENDPROC
21942 ENDPROC(__get_user_1)
21943@@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21944 ENTRY(__get_user_2)
21945 CFI_STARTPROC
21946 add $1,%_ASM_AX
21947+
21948+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21949 jc bad_get_user
21950 GET_THREAD_INFO(%_ASM_DX)
21951 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21952 jae bad_get_user
21953-2: movzwl -1(%_ASM_AX),%edx
21954+
21955+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21956+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21957+ cmp %_ASM_DX,%_ASM_AX
21958+ jae 1234f
21959+ add %_ASM_DX,%_ASM_AX
21960+1234:
21961+#endif
21962+
21963+#endif
21964+
21965+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21966 xor %eax,%eax
21967+ pax_force_retaddr
21968 ret
21969 CFI_ENDPROC
21970 ENDPROC(__get_user_2)
21971@@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21972 ENTRY(__get_user_4)
21973 CFI_STARTPROC
21974 add $3,%_ASM_AX
21975+
21976+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21977 jc bad_get_user
21978 GET_THREAD_INFO(%_ASM_DX)
21979 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21980 jae bad_get_user
21981-3: mov -3(%_ASM_AX),%edx
21982+
21983+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21984+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21985+ cmp %_ASM_DX,%_ASM_AX
21986+ jae 1234f
21987+ add %_ASM_DX,%_ASM_AX
21988+1234:
21989+#endif
21990+
21991+#endif
21992+
21993+3: __copyuser_seg mov -3(%_ASM_AX),%edx
21994 xor %eax,%eax
21995+ pax_force_retaddr
21996 ret
21997 CFI_ENDPROC
21998 ENDPROC(__get_user_4)
21999@@ -80,8 +131,18 @@ ENTRY(__get_user_8)
22000 GET_THREAD_INFO(%_ASM_DX)
22001 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22002 jae bad_get_user
22003+
22004+#ifdef CONFIG_PAX_MEMORY_UDEREF
22005+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22006+ cmp %_ASM_DX,%_ASM_AX
22007+ jae 1234f
22008+ add %_ASM_DX,%_ASM_AX
22009+1234:
22010+#endif
22011+
22012 4: movq -7(%_ASM_AX),%_ASM_DX
22013 xor %eax,%eax
22014+ pax_force_retaddr
22015 ret
22016 CFI_ENDPROC
22017 ENDPROC(__get_user_8)
22018@@ -91,6 +152,7 @@ bad_get_user:
22019 CFI_STARTPROC
22020 xor %edx,%edx
22021 mov $(-EFAULT),%_ASM_AX
22022+ pax_force_retaddr
22023 ret
22024 CFI_ENDPROC
22025 END(bad_get_user)
22026diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
22027index 5a1f9f3..ba9f577 100644
22028--- a/arch/x86/lib/insn.c
22029+++ b/arch/x86/lib/insn.c
22030@@ -21,6 +21,11 @@
22031 #include <linux/string.h>
22032 #include <asm/inat.h>
22033 #include <asm/insn.h>
22034+#ifdef __KERNEL__
22035+#include <asm/pgtable_types.h>
22036+#else
22037+#define ktla_ktva(addr) addr
22038+#endif
22039
22040 /* Verify next sizeof(t) bytes can be on the same instruction */
22041 #define validate_next(t, insn, n) \
22042@@ -49,8 +54,8 @@
22043 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
22044 {
22045 memset(insn, 0, sizeof(*insn));
22046- insn->kaddr = kaddr;
22047- insn->next_byte = kaddr;
22048+ insn->kaddr = ktla_ktva(kaddr);
22049+ insn->next_byte = ktla_ktva(kaddr);
22050 insn->x86_64 = x86_64 ? 1 : 0;
22051 insn->opnd_bytes = 4;
22052 if (x86_64)
22053diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
22054index 05a95e7..326f2fa 100644
22055--- a/arch/x86/lib/iomap_copy_64.S
22056+++ b/arch/x86/lib/iomap_copy_64.S
22057@@ -17,6 +17,7 @@
22058
22059 #include <linux/linkage.h>
22060 #include <asm/dwarf2.h>
22061+#include <asm/alternative-asm.h>
22062
22063 /*
22064 * override generic version in lib/iomap_copy.c
22065@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
22066 CFI_STARTPROC
22067 movl %edx,%ecx
22068 rep movsd
22069+ pax_force_retaddr
22070 ret
22071 CFI_ENDPROC
22072 ENDPROC(__iowrite32_copy)
22073diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
22074index efbf2a0..8893637 100644
22075--- a/arch/x86/lib/memcpy_64.S
22076+++ b/arch/x86/lib/memcpy_64.S
22077@@ -34,6 +34,7 @@
22078 rep movsq
22079 movl %edx, %ecx
22080 rep movsb
22081+ pax_force_retaddr
22082 ret
22083 .Lmemcpy_e:
22084 .previous
22085@@ -51,6 +52,7 @@
22086
22087 movl %edx, %ecx
22088 rep movsb
22089+ pax_force_retaddr
22090 ret
22091 .Lmemcpy_e_e:
22092 .previous
22093@@ -81,13 +83,13 @@ ENTRY(memcpy)
22094 */
22095 movq 0*8(%rsi), %r8
22096 movq 1*8(%rsi), %r9
22097- movq 2*8(%rsi), %r10
22098+ movq 2*8(%rsi), %rcx
22099 movq 3*8(%rsi), %r11
22100 leaq 4*8(%rsi), %rsi
22101
22102 movq %r8, 0*8(%rdi)
22103 movq %r9, 1*8(%rdi)
22104- movq %r10, 2*8(%rdi)
22105+ movq %rcx, 2*8(%rdi)
22106 movq %r11, 3*8(%rdi)
22107 leaq 4*8(%rdi), %rdi
22108 jae .Lcopy_forward_loop
22109@@ -110,12 +112,12 @@ ENTRY(memcpy)
22110 subq $0x20, %rdx
22111 movq -1*8(%rsi), %r8
22112 movq -2*8(%rsi), %r9
22113- movq -3*8(%rsi), %r10
22114+ movq -3*8(%rsi), %rcx
22115 movq -4*8(%rsi), %r11
22116 leaq -4*8(%rsi), %rsi
22117 movq %r8, -1*8(%rdi)
22118 movq %r9, -2*8(%rdi)
22119- movq %r10, -3*8(%rdi)
22120+ movq %rcx, -3*8(%rdi)
22121 movq %r11, -4*8(%rdi)
22122 leaq -4*8(%rdi), %rdi
22123 jae .Lcopy_backward_loop
22124@@ -135,12 +137,13 @@ ENTRY(memcpy)
22125 */
22126 movq 0*8(%rsi), %r8
22127 movq 1*8(%rsi), %r9
22128- movq -2*8(%rsi, %rdx), %r10
22129+ movq -2*8(%rsi, %rdx), %rcx
22130 movq -1*8(%rsi, %rdx), %r11
22131 movq %r8, 0*8(%rdi)
22132 movq %r9, 1*8(%rdi)
22133- movq %r10, -2*8(%rdi, %rdx)
22134+ movq %rcx, -2*8(%rdi, %rdx)
22135 movq %r11, -1*8(%rdi, %rdx)
22136+ pax_force_retaddr
22137 retq
22138 .p2align 4
22139 .Lless_16bytes:
22140@@ -153,6 +156,7 @@ ENTRY(memcpy)
22141 movq -1*8(%rsi, %rdx), %r9
22142 movq %r8, 0*8(%rdi)
22143 movq %r9, -1*8(%rdi, %rdx)
22144+ pax_force_retaddr
22145 retq
22146 .p2align 4
22147 .Lless_8bytes:
22148@@ -166,6 +170,7 @@ ENTRY(memcpy)
22149 movl -4(%rsi, %rdx), %r8d
22150 movl %ecx, (%rdi)
22151 movl %r8d, -4(%rdi, %rdx)
22152+ pax_force_retaddr
22153 retq
22154 .p2align 4
22155 .Lless_3bytes:
22156@@ -183,6 +188,7 @@ ENTRY(memcpy)
22157 jnz .Lloop_1
22158
22159 .Lend:
22160+ pax_force_retaddr
22161 retq
22162 CFI_ENDPROC
22163 ENDPROC(memcpy)
22164diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22165index ee16461..c39c199 100644
22166--- a/arch/x86/lib/memmove_64.S
22167+++ b/arch/x86/lib/memmove_64.S
22168@@ -61,13 +61,13 @@ ENTRY(memmove)
22169 5:
22170 sub $0x20, %rdx
22171 movq 0*8(%rsi), %r11
22172- movq 1*8(%rsi), %r10
22173+ movq 1*8(%rsi), %rcx
22174 movq 2*8(%rsi), %r9
22175 movq 3*8(%rsi), %r8
22176 leaq 4*8(%rsi), %rsi
22177
22178 movq %r11, 0*8(%rdi)
22179- movq %r10, 1*8(%rdi)
22180+ movq %rcx, 1*8(%rdi)
22181 movq %r9, 2*8(%rdi)
22182 movq %r8, 3*8(%rdi)
22183 leaq 4*8(%rdi), %rdi
22184@@ -81,10 +81,10 @@ ENTRY(memmove)
22185 4:
22186 movq %rdx, %rcx
22187 movq -8(%rsi, %rdx), %r11
22188- lea -8(%rdi, %rdx), %r10
22189+ lea -8(%rdi, %rdx), %r9
22190 shrq $3, %rcx
22191 rep movsq
22192- movq %r11, (%r10)
22193+ movq %r11, (%r9)
22194 jmp 13f
22195 .Lmemmove_end_forward:
22196
22197@@ -95,14 +95,14 @@ ENTRY(memmove)
22198 7:
22199 movq %rdx, %rcx
22200 movq (%rsi), %r11
22201- movq %rdi, %r10
22202+ movq %rdi, %r9
22203 leaq -8(%rsi, %rdx), %rsi
22204 leaq -8(%rdi, %rdx), %rdi
22205 shrq $3, %rcx
22206 std
22207 rep movsq
22208 cld
22209- movq %r11, (%r10)
22210+ movq %r11, (%r9)
22211 jmp 13f
22212
22213 /*
22214@@ -127,13 +127,13 @@ ENTRY(memmove)
22215 8:
22216 subq $0x20, %rdx
22217 movq -1*8(%rsi), %r11
22218- movq -2*8(%rsi), %r10
22219+ movq -2*8(%rsi), %rcx
22220 movq -3*8(%rsi), %r9
22221 movq -4*8(%rsi), %r8
22222 leaq -4*8(%rsi), %rsi
22223
22224 movq %r11, -1*8(%rdi)
22225- movq %r10, -2*8(%rdi)
22226+ movq %rcx, -2*8(%rdi)
22227 movq %r9, -3*8(%rdi)
22228 movq %r8, -4*8(%rdi)
22229 leaq -4*8(%rdi), %rdi
22230@@ -151,11 +151,11 @@ ENTRY(memmove)
22231 * Move data from 16 bytes to 31 bytes.
22232 */
22233 movq 0*8(%rsi), %r11
22234- movq 1*8(%rsi), %r10
22235+ movq 1*8(%rsi), %rcx
22236 movq -2*8(%rsi, %rdx), %r9
22237 movq -1*8(%rsi, %rdx), %r8
22238 movq %r11, 0*8(%rdi)
22239- movq %r10, 1*8(%rdi)
22240+ movq %rcx, 1*8(%rdi)
22241 movq %r9, -2*8(%rdi, %rdx)
22242 movq %r8, -1*8(%rdi, %rdx)
22243 jmp 13f
22244@@ -167,9 +167,9 @@ ENTRY(memmove)
22245 * Move data from 8 bytes to 15 bytes.
22246 */
22247 movq 0*8(%rsi), %r11
22248- movq -1*8(%rsi, %rdx), %r10
22249+ movq -1*8(%rsi, %rdx), %r9
22250 movq %r11, 0*8(%rdi)
22251- movq %r10, -1*8(%rdi, %rdx)
22252+ movq %r9, -1*8(%rdi, %rdx)
22253 jmp 13f
22254 10:
22255 cmpq $4, %rdx
22256@@ -178,9 +178,9 @@ ENTRY(memmove)
22257 * Move data from 4 bytes to 7 bytes.
22258 */
22259 movl (%rsi), %r11d
22260- movl -4(%rsi, %rdx), %r10d
22261+ movl -4(%rsi, %rdx), %r9d
22262 movl %r11d, (%rdi)
22263- movl %r10d, -4(%rdi, %rdx)
22264+ movl %r9d, -4(%rdi, %rdx)
22265 jmp 13f
22266 11:
22267 cmp $2, %rdx
22268@@ -189,9 +189,9 @@ ENTRY(memmove)
22269 * Move data from 2 bytes to 3 bytes.
22270 */
22271 movw (%rsi), %r11w
22272- movw -2(%rsi, %rdx), %r10w
22273+ movw -2(%rsi, %rdx), %r9w
22274 movw %r11w, (%rdi)
22275- movw %r10w, -2(%rdi, %rdx)
22276+ movw %r9w, -2(%rdi, %rdx)
22277 jmp 13f
22278 12:
22279 cmp $1, %rdx
22280@@ -202,6 +202,7 @@ ENTRY(memmove)
22281 movb (%rsi), %r11b
22282 movb %r11b, (%rdi)
22283 13:
22284+ pax_force_retaddr
22285 retq
22286 CFI_ENDPROC
22287
22288@@ -210,6 +211,7 @@ ENTRY(memmove)
22289 /* Forward moving data. */
22290 movq %rdx, %rcx
22291 rep movsb
22292+ pax_force_retaddr
22293 retq
22294 .Lmemmove_end_forward_efs:
22295 .previous
22296diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22297index 79bd454..dff325a 100644
22298--- a/arch/x86/lib/memset_64.S
22299+++ b/arch/x86/lib/memset_64.S
22300@@ -31,6 +31,7 @@
22301 movl %r8d,%ecx
22302 rep stosb
22303 movq %r9,%rax
22304+ pax_force_retaddr
22305 ret
22306 .Lmemset_e:
22307 .previous
22308@@ -53,6 +54,7 @@
22309 movl %edx,%ecx
22310 rep stosb
22311 movq %r9,%rax
22312+ pax_force_retaddr
22313 ret
22314 .Lmemset_e_e:
22315 .previous
22316@@ -60,13 +62,13 @@
22317 ENTRY(memset)
22318 ENTRY(__memset)
22319 CFI_STARTPROC
22320- movq %rdi,%r10
22321 movq %rdx,%r11
22322
22323 /* expand byte value */
22324 movzbl %sil,%ecx
22325 movabs $0x0101010101010101,%rax
22326 mul %rcx /* with rax, clobbers rdx */
22327+ movq %rdi,%rdx
22328
22329 /* align dst */
22330 movl %edi,%r9d
22331@@ -120,7 +122,8 @@ ENTRY(__memset)
22332 jnz .Lloop_1
22333
22334 .Lende:
22335- movq %r10,%rax
22336+ movq %rdx,%rax
22337+ pax_force_retaddr
22338 ret
22339
22340 CFI_RESTORE_STATE
22341diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22342index c9f2d9b..e7fd2c0 100644
22343--- a/arch/x86/lib/mmx_32.c
22344+++ b/arch/x86/lib/mmx_32.c
22345@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22346 {
22347 void *p;
22348 int i;
22349+ unsigned long cr0;
22350
22351 if (unlikely(in_interrupt()))
22352 return __memcpy(to, from, len);
22353@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22354 kernel_fpu_begin();
22355
22356 __asm__ __volatile__ (
22357- "1: prefetch (%0)\n" /* This set is 28 bytes */
22358- " prefetch 64(%0)\n"
22359- " prefetch 128(%0)\n"
22360- " prefetch 192(%0)\n"
22361- " prefetch 256(%0)\n"
22362+ "1: prefetch (%1)\n" /* This set is 28 bytes */
22363+ " prefetch 64(%1)\n"
22364+ " prefetch 128(%1)\n"
22365+ " prefetch 192(%1)\n"
22366+ " prefetch 256(%1)\n"
22367 "2: \n"
22368 ".section .fixup, \"ax\"\n"
22369- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22370+ "3: \n"
22371+
22372+#ifdef CONFIG_PAX_KERNEXEC
22373+ " movl %%cr0, %0\n"
22374+ " movl %0, %%eax\n"
22375+ " andl $0xFFFEFFFF, %%eax\n"
22376+ " movl %%eax, %%cr0\n"
22377+#endif
22378+
22379+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22380+
22381+#ifdef CONFIG_PAX_KERNEXEC
22382+ " movl %0, %%cr0\n"
22383+#endif
22384+
22385 " jmp 2b\n"
22386 ".previous\n"
22387 _ASM_EXTABLE(1b, 3b)
22388- : : "r" (from));
22389+ : "=&r" (cr0) : "r" (from) : "ax");
22390
22391 for ( ; i > 5; i--) {
22392 __asm__ __volatile__ (
22393- "1: prefetch 320(%0)\n"
22394- "2: movq (%0), %%mm0\n"
22395- " movq 8(%0), %%mm1\n"
22396- " movq 16(%0), %%mm2\n"
22397- " movq 24(%0), %%mm3\n"
22398- " movq %%mm0, (%1)\n"
22399- " movq %%mm1, 8(%1)\n"
22400- " movq %%mm2, 16(%1)\n"
22401- " movq %%mm3, 24(%1)\n"
22402- " movq 32(%0), %%mm0\n"
22403- " movq 40(%0), %%mm1\n"
22404- " movq 48(%0), %%mm2\n"
22405- " movq 56(%0), %%mm3\n"
22406- " movq %%mm0, 32(%1)\n"
22407- " movq %%mm1, 40(%1)\n"
22408- " movq %%mm2, 48(%1)\n"
22409- " movq %%mm3, 56(%1)\n"
22410+ "1: prefetch 320(%1)\n"
22411+ "2: movq (%1), %%mm0\n"
22412+ " movq 8(%1), %%mm1\n"
22413+ " movq 16(%1), %%mm2\n"
22414+ " movq 24(%1), %%mm3\n"
22415+ " movq %%mm0, (%2)\n"
22416+ " movq %%mm1, 8(%2)\n"
22417+ " movq %%mm2, 16(%2)\n"
22418+ " movq %%mm3, 24(%2)\n"
22419+ " movq 32(%1), %%mm0\n"
22420+ " movq 40(%1), %%mm1\n"
22421+ " movq 48(%1), %%mm2\n"
22422+ " movq 56(%1), %%mm3\n"
22423+ " movq %%mm0, 32(%2)\n"
22424+ " movq %%mm1, 40(%2)\n"
22425+ " movq %%mm2, 48(%2)\n"
22426+ " movq %%mm3, 56(%2)\n"
22427 ".section .fixup, \"ax\"\n"
22428- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22429+ "3:\n"
22430+
22431+#ifdef CONFIG_PAX_KERNEXEC
22432+ " movl %%cr0, %0\n"
22433+ " movl %0, %%eax\n"
22434+ " andl $0xFFFEFFFF, %%eax\n"
22435+ " movl %%eax, %%cr0\n"
22436+#endif
22437+
22438+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22439+
22440+#ifdef CONFIG_PAX_KERNEXEC
22441+ " movl %0, %%cr0\n"
22442+#endif
22443+
22444 " jmp 2b\n"
22445 ".previous\n"
22446 _ASM_EXTABLE(1b, 3b)
22447- : : "r" (from), "r" (to) : "memory");
22448+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22449
22450 from += 64;
22451 to += 64;
22452@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22453 static void fast_copy_page(void *to, void *from)
22454 {
22455 int i;
22456+ unsigned long cr0;
22457
22458 kernel_fpu_begin();
22459
22460@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22461 * but that is for later. -AV
22462 */
22463 __asm__ __volatile__(
22464- "1: prefetch (%0)\n"
22465- " prefetch 64(%0)\n"
22466- " prefetch 128(%0)\n"
22467- " prefetch 192(%0)\n"
22468- " prefetch 256(%0)\n"
22469+ "1: prefetch (%1)\n"
22470+ " prefetch 64(%1)\n"
22471+ " prefetch 128(%1)\n"
22472+ " prefetch 192(%1)\n"
22473+ " prefetch 256(%1)\n"
22474 "2: \n"
22475 ".section .fixup, \"ax\"\n"
22476- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22477+ "3: \n"
22478+
22479+#ifdef CONFIG_PAX_KERNEXEC
22480+ " movl %%cr0, %0\n"
22481+ " movl %0, %%eax\n"
22482+ " andl $0xFFFEFFFF, %%eax\n"
22483+ " movl %%eax, %%cr0\n"
22484+#endif
22485+
22486+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22487+
22488+#ifdef CONFIG_PAX_KERNEXEC
22489+ " movl %0, %%cr0\n"
22490+#endif
22491+
22492 " jmp 2b\n"
22493 ".previous\n"
22494- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22495+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22496
22497 for (i = 0; i < (4096-320)/64; i++) {
22498 __asm__ __volatile__ (
22499- "1: prefetch 320(%0)\n"
22500- "2: movq (%0), %%mm0\n"
22501- " movntq %%mm0, (%1)\n"
22502- " movq 8(%0), %%mm1\n"
22503- " movntq %%mm1, 8(%1)\n"
22504- " movq 16(%0), %%mm2\n"
22505- " movntq %%mm2, 16(%1)\n"
22506- " movq 24(%0), %%mm3\n"
22507- " movntq %%mm3, 24(%1)\n"
22508- " movq 32(%0), %%mm4\n"
22509- " movntq %%mm4, 32(%1)\n"
22510- " movq 40(%0), %%mm5\n"
22511- " movntq %%mm5, 40(%1)\n"
22512- " movq 48(%0), %%mm6\n"
22513- " movntq %%mm6, 48(%1)\n"
22514- " movq 56(%0), %%mm7\n"
22515- " movntq %%mm7, 56(%1)\n"
22516+ "1: prefetch 320(%1)\n"
22517+ "2: movq (%1), %%mm0\n"
22518+ " movntq %%mm0, (%2)\n"
22519+ " movq 8(%1), %%mm1\n"
22520+ " movntq %%mm1, 8(%2)\n"
22521+ " movq 16(%1), %%mm2\n"
22522+ " movntq %%mm2, 16(%2)\n"
22523+ " movq 24(%1), %%mm3\n"
22524+ " movntq %%mm3, 24(%2)\n"
22525+ " movq 32(%1), %%mm4\n"
22526+ " movntq %%mm4, 32(%2)\n"
22527+ " movq 40(%1), %%mm5\n"
22528+ " movntq %%mm5, 40(%2)\n"
22529+ " movq 48(%1), %%mm6\n"
22530+ " movntq %%mm6, 48(%2)\n"
22531+ " movq 56(%1), %%mm7\n"
22532+ " movntq %%mm7, 56(%2)\n"
22533 ".section .fixup, \"ax\"\n"
22534- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22535+ "3:\n"
22536+
22537+#ifdef CONFIG_PAX_KERNEXEC
22538+ " movl %%cr0, %0\n"
22539+ " movl %0, %%eax\n"
22540+ " andl $0xFFFEFFFF, %%eax\n"
22541+ " movl %%eax, %%cr0\n"
22542+#endif
22543+
22544+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22545+
22546+#ifdef CONFIG_PAX_KERNEXEC
22547+ " movl %0, %%cr0\n"
22548+#endif
22549+
22550 " jmp 2b\n"
22551 ".previous\n"
22552- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22553+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22554
22555 from += 64;
22556 to += 64;
22557@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22558 static void fast_copy_page(void *to, void *from)
22559 {
22560 int i;
22561+ unsigned long cr0;
22562
22563 kernel_fpu_begin();
22564
22565 __asm__ __volatile__ (
22566- "1: prefetch (%0)\n"
22567- " prefetch 64(%0)\n"
22568- " prefetch 128(%0)\n"
22569- " prefetch 192(%0)\n"
22570- " prefetch 256(%0)\n"
22571+ "1: prefetch (%1)\n"
22572+ " prefetch 64(%1)\n"
22573+ " prefetch 128(%1)\n"
22574+ " prefetch 192(%1)\n"
22575+ " prefetch 256(%1)\n"
22576 "2: \n"
22577 ".section .fixup, \"ax\"\n"
22578- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22579+ "3: \n"
22580+
22581+#ifdef CONFIG_PAX_KERNEXEC
22582+ " movl %%cr0, %0\n"
22583+ " movl %0, %%eax\n"
22584+ " andl $0xFFFEFFFF, %%eax\n"
22585+ " movl %%eax, %%cr0\n"
22586+#endif
22587+
22588+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22589+
22590+#ifdef CONFIG_PAX_KERNEXEC
22591+ " movl %0, %%cr0\n"
22592+#endif
22593+
22594 " jmp 2b\n"
22595 ".previous\n"
22596- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22597+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22598
22599 for (i = 0; i < 4096/64; i++) {
22600 __asm__ __volatile__ (
22601- "1: prefetch 320(%0)\n"
22602- "2: movq (%0), %%mm0\n"
22603- " movq 8(%0), %%mm1\n"
22604- " movq 16(%0), %%mm2\n"
22605- " movq 24(%0), %%mm3\n"
22606- " movq %%mm0, (%1)\n"
22607- " movq %%mm1, 8(%1)\n"
22608- " movq %%mm2, 16(%1)\n"
22609- " movq %%mm3, 24(%1)\n"
22610- " movq 32(%0), %%mm0\n"
22611- " movq 40(%0), %%mm1\n"
22612- " movq 48(%0), %%mm2\n"
22613- " movq 56(%0), %%mm3\n"
22614- " movq %%mm0, 32(%1)\n"
22615- " movq %%mm1, 40(%1)\n"
22616- " movq %%mm2, 48(%1)\n"
22617- " movq %%mm3, 56(%1)\n"
22618+ "1: prefetch 320(%1)\n"
22619+ "2: movq (%1), %%mm0\n"
22620+ " movq 8(%1), %%mm1\n"
22621+ " movq 16(%1), %%mm2\n"
22622+ " movq 24(%1), %%mm3\n"
22623+ " movq %%mm0, (%2)\n"
22624+ " movq %%mm1, 8(%2)\n"
22625+ " movq %%mm2, 16(%2)\n"
22626+ " movq %%mm3, 24(%2)\n"
22627+ " movq 32(%1), %%mm0\n"
22628+ " movq 40(%1), %%mm1\n"
22629+ " movq 48(%1), %%mm2\n"
22630+ " movq 56(%1), %%mm3\n"
22631+ " movq %%mm0, 32(%2)\n"
22632+ " movq %%mm1, 40(%2)\n"
22633+ " movq %%mm2, 48(%2)\n"
22634+ " movq %%mm3, 56(%2)\n"
22635 ".section .fixup, \"ax\"\n"
22636- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22637+ "3:\n"
22638+
22639+#ifdef CONFIG_PAX_KERNEXEC
22640+ " movl %%cr0, %0\n"
22641+ " movl %0, %%eax\n"
22642+ " andl $0xFFFEFFFF, %%eax\n"
22643+ " movl %%eax, %%cr0\n"
22644+#endif
22645+
22646+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22647+
22648+#ifdef CONFIG_PAX_KERNEXEC
22649+ " movl %0, %%cr0\n"
22650+#endif
22651+
22652 " jmp 2b\n"
22653 ".previous\n"
22654 _ASM_EXTABLE(1b, 3b)
22655- : : "r" (from), "r" (to) : "memory");
22656+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22657
22658 from += 64;
22659 to += 64;
22660diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22661index 69fa106..adda88b 100644
22662--- a/arch/x86/lib/msr-reg.S
22663+++ b/arch/x86/lib/msr-reg.S
22664@@ -3,6 +3,7 @@
22665 #include <asm/dwarf2.h>
22666 #include <asm/asm.h>
22667 #include <asm/msr.h>
22668+#include <asm/alternative-asm.h>
22669
22670 #ifdef CONFIG_X86_64
22671 /*
22672@@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22673 CFI_STARTPROC
22674 pushq_cfi %rbx
22675 pushq_cfi %rbp
22676- movq %rdi, %r10 /* Save pointer */
22677+ movq %rdi, %r9 /* Save pointer */
22678 xorl %r11d, %r11d /* Return value */
22679 movl (%rdi), %eax
22680 movl 4(%rdi), %ecx
22681@@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22682 movl 28(%rdi), %edi
22683 CFI_REMEMBER_STATE
22684 1: \op
22685-2: movl %eax, (%r10)
22686+2: movl %eax, (%r9)
22687 movl %r11d, %eax /* Return value */
22688- movl %ecx, 4(%r10)
22689- movl %edx, 8(%r10)
22690- movl %ebx, 12(%r10)
22691- movl %ebp, 20(%r10)
22692- movl %esi, 24(%r10)
22693- movl %edi, 28(%r10)
22694+ movl %ecx, 4(%r9)
22695+ movl %edx, 8(%r9)
22696+ movl %ebx, 12(%r9)
22697+ movl %ebp, 20(%r9)
22698+ movl %esi, 24(%r9)
22699+ movl %edi, 28(%r9)
22700 popq_cfi %rbp
22701 popq_cfi %rbx
22702+ pax_force_retaddr
22703 ret
22704 3:
22705 CFI_RESTORE_STATE
22706diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22707index 36b0d15..d381858 100644
22708--- a/arch/x86/lib/putuser.S
22709+++ b/arch/x86/lib/putuser.S
22710@@ -15,7 +15,9 @@
22711 #include <asm/thread_info.h>
22712 #include <asm/errno.h>
22713 #include <asm/asm.h>
22714-
22715+#include <asm/segment.h>
22716+#include <asm/pgtable.h>
22717+#include <asm/alternative-asm.h>
22718
22719 /*
22720 * __put_user_X
22721@@ -29,52 +31,119 @@
22722 * as they get called from within inline assembly.
22723 */
22724
22725-#define ENTER CFI_STARTPROC ; \
22726- GET_THREAD_INFO(%_ASM_BX)
22727-#define EXIT ret ; \
22728+#define ENTER CFI_STARTPROC
22729+#define EXIT pax_force_retaddr; ret ; \
22730 CFI_ENDPROC
22731
22732+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22733+#define _DEST %_ASM_CX,%_ASM_BX
22734+#else
22735+#define _DEST %_ASM_CX
22736+#endif
22737+
22738+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22739+#define __copyuser_seg gs;
22740+#else
22741+#define __copyuser_seg
22742+#endif
22743+
22744 .text
22745 ENTRY(__put_user_1)
22746 ENTER
22747+
22748+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22749+ GET_THREAD_INFO(%_ASM_BX)
22750 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22751 jae bad_put_user
22752-1: movb %al,(%_ASM_CX)
22753+
22754+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22755+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22756+ cmp %_ASM_BX,%_ASM_CX
22757+ jb 1234f
22758+ xor %ebx,%ebx
22759+1234:
22760+#endif
22761+
22762+#endif
22763+
22764+1: __copyuser_seg movb %al,(_DEST)
22765 xor %eax,%eax
22766 EXIT
22767 ENDPROC(__put_user_1)
22768
22769 ENTRY(__put_user_2)
22770 ENTER
22771+
22772+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22773+ GET_THREAD_INFO(%_ASM_BX)
22774 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22775 sub $1,%_ASM_BX
22776 cmp %_ASM_BX,%_ASM_CX
22777 jae bad_put_user
22778-2: movw %ax,(%_ASM_CX)
22779+
22780+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22781+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22782+ cmp %_ASM_BX,%_ASM_CX
22783+ jb 1234f
22784+ xor %ebx,%ebx
22785+1234:
22786+#endif
22787+
22788+#endif
22789+
22790+2: __copyuser_seg movw %ax,(_DEST)
22791 xor %eax,%eax
22792 EXIT
22793 ENDPROC(__put_user_2)
22794
22795 ENTRY(__put_user_4)
22796 ENTER
22797+
22798+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22799+ GET_THREAD_INFO(%_ASM_BX)
22800 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22801 sub $3,%_ASM_BX
22802 cmp %_ASM_BX,%_ASM_CX
22803 jae bad_put_user
22804-3: movl %eax,(%_ASM_CX)
22805+
22806+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22807+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22808+ cmp %_ASM_BX,%_ASM_CX
22809+ jb 1234f
22810+ xor %ebx,%ebx
22811+1234:
22812+#endif
22813+
22814+#endif
22815+
22816+3: __copyuser_seg movl %eax,(_DEST)
22817 xor %eax,%eax
22818 EXIT
22819 ENDPROC(__put_user_4)
22820
22821 ENTRY(__put_user_8)
22822 ENTER
22823+
22824+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22825+ GET_THREAD_INFO(%_ASM_BX)
22826 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22827 sub $7,%_ASM_BX
22828 cmp %_ASM_BX,%_ASM_CX
22829 jae bad_put_user
22830-4: mov %_ASM_AX,(%_ASM_CX)
22831+
22832+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22833+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22834+ cmp %_ASM_BX,%_ASM_CX
22835+ jb 1234f
22836+ xor %ebx,%ebx
22837+1234:
22838+#endif
22839+
22840+#endif
22841+
22842+4: __copyuser_seg mov %_ASM_AX,(_DEST)
22843 #ifdef CONFIG_X86_32
22844-5: movl %edx,4(%_ASM_CX)
22845+5: __copyuser_seg movl %edx,4(_DEST)
22846 #endif
22847 xor %eax,%eax
22848 EXIT
22849diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22850index 1cad221..de671ee 100644
22851--- a/arch/x86/lib/rwlock.S
22852+++ b/arch/x86/lib/rwlock.S
22853@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22854 FRAME
22855 0: LOCK_PREFIX
22856 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22857+
22858+#ifdef CONFIG_PAX_REFCOUNT
22859+ jno 1234f
22860+ LOCK_PREFIX
22861+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22862+ int $4
22863+1234:
22864+ _ASM_EXTABLE(1234b, 1234b)
22865+#endif
22866+
22867 1: rep; nop
22868 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22869 jne 1b
22870 LOCK_PREFIX
22871 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22872+
22873+#ifdef CONFIG_PAX_REFCOUNT
22874+ jno 1234f
22875+ LOCK_PREFIX
22876+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22877+ int $4
22878+1234:
22879+ _ASM_EXTABLE(1234b, 1234b)
22880+#endif
22881+
22882 jnz 0b
22883 ENDFRAME
22884+ pax_force_retaddr
22885 ret
22886 CFI_ENDPROC
22887 END(__write_lock_failed)
22888@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22889 FRAME
22890 0: LOCK_PREFIX
22891 READ_LOCK_SIZE(inc) (%__lock_ptr)
22892+
22893+#ifdef CONFIG_PAX_REFCOUNT
22894+ jno 1234f
22895+ LOCK_PREFIX
22896+ READ_LOCK_SIZE(dec) (%__lock_ptr)
22897+ int $4
22898+1234:
22899+ _ASM_EXTABLE(1234b, 1234b)
22900+#endif
22901+
22902 1: rep; nop
22903 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22904 js 1b
22905 LOCK_PREFIX
22906 READ_LOCK_SIZE(dec) (%__lock_ptr)
22907+
22908+#ifdef CONFIG_PAX_REFCOUNT
22909+ jno 1234f
22910+ LOCK_PREFIX
22911+ READ_LOCK_SIZE(inc) (%__lock_ptr)
22912+ int $4
22913+1234:
22914+ _ASM_EXTABLE(1234b, 1234b)
22915+#endif
22916+
22917 js 0b
22918 ENDFRAME
22919+ pax_force_retaddr
22920 ret
22921 CFI_ENDPROC
22922 END(__read_lock_failed)
22923diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22924index 5dff5f0..cadebf4 100644
22925--- a/arch/x86/lib/rwsem.S
22926+++ b/arch/x86/lib/rwsem.S
22927@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22928 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22929 CFI_RESTORE __ASM_REG(dx)
22930 restore_common_regs
22931+ pax_force_retaddr
22932 ret
22933 CFI_ENDPROC
22934 ENDPROC(call_rwsem_down_read_failed)
22935@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22936 movq %rax,%rdi
22937 call rwsem_down_write_failed
22938 restore_common_regs
22939+ pax_force_retaddr
22940 ret
22941 CFI_ENDPROC
22942 ENDPROC(call_rwsem_down_write_failed)
22943@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22944 movq %rax,%rdi
22945 call rwsem_wake
22946 restore_common_regs
22947-1: ret
22948+1: pax_force_retaddr
22949+ ret
22950 CFI_ENDPROC
22951 ENDPROC(call_rwsem_wake)
22952
22953@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22954 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22955 CFI_RESTORE __ASM_REG(dx)
22956 restore_common_regs
22957+ pax_force_retaddr
22958 ret
22959 CFI_ENDPROC
22960 ENDPROC(call_rwsem_downgrade_wake)
22961diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22962index a63efd6..ccecad8 100644
22963--- a/arch/x86/lib/thunk_64.S
22964+++ b/arch/x86/lib/thunk_64.S
22965@@ -8,6 +8,7 @@
22966 #include <linux/linkage.h>
22967 #include <asm/dwarf2.h>
22968 #include <asm/calling.h>
22969+#include <asm/alternative-asm.h>
22970
22971 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22972 .macro THUNK name, func, put_ret_addr_in_rdi=0
22973@@ -41,5 +42,6 @@
22974 SAVE_ARGS
22975 restore:
22976 RESTORE_ARGS
22977+ pax_force_retaddr
22978 ret
22979 CFI_ENDPROC
22980diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22981index e218d5d..a99a1eb 100644
22982--- a/arch/x86/lib/usercopy_32.c
22983+++ b/arch/x86/lib/usercopy_32.c
22984@@ -43,7 +43,7 @@ do { \
22985 __asm__ __volatile__( \
22986 " testl %1,%1\n" \
22987 " jz 2f\n" \
22988- "0: lodsb\n" \
22989+ "0: "__copyuser_seg"lodsb\n" \
22990 " stosb\n" \
22991 " testb %%al,%%al\n" \
22992 " jz 1f\n" \
22993@@ -128,10 +128,12 @@ do { \
22994 int __d0; \
22995 might_fault(); \
22996 __asm__ __volatile__( \
22997+ __COPYUSER_SET_ES \
22998 "0: rep; stosl\n" \
22999 " movl %2,%0\n" \
23000 "1: rep; stosb\n" \
23001 "2:\n" \
23002+ __COPYUSER_RESTORE_ES \
23003 ".section .fixup,\"ax\"\n" \
23004 "3: lea 0(%2,%0,4),%0\n" \
23005 " jmp 2b\n" \
23006@@ -200,6 +202,7 @@ long strnlen_user(const char __user *s, long n)
23007 might_fault();
23008
23009 __asm__ __volatile__(
23010+ __COPYUSER_SET_ES
23011 " testl %0, %0\n"
23012 " jz 3f\n"
23013 " andl %0,%%ecx\n"
23014@@ -208,6 +211,7 @@ long strnlen_user(const char __user *s, long n)
23015 " subl %%ecx,%0\n"
23016 " addl %0,%%eax\n"
23017 "1:\n"
23018+ __COPYUSER_RESTORE_ES
23019 ".section .fixup,\"ax\"\n"
23020 "2: xorl %%eax,%%eax\n"
23021 " jmp 1b\n"
23022@@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
23023
23024 #ifdef CONFIG_X86_INTEL_USERCOPY
23025 static unsigned long
23026-__copy_user_intel(void __user *to, const void *from, unsigned long size)
23027+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
23028 {
23029 int d0, d1;
23030 __asm__ __volatile__(
23031@@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23032 " .align 2,0x90\n"
23033 "3: movl 0(%4), %%eax\n"
23034 "4: movl 4(%4), %%edx\n"
23035- "5: movl %%eax, 0(%3)\n"
23036- "6: movl %%edx, 4(%3)\n"
23037+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
23038+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
23039 "7: movl 8(%4), %%eax\n"
23040 "8: movl 12(%4),%%edx\n"
23041- "9: movl %%eax, 8(%3)\n"
23042- "10: movl %%edx, 12(%3)\n"
23043+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
23044+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
23045 "11: movl 16(%4), %%eax\n"
23046 "12: movl 20(%4), %%edx\n"
23047- "13: movl %%eax, 16(%3)\n"
23048- "14: movl %%edx, 20(%3)\n"
23049+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
23050+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
23051 "15: movl 24(%4), %%eax\n"
23052 "16: movl 28(%4), %%edx\n"
23053- "17: movl %%eax, 24(%3)\n"
23054- "18: movl %%edx, 28(%3)\n"
23055+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
23056+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
23057 "19: movl 32(%4), %%eax\n"
23058 "20: movl 36(%4), %%edx\n"
23059- "21: movl %%eax, 32(%3)\n"
23060- "22: movl %%edx, 36(%3)\n"
23061+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
23062+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
23063 "23: movl 40(%4), %%eax\n"
23064 "24: movl 44(%4), %%edx\n"
23065- "25: movl %%eax, 40(%3)\n"
23066- "26: movl %%edx, 44(%3)\n"
23067+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
23068+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
23069 "27: movl 48(%4), %%eax\n"
23070 "28: movl 52(%4), %%edx\n"
23071- "29: movl %%eax, 48(%3)\n"
23072- "30: movl %%edx, 52(%3)\n"
23073+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
23074+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
23075 "31: movl 56(%4), %%eax\n"
23076 "32: movl 60(%4), %%edx\n"
23077- "33: movl %%eax, 56(%3)\n"
23078- "34: movl %%edx, 60(%3)\n"
23079+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
23080+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
23081 " addl $-64, %0\n"
23082 " addl $64, %4\n"
23083 " addl $64, %3\n"
23084@@ -278,10 +282,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23085 " shrl $2, %0\n"
23086 " andl $3, %%eax\n"
23087 " cld\n"
23088+ __COPYUSER_SET_ES
23089 "99: rep; movsl\n"
23090 "36: movl %%eax, %0\n"
23091 "37: rep; movsb\n"
23092 "100:\n"
23093+ __COPYUSER_RESTORE_ES
23094 ".section .fixup,\"ax\"\n"
23095 "101: lea 0(%%eax,%0,4),%0\n"
23096 " jmp 100b\n"
23097@@ -334,46 +340,155 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23098 }
23099
23100 static unsigned long
23101+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
23102+{
23103+ int d0, d1;
23104+ __asm__ __volatile__(
23105+ " .align 2,0x90\n"
23106+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
23107+ " cmpl $67, %0\n"
23108+ " jbe 3f\n"
23109+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
23110+ " .align 2,0x90\n"
23111+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
23112+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
23113+ "5: movl %%eax, 0(%3)\n"
23114+ "6: movl %%edx, 4(%3)\n"
23115+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
23116+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
23117+ "9: movl %%eax, 8(%3)\n"
23118+ "10: movl %%edx, 12(%3)\n"
23119+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23120+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23121+ "13: movl %%eax, 16(%3)\n"
23122+ "14: movl %%edx, 20(%3)\n"
23123+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23124+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23125+ "17: movl %%eax, 24(%3)\n"
23126+ "18: movl %%edx, 28(%3)\n"
23127+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23128+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23129+ "21: movl %%eax, 32(%3)\n"
23130+ "22: movl %%edx, 36(%3)\n"
23131+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23132+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23133+ "25: movl %%eax, 40(%3)\n"
23134+ "26: movl %%edx, 44(%3)\n"
23135+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23136+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23137+ "29: movl %%eax, 48(%3)\n"
23138+ "30: movl %%edx, 52(%3)\n"
23139+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23140+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23141+ "33: movl %%eax, 56(%3)\n"
23142+ "34: movl %%edx, 60(%3)\n"
23143+ " addl $-64, %0\n"
23144+ " addl $64, %4\n"
23145+ " addl $64, %3\n"
23146+ " cmpl $63, %0\n"
23147+ " ja 1b\n"
23148+ "35: movl %0, %%eax\n"
23149+ " shrl $2, %0\n"
23150+ " andl $3, %%eax\n"
23151+ " cld\n"
23152+ "99: rep; "__copyuser_seg" movsl\n"
23153+ "36: movl %%eax, %0\n"
23154+ "37: rep; "__copyuser_seg" movsb\n"
23155+ "100:\n"
23156+ ".section .fixup,\"ax\"\n"
23157+ "101: lea 0(%%eax,%0,4),%0\n"
23158+ " jmp 100b\n"
23159+ ".previous\n"
23160+ ".section __ex_table,\"a\"\n"
23161+ " .align 4\n"
23162+ " .long 1b,100b\n"
23163+ " .long 2b,100b\n"
23164+ " .long 3b,100b\n"
23165+ " .long 4b,100b\n"
23166+ " .long 5b,100b\n"
23167+ " .long 6b,100b\n"
23168+ " .long 7b,100b\n"
23169+ " .long 8b,100b\n"
23170+ " .long 9b,100b\n"
23171+ " .long 10b,100b\n"
23172+ " .long 11b,100b\n"
23173+ " .long 12b,100b\n"
23174+ " .long 13b,100b\n"
23175+ " .long 14b,100b\n"
23176+ " .long 15b,100b\n"
23177+ " .long 16b,100b\n"
23178+ " .long 17b,100b\n"
23179+ " .long 18b,100b\n"
23180+ " .long 19b,100b\n"
23181+ " .long 20b,100b\n"
23182+ " .long 21b,100b\n"
23183+ " .long 22b,100b\n"
23184+ " .long 23b,100b\n"
23185+ " .long 24b,100b\n"
23186+ " .long 25b,100b\n"
23187+ " .long 26b,100b\n"
23188+ " .long 27b,100b\n"
23189+ " .long 28b,100b\n"
23190+ " .long 29b,100b\n"
23191+ " .long 30b,100b\n"
23192+ " .long 31b,100b\n"
23193+ " .long 32b,100b\n"
23194+ " .long 33b,100b\n"
23195+ " .long 34b,100b\n"
23196+ " .long 35b,100b\n"
23197+ " .long 36b,100b\n"
23198+ " .long 37b,100b\n"
23199+ " .long 99b,101b\n"
23200+ ".previous"
23201+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
23202+ : "1"(to), "2"(from), "0"(size)
23203+ : "eax", "edx", "memory");
23204+ return size;
23205+}
23206+
23207+static unsigned long
23208+__copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size) __size_overflow(3);
23209+static unsigned long
23210 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23211 {
23212 int d0, d1;
23213 __asm__ __volatile__(
23214 " .align 2,0x90\n"
23215- "0: movl 32(%4), %%eax\n"
23216+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23217 " cmpl $67, %0\n"
23218 " jbe 2f\n"
23219- "1: movl 64(%4), %%eax\n"
23220+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23221 " .align 2,0x90\n"
23222- "2: movl 0(%4), %%eax\n"
23223- "21: movl 4(%4), %%edx\n"
23224+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23225+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23226 " movl %%eax, 0(%3)\n"
23227 " movl %%edx, 4(%3)\n"
23228- "3: movl 8(%4), %%eax\n"
23229- "31: movl 12(%4),%%edx\n"
23230+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23231+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23232 " movl %%eax, 8(%3)\n"
23233 " movl %%edx, 12(%3)\n"
23234- "4: movl 16(%4), %%eax\n"
23235- "41: movl 20(%4), %%edx\n"
23236+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23237+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23238 " movl %%eax, 16(%3)\n"
23239 " movl %%edx, 20(%3)\n"
23240- "10: movl 24(%4), %%eax\n"
23241- "51: movl 28(%4), %%edx\n"
23242+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23243+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23244 " movl %%eax, 24(%3)\n"
23245 " movl %%edx, 28(%3)\n"
23246- "11: movl 32(%4), %%eax\n"
23247- "61: movl 36(%4), %%edx\n"
23248+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23249+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23250 " movl %%eax, 32(%3)\n"
23251 " movl %%edx, 36(%3)\n"
23252- "12: movl 40(%4), %%eax\n"
23253- "71: movl 44(%4), %%edx\n"
23254+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23255+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23256 " movl %%eax, 40(%3)\n"
23257 " movl %%edx, 44(%3)\n"
23258- "13: movl 48(%4), %%eax\n"
23259- "81: movl 52(%4), %%edx\n"
23260+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23261+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23262 " movl %%eax, 48(%3)\n"
23263 " movl %%edx, 52(%3)\n"
23264- "14: movl 56(%4), %%eax\n"
23265- "91: movl 60(%4), %%edx\n"
23266+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23267+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23268 " movl %%eax, 56(%3)\n"
23269 " movl %%edx, 60(%3)\n"
23270 " addl $-64, %0\n"
23271@@ -385,9 +500,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23272 " shrl $2, %0\n"
23273 " andl $3, %%eax\n"
23274 " cld\n"
23275- "6: rep; movsl\n"
23276+ "6: rep; "__copyuser_seg" movsl\n"
23277 " movl %%eax,%0\n"
23278- "7: rep; movsb\n"
23279+ "7: rep; "__copyuser_seg" movsb\n"
23280 "8:\n"
23281 ".section .fixup,\"ax\"\n"
23282 "9: lea 0(%%eax,%0,4),%0\n"
23283@@ -434,47 +549,49 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23284 */
23285
23286 static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23287+ const void __user *from, unsigned long size) __size_overflow(3);
23288+static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23289 const void __user *from, unsigned long size)
23290 {
23291 int d0, d1;
23292
23293 __asm__ __volatile__(
23294 " .align 2,0x90\n"
23295- "0: movl 32(%4), %%eax\n"
23296+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23297 " cmpl $67, %0\n"
23298 " jbe 2f\n"
23299- "1: movl 64(%4), %%eax\n"
23300+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23301 " .align 2,0x90\n"
23302- "2: movl 0(%4), %%eax\n"
23303- "21: movl 4(%4), %%edx\n"
23304+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23305+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23306 " movnti %%eax, 0(%3)\n"
23307 " movnti %%edx, 4(%3)\n"
23308- "3: movl 8(%4), %%eax\n"
23309- "31: movl 12(%4),%%edx\n"
23310+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23311+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23312 " movnti %%eax, 8(%3)\n"
23313 " movnti %%edx, 12(%3)\n"
23314- "4: movl 16(%4), %%eax\n"
23315- "41: movl 20(%4), %%edx\n"
23316+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23317+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23318 " movnti %%eax, 16(%3)\n"
23319 " movnti %%edx, 20(%3)\n"
23320- "10: movl 24(%4), %%eax\n"
23321- "51: movl 28(%4), %%edx\n"
23322+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23323+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23324 " movnti %%eax, 24(%3)\n"
23325 " movnti %%edx, 28(%3)\n"
23326- "11: movl 32(%4), %%eax\n"
23327- "61: movl 36(%4), %%edx\n"
23328+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23329+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23330 " movnti %%eax, 32(%3)\n"
23331 " movnti %%edx, 36(%3)\n"
23332- "12: movl 40(%4), %%eax\n"
23333- "71: movl 44(%4), %%edx\n"
23334+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23335+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23336 " movnti %%eax, 40(%3)\n"
23337 " movnti %%edx, 44(%3)\n"
23338- "13: movl 48(%4), %%eax\n"
23339- "81: movl 52(%4), %%edx\n"
23340+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23341+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23342 " movnti %%eax, 48(%3)\n"
23343 " movnti %%edx, 52(%3)\n"
23344- "14: movl 56(%4), %%eax\n"
23345- "91: movl 60(%4), %%edx\n"
23346+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23347+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23348 " movnti %%eax, 56(%3)\n"
23349 " movnti %%edx, 60(%3)\n"
23350 " addl $-64, %0\n"
23351@@ -487,9 +604,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23352 " shrl $2, %0\n"
23353 " andl $3, %%eax\n"
23354 " cld\n"
23355- "6: rep; movsl\n"
23356+ "6: rep; "__copyuser_seg" movsl\n"
23357 " movl %%eax,%0\n"
23358- "7: rep; movsb\n"
23359+ "7: rep; "__copyuser_seg" movsb\n"
23360 "8:\n"
23361 ".section .fixup,\"ax\"\n"
23362 "9: lea 0(%%eax,%0,4),%0\n"
23363@@ -531,47 +648,49 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23364 }
23365
23366 static unsigned long __copy_user_intel_nocache(void *to,
23367+ const void __user *from, unsigned long size) __size_overflow(3);
23368+static unsigned long __copy_user_intel_nocache(void *to,
23369 const void __user *from, unsigned long size)
23370 {
23371 int d0, d1;
23372
23373 __asm__ __volatile__(
23374 " .align 2,0x90\n"
23375- "0: movl 32(%4), %%eax\n"
23376+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23377 " cmpl $67, %0\n"
23378 " jbe 2f\n"
23379- "1: movl 64(%4), %%eax\n"
23380+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23381 " .align 2,0x90\n"
23382- "2: movl 0(%4), %%eax\n"
23383- "21: movl 4(%4), %%edx\n"
23384+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23385+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23386 " movnti %%eax, 0(%3)\n"
23387 " movnti %%edx, 4(%3)\n"
23388- "3: movl 8(%4), %%eax\n"
23389- "31: movl 12(%4),%%edx\n"
23390+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23391+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23392 " movnti %%eax, 8(%3)\n"
23393 " movnti %%edx, 12(%3)\n"
23394- "4: movl 16(%4), %%eax\n"
23395- "41: movl 20(%4), %%edx\n"
23396+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23397+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23398 " movnti %%eax, 16(%3)\n"
23399 " movnti %%edx, 20(%3)\n"
23400- "10: movl 24(%4), %%eax\n"
23401- "51: movl 28(%4), %%edx\n"
23402+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23403+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23404 " movnti %%eax, 24(%3)\n"
23405 " movnti %%edx, 28(%3)\n"
23406- "11: movl 32(%4), %%eax\n"
23407- "61: movl 36(%4), %%edx\n"
23408+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23409+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23410 " movnti %%eax, 32(%3)\n"
23411 " movnti %%edx, 36(%3)\n"
23412- "12: movl 40(%4), %%eax\n"
23413- "71: movl 44(%4), %%edx\n"
23414+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23415+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23416 " movnti %%eax, 40(%3)\n"
23417 " movnti %%edx, 44(%3)\n"
23418- "13: movl 48(%4), %%eax\n"
23419- "81: movl 52(%4), %%edx\n"
23420+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23421+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23422 " movnti %%eax, 48(%3)\n"
23423 " movnti %%edx, 52(%3)\n"
23424- "14: movl 56(%4), %%eax\n"
23425- "91: movl 60(%4), %%edx\n"
23426+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23427+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23428 " movnti %%eax, 56(%3)\n"
23429 " movnti %%edx, 60(%3)\n"
23430 " addl $-64, %0\n"
23431@@ -584,9 +703,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23432 " shrl $2, %0\n"
23433 " andl $3, %%eax\n"
23434 " cld\n"
23435- "6: rep; movsl\n"
23436+ "6: rep; "__copyuser_seg" movsl\n"
23437 " movl %%eax,%0\n"
23438- "7: rep; movsb\n"
23439+ "7: rep; "__copyuser_seg" movsb\n"
23440 "8:\n"
23441 ".section .fixup,\"ax\"\n"
23442 "9: lea 0(%%eax,%0,4),%0\n"
23443@@ -629,32 +748,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23444 */
23445 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23446 unsigned long size);
23447-unsigned long __copy_user_intel(void __user *to, const void *from,
23448+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23449+ unsigned long size);
23450+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23451 unsigned long size);
23452 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23453 const void __user *from, unsigned long size);
23454 #endif /* CONFIG_X86_INTEL_USERCOPY */
23455
23456 /* Generic arbitrary sized copy. */
23457-#define __copy_user(to, from, size) \
23458+#define __copy_user(to, from, size, prefix, set, restore) \
23459 do { \
23460 int __d0, __d1, __d2; \
23461 __asm__ __volatile__( \
23462+ set \
23463 " cmp $7,%0\n" \
23464 " jbe 1f\n" \
23465 " movl %1,%0\n" \
23466 " negl %0\n" \
23467 " andl $7,%0\n" \
23468 " subl %0,%3\n" \
23469- "4: rep; movsb\n" \
23470+ "4: rep; "prefix"movsb\n" \
23471 " movl %3,%0\n" \
23472 " shrl $2,%0\n" \
23473 " andl $3,%3\n" \
23474 " .align 2,0x90\n" \
23475- "0: rep; movsl\n" \
23476+ "0: rep; "prefix"movsl\n" \
23477 " movl %3,%0\n" \
23478- "1: rep; movsb\n" \
23479+ "1: rep; "prefix"movsb\n" \
23480 "2:\n" \
23481+ restore \
23482 ".section .fixup,\"ax\"\n" \
23483 "5: addl %3,%0\n" \
23484 " jmp 2b\n" \
23485@@ -682,14 +805,14 @@ do { \
23486 " negl %0\n" \
23487 " andl $7,%0\n" \
23488 " subl %0,%3\n" \
23489- "4: rep; movsb\n" \
23490+ "4: rep; "__copyuser_seg"movsb\n" \
23491 " movl %3,%0\n" \
23492 " shrl $2,%0\n" \
23493 " andl $3,%3\n" \
23494 " .align 2,0x90\n" \
23495- "0: rep; movsl\n" \
23496+ "0: rep; "__copyuser_seg"movsl\n" \
23497 " movl %3,%0\n" \
23498- "1: rep; movsb\n" \
23499+ "1: rep; "__copyuser_seg"movsb\n" \
23500 "2:\n" \
23501 ".section .fixup,\"ax\"\n" \
23502 "5: addl %3,%0\n" \
23503@@ -775,9 +898,9 @@ survive:
23504 }
23505 #endif
23506 if (movsl_is_ok(to, from, n))
23507- __copy_user(to, from, n);
23508+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23509 else
23510- n = __copy_user_intel(to, from, n);
23511+ n = __generic_copy_to_user_intel(to, from, n);
23512 return n;
23513 }
23514 EXPORT_SYMBOL(__copy_to_user_ll);
23515@@ -797,10 +920,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23516 unsigned long n)
23517 {
23518 if (movsl_is_ok(to, from, n))
23519- __copy_user(to, from, n);
23520+ __copy_user(to, from, n, __copyuser_seg, "", "");
23521 else
23522- n = __copy_user_intel((void __user *)to,
23523- (const void *)from, n);
23524+ n = __generic_copy_from_user_intel(to, from, n);
23525 return n;
23526 }
23527 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23528@@ -827,65 +949,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23529 if (n > 64 && cpu_has_xmm2)
23530 n = __copy_user_intel_nocache(to, from, n);
23531 else
23532- __copy_user(to, from, n);
23533+ __copy_user(to, from, n, __copyuser_seg, "", "");
23534 #else
23535- __copy_user(to, from, n);
23536+ __copy_user(to, from, n, __copyuser_seg, "", "");
23537 #endif
23538 return n;
23539 }
23540 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23541
23542-/**
23543- * copy_to_user: - Copy a block of data into user space.
23544- * @to: Destination address, in user space.
23545- * @from: Source address, in kernel space.
23546- * @n: Number of bytes to copy.
23547- *
23548- * Context: User context only. This function may sleep.
23549- *
23550- * Copy data from kernel space to user space.
23551- *
23552- * Returns number of bytes that could not be copied.
23553- * On success, this will be zero.
23554- */
23555-unsigned long
23556-copy_to_user(void __user *to, const void *from, unsigned long n)
23557-{
23558- if (access_ok(VERIFY_WRITE, to, n))
23559- n = __copy_to_user(to, from, n);
23560- return n;
23561-}
23562-EXPORT_SYMBOL(copy_to_user);
23563-
23564-/**
23565- * copy_from_user: - Copy a block of data from user space.
23566- * @to: Destination address, in kernel space.
23567- * @from: Source address, in user space.
23568- * @n: Number of bytes to copy.
23569- *
23570- * Context: User context only. This function may sleep.
23571- *
23572- * Copy data from user space to kernel space.
23573- *
23574- * Returns number of bytes that could not be copied.
23575- * On success, this will be zero.
23576- *
23577- * If some data could not be copied, this function will pad the copied
23578- * data to the requested size using zero bytes.
23579- */
23580-unsigned long
23581-_copy_from_user(void *to, const void __user *from, unsigned long n)
23582-{
23583- if (access_ok(VERIFY_READ, from, n))
23584- n = __copy_from_user(to, from, n);
23585- else
23586- memset(to, 0, n);
23587- return n;
23588-}
23589-EXPORT_SYMBOL(_copy_from_user);
23590-
23591 void copy_from_user_overflow(void)
23592 {
23593 WARN(1, "Buffer overflow detected!\n");
23594 }
23595 EXPORT_SYMBOL(copy_from_user_overflow);
23596+
23597+void copy_to_user_overflow(void)
23598+{
23599+ WARN(1, "Buffer overflow detected!\n");
23600+}
23601+EXPORT_SYMBOL(copy_to_user_overflow);
23602+
23603+#ifdef CONFIG_PAX_MEMORY_UDEREF
23604+void __set_fs(mm_segment_t x)
23605+{
23606+ switch (x.seg) {
23607+ case 0:
23608+ loadsegment(gs, 0);
23609+ break;
23610+ case TASK_SIZE_MAX:
23611+ loadsegment(gs, __USER_DS);
23612+ break;
23613+ case -1UL:
23614+ loadsegment(gs, __KERNEL_DS);
23615+ break;
23616+ default:
23617+ BUG();
23618+ }
23619+ return;
23620+}
23621+EXPORT_SYMBOL(__set_fs);
23622+
23623+void set_fs(mm_segment_t x)
23624+{
23625+ current_thread_info()->addr_limit = x;
23626+ __set_fs(x);
23627+}
23628+EXPORT_SYMBOL(set_fs);
23629+#endif
23630diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23631index b7c2849..8633ad8 100644
23632--- a/arch/x86/lib/usercopy_64.c
23633+++ b/arch/x86/lib/usercopy_64.c
23634@@ -42,6 +42,12 @@ long
23635 __strncpy_from_user(char *dst, const char __user *src, long count)
23636 {
23637 long res;
23638+
23639+#ifdef CONFIG_PAX_MEMORY_UDEREF
23640+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
23641+ src += PAX_USER_SHADOW_BASE;
23642+#endif
23643+
23644 __do_strncpy_from_user(dst, src, count, res);
23645 return res;
23646 }
23647@@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23648 {
23649 long __d0;
23650 might_fault();
23651+
23652+#ifdef CONFIG_PAX_MEMORY_UDEREF
23653+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23654+ addr += PAX_USER_SHADOW_BASE;
23655+#endif
23656+
23657 /* no memory constraint because it doesn't change any memory gcc knows
23658 about */
23659 asm volatile(
23660@@ -149,12 +161,20 @@ long strlen_user(const char __user *s)
23661 }
23662 EXPORT_SYMBOL(strlen_user);
23663
23664-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23665+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23666 {
23667- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23668- return copy_user_generic((__force void *)to, (__force void *)from, len);
23669- }
23670- return len;
23671+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23672+
23673+#ifdef CONFIG_PAX_MEMORY_UDEREF
23674+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23675+ to += PAX_USER_SHADOW_BASE;
23676+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23677+ from += PAX_USER_SHADOW_BASE;
23678+#endif
23679+
23680+ return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23681+ }
23682+ return len;
23683 }
23684 EXPORT_SYMBOL(copy_in_user);
23685
23686@@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
23687 * it is not necessary to optimize tail handling.
23688 */
23689 unsigned long
23690-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23691+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23692 {
23693 char c;
23694 unsigned zero_len;
23695diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23696index 1fb85db..8b3540b 100644
23697--- a/arch/x86/mm/extable.c
23698+++ b/arch/x86/mm/extable.c
23699@@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
23700 const struct exception_table_entry *fixup;
23701
23702 #ifdef CONFIG_PNPBIOS
23703- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23704+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23705 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23706 extern u32 pnp_bios_is_utter_crap;
23707 pnp_bios_is_utter_crap = 1;
23708diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23709index f0b4caf..d92fd42 100644
23710--- a/arch/x86/mm/fault.c
23711+++ b/arch/x86/mm/fault.c
23712@@ -13,11 +13,18 @@
23713 #include <linux/perf_event.h> /* perf_sw_event */
23714 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23715 #include <linux/prefetch.h> /* prefetchw */
23716+#include <linux/unistd.h>
23717+#include <linux/compiler.h>
23718
23719 #include <asm/traps.h> /* dotraplinkage, ... */
23720 #include <asm/pgalloc.h> /* pgd_*(), ... */
23721 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23722 #include <asm/fixmap.h> /* VSYSCALL_START */
23723+#include <asm/tlbflush.h>
23724+
23725+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23726+#include <asm/stacktrace.h>
23727+#endif
23728
23729 /*
23730 * Page fault error code bits:
23731@@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23732 int ret = 0;
23733
23734 /* kprobe_running() needs smp_processor_id() */
23735- if (kprobes_built_in() && !user_mode_vm(regs)) {
23736+ if (kprobes_built_in() && !user_mode(regs)) {
23737 preempt_disable();
23738 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23739 ret = 1;
23740@@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23741 return !instr_lo || (instr_lo>>1) == 1;
23742 case 0x00:
23743 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23744- if (probe_kernel_address(instr, opcode))
23745+ if (user_mode(regs)) {
23746+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23747+ return 0;
23748+ } else if (probe_kernel_address(instr, opcode))
23749 return 0;
23750
23751 *prefetch = (instr_lo == 0xF) &&
23752@@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23753 while (instr < max_instr) {
23754 unsigned char opcode;
23755
23756- if (probe_kernel_address(instr, opcode))
23757+ if (user_mode(regs)) {
23758+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23759+ break;
23760+ } else if (probe_kernel_address(instr, opcode))
23761 break;
23762
23763 instr++;
23764@@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23765 force_sig_info(si_signo, &info, tsk);
23766 }
23767
23768+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23769+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23770+#endif
23771+
23772+#ifdef CONFIG_PAX_EMUTRAMP
23773+static int pax_handle_fetch_fault(struct pt_regs *regs);
23774+#endif
23775+
23776+#ifdef CONFIG_PAX_PAGEEXEC
23777+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23778+{
23779+ pgd_t *pgd;
23780+ pud_t *pud;
23781+ pmd_t *pmd;
23782+
23783+ pgd = pgd_offset(mm, address);
23784+ if (!pgd_present(*pgd))
23785+ return NULL;
23786+ pud = pud_offset(pgd, address);
23787+ if (!pud_present(*pud))
23788+ return NULL;
23789+ pmd = pmd_offset(pud, address);
23790+ if (!pmd_present(*pmd))
23791+ return NULL;
23792+ return pmd;
23793+}
23794+#endif
23795+
23796 DEFINE_SPINLOCK(pgd_lock);
23797 LIST_HEAD(pgd_list);
23798
23799@@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23800 for (address = VMALLOC_START & PMD_MASK;
23801 address >= TASK_SIZE && address < FIXADDR_TOP;
23802 address += PMD_SIZE) {
23803+
23804+#ifdef CONFIG_PAX_PER_CPU_PGD
23805+ unsigned long cpu;
23806+#else
23807 struct page *page;
23808+#endif
23809
23810 spin_lock(&pgd_lock);
23811+
23812+#ifdef CONFIG_PAX_PER_CPU_PGD
23813+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23814+ pgd_t *pgd = get_cpu_pgd(cpu);
23815+ pmd_t *ret;
23816+#else
23817 list_for_each_entry(page, &pgd_list, lru) {
23818+ pgd_t *pgd = page_address(page);
23819 spinlock_t *pgt_lock;
23820 pmd_t *ret;
23821
23822@@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23823 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23824
23825 spin_lock(pgt_lock);
23826- ret = vmalloc_sync_one(page_address(page), address);
23827+#endif
23828+
23829+ ret = vmalloc_sync_one(pgd, address);
23830+
23831+#ifndef CONFIG_PAX_PER_CPU_PGD
23832 spin_unlock(pgt_lock);
23833+#endif
23834
23835 if (!ret)
23836 break;
23837@@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23838 * an interrupt in the middle of a task switch..
23839 */
23840 pgd_paddr = read_cr3();
23841+
23842+#ifdef CONFIG_PAX_PER_CPU_PGD
23843+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23844+#endif
23845+
23846 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23847 if (!pmd_k)
23848 return -1;
23849@@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23850 * happen within a race in page table update. In the later
23851 * case just flush:
23852 */
23853+
23854+#ifdef CONFIG_PAX_PER_CPU_PGD
23855+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23856+ pgd = pgd_offset_cpu(smp_processor_id(), address);
23857+#else
23858 pgd = pgd_offset(current->active_mm, address);
23859+#endif
23860+
23861 pgd_ref = pgd_offset_k(address);
23862 if (pgd_none(*pgd_ref))
23863 return -1;
23864@@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23865 static int is_errata100(struct pt_regs *regs, unsigned long address)
23866 {
23867 #ifdef CONFIG_X86_64
23868- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23869+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23870 return 1;
23871 #endif
23872 return 0;
23873@@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23874 }
23875
23876 static const char nx_warning[] = KERN_CRIT
23877-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23878+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23879
23880 static void
23881 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23882@@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23883 if (!oops_may_print())
23884 return;
23885
23886- if (error_code & PF_INSTR) {
23887+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23888 unsigned int level;
23889
23890 pte_t *pte = lookup_address(address, &level);
23891
23892 if (pte && pte_present(*pte) && !pte_exec(*pte))
23893- printk(nx_warning, current_uid());
23894+ printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
23895 }
23896
23897+#ifdef CONFIG_PAX_KERNEXEC
23898+ if (init_mm.start_code <= address && address < init_mm.end_code) {
23899+ if (current->signal->curr_ip)
23900+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23901+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23902+ else
23903+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23904+ current->comm, task_pid_nr(current), current_uid(), current_euid());
23905+ }
23906+#endif
23907+
23908 printk(KERN_ALERT "BUG: unable to handle kernel ");
23909 if (address < PAGE_SIZE)
23910 printk(KERN_CONT "NULL pointer dereference");
23911@@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23912 }
23913 #endif
23914
23915+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23916+ if (pax_is_fetch_fault(regs, error_code, address)) {
23917+
23918+#ifdef CONFIG_PAX_EMUTRAMP
23919+ switch (pax_handle_fetch_fault(regs)) {
23920+ case 2:
23921+ return;
23922+ }
23923+#endif
23924+
23925+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23926+ do_group_exit(SIGKILL);
23927+ }
23928+#endif
23929+
23930 if (unlikely(show_unhandled_signals))
23931 show_signal_msg(regs, error_code, address, tsk);
23932
23933@@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23934 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23935 printk(KERN_ERR
23936 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23937- tsk->comm, tsk->pid, address);
23938+ tsk->comm, task_pid_nr(tsk), address);
23939 code = BUS_MCEERR_AR;
23940 }
23941 #endif
23942@@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23943 return 1;
23944 }
23945
23946+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23947+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23948+{
23949+ pte_t *pte;
23950+ pmd_t *pmd;
23951+ spinlock_t *ptl;
23952+ unsigned char pte_mask;
23953+
23954+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23955+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
23956+ return 0;
23957+
23958+ /* PaX: it's our fault, let's handle it if we can */
23959+
23960+ /* PaX: take a look at read faults before acquiring any locks */
23961+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23962+ /* instruction fetch attempt from a protected page in user mode */
23963+ up_read(&mm->mmap_sem);
23964+
23965+#ifdef CONFIG_PAX_EMUTRAMP
23966+ switch (pax_handle_fetch_fault(regs)) {
23967+ case 2:
23968+ return 1;
23969+ }
23970+#endif
23971+
23972+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23973+ do_group_exit(SIGKILL);
23974+ }
23975+
23976+ pmd = pax_get_pmd(mm, address);
23977+ if (unlikely(!pmd))
23978+ return 0;
23979+
23980+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23981+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23982+ pte_unmap_unlock(pte, ptl);
23983+ return 0;
23984+ }
23985+
23986+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23987+ /* write attempt to a protected page in user mode */
23988+ pte_unmap_unlock(pte, ptl);
23989+ return 0;
23990+ }
23991+
23992+#ifdef CONFIG_SMP
23993+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23994+#else
23995+ if (likely(address > get_limit(regs->cs)))
23996+#endif
23997+ {
23998+ set_pte(pte, pte_mkread(*pte));
23999+ __flush_tlb_one(address);
24000+ pte_unmap_unlock(pte, ptl);
24001+ up_read(&mm->mmap_sem);
24002+ return 1;
24003+ }
24004+
24005+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
24006+
24007+ /*
24008+ * PaX: fill DTLB with user rights and retry
24009+ */
24010+ __asm__ __volatile__ (
24011+ "orb %2,(%1)\n"
24012+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
24013+/*
24014+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
24015+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
24016+ * page fault when examined during a TLB load attempt. this is true not only
24017+ * for PTEs holding a non-present entry but also present entries that will
24018+ * raise a page fault (such as those set up by PaX, or the copy-on-write
24019+ * mechanism). in effect it means that we do *not* need to flush the TLBs
24020+ * for our target pages since their PTEs are simply not in the TLBs at all.
24021+
24022+ * the best thing in omitting it is that we gain around 15-20% speed in the
24023+ * fast path of the page fault handler and can get rid of tracing since we
24024+ * can no longer flush unintended entries.
24025+ */
24026+ "invlpg (%0)\n"
24027+#endif
24028+ __copyuser_seg"testb $0,(%0)\n"
24029+ "xorb %3,(%1)\n"
24030+ :
24031+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
24032+ : "memory", "cc");
24033+ pte_unmap_unlock(pte, ptl);
24034+ up_read(&mm->mmap_sem);
24035+ return 1;
24036+}
24037+#endif
24038+
24039 /*
24040 * Handle a spurious fault caused by a stale TLB entry.
24041 *
24042@@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
24043 static inline int
24044 access_error(unsigned long error_code, struct vm_area_struct *vma)
24045 {
24046+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
24047+ return 1;
24048+
24049 if (error_code & PF_WRITE) {
24050 /* write, present and write, not present: */
24051 if (unlikely(!(vma->vm_flags & VM_WRITE)))
24052@@ -1005,18 +1197,32 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24053 {
24054 struct vm_area_struct *vma;
24055 struct task_struct *tsk;
24056- unsigned long address;
24057 struct mm_struct *mm;
24058 int fault;
24059 int write = error_code & PF_WRITE;
24060 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
24061 (write ? FAULT_FLAG_WRITE : 0);
24062
24063- tsk = current;
24064- mm = tsk->mm;
24065-
24066 /* Get the faulting address: */
24067- address = read_cr2();
24068+ unsigned long address = read_cr2();
24069+
24070+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24071+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
24072+ if (!search_exception_tables(regs->ip)) {
24073+ bad_area_nosemaphore(regs, error_code, address);
24074+ return;
24075+ }
24076+ if (address < PAX_USER_SHADOW_BASE) {
24077+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24078+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
24079+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24080+ } else
24081+ address -= PAX_USER_SHADOW_BASE;
24082+ }
24083+#endif
24084+
24085+ tsk = current;
24086+ mm = tsk->mm;
24087
24088 /*
24089 * Detect and handle instructions that would cause a page fault for
24090@@ -1077,7 +1283,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24091 * User-mode registers count as a user access even for any
24092 * potential system fault or CPU buglet:
24093 */
24094- if (user_mode_vm(regs)) {
24095+ if (user_mode(regs)) {
24096 local_irq_enable();
24097 error_code |= PF_USER;
24098 } else {
24099@@ -1132,6 +1338,11 @@ retry:
24100 might_sleep();
24101 }
24102
24103+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24104+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24105+ return;
24106+#endif
24107+
24108 vma = find_vma(mm, address);
24109 if (unlikely(!vma)) {
24110 bad_area(regs, error_code, address);
24111@@ -1143,18 +1354,24 @@ retry:
24112 bad_area(regs, error_code, address);
24113 return;
24114 }
24115- if (error_code & PF_USER) {
24116- /*
24117- * Accessing the stack below %sp is always a bug.
24118- * The large cushion allows instructions like enter
24119- * and pusha to work. ("enter $65535, $31" pushes
24120- * 32 pointers and then decrements %sp by 65535.)
24121- */
24122- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24123- bad_area(regs, error_code, address);
24124- return;
24125- }
24126+ /*
24127+ * Accessing the stack below %sp is always a bug.
24128+ * The large cushion allows instructions like enter
24129+ * and pusha to work. ("enter $65535, $31" pushes
24130+ * 32 pointers and then decrements %sp by 65535.)
24131+ */
24132+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24133+ bad_area(regs, error_code, address);
24134+ return;
24135 }
24136+
24137+#ifdef CONFIG_PAX_SEGMEXEC
24138+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24139+ bad_area(regs, error_code, address);
24140+ return;
24141+ }
24142+#endif
24143+
24144 if (unlikely(expand_stack(vma, address))) {
24145 bad_area(regs, error_code, address);
24146 return;
24147@@ -1209,3 +1426,292 @@ good_area:
24148
24149 up_read(&mm->mmap_sem);
24150 }
24151+
24152+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24153+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24154+{
24155+ struct mm_struct *mm = current->mm;
24156+ unsigned long ip = regs->ip;
24157+
24158+ if (v8086_mode(regs))
24159+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24160+
24161+#ifdef CONFIG_PAX_PAGEEXEC
24162+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24163+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24164+ return true;
24165+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24166+ return true;
24167+ return false;
24168+ }
24169+#endif
24170+
24171+#ifdef CONFIG_PAX_SEGMEXEC
24172+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24173+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24174+ return true;
24175+ return false;
24176+ }
24177+#endif
24178+
24179+ return false;
24180+}
24181+#endif
24182+
24183+#ifdef CONFIG_PAX_EMUTRAMP
24184+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24185+{
24186+ int err;
24187+
24188+ do { /* PaX: libffi trampoline emulation */
24189+ unsigned char mov, jmp;
24190+ unsigned int addr1, addr2;
24191+
24192+#ifdef CONFIG_X86_64
24193+ if ((regs->ip + 9) >> 32)
24194+ break;
24195+#endif
24196+
24197+ err = get_user(mov, (unsigned char __user *)regs->ip);
24198+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24199+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24200+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24201+
24202+ if (err)
24203+ break;
24204+
24205+ if (mov == 0xB8 && jmp == 0xE9) {
24206+ regs->ax = addr1;
24207+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24208+ return 2;
24209+ }
24210+ } while (0);
24211+
24212+ do { /* PaX: gcc trampoline emulation #1 */
24213+ unsigned char mov1, mov2;
24214+ unsigned short jmp;
24215+ unsigned int addr1, addr2;
24216+
24217+#ifdef CONFIG_X86_64
24218+ if ((regs->ip + 11) >> 32)
24219+ break;
24220+#endif
24221+
24222+ err = get_user(mov1, (unsigned char __user *)regs->ip);
24223+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24224+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24225+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24226+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24227+
24228+ if (err)
24229+ break;
24230+
24231+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24232+ regs->cx = addr1;
24233+ regs->ax = addr2;
24234+ regs->ip = addr2;
24235+ return 2;
24236+ }
24237+ } while (0);
24238+
24239+ do { /* PaX: gcc trampoline emulation #2 */
24240+ unsigned char mov, jmp;
24241+ unsigned int addr1, addr2;
24242+
24243+#ifdef CONFIG_X86_64
24244+ if ((regs->ip + 9) >> 32)
24245+ break;
24246+#endif
24247+
24248+ err = get_user(mov, (unsigned char __user *)regs->ip);
24249+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24250+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24251+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24252+
24253+ if (err)
24254+ break;
24255+
24256+ if (mov == 0xB9 && jmp == 0xE9) {
24257+ regs->cx = addr1;
24258+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24259+ return 2;
24260+ }
24261+ } while (0);
24262+
24263+ return 1; /* PaX in action */
24264+}
24265+
24266+#ifdef CONFIG_X86_64
24267+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24268+{
24269+ int err;
24270+
24271+ do { /* PaX: libffi trampoline emulation */
24272+ unsigned short mov1, mov2, jmp1;
24273+ unsigned char stcclc, jmp2;
24274+ unsigned long addr1, addr2;
24275+
24276+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24277+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24278+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24279+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24280+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24281+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24282+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24283+
24284+ if (err)
24285+ break;
24286+
24287+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24288+ regs->r11 = addr1;
24289+ regs->r10 = addr2;
24290+ if (stcclc == 0xF8)
24291+ regs->flags &= ~X86_EFLAGS_CF;
24292+ else
24293+ regs->flags |= X86_EFLAGS_CF;
24294+ regs->ip = addr1;
24295+ return 2;
24296+ }
24297+ } while (0);
24298+
24299+ do { /* PaX: gcc trampoline emulation #1 */
24300+ unsigned short mov1, mov2, jmp1;
24301+ unsigned char jmp2;
24302+ unsigned int addr1;
24303+ unsigned long addr2;
24304+
24305+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24306+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24307+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24308+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24309+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24310+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24311+
24312+ if (err)
24313+ break;
24314+
24315+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24316+ regs->r11 = addr1;
24317+ regs->r10 = addr2;
24318+ regs->ip = addr1;
24319+ return 2;
24320+ }
24321+ } while (0);
24322+
24323+ do { /* PaX: gcc trampoline emulation #2 */
24324+ unsigned short mov1, mov2, jmp1;
24325+ unsigned char jmp2;
24326+ unsigned long addr1, addr2;
24327+
24328+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24329+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24330+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24331+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24332+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24333+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24334+
24335+ if (err)
24336+ break;
24337+
24338+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24339+ regs->r11 = addr1;
24340+ regs->r10 = addr2;
24341+ regs->ip = addr1;
24342+ return 2;
24343+ }
24344+ } while (0);
24345+
24346+ return 1; /* PaX in action */
24347+}
24348+#endif
24349+
24350+/*
24351+ * PaX: decide what to do with offenders (regs->ip = fault address)
24352+ *
24353+ * returns 1 when task should be killed
24354+ * 2 when gcc trampoline was detected
24355+ */
24356+static int pax_handle_fetch_fault(struct pt_regs *regs)
24357+{
24358+ if (v8086_mode(regs))
24359+ return 1;
24360+
24361+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24362+ return 1;
24363+
24364+#ifdef CONFIG_X86_32
24365+ return pax_handle_fetch_fault_32(regs);
24366+#else
24367+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24368+ return pax_handle_fetch_fault_32(regs);
24369+ else
24370+ return pax_handle_fetch_fault_64(regs);
24371+#endif
24372+}
24373+#endif
24374+
24375+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24376+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24377+{
24378+ long i;
24379+
24380+ printk(KERN_ERR "PAX: bytes at PC: ");
24381+ for (i = 0; i < 20; i++) {
24382+ unsigned char c;
24383+ if (get_user(c, (unsigned char __force_user *)pc+i))
24384+ printk(KERN_CONT "?? ");
24385+ else
24386+ printk(KERN_CONT "%02x ", c);
24387+ }
24388+ printk("\n");
24389+
24390+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24391+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
24392+ unsigned long c;
24393+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
24394+#ifdef CONFIG_X86_32
24395+ printk(KERN_CONT "???????? ");
24396+#else
24397+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24398+ printk(KERN_CONT "???????? ???????? ");
24399+ else
24400+ printk(KERN_CONT "???????????????? ");
24401+#endif
24402+ } else {
24403+#ifdef CONFIG_X86_64
24404+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24405+ printk(KERN_CONT "%08x ", (unsigned int)c);
24406+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24407+ } else
24408+#endif
24409+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24410+ }
24411+ }
24412+ printk("\n");
24413+}
24414+#endif
24415+
24416+/**
24417+ * probe_kernel_write(): safely attempt to write to a location
24418+ * @dst: address to write to
24419+ * @src: pointer to the data that shall be written
24420+ * @size: size of the data chunk
24421+ *
24422+ * Safely write to address @dst from the buffer at @src. If a kernel fault
24423+ * happens, handle that and return -EFAULT.
24424+ */
24425+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24426+{
24427+ long ret;
24428+ mm_segment_t old_fs = get_fs();
24429+
24430+ set_fs(KERNEL_DS);
24431+ pagefault_disable();
24432+ pax_open_kernel();
24433+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24434+ pax_close_kernel();
24435+ pagefault_enable();
24436+ set_fs(old_fs);
24437+
24438+ return ret ? -EFAULT : 0;
24439+}
24440diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24441index dd74e46..7d26398 100644
24442--- a/arch/x86/mm/gup.c
24443+++ b/arch/x86/mm/gup.c
24444@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24445 addr = start;
24446 len = (unsigned long) nr_pages << PAGE_SHIFT;
24447 end = start + len;
24448- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24449+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24450 (void __user *)start, len)))
24451 return 0;
24452
24453diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24454index f4f29b1..5cac4fb 100644
24455--- a/arch/x86/mm/highmem_32.c
24456+++ b/arch/x86/mm/highmem_32.c
24457@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24458 idx = type + KM_TYPE_NR*smp_processor_id();
24459 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24460 BUG_ON(!pte_none(*(kmap_pte-idx)));
24461+
24462+ pax_open_kernel();
24463 set_pte(kmap_pte-idx, mk_pte(page, prot));
24464+ pax_close_kernel();
24465+
24466 arch_flush_lazy_mmu_mode();
24467
24468 return (void *)vaddr;
24469diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24470index 8ecbb4b..a269cab 100644
24471--- a/arch/x86/mm/hugetlbpage.c
24472+++ b/arch/x86/mm/hugetlbpage.c
24473@@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24474 struct hstate *h = hstate_file(file);
24475 struct mm_struct *mm = current->mm;
24476 struct vm_area_struct *vma;
24477- unsigned long start_addr;
24478+ unsigned long start_addr, pax_task_size = TASK_SIZE;
24479+
24480+#ifdef CONFIG_PAX_SEGMEXEC
24481+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24482+ pax_task_size = SEGMEXEC_TASK_SIZE;
24483+#endif
24484+
24485+ pax_task_size -= PAGE_SIZE;
24486
24487 if (len > mm->cached_hole_size) {
24488- start_addr = mm->free_area_cache;
24489+ start_addr = mm->free_area_cache;
24490 } else {
24491- start_addr = TASK_UNMAPPED_BASE;
24492- mm->cached_hole_size = 0;
24493+ start_addr = mm->mmap_base;
24494+ mm->cached_hole_size = 0;
24495 }
24496
24497 full_search:
24498@@ -280,26 +287,27 @@ full_search:
24499
24500 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24501 /* At this point: (!vma || addr < vma->vm_end). */
24502- if (TASK_SIZE - len < addr) {
24503+ if (pax_task_size - len < addr) {
24504 /*
24505 * Start a new search - just in case we missed
24506 * some holes.
24507 */
24508- if (start_addr != TASK_UNMAPPED_BASE) {
24509- start_addr = TASK_UNMAPPED_BASE;
24510+ if (start_addr != mm->mmap_base) {
24511+ start_addr = mm->mmap_base;
24512 mm->cached_hole_size = 0;
24513 goto full_search;
24514 }
24515 return -ENOMEM;
24516 }
24517- if (!vma || addr + len <= vma->vm_start) {
24518- mm->free_area_cache = addr + len;
24519- return addr;
24520- }
24521+ if (check_heap_stack_gap(vma, addr, len))
24522+ break;
24523 if (addr + mm->cached_hole_size < vma->vm_start)
24524 mm->cached_hole_size = vma->vm_start - addr;
24525 addr = ALIGN(vma->vm_end, huge_page_size(h));
24526 }
24527+
24528+ mm->free_area_cache = addr + len;
24529+ return addr;
24530 }
24531
24532 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24533@@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24534 {
24535 struct hstate *h = hstate_file(file);
24536 struct mm_struct *mm = current->mm;
24537- struct vm_area_struct *vma, *prev_vma;
24538- unsigned long base = mm->mmap_base, addr = addr0;
24539+ struct vm_area_struct *vma;
24540+ unsigned long base = mm->mmap_base, addr;
24541 unsigned long largest_hole = mm->cached_hole_size;
24542- int first_time = 1;
24543
24544 /* don't allow allocations above current base */
24545 if (mm->free_area_cache > base)
24546@@ -321,14 +328,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24547 largest_hole = 0;
24548 mm->free_area_cache = base;
24549 }
24550-try_again:
24551+
24552 /* make sure it can fit in the remaining address space */
24553 if (mm->free_area_cache < len)
24554 goto fail;
24555
24556 /* either no address requested or can't fit in requested address hole */
24557- addr = (mm->free_area_cache - len) & huge_page_mask(h);
24558+ addr = (mm->free_area_cache - len);
24559 do {
24560+ addr &= huge_page_mask(h);
24561 /*
24562 * Lookup failure means no vma is above this address,
24563 * i.e. return with success:
24564@@ -341,46 +349,47 @@ try_again:
24565 * new region fits between prev_vma->vm_end and
24566 * vma->vm_start, use it:
24567 */
24568- prev_vma = vma->vm_prev;
24569- if (addr + len <= vma->vm_start &&
24570- (!prev_vma || (addr >= prev_vma->vm_end))) {
24571+ if (check_heap_stack_gap(vma, addr, len)) {
24572 /* remember the address as a hint for next time */
24573- mm->cached_hole_size = largest_hole;
24574- return (mm->free_area_cache = addr);
24575- } else {
24576- /* pull free_area_cache down to the first hole */
24577- if (mm->free_area_cache == vma->vm_end) {
24578- mm->free_area_cache = vma->vm_start;
24579- mm->cached_hole_size = largest_hole;
24580- }
24581+ mm->cached_hole_size = largest_hole;
24582+ return (mm->free_area_cache = addr);
24583+ }
24584+ /* pull free_area_cache down to the first hole */
24585+ if (mm->free_area_cache == vma->vm_end) {
24586+ mm->free_area_cache = vma->vm_start;
24587+ mm->cached_hole_size = largest_hole;
24588 }
24589
24590 /* remember the largest hole we saw so far */
24591 if (addr + largest_hole < vma->vm_start)
24592- largest_hole = vma->vm_start - addr;
24593+ largest_hole = vma->vm_start - addr;
24594
24595 /* try just below the current vma->vm_start */
24596- addr = (vma->vm_start - len) & huge_page_mask(h);
24597- } while (len <= vma->vm_start);
24598+ addr = skip_heap_stack_gap(vma, len);
24599+ } while (!IS_ERR_VALUE(addr));
24600
24601 fail:
24602 /*
24603- * if hint left us with no space for the requested
24604- * mapping then try again:
24605- */
24606- if (first_time) {
24607- mm->free_area_cache = base;
24608- largest_hole = 0;
24609- first_time = 0;
24610- goto try_again;
24611- }
24612- /*
24613 * A failed mmap() very likely causes application failure,
24614 * so fall back to the bottom-up function here. This scenario
24615 * can happen with large stack limits and large mmap()
24616 * allocations.
24617 */
24618- mm->free_area_cache = TASK_UNMAPPED_BASE;
24619+
24620+#ifdef CONFIG_PAX_SEGMEXEC
24621+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24622+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24623+ else
24624+#endif
24625+
24626+ mm->mmap_base = TASK_UNMAPPED_BASE;
24627+
24628+#ifdef CONFIG_PAX_RANDMMAP
24629+ if (mm->pax_flags & MF_PAX_RANDMMAP)
24630+ mm->mmap_base += mm->delta_mmap;
24631+#endif
24632+
24633+ mm->free_area_cache = mm->mmap_base;
24634 mm->cached_hole_size = ~0UL;
24635 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24636 len, pgoff, flags);
24637@@ -388,6 +397,7 @@ fail:
24638 /*
24639 * Restore the topdown base:
24640 */
24641+ mm->mmap_base = base;
24642 mm->free_area_cache = base;
24643 mm->cached_hole_size = ~0UL;
24644
24645@@ -401,10 +411,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24646 struct hstate *h = hstate_file(file);
24647 struct mm_struct *mm = current->mm;
24648 struct vm_area_struct *vma;
24649+ unsigned long pax_task_size = TASK_SIZE;
24650
24651 if (len & ~huge_page_mask(h))
24652 return -EINVAL;
24653- if (len > TASK_SIZE)
24654+
24655+#ifdef CONFIG_PAX_SEGMEXEC
24656+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24657+ pax_task_size = SEGMEXEC_TASK_SIZE;
24658+#endif
24659+
24660+ pax_task_size -= PAGE_SIZE;
24661+
24662+ if (len > pax_task_size)
24663 return -ENOMEM;
24664
24665 if (flags & MAP_FIXED) {
24666@@ -416,8 +435,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24667 if (addr) {
24668 addr = ALIGN(addr, huge_page_size(h));
24669 vma = find_vma(mm, addr);
24670- if (TASK_SIZE - len >= addr &&
24671- (!vma || addr + len <= vma->vm_start))
24672+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24673 return addr;
24674 }
24675 if (mm->get_unmapped_area == arch_get_unmapped_area)
24676diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24677index 6cabf65..74565da 100644
24678--- a/arch/x86/mm/init.c
24679+++ b/arch/x86/mm/init.c
24680@@ -17,6 +17,8 @@
24681 #include <asm/tlb.h>
24682 #include <asm/proto.h>
24683 #include <asm/dma.h> /* for MAX_DMA_PFN */
24684+#include <asm/desc.h>
24685+#include <asm/bios_ebda.h>
24686
24687 unsigned long __initdata pgt_buf_start;
24688 unsigned long __meminitdata pgt_buf_end;
24689@@ -33,7 +35,7 @@ int direct_gbpages
24690 static void __init find_early_table_space(unsigned long end, int use_pse,
24691 int use_gbpages)
24692 {
24693- unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24694+ unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24695 phys_addr_t base;
24696
24697 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24698@@ -312,10 +314,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24699 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24700 * mmio resources as well as potential bios/acpi data regions.
24701 */
24702+
24703+#ifdef CONFIG_GRKERNSEC_KMEM
24704+static unsigned int ebda_start __read_only;
24705+static unsigned int ebda_end __read_only;
24706+#endif
24707+
24708 int devmem_is_allowed(unsigned long pagenr)
24709 {
24710+#ifdef CONFIG_GRKERNSEC_KMEM
24711+ /* allow BDA */
24712+ if (!pagenr)
24713+ return 1;
24714+ /* allow EBDA */
24715+ if (pagenr >= ebda_start && pagenr < ebda_end)
24716+ return 1;
24717+#else
24718+ if (!pagenr)
24719+ return 1;
24720+#ifdef CONFIG_VM86
24721+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24722+ return 1;
24723+#endif
24724+#endif
24725+
24726+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24727+ return 1;
24728+#ifdef CONFIG_GRKERNSEC_KMEM
24729+ /* throw out everything else below 1MB */
24730 if (pagenr <= 256)
24731- return 1;
24732+ return 0;
24733+#endif
24734 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24735 return 0;
24736 if (!page_is_ram(pagenr))
24737@@ -372,8 +401,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24738 #endif
24739 }
24740
24741+#ifdef CONFIG_GRKERNSEC_KMEM
24742+static inline void gr_init_ebda(void)
24743+{
24744+ unsigned int ebda_addr;
24745+ unsigned int ebda_size = 0;
24746+
24747+ ebda_addr = get_bios_ebda();
24748+ if (ebda_addr) {
24749+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24750+ ebda_size <<= 10;
24751+ }
24752+ if (ebda_addr && ebda_size) {
24753+ ebda_start = ebda_addr >> PAGE_SHIFT;
24754+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24755+ } else {
24756+ ebda_start = 0x9f000 >> PAGE_SHIFT;
24757+ ebda_end = 0xa0000 >> PAGE_SHIFT;
24758+ }
24759+}
24760+#else
24761+static inline void gr_init_ebda(void) { }
24762+#endif
24763+
24764 void free_initmem(void)
24765 {
24766+#ifdef CONFIG_PAX_KERNEXEC
24767+#ifdef CONFIG_X86_32
24768+ /* PaX: limit KERNEL_CS to actual size */
24769+ unsigned long addr, limit;
24770+ struct desc_struct d;
24771+ int cpu;
24772+#else
24773+ pgd_t *pgd;
24774+ pud_t *pud;
24775+ pmd_t *pmd;
24776+ unsigned long addr, end;
24777+#endif
24778+#endif
24779+
24780+ gr_init_ebda();
24781+
24782+#ifdef CONFIG_PAX_KERNEXEC
24783+#ifdef CONFIG_X86_32
24784+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24785+ limit = (limit - 1UL) >> PAGE_SHIFT;
24786+
24787+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24788+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24789+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24790+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24791+ }
24792+
24793+ /* PaX: make KERNEL_CS read-only */
24794+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24795+ if (!paravirt_enabled())
24796+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24797+/*
24798+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24799+ pgd = pgd_offset_k(addr);
24800+ pud = pud_offset(pgd, addr);
24801+ pmd = pmd_offset(pud, addr);
24802+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24803+ }
24804+*/
24805+#ifdef CONFIG_X86_PAE
24806+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24807+/*
24808+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24809+ pgd = pgd_offset_k(addr);
24810+ pud = pud_offset(pgd, addr);
24811+ pmd = pmd_offset(pud, addr);
24812+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24813+ }
24814+*/
24815+#endif
24816+
24817+#ifdef CONFIG_MODULES
24818+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24819+#endif
24820+
24821+#else
24822+ /* PaX: make kernel code/rodata read-only, rest non-executable */
24823+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24824+ pgd = pgd_offset_k(addr);
24825+ pud = pud_offset(pgd, addr);
24826+ pmd = pmd_offset(pud, addr);
24827+ if (!pmd_present(*pmd))
24828+ continue;
24829+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24830+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24831+ else
24832+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24833+ }
24834+
24835+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24836+ end = addr + KERNEL_IMAGE_SIZE;
24837+ for (; addr < end; addr += PMD_SIZE) {
24838+ pgd = pgd_offset_k(addr);
24839+ pud = pud_offset(pgd, addr);
24840+ pmd = pmd_offset(pud, addr);
24841+ if (!pmd_present(*pmd))
24842+ continue;
24843+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24844+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24845+ }
24846+#endif
24847+
24848+ flush_tlb_all();
24849+#endif
24850+
24851 free_init_pages("unused kernel memory",
24852 (unsigned long)(&__init_begin),
24853 (unsigned long)(&__init_end));
24854diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24855index 8663f6c..829ae76 100644
24856--- a/arch/x86/mm/init_32.c
24857+++ b/arch/x86/mm/init_32.c
24858@@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
24859 }
24860
24861 /*
24862- * Creates a middle page table and puts a pointer to it in the
24863- * given global directory entry. This only returns the gd entry
24864- * in non-PAE compilation mode, since the middle layer is folded.
24865- */
24866-static pmd_t * __init one_md_table_init(pgd_t *pgd)
24867-{
24868- pud_t *pud;
24869- pmd_t *pmd_table;
24870-
24871-#ifdef CONFIG_X86_PAE
24872- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24873- if (after_bootmem)
24874- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24875- else
24876- pmd_table = (pmd_t *)alloc_low_page();
24877- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24878- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24879- pud = pud_offset(pgd, 0);
24880- BUG_ON(pmd_table != pmd_offset(pud, 0));
24881-
24882- return pmd_table;
24883- }
24884-#endif
24885- pud = pud_offset(pgd, 0);
24886- pmd_table = pmd_offset(pud, 0);
24887-
24888- return pmd_table;
24889-}
24890-
24891-/*
24892 * Create a page table and place a pointer to it in a middle page
24893 * directory entry:
24894 */
24895@@ -123,13 +93,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24896 page_table = (pte_t *)alloc_low_page();
24897
24898 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24899+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24900+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24901+#else
24902 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24903+#endif
24904 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24905 }
24906
24907 return pte_offset_kernel(pmd, 0);
24908 }
24909
24910+static pmd_t * __init one_md_table_init(pgd_t *pgd)
24911+{
24912+ pud_t *pud;
24913+ pmd_t *pmd_table;
24914+
24915+ pud = pud_offset(pgd, 0);
24916+ pmd_table = pmd_offset(pud, 0);
24917+
24918+ return pmd_table;
24919+}
24920+
24921 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24922 {
24923 int pgd_idx = pgd_index(vaddr);
24924@@ -203,6 +188,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24925 int pgd_idx, pmd_idx;
24926 unsigned long vaddr;
24927 pgd_t *pgd;
24928+ pud_t *pud;
24929 pmd_t *pmd;
24930 pte_t *pte = NULL;
24931
24932@@ -212,8 +198,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24933 pgd = pgd_base + pgd_idx;
24934
24935 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24936- pmd = one_md_table_init(pgd);
24937- pmd = pmd + pmd_index(vaddr);
24938+ pud = pud_offset(pgd, vaddr);
24939+ pmd = pmd_offset(pud, vaddr);
24940+
24941+#ifdef CONFIG_X86_PAE
24942+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24943+#endif
24944+
24945 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24946 pmd++, pmd_idx++) {
24947 pte = page_table_kmap_check(one_page_table_init(pmd),
24948@@ -225,11 +216,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24949 }
24950 }
24951
24952-static inline int is_kernel_text(unsigned long addr)
24953+static inline int is_kernel_text(unsigned long start, unsigned long end)
24954 {
24955- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24956- return 1;
24957- return 0;
24958+ if ((start > ktla_ktva((unsigned long)_etext) ||
24959+ end <= ktla_ktva((unsigned long)_stext)) &&
24960+ (start > ktla_ktva((unsigned long)_einittext) ||
24961+ end <= ktla_ktva((unsigned long)_sinittext)) &&
24962+
24963+#ifdef CONFIG_ACPI_SLEEP
24964+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24965+#endif
24966+
24967+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24968+ return 0;
24969+ return 1;
24970 }
24971
24972 /*
24973@@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned long start,
24974 unsigned long last_map_addr = end;
24975 unsigned long start_pfn, end_pfn;
24976 pgd_t *pgd_base = swapper_pg_dir;
24977- int pgd_idx, pmd_idx, pte_ofs;
24978+ unsigned int pgd_idx, pmd_idx, pte_ofs;
24979 unsigned long pfn;
24980 pgd_t *pgd;
24981+ pud_t *pud;
24982 pmd_t *pmd;
24983 pte_t *pte;
24984 unsigned pages_2m, pages_4k;
24985@@ -281,8 +282,13 @@ repeat:
24986 pfn = start_pfn;
24987 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24988 pgd = pgd_base + pgd_idx;
24989- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24990- pmd = one_md_table_init(pgd);
24991+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24992+ pud = pud_offset(pgd, 0);
24993+ pmd = pmd_offset(pud, 0);
24994+
24995+#ifdef CONFIG_X86_PAE
24996+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24997+#endif
24998
24999 if (pfn >= end_pfn)
25000 continue;
25001@@ -294,14 +300,13 @@ repeat:
25002 #endif
25003 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
25004 pmd++, pmd_idx++) {
25005- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
25006+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
25007
25008 /*
25009 * Map with big pages if possible, otherwise
25010 * create normal page tables:
25011 */
25012 if (use_pse) {
25013- unsigned int addr2;
25014 pgprot_t prot = PAGE_KERNEL_LARGE;
25015 /*
25016 * first pass will use the same initial
25017@@ -311,11 +316,7 @@ repeat:
25018 __pgprot(PTE_IDENT_ATTR |
25019 _PAGE_PSE);
25020
25021- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
25022- PAGE_OFFSET + PAGE_SIZE-1;
25023-
25024- if (is_kernel_text(addr) ||
25025- is_kernel_text(addr2))
25026+ if (is_kernel_text(address, address + PMD_SIZE))
25027 prot = PAGE_KERNEL_LARGE_EXEC;
25028
25029 pages_2m++;
25030@@ -332,7 +333,7 @@ repeat:
25031 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25032 pte += pte_ofs;
25033 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
25034- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
25035+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
25036 pgprot_t prot = PAGE_KERNEL;
25037 /*
25038 * first pass will use the same initial
25039@@ -340,7 +341,7 @@ repeat:
25040 */
25041 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
25042
25043- if (is_kernel_text(addr))
25044+ if (is_kernel_text(address, address + PAGE_SIZE))
25045 prot = PAGE_KERNEL_EXEC;
25046
25047 pages_4k++;
25048@@ -466,7 +467,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
25049
25050 pud = pud_offset(pgd, va);
25051 pmd = pmd_offset(pud, va);
25052- if (!pmd_present(*pmd))
25053+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
25054 break;
25055
25056 pte = pte_offset_kernel(pmd, va);
25057@@ -518,12 +519,10 @@ void __init early_ioremap_page_table_range_init(void)
25058
25059 static void __init pagetable_init(void)
25060 {
25061- pgd_t *pgd_base = swapper_pg_dir;
25062-
25063- permanent_kmaps_init(pgd_base);
25064+ permanent_kmaps_init(swapper_pg_dir);
25065 }
25066
25067-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25068+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25069 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25070
25071 /* user-defined highmem size */
25072@@ -735,6 +734,12 @@ void __init mem_init(void)
25073
25074 pci_iommu_alloc();
25075
25076+#ifdef CONFIG_PAX_PER_CPU_PGD
25077+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25078+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25079+ KERNEL_PGD_PTRS);
25080+#endif
25081+
25082 #ifdef CONFIG_FLATMEM
25083 BUG_ON(!mem_map);
25084 #endif
25085@@ -761,7 +766,7 @@ void __init mem_init(void)
25086 reservedpages++;
25087
25088 codesize = (unsigned long) &_etext - (unsigned long) &_text;
25089- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25090+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25091 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25092
25093 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25094@@ -802,10 +807,10 @@ void __init mem_init(void)
25095 ((unsigned long)&__init_end -
25096 (unsigned long)&__init_begin) >> 10,
25097
25098- (unsigned long)&_etext, (unsigned long)&_edata,
25099- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25100+ (unsigned long)&_sdata, (unsigned long)&_edata,
25101+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25102
25103- (unsigned long)&_text, (unsigned long)&_etext,
25104+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25105 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25106
25107 /*
25108@@ -883,6 +888,7 @@ void set_kernel_text_rw(void)
25109 if (!kernel_set_to_readonly)
25110 return;
25111
25112+ start = ktla_ktva(start);
25113 pr_debug("Set kernel text: %lx - %lx for read write\n",
25114 start, start+size);
25115
25116@@ -897,6 +903,7 @@ void set_kernel_text_ro(void)
25117 if (!kernel_set_to_readonly)
25118 return;
25119
25120+ start = ktla_ktva(start);
25121 pr_debug("Set kernel text: %lx - %lx for read only\n",
25122 start, start+size);
25123
25124@@ -925,6 +932,7 @@ void mark_rodata_ro(void)
25125 unsigned long start = PFN_ALIGN(_text);
25126 unsigned long size = PFN_ALIGN(_etext) - start;
25127
25128+ start = ktla_ktva(start);
25129 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25130 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25131 size >> 10);
25132diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25133index 436a030..4f97ffc 100644
25134--- a/arch/x86/mm/init_64.c
25135+++ b/arch/x86/mm/init_64.c
25136@@ -75,7 +75,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25137 * around without checking the pgd every time.
25138 */
25139
25140-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25141+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25142 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25143
25144 int force_personality32;
25145@@ -108,12 +108,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25146
25147 for (address = start; address <= end; address += PGDIR_SIZE) {
25148 const pgd_t *pgd_ref = pgd_offset_k(address);
25149+
25150+#ifdef CONFIG_PAX_PER_CPU_PGD
25151+ unsigned long cpu;
25152+#else
25153 struct page *page;
25154+#endif
25155
25156 if (pgd_none(*pgd_ref))
25157 continue;
25158
25159 spin_lock(&pgd_lock);
25160+
25161+#ifdef CONFIG_PAX_PER_CPU_PGD
25162+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25163+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
25164+#else
25165 list_for_each_entry(page, &pgd_list, lru) {
25166 pgd_t *pgd;
25167 spinlock_t *pgt_lock;
25168@@ -122,6 +132,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25169 /* the pgt_lock only for Xen */
25170 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25171 spin_lock(pgt_lock);
25172+#endif
25173
25174 if (pgd_none(*pgd))
25175 set_pgd(pgd, *pgd_ref);
25176@@ -129,7 +140,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25177 BUG_ON(pgd_page_vaddr(*pgd)
25178 != pgd_page_vaddr(*pgd_ref));
25179
25180+#ifndef CONFIG_PAX_PER_CPU_PGD
25181 spin_unlock(pgt_lock);
25182+#endif
25183+
25184 }
25185 spin_unlock(&pgd_lock);
25186 }
25187@@ -162,7 +176,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25188 {
25189 if (pgd_none(*pgd)) {
25190 pud_t *pud = (pud_t *)spp_getpage();
25191- pgd_populate(&init_mm, pgd, pud);
25192+ pgd_populate_kernel(&init_mm, pgd, pud);
25193 if (pud != pud_offset(pgd, 0))
25194 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25195 pud, pud_offset(pgd, 0));
25196@@ -174,7 +188,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25197 {
25198 if (pud_none(*pud)) {
25199 pmd_t *pmd = (pmd_t *) spp_getpage();
25200- pud_populate(&init_mm, pud, pmd);
25201+ pud_populate_kernel(&init_mm, pud, pmd);
25202 if (pmd != pmd_offset(pud, 0))
25203 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25204 pmd, pmd_offset(pud, 0));
25205@@ -203,7 +217,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25206 pmd = fill_pmd(pud, vaddr);
25207 pte = fill_pte(pmd, vaddr);
25208
25209+ pax_open_kernel();
25210 set_pte(pte, new_pte);
25211+ pax_close_kernel();
25212
25213 /*
25214 * It's enough to flush this one mapping.
25215@@ -262,14 +278,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25216 pgd = pgd_offset_k((unsigned long)__va(phys));
25217 if (pgd_none(*pgd)) {
25218 pud = (pud_t *) spp_getpage();
25219- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25220- _PAGE_USER));
25221+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25222 }
25223 pud = pud_offset(pgd, (unsigned long)__va(phys));
25224 if (pud_none(*pud)) {
25225 pmd = (pmd_t *) spp_getpage();
25226- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25227- _PAGE_USER));
25228+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25229 }
25230 pmd = pmd_offset(pud, phys);
25231 BUG_ON(!pmd_none(*pmd));
25232@@ -330,7 +344,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25233 if (pfn >= pgt_buf_top)
25234 panic("alloc_low_page: ran out of memory");
25235
25236- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25237+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25238 clear_page(adr);
25239 *phys = pfn * PAGE_SIZE;
25240 return adr;
25241@@ -346,7 +360,7 @@ static __ref void *map_low_page(void *virt)
25242
25243 phys = __pa(virt);
25244 left = phys & (PAGE_SIZE - 1);
25245- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25246+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25247 adr = (void *)(((unsigned long)adr) | left);
25248
25249 return adr;
25250@@ -546,7 +560,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25251 unmap_low_page(pmd);
25252
25253 spin_lock(&init_mm.page_table_lock);
25254- pud_populate(&init_mm, pud, __va(pmd_phys));
25255+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25256 spin_unlock(&init_mm.page_table_lock);
25257 }
25258 __flush_tlb_all();
25259@@ -592,7 +606,7 @@ kernel_physical_mapping_init(unsigned long start,
25260 unmap_low_page(pud);
25261
25262 spin_lock(&init_mm.page_table_lock);
25263- pgd_populate(&init_mm, pgd, __va(pud_phys));
25264+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25265 spin_unlock(&init_mm.page_table_lock);
25266 pgd_changed = true;
25267 }
25268@@ -684,6 +698,12 @@ void __init mem_init(void)
25269
25270 pci_iommu_alloc();
25271
25272+#ifdef CONFIG_PAX_PER_CPU_PGD
25273+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25274+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25275+ KERNEL_PGD_PTRS);
25276+#endif
25277+
25278 /* clear_bss() already clear the empty_zero_page */
25279
25280 reservedpages = 0;
25281@@ -844,8 +864,8 @@ int kern_addr_valid(unsigned long addr)
25282 static struct vm_area_struct gate_vma = {
25283 .vm_start = VSYSCALL_START,
25284 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25285- .vm_page_prot = PAGE_READONLY_EXEC,
25286- .vm_flags = VM_READ | VM_EXEC
25287+ .vm_page_prot = PAGE_READONLY,
25288+ .vm_flags = VM_READ
25289 };
25290
25291 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25292@@ -879,7 +899,7 @@ int in_gate_area_no_mm(unsigned long addr)
25293
25294 const char *arch_vma_name(struct vm_area_struct *vma)
25295 {
25296- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25297+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25298 return "[vdso]";
25299 if (vma == &gate_vma)
25300 return "[vsyscall]";
25301diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25302index 7b179b4..6bd1777 100644
25303--- a/arch/x86/mm/iomap_32.c
25304+++ b/arch/x86/mm/iomap_32.c
25305@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25306 type = kmap_atomic_idx_push();
25307 idx = type + KM_TYPE_NR * smp_processor_id();
25308 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25309+
25310+ pax_open_kernel();
25311 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25312+ pax_close_kernel();
25313+
25314 arch_flush_lazy_mmu_mode();
25315
25316 return (void *)vaddr;
25317diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25318index be1ef57..55f0160 100644
25319--- a/arch/x86/mm/ioremap.c
25320+++ b/arch/x86/mm/ioremap.c
25321@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25322 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25323 int is_ram = page_is_ram(pfn);
25324
25325- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25326+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25327 return NULL;
25328 WARN_ON_ONCE(is_ram);
25329 }
25330@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25331
25332 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25333 if (page_is_ram(start >> PAGE_SHIFT))
25334+#ifdef CONFIG_HIGHMEM
25335+ if ((start >> PAGE_SHIFT) < max_low_pfn)
25336+#endif
25337 return __va(phys);
25338
25339 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25340@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25341 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25342
25343 static __initdata int after_paging_init;
25344-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25345+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25346
25347 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25348 {
25349@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25350 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25351
25352 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25353- memset(bm_pte, 0, sizeof(bm_pte));
25354- pmd_populate_kernel(&init_mm, pmd, bm_pte);
25355+ pmd_populate_user(&init_mm, pmd, bm_pte);
25356
25357 /*
25358 * The boot-ioremap range spans multiple pmds, for which
25359diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25360index d87dd6d..bf3fa66 100644
25361--- a/arch/x86/mm/kmemcheck/kmemcheck.c
25362+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25363@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25364 * memory (e.g. tracked pages)? For now, we need this to avoid
25365 * invoking kmemcheck for PnP BIOS calls.
25366 */
25367- if (regs->flags & X86_VM_MASK)
25368+ if (v8086_mode(regs))
25369 return false;
25370- if (regs->cs != __KERNEL_CS)
25371+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25372 return false;
25373
25374 pte = kmemcheck_pte_lookup(address);
25375diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25376index 845df68..1d8d29f 100644
25377--- a/arch/x86/mm/mmap.c
25378+++ b/arch/x86/mm/mmap.c
25379@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25380 * Leave an at least ~128 MB hole with possible stack randomization.
25381 */
25382 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25383-#define MAX_GAP (TASK_SIZE/6*5)
25384+#define MAX_GAP (pax_task_size/6*5)
25385
25386 static int mmap_is_legacy(void)
25387 {
25388@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25389 return rnd << PAGE_SHIFT;
25390 }
25391
25392-static unsigned long mmap_base(void)
25393+static unsigned long mmap_base(struct mm_struct *mm)
25394 {
25395 unsigned long gap = rlimit(RLIMIT_STACK);
25396+ unsigned long pax_task_size = TASK_SIZE;
25397+
25398+#ifdef CONFIG_PAX_SEGMEXEC
25399+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25400+ pax_task_size = SEGMEXEC_TASK_SIZE;
25401+#endif
25402
25403 if (gap < MIN_GAP)
25404 gap = MIN_GAP;
25405 else if (gap > MAX_GAP)
25406 gap = MAX_GAP;
25407
25408- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25409+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25410 }
25411
25412 /*
25413 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25414 * does, but not when emulating X86_32
25415 */
25416-static unsigned long mmap_legacy_base(void)
25417+static unsigned long mmap_legacy_base(struct mm_struct *mm)
25418 {
25419- if (mmap_is_ia32())
25420+ if (mmap_is_ia32()) {
25421+
25422+#ifdef CONFIG_PAX_SEGMEXEC
25423+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25424+ return SEGMEXEC_TASK_UNMAPPED_BASE;
25425+ else
25426+#endif
25427+
25428 return TASK_UNMAPPED_BASE;
25429- else
25430+ } else
25431 return TASK_UNMAPPED_BASE + mmap_rnd();
25432 }
25433
25434@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25435 void arch_pick_mmap_layout(struct mm_struct *mm)
25436 {
25437 if (mmap_is_legacy()) {
25438- mm->mmap_base = mmap_legacy_base();
25439+ mm->mmap_base = mmap_legacy_base(mm);
25440+
25441+#ifdef CONFIG_PAX_RANDMMAP
25442+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25443+ mm->mmap_base += mm->delta_mmap;
25444+#endif
25445+
25446 mm->get_unmapped_area = arch_get_unmapped_area;
25447 mm->unmap_area = arch_unmap_area;
25448 } else {
25449- mm->mmap_base = mmap_base();
25450+ mm->mmap_base = mmap_base(mm);
25451+
25452+#ifdef CONFIG_PAX_RANDMMAP
25453+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25454+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25455+#endif
25456+
25457 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25458 mm->unmap_area = arch_unmap_area_topdown;
25459 }
25460diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25461index dc0b727..dc9d71a 100644
25462--- a/arch/x86/mm/mmio-mod.c
25463+++ b/arch/x86/mm/mmio-mod.c
25464@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25465 break;
25466 default:
25467 {
25468- unsigned char *ip = (unsigned char *)instptr;
25469+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25470 my_trace->opcode = MMIO_UNKNOWN_OP;
25471 my_trace->width = 0;
25472 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25473@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25474 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25475 void __iomem *addr)
25476 {
25477- static atomic_t next_id;
25478+ static atomic_unchecked_t next_id;
25479 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25480 /* These are page-unaligned. */
25481 struct mmiotrace_map map = {
25482@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25483 .private = trace
25484 },
25485 .phys = offset,
25486- .id = atomic_inc_return(&next_id)
25487+ .id = atomic_inc_return_unchecked(&next_id)
25488 };
25489 map.map_id = trace->id;
25490
25491diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25492index b008656..773eac2 100644
25493--- a/arch/x86/mm/pageattr-test.c
25494+++ b/arch/x86/mm/pageattr-test.c
25495@@ -36,7 +36,7 @@ enum {
25496
25497 static int pte_testbit(pte_t pte)
25498 {
25499- return pte_flags(pte) & _PAGE_UNUSED1;
25500+ return pte_flags(pte) & _PAGE_CPA_TEST;
25501 }
25502
25503 struct split_state {
25504diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25505index e1ebde3..b1e1db38 100644
25506--- a/arch/x86/mm/pageattr.c
25507+++ b/arch/x86/mm/pageattr.c
25508@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25509 */
25510 #ifdef CONFIG_PCI_BIOS
25511 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25512- pgprot_val(forbidden) |= _PAGE_NX;
25513+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25514 #endif
25515
25516 /*
25517@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25518 * Does not cover __inittext since that is gone later on. On
25519 * 64bit we do not enforce !NX on the low mapping
25520 */
25521- if (within(address, (unsigned long)_text, (unsigned long)_etext))
25522- pgprot_val(forbidden) |= _PAGE_NX;
25523+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25524+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25525
25526+#ifdef CONFIG_DEBUG_RODATA
25527 /*
25528 * The .rodata section needs to be read-only. Using the pfn
25529 * catches all aliases.
25530@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25531 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25532 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25533 pgprot_val(forbidden) |= _PAGE_RW;
25534+#endif
25535
25536 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25537 /*
25538@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25539 }
25540 #endif
25541
25542+#ifdef CONFIG_PAX_KERNEXEC
25543+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25544+ pgprot_val(forbidden) |= _PAGE_RW;
25545+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25546+ }
25547+#endif
25548+
25549 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25550
25551 return prot;
25552@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25553 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25554 {
25555 /* change init_mm */
25556+ pax_open_kernel();
25557 set_pte_atomic(kpte, pte);
25558+
25559 #ifdef CONFIG_X86_32
25560 if (!SHARED_KERNEL_PMD) {
25561+
25562+#ifdef CONFIG_PAX_PER_CPU_PGD
25563+ unsigned long cpu;
25564+#else
25565 struct page *page;
25566+#endif
25567
25568+#ifdef CONFIG_PAX_PER_CPU_PGD
25569+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25570+ pgd_t *pgd = get_cpu_pgd(cpu);
25571+#else
25572 list_for_each_entry(page, &pgd_list, lru) {
25573- pgd_t *pgd;
25574+ pgd_t *pgd = (pgd_t *)page_address(page);
25575+#endif
25576+
25577 pud_t *pud;
25578 pmd_t *pmd;
25579
25580- pgd = (pgd_t *)page_address(page) + pgd_index(address);
25581+ pgd += pgd_index(address);
25582 pud = pud_offset(pgd, address);
25583 pmd = pmd_offset(pud, address);
25584 set_pte_atomic((pte_t *)pmd, pte);
25585 }
25586 }
25587 #endif
25588+ pax_close_kernel();
25589 }
25590
25591 static int
25592diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25593index f6ff57b..481690f 100644
25594--- a/arch/x86/mm/pat.c
25595+++ b/arch/x86/mm/pat.c
25596@@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
25597
25598 if (!entry) {
25599 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
25600- current->comm, current->pid, start, end);
25601+ current->comm, task_pid_nr(current), start, end);
25602 return -EINVAL;
25603 }
25604
25605@@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25606 while (cursor < to) {
25607 if (!devmem_is_allowed(pfn)) {
25608 printk(KERN_INFO
25609- "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
25610- current->comm, from, to);
25611+ "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
25612+ current->comm, from, to, cursor);
25613 return 0;
25614 }
25615 cursor += PAGE_SIZE;
25616@@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25617 printk(KERN_INFO
25618 "%s:%d ioremap_change_attr failed %s "
25619 "for %Lx-%Lx\n",
25620- current->comm, current->pid,
25621+ current->comm, task_pid_nr(current),
25622 cattr_name(flags),
25623 base, (unsigned long long)(base + size));
25624 return -EINVAL;
25625@@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25626 if (want_flags != flags) {
25627 printk(KERN_WARNING
25628 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
25629- current->comm, current->pid,
25630+ current->comm, task_pid_nr(current),
25631 cattr_name(want_flags),
25632 (unsigned long long)paddr,
25633 (unsigned long long)(paddr + size),
25634@@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25635 free_memtype(paddr, paddr + size);
25636 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25637 " for %Lx-%Lx, got %s\n",
25638- current->comm, current->pid,
25639+ current->comm, task_pid_nr(current),
25640 cattr_name(want_flags),
25641 (unsigned long long)paddr,
25642 (unsigned long long)(paddr + size),
25643diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25644index 9f0614d..92ae64a 100644
25645--- a/arch/x86/mm/pf_in.c
25646+++ b/arch/x86/mm/pf_in.c
25647@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25648 int i;
25649 enum reason_type rv = OTHERS;
25650
25651- p = (unsigned char *)ins_addr;
25652+ p = (unsigned char *)ktla_ktva(ins_addr);
25653 p += skip_prefix(p, &prf);
25654 p += get_opcode(p, &opcode);
25655
25656@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25657 struct prefix_bits prf;
25658 int i;
25659
25660- p = (unsigned char *)ins_addr;
25661+ p = (unsigned char *)ktla_ktva(ins_addr);
25662 p += skip_prefix(p, &prf);
25663 p += get_opcode(p, &opcode);
25664
25665@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25666 struct prefix_bits prf;
25667 int i;
25668
25669- p = (unsigned char *)ins_addr;
25670+ p = (unsigned char *)ktla_ktva(ins_addr);
25671 p += skip_prefix(p, &prf);
25672 p += get_opcode(p, &opcode);
25673
25674@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25675 struct prefix_bits prf;
25676 int i;
25677
25678- p = (unsigned char *)ins_addr;
25679+ p = (unsigned char *)ktla_ktva(ins_addr);
25680 p += skip_prefix(p, &prf);
25681 p += get_opcode(p, &opcode);
25682 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25683@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25684 struct prefix_bits prf;
25685 int i;
25686
25687- p = (unsigned char *)ins_addr;
25688+ p = (unsigned char *)ktla_ktva(ins_addr);
25689 p += skip_prefix(p, &prf);
25690 p += get_opcode(p, &opcode);
25691 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25692diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25693index 8573b83..4f3ed7e 100644
25694--- a/arch/x86/mm/pgtable.c
25695+++ b/arch/x86/mm/pgtable.c
25696@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25697 list_del(&page->lru);
25698 }
25699
25700-#define UNSHARED_PTRS_PER_PGD \
25701- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25702+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25703+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25704
25705+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25706+{
25707+ unsigned int count = USER_PGD_PTRS;
25708
25709+ while (count--)
25710+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25711+}
25712+#endif
25713+
25714+#ifdef CONFIG_PAX_PER_CPU_PGD
25715+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25716+{
25717+ unsigned int count = USER_PGD_PTRS;
25718+
25719+ while (count--) {
25720+ pgd_t pgd;
25721+
25722+#ifdef CONFIG_X86_64
25723+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25724+#else
25725+ pgd = *src++;
25726+#endif
25727+
25728+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25729+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25730+#endif
25731+
25732+ *dst++ = pgd;
25733+ }
25734+
25735+}
25736+#endif
25737+
25738+#ifdef CONFIG_X86_64
25739+#define pxd_t pud_t
25740+#define pyd_t pgd_t
25741+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25742+#define pxd_free(mm, pud) pud_free((mm), (pud))
25743+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25744+#define pyd_offset(mm, address) pgd_offset((mm), (address))
25745+#define PYD_SIZE PGDIR_SIZE
25746+#else
25747+#define pxd_t pmd_t
25748+#define pyd_t pud_t
25749+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25750+#define pxd_free(mm, pud) pmd_free((mm), (pud))
25751+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25752+#define pyd_offset(mm, address) pud_offset((mm), (address))
25753+#define PYD_SIZE PUD_SIZE
25754+#endif
25755+
25756+#ifdef CONFIG_PAX_PER_CPU_PGD
25757+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25758+static inline void pgd_dtor(pgd_t *pgd) {}
25759+#else
25760 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25761 {
25762 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25763@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25764 pgd_list_del(pgd);
25765 spin_unlock(&pgd_lock);
25766 }
25767+#endif
25768
25769 /*
25770 * List of all pgd's needed for non-PAE so it can invalidate entries
25771@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25772 * -- wli
25773 */
25774
25775-#ifdef CONFIG_X86_PAE
25776+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25777 /*
25778 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25779 * updating the top-level pagetable entries to guarantee the
25780@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25781 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25782 * and initialize the kernel pmds here.
25783 */
25784-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25785+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25786
25787 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25788 {
25789@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25790 */
25791 flush_tlb_mm(mm);
25792 }
25793+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25794+#define PREALLOCATED_PXDS USER_PGD_PTRS
25795 #else /* !CONFIG_X86_PAE */
25796
25797 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25798-#define PREALLOCATED_PMDS 0
25799+#define PREALLOCATED_PXDS 0
25800
25801 #endif /* CONFIG_X86_PAE */
25802
25803-static void free_pmds(pmd_t *pmds[])
25804+static void free_pxds(pxd_t *pxds[])
25805 {
25806 int i;
25807
25808- for(i = 0; i < PREALLOCATED_PMDS; i++)
25809- if (pmds[i])
25810- free_page((unsigned long)pmds[i]);
25811+ for(i = 0; i < PREALLOCATED_PXDS; i++)
25812+ if (pxds[i])
25813+ free_page((unsigned long)pxds[i]);
25814 }
25815
25816-static int preallocate_pmds(pmd_t *pmds[])
25817+static int preallocate_pxds(pxd_t *pxds[])
25818 {
25819 int i;
25820 bool failed = false;
25821
25822- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25823- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25824- if (pmd == NULL)
25825+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25826+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25827+ if (pxd == NULL)
25828 failed = true;
25829- pmds[i] = pmd;
25830+ pxds[i] = pxd;
25831 }
25832
25833 if (failed) {
25834- free_pmds(pmds);
25835+ free_pxds(pxds);
25836 return -ENOMEM;
25837 }
25838
25839@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25840 * preallocate which never got a corresponding vma will need to be
25841 * freed manually.
25842 */
25843-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25844+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25845 {
25846 int i;
25847
25848- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25849+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25850 pgd_t pgd = pgdp[i];
25851
25852 if (pgd_val(pgd) != 0) {
25853- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25854+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25855
25856- pgdp[i] = native_make_pgd(0);
25857+ set_pgd(pgdp + i, native_make_pgd(0));
25858
25859- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25860- pmd_free(mm, pmd);
25861+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25862+ pxd_free(mm, pxd);
25863 }
25864 }
25865 }
25866
25867-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25868+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25869 {
25870- pud_t *pud;
25871+ pyd_t *pyd;
25872 unsigned long addr;
25873 int i;
25874
25875- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25876+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25877 return;
25878
25879- pud = pud_offset(pgd, 0);
25880+#ifdef CONFIG_X86_64
25881+ pyd = pyd_offset(mm, 0L);
25882+#else
25883+ pyd = pyd_offset(pgd, 0L);
25884+#endif
25885
25886- for (addr = i = 0; i < PREALLOCATED_PMDS;
25887- i++, pud++, addr += PUD_SIZE) {
25888- pmd_t *pmd = pmds[i];
25889+ for (addr = i = 0; i < PREALLOCATED_PXDS;
25890+ i++, pyd++, addr += PYD_SIZE) {
25891+ pxd_t *pxd = pxds[i];
25892
25893 if (i >= KERNEL_PGD_BOUNDARY)
25894- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25895- sizeof(pmd_t) * PTRS_PER_PMD);
25896+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25897+ sizeof(pxd_t) * PTRS_PER_PMD);
25898
25899- pud_populate(mm, pud, pmd);
25900+ pyd_populate(mm, pyd, pxd);
25901 }
25902 }
25903
25904 pgd_t *pgd_alloc(struct mm_struct *mm)
25905 {
25906 pgd_t *pgd;
25907- pmd_t *pmds[PREALLOCATED_PMDS];
25908+ pxd_t *pxds[PREALLOCATED_PXDS];
25909
25910 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25911
25912@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25913
25914 mm->pgd = pgd;
25915
25916- if (preallocate_pmds(pmds) != 0)
25917+ if (preallocate_pxds(pxds) != 0)
25918 goto out_free_pgd;
25919
25920 if (paravirt_pgd_alloc(mm) != 0)
25921- goto out_free_pmds;
25922+ goto out_free_pxds;
25923
25924 /*
25925 * Make sure that pre-populating the pmds is atomic with
25926@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25927 spin_lock(&pgd_lock);
25928
25929 pgd_ctor(mm, pgd);
25930- pgd_prepopulate_pmd(mm, pgd, pmds);
25931+ pgd_prepopulate_pxd(mm, pgd, pxds);
25932
25933 spin_unlock(&pgd_lock);
25934
25935 return pgd;
25936
25937-out_free_pmds:
25938- free_pmds(pmds);
25939+out_free_pxds:
25940+ free_pxds(pxds);
25941 out_free_pgd:
25942 free_page((unsigned long)pgd);
25943 out:
25944@@ -295,7 +356,7 @@ out:
25945
25946 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25947 {
25948- pgd_mop_up_pmds(mm, pgd);
25949+ pgd_mop_up_pxds(mm, pgd);
25950 pgd_dtor(pgd);
25951 paravirt_pgd_free(mm, pgd);
25952 free_page((unsigned long)pgd);
25953diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25954index cac7184..09a39fa 100644
25955--- a/arch/x86/mm/pgtable_32.c
25956+++ b/arch/x86/mm/pgtable_32.c
25957@@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25958 return;
25959 }
25960 pte = pte_offset_kernel(pmd, vaddr);
25961+
25962+ pax_open_kernel();
25963 if (pte_val(pteval))
25964 set_pte_at(&init_mm, vaddr, pte, pteval);
25965 else
25966 pte_clear(&init_mm, vaddr, pte);
25967+ pax_close_kernel();
25968
25969 /*
25970 * It's enough to flush this one mapping.
25971diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25972index 410531d..0f16030 100644
25973--- a/arch/x86/mm/setup_nx.c
25974+++ b/arch/x86/mm/setup_nx.c
25975@@ -5,8 +5,10 @@
25976 #include <asm/pgtable.h>
25977 #include <asm/proto.h>
25978
25979+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25980 static int disable_nx __cpuinitdata;
25981
25982+#ifndef CONFIG_PAX_PAGEEXEC
25983 /*
25984 * noexec = on|off
25985 *
25986@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25987 return 0;
25988 }
25989 early_param("noexec", noexec_setup);
25990+#endif
25991+
25992+#endif
25993
25994 void __cpuinit x86_configure_nx(void)
25995 {
25996+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25997 if (cpu_has_nx && !disable_nx)
25998 __supported_pte_mask |= _PAGE_NX;
25999 else
26000+#endif
26001 __supported_pte_mask &= ~_PAGE_NX;
26002 }
26003
26004diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
26005index d6c0418..06a0ad5 100644
26006--- a/arch/x86/mm/tlb.c
26007+++ b/arch/x86/mm/tlb.c
26008@@ -65,7 +65,11 @@ void leave_mm(int cpu)
26009 BUG();
26010 cpumask_clear_cpu(cpu,
26011 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
26012+
26013+#ifndef CONFIG_PAX_PER_CPU_PGD
26014 load_cr3(swapper_pg_dir);
26015+#endif
26016+
26017 }
26018 EXPORT_SYMBOL_GPL(leave_mm);
26019
26020diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
26021index 6687022..ceabcfa 100644
26022--- a/arch/x86/net/bpf_jit.S
26023+++ b/arch/x86/net/bpf_jit.S
26024@@ -9,6 +9,7 @@
26025 */
26026 #include <linux/linkage.h>
26027 #include <asm/dwarf2.h>
26028+#include <asm/alternative-asm.h>
26029
26030 /*
26031 * Calling convention :
26032@@ -35,6 +36,7 @@ sk_load_word:
26033 jle bpf_slow_path_word
26034 mov (SKBDATA,%rsi),%eax
26035 bswap %eax /* ntohl() */
26036+ pax_force_retaddr
26037 ret
26038
26039
26040@@ -53,6 +55,7 @@ sk_load_half:
26041 jle bpf_slow_path_half
26042 movzwl (SKBDATA,%rsi),%eax
26043 rol $8,%ax # ntohs()
26044+ pax_force_retaddr
26045 ret
26046
26047 sk_load_byte_ind:
26048@@ -66,6 +69,7 @@ sk_load_byte:
26049 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
26050 jle bpf_slow_path_byte
26051 movzbl (SKBDATA,%rsi),%eax
26052+ pax_force_retaddr
26053 ret
26054
26055 /**
26056@@ -82,6 +86,7 @@ ENTRY(sk_load_byte_msh)
26057 movzbl (SKBDATA,%rsi),%ebx
26058 and $15,%bl
26059 shl $2,%bl
26060+ pax_force_retaddr
26061 ret
26062 CFI_ENDPROC
26063 ENDPROC(sk_load_byte_msh)
26064@@ -91,6 +96,7 @@ bpf_error:
26065 xor %eax,%eax
26066 mov -8(%rbp),%rbx
26067 leaveq
26068+ pax_force_retaddr
26069 ret
26070
26071 /* rsi contains offset and can be scratched */
26072@@ -113,6 +119,7 @@ bpf_slow_path_word:
26073 js bpf_error
26074 mov -12(%rbp),%eax
26075 bswap %eax
26076+ pax_force_retaddr
26077 ret
26078
26079 bpf_slow_path_half:
26080@@ -121,12 +128,14 @@ bpf_slow_path_half:
26081 mov -12(%rbp),%ax
26082 rol $8,%ax
26083 movzwl %ax,%eax
26084+ pax_force_retaddr
26085 ret
26086
26087 bpf_slow_path_byte:
26088 bpf_slow_path_common(1)
26089 js bpf_error
26090 movzbl -12(%rbp),%eax
26091+ pax_force_retaddr
26092 ret
26093
26094 bpf_slow_path_byte_msh:
26095@@ -137,4 +146,5 @@ bpf_slow_path_byte_msh:
26096 and $15,%al
26097 shl $2,%al
26098 xchg %eax,%ebx
26099+ pax_force_retaddr
26100 ret
26101diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26102index 5a5b6e4..201d42e 100644
26103--- a/arch/x86/net/bpf_jit_comp.c
26104+++ b/arch/x86/net/bpf_jit_comp.c
26105@@ -117,6 +117,10 @@ static inline void bpf_flush_icache(void *start, void *end)
26106 set_fs(old_fs);
26107 }
26108
26109+struct bpf_jit_work {
26110+ struct work_struct work;
26111+ void *image;
26112+};
26113
26114 void bpf_jit_compile(struct sk_filter *fp)
26115 {
26116@@ -141,6 +145,10 @@ void bpf_jit_compile(struct sk_filter *fp)
26117 if (addrs == NULL)
26118 return;
26119
26120+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26121+ if (!fp->work)
26122+ goto out;
26123+
26124 /* Before first pass, make a rough estimation of addrs[]
26125 * each bpf instruction is translated to less than 64 bytes
26126 */
26127@@ -477,7 +485,7 @@ void bpf_jit_compile(struct sk_filter *fp)
26128 common_load: seen |= SEEN_DATAREF;
26129 if ((int)K < 0) {
26130 /* Abort the JIT because __load_pointer() is needed. */
26131- goto out;
26132+ goto error;
26133 }
26134 t_offset = func - (image + addrs[i]);
26135 EMIT1_off32(0xbe, K); /* mov imm32,%esi */
26136@@ -492,7 +500,7 @@ common_load: seen |= SEEN_DATAREF;
26137 case BPF_S_LDX_B_MSH:
26138 if ((int)K < 0) {
26139 /* Abort the JIT because __load_pointer() is needed. */
26140- goto out;
26141+ goto error;
26142 }
26143 seen |= SEEN_DATAREF | SEEN_XREG;
26144 t_offset = sk_load_byte_msh - (image + addrs[i]);
26145@@ -582,17 +590,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26146 break;
26147 default:
26148 /* hmm, too complex filter, give up with jit compiler */
26149- goto out;
26150+ goto error;
26151 }
26152 ilen = prog - temp;
26153 if (image) {
26154 if (unlikely(proglen + ilen > oldproglen)) {
26155 pr_err("bpb_jit_compile fatal error\n");
26156- kfree(addrs);
26157- module_free(NULL, image);
26158- return;
26159+ module_free_exec(NULL, image);
26160+ goto error;
26161 }
26162+ pax_open_kernel();
26163 memcpy(image + proglen, temp, ilen);
26164+ pax_close_kernel();
26165 }
26166 proglen += ilen;
26167 addrs[i] = proglen;
26168@@ -613,11 +622,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26169 break;
26170 }
26171 if (proglen == oldproglen) {
26172- image = module_alloc(max_t(unsigned int,
26173- proglen,
26174- sizeof(struct work_struct)));
26175+ image = module_alloc_exec(proglen);
26176 if (!image)
26177- goto out;
26178+ goto error;
26179 }
26180 oldproglen = proglen;
26181 }
26182@@ -633,7 +640,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26183 bpf_flush_icache(image, image + proglen);
26184
26185 fp->bpf_func = (void *)image;
26186- }
26187+ } else
26188+error:
26189+ kfree(fp->work);
26190+
26191 out:
26192 kfree(addrs);
26193 return;
26194@@ -641,18 +651,20 @@ out:
26195
26196 static void jit_free_defer(struct work_struct *arg)
26197 {
26198- module_free(NULL, arg);
26199+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26200+ kfree(arg);
26201 }
26202
26203 /* run from softirq, we must use a work_struct to call
26204- * module_free() from process context
26205+ * module_free_exec() from process context
26206 */
26207 void bpf_jit_free(struct sk_filter *fp)
26208 {
26209 if (fp->bpf_func != sk_run_filter) {
26210- struct work_struct *work = (struct work_struct *)fp->bpf_func;
26211+ struct work_struct *work = &fp->work->work;
26212
26213 INIT_WORK(work, jit_free_defer);
26214+ fp->work->image = fp->bpf_func;
26215 schedule_work(work);
26216 }
26217 }
26218diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26219index bff89df..377758a 100644
26220--- a/arch/x86/oprofile/backtrace.c
26221+++ b/arch/x86/oprofile/backtrace.c
26222@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26223 struct stack_frame_ia32 *fp;
26224 unsigned long bytes;
26225
26226- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26227+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26228 if (bytes != sizeof(bufhead))
26229 return NULL;
26230
26231- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26232+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26233
26234 oprofile_add_trace(bufhead[0].return_address);
26235
26236@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26237 struct stack_frame bufhead[2];
26238 unsigned long bytes;
26239
26240- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26241+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26242 if (bytes != sizeof(bufhead))
26243 return NULL;
26244
26245@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26246 {
26247 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26248
26249- if (!user_mode_vm(regs)) {
26250+ if (!user_mode(regs)) {
26251 unsigned long stack = kernel_stack_pointer(regs);
26252 if (depth)
26253 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26254diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26255index cb29191..036766d 100644
26256--- a/arch/x86/pci/mrst.c
26257+++ b/arch/x86/pci/mrst.c
26258@@ -234,7 +234,9 @@ int __init pci_mrst_init(void)
26259 printk(KERN_INFO "Moorestown platform detected, using MRST PCI ops\n");
26260 pci_mmcfg_late_init();
26261 pcibios_enable_irq = mrst_pci_irq_enable;
26262- pci_root_ops = pci_mrst_ops;
26263+ pax_open_kernel();
26264+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26265+ pax_close_kernel();
26266 /* Continue with standard init */
26267 return 1;
26268 }
26269diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26270index da8fe05..7ee6704 100644
26271--- a/arch/x86/pci/pcbios.c
26272+++ b/arch/x86/pci/pcbios.c
26273@@ -79,50 +79,93 @@ union bios32 {
26274 static struct {
26275 unsigned long address;
26276 unsigned short segment;
26277-} bios32_indirect = { 0, __KERNEL_CS };
26278+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26279
26280 /*
26281 * Returns the entry point for the given service, NULL on error
26282 */
26283
26284-static unsigned long bios32_service(unsigned long service)
26285+static unsigned long __devinit bios32_service(unsigned long service)
26286 {
26287 unsigned char return_code; /* %al */
26288 unsigned long address; /* %ebx */
26289 unsigned long length; /* %ecx */
26290 unsigned long entry; /* %edx */
26291 unsigned long flags;
26292+ struct desc_struct d, *gdt;
26293
26294 local_irq_save(flags);
26295- __asm__("lcall *(%%edi); cld"
26296+
26297+ gdt = get_cpu_gdt_table(smp_processor_id());
26298+
26299+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26300+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26301+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26302+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26303+
26304+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26305 : "=a" (return_code),
26306 "=b" (address),
26307 "=c" (length),
26308 "=d" (entry)
26309 : "0" (service),
26310 "1" (0),
26311- "D" (&bios32_indirect));
26312+ "D" (&bios32_indirect),
26313+ "r"(__PCIBIOS_DS)
26314+ : "memory");
26315+
26316+ pax_open_kernel();
26317+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26318+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26319+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26320+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26321+ pax_close_kernel();
26322+
26323 local_irq_restore(flags);
26324
26325 switch (return_code) {
26326- case 0:
26327- return address + entry;
26328- case 0x80: /* Not present */
26329- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26330- return 0;
26331- default: /* Shouldn't happen */
26332- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26333- service, return_code);
26334+ case 0: {
26335+ int cpu;
26336+ unsigned char flags;
26337+
26338+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26339+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26340+ printk(KERN_WARNING "bios32_service: not valid\n");
26341 return 0;
26342+ }
26343+ address = address + PAGE_OFFSET;
26344+ length += 16UL; /* some BIOSs underreport this... */
26345+ flags = 4;
26346+ if (length >= 64*1024*1024) {
26347+ length >>= PAGE_SHIFT;
26348+ flags |= 8;
26349+ }
26350+
26351+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26352+ gdt = get_cpu_gdt_table(cpu);
26353+ pack_descriptor(&d, address, length, 0x9b, flags);
26354+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26355+ pack_descriptor(&d, address, length, 0x93, flags);
26356+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26357+ }
26358+ return entry;
26359+ }
26360+ case 0x80: /* Not present */
26361+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26362+ return 0;
26363+ default: /* Shouldn't happen */
26364+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26365+ service, return_code);
26366+ return 0;
26367 }
26368 }
26369
26370 static struct {
26371 unsigned long address;
26372 unsigned short segment;
26373-} pci_indirect = { 0, __KERNEL_CS };
26374+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26375
26376-static int pci_bios_present;
26377+static int pci_bios_present __read_only;
26378
26379 static int __devinit check_pcibios(void)
26380 {
26381@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26382 unsigned long flags, pcibios_entry;
26383
26384 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26385- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26386+ pci_indirect.address = pcibios_entry;
26387
26388 local_irq_save(flags);
26389- __asm__(
26390- "lcall *(%%edi); cld\n\t"
26391+ __asm__("movw %w6, %%ds\n\t"
26392+ "lcall *%%ss:(%%edi); cld\n\t"
26393+ "push %%ss\n\t"
26394+ "pop %%ds\n\t"
26395 "jc 1f\n\t"
26396 "xor %%ah, %%ah\n"
26397 "1:"
26398@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26399 "=b" (ebx),
26400 "=c" (ecx)
26401 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26402- "D" (&pci_indirect)
26403+ "D" (&pci_indirect),
26404+ "r" (__PCIBIOS_DS)
26405 : "memory");
26406 local_irq_restore(flags);
26407
26408@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26409
26410 switch (len) {
26411 case 1:
26412- __asm__("lcall *(%%esi); cld\n\t"
26413+ __asm__("movw %w6, %%ds\n\t"
26414+ "lcall *%%ss:(%%esi); cld\n\t"
26415+ "push %%ss\n\t"
26416+ "pop %%ds\n\t"
26417 "jc 1f\n\t"
26418 "xor %%ah, %%ah\n"
26419 "1:"
26420@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26421 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26422 "b" (bx),
26423 "D" ((long)reg),
26424- "S" (&pci_indirect));
26425+ "S" (&pci_indirect),
26426+ "r" (__PCIBIOS_DS));
26427 /*
26428 * Zero-extend the result beyond 8 bits, do not trust the
26429 * BIOS having done it:
26430@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26431 *value &= 0xff;
26432 break;
26433 case 2:
26434- __asm__("lcall *(%%esi); cld\n\t"
26435+ __asm__("movw %w6, %%ds\n\t"
26436+ "lcall *%%ss:(%%esi); cld\n\t"
26437+ "push %%ss\n\t"
26438+ "pop %%ds\n\t"
26439 "jc 1f\n\t"
26440 "xor %%ah, %%ah\n"
26441 "1:"
26442@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26443 : "1" (PCIBIOS_READ_CONFIG_WORD),
26444 "b" (bx),
26445 "D" ((long)reg),
26446- "S" (&pci_indirect));
26447+ "S" (&pci_indirect),
26448+ "r" (__PCIBIOS_DS));
26449 /*
26450 * Zero-extend the result beyond 16 bits, do not trust the
26451 * BIOS having done it:
26452@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26453 *value &= 0xffff;
26454 break;
26455 case 4:
26456- __asm__("lcall *(%%esi); cld\n\t"
26457+ __asm__("movw %w6, %%ds\n\t"
26458+ "lcall *%%ss:(%%esi); cld\n\t"
26459+ "push %%ss\n\t"
26460+ "pop %%ds\n\t"
26461 "jc 1f\n\t"
26462 "xor %%ah, %%ah\n"
26463 "1:"
26464@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26465 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26466 "b" (bx),
26467 "D" ((long)reg),
26468- "S" (&pci_indirect));
26469+ "S" (&pci_indirect),
26470+ "r" (__PCIBIOS_DS));
26471 break;
26472 }
26473
26474@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26475
26476 switch (len) {
26477 case 1:
26478- __asm__("lcall *(%%esi); cld\n\t"
26479+ __asm__("movw %w6, %%ds\n\t"
26480+ "lcall *%%ss:(%%esi); cld\n\t"
26481+ "push %%ss\n\t"
26482+ "pop %%ds\n\t"
26483 "jc 1f\n\t"
26484 "xor %%ah, %%ah\n"
26485 "1:"
26486@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26487 "c" (value),
26488 "b" (bx),
26489 "D" ((long)reg),
26490- "S" (&pci_indirect));
26491+ "S" (&pci_indirect),
26492+ "r" (__PCIBIOS_DS));
26493 break;
26494 case 2:
26495- __asm__("lcall *(%%esi); cld\n\t"
26496+ __asm__("movw %w6, %%ds\n\t"
26497+ "lcall *%%ss:(%%esi); cld\n\t"
26498+ "push %%ss\n\t"
26499+ "pop %%ds\n\t"
26500 "jc 1f\n\t"
26501 "xor %%ah, %%ah\n"
26502 "1:"
26503@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26504 "c" (value),
26505 "b" (bx),
26506 "D" ((long)reg),
26507- "S" (&pci_indirect));
26508+ "S" (&pci_indirect),
26509+ "r" (__PCIBIOS_DS));
26510 break;
26511 case 4:
26512- __asm__("lcall *(%%esi); cld\n\t"
26513+ __asm__("movw %w6, %%ds\n\t"
26514+ "lcall *%%ss:(%%esi); cld\n\t"
26515+ "push %%ss\n\t"
26516+ "pop %%ds\n\t"
26517 "jc 1f\n\t"
26518 "xor %%ah, %%ah\n"
26519 "1:"
26520@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26521 "c" (value),
26522 "b" (bx),
26523 "D" ((long)reg),
26524- "S" (&pci_indirect));
26525+ "S" (&pci_indirect),
26526+ "r" (__PCIBIOS_DS));
26527 break;
26528 }
26529
26530@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26531
26532 DBG("PCI: Fetching IRQ routing table... ");
26533 __asm__("push %%es\n\t"
26534+ "movw %w8, %%ds\n\t"
26535 "push %%ds\n\t"
26536 "pop %%es\n\t"
26537- "lcall *(%%esi); cld\n\t"
26538+ "lcall *%%ss:(%%esi); cld\n\t"
26539 "pop %%es\n\t"
26540+ "push %%ss\n\t"
26541+ "pop %%ds\n"
26542 "jc 1f\n\t"
26543 "xor %%ah, %%ah\n"
26544 "1:"
26545@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26546 "1" (0),
26547 "D" ((long) &opt),
26548 "S" (&pci_indirect),
26549- "m" (opt)
26550+ "m" (opt),
26551+ "r" (__PCIBIOS_DS)
26552 : "memory");
26553 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26554 if (ret & 0xff00)
26555@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26556 {
26557 int ret;
26558
26559- __asm__("lcall *(%%esi); cld\n\t"
26560+ __asm__("movw %w5, %%ds\n\t"
26561+ "lcall *%%ss:(%%esi); cld\n\t"
26562+ "push %%ss\n\t"
26563+ "pop %%ds\n"
26564 "jc 1f\n\t"
26565 "xor %%ah, %%ah\n"
26566 "1:"
26567@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26568 : "0" (PCIBIOS_SET_PCI_HW_INT),
26569 "b" ((dev->bus->number << 8) | dev->devfn),
26570 "c" ((irq << 8) | (pin + 10)),
26571- "S" (&pci_indirect));
26572+ "S" (&pci_indirect),
26573+ "r" (__PCIBIOS_DS));
26574 return !(ret & 0xff00);
26575 }
26576 EXPORT_SYMBOL(pcibios_set_irq_routing);
26577diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26578index 40e4469..1ab536e 100644
26579--- a/arch/x86/platform/efi/efi_32.c
26580+++ b/arch/x86/platform/efi/efi_32.c
26581@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26582 {
26583 struct desc_ptr gdt_descr;
26584
26585+#ifdef CONFIG_PAX_KERNEXEC
26586+ struct desc_struct d;
26587+#endif
26588+
26589 local_irq_save(efi_rt_eflags);
26590
26591 load_cr3(initial_page_table);
26592 __flush_tlb_all();
26593
26594+#ifdef CONFIG_PAX_KERNEXEC
26595+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26596+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26597+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26598+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26599+#endif
26600+
26601 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26602 gdt_descr.size = GDT_SIZE - 1;
26603 load_gdt(&gdt_descr);
26604@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26605 {
26606 struct desc_ptr gdt_descr;
26607
26608+#ifdef CONFIG_PAX_KERNEXEC
26609+ struct desc_struct d;
26610+
26611+ memset(&d, 0, sizeof d);
26612+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26613+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26614+#endif
26615+
26616 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26617 gdt_descr.size = GDT_SIZE - 1;
26618 load_gdt(&gdt_descr);
26619diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26620index fbe66e6..c5c0dd2 100644
26621--- a/arch/x86/platform/efi/efi_stub_32.S
26622+++ b/arch/x86/platform/efi/efi_stub_32.S
26623@@ -6,7 +6,9 @@
26624 */
26625
26626 #include <linux/linkage.h>
26627+#include <linux/init.h>
26628 #include <asm/page_types.h>
26629+#include <asm/segment.h>
26630
26631 /*
26632 * efi_call_phys(void *, ...) is a function with variable parameters.
26633@@ -20,7 +22,7 @@
26634 * service functions will comply with gcc calling convention, too.
26635 */
26636
26637-.text
26638+__INIT
26639 ENTRY(efi_call_phys)
26640 /*
26641 * 0. The function can only be called in Linux kernel. So CS has been
26642@@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
26643 * The mapping of lower virtual memory has been created in prelog and
26644 * epilog.
26645 */
26646- movl $1f, %edx
26647- subl $__PAGE_OFFSET, %edx
26648- jmp *%edx
26649+ movl $(__KERNEXEC_EFI_DS), %edx
26650+ mov %edx, %ds
26651+ mov %edx, %es
26652+ mov %edx, %ss
26653+ ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
26654 1:
26655
26656 /*
26657@@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
26658 * parameter 2, ..., param n. To make things easy, we save the return
26659 * address of efi_call_phys in a global variable.
26660 */
26661- popl %edx
26662- movl %edx, saved_return_addr
26663- /* get the function pointer into ECX*/
26664- popl %ecx
26665- movl %ecx, efi_rt_function_ptr
26666- movl $2f, %edx
26667- subl $__PAGE_OFFSET, %edx
26668- pushl %edx
26669+ popl (saved_return_addr)
26670+ popl (efi_rt_function_ptr)
26671
26672 /*
26673 * 3. Clear PG bit in %CR0.
26674@@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
26675 /*
26676 * 5. Call the physical function.
26677 */
26678- jmp *%ecx
26679+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
26680
26681-2:
26682 /*
26683 * 6. After EFI runtime service returns, control will return to
26684 * following instruction. We'd better readjust stack pointer first.
26685@@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
26686 movl %cr0, %edx
26687 orl $0x80000000, %edx
26688 movl %edx, %cr0
26689- jmp 1f
26690-1:
26691+
26692 /*
26693 * 8. Now restore the virtual mode from flat mode by
26694 * adding EIP with PAGE_OFFSET.
26695 */
26696- movl $1f, %edx
26697- jmp *%edx
26698+ ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
26699 1:
26700+ movl $(__KERNEL_DS), %edx
26701+ mov %edx, %ds
26702+ mov %edx, %es
26703+ mov %edx, %ss
26704
26705 /*
26706 * 9. Balance the stack. And because EAX contain the return value,
26707 * we'd better not clobber it.
26708 */
26709- leal efi_rt_function_ptr, %edx
26710- movl (%edx), %ecx
26711- pushl %ecx
26712+ pushl (efi_rt_function_ptr)
26713
26714 /*
26715- * 10. Push the saved return address onto the stack and return.
26716+ * 10. Return to the saved return address.
26717 */
26718- leal saved_return_addr, %edx
26719- movl (%edx), %ecx
26720- pushl %ecx
26721- ret
26722+ jmpl *(saved_return_addr)
26723 ENDPROC(efi_call_phys)
26724 .previous
26725
26726-.data
26727+__INITDATA
26728 saved_return_addr:
26729 .long 0
26730 efi_rt_function_ptr:
26731diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26732index 4c07cca..2c8427d 100644
26733--- a/arch/x86/platform/efi/efi_stub_64.S
26734+++ b/arch/x86/platform/efi/efi_stub_64.S
26735@@ -7,6 +7,7 @@
26736 */
26737
26738 #include <linux/linkage.h>
26739+#include <asm/alternative-asm.h>
26740
26741 #define SAVE_XMM \
26742 mov %rsp, %rax; \
26743@@ -40,6 +41,7 @@ ENTRY(efi_call0)
26744 call *%rdi
26745 addq $32, %rsp
26746 RESTORE_XMM
26747+ pax_force_retaddr 0, 1
26748 ret
26749 ENDPROC(efi_call0)
26750
26751@@ -50,6 +52,7 @@ ENTRY(efi_call1)
26752 call *%rdi
26753 addq $32, %rsp
26754 RESTORE_XMM
26755+ pax_force_retaddr 0, 1
26756 ret
26757 ENDPROC(efi_call1)
26758
26759@@ -60,6 +63,7 @@ ENTRY(efi_call2)
26760 call *%rdi
26761 addq $32, %rsp
26762 RESTORE_XMM
26763+ pax_force_retaddr 0, 1
26764 ret
26765 ENDPROC(efi_call2)
26766
26767@@ -71,6 +75,7 @@ ENTRY(efi_call3)
26768 call *%rdi
26769 addq $32, %rsp
26770 RESTORE_XMM
26771+ pax_force_retaddr 0, 1
26772 ret
26773 ENDPROC(efi_call3)
26774
26775@@ -83,6 +88,7 @@ ENTRY(efi_call4)
26776 call *%rdi
26777 addq $32, %rsp
26778 RESTORE_XMM
26779+ pax_force_retaddr 0, 1
26780 ret
26781 ENDPROC(efi_call4)
26782
26783@@ -96,6 +102,7 @@ ENTRY(efi_call5)
26784 call *%rdi
26785 addq $48, %rsp
26786 RESTORE_XMM
26787+ pax_force_retaddr 0, 1
26788 ret
26789 ENDPROC(efi_call5)
26790
26791@@ -112,5 +119,6 @@ ENTRY(efi_call6)
26792 call *%rdi
26793 addq $48, %rsp
26794 RESTORE_XMM
26795+ pax_force_retaddr 0, 1
26796 ret
26797 ENDPROC(efi_call6)
26798diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26799index 475e2cd..1b8e708 100644
26800--- a/arch/x86/platform/mrst/mrst.c
26801+++ b/arch/x86/platform/mrst/mrst.c
26802@@ -76,18 +76,20 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26803 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26804 int sfi_mrtc_num;
26805
26806-static void mrst_power_off(void)
26807+static __noreturn void mrst_power_off(void)
26808 {
26809 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
26810 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 1);
26811+ BUG();
26812 }
26813
26814-static void mrst_reboot(void)
26815+static __noreturn void mrst_reboot(void)
26816 {
26817 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
26818 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 0);
26819 else
26820 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26821+ BUG();
26822 }
26823
26824 /* parse all the mtimer info to a static mtimer array */
26825diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26826index f10c0af..3ec1f95 100644
26827--- a/arch/x86/power/cpu.c
26828+++ b/arch/x86/power/cpu.c
26829@@ -131,7 +131,7 @@ static void do_fpu_end(void)
26830 static void fix_processor_context(void)
26831 {
26832 int cpu = smp_processor_id();
26833- struct tss_struct *t = &per_cpu(init_tss, cpu);
26834+ struct tss_struct *t = init_tss + cpu;
26835
26836 set_tss_desc(cpu, t); /*
26837 * This just modifies memory; should not be
26838@@ -141,7 +141,9 @@ static void fix_processor_context(void)
26839 */
26840
26841 #ifdef CONFIG_X86_64
26842+ pax_open_kernel();
26843 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26844+ pax_close_kernel();
26845
26846 syscall_init(); /* This sets MSR_*STAR and related */
26847 #endif
26848diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26849index 5d17950..2253fc9 100644
26850--- a/arch/x86/vdso/Makefile
26851+++ b/arch/x86/vdso/Makefile
26852@@ -137,7 +137,7 @@ quiet_cmd_vdso = VDSO $@
26853 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26854 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26855
26856-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26857+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26858 GCOV_PROFILE := n
26859
26860 #
26861diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26862index 468d591..8e80a0a 100644
26863--- a/arch/x86/vdso/vdso32-setup.c
26864+++ b/arch/x86/vdso/vdso32-setup.c
26865@@ -25,6 +25,7 @@
26866 #include <asm/tlbflush.h>
26867 #include <asm/vdso.h>
26868 #include <asm/proto.h>
26869+#include <asm/mman.h>
26870
26871 enum {
26872 VDSO_DISABLED = 0,
26873@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26874 void enable_sep_cpu(void)
26875 {
26876 int cpu = get_cpu();
26877- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26878+ struct tss_struct *tss = init_tss + cpu;
26879
26880 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26881 put_cpu();
26882@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26883 gate_vma.vm_start = FIXADDR_USER_START;
26884 gate_vma.vm_end = FIXADDR_USER_END;
26885 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26886- gate_vma.vm_page_prot = __P101;
26887+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26888 /*
26889 * Make sure the vDSO gets into every core dump.
26890 * Dumping its contents makes post-mortem fully interpretable later
26891@@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26892 if (compat)
26893 addr = VDSO_HIGH_BASE;
26894 else {
26895- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26896+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26897 if (IS_ERR_VALUE(addr)) {
26898 ret = addr;
26899 goto up_fail;
26900 }
26901 }
26902
26903- current->mm->context.vdso = (void *)addr;
26904+ current->mm->context.vdso = addr;
26905
26906 if (compat_uses_vma || !compat) {
26907 /*
26908@@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26909 }
26910
26911 current_thread_info()->sysenter_return =
26912- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26913+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26914
26915 up_fail:
26916 if (ret)
26917- current->mm->context.vdso = NULL;
26918+ current->mm->context.vdso = 0;
26919
26920 up_write(&mm->mmap_sem);
26921
26922@@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
26923
26924 const char *arch_vma_name(struct vm_area_struct *vma)
26925 {
26926- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26927+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26928 return "[vdso]";
26929+
26930+#ifdef CONFIG_PAX_SEGMEXEC
26931+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26932+ return "[vdso]";
26933+#endif
26934+
26935 return NULL;
26936 }
26937
26938@@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26939 * Check to see if the corresponding task was created in compat vdso
26940 * mode.
26941 */
26942- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26943+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26944 return &gate_vma;
26945 return NULL;
26946 }
26947diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26948index 153407c..611cba9 100644
26949--- a/arch/x86/vdso/vma.c
26950+++ b/arch/x86/vdso/vma.c
26951@@ -16,8 +16,6 @@
26952 #include <asm/vdso.h>
26953 #include <asm/page.h>
26954
26955-unsigned int __read_mostly vdso_enabled = 1;
26956-
26957 extern char vdso_start[], vdso_end[];
26958 extern unsigned short vdso_sync_cpuid;
26959
26960@@ -96,7 +94,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26961 * unaligned here as a result of stack start randomization.
26962 */
26963 addr = PAGE_ALIGN(addr);
26964- addr = align_addr(addr, NULL, ALIGN_VDSO);
26965
26966 return addr;
26967 }
26968@@ -106,40 +103,35 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26969 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26970 {
26971 struct mm_struct *mm = current->mm;
26972- unsigned long addr;
26973+ unsigned long addr = 0;
26974 int ret;
26975
26976- if (!vdso_enabled)
26977- return 0;
26978-
26979 down_write(&mm->mmap_sem);
26980+
26981+#ifdef CONFIG_PAX_RANDMMAP
26982+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26983+#endif
26984+
26985 addr = vdso_addr(mm->start_stack, vdso_size);
26986+ addr = align_addr(addr, NULL, ALIGN_VDSO);
26987 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
26988 if (IS_ERR_VALUE(addr)) {
26989 ret = addr;
26990 goto up_fail;
26991 }
26992
26993- current->mm->context.vdso = (void *)addr;
26994+ mm->context.vdso = addr;
26995
26996 ret = install_special_mapping(mm, addr, vdso_size,
26997 VM_READ|VM_EXEC|
26998 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
26999 VM_ALWAYSDUMP,
27000 vdso_pages);
27001- if (ret) {
27002- current->mm->context.vdso = NULL;
27003- goto up_fail;
27004- }
27005+
27006+ if (ret)
27007+ mm->context.vdso = 0;
27008
27009 up_fail:
27010 up_write(&mm->mmap_sem);
27011 return ret;
27012 }
27013-
27014-static __init int vdso_setup(char *s)
27015-{
27016- vdso_enabled = simple_strtoul(s, NULL, 0);
27017- return 0;
27018-}
27019-__setup("vdso=", vdso_setup);
27020diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27021index 4e517d4..68a48f5 100644
27022--- a/arch/x86/xen/enlighten.c
27023+++ b/arch/x86/xen/enlighten.c
27024@@ -86,8 +86,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27025
27026 struct shared_info xen_dummy_shared_info;
27027
27028-void *xen_initial_gdt;
27029-
27030 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27031 __read_mostly int xen_have_vector_callback;
27032 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27033@@ -1030,30 +1028,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27034 #endif
27035 };
27036
27037-static void xen_reboot(int reason)
27038+static __noreturn void xen_reboot(int reason)
27039 {
27040 struct sched_shutdown r = { .reason = reason };
27041
27042- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27043- BUG();
27044+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27045+ BUG();
27046 }
27047
27048-static void xen_restart(char *msg)
27049+static __noreturn void xen_restart(char *msg)
27050 {
27051 xen_reboot(SHUTDOWN_reboot);
27052 }
27053
27054-static void xen_emergency_restart(void)
27055+static __noreturn void xen_emergency_restart(void)
27056 {
27057 xen_reboot(SHUTDOWN_reboot);
27058 }
27059
27060-static void xen_machine_halt(void)
27061+static __noreturn void xen_machine_halt(void)
27062 {
27063 xen_reboot(SHUTDOWN_poweroff);
27064 }
27065
27066-static void xen_machine_power_off(void)
27067+static __noreturn void xen_machine_power_off(void)
27068 {
27069 if (pm_power_off)
27070 pm_power_off();
27071@@ -1156,7 +1154,17 @@ asmlinkage void __init xen_start_kernel(void)
27072 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27073
27074 /* Work out if we support NX */
27075- x86_configure_nx();
27076+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27077+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27078+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27079+ unsigned l, h;
27080+
27081+ __supported_pte_mask |= _PAGE_NX;
27082+ rdmsr(MSR_EFER, l, h);
27083+ l |= EFER_NX;
27084+ wrmsr(MSR_EFER, l, h);
27085+ }
27086+#endif
27087
27088 xen_setup_features();
27089
27090@@ -1187,13 +1195,6 @@ asmlinkage void __init xen_start_kernel(void)
27091
27092 machine_ops = xen_machine_ops;
27093
27094- /*
27095- * The only reliable way to retain the initial address of the
27096- * percpu gdt_page is to remember it here, so we can go and
27097- * mark it RW later, when the initial percpu area is freed.
27098- */
27099- xen_initial_gdt = &per_cpu(gdt_page, 0);
27100-
27101 xen_smp_init();
27102
27103 #ifdef CONFIG_ACPI_NUMA
27104diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27105index dc19347..1b07a2c 100644
27106--- a/arch/x86/xen/mmu.c
27107+++ b/arch/x86/xen/mmu.c
27108@@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27109 convert_pfn_mfn(init_level4_pgt);
27110 convert_pfn_mfn(level3_ident_pgt);
27111 convert_pfn_mfn(level3_kernel_pgt);
27112+ convert_pfn_mfn(level3_vmalloc_start_pgt);
27113+ convert_pfn_mfn(level3_vmalloc_end_pgt);
27114+ convert_pfn_mfn(level3_vmemmap_pgt);
27115
27116 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27117 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27118@@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27119 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27120 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27121 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27122+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27123+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27124+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27125 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27126+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27127 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27128 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27129
27130@@ -1963,6 +1970,7 @@ static void __init xen_post_allocator_init(void)
27131 pv_mmu_ops.set_pud = xen_set_pud;
27132 #if PAGETABLE_LEVELS == 4
27133 pv_mmu_ops.set_pgd = xen_set_pgd;
27134+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27135 #endif
27136
27137 /* This will work as long as patching hasn't happened yet
27138@@ -2044,6 +2052,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27139 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27140 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27141 .set_pgd = xen_set_pgd_hyper,
27142+ .set_pgd_batched = xen_set_pgd_hyper,
27143
27144 .alloc_pud = xen_alloc_pmd_init,
27145 .release_pud = xen_release_pmd_init,
27146diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27147index f2ce60a..14e08dc 100644
27148--- a/arch/x86/xen/smp.c
27149+++ b/arch/x86/xen/smp.c
27150@@ -209,11 +209,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27151 {
27152 BUG_ON(smp_processor_id() != 0);
27153 native_smp_prepare_boot_cpu();
27154-
27155- /* We've switched to the "real" per-cpu gdt, so make sure the
27156- old memory can be recycled */
27157- make_lowmem_page_readwrite(xen_initial_gdt);
27158-
27159 xen_filter_cpu_maps();
27160 xen_setup_vcpu_info_placement();
27161 }
27162@@ -290,12 +285,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27163 gdt = get_cpu_gdt_table(cpu);
27164
27165 ctxt->flags = VGCF_IN_KERNEL;
27166- ctxt->user_regs.ds = __USER_DS;
27167- ctxt->user_regs.es = __USER_DS;
27168+ ctxt->user_regs.ds = __KERNEL_DS;
27169+ ctxt->user_regs.es = __KERNEL_DS;
27170 ctxt->user_regs.ss = __KERNEL_DS;
27171 #ifdef CONFIG_X86_32
27172 ctxt->user_regs.fs = __KERNEL_PERCPU;
27173- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27174+ savesegment(gs, ctxt->user_regs.gs);
27175 #else
27176 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27177 #endif
27178@@ -346,13 +341,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
27179 int rc;
27180
27181 per_cpu(current_task, cpu) = idle;
27182+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27183 #ifdef CONFIG_X86_32
27184 irq_ctx_init(cpu);
27185 #else
27186 clear_tsk_thread_flag(idle, TIF_FORK);
27187- per_cpu(kernel_stack, cpu) =
27188- (unsigned long)task_stack_page(idle) -
27189- KERNEL_STACK_OFFSET + THREAD_SIZE;
27190+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27191 #endif
27192 xen_setup_runstate_info(cpu);
27193 xen_setup_timer(cpu);
27194diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27195index b040b0e..8cc4fe0 100644
27196--- a/arch/x86/xen/xen-asm_32.S
27197+++ b/arch/x86/xen/xen-asm_32.S
27198@@ -83,14 +83,14 @@ ENTRY(xen_iret)
27199 ESP_OFFSET=4 # bytes pushed onto stack
27200
27201 /*
27202- * Store vcpu_info pointer for easy access. Do it this way to
27203- * avoid having to reload %fs
27204+ * Store vcpu_info pointer for easy access.
27205 */
27206 #ifdef CONFIG_SMP
27207- GET_THREAD_INFO(%eax)
27208- movl TI_cpu(%eax), %eax
27209- movl __per_cpu_offset(,%eax,4), %eax
27210- mov xen_vcpu(%eax), %eax
27211+ push %fs
27212+ mov $(__KERNEL_PERCPU), %eax
27213+ mov %eax, %fs
27214+ mov PER_CPU_VAR(xen_vcpu), %eax
27215+ pop %fs
27216 #else
27217 movl xen_vcpu, %eax
27218 #endif
27219diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27220index aaa7291..3f77960 100644
27221--- a/arch/x86/xen/xen-head.S
27222+++ b/arch/x86/xen/xen-head.S
27223@@ -19,6 +19,17 @@ ENTRY(startup_xen)
27224 #ifdef CONFIG_X86_32
27225 mov %esi,xen_start_info
27226 mov $init_thread_union+THREAD_SIZE,%esp
27227+#ifdef CONFIG_SMP
27228+ movl $cpu_gdt_table,%edi
27229+ movl $__per_cpu_load,%eax
27230+ movw %ax,__KERNEL_PERCPU + 2(%edi)
27231+ rorl $16,%eax
27232+ movb %al,__KERNEL_PERCPU + 4(%edi)
27233+ movb %ah,__KERNEL_PERCPU + 7(%edi)
27234+ movl $__per_cpu_end - 1,%eax
27235+ subl $__per_cpu_start,%eax
27236+ movw %ax,__KERNEL_PERCPU + 0(%edi)
27237+#endif
27238 #else
27239 mov %rsi,xen_start_info
27240 mov $init_thread_union+THREAD_SIZE,%rsp
27241diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27242index b095739..8c17bcd 100644
27243--- a/arch/x86/xen/xen-ops.h
27244+++ b/arch/x86/xen/xen-ops.h
27245@@ -10,8 +10,6 @@
27246 extern const char xen_hypervisor_callback[];
27247 extern const char xen_failsafe_callback[];
27248
27249-extern void *xen_initial_gdt;
27250-
27251 struct trap_info;
27252 void xen_copy_trap_info(struct trap_info *traps);
27253
27254diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27255index 525bd3d..ef888b1 100644
27256--- a/arch/xtensa/variants/dc232b/include/variant/core.h
27257+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27258@@ -119,9 +119,9 @@
27259 ----------------------------------------------------------------------*/
27260
27261 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27262-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27263 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27264 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27265+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27266
27267 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27268 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27269diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27270index 2f33760..835e50a 100644
27271--- a/arch/xtensa/variants/fsf/include/variant/core.h
27272+++ b/arch/xtensa/variants/fsf/include/variant/core.h
27273@@ -11,6 +11,7 @@
27274 #ifndef _XTENSA_CORE_H
27275 #define _XTENSA_CORE_H
27276
27277+#include <linux/const.h>
27278
27279 /****************************************************************************
27280 Parameters Useful for Any Code, USER or PRIVILEGED
27281@@ -112,9 +113,9 @@
27282 ----------------------------------------------------------------------*/
27283
27284 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27285-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27286 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27287 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27288+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27289
27290 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27291 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27292diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27293index af00795..2bb8105 100644
27294--- a/arch/xtensa/variants/s6000/include/variant/core.h
27295+++ b/arch/xtensa/variants/s6000/include/variant/core.h
27296@@ -11,6 +11,7 @@
27297 #ifndef _XTENSA_CORE_CONFIGURATION_H
27298 #define _XTENSA_CORE_CONFIGURATION_H
27299
27300+#include <linux/const.h>
27301
27302 /****************************************************************************
27303 Parameters Useful for Any Code, USER or PRIVILEGED
27304@@ -118,9 +119,9 @@
27305 ----------------------------------------------------------------------*/
27306
27307 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27308-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27309 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27310 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27311+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27312
27313 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27314 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27315diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27316index 58916af..9cb880b 100644
27317--- a/block/blk-iopoll.c
27318+++ b/block/blk-iopoll.c
27319@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27320 }
27321 EXPORT_SYMBOL(blk_iopoll_complete);
27322
27323-static void blk_iopoll_softirq(struct softirq_action *h)
27324+static void blk_iopoll_softirq(void)
27325 {
27326 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27327 int rearm = 0, budget = blk_iopoll_budget;
27328diff --git a/block/blk-map.c b/block/blk-map.c
27329index 623e1cd..ca1e109 100644
27330--- a/block/blk-map.c
27331+++ b/block/blk-map.c
27332@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27333 if (!len || !kbuf)
27334 return -EINVAL;
27335
27336- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27337+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27338 if (do_copy)
27339 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27340 else
27341diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27342index 1366a89..e17f54b 100644
27343--- a/block/blk-softirq.c
27344+++ b/block/blk-softirq.c
27345@@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27346 * Softirq action handler - move entries to local list and loop over them
27347 * while passing them to the queue registered handler.
27348 */
27349-static void blk_done_softirq(struct softirq_action *h)
27350+static void blk_done_softirq(void)
27351 {
27352 struct list_head *cpu_list, local_list;
27353
27354diff --git a/block/bsg.c b/block/bsg.c
27355index ff64ae3..593560c 100644
27356--- a/block/bsg.c
27357+++ b/block/bsg.c
27358@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27359 struct sg_io_v4 *hdr, struct bsg_device *bd,
27360 fmode_t has_write_perm)
27361 {
27362+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27363+ unsigned char *cmdptr;
27364+
27365 if (hdr->request_len > BLK_MAX_CDB) {
27366 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27367 if (!rq->cmd)
27368 return -ENOMEM;
27369- }
27370+ cmdptr = rq->cmd;
27371+ } else
27372+ cmdptr = tmpcmd;
27373
27374- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27375+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27376 hdr->request_len))
27377 return -EFAULT;
27378
27379+ if (cmdptr != rq->cmd)
27380+ memcpy(rq->cmd, cmdptr, hdr->request_len);
27381+
27382 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27383 if (blk_verify_command(rq->cmd, has_write_perm))
27384 return -EPERM;
27385diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27386index 7c668c8..db3521c 100644
27387--- a/block/compat_ioctl.c
27388+++ b/block/compat_ioctl.c
27389@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27390 err |= __get_user(f->spec1, &uf->spec1);
27391 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27392 err |= __get_user(name, &uf->name);
27393- f->name = compat_ptr(name);
27394+ f->name = (void __force_kernel *)compat_ptr(name);
27395 if (err) {
27396 err = -EFAULT;
27397 goto out;
27398diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27399index 6296b40..417c00f 100644
27400--- a/block/partitions/efi.c
27401+++ b/block/partitions/efi.c
27402@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27403 if (!gpt)
27404 return NULL;
27405
27406+ if (!le32_to_cpu(gpt->num_partition_entries))
27407+ return NULL;
27408+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27409+ if (!pte)
27410+ return NULL;
27411+
27412 count = le32_to_cpu(gpt->num_partition_entries) *
27413 le32_to_cpu(gpt->sizeof_partition_entry);
27414- if (!count)
27415- return NULL;
27416- pte = kzalloc(count, GFP_KERNEL);
27417- if (!pte)
27418- return NULL;
27419-
27420 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27421 (u8 *) pte,
27422 count) < count) {
27423diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27424index 260fa80..e8f3caf 100644
27425--- a/block/scsi_ioctl.c
27426+++ b/block/scsi_ioctl.c
27427@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27428 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27429 struct sg_io_hdr *hdr, fmode_t mode)
27430 {
27431- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27432+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27433+ unsigned char *cmdptr;
27434+
27435+ if (rq->cmd != rq->__cmd)
27436+ cmdptr = rq->cmd;
27437+ else
27438+ cmdptr = tmpcmd;
27439+
27440+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27441 return -EFAULT;
27442+
27443+ if (cmdptr != rq->cmd)
27444+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27445+
27446 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27447 return -EPERM;
27448
27449@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27450 int err;
27451 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27452 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27453+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27454+ unsigned char *cmdptr;
27455
27456 if (!sic)
27457 return -EINVAL;
27458@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27459 */
27460 err = -EFAULT;
27461 rq->cmd_len = cmdlen;
27462- if (copy_from_user(rq->cmd, sic->data, cmdlen))
27463+
27464+ if (rq->cmd != rq->__cmd)
27465+ cmdptr = rq->cmd;
27466+ else
27467+ cmdptr = tmpcmd;
27468+
27469+ if (copy_from_user(cmdptr, sic->data, cmdlen))
27470 goto error;
27471
27472+ if (rq->cmd != cmdptr)
27473+ memcpy(rq->cmd, cmdptr, cmdlen);
27474+
27475 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27476 goto error;
27477
27478diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27479index 671d4d6..5f24030 100644
27480--- a/crypto/cryptd.c
27481+++ b/crypto/cryptd.c
27482@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27483
27484 struct cryptd_blkcipher_request_ctx {
27485 crypto_completion_t complete;
27486-};
27487+} __no_const;
27488
27489 struct cryptd_hash_ctx {
27490 struct crypto_shash *child;
27491@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27492
27493 struct cryptd_aead_request_ctx {
27494 crypto_completion_t complete;
27495-};
27496+} __no_const;
27497
27498 static void cryptd_queue_worker(struct work_struct *work);
27499
27500diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27501index 5d41894..22021e4 100644
27502--- a/drivers/acpi/apei/cper.c
27503+++ b/drivers/acpi/apei/cper.c
27504@@ -38,12 +38,12 @@
27505 */
27506 u64 cper_next_record_id(void)
27507 {
27508- static atomic64_t seq;
27509+ static atomic64_unchecked_t seq;
27510
27511- if (!atomic64_read(&seq))
27512- atomic64_set(&seq, ((u64)get_seconds()) << 32);
27513+ if (!atomic64_read_unchecked(&seq))
27514+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27515
27516- return atomic64_inc_return(&seq);
27517+ return atomic64_inc_return_unchecked(&seq);
27518 }
27519 EXPORT_SYMBOL_GPL(cper_next_record_id);
27520
27521diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27522index b258cab..3fb7da7 100644
27523--- a/drivers/acpi/ec_sys.c
27524+++ b/drivers/acpi/ec_sys.c
27525@@ -12,6 +12,7 @@
27526 #include <linux/acpi.h>
27527 #include <linux/debugfs.h>
27528 #include <linux/module.h>
27529+#include <linux/uaccess.h>
27530 #include "internal.h"
27531
27532 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27533@@ -40,7 +41,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27534 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27535 */
27536 unsigned int size = EC_SPACE_SIZE;
27537- u8 *data = (u8 *) buf;
27538+ u8 data;
27539 loff_t init_off = *off;
27540 int err = 0;
27541
27542@@ -53,9 +54,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27543 size = count;
27544
27545 while (size) {
27546- err = ec_read(*off, &data[*off - init_off]);
27547+ err = ec_read(*off, &data);
27548 if (err)
27549 return err;
27550+ if (put_user(data, &buf[*off - init_off]))
27551+ return -EFAULT;
27552 *off += 1;
27553 size--;
27554 }
27555@@ -71,7 +74,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27556
27557 unsigned int size = count;
27558 loff_t init_off = *off;
27559- u8 *data = (u8 *) buf;
27560 int err = 0;
27561
27562 if (*off >= EC_SPACE_SIZE)
27563@@ -82,7 +84,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27564 }
27565
27566 while (size) {
27567- u8 byte_write = data[*off - init_off];
27568+ u8 byte_write;
27569+ if (get_user(byte_write, &buf[*off - init_off]))
27570+ return -EFAULT;
27571 err = ec_write(*off, byte_write);
27572 if (err)
27573 return err;
27574diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27575index 251c7b62..000462d 100644
27576--- a/drivers/acpi/proc.c
27577+++ b/drivers/acpi/proc.c
27578@@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27579 size_t count, loff_t * ppos)
27580 {
27581 struct list_head *node, *next;
27582- char strbuf[5];
27583- char str[5] = "";
27584- unsigned int len = count;
27585+ char strbuf[5] = {0};
27586
27587- if (len > 4)
27588- len = 4;
27589- if (len < 0)
27590+ if (count > 4)
27591+ count = 4;
27592+ if (copy_from_user(strbuf, buffer, count))
27593 return -EFAULT;
27594-
27595- if (copy_from_user(strbuf, buffer, len))
27596- return -EFAULT;
27597- strbuf[len] = '\0';
27598- sscanf(strbuf, "%s", str);
27599+ strbuf[count] = '\0';
27600
27601 mutex_lock(&acpi_device_lock);
27602 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27603@@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27604 if (!dev->wakeup.flags.valid)
27605 continue;
27606
27607- if (!strncmp(dev->pnp.bus_id, str, 4)) {
27608+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27609 if (device_can_wakeup(&dev->dev)) {
27610 bool enable = !device_may_wakeup(&dev->dev);
27611 device_set_wakeup_enable(&dev->dev, enable);
27612diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27613index 8ae05ce..7dbbed9 100644
27614--- a/drivers/acpi/processor_driver.c
27615+++ b/drivers/acpi/processor_driver.c
27616@@ -555,7 +555,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27617 return 0;
27618 #endif
27619
27620- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27621+ BUG_ON(pr->id >= nr_cpu_ids);
27622
27623 /*
27624 * Buggy BIOS check
27625diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27626index c06e0ec..a2c06ba 100644
27627--- a/drivers/ata/libata-core.c
27628+++ b/drivers/ata/libata-core.c
27629@@ -4736,7 +4736,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27630 struct ata_port *ap;
27631 unsigned int tag;
27632
27633- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27634+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27635 ap = qc->ap;
27636
27637 qc->flags = 0;
27638@@ -4752,7 +4752,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27639 struct ata_port *ap;
27640 struct ata_link *link;
27641
27642- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27643+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27644 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27645 ap = qc->ap;
27646 link = qc->dev->link;
27647@@ -5816,6 +5816,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27648 return;
27649
27650 spin_lock(&lock);
27651+ pax_open_kernel();
27652
27653 for (cur = ops->inherits; cur; cur = cur->inherits) {
27654 void **inherit = (void **)cur;
27655@@ -5829,8 +5830,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27656 if (IS_ERR(*pp))
27657 *pp = NULL;
27658
27659- ops->inherits = NULL;
27660+ *(struct ata_port_operations **)&ops->inherits = NULL;
27661
27662+ pax_close_kernel();
27663 spin_unlock(&lock);
27664 }
27665
27666diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27667index 048589f..4002b98 100644
27668--- a/drivers/ata/pata_arasan_cf.c
27669+++ b/drivers/ata/pata_arasan_cf.c
27670@@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27671 /* Handle platform specific quirks */
27672 if (pdata->quirk) {
27673 if (pdata->quirk & CF_BROKEN_PIO) {
27674- ap->ops->set_piomode = NULL;
27675+ pax_open_kernel();
27676+ *(void **)&ap->ops->set_piomode = NULL;
27677+ pax_close_kernel();
27678 ap->pio_mask = 0;
27679 }
27680 if (pdata->quirk & CF_BROKEN_MWDMA)
27681diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27682index f9b983a..887b9d8 100644
27683--- a/drivers/atm/adummy.c
27684+++ b/drivers/atm/adummy.c
27685@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27686 vcc->pop(vcc, skb);
27687 else
27688 dev_kfree_skb_any(skb);
27689- atomic_inc(&vcc->stats->tx);
27690+ atomic_inc_unchecked(&vcc->stats->tx);
27691
27692 return 0;
27693 }
27694diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27695index f8f41e0..1f987dd 100644
27696--- a/drivers/atm/ambassador.c
27697+++ b/drivers/atm/ambassador.c
27698@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27699 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27700
27701 // VC layer stats
27702- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27703+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27704
27705 // free the descriptor
27706 kfree (tx_descr);
27707@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27708 dump_skb ("<<<", vc, skb);
27709
27710 // VC layer stats
27711- atomic_inc(&atm_vcc->stats->rx);
27712+ atomic_inc_unchecked(&atm_vcc->stats->rx);
27713 __net_timestamp(skb);
27714 // end of our responsibility
27715 atm_vcc->push (atm_vcc, skb);
27716@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27717 } else {
27718 PRINTK (KERN_INFO, "dropped over-size frame");
27719 // should we count this?
27720- atomic_inc(&atm_vcc->stats->rx_drop);
27721+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27722 }
27723
27724 } else {
27725@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27726 }
27727
27728 if (check_area (skb->data, skb->len)) {
27729- atomic_inc(&atm_vcc->stats->tx_err);
27730+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27731 return -ENOMEM; // ?
27732 }
27733
27734diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27735index b22d71c..d6e1049 100644
27736--- a/drivers/atm/atmtcp.c
27737+++ b/drivers/atm/atmtcp.c
27738@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27739 if (vcc->pop) vcc->pop(vcc,skb);
27740 else dev_kfree_skb(skb);
27741 if (dev_data) return 0;
27742- atomic_inc(&vcc->stats->tx_err);
27743+ atomic_inc_unchecked(&vcc->stats->tx_err);
27744 return -ENOLINK;
27745 }
27746 size = skb->len+sizeof(struct atmtcp_hdr);
27747@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27748 if (!new_skb) {
27749 if (vcc->pop) vcc->pop(vcc,skb);
27750 else dev_kfree_skb(skb);
27751- atomic_inc(&vcc->stats->tx_err);
27752+ atomic_inc_unchecked(&vcc->stats->tx_err);
27753 return -ENOBUFS;
27754 }
27755 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27756@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27757 if (vcc->pop) vcc->pop(vcc,skb);
27758 else dev_kfree_skb(skb);
27759 out_vcc->push(out_vcc,new_skb);
27760- atomic_inc(&vcc->stats->tx);
27761- atomic_inc(&out_vcc->stats->rx);
27762+ atomic_inc_unchecked(&vcc->stats->tx);
27763+ atomic_inc_unchecked(&out_vcc->stats->rx);
27764 return 0;
27765 }
27766
27767@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27768 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27769 read_unlock(&vcc_sklist_lock);
27770 if (!out_vcc) {
27771- atomic_inc(&vcc->stats->tx_err);
27772+ atomic_inc_unchecked(&vcc->stats->tx_err);
27773 goto done;
27774 }
27775 skb_pull(skb,sizeof(struct atmtcp_hdr));
27776@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27777 __net_timestamp(new_skb);
27778 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27779 out_vcc->push(out_vcc,new_skb);
27780- atomic_inc(&vcc->stats->tx);
27781- atomic_inc(&out_vcc->stats->rx);
27782+ atomic_inc_unchecked(&vcc->stats->tx);
27783+ atomic_inc_unchecked(&out_vcc->stats->rx);
27784 done:
27785 if (vcc->pop) vcc->pop(vcc,skb);
27786 else dev_kfree_skb(skb);
27787diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27788index 956e9ac..133516d 100644
27789--- a/drivers/atm/eni.c
27790+++ b/drivers/atm/eni.c
27791@@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27792 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27793 vcc->dev->number);
27794 length = 0;
27795- atomic_inc(&vcc->stats->rx_err);
27796+ atomic_inc_unchecked(&vcc->stats->rx_err);
27797 }
27798 else {
27799 length = ATM_CELL_SIZE-1; /* no HEC */
27800@@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27801 size);
27802 }
27803 eff = length = 0;
27804- atomic_inc(&vcc->stats->rx_err);
27805+ atomic_inc_unchecked(&vcc->stats->rx_err);
27806 }
27807 else {
27808 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27809@@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27810 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27811 vcc->dev->number,vcc->vci,length,size << 2,descr);
27812 length = eff = 0;
27813- atomic_inc(&vcc->stats->rx_err);
27814+ atomic_inc_unchecked(&vcc->stats->rx_err);
27815 }
27816 }
27817 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27818@@ -771,7 +771,7 @@ rx_dequeued++;
27819 vcc->push(vcc,skb);
27820 pushed++;
27821 }
27822- atomic_inc(&vcc->stats->rx);
27823+ atomic_inc_unchecked(&vcc->stats->rx);
27824 }
27825 wake_up(&eni_dev->rx_wait);
27826 }
27827@@ -1229,7 +1229,7 @@ static void dequeue_tx(struct atm_dev *dev)
27828 PCI_DMA_TODEVICE);
27829 if (vcc->pop) vcc->pop(vcc,skb);
27830 else dev_kfree_skb_irq(skb);
27831- atomic_inc(&vcc->stats->tx);
27832+ atomic_inc_unchecked(&vcc->stats->tx);
27833 wake_up(&eni_dev->tx_wait);
27834 dma_complete++;
27835 }
27836@@ -1569,7 +1569,7 @@ tx_complete++;
27837 /*--------------------------------- entries ---------------------------------*/
27838
27839
27840-static const char *media_name[] __devinitdata = {
27841+static const char *media_name[] __devinitconst = {
27842 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27843 "UTP", "05?", "06?", "07?", /* 4- 7 */
27844 "TAXI","09?", "10?", "11?", /* 8-11 */
27845diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27846index 5072f8a..fa52520d 100644
27847--- a/drivers/atm/firestream.c
27848+++ b/drivers/atm/firestream.c
27849@@ -750,7 +750,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27850 }
27851 }
27852
27853- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27854+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27855
27856 fs_dprintk (FS_DEBUG_TXMEM, "i");
27857 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27858@@ -817,7 +817,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27859 #endif
27860 skb_put (skb, qe->p1 & 0xffff);
27861 ATM_SKB(skb)->vcc = atm_vcc;
27862- atomic_inc(&atm_vcc->stats->rx);
27863+ atomic_inc_unchecked(&atm_vcc->stats->rx);
27864 __net_timestamp(skb);
27865 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27866 atm_vcc->push (atm_vcc, skb);
27867@@ -838,12 +838,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27868 kfree (pe);
27869 }
27870 if (atm_vcc)
27871- atomic_inc(&atm_vcc->stats->rx_drop);
27872+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27873 break;
27874 case 0x1f: /* Reassembly abort: no buffers. */
27875 /* Silently increment error counter. */
27876 if (atm_vcc)
27877- atomic_inc(&atm_vcc->stats->rx_drop);
27878+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27879 break;
27880 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27881 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27882diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27883index 361f5ae..7fc552d 100644
27884--- a/drivers/atm/fore200e.c
27885+++ b/drivers/atm/fore200e.c
27886@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27887 #endif
27888 /* check error condition */
27889 if (*entry->status & STATUS_ERROR)
27890- atomic_inc(&vcc->stats->tx_err);
27891+ atomic_inc_unchecked(&vcc->stats->tx_err);
27892 else
27893- atomic_inc(&vcc->stats->tx);
27894+ atomic_inc_unchecked(&vcc->stats->tx);
27895 }
27896 }
27897
27898@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27899 if (skb == NULL) {
27900 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27901
27902- atomic_inc(&vcc->stats->rx_drop);
27903+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27904 return -ENOMEM;
27905 }
27906
27907@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27908
27909 dev_kfree_skb_any(skb);
27910
27911- atomic_inc(&vcc->stats->rx_drop);
27912+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27913 return -ENOMEM;
27914 }
27915
27916 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27917
27918 vcc->push(vcc, skb);
27919- atomic_inc(&vcc->stats->rx);
27920+ atomic_inc_unchecked(&vcc->stats->rx);
27921
27922 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27923
27924@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
27925 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27926 fore200e->atm_dev->number,
27927 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27928- atomic_inc(&vcc->stats->rx_err);
27929+ atomic_inc_unchecked(&vcc->stats->rx_err);
27930 }
27931 }
27932
27933@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
27934 goto retry_here;
27935 }
27936
27937- atomic_inc(&vcc->stats->tx_err);
27938+ atomic_inc_unchecked(&vcc->stats->tx_err);
27939
27940 fore200e->tx_sat++;
27941 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
27942diff --git a/drivers/atm/he.c b/drivers/atm/he.c
27943index b182c2f..1c6fa8a 100644
27944--- a/drivers/atm/he.c
27945+++ b/drivers/atm/he.c
27946@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27947
27948 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
27949 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
27950- atomic_inc(&vcc->stats->rx_drop);
27951+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27952 goto return_host_buffers;
27953 }
27954
27955@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27956 RBRQ_LEN_ERR(he_dev->rbrq_head)
27957 ? "LEN_ERR" : "",
27958 vcc->vpi, vcc->vci);
27959- atomic_inc(&vcc->stats->rx_err);
27960+ atomic_inc_unchecked(&vcc->stats->rx_err);
27961 goto return_host_buffers;
27962 }
27963
27964@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27965 vcc->push(vcc, skb);
27966 spin_lock(&he_dev->global_lock);
27967
27968- atomic_inc(&vcc->stats->rx);
27969+ atomic_inc_unchecked(&vcc->stats->rx);
27970
27971 return_host_buffers:
27972 ++pdus_assembled;
27973@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
27974 tpd->vcc->pop(tpd->vcc, tpd->skb);
27975 else
27976 dev_kfree_skb_any(tpd->skb);
27977- atomic_inc(&tpd->vcc->stats->tx_err);
27978+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
27979 }
27980 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
27981 return;
27982@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27983 vcc->pop(vcc, skb);
27984 else
27985 dev_kfree_skb_any(skb);
27986- atomic_inc(&vcc->stats->tx_err);
27987+ atomic_inc_unchecked(&vcc->stats->tx_err);
27988 return -EINVAL;
27989 }
27990
27991@@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27992 vcc->pop(vcc, skb);
27993 else
27994 dev_kfree_skb_any(skb);
27995- atomic_inc(&vcc->stats->tx_err);
27996+ atomic_inc_unchecked(&vcc->stats->tx_err);
27997 return -EINVAL;
27998 }
27999 #endif
28000@@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28001 vcc->pop(vcc, skb);
28002 else
28003 dev_kfree_skb_any(skb);
28004- atomic_inc(&vcc->stats->tx_err);
28005+ atomic_inc_unchecked(&vcc->stats->tx_err);
28006 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28007 return -ENOMEM;
28008 }
28009@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28010 vcc->pop(vcc, skb);
28011 else
28012 dev_kfree_skb_any(skb);
28013- atomic_inc(&vcc->stats->tx_err);
28014+ atomic_inc_unchecked(&vcc->stats->tx_err);
28015 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28016 return -ENOMEM;
28017 }
28018@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28019 __enqueue_tpd(he_dev, tpd, cid);
28020 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28021
28022- atomic_inc(&vcc->stats->tx);
28023+ atomic_inc_unchecked(&vcc->stats->tx);
28024
28025 return 0;
28026 }
28027diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28028index b812103..e391a49 100644
28029--- a/drivers/atm/horizon.c
28030+++ b/drivers/atm/horizon.c
28031@@ -1035,7 +1035,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28032 {
28033 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28034 // VC layer stats
28035- atomic_inc(&vcc->stats->rx);
28036+ atomic_inc_unchecked(&vcc->stats->rx);
28037 __net_timestamp(skb);
28038 // end of our responsibility
28039 vcc->push (vcc, skb);
28040@@ -1187,7 +1187,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28041 dev->tx_iovec = NULL;
28042
28043 // VC layer stats
28044- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28045+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28046
28047 // free the skb
28048 hrz_kfree_skb (skb);
28049diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28050index 1c05212..c28e200 100644
28051--- a/drivers/atm/idt77252.c
28052+++ b/drivers/atm/idt77252.c
28053@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28054 else
28055 dev_kfree_skb(skb);
28056
28057- atomic_inc(&vcc->stats->tx);
28058+ atomic_inc_unchecked(&vcc->stats->tx);
28059 }
28060
28061 atomic_dec(&scq->used);
28062@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28063 if ((sb = dev_alloc_skb(64)) == NULL) {
28064 printk("%s: Can't allocate buffers for aal0.\n",
28065 card->name);
28066- atomic_add(i, &vcc->stats->rx_drop);
28067+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28068 break;
28069 }
28070 if (!atm_charge(vcc, sb->truesize)) {
28071 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28072 card->name);
28073- atomic_add(i - 1, &vcc->stats->rx_drop);
28074+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28075 dev_kfree_skb(sb);
28076 break;
28077 }
28078@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28079 ATM_SKB(sb)->vcc = vcc;
28080 __net_timestamp(sb);
28081 vcc->push(vcc, sb);
28082- atomic_inc(&vcc->stats->rx);
28083+ atomic_inc_unchecked(&vcc->stats->rx);
28084
28085 cell += ATM_CELL_PAYLOAD;
28086 }
28087@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28088 "(CDC: %08x)\n",
28089 card->name, len, rpp->len, readl(SAR_REG_CDC));
28090 recycle_rx_pool_skb(card, rpp);
28091- atomic_inc(&vcc->stats->rx_err);
28092+ atomic_inc_unchecked(&vcc->stats->rx_err);
28093 return;
28094 }
28095 if (stat & SAR_RSQE_CRC) {
28096 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28097 recycle_rx_pool_skb(card, rpp);
28098- atomic_inc(&vcc->stats->rx_err);
28099+ atomic_inc_unchecked(&vcc->stats->rx_err);
28100 return;
28101 }
28102 if (skb_queue_len(&rpp->queue) > 1) {
28103@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28104 RXPRINTK("%s: Can't alloc RX skb.\n",
28105 card->name);
28106 recycle_rx_pool_skb(card, rpp);
28107- atomic_inc(&vcc->stats->rx_err);
28108+ atomic_inc_unchecked(&vcc->stats->rx_err);
28109 return;
28110 }
28111 if (!atm_charge(vcc, skb->truesize)) {
28112@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28113 __net_timestamp(skb);
28114
28115 vcc->push(vcc, skb);
28116- atomic_inc(&vcc->stats->rx);
28117+ atomic_inc_unchecked(&vcc->stats->rx);
28118
28119 return;
28120 }
28121@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28122 __net_timestamp(skb);
28123
28124 vcc->push(vcc, skb);
28125- atomic_inc(&vcc->stats->rx);
28126+ atomic_inc_unchecked(&vcc->stats->rx);
28127
28128 if (skb->truesize > SAR_FB_SIZE_3)
28129 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28130@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28131 if (vcc->qos.aal != ATM_AAL0) {
28132 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28133 card->name, vpi, vci);
28134- atomic_inc(&vcc->stats->rx_drop);
28135+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28136 goto drop;
28137 }
28138
28139 if ((sb = dev_alloc_skb(64)) == NULL) {
28140 printk("%s: Can't allocate buffers for AAL0.\n",
28141 card->name);
28142- atomic_inc(&vcc->stats->rx_err);
28143+ atomic_inc_unchecked(&vcc->stats->rx_err);
28144 goto drop;
28145 }
28146
28147@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28148 ATM_SKB(sb)->vcc = vcc;
28149 __net_timestamp(sb);
28150 vcc->push(vcc, sb);
28151- atomic_inc(&vcc->stats->rx);
28152+ atomic_inc_unchecked(&vcc->stats->rx);
28153
28154 drop:
28155 skb_pull(queue, 64);
28156@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28157
28158 if (vc == NULL) {
28159 printk("%s: NULL connection in send().\n", card->name);
28160- atomic_inc(&vcc->stats->tx_err);
28161+ atomic_inc_unchecked(&vcc->stats->tx_err);
28162 dev_kfree_skb(skb);
28163 return -EINVAL;
28164 }
28165 if (!test_bit(VCF_TX, &vc->flags)) {
28166 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28167- atomic_inc(&vcc->stats->tx_err);
28168+ atomic_inc_unchecked(&vcc->stats->tx_err);
28169 dev_kfree_skb(skb);
28170 return -EINVAL;
28171 }
28172@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28173 break;
28174 default:
28175 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28176- atomic_inc(&vcc->stats->tx_err);
28177+ atomic_inc_unchecked(&vcc->stats->tx_err);
28178 dev_kfree_skb(skb);
28179 return -EINVAL;
28180 }
28181
28182 if (skb_shinfo(skb)->nr_frags != 0) {
28183 printk("%s: No scatter-gather yet.\n", card->name);
28184- atomic_inc(&vcc->stats->tx_err);
28185+ atomic_inc_unchecked(&vcc->stats->tx_err);
28186 dev_kfree_skb(skb);
28187 return -EINVAL;
28188 }
28189@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28190
28191 err = queue_skb(card, vc, skb, oam);
28192 if (err) {
28193- atomic_inc(&vcc->stats->tx_err);
28194+ atomic_inc_unchecked(&vcc->stats->tx_err);
28195 dev_kfree_skb(skb);
28196 return err;
28197 }
28198@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28199 skb = dev_alloc_skb(64);
28200 if (!skb) {
28201 printk("%s: Out of memory in send_oam().\n", card->name);
28202- atomic_inc(&vcc->stats->tx_err);
28203+ atomic_inc_unchecked(&vcc->stats->tx_err);
28204 return -ENOMEM;
28205 }
28206 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28207diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28208index 9e373ba..cf93727 100644
28209--- a/drivers/atm/iphase.c
28210+++ b/drivers/atm/iphase.c
28211@@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
28212 status = (u_short) (buf_desc_ptr->desc_mode);
28213 if (status & (RX_CER | RX_PTE | RX_OFL))
28214 {
28215- atomic_inc(&vcc->stats->rx_err);
28216+ atomic_inc_unchecked(&vcc->stats->rx_err);
28217 IF_ERR(printk("IA: bad packet, dropping it");)
28218 if (status & RX_CER) {
28219 IF_ERR(printk(" cause: packet CRC error\n");)
28220@@ -1169,7 +1169,7 @@ static int rx_pkt(struct atm_dev *dev)
28221 len = dma_addr - buf_addr;
28222 if (len > iadev->rx_buf_sz) {
28223 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28224- atomic_inc(&vcc->stats->rx_err);
28225+ atomic_inc_unchecked(&vcc->stats->rx_err);
28226 goto out_free_desc;
28227 }
28228
28229@@ -1319,7 +1319,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28230 ia_vcc = INPH_IA_VCC(vcc);
28231 if (ia_vcc == NULL)
28232 {
28233- atomic_inc(&vcc->stats->rx_err);
28234+ atomic_inc_unchecked(&vcc->stats->rx_err);
28235 atm_return(vcc, skb->truesize);
28236 dev_kfree_skb_any(skb);
28237 goto INCR_DLE;
28238@@ -1331,7 +1331,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28239 if ((length > iadev->rx_buf_sz) || (length >
28240 (skb->len - sizeof(struct cpcs_trailer))))
28241 {
28242- atomic_inc(&vcc->stats->rx_err);
28243+ atomic_inc_unchecked(&vcc->stats->rx_err);
28244 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28245 length, skb->len);)
28246 atm_return(vcc, skb->truesize);
28247@@ -1347,7 +1347,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28248
28249 IF_RX(printk("rx_dle_intr: skb push");)
28250 vcc->push(vcc,skb);
28251- atomic_inc(&vcc->stats->rx);
28252+ atomic_inc_unchecked(&vcc->stats->rx);
28253 iadev->rx_pkt_cnt++;
28254 }
28255 INCR_DLE:
28256@@ -2827,15 +2827,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28257 {
28258 struct k_sonet_stats *stats;
28259 stats = &PRIV(_ia_dev[board])->sonet_stats;
28260- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28261- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28262- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28263- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28264- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28265- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28266- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28267- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28268- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28269+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28270+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28271+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28272+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28273+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28274+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28275+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28276+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28277+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28278 }
28279 ia_cmds.status = 0;
28280 break;
28281@@ -2940,7 +2940,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28282 if ((desc == 0) || (desc > iadev->num_tx_desc))
28283 {
28284 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28285- atomic_inc(&vcc->stats->tx);
28286+ atomic_inc_unchecked(&vcc->stats->tx);
28287 if (vcc->pop)
28288 vcc->pop(vcc, skb);
28289 else
28290@@ -3045,14 +3045,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28291 ATM_DESC(skb) = vcc->vci;
28292 skb_queue_tail(&iadev->tx_dma_q, skb);
28293
28294- atomic_inc(&vcc->stats->tx);
28295+ atomic_inc_unchecked(&vcc->stats->tx);
28296 iadev->tx_pkt_cnt++;
28297 /* Increment transaction counter */
28298 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28299
28300 #if 0
28301 /* add flow control logic */
28302- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28303+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28304 if (iavcc->vc_desc_cnt > 10) {
28305 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28306 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28307diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28308index f556969..0da15eb 100644
28309--- a/drivers/atm/lanai.c
28310+++ b/drivers/atm/lanai.c
28311@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28312 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28313 lanai_endtx(lanai, lvcc);
28314 lanai_free_skb(lvcc->tx.atmvcc, skb);
28315- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28316+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28317 }
28318
28319 /* Try to fill the buffer - don't call unless there is backlog */
28320@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28321 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28322 __net_timestamp(skb);
28323 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28324- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28325+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28326 out:
28327 lvcc->rx.buf.ptr = end;
28328 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28329@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28330 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28331 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28332 lanai->stats.service_rxnotaal5++;
28333- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28334+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28335 return 0;
28336 }
28337 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28338@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28339 int bytes;
28340 read_unlock(&vcc_sklist_lock);
28341 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28342- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28343+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28344 lvcc->stats.x.aal5.service_trash++;
28345 bytes = (SERVICE_GET_END(s) * 16) -
28346 (((unsigned long) lvcc->rx.buf.ptr) -
28347@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28348 }
28349 if (s & SERVICE_STREAM) {
28350 read_unlock(&vcc_sklist_lock);
28351- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28352+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28353 lvcc->stats.x.aal5.service_stream++;
28354 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28355 "PDU on VCI %d!\n", lanai->number, vci);
28356@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28357 return 0;
28358 }
28359 DPRINTK("got rx crc error on vci %d\n", vci);
28360- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28361+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28362 lvcc->stats.x.aal5.service_rxcrc++;
28363 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28364 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28365diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28366index 1c70c45..300718d 100644
28367--- a/drivers/atm/nicstar.c
28368+++ b/drivers/atm/nicstar.c
28369@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28370 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28371 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28372 card->index);
28373- atomic_inc(&vcc->stats->tx_err);
28374+ atomic_inc_unchecked(&vcc->stats->tx_err);
28375 dev_kfree_skb_any(skb);
28376 return -EINVAL;
28377 }
28378@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28379 if (!vc->tx) {
28380 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28381 card->index);
28382- atomic_inc(&vcc->stats->tx_err);
28383+ atomic_inc_unchecked(&vcc->stats->tx_err);
28384 dev_kfree_skb_any(skb);
28385 return -EINVAL;
28386 }
28387@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28388 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28389 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28390 card->index);
28391- atomic_inc(&vcc->stats->tx_err);
28392+ atomic_inc_unchecked(&vcc->stats->tx_err);
28393 dev_kfree_skb_any(skb);
28394 return -EINVAL;
28395 }
28396
28397 if (skb_shinfo(skb)->nr_frags != 0) {
28398 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28399- atomic_inc(&vcc->stats->tx_err);
28400+ atomic_inc_unchecked(&vcc->stats->tx_err);
28401 dev_kfree_skb_any(skb);
28402 return -EINVAL;
28403 }
28404@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28405 }
28406
28407 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28408- atomic_inc(&vcc->stats->tx_err);
28409+ atomic_inc_unchecked(&vcc->stats->tx_err);
28410 dev_kfree_skb_any(skb);
28411 return -EIO;
28412 }
28413- atomic_inc(&vcc->stats->tx);
28414+ atomic_inc_unchecked(&vcc->stats->tx);
28415
28416 return 0;
28417 }
28418@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28419 printk
28420 ("nicstar%d: Can't allocate buffers for aal0.\n",
28421 card->index);
28422- atomic_add(i, &vcc->stats->rx_drop);
28423+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28424 break;
28425 }
28426 if (!atm_charge(vcc, sb->truesize)) {
28427 RXPRINTK
28428 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28429 card->index);
28430- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28431+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28432 dev_kfree_skb_any(sb);
28433 break;
28434 }
28435@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28436 ATM_SKB(sb)->vcc = vcc;
28437 __net_timestamp(sb);
28438 vcc->push(vcc, sb);
28439- atomic_inc(&vcc->stats->rx);
28440+ atomic_inc_unchecked(&vcc->stats->rx);
28441 cell += ATM_CELL_PAYLOAD;
28442 }
28443
28444@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28445 if (iovb == NULL) {
28446 printk("nicstar%d: Out of iovec buffers.\n",
28447 card->index);
28448- atomic_inc(&vcc->stats->rx_drop);
28449+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28450 recycle_rx_buf(card, skb);
28451 return;
28452 }
28453@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28454 small or large buffer itself. */
28455 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28456 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28457- atomic_inc(&vcc->stats->rx_err);
28458+ atomic_inc_unchecked(&vcc->stats->rx_err);
28459 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28460 NS_MAX_IOVECS);
28461 NS_PRV_IOVCNT(iovb) = 0;
28462@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28463 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28464 card->index);
28465 which_list(card, skb);
28466- atomic_inc(&vcc->stats->rx_err);
28467+ atomic_inc_unchecked(&vcc->stats->rx_err);
28468 recycle_rx_buf(card, skb);
28469 vc->rx_iov = NULL;
28470 recycle_iov_buf(card, iovb);
28471@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28472 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28473 card->index);
28474 which_list(card, skb);
28475- atomic_inc(&vcc->stats->rx_err);
28476+ atomic_inc_unchecked(&vcc->stats->rx_err);
28477 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28478 NS_PRV_IOVCNT(iovb));
28479 vc->rx_iov = NULL;
28480@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28481 printk(" - PDU size mismatch.\n");
28482 else
28483 printk(".\n");
28484- atomic_inc(&vcc->stats->rx_err);
28485+ atomic_inc_unchecked(&vcc->stats->rx_err);
28486 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28487 NS_PRV_IOVCNT(iovb));
28488 vc->rx_iov = NULL;
28489@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28490 /* skb points to a small buffer */
28491 if (!atm_charge(vcc, skb->truesize)) {
28492 push_rxbufs(card, skb);
28493- atomic_inc(&vcc->stats->rx_drop);
28494+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28495 } else {
28496 skb_put(skb, len);
28497 dequeue_sm_buf(card, skb);
28498@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28499 ATM_SKB(skb)->vcc = vcc;
28500 __net_timestamp(skb);
28501 vcc->push(vcc, skb);
28502- atomic_inc(&vcc->stats->rx);
28503+ atomic_inc_unchecked(&vcc->stats->rx);
28504 }
28505 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28506 struct sk_buff *sb;
28507@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28508 if (len <= NS_SMBUFSIZE) {
28509 if (!atm_charge(vcc, sb->truesize)) {
28510 push_rxbufs(card, sb);
28511- atomic_inc(&vcc->stats->rx_drop);
28512+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28513 } else {
28514 skb_put(sb, len);
28515 dequeue_sm_buf(card, sb);
28516@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28517 ATM_SKB(sb)->vcc = vcc;
28518 __net_timestamp(sb);
28519 vcc->push(vcc, sb);
28520- atomic_inc(&vcc->stats->rx);
28521+ atomic_inc_unchecked(&vcc->stats->rx);
28522 }
28523
28524 push_rxbufs(card, skb);
28525@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28526
28527 if (!atm_charge(vcc, skb->truesize)) {
28528 push_rxbufs(card, skb);
28529- atomic_inc(&vcc->stats->rx_drop);
28530+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28531 } else {
28532 dequeue_lg_buf(card, skb);
28533 #ifdef NS_USE_DESTRUCTORS
28534@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28535 ATM_SKB(skb)->vcc = vcc;
28536 __net_timestamp(skb);
28537 vcc->push(vcc, skb);
28538- atomic_inc(&vcc->stats->rx);
28539+ atomic_inc_unchecked(&vcc->stats->rx);
28540 }
28541
28542 push_rxbufs(card, sb);
28543@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28544 printk
28545 ("nicstar%d: Out of huge buffers.\n",
28546 card->index);
28547- atomic_inc(&vcc->stats->rx_drop);
28548+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28549 recycle_iovec_rx_bufs(card,
28550 (struct iovec *)
28551 iovb->data,
28552@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28553 card->hbpool.count++;
28554 } else
28555 dev_kfree_skb_any(hb);
28556- atomic_inc(&vcc->stats->rx_drop);
28557+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28558 } else {
28559 /* Copy the small buffer to the huge buffer */
28560 sb = (struct sk_buff *)iov->iov_base;
28561@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28562 #endif /* NS_USE_DESTRUCTORS */
28563 __net_timestamp(hb);
28564 vcc->push(vcc, hb);
28565- atomic_inc(&vcc->stats->rx);
28566+ atomic_inc_unchecked(&vcc->stats->rx);
28567 }
28568 }
28569
28570diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28571index e8cd652..bbbd1fc 100644
28572--- a/drivers/atm/solos-pci.c
28573+++ b/drivers/atm/solos-pci.c
28574@@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28575 }
28576 atm_charge(vcc, skb->truesize);
28577 vcc->push(vcc, skb);
28578- atomic_inc(&vcc->stats->rx);
28579+ atomic_inc_unchecked(&vcc->stats->rx);
28580 break;
28581
28582 case PKT_STATUS:
28583@@ -1008,7 +1008,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28584 vcc = SKB_CB(oldskb)->vcc;
28585
28586 if (vcc) {
28587- atomic_inc(&vcc->stats->tx);
28588+ atomic_inc_unchecked(&vcc->stats->tx);
28589 solos_pop(vcc, oldskb);
28590 } else
28591 dev_kfree_skb_irq(oldskb);
28592diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28593index 90f1ccc..04c4a1e 100644
28594--- a/drivers/atm/suni.c
28595+++ b/drivers/atm/suni.c
28596@@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28597
28598
28599 #define ADD_LIMITED(s,v) \
28600- atomic_add((v),&stats->s); \
28601- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28602+ atomic_add_unchecked((v),&stats->s); \
28603+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28604
28605
28606 static void suni_hz(unsigned long from_timer)
28607diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28608index 5120a96..e2572bd 100644
28609--- a/drivers/atm/uPD98402.c
28610+++ b/drivers/atm/uPD98402.c
28611@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28612 struct sonet_stats tmp;
28613 int error = 0;
28614
28615- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28616+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28617 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28618 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28619 if (zero && !error) {
28620@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28621
28622
28623 #define ADD_LIMITED(s,v) \
28624- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28625- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28626- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28627+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28628+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28629+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28630
28631
28632 static void stat_event(struct atm_dev *dev)
28633@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28634 if (reason & uPD98402_INT_PFM) stat_event(dev);
28635 if (reason & uPD98402_INT_PCO) {
28636 (void) GET(PCOCR); /* clear interrupt cause */
28637- atomic_add(GET(HECCT),
28638+ atomic_add_unchecked(GET(HECCT),
28639 &PRIV(dev)->sonet_stats.uncorr_hcs);
28640 }
28641 if ((reason & uPD98402_INT_RFO) &&
28642@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28643 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28644 uPD98402_INT_LOS),PIMR); /* enable them */
28645 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28646- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28647- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28648- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28649+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28650+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28651+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28652 return 0;
28653 }
28654
28655diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28656index d889f56..17eb71e 100644
28657--- a/drivers/atm/zatm.c
28658+++ b/drivers/atm/zatm.c
28659@@ -460,7 +460,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28660 }
28661 if (!size) {
28662 dev_kfree_skb_irq(skb);
28663- if (vcc) atomic_inc(&vcc->stats->rx_err);
28664+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28665 continue;
28666 }
28667 if (!atm_charge(vcc,skb->truesize)) {
28668@@ -470,7 +470,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28669 skb->len = size;
28670 ATM_SKB(skb)->vcc = vcc;
28671 vcc->push(vcc,skb);
28672- atomic_inc(&vcc->stats->rx);
28673+ atomic_inc_unchecked(&vcc->stats->rx);
28674 }
28675 zout(pos & 0xffff,MTA(mbx));
28676 #if 0 /* probably a stupid idea */
28677@@ -734,7 +734,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28678 skb_queue_head(&zatm_vcc->backlog,skb);
28679 break;
28680 }
28681- atomic_inc(&vcc->stats->tx);
28682+ atomic_inc_unchecked(&vcc->stats->tx);
28683 wake_up(&zatm_vcc->tx_wait);
28684 }
28685
28686diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28687index 8493536..31adee0 100644
28688--- a/drivers/base/devtmpfs.c
28689+++ b/drivers/base/devtmpfs.c
28690@@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28691 if (!thread)
28692 return 0;
28693
28694- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28695+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28696 if (err)
28697 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28698 else
28699diff --git a/drivers/base/node.c b/drivers/base/node.c
28700index 90aa2a1..af1a177 100644
28701--- a/drivers/base/node.c
28702+++ b/drivers/base/node.c
28703@@ -592,11 +592,9 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
28704 {
28705 int n;
28706
28707- n = nodelist_scnprintf(buf, PAGE_SIZE, node_states[state]);
28708- if (n > 0 && PAGE_SIZE > n + 1) {
28709- *(buf + n++) = '\n';
28710- *(buf + n++) = '\0';
28711- }
28712+ n = nodelist_scnprintf(buf, PAGE_SIZE-2, node_states[state]);
28713+ buf[n++] = '\n';
28714+ buf[n] = '\0';
28715 return n;
28716 }
28717
28718diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28719index caf995f..6f76697 100644
28720--- a/drivers/base/power/wakeup.c
28721+++ b/drivers/base/power/wakeup.c
28722@@ -30,14 +30,14 @@ bool events_check_enabled;
28723 * They need to be modified together atomically, so it's better to use one
28724 * atomic variable to hold them both.
28725 */
28726-static atomic_t combined_event_count = ATOMIC_INIT(0);
28727+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28728
28729 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28730 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28731
28732 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28733 {
28734- unsigned int comb = atomic_read(&combined_event_count);
28735+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
28736
28737 *cnt = (comb >> IN_PROGRESS_BITS);
28738 *inpr = comb & MAX_IN_PROGRESS;
28739@@ -353,7 +353,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28740 ws->last_time = ktime_get();
28741
28742 /* Increment the counter of events in progress. */
28743- atomic_inc(&combined_event_count);
28744+ atomic_inc_unchecked(&combined_event_count);
28745 }
28746
28747 /**
28748@@ -443,7 +443,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28749 * Increment the counter of registered wakeup events and decrement the
28750 * couter of wakeup events in progress simultaneously.
28751 */
28752- atomic_add(MAX_IN_PROGRESS, &combined_event_count);
28753+ atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28754 }
28755
28756 /**
28757diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28758index b0f553b..77b928b 100644
28759--- a/drivers/block/cciss.c
28760+++ b/drivers/block/cciss.c
28761@@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28762 int err;
28763 u32 cp;
28764
28765+ memset(&arg64, 0, sizeof(arg64));
28766+
28767 err = 0;
28768 err |=
28769 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28770@@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28771 while (!list_empty(&h->reqQ)) {
28772 c = list_entry(h->reqQ.next, CommandList_struct, list);
28773 /* can't do anything if fifo is full */
28774- if ((h->access.fifo_full(h))) {
28775+ if ((h->access->fifo_full(h))) {
28776 dev_warn(&h->pdev->dev, "fifo full\n");
28777 break;
28778 }
28779@@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28780 h->Qdepth--;
28781
28782 /* Tell the controller execute command */
28783- h->access.submit_command(h, c);
28784+ h->access->submit_command(h, c);
28785
28786 /* Put job onto the completed Q */
28787 addQ(&h->cmpQ, c);
28788@@ -3443,17 +3445,17 @@ startio:
28789
28790 static inline unsigned long get_next_completion(ctlr_info_t *h)
28791 {
28792- return h->access.command_completed(h);
28793+ return h->access->command_completed(h);
28794 }
28795
28796 static inline int interrupt_pending(ctlr_info_t *h)
28797 {
28798- return h->access.intr_pending(h);
28799+ return h->access->intr_pending(h);
28800 }
28801
28802 static inline long interrupt_not_for_us(ctlr_info_t *h)
28803 {
28804- return ((h->access.intr_pending(h) == 0) ||
28805+ return ((h->access->intr_pending(h) == 0) ||
28806 (h->interrupts_enabled == 0));
28807 }
28808
28809@@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28810 u32 a;
28811
28812 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28813- return h->access.command_completed(h);
28814+ return h->access->command_completed(h);
28815
28816 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28817 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28818@@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28819 trans_support & CFGTBL_Trans_use_short_tags);
28820
28821 /* Change the access methods to the performant access methods */
28822- h->access = SA5_performant_access;
28823+ h->access = &SA5_performant_access;
28824 h->transMethod = CFGTBL_Trans_Performant;
28825
28826 return;
28827@@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28828 if (prod_index < 0)
28829 return -ENODEV;
28830 h->product_name = products[prod_index].product_name;
28831- h->access = *(products[prod_index].access);
28832+ h->access = products[prod_index].access;
28833
28834 if (cciss_board_disabled(h)) {
28835 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28836@@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28837 }
28838
28839 /* make sure the board interrupts are off */
28840- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28841+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28842 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28843 if (rc)
28844 goto clean2;
28845@@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28846 * fake ones to scoop up any residual completions.
28847 */
28848 spin_lock_irqsave(&h->lock, flags);
28849- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28850+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28851 spin_unlock_irqrestore(&h->lock, flags);
28852 free_irq(h->intr[h->intr_mode], h);
28853 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28854@@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28855 dev_info(&h->pdev->dev, "Board READY.\n");
28856 dev_info(&h->pdev->dev,
28857 "Waiting for stale completions to drain.\n");
28858- h->access.set_intr_mask(h, CCISS_INTR_ON);
28859+ h->access->set_intr_mask(h, CCISS_INTR_ON);
28860 msleep(10000);
28861- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28862+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28863
28864 rc = controller_reset_failed(h->cfgtable);
28865 if (rc)
28866@@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28867 cciss_scsi_setup(h);
28868
28869 /* Turn the interrupts on so we can service requests */
28870- h->access.set_intr_mask(h, CCISS_INTR_ON);
28871+ h->access->set_intr_mask(h, CCISS_INTR_ON);
28872
28873 /* Get the firmware version */
28874 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28875@@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28876 kfree(flush_buf);
28877 if (return_code != IO_OK)
28878 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28879- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28880+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28881 free_irq(h->intr[h->intr_mode], h);
28882 }
28883
28884diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28885index 7fda30e..eb5dfe0 100644
28886--- a/drivers/block/cciss.h
28887+++ b/drivers/block/cciss.h
28888@@ -101,7 +101,7 @@ struct ctlr_info
28889 /* information about each logical volume */
28890 drive_info_struct *drv[CISS_MAX_LUN];
28891
28892- struct access_method access;
28893+ struct access_method *access;
28894
28895 /* queue and queue Info */
28896 struct list_head reqQ;
28897diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28898index 9125bbe..eede5c8 100644
28899--- a/drivers/block/cpqarray.c
28900+++ b/drivers/block/cpqarray.c
28901@@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28902 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28903 goto Enomem4;
28904 }
28905- hba[i]->access.set_intr_mask(hba[i], 0);
28906+ hba[i]->access->set_intr_mask(hba[i], 0);
28907 if (request_irq(hba[i]->intr, do_ida_intr,
28908 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28909 {
28910@@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28911 add_timer(&hba[i]->timer);
28912
28913 /* Enable IRQ now that spinlock and rate limit timer are set up */
28914- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28915+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28916
28917 for(j=0; j<NWD; j++) {
28918 struct gendisk *disk = ida_gendisk[i][j];
28919@@ -694,7 +694,7 @@ DBGINFO(
28920 for(i=0; i<NR_PRODUCTS; i++) {
28921 if (board_id == products[i].board_id) {
28922 c->product_name = products[i].product_name;
28923- c->access = *(products[i].access);
28924+ c->access = products[i].access;
28925 break;
28926 }
28927 }
28928@@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28929 hba[ctlr]->intr = intr;
28930 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28931 hba[ctlr]->product_name = products[j].product_name;
28932- hba[ctlr]->access = *(products[j].access);
28933+ hba[ctlr]->access = products[j].access;
28934 hba[ctlr]->ctlr = ctlr;
28935 hba[ctlr]->board_id = board_id;
28936 hba[ctlr]->pci_dev = NULL; /* not PCI */
28937@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
28938
28939 while((c = h->reqQ) != NULL) {
28940 /* Can't do anything if we're busy */
28941- if (h->access.fifo_full(h) == 0)
28942+ if (h->access->fifo_full(h) == 0)
28943 return;
28944
28945 /* Get the first entry from the request Q */
28946@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
28947 h->Qdepth--;
28948
28949 /* Tell the controller to do our bidding */
28950- h->access.submit_command(h, c);
28951+ h->access->submit_command(h, c);
28952
28953 /* Get onto the completion Q */
28954 addQ(&h->cmpQ, c);
28955@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28956 unsigned long flags;
28957 __u32 a,a1;
28958
28959- istat = h->access.intr_pending(h);
28960+ istat = h->access->intr_pending(h);
28961 /* Is this interrupt for us? */
28962 if (istat == 0)
28963 return IRQ_NONE;
28964@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28965 */
28966 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
28967 if (istat & FIFO_NOT_EMPTY) {
28968- while((a = h->access.command_completed(h))) {
28969+ while((a = h->access->command_completed(h))) {
28970 a1 = a; a &= ~3;
28971 if ((c = h->cmpQ) == NULL)
28972 {
28973@@ -1449,11 +1449,11 @@ static int sendcmd(
28974 /*
28975 * Disable interrupt
28976 */
28977- info_p->access.set_intr_mask(info_p, 0);
28978+ info_p->access->set_intr_mask(info_p, 0);
28979 /* Make sure there is room in the command FIFO */
28980 /* Actually it should be completely empty at this time. */
28981 for (i = 200000; i > 0; i--) {
28982- temp = info_p->access.fifo_full(info_p);
28983+ temp = info_p->access->fifo_full(info_p);
28984 if (temp != 0) {
28985 break;
28986 }
28987@@ -1466,7 +1466,7 @@ DBG(
28988 /*
28989 * Send the cmd
28990 */
28991- info_p->access.submit_command(info_p, c);
28992+ info_p->access->submit_command(info_p, c);
28993 complete = pollcomplete(ctlr);
28994
28995 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
28996@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
28997 * we check the new geometry. Then turn interrupts back on when
28998 * we're done.
28999 */
29000- host->access.set_intr_mask(host, 0);
29001+ host->access->set_intr_mask(host, 0);
29002 getgeometry(ctlr);
29003- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29004+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29005
29006 for(i=0; i<NWD; i++) {
29007 struct gendisk *disk = ida_gendisk[ctlr][i];
29008@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29009 /* Wait (up to 2 seconds) for a command to complete */
29010
29011 for (i = 200000; i > 0; i--) {
29012- done = hba[ctlr]->access.command_completed(hba[ctlr]);
29013+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
29014 if (done == 0) {
29015 udelay(10); /* a short fixed delay */
29016 } else
29017diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29018index be73e9d..7fbf140 100644
29019--- a/drivers/block/cpqarray.h
29020+++ b/drivers/block/cpqarray.h
29021@@ -99,7 +99,7 @@ struct ctlr_info {
29022 drv_info_t drv[NWD];
29023 struct proc_dir_entry *proc;
29024
29025- struct access_method access;
29026+ struct access_method *access;
29027
29028 cmdlist_t *reqQ;
29029 cmdlist_t *cmpQ;
29030diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29031index 8d68056..e67050f 100644
29032--- a/drivers/block/drbd/drbd_int.h
29033+++ b/drivers/block/drbd/drbd_int.h
29034@@ -736,7 +736,7 @@ struct drbd_request;
29035 struct drbd_epoch {
29036 struct list_head list;
29037 unsigned int barrier_nr;
29038- atomic_t epoch_size; /* increased on every request added. */
29039+ atomic_unchecked_t epoch_size; /* increased on every request added. */
29040 atomic_t active; /* increased on every req. added, and dec on every finished. */
29041 unsigned long flags;
29042 };
29043@@ -1108,7 +1108,7 @@ struct drbd_conf {
29044 void *int_dig_in;
29045 void *int_dig_vv;
29046 wait_queue_head_t seq_wait;
29047- atomic_t packet_seq;
29048+ atomic_unchecked_t packet_seq;
29049 unsigned int peer_seq;
29050 spinlock_t peer_seq_lock;
29051 unsigned int minor;
29052@@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29053
29054 static inline void drbd_tcp_cork(struct socket *sock)
29055 {
29056- int __user val = 1;
29057+ int val = 1;
29058 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29059- (char __user *)&val, sizeof(val));
29060+ (char __force_user *)&val, sizeof(val));
29061 }
29062
29063 static inline void drbd_tcp_uncork(struct socket *sock)
29064 {
29065- int __user val = 0;
29066+ int val = 0;
29067 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29068- (char __user *)&val, sizeof(val));
29069+ (char __force_user *)&val, sizeof(val));
29070 }
29071
29072 static inline void drbd_tcp_nodelay(struct socket *sock)
29073 {
29074- int __user val = 1;
29075+ int val = 1;
29076 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29077- (char __user *)&val, sizeof(val));
29078+ (char __force_user *)&val, sizeof(val));
29079 }
29080
29081 static inline void drbd_tcp_quickack(struct socket *sock)
29082 {
29083- int __user val = 2;
29084+ int val = 2;
29085 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29086- (char __user *)&val, sizeof(val));
29087+ (char __force_user *)&val, sizeof(val));
29088 }
29089
29090 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29091diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29092index 211fc44..c5116f1 100644
29093--- a/drivers/block/drbd/drbd_main.c
29094+++ b/drivers/block/drbd/drbd_main.c
29095@@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29096 p.sector = sector;
29097 p.block_id = block_id;
29098 p.blksize = blksize;
29099- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29100+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29101
29102 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29103 return false;
29104@@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29105 p.sector = cpu_to_be64(req->sector);
29106 p.block_id = (unsigned long)req;
29107 p.seq_num = cpu_to_be32(req->seq_num =
29108- atomic_add_return(1, &mdev->packet_seq));
29109+ atomic_add_return_unchecked(1, &mdev->packet_seq));
29110
29111 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29112
29113@@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29114 atomic_set(&mdev->unacked_cnt, 0);
29115 atomic_set(&mdev->local_cnt, 0);
29116 atomic_set(&mdev->net_cnt, 0);
29117- atomic_set(&mdev->packet_seq, 0);
29118+ atomic_set_unchecked(&mdev->packet_seq, 0);
29119 atomic_set(&mdev->pp_in_use, 0);
29120 atomic_set(&mdev->pp_in_use_by_net, 0);
29121 atomic_set(&mdev->rs_sect_in, 0);
29122@@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29123 mdev->receiver.t_state);
29124
29125 /* no need to lock it, I'm the only thread alive */
29126- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29127- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29128+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29129+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29130 mdev->al_writ_cnt =
29131 mdev->bm_writ_cnt =
29132 mdev->read_cnt =
29133diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29134index af2a250..0fdeb75 100644
29135--- a/drivers/block/drbd/drbd_nl.c
29136+++ b/drivers/block/drbd/drbd_nl.c
29137@@ -2297,7 +2297,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29138 return;
29139 }
29140
29141- if (!cap_raised(current_cap(), CAP_SYS_ADMIN)) {
29142+ if (!capable(CAP_SYS_ADMIN)) {
29143 retcode = ERR_PERM;
29144 goto fail;
29145 }
29146@@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29147 module_put(THIS_MODULE);
29148 }
29149
29150-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29151+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29152
29153 static unsigned short *
29154 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29155@@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29156 cn_reply->id.idx = CN_IDX_DRBD;
29157 cn_reply->id.val = CN_VAL_DRBD;
29158
29159- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29160+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29161 cn_reply->ack = 0; /* not used here. */
29162 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29163 (int)((char *)tl - (char *)reply->tag_list);
29164@@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29165 cn_reply->id.idx = CN_IDX_DRBD;
29166 cn_reply->id.val = CN_VAL_DRBD;
29167
29168- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29169+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29170 cn_reply->ack = 0; /* not used here. */
29171 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29172 (int)((char *)tl - (char *)reply->tag_list);
29173@@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29174 cn_reply->id.idx = CN_IDX_DRBD;
29175 cn_reply->id.val = CN_VAL_DRBD;
29176
29177- cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29178+ cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29179 cn_reply->ack = 0; // not used here.
29180 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29181 (int)((char*)tl - (char*)reply->tag_list);
29182@@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29183 cn_reply->id.idx = CN_IDX_DRBD;
29184 cn_reply->id.val = CN_VAL_DRBD;
29185
29186- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29187+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29188 cn_reply->ack = 0; /* not used here. */
29189 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29190 (int)((char *)tl - (char *)reply->tag_list);
29191diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29192index 43beaca..4a5b1dd 100644
29193--- a/drivers/block/drbd/drbd_receiver.c
29194+++ b/drivers/block/drbd/drbd_receiver.c
29195@@ -894,7 +894,7 @@ retry:
29196 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29197 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29198
29199- atomic_set(&mdev->packet_seq, 0);
29200+ atomic_set_unchecked(&mdev->packet_seq, 0);
29201 mdev->peer_seq = 0;
29202
29203 drbd_thread_start(&mdev->asender);
29204@@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29205 do {
29206 next_epoch = NULL;
29207
29208- epoch_size = atomic_read(&epoch->epoch_size);
29209+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29210
29211 switch (ev & ~EV_CLEANUP) {
29212 case EV_PUT:
29213@@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29214 rv = FE_DESTROYED;
29215 } else {
29216 epoch->flags = 0;
29217- atomic_set(&epoch->epoch_size, 0);
29218+ atomic_set_unchecked(&epoch->epoch_size, 0);
29219 /* atomic_set(&epoch->active, 0); is already zero */
29220 if (rv == FE_STILL_LIVE)
29221 rv = FE_RECYCLED;
29222@@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29223 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29224 drbd_flush(mdev);
29225
29226- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29227+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29228 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29229 if (epoch)
29230 break;
29231 }
29232
29233 epoch = mdev->current_epoch;
29234- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29235+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29236
29237 D_ASSERT(atomic_read(&epoch->active) == 0);
29238 D_ASSERT(epoch->flags == 0);
29239@@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29240 }
29241
29242 epoch->flags = 0;
29243- atomic_set(&epoch->epoch_size, 0);
29244+ atomic_set_unchecked(&epoch->epoch_size, 0);
29245 atomic_set(&epoch->active, 0);
29246
29247 spin_lock(&mdev->epoch_lock);
29248- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29249+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29250 list_add(&epoch->list, &mdev->current_epoch->list);
29251 mdev->current_epoch = epoch;
29252 mdev->epochs++;
29253@@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29254 spin_unlock(&mdev->peer_seq_lock);
29255
29256 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29257- atomic_inc(&mdev->current_epoch->epoch_size);
29258+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29259 return drbd_drain_block(mdev, data_size);
29260 }
29261
29262@@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29263
29264 spin_lock(&mdev->epoch_lock);
29265 e->epoch = mdev->current_epoch;
29266- atomic_inc(&e->epoch->epoch_size);
29267+ atomic_inc_unchecked(&e->epoch->epoch_size);
29268 atomic_inc(&e->epoch->active);
29269 spin_unlock(&mdev->epoch_lock);
29270
29271@@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29272 D_ASSERT(list_empty(&mdev->done_ee));
29273
29274 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29275- atomic_set(&mdev->current_epoch->epoch_size, 0);
29276+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29277 D_ASSERT(list_empty(&mdev->current_epoch->list));
29278 }
29279
29280diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29281index cd50435..ba1ffb5 100644
29282--- a/drivers/block/loop.c
29283+++ b/drivers/block/loop.c
29284@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29285 mm_segment_t old_fs = get_fs();
29286
29287 set_fs(get_ds());
29288- bw = file->f_op->write(file, buf, len, &pos);
29289+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29290 set_fs(old_fs);
29291 if (likely(bw == len))
29292 return 0;
29293diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29294index 4364303..9adf4ee 100644
29295--- a/drivers/char/Kconfig
29296+++ b/drivers/char/Kconfig
29297@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29298
29299 config DEVKMEM
29300 bool "/dev/kmem virtual device support"
29301- default y
29302+ default n
29303+ depends on !GRKERNSEC_KMEM
29304 help
29305 Say Y here if you want to support the /dev/kmem device. The
29306 /dev/kmem device is rarely used, but can be used for certain
29307@@ -596,6 +597,7 @@ config DEVPORT
29308 bool
29309 depends on !M68K
29310 depends on ISA || PCI
29311+ depends on !GRKERNSEC_KMEM
29312 default y
29313
29314 source "drivers/s390/char/Kconfig"
29315diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29316index 2e04433..22afc64 100644
29317--- a/drivers/char/agp/frontend.c
29318+++ b/drivers/char/agp/frontend.c
29319@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29320 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29321 return -EFAULT;
29322
29323- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29324+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29325 return -EFAULT;
29326
29327 client = agp_find_client_by_pid(reserve.pid);
29328diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
29329index 095ab90..afad0a4 100644
29330--- a/drivers/char/briq_panel.c
29331+++ b/drivers/char/briq_panel.c
29332@@ -9,6 +9,7 @@
29333 #include <linux/types.h>
29334 #include <linux/errno.h>
29335 #include <linux/tty.h>
29336+#include <linux/mutex.h>
29337 #include <linux/timer.h>
29338 #include <linux/kernel.h>
29339 #include <linux/wait.h>
29340@@ -34,6 +35,7 @@ static int vfd_is_open;
29341 static unsigned char vfd[40];
29342 static int vfd_cursor;
29343 static unsigned char ledpb, led;
29344+static DEFINE_MUTEX(vfd_mutex);
29345
29346 static void update_vfd(void)
29347 {
29348@@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
29349 if (!vfd_is_open)
29350 return -EBUSY;
29351
29352+ mutex_lock(&vfd_mutex);
29353 for (;;) {
29354 char c;
29355 if (!indx)
29356 break;
29357- if (get_user(c, buf))
29358+ if (get_user(c, buf)) {
29359+ mutex_unlock(&vfd_mutex);
29360 return -EFAULT;
29361+ }
29362 if (esc) {
29363 set_led(c);
29364 esc = 0;
29365@@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
29366 buf++;
29367 }
29368 update_vfd();
29369+ mutex_unlock(&vfd_mutex);
29370
29371 return len;
29372 }
29373diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29374index f773a9d..65cd683 100644
29375--- a/drivers/char/genrtc.c
29376+++ b/drivers/char/genrtc.c
29377@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
29378 switch (cmd) {
29379
29380 case RTC_PLL_GET:
29381+ memset(&pll, 0, sizeof(pll));
29382 if (get_rtc_pll(&pll))
29383 return -EINVAL;
29384 else
29385diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29386index 0833896..cccce52 100644
29387--- a/drivers/char/hpet.c
29388+++ b/drivers/char/hpet.c
29389@@ -572,7 +572,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29390 }
29391
29392 static int
29393-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29394+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29395 struct hpet_info *info)
29396 {
29397 struct hpet_timer __iomem *timer;
29398diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29399index 58c0e63..46c16bf 100644
29400--- a/drivers/char/ipmi/ipmi_msghandler.c
29401+++ b/drivers/char/ipmi/ipmi_msghandler.c
29402@@ -415,7 +415,7 @@ struct ipmi_smi {
29403 struct proc_dir_entry *proc_dir;
29404 char proc_dir_name[10];
29405
29406- atomic_t stats[IPMI_NUM_STATS];
29407+ atomic_unchecked_t stats[IPMI_NUM_STATS];
29408
29409 /*
29410 * run_to_completion duplicate of smb_info, smi_info
29411@@ -448,9 +448,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29412
29413
29414 #define ipmi_inc_stat(intf, stat) \
29415- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29416+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29417 #define ipmi_get_stat(intf, stat) \
29418- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29419+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29420
29421 static int is_lan_addr(struct ipmi_addr *addr)
29422 {
29423@@ -2868,7 +2868,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29424 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29425 init_waitqueue_head(&intf->waitq);
29426 for (i = 0; i < IPMI_NUM_STATS; i++)
29427- atomic_set(&intf->stats[i], 0);
29428+ atomic_set_unchecked(&intf->stats[i], 0);
29429
29430 intf->proc_dir = NULL;
29431
29432diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29433index 50fcf9c..91b5528 100644
29434--- a/drivers/char/ipmi/ipmi_si_intf.c
29435+++ b/drivers/char/ipmi/ipmi_si_intf.c
29436@@ -277,7 +277,7 @@ struct smi_info {
29437 unsigned char slave_addr;
29438
29439 /* Counters and things for the proc filesystem. */
29440- atomic_t stats[SI_NUM_STATS];
29441+ atomic_unchecked_t stats[SI_NUM_STATS];
29442
29443 struct task_struct *thread;
29444
29445@@ -286,9 +286,9 @@ struct smi_info {
29446 };
29447
29448 #define smi_inc_stat(smi, stat) \
29449- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29450+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29451 #define smi_get_stat(smi, stat) \
29452- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29453+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29454
29455 #define SI_MAX_PARMS 4
29456
29457@@ -3230,7 +3230,7 @@ static int try_smi_init(struct smi_info *new_smi)
29458 atomic_set(&new_smi->req_events, 0);
29459 new_smi->run_to_completion = 0;
29460 for (i = 0; i < SI_NUM_STATS; i++)
29461- atomic_set(&new_smi->stats[i], 0);
29462+ atomic_set_unchecked(&new_smi->stats[i], 0);
29463
29464 new_smi->interrupt_disabled = 1;
29465 atomic_set(&new_smi->stop_operation, 0);
29466diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29467index 1aeaaba..e018570 100644
29468--- a/drivers/char/mbcs.c
29469+++ b/drivers/char/mbcs.c
29470@@ -800,7 +800,7 @@ static int mbcs_remove(struct cx_dev *dev)
29471 return 0;
29472 }
29473
29474-static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29475+static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29476 {
29477 .part_num = MBCS_PART_NUM,
29478 .mfg_num = MBCS_MFG_NUM,
29479diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29480index d6e9d08..4493e89 100644
29481--- a/drivers/char/mem.c
29482+++ b/drivers/char/mem.c
29483@@ -18,6 +18,7 @@
29484 #include <linux/raw.h>
29485 #include <linux/tty.h>
29486 #include <linux/capability.h>
29487+#include <linux/security.h>
29488 #include <linux/ptrace.h>
29489 #include <linux/device.h>
29490 #include <linux/highmem.h>
29491@@ -35,6 +36,10 @@
29492 # include <linux/efi.h>
29493 #endif
29494
29495+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29496+extern const struct file_operations grsec_fops;
29497+#endif
29498+
29499 static inline unsigned long size_inside_page(unsigned long start,
29500 unsigned long size)
29501 {
29502@@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29503
29504 while (cursor < to) {
29505 if (!devmem_is_allowed(pfn)) {
29506+#ifdef CONFIG_GRKERNSEC_KMEM
29507+ gr_handle_mem_readwrite(from, to);
29508+#else
29509 printk(KERN_INFO
29510 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29511 current->comm, from, to);
29512+#endif
29513 return 0;
29514 }
29515 cursor += PAGE_SIZE;
29516@@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29517 }
29518 return 1;
29519 }
29520+#elif defined(CONFIG_GRKERNSEC_KMEM)
29521+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29522+{
29523+ return 0;
29524+}
29525 #else
29526 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29527 {
29528@@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29529
29530 while (count > 0) {
29531 unsigned long remaining;
29532+ char *temp;
29533
29534 sz = size_inside_page(p, count);
29535
29536@@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29537 if (!ptr)
29538 return -EFAULT;
29539
29540- remaining = copy_to_user(buf, ptr, sz);
29541+#ifdef CONFIG_PAX_USERCOPY
29542+ temp = kmalloc(sz, GFP_KERNEL);
29543+ if (!temp) {
29544+ unxlate_dev_mem_ptr(p, ptr);
29545+ return -ENOMEM;
29546+ }
29547+ memcpy(temp, ptr, sz);
29548+#else
29549+ temp = ptr;
29550+#endif
29551+
29552+ remaining = copy_to_user(buf, temp, sz);
29553+
29554+#ifdef CONFIG_PAX_USERCOPY
29555+ kfree(temp);
29556+#endif
29557+
29558 unxlate_dev_mem_ptr(p, ptr);
29559 if (remaining)
29560 return -EFAULT;
29561@@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29562 size_t count, loff_t *ppos)
29563 {
29564 unsigned long p = *ppos;
29565- ssize_t low_count, read, sz;
29566+ ssize_t low_count, read, sz, err = 0;
29567 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29568- int err = 0;
29569
29570 read = 0;
29571 if (p < (unsigned long) high_memory) {
29572@@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29573 }
29574 #endif
29575 while (low_count > 0) {
29576+ char *temp;
29577+
29578 sz = size_inside_page(p, low_count);
29579
29580 /*
29581@@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29582 */
29583 kbuf = xlate_dev_kmem_ptr((char *)p);
29584
29585- if (copy_to_user(buf, kbuf, sz))
29586+#ifdef CONFIG_PAX_USERCOPY
29587+ temp = kmalloc(sz, GFP_KERNEL);
29588+ if (!temp)
29589+ return -ENOMEM;
29590+ memcpy(temp, kbuf, sz);
29591+#else
29592+ temp = kbuf;
29593+#endif
29594+
29595+ err = copy_to_user(buf, temp, sz);
29596+
29597+#ifdef CONFIG_PAX_USERCOPY
29598+ kfree(temp);
29599+#endif
29600+
29601+ if (err)
29602 return -EFAULT;
29603 buf += sz;
29604 p += sz;
29605@@ -867,6 +914,9 @@ static const struct memdev {
29606 #ifdef CONFIG_CRASH_DUMP
29607 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29608 #endif
29609+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29610+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29611+#endif
29612 };
29613
29614 static int memory_open(struct inode *inode, struct file *filp)
29615diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29616index da3cfee..a5a6606 100644
29617--- a/drivers/char/nvram.c
29618+++ b/drivers/char/nvram.c
29619@@ -248,7 +248,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29620
29621 spin_unlock_irq(&rtc_lock);
29622
29623- if (copy_to_user(buf, contents, tmp - contents))
29624+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29625 return -EFAULT;
29626
29627 *ppos = i;
29628diff --git a/drivers/char/random.c b/drivers/char/random.c
29629index 54ca8b2..4a092ed 100644
29630--- a/drivers/char/random.c
29631+++ b/drivers/char/random.c
29632@@ -261,8 +261,13 @@
29633 /*
29634 * Configuration information
29635 */
29636+#ifdef CONFIG_GRKERNSEC_RANDNET
29637+#define INPUT_POOL_WORDS 512
29638+#define OUTPUT_POOL_WORDS 128
29639+#else
29640 #define INPUT_POOL_WORDS 128
29641 #define OUTPUT_POOL_WORDS 32
29642+#endif
29643 #define SEC_XFER_SIZE 512
29644 #define EXTRACT_SIZE 10
29645
29646@@ -300,10 +305,17 @@ static struct poolinfo {
29647 int poolwords;
29648 int tap1, tap2, tap3, tap4, tap5;
29649 } poolinfo_table[] = {
29650+#ifdef CONFIG_GRKERNSEC_RANDNET
29651+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29652+ { 512, 411, 308, 208, 104, 1 },
29653+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29654+ { 128, 103, 76, 51, 25, 1 },
29655+#else
29656 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29657 { 128, 103, 76, 51, 25, 1 },
29658 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29659 { 32, 26, 20, 14, 7, 1 },
29660+#endif
29661 #if 0
29662 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29663 { 2048, 1638, 1231, 819, 411, 1 },
29664@@ -913,7 +925,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29665
29666 extract_buf(r, tmp);
29667 i = min_t(int, nbytes, EXTRACT_SIZE);
29668- if (copy_to_user(buf, tmp, i)) {
29669+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29670 ret = -EFAULT;
29671 break;
29672 }
29673@@ -1238,7 +1250,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29674 #include <linux/sysctl.h>
29675
29676 static int min_read_thresh = 8, min_write_thresh;
29677-static int max_read_thresh = INPUT_POOL_WORDS * 32;
29678+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29679 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29680 static char sysctl_bootid[16];
29681
29682@@ -1260,10 +1272,15 @@ static int proc_do_uuid(ctl_table *table, int write,
29683 uuid = table->data;
29684 if (!uuid) {
29685 uuid = tmp_uuid;
29686- uuid[8] = 0;
29687- }
29688- if (uuid[8] == 0)
29689 generate_random_uuid(uuid);
29690+ } else {
29691+ static DEFINE_SPINLOCK(bootid_spinlock);
29692+
29693+ spin_lock(&bootid_spinlock);
29694+ if (!uuid[8])
29695+ generate_random_uuid(uuid);
29696+ spin_unlock(&bootid_spinlock);
29697+ }
29698
29699 sprintf(buf, "%pU", uuid);
29700
29701diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29702index 1ee8ce7..b778bef 100644
29703--- a/drivers/char/sonypi.c
29704+++ b/drivers/char/sonypi.c
29705@@ -55,6 +55,7 @@
29706 #include <asm/uaccess.h>
29707 #include <asm/io.h>
29708 #include <asm/system.h>
29709+#include <asm/local.h>
29710
29711 #include <linux/sonypi.h>
29712
29713@@ -491,7 +492,7 @@ static struct sonypi_device {
29714 spinlock_t fifo_lock;
29715 wait_queue_head_t fifo_proc_list;
29716 struct fasync_struct *fifo_async;
29717- int open_count;
29718+ local_t open_count;
29719 int model;
29720 struct input_dev *input_jog_dev;
29721 struct input_dev *input_key_dev;
29722@@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29723 static int sonypi_misc_release(struct inode *inode, struct file *file)
29724 {
29725 mutex_lock(&sonypi_device.lock);
29726- sonypi_device.open_count--;
29727+ local_dec(&sonypi_device.open_count);
29728 mutex_unlock(&sonypi_device.lock);
29729 return 0;
29730 }
29731@@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29732 {
29733 mutex_lock(&sonypi_device.lock);
29734 /* Flush input queue on first open */
29735- if (!sonypi_device.open_count)
29736+ if (!local_read(&sonypi_device.open_count))
29737 kfifo_reset(&sonypi_device.fifo);
29738- sonypi_device.open_count++;
29739+ local_inc(&sonypi_device.open_count);
29740 mutex_unlock(&sonypi_device.lock);
29741
29742 return 0;
29743diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29744index ad7c732..5aa8054 100644
29745--- a/drivers/char/tpm/tpm.c
29746+++ b/drivers/char/tpm/tpm.c
29747@@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29748 chip->vendor.req_complete_val)
29749 goto out_recv;
29750
29751- if ((status == chip->vendor.req_canceled)) {
29752+ if (status == chip->vendor.req_canceled) {
29753 dev_err(chip->dev, "Operation Canceled\n");
29754 rc = -ECANCELED;
29755 goto out;
29756diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29757index 0636520..169c1d0 100644
29758--- a/drivers/char/tpm/tpm_bios.c
29759+++ b/drivers/char/tpm/tpm_bios.c
29760@@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29761 event = addr;
29762
29763 if ((event->event_type == 0 && event->event_size == 0) ||
29764- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29765+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29766 return NULL;
29767
29768 return addr;
29769@@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29770 return NULL;
29771
29772 if ((event->event_type == 0 && event->event_size == 0) ||
29773- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29774+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29775 return NULL;
29776
29777 (*pos)++;
29778@@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29779 int i;
29780
29781 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29782- seq_putc(m, data[i]);
29783+ if (!seq_putc(m, data[i]))
29784+ return -EFAULT;
29785
29786 return 0;
29787 }
29788@@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29789 log->bios_event_log_end = log->bios_event_log + len;
29790
29791 virt = acpi_os_map_memory(start, len);
29792+ if (!virt) {
29793+ kfree(log->bios_event_log);
29794+ log->bios_event_log = NULL;
29795+ return -EFAULT;
29796+ }
29797
29798- memcpy(log->bios_event_log, virt, len);
29799+ memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29800
29801 acpi_os_unmap_memory(virt, len);
29802 return 0;
29803diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29804index 41fc148..0dba6dd 100644
29805--- a/drivers/char/virtio_console.c
29806+++ b/drivers/char/virtio_console.c
29807@@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29808 if (to_user) {
29809 ssize_t ret;
29810
29811- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29812+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29813 if (ret)
29814 return -EFAULT;
29815 } else {
29816@@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29817 if (!port_has_data(port) && !port->host_connected)
29818 return 0;
29819
29820- return fill_readbuf(port, ubuf, count, true);
29821+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29822 }
29823
29824 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29825diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
29826index c9eee6d..f9d5280 100644
29827--- a/drivers/edac/amd64_edac.c
29828+++ b/drivers/edac/amd64_edac.c
29829@@ -2685,7 +2685,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
29830 * PCI core identifies what devices are on a system during boot, and then
29831 * inquiry this table to see if this driver is for a given device found.
29832 */
29833-static const struct pci_device_id amd64_pci_table[] __devinitdata = {
29834+static const struct pci_device_id amd64_pci_table[] __devinitconst = {
29835 {
29836 .vendor = PCI_VENDOR_ID_AMD,
29837 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
29838diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
29839index e47e73b..348e0bd 100644
29840--- a/drivers/edac/amd76x_edac.c
29841+++ b/drivers/edac/amd76x_edac.c
29842@@ -321,7 +321,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
29843 edac_mc_free(mci);
29844 }
29845
29846-static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
29847+static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
29848 {
29849 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29850 AMD762},
29851diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
29852index 1af531a..3a8ff27 100644
29853--- a/drivers/edac/e752x_edac.c
29854+++ b/drivers/edac/e752x_edac.c
29855@@ -1380,7 +1380,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
29856 edac_mc_free(mci);
29857 }
29858
29859-static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
29860+static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
29861 {
29862 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29863 E7520},
29864diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
29865index 6ffb6d2..383d8d7 100644
29866--- a/drivers/edac/e7xxx_edac.c
29867+++ b/drivers/edac/e7xxx_edac.c
29868@@ -525,7 +525,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
29869 edac_mc_free(mci);
29870 }
29871
29872-static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
29873+static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
29874 {
29875 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29876 E7205},
29877diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29878index 97f5064..202b6e6 100644
29879--- a/drivers/edac/edac_pci_sysfs.c
29880+++ b/drivers/edac/edac_pci_sysfs.c
29881@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29882 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29883 static int edac_pci_poll_msec = 1000; /* one second workq period */
29884
29885-static atomic_t pci_parity_count = ATOMIC_INIT(0);
29886-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29887+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29888+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29889
29890 static struct kobject *edac_pci_top_main_kobj;
29891 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29892@@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29893 edac_printk(KERN_CRIT, EDAC_PCI,
29894 "Signaled System Error on %s\n",
29895 pci_name(dev));
29896- atomic_inc(&pci_nonparity_count);
29897+ atomic_inc_unchecked(&pci_nonparity_count);
29898 }
29899
29900 if (status & (PCI_STATUS_PARITY)) {
29901@@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29902 "Master Data Parity Error on %s\n",
29903 pci_name(dev));
29904
29905- atomic_inc(&pci_parity_count);
29906+ atomic_inc_unchecked(&pci_parity_count);
29907 }
29908
29909 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29910@@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29911 "Detected Parity Error on %s\n",
29912 pci_name(dev));
29913
29914- atomic_inc(&pci_parity_count);
29915+ atomic_inc_unchecked(&pci_parity_count);
29916 }
29917 }
29918
29919@@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29920 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29921 "Signaled System Error on %s\n",
29922 pci_name(dev));
29923- atomic_inc(&pci_nonparity_count);
29924+ atomic_inc_unchecked(&pci_nonparity_count);
29925 }
29926
29927 if (status & (PCI_STATUS_PARITY)) {
29928@@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29929 "Master Data Parity Error on "
29930 "%s\n", pci_name(dev));
29931
29932- atomic_inc(&pci_parity_count);
29933+ atomic_inc_unchecked(&pci_parity_count);
29934 }
29935
29936 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29937@@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29938 "Detected Parity Error on %s\n",
29939 pci_name(dev));
29940
29941- atomic_inc(&pci_parity_count);
29942+ atomic_inc_unchecked(&pci_parity_count);
29943 }
29944 }
29945 }
29946@@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29947 if (!check_pci_errors)
29948 return;
29949
29950- before_count = atomic_read(&pci_parity_count);
29951+ before_count = atomic_read_unchecked(&pci_parity_count);
29952
29953 /* scan all PCI devices looking for a Parity Error on devices and
29954 * bridges.
29955@@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29956 /* Only if operator has selected panic on PCI Error */
29957 if (edac_pci_get_panic_on_pe()) {
29958 /* If the count is different 'after' from 'before' */
29959- if (before_count != atomic_read(&pci_parity_count))
29960+ if (before_count != atomic_read_unchecked(&pci_parity_count))
29961 panic("EDAC: PCI Parity Error");
29962 }
29963 }
29964diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
29965index c0510b3..6e2a954 100644
29966--- a/drivers/edac/i3000_edac.c
29967+++ b/drivers/edac/i3000_edac.c
29968@@ -470,7 +470,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
29969 edac_mc_free(mci);
29970 }
29971
29972-static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
29973+static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
29974 {
29975 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29976 I3000},
29977diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
29978index 73f55e200..5faaf59 100644
29979--- a/drivers/edac/i3200_edac.c
29980+++ b/drivers/edac/i3200_edac.c
29981@@ -445,7 +445,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
29982 edac_mc_free(mci);
29983 }
29984
29985-static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
29986+static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
29987 {
29988 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29989 I3200},
29990diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
29991index 4dc3ac2..67d05a6 100644
29992--- a/drivers/edac/i5000_edac.c
29993+++ b/drivers/edac/i5000_edac.c
29994@@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
29995 *
29996 * The "E500P" device is the first device supported.
29997 */
29998-static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
29999+static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
30000 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
30001 .driver_data = I5000P},
30002
30003diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
30004index bcbdeec..9886d16 100644
30005--- a/drivers/edac/i5100_edac.c
30006+++ b/drivers/edac/i5100_edac.c
30007@@ -1051,7 +1051,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
30008 edac_mc_free(mci);
30009 }
30010
30011-static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
30012+static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
30013 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
30014 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
30015 { 0, }
30016diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
30017index 74d6ec34..baff517 100644
30018--- a/drivers/edac/i5400_edac.c
30019+++ b/drivers/edac/i5400_edac.c
30020@@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
30021 *
30022 * The "E500P" device is the first device supported.
30023 */
30024-static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
30025+static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
30026 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
30027 {0,} /* 0 terminated list. */
30028 };
30029diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
30030index 6104dba..e7ea8e1 100644
30031--- a/drivers/edac/i7300_edac.c
30032+++ b/drivers/edac/i7300_edac.c
30033@@ -1192,7 +1192,7 @@ static void __devexit i7300_remove_one(struct pci_dev *pdev)
30034 *
30035 * Has only 8086:360c PCI ID
30036 */
30037-static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
30038+static const struct pci_device_id i7300_pci_tbl[] __devinitconst = {
30039 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
30040 {0,} /* 0 terminated list. */
30041 };
30042diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
30043index 8568d9b..42b2fa8 100644
30044--- a/drivers/edac/i7core_edac.c
30045+++ b/drivers/edac/i7core_edac.c
30046@@ -391,7 +391,7 @@ static const struct pci_id_table pci_dev_table[] = {
30047 /*
30048 * pci_device_id table for which devices we are looking for
30049 */
30050-static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
30051+static const struct pci_device_id i7core_pci_tbl[] __devinitconst = {
30052 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
30053 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)},
30054 {0,} /* 0 terminated list. */
30055diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
30056index 4329d39..f3022ef 100644
30057--- a/drivers/edac/i82443bxgx_edac.c
30058+++ b/drivers/edac/i82443bxgx_edac.c
30059@@ -380,7 +380,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
30060
30061 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
30062
30063-static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
30064+static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
30065 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
30066 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
30067 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
30068diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
30069index 931a057..fd28340 100644
30070--- a/drivers/edac/i82860_edac.c
30071+++ b/drivers/edac/i82860_edac.c
30072@@ -270,7 +270,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
30073 edac_mc_free(mci);
30074 }
30075
30076-static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
30077+static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
30078 {
30079 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30080 I82860},
30081diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
30082index 33864c6..01edc61 100644
30083--- a/drivers/edac/i82875p_edac.c
30084+++ b/drivers/edac/i82875p_edac.c
30085@@ -511,7 +511,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
30086 edac_mc_free(mci);
30087 }
30088
30089-static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
30090+static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
30091 {
30092 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30093 I82875P},
30094diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
30095index 4184e01..dcb2cd3 100644
30096--- a/drivers/edac/i82975x_edac.c
30097+++ b/drivers/edac/i82975x_edac.c
30098@@ -612,7 +612,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
30099 edac_mc_free(mci);
30100 }
30101
30102-static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
30103+static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
30104 {
30105 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30106 I82975X
30107diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30108index 0106747..0b40417 100644
30109--- a/drivers/edac/mce_amd.h
30110+++ b/drivers/edac/mce_amd.h
30111@@ -83,7 +83,7 @@ struct amd_decoder_ops {
30112 bool (*dc_mce)(u16, u8);
30113 bool (*ic_mce)(u16, u8);
30114 bool (*nb_mce)(u16, u8);
30115-};
30116+} __no_const;
30117
30118 void amd_report_gart_errors(bool);
30119 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30120diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
30121index e294e1b..a41b05b 100644
30122--- a/drivers/edac/r82600_edac.c
30123+++ b/drivers/edac/r82600_edac.c
30124@@ -373,7 +373,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
30125 edac_mc_free(mci);
30126 }
30127
30128-static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
30129+static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
30130 {
30131 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
30132 },
30133diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
30134index 1dc118d..8c68af9 100644
30135--- a/drivers/edac/sb_edac.c
30136+++ b/drivers/edac/sb_edac.c
30137@@ -367,7 +367,7 @@ static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
30138 /*
30139 * pci_device_id table for which devices we are looking for
30140 */
30141-static const struct pci_device_id sbridge_pci_tbl[] __devinitdata = {
30142+static const struct pci_device_id sbridge_pci_tbl[] __devinitconst = {
30143 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)},
30144 {0,} /* 0 terminated list. */
30145 };
30146diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
30147index b6f47de..c5acf3a 100644
30148--- a/drivers/edac/x38_edac.c
30149+++ b/drivers/edac/x38_edac.c
30150@@ -440,7 +440,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
30151 edac_mc_free(mci);
30152 }
30153
30154-static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
30155+static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
30156 {
30157 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30158 X38},
30159diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30160index 85661b0..c784559a 100644
30161--- a/drivers/firewire/core-card.c
30162+++ b/drivers/firewire/core-card.c
30163@@ -657,7 +657,7 @@ void fw_card_release(struct kref *kref)
30164
30165 void fw_core_remove_card(struct fw_card *card)
30166 {
30167- struct fw_card_driver dummy_driver = dummy_driver_template;
30168+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
30169
30170 card->driver->update_phy_reg(card, 4,
30171 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30172diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30173index 4799393..37bd3ab 100644
30174--- a/drivers/firewire/core-cdev.c
30175+++ b/drivers/firewire/core-cdev.c
30176@@ -1331,8 +1331,7 @@ static int init_iso_resource(struct client *client,
30177 int ret;
30178
30179 if ((request->channels == 0 && request->bandwidth == 0) ||
30180- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30181- request->bandwidth < 0)
30182+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30183 return -EINVAL;
30184
30185 r = kmalloc(sizeof(*r), GFP_KERNEL);
30186diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30187index 855ab3f..11f4bbd 100644
30188--- a/drivers/firewire/core-transaction.c
30189+++ b/drivers/firewire/core-transaction.c
30190@@ -37,6 +37,7 @@
30191 #include <linux/timer.h>
30192 #include <linux/types.h>
30193 #include <linux/workqueue.h>
30194+#include <linux/sched.h>
30195
30196 #include <asm/byteorder.h>
30197
30198diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30199index b45be57..5fad18b 100644
30200--- a/drivers/firewire/core.h
30201+++ b/drivers/firewire/core.h
30202@@ -101,6 +101,7 @@ struct fw_card_driver {
30203
30204 int (*stop_iso)(struct fw_iso_context *ctx);
30205 };
30206+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30207
30208 void fw_card_initialize(struct fw_card *card,
30209 const struct fw_card_driver *driver, struct device *device);
30210diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30211index 153980b..4b4d046 100644
30212--- a/drivers/firmware/dmi_scan.c
30213+++ b/drivers/firmware/dmi_scan.c
30214@@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
30215 }
30216 }
30217 else {
30218- /*
30219- * no iounmap() for that ioremap(); it would be a no-op, but
30220- * it's so early in setup that sucker gets confused into doing
30221- * what it shouldn't if we actually call it.
30222- */
30223 p = dmi_ioremap(0xF0000, 0x10000);
30224 if (p == NULL)
30225 goto error;
30226@@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30227 if (buf == NULL)
30228 return -1;
30229
30230- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30231+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30232
30233 iounmap(buf);
30234 return 0;
30235diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30236index 82d5c20..44a7177 100644
30237--- a/drivers/gpio/gpio-vr41xx.c
30238+++ b/drivers/gpio/gpio-vr41xx.c
30239@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30240 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30241 maskl, pendl, maskh, pendh);
30242
30243- atomic_inc(&irq_err_count);
30244+ atomic_inc_unchecked(&irq_err_count);
30245
30246 return -EINVAL;
30247 }
30248diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30249index 84a4a80..ce0306e 100644
30250--- a/drivers/gpu/drm/drm_crtc_helper.c
30251+++ b/drivers/gpu/drm/drm_crtc_helper.c
30252@@ -280,7 +280,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30253 struct drm_crtc *tmp;
30254 int crtc_mask = 1;
30255
30256- WARN(!crtc, "checking null crtc?\n");
30257+ BUG_ON(!crtc);
30258
30259 dev = crtc->dev;
30260
30261diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30262index ebf7d3f..d64c436 100644
30263--- a/drivers/gpu/drm/drm_drv.c
30264+++ b/drivers/gpu/drm/drm_drv.c
30265@@ -312,7 +312,7 @@ module_exit(drm_core_exit);
30266 /**
30267 * Copy and IOCTL return string to user space
30268 */
30269-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30270+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30271 {
30272 int len;
30273
30274@@ -391,7 +391,7 @@ long drm_ioctl(struct file *filp,
30275
30276 dev = file_priv->minor->dev;
30277 atomic_inc(&dev->ioctl_count);
30278- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30279+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30280 ++file_priv->ioctl_count;
30281
30282 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30283diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30284index 6263b01..7987f55 100644
30285--- a/drivers/gpu/drm/drm_fops.c
30286+++ b/drivers/gpu/drm/drm_fops.c
30287@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30288 }
30289
30290 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30291- atomic_set(&dev->counts[i], 0);
30292+ atomic_set_unchecked(&dev->counts[i], 0);
30293
30294 dev->sigdata.lock = NULL;
30295
30296@@ -135,8 +135,8 @@ int drm_open(struct inode *inode, struct file *filp)
30297
30298 retcode = drm_open_helper(inode, filp, dev);
30299 if (!retcode) {
30300- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30301- if (!dev->open_count++)
30302+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30303+ if (local_inc_return(&dev->open_count) == 1)
30304 retcode = drm_setup(dev);
30305 }
30306 if (!retcode) {
30307@@ -473,7 +473,7 @@ int drm_release(struct inode *inode, struct file *filp)
30308
30309 mutex_lock(&drm_global_mutex);
30310
30311- DRM_DEBUG("open_count = %d\n", dev->open_count);
30312+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30313
30314 if (dev->driver->preclose)
30315 dev->driver->preclose(dev, file_priv);
30316@@ -482,10 +482,10 @@ int drm_release(struct inode *inode, struct file *filp)
30317 * Begin inline drm_release
30318 */
30319
30320- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30321+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30322 task_pid_nr(current),
30323 (long)old_encode_dev(file_priv->minor->device),
30324- dev->open_count);
30325+ local_read(&dev->open_count));
30326
30327 /* Release any auth tokens that might point to this file_priv,
30328 (do that under the drm_global_mutex) */
30329@@ -571,8 +571,8 @@ int drm_release(struct inode *inode, struct file *filp)
30330 * End inline drm_release
30331 */
30332
30333- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30334- if (!--dev->open_count) {
30335+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30336+ if (local_dec_and_test(&dev->open_count)) {
30337 if (atomic_read(&dev->ioctl_count)) {
30338 DRM_ERROR("Device busy: %d\n",
30339 atomic_read(&dev->ioctl_count));
30340diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30341index c87dc96..326055d 100644
30342--- a/drivers/gpu/drm/drm_global.c
30343+++ b/drivers/gpu/drm/drm_global.c
30344@@ -36,7 +36,7 @@
30345 struct drm_global_item {
30346 struct mutex mutex;
30347 void *object;
30348- int refcount;
30349+ atomic_t refcount;
30350 };
30351
30352 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30353@@ -49,7 +49,7 @@ void drm_global_init(void)
30354 struct drm_global_item *item = &glob[i];
30355 mutex_init(&item->mutex);
30356 item->object = NULL;
30357- item->refcount = 0;
30358+ atomic_set(&item->refcount, 0);
30359 }
30360 }
30361
30362@@ -59,7 +59,7 @@ void drm_global_release(void)
30363 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30364 struct drm_global_item *item = &glob[i];
30365 BUG_ON(item->object != NULL);
30366- BUG_ON(item->refcount != 0);
30367+ BUG_ON(atomic_read(&item->refcount) != 0);
30368 }
30369 }
30370
30371@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30372 void *object;
30373
30374 mutex_lock(&item->mutex);
30375- if (item->refcount == 0) {
30376+ if (atomic_read(&item->refcount) == 0) {
30377 item->object = kzalloc(ref->size, GFP_KERNEL);
30378 if (unlikely(item->object == NULL)) {
30379 ret = -ENOMEM;
30380@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30381 goto out_err;
30382
30383 }
30384- ++item->refcount;
30385+ atomic_inc(&item->refcount);
30386 ref->object = item->object;
30387 object = item->object;
30388 mutex_unlock(&item->mutex);
30389@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30390 struct drm_global_item *item = &glob[ref->global_type];
30391
30392 mutex_lock(&item->mutex);
30393- BUG_ON(item->refcount == 0);
30394+ BUG_ON(atomic_read(&item->refcount) == 0);
30395 BUG_ON(ref->object != item->object);
30396- if (--item->refcount == 0) {
30397+ if (atomic_dec_and_test(&item->refcount)) {
30398 ref->release(ref);
30399 item->object = NULL;
30400 }
30401diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30402index ab1162d..42587b2 100644
30403--- a/drivers/gpu/drm/drm_info.c
30404+++ b/drivers/gpu/drm/drm_info.c
30405@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30406 struct drm_local_map *map;
30407 struct drm_map_list *r_list;
30408
30409- /* Hardcoded from _DRM_FRAME_BUFFER,
30410- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30411- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30412- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30413+ static const char * const types[] = {
30414+ [_DRM_FRAME_BUFFER] = "FB",
30415+ [_DRM_REGISTERS] = "REG",
30416+ [_DRM_SHM] = "SHM",
30417+ [_DRM_AGP] = "AGP",
30418+ [_DRM_SCATTER_GATHER] = "SG",
30419+ [_DRM_CONSISTENT] = "PCI",
30420+ [_DRM_GEM] = "GEM" };
30421 const char *type;
30422 int i;
30423
30424@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30425 map = r_list->map;
30426 if (!map)
30427 continue;
30428- if (map->type < 0 || map->type > 5)
30429+ if (map->type >= ARRAY_SIZE(types))
30430 type = "??";
30431 else
30432 type = types[map->type];
30433@@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30434 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30435 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30436 vma->vm_flags & VM_IO ? 'i' : '-',
30437+#ifdef CONFIG_GRKERNSEC_HIDESYM
30438+ 0);
30439+#else
30440 vma->vm_pgoff);
30441+#endif
30442
30443 #if defined(__i386__)
30444 pgprot = pgprot_val(vma->vm_page_prot);
30445diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30446index 637fcc3..e890b33 100644
30447--- a/drivers/gpu/drm/drm_ioc32.c
30448+++ b/drivers/gpu/drm/drm_ioc32.c
30449@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30450 request = compat_alloc_user_space(nbytes);
30451 if (!access_ok(VERIFY_WRITE, request, nbytes))
30452 return -EFAULT;
30453- list = (struct drm_buf_desc *) (request + 1);
30454+ list = (struct drm_buf_desc __user *) (request + 1);
30455
30456 if (__put_user(count, &request->count)
30457 || __put_user(list, &request->list))
30458@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30459 request = compat_alloc_user_space(nbytes);
30460 if (!access_ok(VERIFY_WRITE, request, nbytes))
30461 return -EFAULT;
30462- list = (struct drm_buf_pub *) (request + 1);
30463+ list = (struct drm_buf_pub __user *) (request + 1);
30464
30465 if (__put_user(count, &request->count)
30466 || __put_user(list, &request->list))
30467diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30468index 956fd38..e52167a 100644
30469--- a/drivers/gpu/drm/drm_ioctl.c
30470+++ b/drivers/gpu/drm/drm_ioctl.c
30471@@ -251,7 +251,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30472 stats->data[i].value =
30473 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30474 else
30475- stats->data[i].value = atomic_read(&dev->counts[i]);
30476+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30477 stats->data[i].type = dev->types[i];
30478 }
30479
30480diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30481index c79c713..2048588 100644
30482--- a/drivers/gpu/drm/drm_lock.c
30483+++ b/drivers/gpu/drm/drm_lock.c
30484@@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30485 if (drm_lock_take(&master->lock, lock->context)) {
30486 master->lock.file_priv = file_priv;
30487 master->lock.lock_time = jiffies;
30488- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30489+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30490 break; /* Got lock */
30491 }
30492
30493@@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30494 return -EINVAL;
30495 }
30496
30497- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30498+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30499
30500 if (drm_lock_free(&master->lock, lock->context)) {
30501 /* FIXME: Should really bail out here. */
30502diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30503index 7f4b4e1..bf4def2 100644
30504--- a/drivers/gpu/drm/i810/i810_dma.c
30505+++ b/drivers/gpu/drm/i810/i810_dma.c
30506@@ -948,8 +948,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30507 dma->buflist[vertex->idx],
30508 vertex->discard, vertex->used);
30509
30510- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30511- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30512+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30513+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30514 sarea_priv->last_enqueue = dev_priv->counter - 1;
30515 sarea_priv->last_dispatch = (int)hw_status[5];
30516
30517@@ -1109,8 +1109,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30518 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30519 mc->last_render);
30520
30521- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30522- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30523+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30524+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30525 sarea_priv->last_enqueue = dev_priv->counter - 1;
30526 sarea_priv->last_dispatch = (int)hw_status[5];
30527
30528diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30529index c9339f4..f5e1b9d 100644
30530--- a/drivers/gpu/drm/i810/i810_drv.h
30531+++ b/drivers/gpu/drm/i810/i810_drv.h
30532@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30533 int page_flipping;
30534
30535 wait_queue_head_t irq_queue;
30536- atomic_t irq_received;
30537- atomic_t irq_emitted;
30538+ atomic_unchecked_t irq_received;
30539+ atomic_unchecked_t irq_emitted;
30540
30541 int front_offset;
30542 } drm_i810_private_t;
30543diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30544index deaa657..e0fd296 100644
30545--- a/drivers/gpu/drm/i915/i915_debugfs.c
30546+++ b/drivers/gpu/drm/i915/i915_debugfs.c
30547@@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30548 I915_READ(GTIMR));
30549 }
30550 seq_printf(m, "Interrupts received: %d\n",
30551- atomic_read(&dev_priv->irq_received));
30552+ atomic_read_unchecked(&dev_priv->irq_received));
30553 for (i = 0; i < I915_NUM_RINGS; i++) {
30554 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30555 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30556@@ -1321,7 +1321,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
30557 return ret;
30558
30559 if (opregion->header)
30560- seq_write(m, opregion->header, OPREGION_SIZE);
30561+ seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
30562
30563 mutex_unlock(&dev->struct_mutex);
30564
30565diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30566index ddfe3d9..f6e6b21 100644
30567--- a/drivers/gpu/drm/i915/i915_dma.c
30568+++ b/drivers/gpu/drm/i915/i915_dma.c
30569@@ -1175,7 +1175,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30570 bool can_switch;
30571
30572 spin_lock(&dev->count_lock);
30573- can_switch = (dev->open_count == 0);
30574+ can_switch = (local_read(&dev->open_count) == 0);
30575 spin_unlock(&dev->count_lock);
30576 return can_switch;
30577 }
30578diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30579index 9689ca3..294f9c1 100644
30580--- a/drivers/gpu/drm/i915/i915_drv.h
30581+++ b/drivers/gpu/drm/i915/i915_drv.h
30582@@ -231,7 +231,7 @@ struct drm_i915_display_funcs {
30583 /* render clock increase/decrease */
30584 /* display clock increase/decrease */
30585 /* pll clock increase/decrease */
30586-};
30587+} __no_const;
30588
30589 struct intel_device_info {
30590 u8 gen;
30591@@ -320,7 +320,7 @@ typedef struct drm_i915_private {
30592 int current_page;
30593 int page_flipping;
30594
30595- atomic_t irq_received;
30596+ atomic_unchecked_t irq_received;
30597
30598 /* protects the irq masks */
30599 spinlock_t irq_lock;
30600@@ -896,7 +896,7 @@ struct drm_i915_gem_object {
30601 * will be page flipped away on the next vblank. When it
30602 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30603 */
30604- atomic_t pending_flip;
30605+ atomic_unchecked_t pending_flip;
30606 };
30607
30608 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30609@@ -1276,7 +1276,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
30610 extern void intel_teardown_gmbus(struct drm_device *dev);
30611 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30612 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30613-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30614+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30615 {
30616 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30617 }
30618diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30619index e159e33..cdcc663 100644
30620--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30621+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30622@@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30623 i915_gem_clflush_object(obj);
30624
30625 if (obj->base.pending_write_domain)
30626- cd->flips |= atomic_read(&obj->pending_flip);
30627+ cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30628
30629 /* The actual obj->write_domain will be updated with
30630 * pending_write_domain after we emit the accumulated flush for all
30631@@ -882,9 +882,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30632
30633 static int
30634 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30635- int count)
30636+ unsigned int count)
30637 {
30638- int i;
30639+ unsigned int i;
30640
30641 for (i = 0; i < count; i++) {
30642 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30643diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30644index 5bd4361..0241a42 100644
30645--- a/drivers/gpu/drm/i915/i915_irq.c
30646+++ b/drivers/gpu/drm/i915/i915_irq.c
30647@@ -475,7 +475,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30648 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30649 struct drm_i915_master_private *master_priv;
30650
30651- atomic_inc(&dev_priv->irq_received);
30652+ atomic_inc_unchecked(&dev_priv->irq_received);
30653
30654 /* disable master interrupt before clearing iir */
30655 de_ier = I915_READ(DEIER);
30656@@ -566,7 +566,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30657 struct drm_i915_master_private *master_priv;
30658 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
30659
30660- atomic_inc(&dev_priv->irq_received);
30661+ atomic_inc_unchecked(&dev_priv->irq_received);
30662
30663 if (IS_GEN6(dev))
30664 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
30665@@ -1231,7 +1231,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
30666 int ret = IRQ_NONE, pipe;
30667 bool blc_event = false;
30668
30669- atomic_inc(&dev_priv->irq_received);
30670+ atomic_inc_unchecked(&dev_priv->irq_received);
30671
30672 iir = I915_READ(IIR);
30673
30674@@ -1743,7 +1743,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30675 {
30676 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30677
30678- atomic_set(&dev_priv->irq_received, 0);
30679+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30680
30681 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30682 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30683@@ -1932,7 +1932,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
30684 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30685 int pipe;
30686
30687- atomic_set(&dev_priv->irq_received, 0);
30688+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30689
30690 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30691 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30692diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30693index 2163818..cede019 100644
30694--- a/drivers/gpu/drm/i915/intel_display.c
30695+++ b/drivers/gpu/drm/i915/intel_display.c
30696@@ -2238,7 +2238,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
30697
30698 wait_event(dev_priv->pending_flip_queue,
30699 atomic_read(&dev_priv->mm.wedged) ||
30700- atomic_read(&obj->pending_flip) == 0);
30701+ atomic_read_unchecked(&obj->pending_flip) == 0);
30702
30703 /* Big Hammer, we also need to ensure that any pending
30704 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30705@@ -2859,7 +2859,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
30706 obj = to_intel_framebuffer(crtc->fb)->obj;
30707 dev_priv = crtc->dev->dev_private;
30708 wait_event(dev_priv->pending_flip_queue,
30709- atomic_read(&obj->pending_flip) == 0);
30710+ atomic_read_unchecked(&obj->pending_flip) == 0);
30711 }
30712
30713 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
30714@@ -7171,7 +7171,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30715
30716 atomic_clear_mask(1 << intel_crtc->plane,
30717 &obj->pending_flip.counter);
30718- if (atomic_read(&obj->pending_flip) == 0)
30719+ if (atomic_read_unchecked(&obj->pending_flip) == 0)
30720 wake_up(&dev_priv->pending_flip_queue);
30721
30722 schedule_work(&work->work);
30723@@ -7354,7 +7354,13 @@ static int intel_gen6_queue_flip(struct drm_device *dev,
30724 OUT_RING(fb->pitches[0] | obj->tiling_mode);
30725 OUT_RING(obj->gtt_offset);
30726
30727- pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
30728+ /* Contrary to the suggestions in the documentation,
30729+ * "Enable Panel Fitter" does not seem to be required when page
30730+ * flipping with a non-native mode, and worse causes a normal
30731+ * modeset to fail.
30732+ * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
30733+ */
30734+ pf = 0;
30735 pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
30736 OUT_RING(pf | pipesrc);
30737 ADVANCE_LP_RING();
30738@@ -7461,7 +7467,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30739 /* Block clients from rendering to the new back buffer until
30740 * the flip occurs and the object is no longer visible.
30741 */
30742- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30743+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30744
30745 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30746 if (ret)
30747@@ -7475,7 +7481,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30748 return 0;
30749
30750 cleanup_pending:
30751- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30752+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30753 drm_gem_object_unreference(&work->old_fb_obj->base);
30754 drm_gem_object_unreference(&obj->base);
30755 mutex_unlock(&dev->struct_mutex);
30756diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30757index 54558a0..2d97005 100644
30758--- a/drivers/gpu/drm/mga/mga_drv.h
30759+++ b/drivers/gpu/drm/mga/mga_drv.h
30760@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30761 u32 clear_cmd;
30762 u32 maccess;
30763
30764- atomic_t vbl_received; /**< Number of vblanks received. */
30765+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30766 wait_queue_head_t fence_queue;
30767- atomic_t last_fence_retired;
30768+ atomic_unchecked_t last_fence_retired;
30769 u32 next_fence_to_post;
30770
30771 unsigned int fb_cpp;
30772diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30773index 2581202..f230a8d9 100644
30774--- a/drivers/gpu/drm/mga/mga_irq.c
30775+++ b/drivers/gpu/drm/mga/mga_irq.c
30776@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30777 if (crtc != 0)
30778 return 0;
30779
30780- return atomic_read(&dev_priv->vbl_received);
30781+ return atomic_read_unchecked(&dev_priv->vbl_received);
30782 }
30783
30784
30785@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30786 /* VBLANK interrupt */
30787 if (status & MGA_VLINEPEN) {
30788 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30789- atomic_inc(&dev_priv->vbl_received);
30790+ atomic_inc_unchecked(&dev_priv->vbl_received);
30791 drm_handle_vblank(dev, 0);
30792 handled = 1;
30793 }
30794@@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30795 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30796 MGA_WRITE(MGA_PRIMEND, prim_end);
30797
30798- atomic_inc(&dev_priv->last_fence_retired);
30799+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
30800 DRM_WAKEUP(&dev_priv->fence_queue);
30801 handled = 1;
30802 }
30803@@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30804 * using fences.
30805 */
30806 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30807- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30808+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30809 - *sequence) <= (1 << 23)));
30810
30811 *sequence = cur_fence;
30812diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30813index e5cbead..6c354a3 100644
30814--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30815+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30816@@ -199,7 +199,7 @@ struct methods {
30817 const char desc[8];
30818 void (*loadbios)(struct drm_device *, uint8_t *);
30819 const bool rw;
30820-};
30821+} __do_const;
30822
30823 static struct methods shadow_methods[] = {
30824 { "PRAMIN", load_vbios_pramin, true },
30825@@ -5290,7 +5290,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30826 struct bit_table {
30827 const char id;
30828 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30829-};
30830+} __no_const;
30831
30832 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30833
30834diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30835index b827098..c31a797 100644
30836--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30837+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30838@@ -242,7 +242,7 @@ struct nouveau_channel {
30839 struct list_head pending;
30840 uint32_t sequence;
30841 uint32_t sequence_ack;
30842- atomic_t last_sequence_irq;
30843+ atomic_unchecked_t last_sequence_irq;
30844 struct nouveau_vma vma;
30845 } fence;
30846
30847@@ -323,7 +323,7 @@ struct nouveau_exec_engine {
30848 u32 handle, u16 class);
30849 void (*set_tile_region)(struct drm_device *dev, int i);
30850 void (*tlb_flush)(struct drm_device *, int engine);
30851-};
30852+} __no_const;
30853
30854 struct nouveau_instmem_engine {
30855 void *priv;
30856@@ -345,13 +345,13 @@ struct nouveau_instmem_engine {
30857 struct nouveau_mc_engine {
30858 int (*init)(struct drm_device *dev);
30859 void (*takedown)(struct drm_device *dev);
30860-};
30861+} __no_const;
30862
30863 struct nouveau_timer_engine {
30864 int (*init)(struct drm_device *dev);
30865 void (*takedown)(struct drm_device *dev);
30866 uint64_t (*read)(struct drm_device *dev);
30867-};
30868+} __no_const;
30869
30870 struct nouveau_fb_engine {
30871 int num_tiles;
30872@@ -566,7 +566,7 @@ struct nouveau_vram_engine {
30873 void (*put)(struct drm_device *, struct nouveau_mem **);
30874
30875 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30876-};
30877+} __no_const;
30878
30879 struct nouveau_engine {
30880 struct nouveau_instmem_engine instmem;
30881@@ -714,7 +714,7 @@ struct drm_nouveau_private {
30882 struct drm_global_reference mem_global_ref;
30883 struct ttm_bo_global_ref bo_global_ref;
30884 struct ttm_bo_device bdev;
30885- atomic_t validate_sequence;
30886+ atomic_unchecked_t validate_sequence;
30887 } ttm;
30888
30889 struct {
30890diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
30891index 2f6daae..c9d7b9e 100644
30892--- a/drivers/gpu/drm/nouveau/nouveau_fence.c
30893+++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
30894@@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
30895 if (USE_REFCNT(dev))
30896 sequence = nvchan_rd32(chan, 0x48);
30897 else
30898- sequence = atomic_read(&chan->fence.last_sequence_irq);
30899+ sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
30900
30901 if (chan->fence.sequence_ack == sequence)
30902 goto out;
30903@@ -539,7 +539,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
30904 return ret;
30905 }
30906
30907- atomic_set(&chan->fence.last_sequence_irq, 0);
30908+ atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
30909 return 0;
30910 }
30911
30912diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30913index 7ce3fde..cb3ea04 100644
30914--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30915+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30916@@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30917 int trycnt = 0;
30918 int ret, i;
30919
30920- sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30921+ sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30922 retry:
30923 if (++trycnt > 100000) {
30924 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30925diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30926index f80c5e0..936baa7 100644
30927--- a/drivers/gpu/drm/nouveau/nouveau_state.c
30928+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30929@@ -543,7 +543,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30930 bool can_switch;
30931
30932 spin_lock(&dev->count_lock);
30933- can_switch = (dev->open_count == 0);
30934+ can_switch = (local_read(&dev->open_count) == 0);
30935 spin_unlock(&dev->count_lock);
30936 return can_switch;
30937 }
30938diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
30939index dbdea8e..cd6eeeb 100644
30940--- a/drivers/gpu/drm/nouveau/nv04_graph.c
30941+++ b/drivers/gpu/drm/nouveau/nv04_graph.c
30942@@ -554,7 +554,7 @@ static int
30943 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
30944 u32 class, u32 mthd, u32 data)
30945 {
30946- atomic_set(&chan->fence.last_sequence_irq, data);
30947+ atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
30948 return 0;
30949 }
30950
30951diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30952index bcac90b..53bfc76 100644
30953--- a/drivers/gpu/drm/r128/r128_cce.c
30954+++ b/drivers/gpu/drm/r128/r128_cce.c
30955@@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30956
30957 /* GH: Simple idle check.
30958 */
30959- atomic_set(&dev_priv->idle_count, 0);
30960+ atomic_set_unchecked(&dev_priv->idle_count, 0);
30961
30962 /* We don't support anything other than bus-mastering ring mode,
30963 * but the ring can be in either AGP or PCI space for the ring
30964diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30965index 930c71b..499aded 100644
30966--- a/drivers/gpu/drm/r128/r128_drv.h
30967+++ b/drivers/gpu/drm/r128/r128_drv.h
30968@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30969 int is_pci;
30970 unsigned long cce_buffers_offset;
30971
30972- atomic_t idle_count;
30973+ atomic_unchecked_t idle_count;
30974
30975 int page_flipping;
30976 int current_page;
30977 u32 crtc_offset;
30978 u32 crtc_offset_cntl;
30979
30980- atomic_t vbl_received;
30981+ atomic_unchecked_t vbl_received;
30982
30983 u32 color_fmt;
30984 unsigned int front_offset;
30985diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30986index 429d5a0..7e899ed 100644
30987--- a/drivers/gpu/drm/r128/r128_irq.c
30988+++ b/drivers/gpu/drm/r128/r128_irq.c
30989@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30990 if (crtc != 0)
30991 return 0;
30992
30993- return atomic_read(&dev_priv->vbl_received);
30994+ return atomic_read_unchecked(&dev_priv->vbl_received);
30995 }
30996
30997 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30998@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30999 /* VBLANK interrupt */
31000 if (status & R128_CRTC_VBLANK_INT) {
31001 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31002- atomic_inc(&dev_priv->vbl_received);
31003+ atomic_inc_unchecked(&dev_priv->vbl_received);
31004 drm_handle_vblank(dev, 0);
31005 return IRQ_HANDLED;
31006 }
31007diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31008index a9e33ce..09edd4b 100644
31009--- a/drivers/gpu/drm/r128/r128_state.c
31010+++ b/drivers/gpu/drm/r128/r128_state.c
31011@@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31012
31013 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31014 {
31015- if (atomic_read(&dev_priv->idle_count) == 0)
31016+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31017 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31018 else
31019- atomic_set(&dev_priv->idle_count, 0);
31020+ atomic_set_unchecked(&dev_priv->idle_count, 0);
31021 }
31022
31023 #endif
31024diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31025index 5a82b6b..9e69c73 100644
31026--- a/drivers/gpu/drm/radeon/mkregtable.c
31027+++ b/drivers/gpu/drm/radeon/mkregtable.c
31028@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31029 regex_t mask_rex;
31030 regmatch_t match[4];
31031 char buf[1024];
31032- size_t end;
31033+ long end;
31034 int len;
31035 int done = 0;
31036 int r;
31037 unsigned o;
31038 struct offset *offset;
31039 char last_reg_s[10];
31040- int last_reg;
31041+ unsigned long last_reg;
31042
31043 if (regcomp
31044 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31045diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31046index 1668ec1..30ebdab 100644
31047--- a/drivers/gpu/drm/radeon/radeon.h
31048+++ b/drivers/gpu/drm/radeon/radeon.h
31049@@ -250,7 +250,7 @@ struct radeon_fence_driver {
31050 uint32_t scratch_reg;
31051 uint64_t gpu_addr;
31052 volatile uint32_t *cpu_addr;
31053- atomic_t seq;
31054+ atomic_unchecked_t seq;
31055 uint32_t last_seq;
31056 unsigned long last_jiffies;
31057 unsigned long last_timeout;
31058@@ -752,7 +752,7 @@ struct r600_blit_cp_primitives {
31059 int x2, int y2);
31060 void (*draw_auto)(struct radeon_device *rdev);
31061 void (*set_default_state)(struct radeon_device *rdev);
31062-};
31063+} __no_const;
31064
31065 struct r600_blit {
31066 struct mutex mutex;
31067@@ -1201,7 +1201,7 @@ struct radeon_asic {
31068 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
31069 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31070 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31071-};
31072+} __no_const;
31073
31074 /*
31075 * Asic structures
31076diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31077index 49f7cb7..2fcb48f 100644
31078--- a/drivers/gpu/drm/radeon/radeon_device.c
31079+++ b/drivers/gpu/drm/radeon/radeon_device.c
31080@@ -687,7 +687,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31081 bool can_switch;
31082
31083 spin_lock(&dev->count_lock);
31084- can_switch = (dev->open_count == 0);
31085+ can_switch = (local_read(&dev->open_count) == 0);
31086 spin_unlock(&dev->count_lock);
31087 return can_switch;
31088 }
31089diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31090index a1b59ca..86f2d44 100644
31091--- a/drivers/gpu/drm/radeon/radeon_drv.h
31092+++ b/drivers/gpu/drm/radeon/radeon_drv.h
31093@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31094
31095 /* SW interrupt */
31096 wait_queue_head_t swi_queue;
31097- atomic_t swi_emitted;
31098+ atomic_unchecked_t swi_emitted;
31099 int vblank_crtc;
31100 uint32_t irq_enable_reg;
31101 uint32_t r500_disp_irq_reg;
31102diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
31103index 4bd36a3..e66fe9c 100644
31104--- a/drivers/gpu/drm/radeon/radeon_fence.c
31105+++ b/drivers/gpu/drm/radeon/radeon_fence.c
31106@@ -70,7 +70,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
31107 write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
31108 return 0;
31109 }
31110- fence->seq = atomic_add_return(1, &rdev->fence_drv[fence->ring].seq);
31111+ fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv[fence->ring].seq);
31112 if (!rdev->ring[fence->ring].ready)
31113 /* FIXME: cp is not running assume everythings is done right
31114 * away
31115@@ -405,7 +405,7 @@ int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
31116 }
31117 rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
31118 rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
31119- radeon_fence_write(rdev, atomic_read(&rdev->fence_drv[ring].seq), ring);
31120+ radeon_fence_write(rdev, atomic_read_unchecked(&rdev->fence_drv[ring].seq), ring);
31121 rdev->fence_drv[ring].initialized = true;
31122 DRM_INFO("fence driver on ring %d use gpu addr 0x%08Lx and cpu addr 0x%p\n",
31123 ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
31124@@ -418,7 +418,7 @@ static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
31125 rdev->fence_drv[ring].scratch_reg = -1;
31126 rdev->fence_drv[ring].cpu_addr = NULL;
31127 rdev->fence_drv[ring].gpu_addr = 0;
31128- atomic_set(&rdev->fence_drv[ring].seq, 0);
31129+ atomic_set_unchecked(&rdev->fence_drv[ring].seq, 0);
31130 INIT_LIST_HEAD(&rdev->fence_drv[ring].created);
31131 INIT_LIST_HEAD(&rdev->fence_drv[ring].emitted);
31132 INIT_LIST_HEAD(&rdev->fence_drv[ring].signaled);
31133diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31134index 48b7cea..342236f 100644
31135--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31136+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31137@@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31138 request = compat_alloc_user_space(sizeof(*request));
31139 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31140 || __put_user(req32.param, &request->param)
31141- || __put_user((void __user *)(unsigned long)req32.value,
31142+ || __put_user((unsigned long)req32.value,
31143 &request->value))
31144 return -EFAULT;
31145
31146diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31147index 00da384..32f972d 100644
31148--- a/drivers/gpu/drm/radeon/radeon_irq.c
31149+++ b/drivers/gpu/drm/radeon/radeon_irq.c
31150@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31151 unsigned int ret;
31152 RING_LOCALS;
31153
31154- atomic_inc(&dev_priv->swi_emitted);
31155- ret = atomic_read(&dev_priv->swi_emitted);
31156+ atomic_inc_unchecked(&dev_priv->swi_emitted);
31157+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31158
31159 BEGIN_RING(4);
31160 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31161@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31162 drm_radeon_private_t *dev_priv =
31163 (drm_radeon_private_t *) dev->dev_private;
31164
31165- atomic_set(&dev_priv->swi_emitted, 0);
31166+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31167 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31168
31169 dev->max_vblank_count = 0x001fffff;
31170diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31171index e8422ae..d22d4a8 100644
31172--- a/drivers/gpu/drm/radeon/radeon_state.c
31173+++ b/drivers/gpu/drm/radeon/radeon_state.c
31174@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31175 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31176 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31177
31178- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31179+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31180 sarea_priv->nbox * sizeof(depth_boxes[0])))
31181 return -EFAULT;
31182
31183@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31184 {
31185 drm_radeon_private_t *dev_priv = dev->dev_private;
31186 drm_radeon_getparam_t *param = data;
31187- int value;
31188+ int value = 0;
31189
31190 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31191
31192diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31193index c421e77..e6bf2e8 100644
31194--- a/drivers/gpu/drm/radeon/radeon_ttm.c
31195+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31196@@ -842,8 +842,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31197 }
31198 if (unlikely(ttm_vm_ops == NULL)) {
31199 ttm_vm_ops = vma->vm_ops;
31200- radeon_ttm_vm_ops = *ttm_vm_ops;
31201- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31202+ pax_open_kernel();
31203+ memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31204+ *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31205+ pax_close_kernel();
31206 }
31207 vma->vm_ops = &radeon_ttm_vm_ops;
31208 return 0;
31209diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31210index f68dff2..8df955c 100644
31211--- a/drivers/gpu/drm/radeon/rs690.c
31212+++ b/drivers/gpu/drm/radeon/rs690.c
31213@@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31214 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31215 rdev->pm.sideport_bandwidth.full)
31216 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31217- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31218+ read_delay_latency.full = dfixed_const(800 * 1000);
31219 read_delay_latency.full = dfixed_div(read_delay_latency,
31220 rdev->pm.igp_sideport_mclk);
31221+ a.full = dfixed_const(370);
31222+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31223 } else {
31224 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31225 rdev->pm.k8_bandwidth.full)
31226diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31227index 499debd..66fce72 100644
31228--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31229+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31230@@ -398,9 +398,9 @@ static int ttm_pool_get_num_unused_pages(void)
31231 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31232 struct shrink_control *sc)
31233 {
31234- static atomic_t start_pool = ATOMIC_INIT(0);
31235+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31236 unsigned i;
31237- unsigned pool_offset = atomic_add_return(1, &start_pool);
31238+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31239 struct ttm_page_pool *pool;
31240 int shrink_pages = sc->nr_to_scan;
31241
31242diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31243index 88edacc..1e5412b 100644
31244--- a/drivers/gpu/drm/via/via_drv.h
31245+++ b/drivers/gpu/drm/via/via_drv.h
31246@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31247 typedef uint32_t maskarray_t[5];
31248
31249 typedef struct drm_via_irq {
31250- atomic_t irq_received;
31251+ atomic_unchecked_t irq_received;
31252 uint32_t pending_mask;
31253 uint32_t enable_mask;
31254 wait_queue_head_t irq_queue;
31255@@ -75,7 +75,7 @@ typedef struct drm_via_private {
31256 struct timeval last_vblank;
31257 int last_vblank_valid;
31258 unsigned usec_per_vblank;
31259- atomic_t vbl_received;
31260+ atomic_unchecked_t vbl_received;
31261 drm_via_state_t hc_state;
31262 char pci_buf[VIA_PCI_BUF_SIZE];
31263 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31264diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31265index d391f48..10c8ca3 100644
31266--- a/drivers/gpu/drm/via/via_irq.c
31267+++ b/drivers/gpu/drm/via/via_irq.c
31268@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31269 if (crtc != 0)
31270 return 0;
31271
31272- return atomic_read(&dev_priv->vbl_received);
31273+ return atomic_read_unchecked(&dev_priv->vbl_received);
31274 }
31275
31276 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31277@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31278
31279 status = VIA_READ(VIA_REG_INTERRUPT);
31280 if (status & VIA_IRQ_VBLANK_PENDING) {
31281- atomic_inc(&dev_priv->vbl_received);
31282- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31283+ atomic_inc_unchecked(&dev_priv->vbl_received);
31284+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31285 do_gettimeofday(&cur_vblank);
31286 if (dev_priv->last_vblank_valid) {
31287 dev_priv->usec_per_vblank =
31288@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31289 dev_priv->last_vblank = cur_vblank;
31290 dev_priv->last_vblank_valid = 1;
31291 }
31292- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31293+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31294 DRM_DEBUG("US per vblank is: %u\n",
31295 dev_priv->usec_per_vblank);
31296 }
31297@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31298
31299 for (i = 0; i < dev_priv->num_irqs; ++i) {
31300 if (status & cur_irq->pending_mask) {
31301- atomic_inc(&cur_irq->irq_received);
31302+ atomic_inc_unchecked(&cur_irq->irq_received);
31303 DRM_WAKEUP(&cur_irq->irq_queue);
31304 handled = 1;
31305 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31306@@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31307 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31308 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31309 masks[irq][4]));
31310- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31311+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31312 } else {
31313 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31314 (((cur_irq_sequence =
31315- atomic_read(&cur_irq->irq_received)) -
31316+ atomic_read_unchecked(&cur_irq->irq_received)) -
31317 *sequence) <= (1 << 23)));
31318 }
31319 *sequence = cur_irq_sequence;
31320@@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31321 }
31322
31323 for (i = 0; i < dev_priv->num_irqs; ++i) {
31324- atomic_set(&cur_irq->irq_received, 0);
31325+ atomic_set_unchecked(&cur_irq->irq_received, 0);
31326 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31327 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31328 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31329@@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31330 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31331 case VIA_IRQ_RELATIVE:
31332 irqwait->request.sequence +=
31333- atomic_read(&cur_irq->irq_received);
31334+ atomic_read_unchecked(&cur_irq->irq_received);
31335 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31336 case VIA_IRQ_ABSOLUTE:
31337 break;
31338diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31339index dc27970..f18b008 100644
31340--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31341+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31342@@ -260,7 +260,7 @@ struct vmw_private {
31343 * Fencing and IRQs.
31344 */
31345
31346- atomic_t marker_seq;
31347+ atomic_unchecked_t marker_seq;
31348 wait_queue_head_t fence_queue;
31349 wait_queue_head_t fifo_queue;
31350 int fence_queue_waiters; /* Protected by hw_mutex */
31351diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31352index a0c2f12..68ae6cb 100644
31353--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31354+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31355@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31356 (unsigned int) min,
31357 (unsigned int) fifo->capabilities);
31358
31359- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31360+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31361 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31362 vmw_marker_queue_init(&fifo->marker_queue);
31363 return vmw_fifo_send_fence(dev_priv, &dummy);
31364@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31365 if (reserveable)
31366 iowrite32(bytes, fifo_mem +
31367 SVGA_FIFO_RESERVED);
31368- return fifo_mem + (next_cmd >> 2);
31369+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31370 } else {
31371 need_bounce = true;
31372 }
31373@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31374
31375 fm = vmw_fifo_reserve(dev_priv, bytes);
31376 if (unlikely(fm == NULL)) {
31377- *seqno = atomic_read(&dev_priv->marker_seq);
31378+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31379 ret = -ENOMEM;
31380 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31381 false, 3*HZ);
31382@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31383 }
31384
31385 do {
31386- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31387+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31388 } while (*seqno == 0);
31389
31390 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31391diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31392index cabc95f..14b3d77 100644
31393--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31394+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31395@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31396 * emitted. Then the fence is stale and signaled.
31397 */
31398
31399- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31400+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31401 > VMW_FENCE_WRAP);
31402
31403 return ret;
31404@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31405
31406 if (fifo_idle)
31407 down_read(&fifo_state->rwsem);
31408- signal_seq = atomic_read(&dev_priv->marker_seq);
31409+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31410 ret = 0;
31411
31412 for (;;) {
31413diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31414index 8a8725c..afed796 100644
31415--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31416+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31417@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31418 while (!vmw_lag_lt(queue, us)) {
31419 spin_lock(&queue->lock);
31420 if (list_empty(&queue->head))
31421- seqno = atomic_read(&dev_priv->marker_seq);
31422+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31423 else {
31424 marker = list_first_entry(&queue->head,
31425 struct vmw_marker, head);
31426diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31427index 75dbe34..f9204a8 100644
31428--- a/drivers/hid/hid-core.c
31429+++ b/drivers/hid/hid-core.c
31430@@ -2021,7 +2021,7 @@ static bool hid_ignore(struct hid_device *hdev)
31431
31432 int hid_add_device(struct hid_device *hdev)
31433 {
31434- static atomic_t id = ATOMIC_INIT(0);
31435+ static atomic_unchecked_t id = ATOMIC_INIT(0);
31436 int ret;
31437
31438 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31439@@ -2036,7 +2036,7 @@ int hid_add_device(struct hid_device *hdev)
31440 /* XXX hack, any other cleaner solution after the driver core
31441 * is converted to allow more than 20 bytes as the device name? */
31442 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31443- hdev->vendor, hdev->product, atomic_inc_return(&id));
31444+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31445
31446 hid_debug_register(hdev, dev_name(&hdev->dev));
31447 ret = device_add(&hdev->dev);
31448diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31449index b1ec0e2..c295a61 100644
31450--- a/drivers/hid/usbhid/hiddev.c
31451+++ b/drivers/hid/usbhid/hiddev.c
31452@@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31453 break;
31454
31455 case HIDIOCAPPLICATION:
31456- if (arg < 0 || arg >= hid->maxapplication)
31457+ if (arg >= hid->maxapplication)
31458 break;
31459
31460 for (i = 0; i < hid->maxcollection; i++)
31461diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31462index 4065374..10ed7dc 100644
31463--- a/drivers/hv/channel.c
31464+++ b/drivers/hv/channel.c
31465@@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31466 int ret = 0;
31467 int t;
31468
31469- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31470- atomic_inc(&vmbus_connection.next_gpadl_handle);
31471+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31472+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31473
31474 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31475 if (ret)
31476diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31477index 12aa97f..c0679f7 100644
31478--- a/drivers/hv/hv.c
31479+++ b/drivers/hv/hv.c
31480@@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31481 u64 output_address = (output) ? virt_to_phys(output) : 0;
31482 u32 output_address_hi = output_address >> 32;
31483 u32 output_address_lo = output_address & 0xFFFFFFFF;
31484- void *hypercall_page = hv_context.hypercall_page;
31485+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31486
31487 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31488 "=a"(hv_status_lo) : "d" (control_hi),
31489diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31490index 6d7d286..92b0873 100644
31491--- a/drivers/hv/hyperv_vmbus.h
31492+++ b/drivers/hv/hyperv_vmbus.h
31493@@ -556,7 +556,7 @@ enum vmbus_connect_state {
31494 struct vmbus_connection {
31495 enum vmbus_connect_state conn_state;
31496
31497- atomic_t next_gpadl_handle;
31498+ atomic_unchecked_t next_gpadl_handle;
31499
31500 /*
31501 * Represents channel interrupts. Each bit position represents a
31502diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31503index a220e57..428f54d 100644
31504--- a/drivers/hv/vmbus_drv.c
31505+++ b/drivers/hv/vmbus_drv.c
31506@@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31507 {
31508 int ret = 0;
31509
31510- static atomic_t device_num = ATOMIC_INIT(0);
31511+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31512
31513 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31514- atomic_inc_return(&device_num));
31515+ atomic_inc_return_unchecked(&device_num));
31516
31517 child_device_obj->device.bus = &hv_bus;
31518 child_device_obj->device.parent = &hv_acpi_dev->dev;
31519diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31520index 554f046..f8b4729 100644
31521--- a/drivers/hwmon/acpi_power_meter.c
31522+++ b/drivers/hwmon/acpi_power_meter.c
31523@@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31524 return res;
31525
31526 temp /= 1000;
31527- if (temp < 0)
31528- return -EINVAL;
31529
31530 mutex_lock(&resource->lock);
31531 resource->trip[attr->index - 7] = temp;
31532diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31533index 91fdd1f..b66a686 100644
31534--- a/drivers/hwmon/sht15.c
31535+++ b/drivers/hwmon/sht15.c
31536@@ -166,7 +166,7 @@ struct sht15_data {
31537 int supply_uV;
31538 bool supply_uV_valid;
31539 struct work_struct update_supply_work;
31540- atomic_t interrupt_handled;
31541+ atomic_unchecked_t interrupt_handled;
31542 };
31543
31544 /**
31545@@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31546 return ret;
31547
31548 gpio_direction_input(data->pdata->gpio_data);
31549- atomic_set(&data->interrupt_handled, 0);
31550+ atomic_set_unchecked(&data->interrupt_handled, 0);
31551
31552 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31553 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31554 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31555 /* Only relevant if the interrupt hasn't occurred. */
31556- if (!atomic_read(&data->interrupt_handled))
31557+ if (!atomic_read_unchecked(&data->interrupt_handled))
31558 schedule_work(&data->read_work);
31559 }
31560 ret = wait_event_timeout(data->wait_queue,
31561@@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31562
31563 /* First disable the interrupt */
31564 disable_irq_nosync(irq);
31565- atomic_inc(&data->interrupt_handled);
31566+ atomic_inc_unchecked(&data->interrupt_handled);
31567 /* Then schedule a reading work struct */
31568 if (data->state != SHT15_READING_NOTHING)
31569 schedule_work(&data->read_work);
31570@@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31571 * If not, then start the interrupt again - care here as could
31572 * have gone low in meantime so verify it hasn't!
31573 */
31574- atomic_set(&data->interrupt_handled, 0);
31575+ atomic_set_unchecked(&data->interrupt_handled, 0);
31576 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31577 /* If still not occurred or another handler has been scheduled */
31578 if (gpio_get_value(data->pdata->gpio_data)
31579- || atomic_read(&data->interrupt_handled))
31580+ || atomic_read_unchecked(&data->interrupt_handled))
31581 return;
31582 }
31583
31584diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31585index 378fcb5..5e91fa8 100644
31586--- a/drivers/i2c/busses/i2c-amd756-s4882.c
31587+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31588@@ -43,7 +43,7 @@
31589 extern struct i2c_adapter amd756_smbus;
31590
31591 static struct i2c_adapter *s4882_adapter;
31592-static struct i2c_algorithm *s4882_algo;
31593+static i2c_algorithm_no_const *s4882_algo;
31594
31595 /* Wrapper access functions for multiplexed SMBus */
31596 static DEFINE_MUTEX(amd756_lock);
31597diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31598index 29015eb..af2d8e9 100644
31599--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31600+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31601@@ -41,7 +41,7 @@
31602 extern struct i2c_adapter *nforce2_smbus;
31603
31604 static struct i2c_adapter *s4985_adapter;
31605-static struct i2c_algorithm *s4985_algo;
31606+static i2c_algorithm_no_const *s4985_algo;
31607
31608 /* Wrapper access functions for multiplexed SMBus */
31609 static DEFINE_MUTEX(nforce2_lock);
31610diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31611index d7a4833..7fae376 100644
31612--- a/drivers/i2c/i2c-mux.c
31613+++ b/drivers/i2c/i2c-mux.c
31614@@ -28,7 +28,7 @@
31615 /* multiplexer per channel data */
31616 struct i2c_mux_priv {
31617 struct i2c_adapter adap;
31618- struct i2c_algorithm algo;
31619+ i2c_algorithm_no_const algo;
31620
31621 struct i2c_adapter *parent;
31622 void *mux_dev; /* the mux chip/device */
31623diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31624index 57d00ca..0145194 100644
31625--- a/drivers/ide/aec62xx.c
31626+++ b/drivers/ide/aec62xx.c
31627@@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31628 .cable_detect = atp86x_cable_detect,
31629 };
31630
31631-static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31632+static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31633 { /* 0: AEC6210 */
31634 .name = DRV_NAME,
31635 .init_chipset = init_chipset_aec62xx,
31636diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31637index 2c8016a..911a27c 100644
31638--- a/drivers/ide/alim15x3.c
31639+++ b/drivers/ide/alim15x3.c
31640@@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31641 .dma_sff_read_status = ide_dma_sff_read_status,
31642 };
31643
31644-static const struct ide_port_info ali15x3_chipset __devinitdata = {
31645+static const struct ide_port_info ali15x3_chipset __devinitconst = {
31646 .name = DRV_NAME,
31647 .init_chipset = init_chipset_ali15x3,
31648 .init_hwif = init_hwif_ali15x3,
31649diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31650index 3747b25..56fc995 100644
31651--- a/drivers/ide/amd74xx.c
31652+++ b/drivers/ide/amd74xx.c
31653@@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31654 .udma_mask = udma, \
31655 }
31656
31657-static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31658+static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31659 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31660 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31661 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31662diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31663index 15f0ead..cb43480 100644
31664--- a/drivers/ide/atiixp.c
31665+++ b/drivers/ide/atiixp.c
31666@@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31667 .cable_detect = atiixp_cable_detect,
31668 };
31669
31670-static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31671+static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31672 { /* 0: IXP200/300/400/700 */
31673 .name = DRV_NAME,
31674 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31675diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31676index 5f80312..d1fc438 100644
31677--- a/drivers/ide/cmd64x.c
31678+++ b/drivers/ide/cmd64x.c
31679@@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31680 .dma_sff_read_status = ide_dma_sff_read_status,
31681 };
31682
31683-static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31684+static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31685 { /* 0: CMD643 */
31686 .name = DRV_NAME,
31687 .init_chipset = init_chipset_cmd64x,
31688diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31689index 2c1e5f7..1444762 100644
31690--- a/drivers/ide/cs5520.c
31691+++ b/drivers/ide/cs5520.c
31692@@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31693 .set_dma_mode = cs5520_set_dma_mode,
31694 };
31695
31696-static const struct ide_port_info cyrix_chipset __devinitdata = {
31697+static const struct ide_port_info cyrix_chipset __devinitconst = {
31698 .name = DRV_NAME,
31699 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31700 .port_ops = &cs5520_port_ops,
31701diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31702index 4dc4eb9..49b40ad 100644
31703--- a/drivers/ide/cs5530.c
31704+++ b/drivers/ide/cs5530.c
31705@@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31706 .udma_filter = cs5530_udma_filter,
31707 };
31708
31709-static const struct ide_port_info cs5530_chipset __devinitdata = {
31710+static const struct ide_port_info cs5530_chipset __devinitconst = {
31711 .name = DRV_NAME,
31712 .init_chipset = init_chipset_cs5530,
31713 .init_hwif = init_hwif_cs5530,
31714diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31715index 5059faf..18d4c85 100644
31716--- a/drivers/ide/cs5535.c
31717+++ b/drivers/ide/cs5535.c
31718@@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31719 .cable_detect = cs5535_cable_detect,
31720 };
31721
31722-static const struct ide_port_info cs5535_chipset __devinitdata = {
31723+static const struct ide_port_info cs5535_chipset __devinitconst = {
31724 .name = DRV_NAME,
31725 .port_ops = &cs5535_port_ops,
31726 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31727diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31728index 847553f..3ffb49d 100644
31729--- a/drivers/ide/cy82c693.c
31730+++ b/drivers/ide/cy82c693.c
31731@@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31732 .set_dma_mode = cy82c693_set_dma_mode,
31733 };
31734
31735-static const struct ide_port_info cy82c693_chipset __devinitdata = {
31736+static const struct ide_port_info cy82c693_chipset __devinitconst = {
31737 .name = DRV_NAME,
31738 .init_iops = init_iops_cy82c693,
31739 .port_ops = &cy82c693_port_ops,
31740diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31741index 58c51cd..4aec3b8 100644
31742--- a/drivers/ide/hpt366.c
31743+++ b/drivers/ide/hpt366.c
31744@@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31745 }
31746 };
31747
31748-static const struct hpt_info hpt36x __devinitdata = {
31749+static const struct hpt_info hpt36x __devinitconst = {
31750 .chip_name = "HPT36x",
31751 .chip_type = HPT36x,
31752 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31753@@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31754 .timings = &hpt36x_timings
31755 };
31756
31757-static const struct hpt_info hpt370 __devinitdata = {
31758+static const struct hpt_info hpt370 __devinitconst = {
31759 .chip_name = "HPT370",
31760 .chip_type = HPT370,
31761 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31762@@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31763 .timings = &hpt37x_timings
31764 };
31765
31766-static const struct hpt_info hpt370a __devinitdata = {
31767+static const struct hpt_info hpt370a __devinitconst = {
31768 .chip_name = "HPT370A",
31769 .chip_type = HPT370A,
31770 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31771@@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31772 .timings = &hpt37x_timings
31773 };
31774
31775-static const struct hpt_info hpt374 __devinitdata = {
31776+static const struct hpt_info hpt374 __devinitconst = {
31777 .chip_name = "HPT374",
31778 .chip_type = HPT374,
31779 .udma_mask = ATA_UDMA5,
31780@@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31781 .timings = &hpt37x_timings
31782 };
31783
31784-static const struct hpt_info hpt372 __devinitdata = {
31785+static const struct hpt_info hpt372 __devinitconst = {
31786 .chip_name = "HPT372",
31787 .chip_type = HPT372,
31788 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31789@@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31790 .timings = &hpt37x_timings
31791 };
31792
31793-static const struct hpt_info hpt372a __devinitdata = {
31794+static const struct hpt_info hpt372a __devinitconst = {
31795 .chip_name = "HPT372A",
31796 .chip_type = HPT372A,
31797 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31798@@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31799 .timings = &hpt37x_timings
31800 };
31801
31802-static const struct hpt_info hpt302 __devinitdata = {
31803+static const struct hpt_info hpt302 __devinitconst = {
31804 .chip_name = "HPT302",
31805 .chip_type = HPT302,
31806 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31807@@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31808 .timings = &hpt37x_timings
31809 };
31810
31811-static const struct hpt_info hpt371 __devinitdata = {
31812+static const struct hpt_info hpt371 __devinitconst = {
31813 .chip_name = "HPT371",
31814 .chip_type = HPT371,
31815 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31816@@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31817 .timings = &hpt37x_timings
31818 };
31819
31820-static const struct hpt_info hpt372n __devinitdata = {
31821+static const struct hpt_info hpt372n __devinitconst = {
31822 .chip_name = "HPT372N",
31823 .chip_type = HPT372N,
31824 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31825@@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31826 .timings = &hpt37x_timings
31827 };
31828
31829-static const struct hpt_info hpt302n __devinitdata = {
31830+static const struct hpt_info hpt302n __devinitconst = {
31831 .chip_name = "HPT302N",
31832 .chip_type = HPT302N,
31833 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31834@@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31835 .timings = &hpt37x_timings
31836 };
31837
31838-static const struct hpt_info hpt371n __devinitdata = {
31839+static const struct hpt_info hpt371n __devinitconst = {
31840 .chip_name = "HPT371N",
31841 .chip_type = HPT371N,
31842 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31843@@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31844 .dma_sff_read_status = ide_dma_sff_read_status,
31845 };
31846
31847-static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31848+static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31849 { /* 0: HPT36x */
31850 .name = DRV_NAME,
31851 .init_chipset = init_chipset_hpt366,
31852diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31853index 8126824..55a2798 100644
31854--- a/drivers/ide/ide-cd.c
31855+++ b/drivers/ide/ide-cd.c
31856@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31857 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31858 if ((unsigned long)buf & alignment
31859 || blk_rq_bytes(rq) & q->dma_pad_mask
31860- || object_is_on_stack(buf))
31861+ || object_starts_on_stack(buf))
31862 drive->dma = 0;
31863 }
31864 }
31865diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31866index 7f56b73..dab5b67 100644
31867--- a/drivers/ide/ide-pci-generic.c
31868+++ b/drivers/ide/ide-pci-generic.c
31869@@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31870 .udma_mask = ATA_UDMA6, \
31871 }
31872
31873-static const struct ide_port_info generic_chipsets[] __devinitdata = {
31874+static const struct ide_port_info generic_chipsets[] __devinitconst = {
31875 /* 0: Unknown */
31876 DECLARE_GENERIC_PCI_DEV(0),
31877
31878diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31879index 560e66d..d5dd180 100644
31880--- a/drivers/ide/it8172.c
31881+++ b/drivers/ide/it8172.c
31882@@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31883 .set_dma_mode = it8172_set_dma_mode,
31884 };
31885
31886-static const struct ide_port_info it8172_port_info __devinitdata = {
31887+static const struct ide_port_info it8172_port_info __devinitconst = {
31888 .name = DRV_NAME,
31889 .port_ops = &it8172_port_ops,
31890 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31891diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31892index 46816ba..1847aeb 100644
31893--- a/drivers/ide/it8213.c
31894+++ b/drivers/ide/it8213.c
31895@@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31896 .cable_detect = it8213_cable_detect,
31897 };
31898
31899-static const struct ide_port_info it8213_chipset __devinitdata = {
31900+static const struct ide_port_info it8213_chipset __devinitconst = {
31901 .name = DRV_NAME,
31902 .enablebits = { {0x41, 0x80, 0x80} },
31903 .port_ops = &it8213_port_ops,
31904diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31905index 2e3169f..c5611db 100644
31906--- a/drivers/ide/it821x.c
31907+++ b/drivers/ide/it821x.c
31908@@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31909 .cable_detect = it821x_cable_detect,
31910 };
31911
31912-static const struct ide_port_info it821x_chipset __devinitdata = {
31913+static const struct ide_port_info it821x_chipset __devinitconst = {
31914 .name = DRV_NAME,
31915 .init_chipset = init_chipset_it821x,
31916 .init_hwif = init_hwif_it821x,
31917diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31918index 74c2c4a..efddd7d 100644
31919--- a/drivers/ide/jmicron.c
31920+++ b/drivers/ide/jmicron.c
31921@@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31922 .cable_detect = jmicron_cable_detect,
31923 };
31924
31925-static const struct ide_port_info jmicron_chipset __devinitdata = {
31926+static const struct ide_port_info jmicron_chipset __devinitconst = {
31927 .name = DRV_NAME,
31928 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31929 .port_ops = &jmicron_port_ops,
31930diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31931index 95327a2..73f78d8 100644
31932--- a/drivers/ide/ns87415.c
31933+++ b/drivers/ide/ns87415.c
31934@@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31935 .dma_sff_read_status = superio_dma_sff_read_status,
31936 };
31937
31938-static const struct ide_port_info ns87415_chipset __devinitdata = {
31939+static const struct ide_port_info ns87415_chipset __devinitconst = {
31940 .name = DRV_NAME,
31941 .init_hwif = init_hwif_ns87415,
31942 .tp_ops = &ns87415_tp_ops,
31943diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31944index 1a53a4c..39edc66 100644
31945--- a/drivers/ide/opti621.c
31946+++ b/drivers/ide/opti621.c
31947@@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31948 .set_pio_mode = opti621_set_pio_mode,
31949 };
31950
31951-static const struct ide_port_info opti621_chipset __devinitdata = {
31952+static const struct ide_port_info opti621_chipset __devinitconst = {
31953 .name = DRV_NAME,
31954 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31955 .port_ops = &opti621_port_ops,
31956diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31957index 9546fe2..2e5ceb6 100644
31958--- a/drivers/ide/pdc202xx_new.c
31959+++ b/drivers/ide/pdc202xx_new.c
31960@@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31961 .udma_mask = udma, \
31962 }
31963
31964-static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31965+static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31966 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31967 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31968 };
31969diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31970index 3a35ec6..5634510 100644
31971--- a/drivers/ide/pdc202xx_old.c
31972+++ b/drivers/ide/pdc202xx_old.c
31973@@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31974 .max_sectors = sectors, \
31975 }
31976
31977-static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31978+static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31979 { /* 0: PDC20246 */
31980 .name = DRV_NAME,
31981 .init_chipset = init_chipset_pdc202xx,
31982diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31983index 1892e81..fe0fd60 100644
31984--- a/drivers/ide/piix.c
31985+++ b/drivers/ide/piix.c
31986@@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31987 .udma_mask = udma, \
31988 }
31989
31990-static const struct ide_port_info piix_pci_info[] __devinitdata = {
31991+static const struct ide_port_info piix_pci_info[] __devinitconst = {
31992 /* 0: MPIIX */
31993 { /*
31994 * MPIIX actually has only a single IDE channel mapped to
31995diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31996index a6414a8..c04173e 100644
31997--- a/drivers/ide/rz1000.c
31998+++ b/drivers/ide/rz1000.c
31999@@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32000 }
32001 }
32002
32003-static const struct ide_port_info rz1000_chipset __devinitdata = {
32004+static const struct ide_port_info rz1000_chipset __devinitconst = {
32005 .name = DRV_NAME,
32006 .host_flags = IDE_HFLAG_NO_DMA,
32007 };
32008diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32009index 356b9b5..d4758eb 100644
32010--- a/drivers/ide/sc1200.c
32011+++ b/drivers/ide/sc1200.c
32012@@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32013 .dma_sff_read_status = ide_dma_sff_read_status,
32014 };
32015
32016-static const struct ide_port_info sc1200_chipset __devinitdata = {
32017+static const struct ide_port_info sc1200_chipset __devinitconst = {
32018 .name = DRV_NAME,
32019 .port_ops = &sc1200_port_ops,
32020 .dma_ops = &sc1200_dma_ops,
32021diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32022index b7f5b0c..9701038 100644
32023--- a/drivers/ide/scc_pata.c
32024+++ b/drivers/ide/scc_pata.c
32025@@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32026 .dma_sff_read_status = scc_dma_sff_read_status,
32027 };
32028
32029-static const struct ide_port_info scc_chipset __devinitdata = {
32030+static const struct ide_port_info scc_chipset __devinitconst = {
32031 .name = "sccIDE",
32032 .init_iops = init_iops_scc,
32033 .init_dma = scc_init_dma,
32034diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32035index 35fb8da..24d72ef 100644
32036--- a/drivers/ide/serverworks.c
32037+++ b/drivers/ide/serverworks.c
32038@@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32039 .cable_detect = svwks_cable_detect,
32040 };
32041
32042-static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32043+static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32044 { /* 0: OSB4 */
32045 .name = DRV_NAME,
32046 .init_chipset = init_chipset_svwks,
32047diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32048index ddeda44..46f7e30 100644
32049--- a/drivers/ide/siimage.c
32050+++ b/drivers/ide/siimage.c
32051@@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32052 .udma_mask = ATA_UDMA6, \
32053 }
32054
32055-static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32056+static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32057 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32058 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32059 };
32060diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32061index 4a00225..09e61b4 100644
32062--- a/drivers/ide/sis5513.c
32063+++ b/drivers/ide/sis5513.c
32064@@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32065 .cable_detect = sis_cable_detect,
32066 };
32067
32068-static const struct ide_port_info sis5513_chipset __devinitdata = {
32069+static const struct ide_port_info sis5513_chipset __devinitconst = {
32070 .name = DRV_NAME,
32071 .init_chipset = init_chipset_sis5513,
32072 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32073diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32074index f21dc2a..d051cd2 100644
32075--- a/drivers/ide/sl82c105.c
32076+++ b/drivers/ide/sl82c105.c
32077@@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32078 .dma_sff_read_status = ide_dma_sff_read_status,
32079 };
32080
32081-static const struct ide_port_info sl82c105_chipset __devinitdata = {
32082+static const struct ide_port_info sl82c105_chipset __devinitconst = {
32083 .name = DRV_NAME,
32084 .init_chipset = init_chipset_sl82c105,
32085 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32086diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32087index 864ffe0..863a5e9 100644
32088--- a/drivers/ide/slc90e66.c
32089+++ b/drivers/ide/slc90e66.c
32090@@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32091 .cable_detect = slc90e66_cable_detect,
32092 };
32093
32094-static const struct ide_port_info slc90e66_chipset __devinitdata = {
32095+static const struct ide_port_info slc90e66_chipset __devinitconst = {
32096 .name = DRV_NAME,
32097 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32098 .port_ops = &slc90e66_port_ops,
32099diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32100index 4799d5c..1794678 100644
32101--- a/drivers/ide/tc86c001.c
32102+++ b/drivers/ide/tc86c001.c
32103@@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32104 .dma_sff_read_status = ide_dma_sff_read_status,
32105 };
32106
32107-static const struct ide_port_info tc86c001_chipset __devinitdata = {
32108+static const struct ide_port_info tc86c001_chipset __devinitconst = {
32109 .name = DRV_NAME,
32110 .init_hwif = init_hwif_tc86c001,
32111 .port_ops = &tc86c001_port_ops,
32112diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32113index 281c914..55ce1b8 100644
32114--- a/drivers/ide/triflex.c
32115+++ b/drivers/ide/triflex.c
32116@@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32117 .set_dma_mode = triflex_set_mode,
32118 };
32119
32120-static const struct ide_port_info triflex_device __devinitdata = {
32121+static const struct ide_port_info triflex_device __devinitconst = {
32122 .name = DRV_NAME,
32123 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32124 .port_ops = &triflex_port_ops,
32125diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32126index 4b42ca0..e494a98 100644
32127--- a/drivers/ide/trm290.c
32128+++ b/drivers/ide/trm290.c
32129@@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32130 .dma_check = trm290_dma_check,
32131 };
32132
32133-static const struct ide_port_info trm290_chipset __devinitdata = {
32134+static const struct ide_port_info trm290_chipset __devinitconst = {
32135 .name = DRV_NAME,
32136 .init_hwif = init_hwif_trm290,
32137 .tp_ops = &trm290_tp_ops,
32138diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32139index f46f49c..eb77678 100644
32140--- a/drivers/ide/via82cxxx.c
32141+++ b/drivers/ide/via82cxxx.c
32142@@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32143 .cable_detect = via82cxxx_cable_detect,
32144 };
32145
32146-static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32147+static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32148 .name = DRV_NAME,
32149 .init_chipset = init_chipset_via82cxxx,
32150 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32151diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32152index 73d4531..c90cd2d 100644
32153--- a/drivers/ieee802154/fakehard.c
32154+++ b/drivers/ieee802154/fakehard.c
32155@@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32156 phy->transmit_power = 0xbf;
32157
32158 dev->netdev_ops = &fake_ops;
32159- dev->ml_priv = &fake_mlme;
32160+ dev->ml_priv = (void *)&fake_mlme;
32161
32162 priv = netdev_priv(dev);
32163 priv->phy = phy;
32164diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32165index c889aae..6cf5aa7 100644
32166--- a/drivers/infiniband/core/cm.c
32167+++ b/drivers/infiniband/core/cm.c
32168@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32169
32170 struct cm_counter_group {
32171 struct kobject obj;
32172- atomic_long_t counter[CM_ATTR_COUNT];
32173+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32174 };
32175
32176 struct cm_counter_attribute {
32177@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32178 struct ib_mad_send_buf *msg = NULL;
32179 int ret;
32180
32181- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32182+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32183 counter[CM_REQ_COUNTER]);
32184
32185 /* Quick state check to discard duplicate REQs. */
32186@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32187 if (!cm_id_priv)
32188 return;
32189
32190- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32191+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32192 counter[CM_REP_COUNTER]);
32193 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32194 if (ret)
32195@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32196 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32197 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32198 spin_unlock_irq(&cm_id_priv->lock);
32199- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32200+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32201 counter[CM_RTU_COUNTER]);
32202 goto out;
32203 }
32204@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32205 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32206 dreq_msg->local_comm_id);
32207 if (!cm_id_priv) {
32208- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32209+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32210 counter[CM_DREQ_COUNTER]);
32211 cm_issue_drep(work->port, work->mad_recv_wc);
32212 return -EINVAL;
32213@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32214 case IB_CM_MRA_REP_RCVD:
32215 break;
32216 case IB_CM_TIMEWAIT:
32217- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32218+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32219 counter[CM_DREQ_COUNTER]);
32220 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32221 goto unlock;
32222@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32223 cm_free_msg(msg);
32224 goto deref;
32225 case IB_CM_DREQ_RCVD:
32226- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32227+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32228 counter[CM_DREQ_COUNTER]);
32229 goto unlock;
32230 default:
32231@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32232 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32233 cm_id_priv->msg, timeout)) {
32234 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32235- atomic_long_inc(&work->port->
32236+ atomic_long_inc_unchecked(&work->port->
32237 counter_group[CM_RECV_DUPLICATES].
32238 counter[CM_MRA_COUNTER]);
32239 goto out;
32240@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32241 break;
32242 case IB_CM_MRA_REQ_RCVD:
32243 case IB_CM_MRA_REP_RCVD:
32244- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32245+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32246 counter[CM_MRA_COUNTER]);
32247 /* fall through */
32248 default:
32249@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32250 case IB_CM_LAP_IDLE:
32251 break;
32252 case IB_CM_MRA_LAP_SENT:
32253- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32254+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32255 counter[CM_LAP_COUNTER]);
32256 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32257 goto unlock;
32258@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32259 cm_free_msg(msg);
32260 goto deref;
32261 case IB_CM_LAP_RCVD:
32262- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32263+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32264 counter[CM_LAP_COUNTER]);
32265 goto unlock;
32266 default:
32267@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32268 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32269 if (cur_cm_id_priv) {
32270 spin_unlock_irq(&cm.lock);
32271- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32272+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32273 counter[CM_SIDR_REQ_COUNTER]);
32274 goto out; /* Duplicate message. */
32275 }
32276@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32277 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32278 msg->retries = 1;
32279
32280- atomic_long_add(1 + msg->retries,
32281+ atomic_long_add_unchecked(1 + msg->retries,
32282 &port->counter_group[CM_XMIT].counter[attr_index]);
32283 if (msg->retries)
32284- atomic_long_add(msg->retries,
32285+ atomic_long_add_unchecked(msg->retries,
32286 &port->counter_group[CM_XMIT_RETRIES].
32287 counter[attr_index]);
32288
32289@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32290 }
32291
32292 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32293- atomic_long_inc(&port->counter_group[CM_RECV].
32294+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32295 counter[attr_id - CM_ATTR_ID_OFFSET]);
32296
32297 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32298@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32299 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32300
32301 return sprintf(buf, "%ld\n",
32302- atomic_long_read(&group->counter[cm_attr->index]));
32303+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32304 }
32305
32306 static const struct sysfs_ops cm_counter_ops = {
32307diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32308index 176c8f9..2627b62 100644
32309--- a/drivers/infiniband/core/fmr_pool.c
32310+++ b/drivers/infiniband/core/fmr_pool.c
32311@@ -98,8 +98,8 @@ struct ib_fmr_pool {
32312
32313 struct task_struct *thread;
32314
32315- atomic_t req_ser;
32316- atomic_t flush_ser;
32317+ atomic_unchecked_t req_ser;
32318+ atomic_unchecked_t flush_ser;
32319
32320 wait_queue_head_t force_wait;
32321 };
32322@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32323 struct ib_fmr_pool *pool = pool_ptr;
32324
32325 do {
32326- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32327+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32328 ib_fmr_batch_release(pool);
32329
32330- atomic_inc(&pool->flush_ser);
32331+ atomic_inc_unchecked(&pool->flush_ser);
32332 wake_up_interruptible(&pool->force_wait);
32333
32334 if (pool->flush_function)
32335@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32336 }
32337
32338 set_current_state(TASK_INTERRUPTIBLE);
32339- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32340+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32341 !kthread_should_stop())
32342 schedule();
32343 __set_current_state(TASK_RUNNING);
32344@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32345 pool->dirty_watermark = params->dirty_watermark;
32346 pool->dirty_len = 0;
32347 spin_lock_init(&pool->pool_lock);
32348- atomic_set(&pool->req_ser, 0);
32349- atomic_set(&pool->flush_ser, 0);
32350+ atomic_set_unchecked(&pool->req_ser, 0);
32351+ atomic_set_unchecked(&pool->flush_ser, 0);
32352 init_waitqueue_head(&pool->force_wait);
32353
32354 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32355@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32356 }
32357 spin_unlock_irq(&pool->pool_lock);
32358
32359- serial = atomic_inc_return(&pool->req_ser);
32360+ serial = atomic_inc_return_unchecked(&pool->req_ser);
32361 wake_up_process(pool->thread);
32362
32363 if (wait_event_interruptible(pool->force_wait,
32364- atomic_read(&pool->flush_ser) - serial >= 0))
32365+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32366 return -EINTR;
32367
32368 return 0;
32369@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32370 } else {
32371 list_add_tail(&fmr->list, &pool->dirty_list);
32372 if (++pool->dirty_len >= pool->dirty_watermark) {
32373- atomic_inc(&pool->req_ser);
32374+ atomic_inc_unchecked(&pool->req_ser);
32375 wake_up_process(pool->thread);
32376 }
32377 }
32378diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32379index 40c8353..946b0e4 100644
32380--- a/drivers/infiniband/hw/cxgb4/mem.c
32381+++ b/drivers/infiniband/hw/cxgb4/mem.c
32382@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32383 int err;
32384 struct fw_ri_tpte tpt;
32385 u32 stag_idx;
32386- static atomic_t key;
32387+ static atomic_unchecked_t key;
32388
32389 if (c4iw_fatal_error(rdev))
32390 return -EIO;
32391@@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32392 &rdev->resource.tpt_fifo_lock);
32393 if (!stag_idx)
32394 return -ENOMEM;
32395- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32396+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32397 }
32398 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32399 __func__, stag_state, type, pdid, stag_idx);
32400diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32401index 79b3dbc..96e5fcc 100644
32402--- a/drivers/infiniband/hw/ipath/ipath_rc.c
32403+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32404@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32405 struct ib_atomic_eth *ateth;
32406 struct ipath_ack_entry *e;
32407 u64 vaddr;
32408- atomic64_t *maddr;
32409+ atomic64_unchecked_t *maddr;
32410 u64 sdata;
32411 u32 rkey;
32412 u8 next;
32413@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32414 IB_ACCESS_REMOTE_ATOMIC)))
32415 goto nack_acc_unlck;
32416 /* Perform atomic OP and save result. */
32417- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32418+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32419 sdata = be64_to_cpu(ateth->swap_data);
32420 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32421 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32422- (u64) atomic64_add_return(sdata, maddr) - sdata :
32423+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32424 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32425 be64_to_cpu(ateth->compare_data),
32426 sdata);
32427diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32428index 1f95bba..9530f87 100644
32429--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32430+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32431@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32432 unsigned long flags;
32433 struct ib_wc wc;
32434 u64 sdata;
32435- atomic64_t *maddr;
32436+ atomic64_unchecked_t *maddr;
32437 enum ib_wc_status send_status;
32438
32439 /*
32440@@ -382,11 +382,11 @@ again:
32441 IB_ACCESS_REMOTE_ATOMIC)))
32442 goto acc_err;
32443 /* Perform atomic OP and save result. */
32444- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32445+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32446 sdata = wqe->wr.wr.atomic.compare_add;
32447 *(u64 *) sqp->s_sge.sge.vaddr =
32448 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32449- (u64) atomic64_add_return(sdata, maddr) - sdata :
32450+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32451 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32452 sdata, wqe->wr.wr.atomic.swap);
32453 goto send_comp;
32454diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32455index 7140199..da60063 100644
32456--- a/drivers/infiniband/hw/nes/nes.c
32457+++ b/drivers/infiniband/hw/nes/nes.c
32458@@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32459 LIST_HEAD(nes_adapter_list);
32460 static LIST_HEAD(nes_dev_list);
32461
32462-atomic_t qps_destroyed;
32463+atomic_unchecked_t qps_destroyed;
32464
32465 static unsigned int ee_flsh_adapter;
32466 static unsigned int sysfs_nonidx_addr;
32467@@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32468 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32469 struct nes_adapter *nesadapter = nesdev->nesadapter;
32470
32471- atomic_inc(&qps_destroyed);
32472+ atomic_inc_unchecked(&qps_destroyed);
32473
32474 /* Free the control structures */
32475
32476diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32477index c438e46..ca30356 100644
32478--- a/drivers/infiniband/hw/nes/nes.h
32479+++ b/drivers/infiniband/hw/nes/nes.h
32480@@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32481 extern unsigned int wqm_quanta;
32482 extern struct list_head nes_adapter_list;
32483
32484-extern atomic_t cm_connects;
32485-extern atomic_t cm_accepts;
32486-extern atomic_t cm_disconnects;
32487-extern atomic_t cm_closes;
32488-extern atomic_t cm_connecteds;
32489-extern atomic_t cm_connect_reqs;
32490-extern atomic_t cm_rejects;
32491-extern atomic_t mod_qp_timouts;
32492-extern atomic_t qps_created;
32493-extern atomic_t qps_destroyed;
32494-extern atomic_t sw_qps_destroyed;
32495+extern atomic_unchecked_t cm_connects;
32496+extern atomic_unchecked_t cm_accepts;
32497+extern atomic_unchecked_t cm_disconnects;
32498+extern atomic_unchecked_t cm_closes;
32499+extern atomic_unchecked_t cm_connecteds;
32500+extern atomic_unchecked_t cm_connect_reqs;
32501+extern atomic_unchecked_t cm_rejects;
32502+extern atomic_unchecked_t mod_qp_timouts;
32503+extern atomic_unchecked_t qps_created;
32504+extern atomic_unchecked_t qps_destroyed;
32505+extern atomic_unchecked_t sw_qps_destroyed;
32506 extern u32 mh_detected;
32507 extern u32 mh_pauses_sent;
32508 extern u32 cm_packets_sent;
32509@@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32510 extern u32 cm_packets_received;
32511 extern u32 cm_packets_dropped;
32512 extern u32 cm_packets_retrans;
32513-extern atomic_t cm_listens_created;
32514-extern atomic_t cm_listens_destroyed;
32515+extern atomic_unchecked_t cm_listens_created;
32516+extern atomic_unchecked_t cm_listens_destroyed;
32517 extern u32 cm_backlog_drops;
32518-extern atomic_t cm_loopbacks;
32519-extern atomic_t cm_nodes_created;
32520-extern atomic_t cm_nodes_destroyed;
32521-extern atomic_t cm_accel_dropped_pkts;
32522-extern atomic_t cm_resets_recvd;
32523-extern atomic_t pau_qps_created;
32524-extern atomic_t pau_qps_destroyed;
32525+extern atomic_unchecked_t cm_loopbacks;
32526+extern atomic_unchecked_t cm_nodes_created;
32527+extern atomic_unchecked_t cm_nodes_destroyed;
32528+extern atomic_unchecked_t cm_accel_dropped_pkts;
32529+extern atomic_unchecked_t cm_resets_recvd;
32530+extern atomic_unchecked_t pau_qps_created;
32531+extern atomic_unchecked_t pau_qps_destroyed;
32532
32533 extern u32 int_mod_timer_init;
32534 extern u32 int_mod_cq_depth_256;
32535diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32536index a4972ab..1bcfc31 100644
32537--- a/drivers/infiniband/hw/nes/nes_cm.c
32538+++ b/drivers/infiniband/hw/nes/nes_cm.c
32539@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32540 u32 cm_packets_retrans;
32541 u32 cm_packets_created;
32542 u32 cm_packets_received;
32543-atomic_t cm_listens_created;
32544-atomic_t cm_listens_destroyed;
32545+atomic_unchecked_t cm_listens_created;
32546+atomic_unchecked_t cm_listens_destroyed;
32547 u32 cm_backlog_drops;
32548-atomic_t cm_loopbacks;
32549-atomic_t cm_nodes_created;
32550-atomic_t cm_nodes_destroyed;
32551-atomic_t cm_accel_dropped_pkts;
32552-atomic_t cm_resets_recvd;
32553+atomic_unchecked_t cm_loopbacks;
32554+atomic_unchecked_t cm_nodes_created;
32555+atomic_unchecked_t cm_nodes_destroyed;
32556+atomic_unchecked_t cm_accel_dropped_pkts;
32557+atomic_unchecked_t cm_resets_recvd;
32558
32559 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32560 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32561@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32562
32563 static struct nes_cm_core *g_cm_core;
32564
32565-atomic_t cm_connects;
32566-atomic_t cm_accepts;
32567-atomic_t cm_disconnects;
32568-atomic_t cm_closes;
32569-atomic_t cm_connecteds;
32570-atomic_t cm_connect_reqs;
32571-atomic_t cm_rejects;
32572+atomic_unchecked_t cm_connects;
32573+atomic_unchecked_t cm_accepts;
32574+atomic_unchecked_t cm_disconnects;
32575+atomic_unchecked_t cm_closes;
32576+atomic_unchecked_t cm_connecteds;
32577+atomic_unchecked_t cm_connect_reqs;
32578+atomic_unchecked_t cm_rejects;
32579
32580 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32581 {
32582@@ -1274,7 +1274,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32583 kfree(listener);
32584 listener = NULL;
32585 ret = 0;
32586- atomic_inc(&cm_listens_destroyed);
32587+ atomic_inc_unchecked(&cm_listens_destroyed);
32588 } else {
32589 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32590 }
32591@@ -1473,7 +1473,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32592 cm_node->rem_mac);
32593
32594 add_hte_node(cm_core, cm_node);
32595- atomic_inc(&cm_nodes_created);
32596+ atomic_inc_unchecked(&cm_nodes_created);
32597
32598 return cm_node;
32599 }
32600@@ -1531,7 +1531,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32601 }
32602
32603 atomic_dec(&cm_core->node_cnt);
32604- atomic_inc(&cm_nodes_destroyed);
32605+ atomic_inc_unchecked(&cm_nodes_destroyed);
32606 nesqp = cm_node->nesqp;
32607 if (nesqp) {
32608 nesqp->cm_node = NULL;
32609@@ -1595,7 +1595,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32610
32611 static void drop_packet(struct sk_buff *skb)
32612 {
32613- atomic_inc(&cm_accel_dropped_pkts);
32614+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32615 dev_kfree_skb_any(skb);
32616 }
32617
32618@@ -1658,7 +1658,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32619 {
32620
32621 int reset = 0; /* whether to send reset in case of err.. */
32622- atomic_inc(&cm_resets_recvd);
32623+ atomic_inc_unchecked(&cm_resets_recvd);
32624 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32625 " refcnt=%d\n", cm_node, cm_node->state,
32626 atomic_read(&cm_node->ref_count));
32627@@ -2299,7 +2299,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32628 rem_ref_cm_node(cm_node->cm_core, cm_node);
32629 return NULL;
32630 }
32631- atomic_inc(&cm_loopbacks);
32632+ atomic_inc_unchecked(&cm_loopbacks);
32633 loopbackremotenode->loopbackpartner = cm_node;
32634 loopbackremotenode->tcp_cntxt.rcv_wscale =
32635 NES_CM_DEFAULT_RCV_WND_SCALE;
32636@@ -2574,7 +2574,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32637 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32638 else {
32639 rem_ref_cm_node(cm_core, cm_node);
32640- atomic_inc(&cm_accel_dropped_pkts);
32641+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32642 dev_kfree_skb_any(skb);
32643 }
32644 break;
32645@@ -2881,7 +2881,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32646
32647 if ((cm_id) && (cm_id->event_handler)) {
32648 if (issue_disconn) {
32649- atomic_inc(&cm_disconnects);
32650+ atomic_inc_unchecked(&cm_disconnects);
32651 cm_event.event = IW_CM_EVENT_DISCONNECT;
32652 cm_event.status = disconn_status;
32653 cm_event.local_addr = cm_id->local_addr;
32654@@ -2903,7 +2903,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32655 }
32656
32657 if (issue_close) {
32658- atomic_inc(&cm_closes);
32659+ atomic_inc_unchecked(&cm_closes);
32660 nes_disconnect(nesqp, 1);
32661
32662 cm_id->provider_data = nesqp;
32663@@ -3039,7 +3039,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32664
32665 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32666 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32667- atomic_inc(&cm_accepts);
32668+ atomic_inc_unchecked(&cm_accepts);
32669
32670 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32671 netdev_refcnt_read(nesvnic->netdev));
32672@@ -3241,7 +3241,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32673 struct nes_cm_core *cm_core;
32674 u8 *start_buff;
32675
32676- atomic_inc(&cm_rejects);
32677+ atomic_inc_unchecked(&cm_rejects);
32678 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32679 loopback = cm_node->loopbackpartner;
32680 cm_core = cm_node->cm_core;
32681@@ -3301,7 +3301,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32682 ntohl(cm_id->local_addr.sin_addr.s_addr),
32683 ntohs(cm_id->local_addr.sin_port));
32684
32685- atomic_inc(&cm_connects);
32686+ atomic_inc_unchecked(&cm_connects);
32687 nesqp->active_conn = 1;
32688
32689 /* cache the cm_id in the qp */
32690@@ -3407,7 +3407,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32691 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32692 return err;
32693 }
32694- atomic_inc(&cm_listens_created);
32695+ atomic_inc_unchecked(&cm_listens_created);
32696 }
32697
32698 cm_id->add_ref(cm_id);
32699@@ -3508,7 +3508,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32700
32701 if (nesqp->destroyed)
32702 return;
32703- atomic_inc(&cm_connecteds);
32704+ atomic_inc_unchecked(&cm_connecteds);
32705 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32706 " local port 0x%04X. jiffies = %lu.\n",
32707 nesqp->hwqp.qp_id,
32708@@ -3695,7 +3695,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32709
32710 cm_id->add_ref(cm_id);
32711 ret = cm_id->event_handler(cm_id, &cm_event);
32712- atomic_inc(&cm_closes);
32713+ atomic_inc_unchecked(&cm_closes);
32714 cm_event.event = IW_CM_EVENT_CLOSE;
32715 cm_event.status = 0;
32716 cm_event.provider_data = cm_id->provider_data;
32717@@ -3731,7 +3731,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32718 return;
32719 cm_id = cm_node->cm_id;
32720
32721- atomic_inc(&cm_connect_reqs);
32722+ atomic_inc_unchecked(&cm_connect_reqs);
32723 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32724 cm_node, cm_id, jiffies);
32725
32726@@ -3771,7 +3771,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32727 return;
32728 cm_id = cm_node->cm_id;
32729
32730- atomic_inc(&cm_connect_reqs);
32731+ atomic_inc_unchecked(&cm_connect_reqs);
32732 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32733 cm_node, cm_id, jiffies);
32734
32735diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32736index 3ba7be3..c81f6ff 100644
32737--- a/drivers/infiniband/hw/nes/nes_mgt.c
32738+++ b/drivers/infiniband/hw/nes/nes_mgt.c
32739@@ -40,8 +40,8 @@
32740 #include "nes.h"
32741 #include "nes_mgt.h"
32742
32743-atomic_t pau_qps_created;
32744-atomic_t pau_qps_destroyed;
32745+atomic_unchecked_t pau_qps_created;
32746+atomic_unchecked_t pau_qps_destroyed;
32747
32748 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32749 {
32750@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32751 {
32752 struct sk_buff *skb;
32753 unsigned long flags;
32754- atomic_inc(&pau_qps_destroyed);
32755+ atomic_inc_unchecked(&pau_qps_destroyed);
32756
32757 /* Free packets that have not yet been forwarded */
32758 /* Lock is acquired by skb_dequeue when removing the skb */
32759@@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32760 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32761 skb_queue_head_init(&nesqp->pau_list);
32762 spin_lock_init(&nesqp->pau_lock);
32763- atomic_inc(&pau_qps_created);
32764+ atomic_inc_unchecked(&pau_qps_created);
32765 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32766 }
32767
32768diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32769index f3a3ecf..57d311d 100644
32770--- a/drivers/infiniband/hw/nes/nes_nic.c
32771+++ b/drivers/infiniband/hw/nes/nes_nic.c
32772@@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32773 target_stat_values[++index] = mh_detected;
32774 target_stat_values[++index] = mh_pauses_sent;
32775 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32776- target_stat_values[++index] = atomic_read(&cm_connects);
32777- target_stat_values[++index] = atomic_read(&cm_accepts);
32778- target_stat_values[++index] = atomic_read(&cm_disconnects);
32779- target_stat_values[++index] = atomic_read(&cm_connecteds);
32780- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32781- target_stat_values[++index] = atomic_read(&cm_rejects);
32782- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32783- target_stat_values[++index] = atomic_read(&qps_created);
32784- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32785- target_stat_values[++index] = atomic_read(&qps_destroyed);
32786- target_stat_values[++index] = atomic_read(&cm_closes);
32787+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32788+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32789+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32790+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32791+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32792+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32793+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32794+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32795+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32796+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32797+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32798 target_stat_values[++index] = cm_packets_sent;
32799 target_stat_values[++index] = cm_packets_bounced;
32800 target_stat_values[++index] = cm_packets_created;
32801 target_stat_values[++index] = cm_packets_received;
32802 target_stat_values[++index] = cm_packets_dropped;
32803 target_stat_values[++index] = cm_packets_retrans;
32804- target_stat_values[++index] = atomic_read(&cm_listens_created);
32805- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32806+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32807+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32808 target_stat_values[++index] = cm_backlog_drops;
32809- target_stat_values[++index] = atomic_read(&cm_loopbacks);
32810- target_stat_values[++index] = atomic_read(&cm_nodes_created);
32811- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32812- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32813- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32814+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32815+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32816+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32817+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32818+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32819 target_stat_values[++index] = nesadapter->free_4kpbl;
32820 target_stat_values[++index] = nesadapter->free_256pbl;
32821 target_stat_values[++index] = int_mod_timer_init;
32822 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32823 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32824 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32825- target_stat_values[++index] = atomic_read(&pau_qps_created);
32826- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32827+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32828+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32829 }
32830
32831 /**
32832diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32833index 0927b5c..ed67986 100644
32834--- a/drivers/infiniband/hw/nes/nes_verbs.c
32835+++ b/drivers/infiniband/hw/nes/nes_verbs.c
32836@@ -46,9 +46,9 @@
32837
32838 #include <rdma/ib_umem.h>
32839
32840-atomic_t mod_qp_timouts;
32841-atomic_t qps_created;
32842-atomic_t sw_qps_destroyed;
32843+atomic_unchecked_t mod_qp_timouts;
32844+atomic_unchecked_t qps_created;
32845+atomic_unchecked_t sw_qps_destroyed;
32846
32847 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32848
32849@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32850 if (init_attr->create_flags)
32851 return ERR_PTR(-EINVAL);
32852
32853- atomic_inc(&qps_created);
32854+ atomic_inc_unchecked(&qps_created);
32855 switch (init_attr->qp_type) {
32856 case IB_QPT_RC:
32857 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32858@@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32859 struct iw_cm_event cm_event;
32860 int ret = 0;
32861
32862- atomic_inc(&sw_qps_destroyed);
32863+ atomic_inc_unchecked(&sw_qps_destroyed);
32864 nesqp->destroyed = 1;
32865
32866 /* Blow away the connection if it exists. */
32867diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32868index b881bdc..c2e360c 100644
32869--- a/drivers/infiniband/hw/qib/qib.h
32870+++ b/drivers/infiniband/hw/qib/qib.h
32871@@ -51,6 +51,7 @@
32872 #include <linux/completion.h>
32873 #include <linux/kref.h>
32874 #include <linux/sched.h>
32875+#include <linux/slab.h>
32876
32877 #include "qib_common.h"
32878 #include "qib_verbs.h"
32879diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32880index c351aa4..e6967c2 100644
32881--- a/drivers/input/gameport/gameport.c
32882+++ b/drivers/input/gameport/gameport.c
32883@@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32884 */
32885 static void gameport_init_port(struct gameport *gameport)
32886 {
32887- static atomic_t gameport_no = ATOMIC_INIT(0);
32888+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32889
32890 __module_get(THIS_MODULE);
32891
32892 mutex_init(&gameport->drv_mutex);
32893 device_initialize(&gameport->dev);
32894 dev_set_name(&gameport->dev, "gameport%lu",
32895- (unsigned long)atomic_inc_return(&gameport_no) - 1);
32896+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32897 gameport->dev.bus = &gameport_bus;
32898 gameport->dev.release = gameport_release_port;
32899 if (gameport->parent)
32900diff --git a/drivers/input/input.c b/drivers/input/input.c
32901index 1f78c95..3cddc6c 100644
32902--- a/drivers/input/input.c
32903+++ b/drivers/input/input.c
32904@@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32905 */
32906 int input_register_device(struct input_dev *dev)
32907 {
32908- static atomic_t input_no = ATOMIC_INIT(0);
32909+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32910 struct input_handler *handler;
32911 const char *path;
32912 int error;
32913@@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32914 dev->setkeycode = input_default_setkeycode;
32915
32916 dev_set_name(&dev->dev, "input%ld",
32917- (unsigned long) atomic_inc_return(&input_no) - 1);
32918+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32919
32920 error = device_add(&dev->dev);
32921 if (error)
32922diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32923index b8d8611..7a4a04b 100644
32924--- a/drivers/input/joystick/sidewinder.c
32925+++ b/drivers/input/joystick/sidewinder.c
32926@@ -30,6 +30,7 @@
32927 #include <linux/kernel.h>
32928 #include <linux/module.h>
32929 #include <linux/slab.h>
32930+#include <linux/sched.h>
32931 #include <linux/init.h>
32932 #include <linux/input.h>
32933 #include <linux/gameport.h>
32934diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32935index fd7a0d5..a4af10c 100644
32936--- a/drivers/input/joystick/xpad.c
32937+++ b/drivers/input/joystick/xpad.c
32938@@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32939
32940 static int xpad_led_probe(struct usb_xpad *xpad)
32941 {
32942- static atomic_t led_seq = ATOMIC_INIT(0);
32943+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32944 long led_no;
32945 struct xpad_led *led;
32946 struct led_classdev *led_cdev;
32947@@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32948 if (!led)
32949 return -ENOMEM;
32950
32951- led_no = (long)atomic_inc_return(&led_seq) - 1;
32952+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32953
32954 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32955 led->xpad = xpad;
32956diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32957index 0110b5a..d3ad144 100644
32958--- a/drivers/input/mousedev.c
32959+++ b/drivers/input/mousedev.c
32960@@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32961
32962 spin_unlock_irq(&client->packet_lock);
32963
32964- if (copy_to_user(buffer, data, count))
32965+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
32966 return -EFAULT;
32967
32968 return count;
32969diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32970index ba70058..571d25d 100644
32971--- a/drivers/input/serio/serio.c
32972+++ b/drivers/input/serio/serio.c
32973@@ -497,7 +497,7 @@ static void serio_release_port(struct device *dev)
32974 */
32975 static void serio_init_port(struct serio *serio)
32976 {
32977- static atomic_t serio_no = ATOMIC_INIT(0);
32978+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32979
32980 __module_get(THIS_MODULE);
32981
32982@@ -508,7 +508,7 @@ static void serio_init_port(struct serio *serio)
32983 mutex_init(&serio->drv_mutex);
32984 device_initialize(&serio->dev);
32985 dev_set_name(&serio->dev, "serio%ld",
32986- (long)atomic_inc_return(&serio_no) - 1);
32987+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
32988 serio->dev.bus = &serio_bus;
32989 serio->dev.release = serio_release_port;
32990 serio->dev.groups = serio_device_attr_groups;
32991diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32992index e44933d..9ba484a 100644
32993--- a/drivers/isdn/capi/capi.c
32994+++ b/drivers/isdn/capi/capi.c
32995@@ -83,8 +83,8 @@ struct capiminor {
32996
32997 struct capi20_appl *ap;
32998 u32 ncci;
32999- atomic_t datahandle;
33000- atomic_t msgid;
33001+ atomic_unchecked_t datahandle;
33002+ atomic_unchecked_t msgid;
33003
33004 struct tty_port port;
33005 int ttyinstop;
33006@@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33007 capimsg_setu16(s, 2, mp->ap->applid);
33008 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33009 capimsg_setu8 (s, 5, CAPI_RESP);
33010- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33011+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33012 capimsg_setu32(s, 8, mp->ncci);
33013 capimsg_setu16(s, 12, datahandle);
33014 }
33015@@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
33016 mp->outbytes -= len;
33017 spin_unlock_bh(&mp->outlock);
33018
33019- datahandle = atomic_inc_return(&mp->datahandle);
33020+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33021 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33022 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33023 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33024 capimsg_setu16(skb->data, 2, mp->ap->applid);
33025 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33026 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33027- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33028+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33029 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33030 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33031 capimsg_setu16(skb->data, 16, len); /* Data length */
33032diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
33033index db621db..825ea1a 100644
33034--- a/drivers/isdn/gigaset/common.c
33035+++ b/drivers/isdn/gigaset/common.c
33036@@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
33037 cs->commands_pending = 0;
33038 cs->cur_at_seq = 0;
33039 cs->gotfwver = -1;
33040- cs->open_count = 0;
33041+ local_set(&cs->open_count, 0);
33042 cs->dev = NULL;
33043 cs->tty = NULL;
33044 cs->tty_dev = NULL;
33045diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
33046index 212efaf..f187c6b 100644
33047--- a/drivers/isdn/gigaset/gigaset.h
33048+++ b/drivers/isdn/gigaset/gigaset.h
33049@@ -35,6 +35,7 @@
33050 #include <linux/tty_driver.h>
33051 #include <linux/list.h>
33052 #include <linux/atomic.h>
33053+#include <asm/local.h>
33054
33055 #define GIG_VERSION {0, 5, 0, 0}
33056 #define GIG_COMPAT {0, 4, 0, 0}
33057@@ -433,7 +434,7 @@ struct cardstate {
33058 spinlock_t cmdlock;
33059 unsigned curlen, cmdbytes;
33060
33061- unsigned open_count;
33062+ local_t open_count;
33063 struct tty_struct *tty;
33064 struct tasklet_struct if_wake_tasklet;
33065 unsigned control_state;
33066diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33067index ee0a549..a7c9798 100644
33068--- a/drivers/isdn/gigaset/interface.c
33069+++ b/drivers/isdn/gigaset/interface.c
33070@@ -163,9 +163,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33071 }
33072 tty->driver_data = cs;
33073
33074- ++cs->open_count;
33075-
33076- if (cs->open_count == 1) {
33077+ if (local_inc_return(&cs->open_count) == 1) {
33078 spin_lock_irqsave(&cs->lock, flags);
33079 cs->tty = tty;
33080 spin_unlock_irqrestore(&cs->lock, flags);
33081@@ -193,10 +191,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33082
33083 if (!cs->connected)
33084 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33085- else if (!cs->open_count)
33086+ else if (!local_read(&cs->open_count))
33087 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33088 else {
33089- if (!--cs->open_count) {
33090+ if (!local_dec_return(&cs->open_count)) {
33091 spin_lock_irqsave(&cs->lock, flags);
33092 cs->tty = NULL;
33093 spin_unlock_irqrestore(&cs->lock, flags);
33094@@ -231,7 +229,7 @@ static int if_ioctl(struct tty_struct *tty,
33095 if (!cs->connected) {
33096 gig_dbg(DEBUG_IF, "not connected");
33097 retval = -ENODEV;
33098- } else if (!cs->open_count)
33099+ } else if (!local_read(&cs->open_count))
33100 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33101 else {
33102 retval = 0;
33103@@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
33104 retval = -ENODEV;
33105 goto done;
33106 }
33107- if (!cs->open_count) {
33108+ if (!local_read(&cs->open_count)) {
33109 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33110 retval = -ENODEV;
33111 goto done;
33112@@ -414,7 +412,7 @@ static int if_write_room(struct tty_struct *tty)
33113 if (!cs->connected) {
33114 gig_dbg(DEBUG_IF, "not connected");
33115 retval = -ENODEV;
33116- } else if (!cs->open_count)
33117+ } else if (!local_read(&cs->open_count))
33118 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33119 else if (cs->mstate != MS_LOCKED) {
33120 dev_warn(cs->dev, "can't write to unlocked device\n");
33121@@ -444,7 +442,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
33122
33123 if (!cs->connected)
33124 gig_dbg(DEBUG_IF, "not connected");
33125- else if (!cs->open_count)
33126+ else if (!local_read(&cs->open_count))
33127 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33128 else if (cs->mstate != MS_LOCKED)
33129 dev_warn(cs->dev, "can't write to unlocked device\n");
33130@@ -472,7 +470,7 @@ static void if_throttle(struct tty_struct *tty)
33131
33132 if (!cs->connected)
33133 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33134- else if (!cs->open_count)
33135+ else if (!local_read(&cs->open_count))
33136 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33137 else
33138 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
33139@@ -496,7 +494,7 @@ static void if_unthrottle(struct tty_struct *tty)
33140
33141 if (!cs->connected)
33142 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33143- else if (!cs->open_count)
33144+ else if (!local_read(&cs->open_count))
33145 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33146 else
33147 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
33148@@ -527,7 +525,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
33149 goto out;
33150 }
33151
33152- if (!cs->open_count) {
33153+ if (!local_read(&cs->open_count)) {
33154 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33155 goto out;
33156 }
33157diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33158index 2a57da59..e7a12ed 100644
33159--- a/drivers/isdn/hardware/avm/b1.c
33160+++ b/drivers/isdn/hardware/avm/b1.c
33161@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
33162 }
33163 if (left) {
33164 if (t4file->user) {
33165- if (copy_from_user(buf, dp, left))
33166+ if (left > sizeof buf || copy_from_user(buf, dp, left))
33167 return -EFAULT;
33168 } else {
33169 memcpy(buf, dp, left);
33170@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
33171 }
33172 if (left) {
33173 if (config->user) {
33174- if (copy_from_user(buf, dp, left))
33175+ if (left > sizeof buf || copy_from_user(buf, dp, left))
33176 return -EFAULT;
33177 } else {
33178 memcpy(buf, dp, left);
33179diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33180index 85784a7..a19ca98 100644
33181--- a/drivers/isdn/hardware/eicon/divasync.h
33182+++ b/drivers/isdn/hardware/eicon/divasync.h
33183@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33184 } diva_didd_add_adapter_t;
33185 typedef struct _diva_didd_remove_adapter {
33186 IDI_CALL p_request;
33187-} diva_didd_remove_adapter_t;
33188+} __no_const diva_didd_remove_adapter_t;
33189 typedef struct _diva_didd_read_adapter_array {
33190 void * buffer;
33191 dword length;
33192diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33193index a3bd163..8956575 100644
33194--- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33195+++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33196@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33197 typedef struct _diva_os_idi_adapter_interface {
33198 diva_init_card_proc_t cleanup_adapter_proc;
33199 diva_cmd_card_proc_t cmd_proc;
33200-} diva_os_idi_adapter_interface_t;
33201+} __no_const diva_os_idi_adapter_interface_t;
33202
33203 typedef struct _diva_os_xdi_adapter {
33204 struct list_head link;
33205diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33206index 1f355bb..43f1fea 100644
33207--- a/drivers/isdn/icn/icn.c
33208+++ b/drivers/isdn/icn/icn.c
33209@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
33210 if (count > len)
33211 count = len;
33212 if (user) {
33213- if (copy_from_user(msg, buf, count))
33214+ if (count > sizeof msg || copy_from_user(msg, buf, count))
33215 return -EFAULT;
33216 } else
33217 memcpy(msg, buf, count);
33218diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
33219index 8bc4915..4cc6a2e 100644
33220--- a/drivers/leds/leds-mc13783.c
33221+++ b/drivers/leds/leds-mc13783.c
33222@@ -280,7 +280,7 @@ static int __devinit mc13783_led_probe(struct platform_device *pdev)
33223 return -EINVAL;
33224 }
33225
33226- led = kzalloc(sizeof(*led) * pdata->num_leds, GFP_KERNEL);
33227+ led = kcalloc(pdata->num_leds, sizeof(*led), GFP_KERNEL);
33228 if (led == NULL) {
33229 dev_err(&pdev->dev, "failed to alloc memory\n");
33230 return -ENOMEM;
33231diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33232index b5fdcb7..5b6c59f 100644
33233--- a/drivers/lguest/core.c
33234+++ b/drivers/lguest/core.c
33235@@ -92,9 +92,17 @@ static __init int map_switcher(void)
33236 * it's worked so far. The end address needs +1 because __get_vm_area
33237 * allocates an extra guard page, so we need space for that.
33238 */
33239+
33240+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33241+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33242+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33243+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33244+#else
33245 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33246 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33247 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33248+#endif
33249+
33250 if (!switcher_vma) {
33251 err = -ENOMEM;
33252 printk("lguest: could not map switcher pages high\n");
33253@@ -119,7 +127,7 @@ static __init int map_switcher(void)
33254 * Now the Switcher is mapped at the right address, we can't fail!
33255 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33256 */
33257- memcpy(switcher_vma->addr, start_switcher_text,
33258+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33259 end_switcher_text - start_switcher_text);
33260
33261 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33262diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33263index 3980903..ce25c5e 100644
33264--- a/drivers/lguest/x86/core.c
33265+++ b/drivers/lguest/x86/core.c
33266@@ -59,7 +59,7 @@ static struct {
33267 /* Offset from where switcher.S was compiled to where we've copied it */
33268 static unsigned long switcher_offset(void)
33269 {
33270- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33271+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33272 }
33273
33274 /* This cpu's struct lguest_pages. */
33275@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33276 * These copies are pretty cheap, so we do them unconditionally: */
33277 /* Save the current Host top-level page directory.
33278 */
33279+
33280+#ifdef CONFIG_PAX_PER_CPU_PGD
33281+ pages->state.host_cr3 = read_cr3();
33282+#else
33283 pages->state.host_cr3 = __pa(current->mm->pgd);
33284+#endif
33285+
33286 /*
33287 * Set up the Guest's page tables to see this CPU's pages (and no
33288 * other CPU's pages).
33289@@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33290 * compiled-in switcher code and the high-mapped copy we just made.
33291 */
33292 for (i = 0; i < IDT_ENTRIES; i++)
33293- default_idt_entries[i] += switcher_offset();
33294+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33295
33296 /*
33297 * Set up the Switcher's per-cpu areas.
33298@@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33299 * it will be undisturbed when we switch. To change %cs and jump we
33300 * need this structure to feed to Intel's "lcall" instruction.
33301 */
33302- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33303+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33304 lguest_entry.segment = LGUEST_CS;
33305
33306 /*
33307diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33308index 40634b0..4f5855e 100644
33309--- a/drivers/lguest/x86/switcher_32.S
33310+++ b/drivers/lguest/x86/switcher_32.S
33311@@ -87,6 +87,7 @@
33312 #include <asm/page.h>
33313 #include <asm/segment.h>
33314 #include <asm/lguest.h>
33315+#include <asm/processor-flags.h>
33316
33317 // We mark the start of the code to copy
33318 // It's placed in .text tho it's never run here
33319@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33320 // Changes type when we load it: damn Intel!
33321 // For after we switch over our page tables
33322 // That entry will be read-only: we'd crash.
33323+
33324+#ifdef CONFIG_PAX_KERNEXEC
33325+ mov %cr0, %edx
33326+ xor $X86_CR0_WP, %edx
33327+ mov %edx, %cr0
33328+#endif
33329+
33330 movl $(GDT_ENTRY_TSS*8), %edx
33331 ltr %dx
33332
33333@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33334 // Let's clear it again for our return.
33335 // The GDT descriptor of the Host
33336 // Points to the table after two "size" bytes
33337- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33338+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33339 // Clear "used" from type field (byte 5, bit 2)
33340- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33341+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33342+
33343+#ifdef CONFIG_PAX_KERNEXEC
33344+ mov %cr0, %eax
33345+ xor $X86_CR0_WP, %eax
33346+ mov %eax, %cr0
33347+#endif
33348
33349 // Once our page table's switched, the Guest is live!
33350 // The Host fades as we run this final step.
33351@@ -295,13 +309,12 @@ deliver_to_host:
33352 // I consulted gcc, and it gave
33353 // These instructions, which I gladly credit:
33354 leal (%edx,%ebx,8), %eax
33355- movzwl (%eax),%edx
33356- movl 4(%eax), %eax
33357- xorw %ax, %ax
33358- orl %eax, %edx
33359+ movl 4(%eax), %edx
33360+ movw (%eax), %dx
33361 // Now the address of the handler's in %edx
33362 // We call it now: its "iret" drops us home.
33363- jmp *%edx
33364+ ljmp $__KERNEL_CS, $1f
33365+1: jmp *%edx
33366
33367 // Every interrupt can come to us here
33368 // But we must truly tell each apart.
33369diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33370index 4daf9e5..b8d1d0f 100644
33371--- a/drivers/macintosh/macio_asic.c
33372+++ b/drivers/macintosh/macio_asic.c
33373@@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33374 * MacIO is matched against any Apple ID, it's probe() function
33375 * will then decide wether it applies or not
33376 */
33377-static const struct pci_device_id __devinitdata pci_ids [] = { {
33378+static const struct pci_device_id __devinitconst pci_ids [] = { {
33379 .vendor = PCI_VENDOR_ID_APPLE,
33380 .device = PCI_ANY_ID,
33381 .subvendor = PCI_ANY_ID,
33382diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33383index 1ce84ed..0fdd40a 100644
33384--- a/drivers/md/dm-ioctl.c
33385+++ b/drivers/md/dm-ioctl.c
33386@@ -1589,7 +1589,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33387 cmd == DM_LIST_VERSIONS_CMD)
33388 return 0;
33389
33390- if ((cmd == DM_DEV_CREATE_CMD)) {
33391+ if (cmd == DM_DEV_CREATE_CMD) {
33392 if (!*param->name) {
33393 DMWARN("name not supplied when creating device");
33394 return -EINVAL;
33395diff --git a/drivers/md/dm-log-userspace-transfer.c b/drivers/md/dm-log-userspace-transfer.c
33396index 1f23e04..08d9a20 100644
33397--- a/drivers/md/dm-log-userspace-transfer.c
33398+++ b/drivers/md/dm-log-userspace-transfer.c
33399@@ -134,7 +134,7 @@ static void cn_ulog_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
33400 {
33401 struct dm_ulog_request *tfr = (struct dm_ulog_request *)(msg + 1);
33402
33403- if (!cap_raised(current_cap(), CAP_SYS_ADMIN))
33404+ if (!capable(CAP_SYS_ADMIN))
33405 return;
33406
33407 spin_lock(&receiving_list_lock);
33408diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33409index 9bfd057..01180bc 100644
33410--- a/drivers/md/dm-raid1.c
33411+++ b/drivers/md/dm-raid1.c
33412@@ -40,7 +40,7 @@ enum dm_raid1_error {
33413
33414 struct mirror {
33415 struct mirror_set *ms;
33416- atomic_t error_count;
33417+ atomic_unchecked_t error_count;
33418 unsigned long error_type;
33419 struct dm_dev *dev;
33420 sector_t offset;
33421@@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33422 struct mirror *m;
33423
33424 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33425- if (!atomic_read(&m->error_count))
33426+ if (!atomic_read_unchecked(&m->error_count))
33427 return m;
33428
33429 return NULL;
33430@@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33431 * simple way to tell if a device has encountered
33432 * errors.
33433 */
33434- atomic_inc(&m->error_count);
33435+ atomic_inc_unchecked(&m->error_count);
33436
33437 if (test_and_set_bit(error_type, &m->error_type))
33438 return;
33439@@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33440 struct mirror *m = get_default_mirror(ms);
33441
33442 do {
33443- if (likely(!atomic_read(&m->error_count)))
33444+ if (likely(!atomic_read_unchecked(&m->error_count)))
33445 return m;
33446
33447 if (m-- == ms->mirror)
33448@@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33449 {
33450 struct mirror *default_mirror = get_default_mirror(m->ms);
33451
33452- return !atomic_read(&default_mirror->error_count);
33453+ return !atomic_read_unchecked(&default_mirror->error_count);
33454 }
33455
33456 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33457@@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33458 */
33459 if (likely(region_in_sync(ms, region, 1)))
33460 m = choose_mirror(ms, bio->bi_sector);
33461- else if (m && atomic_read(&m->error_count))
33462+ else if (m && atomic_read_unchecked(&m->error_count))
33463 m = NULL;
33464
33465 if (likely(m))
33466@@ -937,7 +937,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33467 }
33468
33469 ms->mirror[mirror].ms = ms;
33470- atomic_set(&(ms->mirror[mirror].error_count), 0);
33471+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33472 ms->mirror[mirror].error_type = 0;
33473 ms->mirror[mirror].offset = offset;
33474
33475@@ -1347,7 +1347,7 @@ static void mirror_resume(struct dm_target *ti)
33476 */
33477 static char device_status_char(struct mirror *m)
33478 {
33479- if (!atomic_read(&(m->error_count)))
33480+ if (!atomic_read_unchecked(&(m->error_count)))
33481 return 'A';
33482
33483 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33484diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33485index 3d80cf0..b77cc47 100644
33486--- a/drivers/md/dm-stripe.c
33487+++ b/drivers/md/dm-stripe.c
33488@@ -20,7 +20,7 @@ struct stripe {
33489 struct dm_dev *dev;
33490 sector_t physical_start;
33491
33492- atomic_t error_count;
33493+ atomic_unchecked_t error_count;
33494 };
33495
33496 struct stripe_c {
33497@@ -192,7 +192,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33498 kfree(sc);
33499 return r;
33500 }
33501- atomic_set(&(sc->stripe[i].error_count), 0);
33502+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33503 }
33504
33505 ti->private = sc;
33506@@ -314,7 +314,7 @@ static int stripe_status(struct dm_target *ti,
33507 DMEMIT("%d ", sc->stripes);
33508 for (i = 0; i < sc->stripes; i++) {
33509 DMEMIT("%s ", sc->stripe[i].dev->name);
33510- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33511+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33512 'D' : 'A';
33513 }
33514 buffer[i] = '\0';
33515@@ -361,8 +361,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33516 */
33517 for (i = 0; i < sc->stripes; i++)
33518 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33519- atomic_inc(&(sc->stripe[i].error_count));
33520- if (atomic_read(&(sc->stripe[i].error_count)) <
33521+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
33522+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33523 DM_IO_ERROR_THRESHOLD)
33524 schedule_work(&sc->trigger_event);
33525 }
33526diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33527index 63cc542..8d45caf3 100644
33528--- a/drivers/md/dm-table.c
33529+++ b/drivers/md/dm-table.c
33530@@ -391,7 +391,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33531 if (!dev_size)
33532 return 0;
33533
33534- if ((start >= dev_size) || (start + len > dev_size)) {
33535+ if ((start >= dev_size) || (len > dev_size - start)) {
33536 DMWARN("%s: %s too small for target: "
33537 "start=%llu, len=%llu, dev_size=%llu",
33538 dm_device_name(ti->table->md), bdevname(bdev, b),
33539diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33540index 237571a..fb6d19b 100644
33541--- a/drivers/md/dm-thin-metadata.c
33542+++ b/drivers/md/dm-thin-metadata.c
33543@@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33544
33545 pmd->info.tm = tm;
33546 pmd->info.levels = 2;
33547- pmd->info.value_type.context = pmd->data_sm;
33548+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33549 pmd->info.value_type.size = sizeof(__le64);
33550 pmd->info.value_type.inc = data_block_inc;
33551 pmd->info.value_type.dec = data_block_dec;
33552@@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33553
33554 pmd->bl_info.tm = tm;
33555 pmd->bl_info.levels = 1;
33556- pmd->bl_info.value_type.context = pmd->data_sm;
33557+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33558 pmd->bl_info.value_type.size = sizeof(__le64);
33559 pmd->bl_info.value_type.inc = data_block_inc;
33560 pmd->bl_info.value_type.dec = data_block_dec;
33561diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33562index b89c548..2af3ce4 100644
33563--- a/drivers/md/dm.c
33564+++ b/drivers/md/dm.c
33565@@ -176,9 +176,9 @@ struct mapped_device {
33566 /*
33567 * Event handling.
33568 */
33569- atomic_t event_nr;
33570+ atomic_unchecked_t event_nr;
33571 wait_queue_head_t eventq;
33572- atomic_t uevent_seq;
33573+ atomic_unchecked_t uevent_seq;
33574 struct list_head uevent_list;
33575 spinlock_t uevent_lock; /* Protect access to uevent_list */
33576
33577@@ -1844,8 +1844,8 @@ static struct mapped_device *alloc_dev(int minor)
33578 rwlock_init(&md->map_lock);
33579 atomic_set(&md->holders, 1);
33580 atomic_set(&md->open_count, 0);
33581- atomic_set(&md->event_nr, 0);
33582- atomic_set(&md->uevent_seq, 0);
33583+ atomic_set_unchecked(&md->event_nr, 0);
33584+ atomic_set_unchecked(&md->uevent_seq, 0);
33585 INIT_LIST_HEAD(&md->uevent_list);
33586 spin_lock_init(&md->uevent_lock);
33587
33588@@ -1979,7 +1979,7 @@ static void event_callback(void *context)
33589
33590 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33591
33592- atomic_inc(&md->event_nr);
33593+ atomic_inc_unchecked(&md->event_nr);
33594 wake_up(&md->eventq);
33595 }
33596
33597@@ -2621,18 +2621,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33598
33599 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33600 {
33601- return atomic_add_return(1, &md->uevent_seq);
33602+ return atomic_add_return_unchecked(1, &md->uevent_seq);
33603 }
33604
33605 uint32_t dm_get_event_nr(struct mapped_device *md)
33606 {
33607- return atomic_read(&md->event_nr);
33608+ return atomic_read_unchecked(&md->event_nr);
33609 }
33610
33611 int dm_wait_event(struct mapped_device *md, int event_nr)
33612 {
33613 return wait_event_interruptible(md->eventq,
33614- (event_nr != atomic_read(&md->event_nr)));
33615+ (event_nr != atomic_read_unchecked(&md->event_nr)));
33616 }
33617
33618 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33619diff --git a/drivers/md/md.c b/drivers/md/md.c
33620index 363aaf4..d875264 100644
33621--- a/drivers/md/md.c
33622+++ b/drivers/md/md.c
33623@@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33624 * start build, activate spare
33625 */
33626 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33627-static atomic_t md_event_count;
33628+static atomic_unchecked_t md_event_count;
33629 void md_new_event(struct mddev *mddev)
33630 {
33631- atomic_inc(&md_event_count);
33632+ atomic_inc_unchecked(&md_event_count);
33633 wake_up(&md_event_waiters);
33634 }
33635 EXPORT_SYMBOL_GPL(md_new_event);
33636@@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33637 */
33638 static void md_new_event_inintr(struct mddev *mddev)
33639 {
33640- atomic_inc(&md_event_count);
33641+ atomic_inc_unchecked(&md_event_count);
33642 wake_up(&md_event_waiters);
33643 }
33644
33645@@ -1526,7 +1526,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33646
33647 rdev->preferred_minor = 0xffff;
33648 rdev->data_offset = le64_to_cpu(sb->data_offset);
33649- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33650+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33651
33652 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33653 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33654@@ -1745,7 +1745,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33655 else
33656 sb->resync_offset = cpu_to_le64(0);
33657
33658- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33659+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33660
33661 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33662 sb->size = cpu_to_le64(mddev->dev_sectors);
33663@@ -2691,7 +2691,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33664 static ssize_t
33665 errors_show(struct md_rdev *rdev, char *page)
33666 {
33667- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33668+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33669 }
33670
33671 static ssize_t
33672@@ -2700,7 +2700,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33673 char *e;
33674 unsigned long n = simple_strtoul(buf, &e, 10);
33675 if (*buf && (*e == 0 || *e == '\n')) {
33676- atomic_set(&rdev->corrected_errors, n);
33677+ atomic_set_unchecked(&rdev->corrected_errors, n);
33678 return len;
33679 }
33680 return -EINVAL;
33681@@ -3086,8 +3086,8 @@ int md_rdev_init(struct md_rdev *rdev)
33682 rdev->sb_loaded = 0;
33683 rdev->bb_page = NULL;
33684 atomic_set(&rdev->nr_pending, 0);
33685- atomic_set(&rdev->read_errors, 0);
33686- atomic_set(&rdev->corrected_errors, 0);
33687+ atomic_set_unchecked(&rdev->read_errors, 0);
33688+ atomic_set_unchecked(&rdev->corrected_errors, 0);
33689
33690 INIT_LIST_HEAD(&rdev->same_set);
33691 init_waitqueue_head(&rdev->blocked_wait);
33692@@ -6738,7 +6738,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33693
33694 spin_unlock(&pers_lock);
33695 seq_printf(seq, "\n");
33696- seq->poll_event = atomic_read(&md_event_count);
33697+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33698 return 0;
33699 }
33700 if (v == (void*)2) {
33701@@ -6830,7 +6830,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33702 chunk_kb ? "KB" : "B");
33703 if (bitmap->file) {
33704 seq_printf(seq, ", file: ");
33705- seq_path(seq, &bitmap->file->f_path, " \t\n");
33706+ seq_path(seq, &bitmap->file->f_path, " \t\n\\");
33707 }
33708
33709 seq_printf(seq, "\n");
33710@@ -6861,7 +6861,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33711 return error;
33712
33713 seq = file->private_data;
33714- seq->poll_event = atomic_read(&md_event_count);
33715+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33716 return error;
33717 }
33718
33719@@ -6875,7 +6875,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33720 /* always allow read */
33721 mask = POLLIN | POLLRDNORM;
33722
33723- if (seq->poll_event != atomic_read(&md_event_count))
33724+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33725 mask |= POLLERR | POLLPRI;
33726 return mask;
33727 }
33728@@ -6919,7 +6919,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33729 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33730 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33731 (int)part_stat_read(&disk->part0, sectors[1]) -
33732- atomic_read(&disk->sync_io);
33733+ atomic_read_unchecked(&disk->sync_io);
33734 /* sync IO will cause sync_io to increase before the disk_stats
33735 * as sync_io is counted when a request starts, and
33736 * disk_stats is counted when it completes.
33737diff --git a/drivers/md/md.h b/drivers/md/md.h
33738index 44c63df..b795d1a 100644
33739--- a/drivers/md/md.h
33740+++ b/drivers/md/md.h
33741@@ -93,13 +93,13 @@ struct md_rdev {
33742 * only maintained for arrays that
33743 * support hot removal
33744 */
33745- atomic_t read_errors; /* number of consecutive read errors that
33746+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
33747 * we have tried to ignore.
33748 */
33749 struct timespec last_read_error; /* monotonic time since our
33750 * last read error
33751 */
33752- atomic_t corrected_errors; /* number of corrected read errors,
33753+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33754 * for reporting to userspace and storing
33755 * in superblock.
33756 */
33757@@ -421,7 +421,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33758
33759 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33760 {
33761- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33762+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33763 }
33764
33765 struct md_personality
33766diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33767index 50ed53b..4f29d7d 100644
33768--- a/drivers/md/persistent-data/dm-space-map-checker.c
33769+++ b/drivers/md/persistent-data/dm-space-map-checker.c
33770@@ -159,7 +159,7 @@ static void ca_destroy(struct count_array *ca)
33771 /*----------------------------------------------------------------*/
33772
33773 struct sm_checker {
33774- struct dm_space_map sm;
33775+ dm_space_map_no_const sm;
33776
33777 struct count_array old_counts;
33778 struct count_array counts;
33779diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33780index fc469ba..2d91555 100644
33781--- a/drivers/md/persistent-data/dm-space-map-disk.c
33782+++ b/drivers/md/persistent-data/dm-space-map-disk.c
33783@@ -23,7 +23,7 @@
33784 * Space map interface.
33785 */
33786 struct sm_disk {
33787- struct dm_space_map sm;
33788+ dm_space_map_no_const sm;
33789
33790 struct ll_disk ll;
33791 struct ll_disk old_ll;
33792diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33793index e89ae5e..062e4c2 100644
33794--- a/drivers/md/persistent-data/dm-space-map-metadata.c
33795+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33796@@ -43,7 +43,7 @@ struct block_op {
33797 };
33798
33799 struct sm_metadata {
33800- struct dm_space_map sm;
33801+ dm_space_map_no_const sm;
33802
33803 struct ll_disk ll;
33804 struct ll_disk old_ll;
33805diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33806index 1cbfc6b..56e1dbb 100644
33807--- a/drivers/md/persistent-data/dm-space-map.h
33808+++ b/drivers/md/persistent-data/dm-space-map.h
33809@@ -60,6 +60,7 @@ struct dm_space_map {
33810 int (*root_size)(struct dm_space_map *sm, size_t *result);
33811 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33812 };
33813+typedef struct dm_space_map __no_const dm_space_map_no_const;
33814
33815 /*----------------------------------------------------------------*/
33816
33817diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33818index edc735a..e9b97f1 100644
33819--- a/drivers/md/raid1.c
33820+++ b/drivers/md/raid1.c
33821@@ -1645,7 +1645,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33822 if (r1_sync_page_io(rdev, sect, s,
33823 bio->bi_io_vec[idx].bv_page,
33824 READ) != 0)
33825- atomic_add(s, &rdev->corrected_errors);
33826+ atomic_add_unchecked(s, &rdev->corrected_errors);
33827 }
33828 sectors -= s;
33829 sect += s;
33830@@ -1859,7 +1859,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33831 test_bit(In_sync, &rdev->flags)) {
33832 if (r1_sync_page_io(rdev, sect, s,
33833 conf->tmppage, READ)) {
33834- atomic_add(s, &rdev->corrected_errors);
33835+ atomic_add_unchecked(s, &rdev->corrected_errors);
33836 printk(KERN_INFO
33837 "md/raid1:%s: read error corrected "
33838 "(%d sectors at %llu on %s)\n",
33839diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33840index 1898389..a3aa617 100644
33841--- a/drivers/md/raid10.c
33842+++ b/drivers/md/raid10.c
33843@@ -1636,7 +1636,7 @@ static void end_sync_read(struct bio *bio, int error)
33844 /* The write handler will notice the lack of
33845 * R10BIO_Uptodate and record any errors etc
33846 */
33847- atomic_add(r10_bio->sectors,
33848+ atomic_add_unchecked(r10_bio->sectors,
33849 &conf->mirrors[d].rdev->corrected_errors);
33850
33851 /* for reconstruct, we always reschedule after a read.
33852@@ -1987,7 +1987,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33853 {
33854 struct timespec cur_time_mon;
33855 unsigned long hours_since_last;
33856- unsigned int read_errors = atomic_read(&rdev->read_errors);
33857+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33858
33859 ktime_get_ts(&cur_time_mon);
33860
33861@@ -2009,9 +2009,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33862 * overflowing the shift of read_errors by hours_since_last.
33863 */
33864 if (hours_since_last >= 8 * sizeof(read_errors))
33865- atomic_set(&rdev->read_errors, 0);
33866+ atomic_set_unchecked(&rdev->read_errors, 0);
33867 else
33868- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33869+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33870 }
33871
33872 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33873@@ -2065,8 +2065,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33874 return;
33875
33876 check_decay_read_errors(mddev, rdev);
33877- atomic_inc(&rdev->read_errors);
33878- if (atomic_read(&rdev->read_errors) > max_read_errors) {
33879+ atomic_inc_unchecked(&rdev->read_errors);
33880+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33881 char b[BDEVNAME_SIZE];
33882 bdevname(rdev->bdev, b);
33883
33884@@ -2074,7 +2074,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33885 "md/raid10:%s: %s: Raid device exceeded "
33886 "read_error threshold [cur %d:max %d]\n",
33887 mdname(mddev), b,
33888- atomic_read(&rdev->read_errors), max_read_errors);
33889+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33890 printk(KERN_NOTICE
33891 "md/raid10:%s: %s: Failing raid device\n",
33892 mdname(mddev), b);
33893@@ -2223,7 +2223,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33894 (unsigned long long)(
33895 sect + rdev->data_offset),
33896 bdevname(rdev->bdev, b));
33897- atomic_add(s, &rdev->corrected_errors);
33898+ atomic_add_unchecked(s, &rdev->corrected_errors);
33899 }
33900
33901 rdev_dec_pending(rdev, mddev);
33902diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33903index d1162e5..c7cd902 100644
33904--- a/drivers/md/raid5.c
33905+++ b/drivers/md/raid5.c
33906@@ -1687,18 +1687,18 @@ static void raid5_end_read_request(struct bio * bi, int error)
33907 (unsigned long long)(sh->sector
33908 + rdev->data_offset),
33909 bdevname(rdev->bdev, b));
33910- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33911+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33912 clear_bit(R5_ReadError, &sh->dev[i].flags);
33913 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33914 }
33915- if (atomic_read(&rdev->read_errors))
33916- atomic_set(&rdev->read_errors, 0);
33917+ if (atomic_read_unchecked(&rdev->read_errors))
33918+ atomic_set_unchecked(&rdev->read_errors, 0);
33919 } else {
33920 const char *bdn = bdevname(rdev->bdev, b);
33921 int retry = 0;
33922
33923 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33924- atomic_inc(&rdev->read_errors);
33925+ atomic_inc_unchecked(&rdev->read_errors);
33926 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33927 printk_ratelimited(
33928 KERN_WARNING
33929@@ -1727,7 +1727,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33930 (unsigned long long)(sh->sector
33931 + rdev->data_offset),
33932 bdn);
33933- else if (atomic_read(&rdev->read_errors)
33934+ else if (atomic_read_unchecked(&rdev->read_errors)
33935 > conf->max_nr_stripes)
33936 printk(KERN_WARNING
33937 "md/raid:%s: Too many read errors, failing device %s.\n",
33938diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33939index ce4f858..7bcfb46 100644
33940--- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33941+++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33942@@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
33943 .subvendor = _subvend, .subdevice = _subdev, \
33944 .driver_data = (unsigned long)&_driverdata }
33945
33946-static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33947+static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33948 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33949 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33950 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33951diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33952index a7d876f..8c21b61 100644
33953--- a/drivers/media/dvb/dvb-core/dvb_demux.h
33954+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33955@@ -73,7 +73,7 @@ struct dvb_demux_feed {
33956 union {
33957 dmx_ts_cb ts;
33958 dmx_section_cb sec;
33959- } cb;
33960+ } __no_const cb;
33961
33962 struct dvb_demux *demux;
33963 void *priv;
33964diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33965index 00a6732..70a682e 100644
33966--- a/drivers/media/dvb/dvb-core/dvbdev.c
33967+++ b/drivers/media/dvb/dvb-core/dvbdev.c
33968@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33969 const struct dvb_device *template, void *priv, int type)
33970 {
33971 struct dvb_device *dvbdev;
33972- struct file_operations *dvbdevfops;
33973+ file_operations_no_const *dvbdevfops;
33974 struct device *clsdev;
33975 int minor;
33976 int id;
33977diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33978index 3940bb0..fb3952a 100644
33979--- a/drivers/media/dvb/dvb-usb/cxusb.c
33980+++ b/drivers/media/dvb/dvb-usb/cxusb.c
33981@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33982
33983 struct dib0700_adapter_state {
33984 int (*set_param_save) (struct dvb_frontend *);
33985-};
33986+} __no_const;
33987
33988 static int dib7070_set_param_override(struct dvb_frontend *fe)
33989 {
33990diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33991index 451c5a7..649f711 100644
33992--- a/drivers/media/dvb/dvb-usb/dw2102.c
33993+++ b/drivers/media/dvb/dvb-usb/dw2102.c
33994@@ -95,7 +95,7 @@ struct su3000_state {
33995
33996 struct s6x0_state {
33997 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33998-};
33999+} __no_const;
34000
34001 /* debug */
34002 static int dvb_usb_dw2102_debug;
34003diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
34004index 404f63a..4796533 100644
34005--- a/drivers/media/dvb/frontends/dib3000.h
34006+++ b/drivers/media/dvb/frontends/dib3000.h
34007@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
34008 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
34009 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
34010 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
34011-};
34012+} __no_const;
34013
34014 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
34015 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
34016diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
34017index 8418c02..8555013 100644
34018--- a/drivers/media/dvb/ngene/ngene-cards.c
34019+++ b/drivers/media/dvb/ngene/ngene-cards.c
34020@@ -477,7 +477,7 @@ static struct ngene_info ngene_info_m780 = {
34021
34022 /****************************************************************************/
34023
34024-static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
34025+static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
34026 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
34027 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
34028 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
34029diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
34030index 16a089f..ab1667d 100644
34031--- a/drivers/media/radio/radio-cadet.c
34032+++ b/drivers/media/radio/radio-cadet.c
34033@@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34034 unsigned char readbuf[RDS_BUFFER];
34035 int i = 0;
34036
34037+ if (count > RDS_BUFFER)
34038+ return -EFAULT;
34039 mutex_lock(&dev->lock);
34040 if (dev->rdsstat == 0) {
34041 dev->rdsstat = 1;
34042diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34043index 9cde353..8c6a1c3 100644
34044--- a/drivers/media/video/au0828/au0828.h
34045+++ b/drivers/media/video/au0828/au0828.h
34046@@ -191,7 +191,7 @@ struct au0828_dev {
34047
34048 /* I2C */
34049 struct i2c_adapter i2c_adap;
34050- struct i2c_algorithm i2c_algo;
34051+ i2c_algorithm_no_const i2c_algo;
34052 struct i2c_client i2c_client;
34053 u32 i2c_rc;
34054
34055diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34056index 04bf662..e0ac026 100644
34057--- a/drivers/media/video/cx88/cx88-alsa.c
34058+++ b/drivers/media/video/cx88/cx88-alsa.c
34059@@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34060 * Only boards with eeprom and byte 1 at eeprom=1 have it
34061 */
34062
34063-static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34064+static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34065 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34066 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34067 {0, }
34068diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34069index 1fb7d5b..3901e77 100644
34070--- a/drivers/media/video/omap/omap_vout.c
34071+++ b/drivers/media/video/omap/omap_vout.c
34072@@ -64,7 +64,6 @@ enum omap_vout_channels {
34073 OMAP_VIDEO2,
34074 };
34075
34076-static struct videobuf_queue_ops video_vbq_ops;
34077 /* Variables configurable through module params*/
34078 static u32 video1_numbuffers = 3;
34079 static u32 video2_numbuffers = 3;
34080@@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34081 {
34082 struct videobuf_queue *q;
34083 struct omap_vout_device *vout = NULL;
34084+ static struct videobuf_queue_ops video_vbq_ops = {
34085+ .buf_setup = omap_vout_buffer_setup,
34086+ .buf_prepare = omap_vout_buffer_prepare,
34087+ .buf_release = omap_vout_buffer_release,
34088+ .buf_queue = omap_vout_buffer_queue,
34089+ };
34090
34091 vout = video_drvdata(file);
34092 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34093@@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34094 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34095
34096 q = &vout->vbq;
34097- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34098- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34099- video_vbq_ops.buf_release = omap_vout_buffer_release;
34100- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34101 spin_lock_init(&vout->vbq_lock);
34102
34103 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34104diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34105index 305e6aa..0143317 100644
34106--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34107+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34108@@ -196,7 +196,7 @@ struct pvr2_hdw {
34109
34110 /* I2C stuff */
34111 struct i2c_adapter i2c_adap;
34112- struct i2c_algorithm i2c_algo;
34113+ i2c_algorithm_no_const i2c_algo;
34114 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34115 int i2c_cx25840_hack_state;
34116 int i2c_linked;
34117diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34118index 4ed1c7c2..8f15e13 100644
34119--- a/drivers/media/video/timblogiw.c
34120+++ b/drivers/media/video/timblogiw.c
34121@@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34122
34123 /* Platform device functions */
34124
34125-static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34126+static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34127 .vidioc_querycap = timblogiw_querycap,
34128 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34129 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34130@@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34131 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34132 };
34133
34134-static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34135+static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34136 .owner = THIS_MODULE,
34137 .open = timblogiw_open,
34138 .release = timblogiw_close,
34139diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34140index a7dc467..a55c423 100644
34141--- a/drivers/message/fusion/mptbase.c
34142+++ b/drivers/message/fusion/mptbase.c
34143@@ -6754,8 +6754,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34144 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34145 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34146
34147+#ifdef CONFIG_GRKERNSEC_HIDESYM
34148+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34149+#else
34150 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34151 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34152+#endif
34153+
34154 /*
34155 * Rounding UP to nearest 4-kB boundary here...
34156 */
34157diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34158index 551262e..7551198 100644
34159--- a/drivers/message/fusion/mptsas.c
34160+++ b/drivers/message/fusion/mptsas.c
34161@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34162 return 0;
34163 }
34164
34165+static inline void
34166+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34167+{
34168+ if (phy_info->port_details) {
34169+ phy_info->port_details->rphy = rphy;
34170+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34171+ ioc->name, rphy));
34172+ }
34173+
34174+ if (rphy) {
34175+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34176+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34177+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34178+ ioc->name, rphy, rphy->dev.release));
34179+ }
34180+}
34181+
34182 /* no mutex */
34183 static void
34184 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34185@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34186 return NULL;
34187 }
34188
34189-static inline void
34190-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34191-{
34192- if (phy_info->port_details) {
34193- phy_info->port_details->rphy = rphy;
34194- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34195- ioc->name, rphy));
34196- }
34197-
34198- if (rphy) {
34199- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34200- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34201- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34202- ioc->name, rphy, rphy->dev.release));
34203- }
34204-}
34205-
34206 static inline struct sas_port *
34207 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34208 {
34209diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34210index 0c3ced7..1fe34ec 100644
34211--- a/drivers/message/fusion/mptscsih.c
34212+++ b/drivers/message/fusion/mptscsih.c
34213@@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34214
34215 h = shost_priv(SChost);
34216
34217- if (h) {
34218- if (h->info_kbuf == NULL)
34219- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34220- return h->info_kbuf;
34221- h->info_kbuf[0] = '\0';
34222+ if (!h)
34223+ return NULL;
34224
34225- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34226- h->info_kbuf[size-1] = '\0';
34227- }
34228+ if (h->info_kbuf == NULL)
34229+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34230+ return h->info_kbuf;
34231+ h->info_kbuf[0] = '\0';
34232+
34233+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34234+ h->info_kbuf[size-1] = '\0';
34235
34236 return h->info_kbuf;
34237 }
34238diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34239index 6d115c7..58ff7fd 100644
34240--- a/drivers/message/i2o/i2o_proc.c
34241+++ b/drivers/message/i2o/i2o_proc.c
34242@@ -255,13 +255,6 @@ static char *scsi_devices[] = {
34243 "Array Controller Device"
34244 };
34245
34246-static char *chtostr(u8 * chars, int n)
34247-{
34248- char tmp[256];
34249- tmp[0] = 0;
34250- return strncat(tmp, (char *)chars, n);
34251-}
34252-
34253 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34254 char *group)
34255 {
34256@@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34257
34258 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34259 seq_printf(seq, "%-#8x", ddm_table.module_id);
34260- seq_printf(seq, "%-29s",
34261- chtostr(ddm_table.module_name_version, 28));
34262+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34263 seq_printf(seq, "%9d ", ddm_table.data_size);
34264 seq_printf(seq, "%8d", ddm_table.code_size);
34265
34266@@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34267
34268 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34269 seq_printf(seq, "%-#8x", dst->module_id);
34270- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
34271- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
34272+ seq_printf(seq, "%-.28s", dst->module_name_version);
34273+ seq_printf(seq, "%-.8s", dst->date);
34274 seq_printf(seq, "%8d ", dst->module_size);
34275 seq_printf(seq, "%8d ", dst->mpb_size);
34276 seq_printf(seq, "0x%04x", dst->module_flags);
34277@@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34278 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34279 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34280 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34281- seq_printf(seq, "Vendor info : %s\n",
34282- chtostr((u8 *) (work32 + 2), 16));
34283- seq_printf(seq, "Product info : %s\n",
34284- chtostr((u8 *) (work32 + 6), 16));
34285- seq_printf(seq, "Description : %s\n",
34286- chtostr((u8 *) (work32 + 10), 16));
34287- seq_printf(seq, "Product rev. : %s\n",
34288- chtostr((u8 *) (work32 + 14), 8));
34289+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34290+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34291+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34292+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34293
34294 seq_printf(seq, "Serial number : ");
34295 print_serial_number(seq, (u8 *) (work32 + 16),
34296@@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34297 }
34298
34299 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34300- seq_printf(seq, "Module name : %s\n",
34301- chtostr(result.module_name, 24));
34302- seq_printf(seq, "Module revision : %s\n",
34303- chtostr(result.module_rev, 8));
34304+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
34305+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34306
34307 seq_printf(seq, "Serial number : ");
34308 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34309@@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34310 return 0;
34311 }
34312
34313- seq_printf(seq, "Device name : %s\n",
34314- chtostr(result.device_name, 64));
34315- seq_printf(seq, "Service name : %s\n",
34316- chtostr(result.service_name, 64));
34317- seq_printf(seq, "Physical name : %s\n",
34318- chtostr(result.physical_location, 64));
34319- seq_printf(seq, "Instance number : %s\n",
34320- chtostr(result.instance_number, 4));
34321+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
34322+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
34323+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34324+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34325
34326 return 0;
34327 }
34328diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34329index a8c08f3..155fe3d 100644
34330--- a/drivers/message/i2o/iop.c
34331+++ b/drivers/message/i2o/iop.c
34332@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34333
34334 spin_lock_irqsave(&c->context_list_lock, flags);
34335
34336- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34337- atomic_inc(&c->context_list_counter);
34338+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34339+ atomic_inc_unchecked(&c->context_list_counter);
34340
34341- entry->context = atomic_read(&c->context_list_counter);
34342+ entry->context = atomic_read_unchecked(&c->context_list_counter);
34343
34344 list_add(&entry->list, &c->context_list);
34345
34346@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34347
34348 #if BITS_PER_LONG == 64
34349 spin_lock_init(&c->context_list_lock);
34350- atomic_set(&c->context_list_counter, 0);
34351+ atomic_set_unchecked(&c->context_list_counter, 0);
34352 INIT_LIST_HEAD(&c->context_list);
34353 #endif
34354
34355diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34356index 7ce65f4..e66e9bc 100644
34357--- a/drivers/mfd/abx500-core.c
34358+++ b/drivers/mfd/abx500-core.c
34359@@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34360
34361 struct abx500_device_entry {
34362 struct list_head list;
34363- struct abx500_ops ops;
34364+ abx500_ops_no_const ops;
34365 struct device *dev;
34366 };
34367
34368diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34369index a9223ed..4127b13 100644
34370--- a/drivers/mfd/janz-cmodio.c
34371+++ b/drivers/mfd/janz-cmodio.c
34372@@ -13,6 +13,7 @@
34373
34374 #include <linux/kernel.h>
34375 #include <linux/module.h>
34376+#include <linux/slab.h>
34377 #include <linux/init.h>
34378 #include <linux/pci.h>
34379 #include <linux/interrupt.h>
34380diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34381index a981e2a..5ca0c8b 100644
34382--- a/drivers/misc/lis3lv02d/lis3lv02d.c
34383+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34384@@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34385 * the lid is closed. This leads to interrupts as soon as a little move
34386 * is done.
34387 */
34388- atomic_inc(&lis3->count);
34389+ atomic_inc_unchecked(&lis3->count);
34390
34391 wake_up_interruptible(&lis3->misc_wait);
34392 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34393@@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34394 if (lis3->pm_dev)
34395 pm_runtime_get_sync(lis3->pm_dev);
34396
34397- atomic_set(&lis3->count, 0);
34398+ atomic_set_unchecked(&lis3->count, 0);
34399 return 0;
34400 }
34401
34402@@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34403 add_wait_queue(&lis3->misc_wait, &wait);
34404 while (true) {
34405 set_current_state(TASK_INTERRUPTIBLE);
34406- data = atomic_xchg(&lis3->count, 0);
34407+ data = atomic_xchg_unchecked(&lis3->count, 0);
34408 if (data)
34409 break;
34410
34411@@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34412 struct lis3lv02d, miscdev);
34413
34414 poll_wait(file, &lis3->misc_wait, wait);
34415- if (atomic_read(&lis3->count))
34416+ if (atomic_read_unchecked(&lis3->count))
34417 return POLLIN | POLLRDNORM;
34418 return 0;
34419 }
34420diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34421index 2b1482a..5d33616 100644
34422--- a/drivers/misc/lis3lv02d/lis3lv02d.h
34423+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34424@@ -266,7 +266,7 @@ struct lis3lv02d {
34425 struct input_polled_dev *idev; /* input device */
34426 struct platform_device *pdev; /* platform device */
34427 struct regulator_bulk_data regulators[2];
34428- atomic_t count; /* interrupt count after last read */
34429+ atomic_unchecked_t count; /* interrupt count after last read */
34430 union axis_conversion ac; /* hw -> logical axis */
34431 int mapped_btns[3];
34432
34433diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34434index 2f30bad..c4c13d0 100644
34435--- a/drivers/misc/sgi-gru/gruhandles.c
34436+++ b/drivers/misc/sgi-gru/gruhandles.c
34437@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34438 unsigned long nsec;
34439
34440 nsec = CLKS2NSEC(clks);
34441- atomic_long_inc(&mcs_op_statistics[op].count);
34442- atomic_long_add(nsec, &mcs_op_statistics[op].total);
34443+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34444+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34445 if (mcs_op_statistics[op].max < nsec)
34446 mcs_op_statistics[op].max = nsec;
34447 }
34448diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34449index 950dbe9..eeef0f8 100644
34450--- a/drivers/misc/sgi-gru/gruprocfs.c
34451+++ b/drivers/misc/sgi-gru/gruprocfs.c
34452@@ -32,9 +32,9 @@
34453
34454 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34455
34456-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34457+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34458 {
34459- unsigned long val = atomic_long_read(v);
34460+ unsigned long val = atomic_long_read_unchecked(v);
34461
34462 seq_printf(s, "%16lu %s\n", val, id);
34463 }
34464@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34465
34466 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34467 for (op = 0; op < mcsop_last; op++) {
34468- count = atomic_long_read(&mcs_op_statistics[op].count);
34469- total = atomic_long_read(&mcs_op_statistics[op].total);
34470+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34471+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34472 max = mcs_op_statistics[op].max;
34473 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34474 count ? total / count : 0, max);
34475diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34476index 5c3ce24..4915ccb 100644
34477--- a/drivers/misc/sgi-gru/grutables.h
34478+++ b/drivers/misc/sgi-gru/grutables.h
34479@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34480 * GRU statistics.
34481 */
34482 struct gru_stats_s {
34483- atomic_long_t vdata_alloc;
34484- atomic_long_t vdata_free;
34485- atomic_long_t gts_alloc;
34486- atomic_long_t gts_free;
34487- atomic_long_t gms_alloc;
34488- atomic_long_t gms_free;
34489- atomic_long_t gts_double_allocate;
34490- atomic_long_t assign_context;
34491- atomic_long_t assign_context_failed;
34492- atomic_long_t free_context;
34493- atomic_long_t load_user_context;
34494- atomic_long_t load_kernel_context;
34495- atomic_long_t lock_kernel_context;
34496- atomic_long_t unlock_kernel_context;
34497- atomic_long_t steal_user_context;
34498- atomic_long_t steal_kernel_context;
34499- atomic_long_t steal_context_failed;
34500- atomic_long_t nopfn;
34501- atomic_long_t asid_new;
34502- atomic_long_t asid_next;
34503- atomic_long_t asid_wrap;
34504- atomic_long_t asid_reuse;
34505- atomic_long_t intr;
34506- atomic_long_t intr_cbr;
34507- atomic_long_t intr_tfh;
34508- atomic_long_t intr_spurious;
34509- atomic_long_t intr_mm_lock_failed;
34510- atomic_long_t call_os;
34511- atomic_long_t call_os_wait_queue;
34512- atomic_long_t user_flush_tlb;
34513- atomic_long_t user_unload_context;
34514- atomic_long_t user_exception;
34515- atomic_long_t set_context_option;
34516- atomic_long_t check_context_retarget_intr;
34517- atomic_long_t check_context_unload;
34518- atomic_long_t tlb_dropin;
34519- atomic_long_t tlb_preload_page;
34520- atomic_long_t tlb_dropin_fail_no_asid;
34521- atomic_long_t tlb_dropin_fail_upm;
34522- atomic_long_t tlb_dropin_fail_invalid;
34523- atomic_long_t tlb_dropin_fail_range_active;
34524- atomic_long_t tlb_dropin_fail_idle;
34525- atomic_long_t tlb_dropin_fail_fmm;
34526- atomic_long_t tlb_dropin_fail_no_exception;
34527- atomic_long_t tfh_stale_on_fault;
34528- atomic_long_t mmu_invalidate_range;
34529- atomic_long_t mmu_invalidate_page;
34530- atomic_long_t flush_tlb;
34531- atomic_long_t flush_tlb_gru;
34532- atomic_long_t flush_tlb_gru_tgh;
34533- atomic_long_t flush_tlb_gru_zero_asid;
34534+ atomic_long_unchecked_t vdata_alloc;
34535+ atomic_long_unchecked_t vdata_free;
34536+ atomic_long_unchecked_t gts_alloc;
34537+ atomic_long_unchecked_t gts_free;
34538+ atomic_long_unchecked_t gms_alloc;
34539+ atomic_long_unchecked_t gms_free;
34540+ atomic_long_unchecked_t gts_double_allocate;
34541+ atomic_long_unchecked_t assign_context;
34542+ atomic_long_unchecked_t assign_context_failed;
34543+ atomic_long_unchecked_t free_context;
34544+ atomic_long_unchecked_t load_user_context;
34545+ atomic_long_unchecked_t load_kernel_context;
34546+ atomic_long_unchecked_t lock_kernel_context;
34547+ atomic_long_unchecked_t unlock_kernel_context;
34548+ atomic_long_unchecked_t steal_user_context;
34549+ atomic_long_unchecked_t steal_kernel_context;
34550+ atomic_long_unchecked_t steal_context_failed;
34551+ atomic_long_unchecked_t nopfn;
34552+ atomic_long_unchecked_t asid_new;
34553+ atomic_long_unchecked_t asid_next;
34554+ atomic_long_unchecked_t asid_wrap;
34555+ atomic_long_unchecked_t asid_reuse;
34556+ atomic_long_unchecked_t intr;
34557+ atomic_long_unchecked_t intr_cbr;
34558+ atomic_long_unchecked_t intr_tfh;
34559+ atomic_long_unchecked_t intr_spurious;
34560+ atomic_long_unchecked_t intr_mm_lock_failed;
34561+ atomic_long_unchecked_t call_os;
34562+ atomic_long_unchecked_t call_os_wait_queue;
34563+ atomic_long_unchecked_t user_flush_tlb;
34564+ atomic_long_unchecked_t user_unload_context;
34565+ atomic_long_unchecked_t user_exception;
34566+ atomic_long_unchecked_t set_context_option;
34567+ atomic_long_unchecked_t check_context_retarget_intr;
34568+ atomic_long_unchecked_t check_context_unload;
34569+ atomic_long_unchecked_t tlb_dropin;
34570+ atomic_long_unchecked_t tlb_preload_page;
34571+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34572+ atomic_long_unchecked_t tlb_dropin_fail_upm;
34573+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
34574+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
34575+ atomic_long_unchecked_t tlb_dropin_fail_idle;
34576+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
34577+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34578+ atomic_long_unchecked_t tfh_stale_on_fault;
34579+ atomic_long_unchecked_t mmu_invalidate_range;
34580+ atomic_long_unchecked_t mmu_invalidate_page;
34581+ atomic_long_unchecked_t flush_tlb;
34582+ atomic_long_unchecked_t flush_tlb_gru;
34583+ atomic_long_unchecked_t flush_tlb_gru_tgh;
34584+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34585
34586- atomic_long_t copy_gpa;
34587- atomic_long_t read_gpa;
34588+ atomic_long_unchecked_t copy_gpa;
34589+ atomic_long_unchecked_t read_gpa;
34590
34591- atomic_long_t mesq_receive;
34592- atomic_long_t mesq_receive_none;
34593- atomic_long_t mesq_send;
34594- atomic_long_t mesq_send_failed;
34595- atomic_long_t mesq_noop;
34596- atomic_long_t mesq_send_unexpected_error;
34597- atomic_long_t mesq_send_lb_overflow;
34598- atomic_long_t mesq_send_qlimit_reached;
34599- atomic_long_t mesq_send_amo_nacked;
34600- atomic_long_t mesq_send_put_nacked;
34601- atomic_long_t mesq_page_overflow;
34602- atomic_long_t mesq_qf_locked;
34603- atomic_long_t mesq_qf_noop_not_full;
34604- atomic_long_t mesq_qf_switch_head_failed;
34605- atomic_long_t mesq_qf_unexpected_error;
34606- atomic_long_t mesq_noop_unexpected_error;
34607- atomic_long_t mesq_noop_lb_overflow;
34608- atomic_long_t mesq_noop_qlimit_reached;
34609- atomic_long_t mesq_noop_amo_nacked;
34610- atomic_long_t mesq_noop_put_nacked;
34611- atomic_long_t mesq_noop_page_overflow;
34612+ atomic_long_unchecked_t mesq_receive;
34613+ atomic_long_unchecked_t mesq_receive_none;
34614+ atomic_long_unchecked_t mesq_send;
34615+ atomic_long_unchecked_t mesq_send_failed;
34616+ atomic_long_unchecked_t mesq_noop;
34617+ atomic_long_unchecked_t mesq_send_unexpected_error;
34618+ atomic_long_unchecked_t mesq_send_lb_overflow;
34619+ atomic_long_unchecked_t mesq_send_qlimit_reached;
34620+ atomic_long_unchecked_t mesq_send_amo_nacked;
34621+ atomic_long_unchecked_t mesq_send_put_nacked;
34622+ atomic_long_unchecked_t mesq_page_overflow;
34623+ atomic_long_unchecked_t mesq_qf_locked;
34624+ atomic_long_unchecked_t mesq_qf_noop_not_full;
34625+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
34626+ atomic_long_unchecked_t mesq_qf_unexpected_error;
34627+ atomic_long_unchecked_t mesq_noop_unexpected_error;
34628+ atomic_long_unchecked_t mesq_noop_lb_overflow;
34629+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
34630+ atomic_long_unchecked_t mesq_noop_amo_nacked;
34631+ atomic_long_unchecked_t mesq_noop_put_nacked;
34632+ atomic_long_unchecked_t mesq_noop_page_overflow;
34633
34634 };
34635
34636@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34637 tghop_invalidate, mcsop_last};
34638
34639 struct mcs_op_statistic {
34640- atomic_long_t count;
34641- atomic_long_t total;
34642+ atomic_long_unchecked_t count;
34643+ atomic_long_unchecked_t total;
34644 unsigned long max;
34645 };
34646
34647@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34648
34649 #define STAT(id) do { \
34650 if (gru_options & OPT_STATS) \
34651- atomic_long_inc(&gru_stats.id); \
34652+ atomic_long_inc_unchecked(&gru_stats.id); \
34653 } while (0)
34654
34655 #ifdef CONFIG_SGI_GRU_DEBUG
34656diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34657index 851b2f2..a4ec097 100644
34658--- a/drivers/misc/sgi-xp/xp.h
34659+++ b/drivers/misc/sgi-xp/xp.h
34660@@ -289,7 +289,7 @@ struct xpc_interface {
34661 xpc_notify_func, void *);
34662 void (*received) (short, int, void *);
34663 enum xp_retval (*partid_to_nasids) (short, void *);
34664-};
34665+} __no_const;
34666
34667 extern struct xpc_interface xpc_interface;
34668
34669diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34670index b94d5f7..7f494c5 100644
34671--- a/drivers/misc/sgi-xp/xpc.h
34672+++ b/drivers/misc/sgi-xp/xpc.h
34673@@ -835,6 +835,7 @@ struct xpc_arch_operations {
34674 void (*received_payload) (struct xpc_channel *, void *);
34675 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34676 };
34677+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34678
34679 /* struct xpc_partition act_state values (for XPC HB) */
34680
34681@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34682 /* found in xpc_main.c */
34683 extern struct device *xpc_part;
34684 extern struct device *xpc_chan;
34685-extern struct xpc_arch_operations xpc_arch_ops;
34686+extern xpc_arch_operations_no_const xpc_arch_ops;
34687 extern int xpc_disengage_timelimit;
34688 extern int xpc_disengage_timedout;
34689 extern int xpc_activate_IRQ_rcvd;
34690diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34691index 8d082b4..aa749ae 100644
34692--- a/drivers/misc/sgi-xp/xpc_main.c
34693+++ b/drivers/misc/sgi-xp/xpc_main.c
34694@@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34695 .notifier_call = xpc_system_die,
34696 };
34697
34698-struct xpc_arch_operations xpc_arch_ops;
34699+xpc_arch_operations_no_const xpc_arch_ops;
34700
34701 /*
34702 * Timer function to enforce the timelimit on the partition disengage.
34703diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34704index 6ebdc40..9edf5d8 100644
34705--- a/drivers/mmc/host/sdhci-pci.c
34706+++ b/drivers/mmc/host/sdhci-pci.c
34707@@ -631,7 +631,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34708 .probe = via_probe,
34709 };
34710
34711-static const struct pci_device_id pci_ids[] __devinitdata = {
34712+static const struct pci_device_id pci_ids[] __devinitconst = {
34713 {
34714 .vendor = PCI_VENDOR_ID_RICOH,
34715 .device = PCI_DEVICE_ID_RICOH_R5C822,
34716diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34717index 87a431c..4959b43 100644
34718--- a/drivers/mtd/devices/doc2000.c
34719+++ b/drivers/mtd/devices/doc2000.c
34720@@ -764,7 +764,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34721
34722 /* The ECC will not be calculated correctly if less than 512 is written */
34723 /* DBB-
34724- if (len != 0x200 && eccbuf)
34725+ if (len != 0x200)
34726 printk(KERN_WARNING
34727 "ECC needs a full sector write (adr: %lx size %lx)\n",
34728 (long) to, (long) len);
34729diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
34730index 9eacf67..4534b5b 100644
34731--- a/drivers/mtd/devices/doc2001.c
34732+++ b/drivers/mtd/devices/doc2001.c
34733@@ -384,7 +384,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
34734 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
34735
34736 /* Don't allow read past end of device */
34737- if (from >= this->totlen)
34738+ if (from >= this->totlen || !len)
34739 return -EINVAL;
34740
34741 /* Don't allow a single read to cross a 512-byte block boundary */
34742diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34743index 3984d48..28aa897 100644
34744--- a/drivers/mtd/nand/denali.c
34745+++ b/drivers/mtd/nand/denali.c
34746@@ -26,6 +26,7 @@
34747 #include <linux/pci.h>
34748 #include <linux/mtd/mtd.h>
34749 #include <linux/module.h>
34750+#include <linux/slab.h>
34751
34752 #include "denali.h"
34753
34754diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34755index 51b9d6a..52af9a7 100644
34756--- a/drivers/mtd/nftlmount.c
34757+++ b/drivers/mtd/nftlmount.c
34758@@ -24,6 +24,7 @@
34759 #include <asm/errno.h>
34760 #include <linux/delay.h>
34761 #include <linux/slab.h>
34762+#include <linux/sched.h>
34763 #include <linux/mtd/mtd.h>
34764 #include <linux/mtd/nand.h>
34765 #include <linux/mtd/nftl.h>
34766diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34767index 071f4c8..440862e 100644
34768--- a/drivers/net/ethernet/atheros/atlx/atl2.c
34769+++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34770@@ -2862,7 +2862,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34771 */
34772
34773 #define ATL2_PARAM(X, desc) \
34774- static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34775+ static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34776 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34777 MODULE_PARM_DESC(X, desc);
34778 #else
34779diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34780index 66da39f..5dc436d 100644
34781--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34782+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34783@@ -473,7 +473,7 @@ struct bnx2x_rx_mode_obj {
34784
34785 int (*wait_comp)(struct bnx2x *bp,
34786 struct bnx2x_rx_mode_ramrod_params *p);
34787-};
34788+} __no_const;
34789
34790 /********************** Set multicast group ***********************************/
34791
34792diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34793index aea8f72..fcebf75 100644
34794--- a/drivers/net/ethernet/broadcom/tg3.h
34795+++ b/drivers/net/ethernet/broadcom/tg3.h
34796@@ -140,6 +140,7 @@
34797 #define CHIPREV_ID_5750_A0 0x4000
34798 #define CHIPREV_ID_5750_A1 0x4001
34799 #define CHIPREV_ID_5750_A3 0x4003
34800+#define CHIPREV_ID_5750_C1 0x4201
34801 #define CHIPREV_ID_5750_C2 0x4202
34802 #define CHIPREV_ID_5752_A0_HW 0x5000
34803 #define CHIPREV_ID_5752_A0 0x6000
34804diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34805index c4e8643..0979484 100644
34806--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34807+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34808@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34809 */
34810 struct l2t_skb_cb {
34811 arp_failure_handler_func arp_failure_handler;
34812-};
34813+} __no_const;
34814
34815 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34816
34817diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34818index 4d71f5a..8004440 100644
34819--- a/drivers/net/ethernet/dec/tulip/de4x5.c
34820+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34821@@ -5392,7 +5392,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34822 for (i=0; i<ETH_ALEN; i++) {
34823 tmp.addr[i] = dev->dev_addr[i];
34824 }
34825- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34826+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34827 break;
34828
34829 case DE4X5_SET_HWADDR: /* Set the hardware address */
34830@@ -5432,7 +5432,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34831 spin_lock_irqsave(&lp->lock, flags);
34832 memcpy(&statbuf, &lp->pktStats, ioc->len);
34833 spin_unlock_irqrestore(&lp->lock, flags);
34834- if (copy_to_user(ioc->data, &statbuf, ioc->len))
34835+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34836 return -EFAULT;
34837 break;
34838 }
34839diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34840index 14d5b61..1398636 100644
34841--- a/drivers/net/ethernet/dec/tulip/eeprom.c
34842+++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34843@@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34844 {NULL}};
34845
34846
34847-static const char *block_name[] __devinitdata = {
34848+static const char *block_name[] __devinitconst = {
34849 "21140 non-MII",
34850 "21140 MII PHY",
34851 "21142 Serial PHY",
34852diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34853index 52da7b2..4ddfe1c 100644
34854--- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34855+++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34856@@ -236,7 +236,7 @@ struct pci_id_info {
34857 int drv_flags; /* Driver use, intended as capability flags. */
34858 };
34859
34860-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34861+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34862 { /* Sometime a Level-One switch card. */
34863 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34864 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34865diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34866index 28a3a9b..d96cb63 100644
34867--- a/drivers/net/ethernet/dlink/sundance.c
34868+++ b/drivers/net/ethernet/dlink/sundance.c
34869@@ -218,7 +218,7 @@ enum {
34870 struct pci_id_info {
34871 const char *name;
34872 };
34873-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34874+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34875 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34876 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34877 {"D-Link DFE-580TX 4 port Server Adapter"},
34878diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34879index e703d64..d62ecf9 100644
34880--- a/drivers/net/ethernet/emulex/benet/be_main.c
34881+++ b/drivers/net/ethernet/emulex/benet/be_main.c
34882@@ -402,7 +402,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34883
34884 if (wrapped)
34885 newacc += 65536;
34886- ACCESS_ONCE(*acc) = newacc;
34887+ ACCESS_ONCE_RW(*acc) = newacc;
34888 }
34889
34890 void be_parse_stats(struct be_adapter *adapter)
34891diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34892index 47f85c3..82ab6c4 100644
34893--- a/drivers/net/ethernet/faraday/ftgmac100.c
34894+++ b/drivers/net/ethernet/faraday/ftgmac100.c
34895@@ -31,6 +31,8 @@
34896 #include <linux/netdevice.h>
34897 #include <linux/phy.h>
34898 #include <linux/platform_device.h>
34899+#include <linux/interrupt.h>
34900+#include <linux/irqreturn.h>
34901 #include <net/ip.h>
34902
34903 #include "ftgmac100.h"
34904diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34905index bb336a0..4b472da 100644
34906--- a/drivers/net/ethernet/faraday/ftmac100.c
34907+++ b/drivers/net/ethernet/faraday/ftmac100.c
34908@@ -31,6 +31,8 @@
34909 #include <linux/module.h>
34910 #include <linux/netdevice.h>
34911 #include <linux/platform_device.h>
34912+#include <linux/interrupt.h>
34913+#include <linux/irqreturn.h>
34914
34915 #include "ftmac100.h"
34916
34917diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34918index c82d444..0007fb4 100644
34919--- a/drivers/net/ethernet/fealnx.c
34920+++ b/drivers/net/ethernet/fealnx.c
34921@@ -150,7 +150,7 @@ struct chip_info {
34922 int flags;
34923 };
34924
34925-static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34926+static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34927 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34928 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34929 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34930diff --git a/drivers/net/ethernet/intel/e1000e/80003es2lan.c b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34931index e1159e5..e18684d 100644
34932--- a/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34933+++ b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34934@@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
34935 {
34936 struct e1000_hw *hw = &adapter->hw;
34937 struct e1000_mac_info *mac = &hw->mac;
34938- struct e1000_mac_operations *func = &mac->ops;
34939+ e1000_mac_operations_no_const *func = &mac->ops;
34940
34941 /* Set media type */
34942 switch (adapter->pdev->device) {
34943diff --git a/drivers/net/ethernet/intel/e1000e/82571.c b/drivers/net/ethernet/intel/e1000e/82571.c
34944index a3e65fd..f451444 100644
34945--- a/drivers/net/ethernet/intel/e1000e/82571.c
34946+++ b/drivers/net/ethernet/intel/e1000e/82571.c
34947@@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
34948 {
34949 struct e1000_hw *hw = &adapter->hw;
34950 struct e1000_mac_info *mac = &hw->mac;
34951- struct e1000_mac_operations *func = &mac->ops;
34952+ e1000_mac_operations_no_const *func = &mac->ops;
34953 u32 swsm = 0;
34954 u32 swsm2 = 0;
34955 bool force_clear_smbi = false;
34956diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34957index 2967039..ca8c40c 100644
34958--- a/drivers/net/ethernet/intel/e1000e/hw.h
34959+++ b/drivers/net/ethernet/intel/e1000e/hw.h
34960@@ -778,6 +778,7 @@ struct e1000_mac_operations {
34961 void (*write_vfta)(struct e1000_hw *, u32, u32);
34962 s32 (*read_mac_addr)(struct e1000_hw *);
34963 };
34964+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34965
34966 /*
34967 * When to use various PHY register access functions:
34968@@ -818,6 +819,7 @@ struct e1000_phy_operations {
34969 void (*power_up)(struct e1000_hw *);
34970 void (*power_down)(struct e1000_hw *);
34971 };
34972+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34973
34974 /* Function pointers for the NVM. */
34975 struct e1000_nvm_operations {
34976@@ -829,9 +831,10 @@ struct e1000_nvm_operations {
34977 s32 (*validate)(struct e1000_hw *);
34978 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34979 };
34980+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34981
34982 struct e1000_mac_info {
34983- struct e1000_mac_operations ops;
34984+ e1000_mac_operations_no_const ops;
34985 u8 addr[ETH_ALEN];
34986 u8 perm_addr[ETH_ALEN];
34987
34988@@ -872,7 +875,7 @@ struct e1000_mac_info {
34989 };
34990
34991 struct e1000_phy_info {
34992- struct e1000_phy_operations ops;
34993+ e1000_phy_operations_no_const ops;
34994
34995 enum e1000_phy_type type;
34996
34997@@ -906,7 +909,7 @@ struct e1000_phy_info {
34998 };
34999
35000 struct e1000_nvm_info {
35001- struct e1000_nvm_operations ops;
35002+ e1000_nvm_operations_no_const ops;
35003
35004 enum e1000_nvm_type type;
35005 enum e1000_nvm_override override;
35006diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35007index f67cbd3..cef9e3d 100644
35008--- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35009+++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35010@@ -314,6 +314,7 @@ struct e1000_mac_operations {
35011 s32 (*read_mac_addr)(struct e1000_hw *);
35012 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
35013 };
35014+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35015
35016 struct e1000_phy_operations {
35017 s32 (*acquire)(struct e1000_hw *);
35018@@ -330,6 +331,7 @@ struct e1000_phy_operations {
35019 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35020 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35021 };
35022+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35023
35024 struct e1000_nvm_operations {
35025 s32 (*acquire)(struct e1000_hw *);
35026@@ -339,6 +341,7 @@ struct e1000_nvm_operations {
35027 s32 (*update)(struct e1000_hw *);
35028 s32 (*validate)(struct e1000_hw *);
35029 };
35030+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35031
35032 struct e1000_info {
35033 s32 (*get_invariants)(struct e1000_hw *);
35034@@ -350,7 +353,7 @@ struct e1000_info {
35035 extern const struct e1000_info e1000_82575_info;
35036
35037 struct e1000_mac_info {
35038- struct e1000_mac_operations ops;
35039+ e1000_mac_operations_no_const ops;
35040
35041 u8 addr[6];
35042 u8 perm_addr[6];
35043@@ -388,7 +391,7 @@ struct e1000_mac_info {
35044 };
35045
35046 struct e1000_phy_info {
35047- struct e1000_phy_operations ops;
35048+ e1000_phy_operations_no_const ops;
35049
35050 enum e1000_phy_type type;
35051
35052@@ -423,7 +426,7 @@ struct e1000_phy_info {
35053 };
35054
35055 struct e1000_nvm_info {
35056- struct e1000_nvm_operations ops;
35057+ e1000_nvm_operations_no_const ops;
35058 enum e1000_nvm_type type;
35059 enum e1000_nvm_override override;
35060
35061@@ -468,6 +471,7 @@ struct e1000_mbx_operations {
35062 s32 (*check_for_ack)(struct e1000_hw *, u16);
35063 s32 (*check_for_rst)(struct e1000_hw *, u16);
35064 };
35065+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35066
35067 struct e1000_mbx_stats {
35068 u32 msgs_tx;
35069@@ -479,7 +483,7 @@ struct e1000_mbx_stats {
35070 };
35071
35072 struct e1000_mbx_info {
35073- struct e1000_mbx_operations ops;
35074+ e1000_mbx_operations_no_const ops;
35075 struct e1000_mbx_stats stats;
35076 u32 timeout;
35077 u32 usec_delay;
35078diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35079index 57db3c6..aa825fc 100644
35080--- a/drivers/net/ethernet/intel/igbvf/vf.h
35081+++ b/drivers/net/ethernet/intel/igbvf/vf.h
35082@@ -189,9 +189,10 @@ struct e1000_mac_operations {
35083 s32 (*read_mac_addr)(struct e1000_hw *);
35084 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35085 };
35086+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35087
35088 struct e1000_mac_info {
35089- struct e1000_mac_operations ops;
35090+ e1000_mac_operations_no_const ops;
35091 u8 addr[6];
35092 u8 perm_addr[6];
35093
35094@@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35095 s32 (*check_for_ack)(struct e1000_hw *);
35096 s32 (*check_for_rst)(struct e1000_hw *);
35097 };
35098+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35099
35100 struct e1000_mbx_stats {
35101 u32 msgs_tx;
35102@@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35103 };
35104
35105 struct e1000_mbx_info {
35106- struct e1000_mbx_operations ops;
35107+ e1000_mbx_operations_no_const ops;
35108 struct e1000_mbx_stats stats;
35109 u32 timeout;
35110 u32 usec_delay;
35111diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35112index 9b95bef..7e254ee 100644
35113--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35114+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35115@@ -2708,6 +2708,7 @@ struct ixgbe_eeprom_operations {
35116 s32 (*update_checksum)(struct ixgbe_hw *);
35117 u16 (*calc_checksum)(struct ixgbe_hw *);
35118 };
35119+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35120
35121 struct ixgbe_mac_operations {
35122 s32 (*init_hw)(struct ixgbe_hw *);
35123@@ -2769,6 +2770,7 @@ struct ixgbe_mac_operations {
35124 /* Manageability interface */
35125 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
35126 };
35127+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35128
35129 struct ixgbe_phy_operations {
35130 s32 (*identify)(struct ixgbe_hw *);
35131@@ -2788,9 +2790,10 @@ struct ixgbe_phy_operations {
35132 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35133 s32 (*check_overtemp)(struct ixgbe_hw *);
35134 };
35135+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35136
35137 struct ixgbe_eeprom_info {
35138- struct ixgbe_eeprom_operations ops;
35139+ ixgbe_eeprom_operations_no_const ops;
35140 enum ixgbe_eeprom_type type;
35141 u32 semaphore_delay;
35142 u16 word_size;
35143@@ -2800,7 +2803,7 @@ struct ixgbe_eeprom_info {
35144
35145 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35146 struct ixgbe_mac_info {
35147- struct ixgbe_mac_operations ops;
35148+ ixgbe_mac_operations_no_const ops;
35149 enum ixgbe_mac_type type;
35150 u8 addr[ETH_ALEN];
35151 u8 perm_addr[ETH_ALEN];
35152@@ -2828,7 +2831,7 @@ struct ixgbe_mac_info {
35153 };
35154
35155 struct ixgbe_phy_info {
35156- struct ixgbe_phy_operations ops;
35157+ ixgbe_phy_operations_no_const ops;
35158 struct mdio_if_info mdio;
35159 enum ixgbe_phy_type type;
35160 u32 id;
35161@@ -2856,6 +2859,7 @@ struct ixgbe_mbx_operations {
35162 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35163 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35164 };
35165+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35166
35167 struct ixgbe_mbx_stats {
35168 u32 msgs_tx;
35169@@ -2867,7 +2871,7 @@ struct ixgbe_mbx_stats {
35170 };
35171
35172 struct ixgbe_mbx_info {
35173- struct ixgbe_mbx_operations ops;
35174+ ixgbe_mbx_operations_no_const ops;
35175 struct ixgbe_mbx_stats stats;
35176 u32 timeout;
35177 u32 usec_delay;
35178diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35179index 25c951d..cc7cf33 100644
35180--- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35181+++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35182@@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35183 s32 (*clear_vfta)(struct ixgbe_hw *);
35184 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35185 };
35186+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35187
35188 enum ixgbe_mac_type {
35189 ixgbe_mac_unknown = 0,
35190@@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35191 };
35192
35193 struct ixgbe_mac_info {
35194- struct ixgbe_mac_operations ops;
35195+ ixgbe_mac_operations_no_const ops;
35196 u8 addr[6];
35197 u8 perm_addr[6];
35198
35199@@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35200 s32 (*check_for_ack)(struct ixgbe_hw *);
35201 s32 (*check_for_rst)(struct ixgbe_hw *);
35202 };
35203+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35204
35205 struct ixgbe_mbx_stats {
35206 u32 msgs_tx;
35207@@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35208 };
35209
35210 struct ixgbe_mbx_info {
35211- struct ixgbe_mbx_operations ops;
35212+ ixgbe_mbx_operations_no_const ops;
35213 struct ixgbe_mbx_stats stats;
35214 u32 timeout;
35215 u32 udelay;
35216diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
35217index 8bf22b6..7f5baaa 100644
35218--- a/drivers/net/ethernet/mellanox/mlx4/main.c
35219+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
35220@@ -41,6 +41,7 @@
35221 #include <linux/slab.h>
35222 #include <linux/io-mapping.h>
35223 #include <linux/delay.h>
35224+#include <linux/sched.h>
35225
35226 #include <linux/mlx4/device.h>
35227 #include <linux/mlx4/doorbell.h>
35228diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35229index 5046a64..71ca936 100644
35230--- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35231+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35232@@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35233 void (*link_down)(struct __vxge_hw_device *devh);
35234 void (*crit_err)(struct __vxge_hw_device *devh,
35235 enum vxge_hw_event type, u64 ext_data);
35236-};
35237+} __no_const;
35238
35239 /*
35240 * struct __vxge_hw_blockpool_entry - Block private data structure
35241diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35242index 4a518a3..936b334 100644
35243--- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35244+++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35245@@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35246 struct vxge_hw_mempool_dma *dma_object,
35247 u32 index,
35248 u32 is_last);
35249-};
35250+} __no_const;
35251
35252 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35253 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35254diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35255index bbacb37..d60887d 100644
35256--- a/drivers/net/ethernet/realtek/r8169.c
35257+++ b/drivers/net/ethernet/realtek/r8169.c
35258@@ -695,17 +695,17 @@ struct rtl8169_private {
35259 struct mdio_ops {
35260 void (*write)(void __iomem *, int, int);
35261 int (*read)(void __iomem *, int);
35262- } mdio_ops;
35263+ } __no_const mdio_ops;
35264
35265 struct pll_power_ops {
35266 void (*down)(struct rtl8169_private *);
35267 void (*up)(struct rtl8169_private *);
35268- } pll_power_ops;
35269+ } __no_const pll_power_ops;
35270
35271 struct jumbo_ops {
35272 void (*enable)(struct rtl8169_private *);
35273 void (*disable)(struct rtl8169_private *);
35274- } jumbo_ops;
35275+ } __no_const jumbo_ops;
35276
35277 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35278 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35279diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35280index 5b118cd..858b523 100644
35281--- a/drivers/net/ethernet/sis/sis190.c
35282+++ b/drivers/net/ethernet/sis/sis190.c
35283@@ -1622,7 +1622,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35284 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35285 struct net_device *dev)
35286 {
35287- static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35288+ static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35289 struct sis190_private *tp = netdev_priv(dev);
35290 struct pci_dev *isa_bridge;
35291 u8 reg, tmp8;
35292diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35293index c07cfe9..81cbf7e 100644
35294--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35295+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35296@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35297
35298 writel(value, ioaddr + MMC_CNTRL);
35299
35300- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35301- MMC_CNTRL, value);
35302+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35303+// MMC_CNTRL, value);
35304 }
35305
35306 /* To mask all all interrupts.*/
35307diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
35308index 6ee593a..3f513b1 100644
35309--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
35310+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
35311@@ -1585,7 +1585,7 @@ static const struct file_operations stmmac_rings_status_fops = {
35312 .open = stmmac_sysfs_ring_open,
35313 .read = seq_read,
35314 .llseek = seq_lseek,
35315- .release = seq_release,
35316+ .release = single_release,
35317 };
35318
35319 static int stmmac_sysfs_dma_cap_read(struct seq_file *seq, void *v)
35320@@ -1657,7 +1657,7 @@ static const struct file_operations stmmac_dma_cap_fops = {
35321 .open = stmmac_sysfs_dma_cap_open,
35322 .read = seq_read,
35323 .llseek = seq_lseek,
35324- .release = seq_release,
35325+ .release = single_release,
35326 };
35327
35328 static int stmmac_init_fs(struct net_device *dev)
35329diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35330index dec5836..6d4db7d 100644
35331--- a/drivers/net/hyperv/hyperv_net.h
35332+++ b/drivers/net/hyperv/hyperv_net.h
35333@@ -97,7 +97,7 @@ struct rndis_device {
35334
35335 enum rndis_device_state state;
35336 bool link_state;
35337- atomic_t new_req_id;
35338+ atomic_unchecked_t new_req_id;
35339
35340 spinlock_t request_lock;
35341 struct list_head req_list;
35342diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35343index 133b7fb..d58c559 100644
35344--- a/drivers/net/hyperv/rndis_filter.c
35345+++ b/drivers/net/hyperv/rndis_filter.c
35346@@ -96,7 +96,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35347 * template
35348 */
35349 set = &rndis_msg->msg.set_req;
35350- set->req_id = atomic_inc_return(&dev->new_req_id);
35351+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35352
35353 /* Add to the request list */
35354 spin_lock_irqsave(&dev->request_lock, flags);
35355@@ -627,7 +627,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35356
35357 /* Setup the rndis set */
35358 halt = &request->request_msg.msg.halt_req;
35359- halt->req_id = atomic_inc_return(&dev->new_req_id);
35360+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35361
35362 /* Ignore return since this msg is optional. */
35363 rndis_filter_send_request(dev, request);
35364diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
35365index 58dc117..f140c77 100644
35366--- a/drivers/net/macvtap.c
35367+++ b/drivers/net/macvtap.c
35368@@ -526,6 +526,8 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
35369 }
35370 base = (unsigned long)from->iov_base + offset1;
35371 size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
35372+ if (i + size >= MAX_SKB_FRAGS)
35373+ return -EFAULT;
35374 num_pages = get_user_pages_fast(base, size, 0, &page[i]);
35375 if ((num_pages != size) ||
35376 (num_pages > MAX_SKB_FRAGS - skb_shinfo(skb)->nr_frags))
35377diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35378index 3ed983c..a1bb418 100644
35379--- a/drivers/net/ppp/ppp_generic.c
35380+++ b/drivers/net/ppp/ppp_generic.c
35381@@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35382 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35383 struct ppp_stats stats;
35384 struct ppp_comp_stats cstats;
35385- char *vers;
35386
35387 switch (cmd) {
35388 case SIOCGPPPSTATS:
35389@@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35390 break;
35391
35392 case SIOCGPPPVER:
35393- vers = PPP_VERSION;
35394- if (copy_to_user(addr, vers, strlen(vers) + 1))
35395+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35396 break;
35397 err = 0;
35398 break;
35399diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
35400index 515f122..41dd273 100644
35401--- a/drivers/net/tokenring/abyss.c
35402+++ b/drivers/net/tokenring/abyss.c
35403@@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
35404
35405 static int __init abyss_init (void)
35406 {
35407- abyss_netdev_ops = tms380tr_netdev_ops;
35408+ pax_open_kernel();
35409+ memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35410
35411- abyss_netdev_ops.ndo_open = abyss_open;
35412- abyss_netdev_ops.ndo_stop = abyss_close;
35413+ *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
35414+ *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
35415+ pax_close_kernel();
35416
35417 return pci_register_driver(&abyss_driver);
35418 }
35419diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
35420index 6153cfd..cf69c1c 100644
35421--- a/drivers/net/tokenring/madgemc.c
35422+++ b/drivers/net/tokenring/madgemc.c
35423@@ -744,9 +744,11 @@ static struct mca_driver madgemc_driver = {
35424
35425 static int __init madgemc_init (void)
35426 {
35427- madgemc_netdev_ops = tms380tr_netdev_ops;
35428- madgemc_netdev_ops.ndo_open = madgemc_open;
35429- madgemc_netdev_ops.ndo_stop = madgemc_close;
35430+ pax_open_kernel();
35431+ memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35432+ *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
35433+ *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
35434+ pax_close_kernel();
35435
35436 return mca_register_driver (&madgemc_driver);
35437 }
35438diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
35439index 8d362e6..f91cc52 100644
35440--- a/drivers/net/tokenring/proteon.c
35441+++ b/drivers/net/tokenring/proteon.c
35442@@ -353,9 +353,11 @@ static int __init proteon_init(void)
35443 struct platform_device *pdev;
35444 int i, num = 0, err = 0;
35445
35446- proteon_netdev_ops = tms380tr_netdev_ops;
35447- proteon_netdev_ops.ndo_open = proteon_open;
35448- proteon_netdev_ops.ndo_stop = tms380tr_close;
35449+ pax_open_kernel();
35450+ memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35451+ *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
35452+ *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
35453+ pax_close_kernel();
35454
35455 err = platform_driver_register(&proteon_driver);
35456 if (err)
35457diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
35458index 46db5c5..37c1536 100644
35459--- a/drivers/net/tokenring/skisa.c
35460+++ b/drivers/net/tokenring/skisa.c
35461@@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
35462 struct platform_device *pdev;
35463 int i, num = 0, err = 0;
35464
35465- sk_isa_netdev_ops = tms380tr_netdev_ops;
35466- sk_isa_netdev_ops.ndo_open = sk_isa_open;
35467- sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35468+ pax_open_kernel();
35469+ memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35470+ *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
35471+ *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35472+ pax_close_kernel();
35473
35474 err = platform_driver_register(&sk_isa_driver);
35475 if (err)
35476diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35477index e1324b4..e1b0041 100644
35478--- a/drivers/net/usb/hso.c
35479+++ b/drivers/net/usb/hso.c
35480@@ -71,7 +71,7 @@
35481 #include <asm/byteorder.h>
35482 #include <linux/serial_core.h>
35483 #include <linux/serial.h>
35484-
35485+#include <asm/local.h>
35486
35487 #define MOD_AUTHOR "Option Wireless"
35488 #define MOD_DESCRIPTION "USB High Speed Option driver"
35489@@ -257,7 +257,7 @@ struct hso_serial {
35490
35491 /* from usb_serial_port */
35492 struct tty_struct *tty;
35493- int open_count;
35494+ local_t open_count;
35495 spinlock_t serial_lock;
35496
35497 int (*write_data) (struct hso_serial *serial);
35498@@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35499 struct urb *urb;
35500
35501 urb = serial->rx_urb[0];
35502- if (serial->open_count > 0) {
35503+ if (local_read(&serial->open_count) > 0) {
35504 count = put_rxbuf_data(urb, serial);
35505 if (count == -1)
35506 return;
35507@@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35508 DUMP1(urb->transfer_buffer, urb->actual_length);
35509
35510 /* Anyone listening? */
35511- if (serial->open_count == 0)
35512+ if (local_read(&serial->open_count) == 0)
35513 return;
35514
35515 if (status == 0) {
35516@@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35517 spin_unlock_irq(&serial->serial_lock);
35518
35519 /* check for port already opened, if not set the termios */
35520- serial->open_count++;
35521- if (serial->open_count == 1) {
35522+ if (local_inc_return(&serial->open_count) == 1) {
35523 serial->rx_state = RX_IDLE;
35524 /* Force default termio settings */
35525 _hso_serial_set_termios(tty, NULL);
35526@@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35527 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35528 if (result) {
35529 hso_stop_serial_device(serial->parent);
35530- serial->open_count--;
35531+ local_dec(&serial->open_count);
35532 kref_put(&serial->parent->ref, hso_serial_ref_free);
35533 }
35534 } else {
35535@@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35536
35537 /* reset the rts and dtr */
35538 /* do the actual close */
35539- serial->open_count--;
35540+ local_dec(&serial->open_count);
35541
35542- if (serial->open_count <= 0) {
35543- serial->open_count = 0;
35544+ if (local_read(&serial->open_count) <= 0) {
35545+ local_set(&serial->open_count, 0);
35546 spin_lock_irq(&serial->serial_lock);
35547 if (serial->tty == tty) {
35548 serial->tty->driver_data = NULL;
35549@@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35550
35551 /* the actual setup */
35552 spin_lock_irqsave(&serial->serial_lock, flags);
35553- if (serial->open_count)
35554+ if (local_read(&serial->open_count))
35555 _hso_serial_set_termios(tty, old);
35556 else
35557 tty->termios = old;
35558@@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
35559 D1("Pending read interrupt on port %d\n", i);
35560 spin_lock(&serial->serial_lock);
35561 if (serial->rx_state == RX_IDLE &&
35562- serial->open_count > 0) {
35563+ local_read(&serial->open_count) > 0) {
35564 /* Setup and send a ctrl req read on
35565 * port i */
35566 if (!serial->rx_urb_filled[0]) {
35567@@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
35568 /* Start all serial ports */
35569 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35570 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35571- if (dev2ser(serial_table[i])->open_count) {
35572+ if (local_read(&dev2ser(serial_table[i])->open_count)) {
35573 result =
35574 hso_start_serial_device(serial_table[i], GFP_NOIO);
35575 hso_kick_transmit(dev2ser(serial_table[i]));
35576diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35577index efc0111..79c8f5b 100644
35578--- a/drivers/net/wireless/ath/ath.h
35579+++ b/drivers/net/wireless/ath/ath.h
35580@@ -119,6 +119,7 @@ struct ath_ops {
35581 void (*write_flush) (void *);
35582 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35583 };
35584+typedef struct ath_ops __no_const ath_ops_no_const;
35585
35586 struct ath_common;
35587 struct ath_bus_ops;
35588diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35589index 7b6417b..ab5db98 100644
35590--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35591+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35592@@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35593 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35594 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35595
35596- ACCESS_ONCE(ads->ds_link) = i->link;
35597- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35598+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
35599+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35600
35601 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35602 ctl6 = SM(i->keytype, AR_EncrType);
35603@@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35604
35605 if ((i->is_first || i->is_last) &&
35606 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35607- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35608+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35609 | set11nTries(i->rates, 1)
35610 | set11nTries(i->rates, 2)
35611 | set11nTries(i->rates, 3)
35612 | (i->dur_update ? AR_DurUpdateEna : 0)
35613 | SM(0, AR_BurstDur);
35614
35615- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35616+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35617 | set11nRate(i->rates, 1)
35618 | set11nRate(i->rates, 2)
35619 | set11nRate(i->rates, 3);
35620 } else {
35621- ACCESS_ONCE(ads->ds_ctl2) = 0;
35622- ACCESS_ONCE(ads->ds_ctl3) = 0;
35623+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35624+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35625 }
35626
35627 if (!i->is_first) {
35628- ACCESS_ONCE(ads->ds_ctl0) = 0;
35629- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35630- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35631+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35632+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35633+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35634 return;
35635 }
35636
35637@@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35638 break;
35639 }
35640
35641- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35642+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35643 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35644 | SM(i->txpower, AR_XmitPower)
35645 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35646@@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35647 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35648 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35649
35650- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35651- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35652+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35653+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35654
35655 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35656 return;
35657
35658- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35659+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35660 | set11nPktDurRTSCTS(i->rates, 1);
35661
35662- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35663+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35664 | set11nPktDurRTSCTS(i->rates, 3);
35665
35666- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35667+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35668 | set11nRateFlags(i->rates, 1)
35669 | set11nRateFlags(i->rates, 2)
35670 | set11nRateFlags(i->rates, 3)
35671diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35672index 09b8c9d..905339e 100644
35673--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35674+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35675@@ -35,47 +35,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35676 (i->qcu << AR_TxQcuNum_S) | 0x17;
35677
35678 checksum += val;
35679- ACCESS_ONCE(ads->info) = val;
35680+ ACCESS_ONCE_RW(ads->info) = val;
35681
35682 checksum += i->link;
35683- ACCESS_ONCE(ads->link) = i->link;
35684+ ACCESS_ONCE_RW(ads->link) = i->link;
35685
35686 checksum += i->buf_addr[0];
35687- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35688+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35689 checksum += i->buf_addr[1];
35690- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35691+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35692 checksum += i->buf_addr[2];
35693- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35694+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35695 checksum += i->buf_addr[3];
35696- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35697+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35698
35699 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35700- ACCESS_ONCE(ads->ctl3) = val;
35701+ ACCESS_ONCE_RW(ads->ctl3) = val;
35702 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35703- ACCESS_ONCE(ads->ctl5) = val;
35704+ ACCESS_ONCE_RW(ads->ctl5) = val;
35705 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35706- ACCESS_ONCE(ads->ctl7) = val;
35707+ ACCESS_ONCE_RW(ads->ctl7) = val;
35708 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35709- ACCESS_ONCE(ads->ctl9) = val;
35710+ ACCESS_ONCE_RW(ads->ctl9) = val;
35711
35712 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35713- ACCESS_ONCE(ads->ctl10) = checksum;
35714+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
35715
35716 if (i->is_first || i->is_last) {
35717- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35718+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35719 | set11nTries(i->rates, 1)
35720 | set11nTries(i->rates, 2)
35721 | set11nTries(i->rates, 3)
35722 | (i->dur_update ? AR_DurUpdateEna : 0)
35723 | SM(0, AR_BurstDur);
35724
35725- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35726+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35727 | set11nRate(i->rates, 1)
35728 | set11nRate(i->rates, 2)
35729 | set11nRate(i->rates, 3);
35730 } else {
35731- ACCESS_ONCE(ads->ctl13) = 0;
35732- ACCESS_ONCE(ads->ctl14) = 0;
35733+ ACCESS_ONCE_RW(ads->ctl13) = 0;
35734+ ACCESS_ONCE_RW(ads->ctl14) = 0;
35735 }
35736
35737 ads->ctl20 = 0;
35738@@ -84,17 +84,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35739
35740 ctl17 = SM(i->keytype, AR_EncrType);
35741 if (!i->is_first) {
35742- ACCESS_ONCE(ads->ctl11) = 0;
35743- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35744- ACCESS_ONCE(ads->ctl15) = 0;
35745- ACCESS_ONCE(ads->ctl16) = 0;
35746- ACCESS_ONCE(ads->ctl17) = ctl17;
35747- ACCESS_ONCE(ads->ctl18) = 0;
35748- ACCESS_ONCE(ads->ctl19) = 0;
35749+ ACCESS_ONCE_RW(ads->ctl11) = 0;
35750+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35751+ ACCESS_ONCE_RW(ads->ctl15) = 0;
35752+ ACCESS_ONCE_RW(ads->ctl16) = 0;
35753+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35754+ ACCESS_ONCE_RW(ads->ctl18) = 0;
35755+ ACCESS_ONCE_RW(ads->ctl19) = 0;
35756 return;
35757 }
35758
35759- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35760+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35761 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35762 | SM(i->txpower, AR_XmitPower)
35763 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35764@@ -130,22 +130,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35765 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35766 ctl12 |= SM(val, AR_PAPRDChainMask);
35767
35768- ACCESS_ONCE(ads->ctl12) = ctl12;
35769- ACCESS_ONCE(ads->ctl17) = ctl17;
35770+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35771+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35772
35773- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35774+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35775 | set11nPktDurRTSCTS(i->rates, 1);
35776
35777- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35778+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35779 | set11nPktDurRTSCTS(i->rates, 3);
35780
35781- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35782+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35783 | set11nRateFlags(i->rates, 1)
35784 | set11nRateFlags(i->rates, 2)
35785 | set11nRateFlags(i->rates, 3)
35786 | SM(i->rtscts_rate, AR_RTSCTSRate);
35787
35788- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35789+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35790 }
35791
35792 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35793diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35794index c8261d4..8d88929 100644
35795--- a/drivers/net/wireless/ath/ath9k/hw.h
35796+++ b/drivers/net/wireless/ath/ath9k/hw.h
35797@@ -773,7 +773,7 @@ struct ath_hw_private_ops {
35798
35799 /* ANI */
35800 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35801-};
35802+} __no_const;
35803
35804 /**
35805 * struct ath_hw_ops - callbacks used by hardware code and driver code
35806@@ -803,7 +803,7 @@ struct ath_hw_ops {
35807 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35808 struct ath_hw_antcomb_conf *antconf);
35809
35810-};
35811+} __no_const;
35812
35813 struct ath_nf_limits {
35814 s16 max;
35815@@ -823,7 +823,7 @@ enum ath_cal_list {
35816 #define AH_FASTCC 0x4
35817
35818 struct ath_hw {
35819- struct ath_ops reg_ops;
35820+ ath_ops_no_const reg_ops;
35821
35822 struct ieee80211_hw *hw;
35823 struct ath_common common;
35824diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35825index af00e2c..ab04d34 100644
35826--- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35827+++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35828@@ -545,7 +545,7 @@ struct phy_func_ptr {
35829 void (*carrsuppr)(struct brcms_phy *);
35830 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35831 void (*detach)(struct brcms_phy *);
35832-};
35833+} __no_const;
35834
35835 struct brcms_phy {
35836 struct brcms_phy_pub pubpi_ro;
35837diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35838index a2ec369..36fdf14 100644
35839--- a/drivers/net/wireless/iwlegacy/3945-mac.c
35840+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35841@@ -3646,7 +3646,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35842 */
35843 if (il3945_mod_params.disable_hw_scan) {
35844 D_INFO("Disabling hw_scan\n");
35845- il3945_hw_ops.hw_scan = NULL;
35846+ pax_open_kernel();
35847+ *(void **)&il3945_hw_ops.hw_scan = NULL;
35848+ pax_close_kernel();
35849 }
35850
35851 D_INFO("*** LOAD DRIVER ***\n");
35852diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
35853index f8fc239..8cade22 100644
35854--- a/drivers/net/wireless/iwlwifi/iwl-debug.h
35855+++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
35856@@ -86,8 +86,8 @@ do { \
35857 } while (0)
35858
35859 #else
35860-#define IWL_DEBUG(m, level, fmt, args...)
35861-#define IWL_DEBUG_LIMIT(m, level, fmt, args...)
35862+#define IWL_DEBUG(m, level, fmt, args...) do {} while (0)
35863+#define IWL_DEBUG_LIMIT(m, level, fmt, args...) do {} while (0)
35864 #define iwl_print_hex_dump(m, level, p, len)
35865 #define IWL_DEBUG_QUIET_RFKILL(p, fmt, args...) \
35866 do { \
35867diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35868index 4b9e730..7603659 100644
35869--- a/drivers/net/wireless/mac80211_hwsim.c
35870+++ b/drivers/net/wireless/mac80211_hwsim.c
35871@@ -1677,9 +1677,11 @@ static int __init init_mac80211_hwsim(void)
35872 return -EINVAL;
35873
35874 if (fake_hw_scan) {
35875- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35876- mac80211_hwsim_ops.sw_scan_start = NULL;
35877- mac80211_hwsim_ops.sw_scan_complete = NULL;
35878+ pax_open_kernel();
35879+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35880+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35881+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35882+ pax_close_kernel();
35883 }
35884
35885 spin_lock_init(&hwsim_radio_lock);
35886diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35887index 3186aa4..b35b09f 100644
35888--- a/drivers/net/wireless/mwifiex/main.h
35889+++ b/drivers/net/wireless/mwifiex/main.h
35890@@ -536,7 +536,7 @@ struct mwifiex_if_ops {
35891 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
35892 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
35893 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35894-};
35895+} __no_const;
35896
35897 struct mwifiex_adapter {
35898 u8 iface_type;
35899diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35900index a330c69..a81540f 100644
35901--- a/drivers/net/wireless/rndis_wlan.c
35902+++ b/drivers/net/wireless/rndis_wlan.c
35903@@ -1278,7 +1278,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35904
35905 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35906
35907- if (rts_threshold < 0 || rts_threshold > 2347)
35908+ if (rts_threshold > 2347)
35909 rts_threshold = 2347;
35910
35911 tmp = cpu_to_le32(rts_threshold);
35912diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
35913index a77f1bb..c608b2b 100644
35914--- a/drivers/net/wireless/wl1251/wl1251.h
35915+++ b/drivers/net/wireless/wl1251/wl1251.h
35916@@ -266,7 +266,7 @@ struct wl1251_if_operations {
35917 void (*reset)(struct wl1251 *wl);
35918 void (*enable_irq)(struct wl1251 *wl);
35919 void (*disable_irq)(struct wl1251 *wl);
35920-};
35921+} __no_const;
35922
35923 struct wl1251 {
35924 struct ieee80211_hw *hw;
35925diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35926index f34b5b2..b5abb9f 100644
35927--- a/drivers/oprofile/buffer_sync.c
35928+++ b/drivers/oprofile/buffer_sync.c
35929@@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35930 if (cookie == NO_COOKIE)
35931 offset = pc;
35932 if (cookie == INVALID_COOKIE) {
35933- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35934+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35935 offset = pc;
35936 }
35937 if (cookie != last_cookie) {
35938@@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35939 /* add userspace sample */
35940
35941 if (!mm) {
35942- atomic_inc(&oprofile_stats.sample_lost_no_mm);
35943+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35944 return 0;
35945 }
35946
35947 cookie = lookup_dcookie(mm, s->eip, &offset);
35948
35949 if (cookie == INVALID_COOKIE) {
35950- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35951+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35952 return 0;
35953 }
35954
35955@@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35956 /* ignore backtraces if failed to add a sample */
35957 if (state == sb_bt_start) {
35958 state = sb_bt_ignore;
35959- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35960+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35961 }
35962 }
35963 release_mm(mm);
35964diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35965index c0cc4e7..44d4e54 100644
35966--- a/drivers/oprofile/event_buffer.c
35967+++ b/drivers/oprofile/event_buffer.c
35968@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35969 }
35970
35971 if (buffer_pos == buffer_size) {
35972- atomic_inc(&oprofile_stats.event_lost_overflow);
35973+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35974 return;
35975 }
35976
35977diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35978index ed2c3ec..deda85a 100644
35979--- a/drivers/oprofile/oprof.c
35980+++ b/drivers/oprofile/oprof.c
35981@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35982 if (oprofile_ops.switch_events())
35983 return;
35984
35985- atomic_inc(&oprofile_stats.multiplex_counter);
35986+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35987 start_switch_worker();
35988 }
35989
35990diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35991index 917d28e..d62d981 100644
35992--- a/drivers/oprofile/oprofile_stats.c
35993+++ b/drivers/oprofile/oprofile_stats.c
35994@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35995 cpu_buf->sample_invalid_eip = 0;
35996 }
35997
35998- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35999- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36000- atomic_set(&oprofile_stats.event_lost_overflow, 0);
36001- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36002- atomic_set(&oprofile_stats.multiplex_counter, 0);
36003+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36004+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36005+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36006+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36007+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36008 }
36009
36010
36011diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36012index 38b6fc0..b5cbfce 100644
36013--- a/drivers/oprofile/oprofile_stats.h
36014+++ b/drivers/oprofile/oprofile_stats.h
36015@@ -13,11 +13,11 @@
36016 #include <linux/atomic.h>
36017
36018 struct oprofile_stat_struct {
36019- atomic_t sample_lost_no_mm;
36020- atomic_t sample_lost_no_mapping;
36021- atomic_t bt_lost_no_mapping;
36022- atomic_t event_lost_overflow;
36023- atomic_t multiplex_counter;
36024+ atomic_unchecked_t sample_lost_no_mm;
36025+ atomic_unchecked_t sample_lost_no_mapping;
36026+ atomic_unchecked_t bt_lost_no_mapping;
36027+ atomic_unchecked_t event_lost_overflow;
36028+ atomic_unchecked_t multiplex_counter;
36029 };
36030
36031 extern struct oprofile_stat_struct oprofile_stats;
36032diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36033index 2f0aa0f..90fab02 100644
36034--- a/drivers/oprofile/oprofilefs.c
36035+++ b/drivers/oprofile/oprofilefs.c
36036@@ -193,7 +193,7 @@ static const struct file_operations atomic_ro_fops = {
36037
36038
36039 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36040- char const *name, atomic_t *val)
36041+ char const *name, atomic_unchecked_t *val)
36042 {
36043 return __oprofilefs_create_file(sb, root, name,
36044 &atomic_ro_fops, 0444, val);
36045diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36046index 3f56bc0..707d642 100644
36047--- a/drivers/parport/procfs.c
36048+++ b/drivers/parport/procfs.c
36049@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36050
36051 *ppos += len;
36052
36053- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36054+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36055 }
36056
36057 #ifdef CONFIG_PARPORT_1284
36058@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36059
36060 *ppos += len;
36061
36062- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36063+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36064 }
36065 #endif /* IEEE1284.3 support. */
36066
36067diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36068index 9fff878..ad0ad53 100644
36069--- a/drivers/pci/hotplug/cpci_hotplug.h
36070+++ b/drivers/pci/hotplug/cpci_hotplug.h
36071@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36072 int (*hardware_test) (struct slot* slot, u32 value);
36073 u8 (*get_power) (struct slot* slot);
36074 int (*set_power) (struct slot* slot, int value);
36075-};
36076+} __no_const;
36077
36078 struct cpci_hp_controller {
36079 unsigned int irq;
36080diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36081index 76ba8a1..20ca857 100644
36082--- a/drivers/pci/hotplug/cpqphp_nvram.c
36083+++ b/drivers/pci/hotplug/cpqphp_nvram.c
36084@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36085
36086 void compaq_nvram_init (void __iomem *rom_start)
36087 {
36088+
36089+#ifndef CONFIG_PAX_KERNEXEC
36090 if (rom_start) {
36091 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36092 }
36093+#endif
36094+
36095 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36096
36097 /* initialize our int15 lock */
36098diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36099index 2275162..95f1a92 100644
36100--- a/drivers/pci/pcie/aspm.c
36101+++ b/drivers/pci/pcie/aspm.c
36102@@ -27,9 +27,9 @@
36103 #define MODULE_PARAM_PREFIX "pcie_aspm."
36104
36105 /* Note: those are not register definitions */
36106-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36107-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36108-#define ASPM_STATE_L1 (4) /* L1 state */
36109+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36110+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36111+#define ASPM_STATE_L1 (4U) /* L1 state */
36112 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36113 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36114
36115diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36116index 71eac9c..2de27ef 100644
36117--- a/drivers/pci/probe.c
36118+++ b/drivers/pci/probe.c
36119@@ -136,7 +136,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36120 u32 l, sz, mask;
36121 u16 orig_cmd;
36122
36123- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36124+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36125
36126 if (!dev->mmio_always_on) {
36127 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
36128diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36129index 27911b5..5b6db88 100644
36130--- a/drivers/pci/proc.c
36131+++ b/drivers/pci/proc.c
36132@@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36133 static int __init pci_proc_init(void)
36134 {
36135 struct pci_dev *dev = NULL;
36136+
36137+#ifdef CONFIG_GRKERNSEC_PROC_ADD
36138+#ifdef CONFIG_GRKERNSEC_PROC_USER
36139+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36140+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36141+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36142+#endif
36143+#else
36144 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36145+#endif
36146 proc_create("devices", 0, proc_bus_pci_dir,
36147 &proc_bus_pci_dev_operations);
36148 proc_initialized = 1;
36149diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36150index ea0c607..58c4628 100644
36151--- a/drivers/platform/x86/thinkpad_acpi.c
36152+++ b/drivers/platform/x86/thinkpad_acpi.c
36153@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
36154 return 0;
36155 }
36156
36157-void static hotkey_mask_warn_incomplete_mask(void)
36158+static void hotkey_mask_warn_incomplete_mask(void)
36159 {
36160 /* log only what the user can fix... */
36161 const u32 wantedmask = hotkey_driver_mask &
36162@@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36163 }
36164 }
36165
36166-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36167- struct tp_nvram_state *newn,
36168- const u32 event_mask)
36169-{
36170-
36171 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36172 do { \
36173 if ((event_mask & (1 << __scancode)) && \
36174@@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36175 tpacpi_hotkey_send_key(__scancode); \
36176 } while (0)
36177
36178- void issue_volchange(const unsigned int oldvol,
36179- const unsigned int newvol)
36180- {
36181- unsigned int i = oldvol;
36182+static void issue_volchange(const unsigned int oldvol,
36183+ const unsigned int newvol,
36184+ const u32 event_mask)
36185+{
36186+ unsigned int i = oldvol;
36187
36188- while (i > newvol) {
36189- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36190- i--;
36191- }
36192- while (i < newvol) {
36193- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36194- i++;
36195- }
36196+ while (i > newvol) {
36197+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36198+ i--;
36199 }
36200+ while (i < newvol) {
36201+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36202+ i++;
36203+ }
36204+}
36205
36206- void issue_brightnesschange(const unsigned int oldbrt,
36207- const unsigned int newbrt)
36208- {
36209- unsigned int i = oldbrt;
36210+static void issue_brightnesschange(const unsigned int oldbrt,
36211+ const unsigned int newbrt,
36212+ const u32 event_mask)
36213+{
36214+ unsigned int i = oldbrt;
36215
36216- while (i > newbrt) {
36217- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36218- i--;
36219- }
36220- while (i < newbrt) {
36221- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36222- i++;
36223- }
36224+ while (i > newbrt) {
36225+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36226+ i--;
36227+ }
36228+ while (i < newbrt) {
36229+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36230+ i++;
36231 }
36232+}
36233
36234+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36235+ struct tp_nvram_state *newn,
36236+ const u32 event_mask)
36237+{
36238 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36239 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36240 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36241@@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36242 oldn->volume_level != newn->volume_level) {
36243 /* recently muted, or repeated mute keypress, or
36244 * multiple presses ending in mute */
36245- issue_volchange(oldn->volume_level, newn->volume_level);
36246+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36247 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36248 }
36249 } else {
36250@@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36251 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36252 }
36253 if (oldn->volume_level != newn->volume_level) {
36254- issue_volchange(oldn->volume_level, newn->volume_level);
36255+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36256 } else if (oldn->volume_toggle != newn->volume_toggle) {
36257 /* repeated vol up/down keypress at end of scale ? */
36258 if (newn->volume_level == 0)
36259@@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36260 /* handle brightness */
36261 if (oldn->brightness_level != newn->brightness_level) {
36262 issue_brightnesschange(oldn->brightness_level,
36263- newn->brightness_level);
36264+ newn->brightness_level,
36265+ event_mask);
36266 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36267 /* repeated key presses that didn't change state */
36268 if (newn->brightness_level == 0)
36269@@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36270 && !tp_features.bright_unkfw)
36271 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36272 }
36273+}
36274
36275 #undef TPACPI_COMPARE_KEY
36276 #undef TPACPI_MAY_SEND_KEY
36277-}
36278
36279 /*
36280 * Polling driver
36281diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36282index b859d16..5cc6b1a 100644
36283--- a/drivers/pnp/pnpbios/bioscalls.c
36284+++ b/drivers/pnp/pnpbios/bioscalls.c
36285@@ -59,7 +59,7 @@ do { \
36286 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36287 } while(0)
36288
36289-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36290+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36291 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36292
36293 /*
36294@@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36295
36296 cpu = get_cpu();
36297 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36298+
36299+ pax_open_kernel();
36300 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36301+ pax_close_kernel();
36302
36303 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36304 spin_lock_irqsave(&pnp_bios_lock, flags);
36305@@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36306 :"memory");
36307 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36308
36309+ pax_open_kernel();
36310 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36311+ pax_close_kernel();
36312+
36313 put_cpu();
36314
36315 /* If we get here and this is set then the PnP BIOS faulted on us. */
36316@@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36317 return status;
36318 }
36319
36320-void pnpbios_calls_init(union pnp_bios_install_struct *header)
36321+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36322 {
36323 int i;
36324
36325@@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36326 pnp_bios_callpoint.offset = header->fields.pm16offset;
36327 pnp_bios_callpoint.segment = PNP_CS16;
36328
36329+ pax_open_kernel();
36330+
36331 for_each_possible_cpu(i) {
36332 struct desc_struct *gdt = get_cpu_gdt_table(i);
36333 if (!gdt)
36334@@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36335 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36336 (unsigned long)__va(header->fields.pm16dseg));
36337 }
36338+
36339+ pax_close_kernel();
36340 }
36341diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36342index b0ecacb..7c9da2e 100644
36343--- a/drivers/pnp/resource.c
36344+++ b/drivers/pnp/resource.c
36345@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36346 return 1;
36347
36348 /* check if the resource is valid */
36349- if (*irq < 0 || *irq > 15)
36350+ if (*irq > 15)
36351 return 0;
36352
36353 /* check if the resource is reserved */
36354@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36355 return 1;
36356
36357 /* check if the resource is valid */
36358- if (*dma < 0 || *dma == 4 || *dma > 7)
36359+ if (*dma == 4 || *dma > 7)
36360 return 0;
36361
36362 /* check if the resource is reserved */
36363diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36364index 1ed6ea0..77c0bd2 100644
36365--- a/drivers/power/bq27x00_battery.c
36366+++ b/drivers/power/bq27x00_battery.c
36367@@ -72,7 +72,7 @@
36368 struct bq27x00_device_info;
36369 struct bq27x00_access_methods {
36370 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36371-};
36372+} __no_const;
36373
36374 enum bq27x00_chip { BQ27000, BQ27500 };
36375
36376diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36377index a838e66..a9e1665 100644
36378--- a/drivers/regulator/max8660.c
36379+++ b/drivers/regulator/max8660.c
36380@@ -383,8 +383,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36381 max8660->shadow_regs[MAX8660_OVER1] = 5;
36382 } else {
36383 /* Otherwise devices can be toggled via software */
36384- max8660_dcdc_ops.enable = max8660_dcdc_enable;
36385- max8660_dcdc_ops.disable = max8660_dcdc_disable;
36386+ pax_open_kernel();
36387+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36388+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36389+ pax_close_kernel();
36390 }
36391
36392 /*
36393diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36394index e8cfc99..072aee2 100644
36395--- a/drivers/regulator/mc13892-regulator.c
36396+++ b/drivers/regulator/mc13892-regulator.c
36397@@ -574,10 +574,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36398 }
36399 mc13xxx_unlock(mc13892);
36400
36401- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36402+ pax_open_kernel();
36403+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36404 = mc13892_vcam_set_mode;
36405- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36406+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36407 = mc13892_vcam_get_mode;
36408+ pax_close_kernel();
36409
36410 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36411 ARRAY_SIZE(mc13892_regulators));
36412diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36413index cace6d3..f623fda 100644
36414--- a/drivers/rtc/rtc-dev.c
36415+++ b/drivers/rtc/rtc-dev.c
36416@@ -14,6 +14,7 @@
36417 #include <linux/module.h>
36418 #include <linux/rtc.h>
36419 #include <linux/sched.h>
36420+#include <linux/grsecurity.h>
36421 #include "rtc-core.h"
36422
36423 static dev_t rtc_devt;
36424@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36425 if (copy_from_user(&tm, uarg, sizeof(tm)))
36426 return -EFAULT;
36427
36428+ gr_log_timechange();
36429+
36430 return rtc_set_time(rtc, &tm);
36431
36432 case RTC_PIE_ON:
36433diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36434index ffb5878..e6d785c 100644
36435--- a/drivers/scsi/aacraid/aacraid.h
36436+++ b/drivers/scsi/aacraid/aacraid.h
36437@@ -492,7 +492,7 @@ struct adapter_ops
36438 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36439 /* Administrative operations */
36440 int (*adapter_comm)(struct aac_dev * dev, int comm);
36441-};
36442+} __no_const;
36443
36444 /*
36445 * Define which interrupt handler needs to be installed
36446diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36447index 705e13e..91c873c 100644
36448--- a/drivers/scsi/aacraid/linit.c
36449+++ b/drivers/scsi/aacraid/linit.c
36450@@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36451 #elif defined(__devinitconst)
36452 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36453 #else
36454-static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36455+static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36456 #endif
36457 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36458 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36459diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36460index d5ff142..49c0ebb 100644
36461--- a/drivers/scsi/aic94xx/aic94xx_init.c
36462+++ b/drivers/scsi/aic94xx/aic94xx_init.c
36463@@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36464 .lldd_control_phy = asd_control_phy,
36465 };
36466
36467-static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36468+static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36469 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36470 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36471 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36472diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36473index a796de9..1ef20e1 100644
36474--- a/drivers/scsi/bfa/bfa.h
36475+++ b/drivers/scsi/bfa/bfa.h
36476@@ -196,7 +196,7 @@ struct bfa_hwif_s {
36477 u32 *end);
36478 int cpe_vec_q0;
36479 int rme_vec_q0;
36480-};
36481+} __no_const;
36482 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36483
36484 struct bfa_faa_cbfn_s {
36485diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36486index f0f80e2..8ec946b 100644
36487--- a/drivers/scsi/bfa/bfa_fcpim.c
36488+++ b/drivers/scsi/bfa/bfa_fcpim.c
36489@@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36490
36491 bfa_iotag_attach(fcp);
36492
36493- fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36494+ fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36495 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36496 (fcp->num_itns * sizeof(struct bfa_itn_s));
36497 memset(fcp->itn_arr, 0,
36498@@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36499 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36500 {
36501 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36502- struct bfa_itn_s *itn;
36503+ bfa_itn_s_no_const *itn;
36504
36505 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36506 itn->isr = isr;
36507diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36508index 36f26da..38a34a8 100644
36509--- a/drivers/scsi/bfa/bfa_fcpim.h
36510+++ b/drivers/scsi/bfa/bfa_fcpim.h
36511@@ -37,6 +37,7 @@ struct bfa_iotag_s {
36512 struct bfa_itn_s {
36513 bfa_isr_func_t isr;
36514 };
36515+typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36516
36517 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36518 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36519@@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36520 struct list_head iotag_tio_free_q; /* free IO resources */
36521 struct list_head iotag_unused_q; /* unused IO resources*/
36522 struct bfa_iotag_s *iotag_arr;
36523- struct bfa_itn_s *itn_arr;
36524+ bfa_itn_s_no_const *itn_arr;
36525 int num_ioim_reqs;
36526 int num_fwtio_reqs;
36527 int num_itns;
36528diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36529index 546d46b..642fa5b 100644
36530--- a/drivers/scsi/bfa/bfa_ioc.h
36531+++ b/drivers/scsi/bfa/bfa_ioc.h
36532@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36533 bfa_ioc_disable_cbfn_t disable_cbfn;
36534 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36535 bfa_ioc_reset_cbfn_t reset_cbfn;
36536-};
36537+} __no_const;
36538
36539 /*
36540 * IOC event notification mechanism.
36541@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36542 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36543 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36544 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36545-};
36546+} __no_const;
36547
36548 /*
36549 * Queue element to wait for room in request queue. FIFO order is
36550diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36551index 351dc0b..951dc32 100644
36552--- a/drivers/scsi/hosts.c
36553+++ b/drivers/scsi/hosts.c
36554@@ -42,7 +42,7 @@
36555 #include "scsi_logging.h"
36556
36557
36558-static atomic_t scsi_host_next_hn; /* host_no for next new host */
36559+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36560
36561
36562 static void scsi_host_cls_release(struct device *dev)
36563@@ -357,7 +357,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36564 * subtract one because we increment first then return, but we need to
36565 * know what the next host number was before increment
36566 */
36567- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36568+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36569 shost->dma_channel = 0xff;
36570
36571 /* These three are default values which can be overridden */
36572diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36573index b96962c..0c82ec2 100644
36574--- a/drivers/scsi/hpsa.c
36575+++ b/drivers/scsi/hpsa.c
36576@@ -507,7 +507,7 @@ static inline u32 next_command(struct ctlr_info *h)
36577 u32 a;
36578
36579 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36580- return h->access.command_completed(h);
36581+ return h->access->command_completed(h);
36582
36583 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36584 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36585@@ -2991,7 +2991,7 @@ static void start_io(struct ctlr_info *h)
36586 while (!list_empty(&h->reqQ)) {
36587 c = list_entry(h->reqQ.next, struct CommandList, list);
36588 /* can't do anything if fifo is full */
36589- if ((h->access.fifo_full(h))) {
36590+ if ((h->access->fifo_full(h))) {
36591 dev_warn(&h->pdev->dev, "fifo full\n");
36592 break;
36593 }
36594@@ -3001,7 +3001,7 @@ static void start_io(struct ctlr_info *h)
36595 h->Qdepth--;
36596
36597 /* Tell the controller execute command */
36598- h->access.submit_command(h, c);
36599+ h->access->submit_command(h, c);
36600
36601 /* Put job onto the completed Q */
36602 addQ(&h->cmpQ, c);
36603@@ -3010,17 +3010,17 @@ static void start_io(struct ctlr_info *h)
36604
36605 static inline unsigned long get_next_completion(struct ctlr_info *h)
36606 {
36607- return h->access.command_completed(h);
36608+ return h->access->command_completed(h);
36609 }
36610
36611 static inline bool interrupt_pending(struct ctlr_info *h)
36612 {
36613- return h->access.intr_pending(h);
36614+ return h->access->intr_pending(h);
36615 }
36616
36617 static inline long interrupt_not_for_us(struct ctlr_info *h)
36618 {
36619- return (h->access.intr_pending(h) == 0) ||
36620+ return (h->access->intr_pending(h) == 0) ||
36621 (h->interrupts_enabled == 0);
36622 }
36623
36624@@ -3919,7 +3919,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36625 if (prod_index < 0)
36626 return -ENODEV;
36627 h->product_name = products[prod_index].product_name;
36628- h->access = *(products[prod_index].access);
36629+ h->access = products[prod_index].access;
36630
36631 if (hpsa_board_disabled(h->pdev)) {
36632 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36633@@ -4164,7 +4164,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36634
36635 assert_spin_locked(&lockup_detector_lock);
36636 remove_ctlr_from_lockup_detector_list(h);
36637- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36638+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36639 spin_lock_irqsave(&h->lock, flags);
36640 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36641 spin_unlock_irqrestore(&h->lock, flags);
36642@@ -4344,7 +4344,7 @@ reinit_after_soft_reset:
36643 }
36644
36645 /* make sure the board interrupts are off */
36646- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36647+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36648
36649 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36650 goto clean2;
36651@@ -4378,7 +4378,7 @@ reinit_after_soft_reset:
36652 * fake ones to scoop up any residual completions.
36653 */
36654 spin_lock_irqsave(&h->lock, flags);
36655- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36656+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36657 spin_unlock_irqrestore(&h->lock, flags);
36658 free_irq(h->intr[h->intr_mode], h);
36659 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36660@@ -4397,9 +4397,9 @@ reinit_after_soft_reset:
36661 dev_info(&h->pdev->dev, "Board READY.\n");
36662 dev_info(&h->pdev->dev,
36663 "Waiting for stale completions to drain.\n");
36664- h->access.set_intr_mask(h, HPSA_INTR_ON);
36665+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36666 msleep(10000);
36667- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36668+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36669
36670 rc = controller_reset_failed(h->cfgtable);
36671 if (rc)
36672@@ -4420,7 +4420,7 @@ reinit_after_soft_reset:
36673 }
36674
36675 /* Turn the interrupts on so we can service requests */
36676- h->access.set_intr_mask(h, HPSA_INTR_ON);
36677+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36678
36679 hpsa_hba_inquiry(h);
36680 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36681@@ -4472,7 +4472,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36682 * To write all data in the battery backed cache to disks
36683 */
36684 hpsa_flush_cache(h);
36685- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36686+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36687 free_irq(h->intr[h->intr_mode], h);
36688 #ifdef CONFIG_PCI_MSI
36689 if (h->msix_vector)
36690@@ -4636,7 +4636,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36691 return;
36692 }
36693 /* Change the access methods to the performant access methods */
36694- h->access = SA5_performant_access;
36695+ h->access = &SA5_performant_access;
36696 h->transMethod = CFGTBL_Trans_Performant;
36697 }
36698
36699diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36700index 91edafb..a9b88ec 100644
36701--- a/drivers/scsi/hpsa.h
36702+++ b/drivers/scsi/hpsa.h
36703@@ -73,7 +73,7 @@ struct ctlr_info {
36704 unsigned int msix_vector;
36705 unsigned int msi_vector;
36706 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36707- struct access_method access;
36708+ struct access_method *access;
36709
36710 /* queue and queue Info */
36711 struct list_head reqQ;
36712diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36713index f2df059..a3a9930 100644
36714--- a/drivers/scsi/ips.h
36715+++ b/drivers/scsi/ips.h
36716@@ -1027,7 +1027,7 @@ typedef struct {
36717 int (*intr)(struct ips_ha *);
36718 void (*enableint)(struct ips_ha *);
36719 uint32_t (*statupd)(struct ips_ha *);
36720-} ips_hw_func_t;
36721+} __no_const ips_hw_func_t;
36722
36723 typedef struct ips_ha {
36724 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36725diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36726index 4d70d96..84d0573 100644
36727--- a/drivers/scsi/libfc/fc_exch.c
36728+++ b/drivers/scsi/libfc/fc_exch.c
36729@@ -105,12 +105,12 @@ struct fc_exch_mgr {
36730 * all together if not used XXX
36731 */
36732 struct {
36733- atomic_t no_free_exch;
36734- atomic_t no_free_exch_xid;
36735- atomic_t xid_not_found;
36736- atomic_t xid_busy;
36737- atomic_t seq_not_found;
36738- atomic_t non_bls_resp;
36739+ atomic_unchecked_t no_free_exch;
36740+ atomic_unchecked_t no_free_exch_xid;
36741+ atomic_unchecked_t xid_not_found;
36742+ atomic_unchecked_t xid_busy;
36743+ atomic_unchecked_t seq_not_found;
36744+ atomic_unchecked_t non_bls_resp;
36745 } stats;
36746 };
36747
36748@@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36749 /* allocate memory for exchange */
36750 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36751 if (!ep) {
36752- atomic_inc(&mp->stats.no_free_exch);
36753+ atomic_inc_unchecked(&mp->stats.no_free_exch);
36754 goto out;
36755 }
36756 memset(ep, 0, sizeof(*ep));
36757@@ -780,7 +780,7 @@ out:
36758 return ep;
36759 err:
36760 spin_unlock_bh(&pool->lock);
36761- atomic_inc(&mp->stats.no_free_exch_xid);
36762+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36763 mempool_free(ep, mp->ep_pool);
36764 return NULL;
36765 }
36766@@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36767 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36768 ep = fc_exch_find(mp, xid);
36769 if (!ep) {
36770- atomic_inc(&mp->stats.xid_not_found);
36771+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36772 reject = FC_RJT_OX_ID;
36773 goto out;
36774 }
36775@@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36776 ep = fc_exch_find(mp, xid);
36777 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36778 if (ep) {
36779- atomic_inc(&mp->stats.xid_busy);
36780+ atomic_inc_unchecked(&mp->stats.xid_busy);
36781 reject = FC_RJT_RX_ID;
36782 goto rel;
36783 }
36784@@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36785 }
36786 xid = ep->xid; /* get our XID */
36787 } else if (!ep) {
36788- atomic_inc(&mp->stats.xid_not_found);
36789+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36790 reject = FC_RJT_RX_ID; /* XID not found */
36791 goto out;
36792 }
36793@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36794 } else {
36795 sp = &ep->seq;
36796 if (sp->id != fh->fh_seq_id) {
36797- atomic_inc(&mp->stats.seq_not_found);
36798+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36799 if (f_ctl & FC_FC_END_SEQ) {
36800 /*
36801 * Update sequence_id based on incoming last
36802@@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36803
36804 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36805 if (!ep) {
36806- atomic_inc(&mp->stats.xid_not_found);
36807+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36808 goto out;
36809 }
36810 if (ep->esb_stat & ESB_ST_COMPLETE) {
36811- atomic_inc(&mp->stats.xid_not_found);
36812+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36813 goto rel;
36814 }
36815 if (ep->rxid == FC_XID_UNKNOWN)
36816 ep->rxid = ntohs(fh->fh_rx_id);
36817 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36818- atomic_inc(&mp->stats.xid_not_found);
36819+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36820 goto rel;
36821 }
36822 if (ep->did != ntoh24(fh->fh_s_id) &&
36823 ep->did != FC_FID_FLOGI) {
36824- atomic_inc(&mp->stats.xid_not_found);
36825+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36826 goto rel;
36827 }
36828 sof = fr_sof(fp);
36829@@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36830 sp->ssb_stat |= SSB_ST_RESP;
36831 sp->id = fh->fh_seq_id;
36832 } else if (sp->id != fh->fh_seq_id) {
36833- atomic_inc(&mp->stats.seq_not_found);
36834+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36835 goto rel;
36836 }
36837
36838@@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36839 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36840
36841 if (!sp)
36842- atomic_inc(&mp->stats.xid_not_found);
36843+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36844 else
36845- atomic_inc(&mp->stats.non_bls_resp);
36846+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
36847
36848 fc_frame_free(fp);
36849 }
36850diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36851index db9238f..4378ed2 100644
36852--- a/drivers/scsi/libsas/sas_ata.c
36853+++ b/drivers/scsi/libsas/sas_ata.c
36854@@ -368,7 +368,7 @@ static struct ata_port_operations sas_sata_ops = {
36855 .postreset = ata_std_postreset,
36856 .error_handler = ata_std_error_handler,
36857 .post_internal_cmd = sas_ata_post_internal,
36858- .qc_defer = ata_std_qc_defer,
36859+ .qc_defer = ata_std_qc_defer,
36860 .qc_prep = ata_noop_qc_prep,
36861 .qc_issue = sas_ata_qc_issue,
36862 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36863diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36864index 825f930..ce42672 100644
36865--- a/drivers/scsi/lpfc/lpfc.h
36866+++ b/drivers/scsi/lpfc/lpfc.h
36867@@ -413,7 +413,7 @@ struct lpfc_vport {
36868 struct dentry *debug_nodelist;
36869 struct dentry *vport_debugfs_root;
36870 struct lpfc_debugfs_trc *disc_trc;
36871- atomic_t disc_trc_cnt;
36872+ atomic_unchecked_t disc_trc_cnt;
36873 #endif
36874 uint8_t stat_data_enabled;
36875 uint8_t stat_data_blocked;
36876@@ -821,8 +821,8 @@ struct lpfc_hba {
36877 struct timer_list fabric_block_timer;
36878 unsigned long bit_flags;
36879 #define FABRIC_COMANDS_BLOCKED 0
36880- atomic_t num_rsrc_err;
36881- atomic_t num_cmd_success;
36882+ atomic_unchecked_t num_rsrc_err;
36883+ atomic_unchecked_t num_cmd_success;
36884 unsigned long last_rsrc_error_time;
36885 unsigned long last_ramp_down_time;
36886 unsigned long last_ramp_up_time;
36887@@ -852,7 +852,7 @@ struct lpfc_hba {
36888
36889 struct dentry *debug_slow_ring_trc;
36890 struct lpfc_debugfs_trc *slow_ring_trc;
36891- atomic_t slow_ring_trc_cnt;
36892+ atomic_unchecked_t slow_ring_trc_cnt;
36893 /* iDiag debugfs sub-directory */
36894 struct dentry *idiag_root;
36895 struct dentry *idiag_pci_cfg;
36896diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36897index 3587a3f..d45b81b 100644
36898--- a/drivers/scsi/lpfc/lpfc_debugfs.c
36899+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36900@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36901
36902 #include <linux/debugfs.h>
36903
36904-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36905+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36906 static unsigned long lpfc_debugfs_start_time = 0L;
36907
36908 /* iDiag */
36909@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36910 lpfc_debugfs_enable = 0;
36911
36912 len = 0;
36913- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36914+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36915 (lpfc_debugfs_max_disc_trc - 1);
36916 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36917 dtp = vport->disc_trc + i;
36918@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36919 lpfc_debugfs_enable = 0;
36920
36921 len = 0;
36922- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36923+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36924 (lpfc_debugfs_max_slow_ring_trc - 1);
36925 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36926 dtp = phba->slow_ring_trc + i;
36927@@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36928 !vport || !vport->disc_trc)
36929 return;
36930
36931- index = atomic_inc_return(&vport->disc_trc_cnt) &
36932+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36933 (lpfc_debugfs_max_disc_trc - 1);
36934 dtp = vport->disc_trc + index;
36935 dtp->fmt = fmt;
36936 dtp->data1 = data1;
36937 dtp->data2 = data2;
36938 dtp->data3 = data3;
36939- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36940+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36941 dtp->jif = jiffies;
36942 #endif
36943 return;
36944@@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36945 !phba || !phba->slow_ring_trc)
36946 return;
36947
36948- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36949+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36950 (lpfc_debugfs_max_slow_ring_trc - 1);
36951 dtp = phba->slow_ring_trc + index;
36952 dtp->fmt = fmt;
36953 dtp->data1 = data1;
36954 dtp->data2 = data2;
36955 dtp->data3 = data3;
36956- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36957+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36958 dtp->jif = jiffies;
36959 #endif
36960 return;
36961@@ -4040,7 +4040,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36962 "slow_ring buffer\n");
36963 goto debug_failed;
36964 }
36965- atomic_set(&phba->slow_ring_trc_cnt, 0);
36966+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36967 memset(phba->slow_ring_trc, 0,
36968 (sizeof(struct lpfc_debugfs_trc) *
36969 lpfc_debugfs_max_slow_ring_trc));
36970@@ -4086,7 +4086,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36971 "buffer\n");
36972 goto debug_failed;
36973 }
36974- atomic_set(&vport->disc_trc_cnt, 0);
36975+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36976
36977 snprintf(name, sizeof(name), "discovery_trace");
36978 vport->debug_disc_trc =
36979diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36980index dfea2da..8e17227 100644
36981--- a/drivers/scsi/lpfc/lpfc_init.c
36982+++ b/drivers/scsi/lpfc/lpfc_init.c
36983@@ -10145,8 +10145,10 @@ lpfc_init(void)
36984 printk(LPFC_COPYRIGHT "\n");
36985
36986 if (lpfc_enable_npiv) {
36987- lpfc_transport_functions.vport_create = lpfc_vport_create;
36988- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36989+ pax_open_kernel();
36990+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36991+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36992+ pax_close_kernel();
36993 }
36994 lpfc_transport_template =
36995 fc_attach_transport(&lpfc_transport_functions);
36996diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36997index c60f5d0..751535c 100644
36998--- a/drivers/scsi/lpfc/lpfc_scsi.c
36999+++ b/drivers/scsi/lpfc/lpfc_scsi.c
37000@@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37001 uint32_t evt_posted;
37002
37003 spin_lock_irqsave(&phba->hbalock, flags);
37004- atomic_inc(&phba->num_rsrc_err);
37005+ atomic_inc_unchecked(&phba->num_rsrc_err);
37006 phba->last_rsrc_error_time = jiffies;
37007
37008 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37009@@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37010 unsigned long flags;
37011 struct lpfc_hba *phba = vport->phba;
37012 uint32_t evt_posted;
37013- atomic_inc(&phba->num_cmd_success);
37014+ atomic_inc_unchecked(&phba->num_cmd_success);
37015
37016 if (vport->cfg_lun_queue_depth <= queue_depth)
37017 return;
37018@@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37019 unsigned long num_rsrc_err, num_cmd_success;
37020 int i;
37021
37022- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37023- num_cmd_success = atomic_read(&phba->num_cmd_success);
37024+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37025+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37026
37027 vports = lpfc_create_vport_work_array(phba);
37028 if (vports != NULL)
37029@@ -411,8 +411,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37030 }
37031 }
37032 lpfc_destroy_vport_work_array(phba, vports);
37033- atomic_set(&phba->num_rsrc_err, 0);
37034- atomic_set(&phba->num_cmd_success, 0);
37035+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
37036+ atomic_set_unchecked(&phba->num_cmd_success, 0);
37037 }
37038
37039 /**
37040@@ -446,8 +446,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37041 }
37042 }
37043 lpfc_destroy_vport_work_array(phba, vports);
37044- atomic_set(&phba->num_rsrc_err, 0);
37045- atomic_set(&phba->num_cmd_success, 0);
37046+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
37047+ atomic_set_unchecked(&phba->num_cmd_success, 0);
37048 }
37049
37050 /**
37051diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37052index ea8a0b4..812a124 100644
37053--- a/drivers/scsi/pmcraid.c
37054+++ b/drivers/scsi/pmcraid.c
37055@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37056 res->scsi_dev = scsi_dev;
37057 scsi_dev->hostdata = res;
37058 res->change_detected = 0;
37059- atomic_set(&res->read_failures, 0);
37060- atomic_set(&res->write_failures, 0);
37061+ atomic_set_unchecked(&res->read_failures, 0);
37062+ atomic_set_unchecked(&res->write_failures, 0);
37063 rc = 0;
37064 }
37065 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37066@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37067
37068 /* If this was a SCSI read/write command keep count of errors */
37069 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37070- atomic_inc(&res->read_failures);
37071+ atomic_inc_unchecked(&res->read_failures);
37072 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37073- atomic_inc(&res->write_failures);
37074+ atomic_inc_unchecked(&res->write_failures);
37075
37076 if (!RES_IS_GSCSI(res->cfg_entry) &&
37077 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37078@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37079 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37080 * hrrq_id assigned here in queuecommand
37081 */
37082- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37083+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37084 pinstance->num_hrrq;
37085 cmd->cmd_done = pmcraid_io_done;
37086
37087@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37088 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37089 * hrrq_id assigned here in queuecommand
37090 */
37091- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37092+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37093 pinstance->num_hrrq;
37094
37095 if (request_size) {
37096@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37097
37098 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37099 /* add resources only after host is added into system */
37100- if (!atomic_read(&pinstance->expose_resources))
37101+ if (!atomic_read_unchecked(&pinstance->expose_resources))
37102 return;
37103
37104 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37105@@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37106 init_waitqueue_head(&pinstance->reset_wait_q);
37107
37108 atomic_set(&pinstance->outstanding_cmds, 0);
37109- atomic_set(&pinstance->last_message_id, 0);
37110- atomic_set(&pinstance->expose_resources, 0);
37111+ atomic_set_unchecked(&pinstance->last_message_id, 0);
37112+ atomic_set_unchecked(&pinstance->expose_resources, 0);
37113
37114 INIT_LIST_HEAD(&pinstance->free_res_q);
37115 INIT_LIST_HEAD(&pinstance->used_res_q);
37116@@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37117 /* Schedule worker thread to handle CCN and take care of adding and
37118 * removing devices to OS
37119 */
37120- atomic_set(&pinstance->expose_resources, 1);
37121+ atomic_set_unchecked(&pinstance->expose_resources, 1);
37122 schedule_work(&pinstance->worker_q);
37123 return rc;
37124
37125diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37126index ca496c7..9c791d5 100644
37127--- a/drivers/scsi/pmcraid.h
37128+++ b/drivers/scsi/pmcraid.h
37129@@ -748,7 +748,7 @@ struct pmcraid_instance {
37130 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37131
37132 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37133- atomic_t last_message_id;
37134+ atomic_unchecked_t last_message_id;
37135
37136 /* configuration table */
37137 struct pmcraid_config_table *cfg_table;
37138@@ -777,7 +777,7 @@ struct pmcraid_instance {
37139 atomic_t outstanding_cmds;
37140
37141 /* should add/delete resources to mid-layer now ?*/
37142- atomic_t expose_resources;
37143+ atomic_unchecked_t expose_resources;
37144
37145
37146
37147@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37148 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37149 };
37150 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37151- atomic_t read_failures; /* count of failed READ commands */
37152- atomic_t write_failures; /* count of failed WRITE commands */
37153+ atomic_unchecked_t read_failures; /* count of failed READ commands */
37154+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37155
37156 /* To indicate add/delete/modify during CCN */
37157 u8 change_detected;
37158diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37159index af1003f..be55a75 100644
37160--- a/drivers/scsi/qla2xxx/qla_def.h
37161+++ b/drivers/scsi/qla2xxx/qla_def.h
37162@@ -2247,7 +2247,7 @@ struct isp_operations {
37163 int (*start_scsi) (srb_t *);
37164 int (*abort_isp) (struct scsi_qla_host *);
37165 int (*iospace_config)(struct qla_hw_data*);
37166-};
37167+} __no_const;
37168
37169 /* MSI-X Support *************************************************************/
37170
37171diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37172index bfe6854..ceac088 100644
37173--- a/drivers/scsi/qla4xxx/ql4_def.h
37174+++ b/drivers/scsi/qla4xxx/ql4_def.h
37175@@ -261,7 +261,7 @@ struct ddb_entry {
37176 * (4000 only) */
37177 atomic_t relogin_timer; /* Max Time to wait for
37178 * relogin to complete */
37179- atomic_t relogin_retry_count; /* Num of times relogin has been
37180+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37181 * retried */
37182 uint32_t default_time2wait; /* Default Min time between
37183 * relogins (+aens) */
37184diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37185index ce6d3b7..73fac54 100644
37186--- a/drivers/scsi/qla4xxx/ql4_os.c
37187+++ b/drivers/scsi/qla4xxx/ql4_os.c
37188@@ -2178,12 +2178,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37189 */
37190 if (!iscsi_is_session_online(cls_sess)) {
37191 /* Reset retry relogin timer */
37192- atomic_inc(&ddb_entry->relogin_retry_count);
37193+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37194 DEBUG2(ql4_printk(KERN_INFO, ha,
37195 "%s: index[%d] relogin timed out-retrying"
37196 " relogin (%d), retry (%d)\n", __func__,
37197 ddb_entry->fw_ddb_index,
37198- atomic_read(&ddb_entry->relogin_retry_count),
37199+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37200 ddb_entry->default_time2wait + 4));
37201 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37202 atomic_set(&ddb_entry->retry_relogin_timer,
37203@@ -3953,7 +3953,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37204
37205 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37206 atomic_set(&ddb_entry->relogin_timer, 0);
37207- atomic_set(&ddb_entry->relogin_retry_count, 0);
37208+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37209 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37210 ddb_entry->default_relogin_timeout =
37211 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37212diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37213index 2aeb2e9..46e3925 100644
37214--- a/drivers/scsi/scsi.c
37215+++ b/drivers/scsi/scsi.c
37216@@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37217 unsigned long timeout;
37218 int rtn = 0;
37219
37220- atomic_inc(&cmd->device->iorequest_cnt);
37221+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37222
37223 /* check if the device is still usable */
37224 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37225diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37226index b2c95db..227d74e 100644
37227--- a/drivers/scsi/scsi_lib.c
37228+++ b/drivers/scsi/scsi_lib.c
37229@@ -1411,7 +1411,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37230 shost = sdev->host;
37231 scsi_init_cmd_errh(cmd);
37232 cmd->result = DID_NO_CONNECT << 16;
37233- atomic_inc(&cmd->device->iorequest_cnt);
37234+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37235
37236 /*
37237 * SCSI request completion path will do scsi_device_unbusy(),
37238@@ -1437,9 +1437,9 @@ static void scsi_softirq_done(struct request *rq)
37239
37240 INIT_LIST_HEAD(&cmd->eh_entry);
37241
37242- atomic_inc(&cmd->device->iodone_cnt);
37243+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
37244 if (cmd->result)
37245- atomic_inc(&cmd->device->ioerr_cnt);
37246+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37247
37248 disposition = scsi_decide_disposition(cmd);
37249 if (disposition != SUCCESS &&
37250diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37251index 04c2a27..9d8bd66 100644
37252--- a/drivers/scsi/scsi_sysfs.c
37253+++ b/drivers/scsi/scsi_sysfs.c
37254@@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37255 char *buf) \
37256 { \
37257 struct scsi_device *sdev = to_scsi_device(dev); \
37258- unsigned long long count = atomic_read(&sdev->field); \
37259+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
37260 return snprintf(buf, 20, "0x%llx\n", count); \
37261 } \
37262 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37263diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37264index 84a1fdf..693b0d6 100644
37265--- a/drivers/scsi/scsi_tgt_lib.c
37266+++ b/drivers/scsi/scsi_tgt_lib.c
37267@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37268 int err;
37269
37270 dprintk("%lx %u\n", uaddr, len);
37271- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37272+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37273 if (err) {
37274 /*
37275 * TODO: need to fixup sg_tablesize, max_segment_size,
37276diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37277index f59d4a0..1d89407 100644
37278--- a/drivers/scsi/scsi_transport_fc.c
37279+++ b/drivers/scsi/scsi_transport_fc.c
37280@@ -484,7 +484,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37281 * Netlink Infrastructure
37282 */
37283
37284-static atomic_t fc_event_seq;
37285+static atomic_unchecked_t fc_event_seq;
37286
37287 /**
37288 * fc_get_event_number - Obtain the next sequential FC event number
37289@@ -497,7 +497,7 @@ static atomic_t fc_event_seq;
37290 u32
37291 fc_get_event_number(void)
37292 {
37293- return atomic_add_return(1, &fc_event_seq);
37294+ return atomic_add_return_unchecked(1, &fc_event_seq);
37295 }
37296 EXPORT_SYMBOL(fc_get_event_number);
37297
37298@@ -645,7 +645,7 @@ static __init int fc_transport_init(void)
37299 {
37300 int error;
37301
37302- atomic_set(&fc_event_seq, 0);
37303+ atomic_set_unchecked(&fc_event_seq, 0);
37304
37305 error = transport_class_register(&fc_host_class);
37306 if (error)
37307@@ -835,7 +835,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37308 char *cp;
37309
37310 *val = simple_strtoul(buf, &cp, 0);
37311- if ((*cp && (*cp != '\n')) || (*val < 0))
37312+ if (*cp && (*cp != '\n'))
37313 return -EINVAL;
37314 /*
37315 * Check for overflow; dev_loss_tmo is u32
37316diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37317index e3e3c7d..ebdab62 100644
37318--- a/drivers/scsi/scsi_transport_iscsi.c
37319+++ b/drivers/scsi/scsi_transport_iscsi.c
37320@@ -79,7 +79,7 @@ struct iscsi_internal {
37321 struct transport_container session_cont;
37322 };
37323
37324-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37325+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37326 static struct workqueue_struct *iscsi_eh_timer_workq;
37327
37328 static DEFINE_IDA(iscsi_sess_ida);
37329@@ -1063,7 +1063,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37330 int err;
37331
37332 ihost = shost->shost_data;
37333- session->sid = atomic_add_return(1, &iscsi_session_nr);
37334+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37335
37336 if (target_id == ISCSI_MAX_TARGET) {
37337 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37338@@ -2680,7 +2680,7 @@ static __init int iscsi_transport_init(void)
37339 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37340 ISCSI_TRANSPORT_VERSION);
37341
37342- atomic_set(&iscsi_session_nr, 0);
37343+ atomic_set_unchecked(&iscsi_session_nr, 0);
37344
37345 err = class_register(&iscsi_transport_class);
37346 if (err)
37347diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37348index 21a045e..ec89e03 100644
37349--- a/drivers/scsi/scsi_transport_srp.c
37350+++ b/drivers/scsi/scsi_transport_srp.c
37351@@ -33,7 +33,7 @@
37352 #include "scsi_transport_srp_internal.h"
37353
37354 struct srp_host_attrs {
37355- atomic_t next_port_id;
37356+ atomic_unchecked_t next_port_id;
37357 };
37358 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37359
37360@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37361 struct Scsi_Host *shost = dev_to_shost(dev);
37362 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37363
37364- atomic_set(&srp_host->next_port_id, 0);
37365+ atomic_set_unchecked(&srp_host->next_port_id, 0);
37366 return 0;
37367 }
37368
37369@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37370 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37371 rport->roles = ids->roles;
37372
37373- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37374+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37375 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37376
37377 transport_setup_device(&rport->dev);
37378diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37379index eacd46b..e3f4d62 100644
37380--- a/drivers/scsi/sg.c
37381+++ b/drivers/scsi/sg.c
37382@@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37383 sdp->disk->disk_name,
37384 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37385 NULL,
37386- (char *)arg);
37387+ (char __user *)arg);
37388 case BLKTRACESTART:
37389 return blk_trace_startstop(sdp->device->request_queue, 1);
37390 case BLKTRACESTOP:
37391@@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
37392 const struct file_operations * fops;
37393 };
37394
37395-static struct sg_proc_leaf sg_proc_leaf_arr[] = {
37396+static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
37397 {"allow_dio", &adio_fops},
37398 {"debug", &debug_fops},
37399 {"def_reserved_size", &dressz_fops},
37400@@ -2332,7 +2332,7 @@ sg_proc_init(void)
37401 if (!sg_proc_sgp)
37402 return 1;
37403 for (k = 0; k < num_leaves; ++k) {
37404- struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37405+ const struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37406 umode_t mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO;
37407 proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops);
37408 }
37409diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
37410index f64250e..1ee3049 100644
37411--- a/drivers/spi/spi-dw-pci.c
37412+++ b/drivers/spi/spi-dw-pci.c
37413@@ -149,7 +149,7 @@ static int spi_resume(struct pci_dev *pdev)
37414 #define spi_resume NULL
37415 #endif
37416
37417-static const struct pci_device_id pci_ids[] __devinitdata = {
37418+static const struct pci_device_id pci_ids[] __devinitconst = {
37419 /* Intel MID platform SPI controller 0 */
37420 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
37421 {},
37422diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37423index b2ccdea..84cde75 100644
37424--- a/drivers/spi/spi.c
37425+++ b/drivers/spi/spi.c
37426@@ -1024,7 +1024,7 @@ int spi_bus_unlock(struct spi_master *master)
37427 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37428
37429 /* portable code must never pass more than 32 bytes */
37430-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37431+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37432
37433 static u8 *buf;
37434
37435diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37436index 400df8c..065d4f4 100644
37437--- a/drivers/staging/octeon/ethernet-rx.c
37438+++ b/drivers/staging/octeon/ethernet-rx.c
37439@@ -420,11 +420,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37440 /* Increment RX stats for virtual ports */
37441 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37442 #ifdef CONFIG_64BIT
37443- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37444- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37445+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37446+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37447 #else
37448- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37449- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37450+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37451+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37452 #endif
37453 }
37454 netif_receive_skb(skb);
37455@@ -436,9 +436,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37456 dev->name);
37457 */
37458 #ifdef CONFIG_64BIT
37459- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37460+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37461 #else
37462- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37463+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37464 #endif
37465 dev_kfree_skb_irq(skb);
37466 }
37467diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37468index 9112cd8..92f8d51 100644
37469--- a/drivers/staging/octeon/ethernet.c
37470+++ b/drivers/staging/octeon/ethernet.c
37471@@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37472 * since the RX tasklet also increments it.
37473 */
37474 #ifdef CONFIG_64BIT
37475- atomic64_add(rx_status.dropped_packets,
37476- (atomic64_t *)&priv->stats.rx_dropped);
37477+ atomic64_add_unchecked(rx_status.dropped_packets,
37478+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37479 #else
37480- atomic_add(rx_status.dropped_packets,
37481- (atomic_t *)&priv->stats.rx_dropped);
37482+ atomic_add_unchecked(rx_status.dropped_packets,
37483+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
37484 #endif
37485 }
37486
37487diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37488index 86308a0..feaa925 100644
37489--- a/drivers/staging/rtl8712/rtl871x_io.h
37490+++ b/drivers/staging/rtl8712/rtl871x_io.h
37491@@ -108,7 +108,7 @@ struct _io_ops {
37492 u8 *pmem);
37493 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37494 u8 *pmem);
37495-};
37496+} __no_const;
37497
37498 struct io_req {
37499 struct list_head list;
37500diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37501index c7b5e8b..783d6cb 100644
37502--- a/drivers/staging/sbe-2t3e3/netdev.c
37503+++ b/drivers/staging/sbe-2t3e3/netdev.c
37504@@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37505 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37506
37507 if (rlen)
37508- if (copy_to_user(data, &resp, rlen))
37509+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37510 return -EFAULT;
37511
37512 return 0;
37513diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37514index 42cdafe..2769103 100644
37515--- a/drivers/staging/speakup/speakup_soft.c
37516+++ b/drivers/staging/speakup/speakup_soft.c
37517@@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37518 break;
37519 } else if (!initialized) {
37520 if (*init) {
37521- ch = *init;
37522 init++;
37523 } else {
37524 initialized = 1;
37525 }
37526+ ch = *init;
37527 } else {
37528 ch = synth_buffer_getc();
37529 }
37530diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37531index b8f8c48..1fc5025 100644
37532--- a/drivers/staging/usbip/usbip_common.h
37533+++ b/drivers/staging/usbip/usbip_common.h
37534@@ -289,7 +289,7 @@ struct usbip_device {
37535 void (*shutdown)(struct usbip_device *);
37536 void (*reset)(struct usbip_device *);
37537 void (*unusable)(struct usbip_device *);
37538- } eh_ops;
37539+ } __no_const eh_ops;
37540 };
37541
37542 /* usbip_common.c */
37543diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37544index 88b3298..3783eee 100644
37545--- a/drivers/staging/usbip/vhci.h
37546+++ b/drivers/staging/usbip/vhci.h
37547@@ -88,7 +88,7 @@ struct vhci_hcd {
37548 unsigned resuming:1;
37549 unsigned long re_timeout;
37550
37551- atomic_t seqnum;
37552+ atomic_unchecked_t seqnum;
37553
37554 /*
37555 * NOTE:
37556diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37557index 2ee97e2..0420b86 100644
37558--- a/drivers/staging/usbip/vhci_hcd.c
37559+++ b/drivers/staging/usbip/vhci_hcd.c
37560@@ -527,7 +527,7 @@ static void vhci_tx_urb(struct urb *urb)
37561 return;
37562 }
37563
37564- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37565+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37566 if (priv->seqnum == 0xffff)
37567 dev_info(&urb->dev->dev, "seqnum max\n");
37568
37569@@ -779,7 +779,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37570 return -ENOMEM;
37571 }
37572
37573- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37574+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37575 if (unlink->seqnum == 0xffff)
37576 pr_info("seqnum max\n");
37577
37578@@ -969,7 +969,7 @@ static int vhci_start(struct usb_hcd *hcd)
37579 vdev->rhport = rhport;
37580 }
37581
37582- atomic_set(&vhci->seqnum, 0);
37583+ atomic_set_unchecked(&vhci->seqnum, 0);
37584 spin_lock_init(&vhci->lock);
37585
37586 hcd->power_budget = 0; /* no limit */
37587diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37588index 3f511b4..d3dbc1e 100644
37589--- a/drivers/staging/usbip/vhci_rx.c
37590+++ b/drivers/staging/usbip/vhci_rx.c
37591@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37592 if (!urb) {
37593 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37594 pr_info("max seqnum %d\n",
37595- atomic_read(&the_controller->seqnum));
37596+ atomic_read_unchecked(&the_controller->seqnum));
37597 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37598 return;
37599 }
37600diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37601index 7735027..30eed13 100644
37602--- a/drivers/staging/vt6655/hostap.c
37603+++ b/drivers/staging/vt6655/hostap.c
37604@@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37605 *
37606 */
37607
37608+static net_device_ops_no_const apdev_netdev_ops;
37609+
37610 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37611 {
37612 PSDevice apdev_priv;
37613 struct net_device *dev = pDevice->dev;
37614 int ret;
37615- const struct net_device_ops apdev_netdev_ops = {
37616- .ndo_start_xmit = pDevice->tx_80211,
37617- };
37618
37619 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37620
37621@@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37622 *apdev_priv = *pDevice;
37623 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37624
37625+ /* only half broken now */
37626+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37627 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37628
37629 pDevice->apdev->type = ARPHRD_IEEE80211;
37630diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37631index 51b5adf..098e320 100644
37632--- a/drivers/staging/vt6656/hostap.c
37633+++ b/drivers/staging/vt6656/hostap.c
37634@@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37635 *
37636 */
37637
37638+static net_device_ops_no_const apdev_netdev_ops;
37639+
37640 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37641 {
37642 PSDevice apdev_priv;
37643 struct net_device *dev = pDevice->dev;
37644 int ret;
37645- const struct net_device_ops apdev_netdev_ops = {
37646- .ndo_start_xmit = pDevice->tx_80211,
37647- };
37648
37649 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37650
37651@@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37652 *apdev_priv = *pDevice;
37653 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37654
37655+ /* only half broken now */
37656+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37657 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37658
37659 pDevice->apdev->type = ARPHRD_IEEE80211;
37660diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37661index 7843dfd..3db105f 100644
37662--- a/drivers/staging/wlan-ng/hfa384x_usb.c
37663+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37664@@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37665
37666 struct usbctlx_completor {
37667 int (*complete) (struct usbctlx_completor *);
37668-};
37669+} __no_const;
37670
37671 static int
37672 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37673diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37674index 1ca66ea..76f1343 100644
37675--- a/drivers/staging/zcache/tmem.c
37676+++ b/drivers/staging/zcache/tmem.c
37677@@ -39,7 +39,7 @@
37678 * A tmem host implementation must use this function to register callbacks
37679 * for memory allocation.
37680 */
37681-static struct tmem_hostops tmem_hostops;
37682+static tmem_hostops_no_const tmem_hostops;
37683
37684 static void tmem_objnode_tree_init(void);
37685
37686@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37687 * A tmem host implementation must use this function to register
37688 * callbacks for a page-accessible memory (PAM) implementation
37689 */
37690-static struct tmem_pamops tmem_pamops;
37691+static tmem_pamops_no_const tmem_pamops;
37692
37693 void tmem_register_pamops(struct tmem_pamops *m)
37694 {
37695diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37696index ed147c4..94fc3c6 100644
37697--- a/drivers/staging/zcache/tmem.h
37698+++ b/drivers/staging/zcache/tmem.h
37699@@ -180,6 +180,7 @@ struct tmem_pamops {
37700 void (*new_obj)(struct tmem_obj *);
37701 int (*replace_in_obj)(void *, struct tmem_obj *);
37702 };
37703+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37704 extern void tmem_register_pamops(struct tmem_pamops *m);
37705
37706 /* memory allocation methods provided by the host implementation */
37707@@ -189,6 +190,7 @@ struct tmem_hostops {
37708 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37709 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37710 };
37711+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37712 extern void tmem_register_hostops(struct tmem_hostops *m);
37713
37714 /* core tmem accessor functions */
37715diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
37716index 97c74ee..7f6d77d 100644
37717--- a/drivers/target/iscsi/iscsi_target.c
37718+++ b/drivers/target/iscsi/iscsi_target.c
37719@@ -1361,7 +1361,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
37720 * outstanding_r2ts reaches zero, go ahead and send the delayed
37721 * TASK_ABORTED status.
37722 */
37723- if (atomic_read(&se_cmd->t_transport_aborted) != 0) {
37724+ if (atomic_read_unchecked(&se_cmd->t_transport_aborted) != 0) {
37725 if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
37726 if (--cmd->outstanding_r2ts < 1) {
37727 iscsit_stop_dataout_timer(cmd);
37728diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
37729index dcb0618..97e3d85 100644
37730--- a/drivers/target/target_core_tmr.c
37731+++ b/drivers/target/target_core_tmr.c
37732@@ -260,7 +260,7 @@ static void core_tmr_drain_task_list(
37733 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
37734 cmd->t_task_list_num,
37735 atomic_read(&cmd->t_task_cdbs_left),
37736- atomic_read(&cmd->t_task_cdbs_sent),
37737+ atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37738 atomic_read(&cmd->t_transport_active),
37739 atomic_read(&cmd->t_transport_stop),
37740 atomic_read(&cmd->t_transport_sent));
37741@@ -291,7 +291,7 @@ static void core_tmr_drain_task_list(
37742 pr_debug("LUN_RESET: got t_transport_active = 1 for"
37743 " task: %p, t_fe_count: %d dev: %p\n", task,
37744 fe_count, dev);
37745- atomic_set(&cmd->t_transport_aborted, 1);
37746+ atomic_set_unchecked(&cmd->t_transport_aborted, 1);
37747 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37748
37749 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
37750@@ -299,7 +299,7 @@ static void core_tmr_drain_task_list(
37751 }
37752 pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p,"
37753 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
37754- atomic_set(&cmd->t_transport_aborted, 1);
37755+ atomic_set_unchecked(&cmd->t_transport_aborted, 1);
37756 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37757
37758 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
37759diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37760index cd5cd95..5249d30 100644
37761--- a/drivers/target/target_core_transport.c
37762+++ b/drivers/target/target_core_transport.c
37763@@ -1330,7 +1330,7 @@ struct se_device *transport_add_device_to_core_hba(
37764 spin_lock_init(&dev->se_port_lock);
37765 spin_lock_init(&dev->se_tmr_lock);
37766 spin_lock_init(&dev->qf_cmd_lock);
37767- atomic_set(&dev->dev_ordered_id, 0);
37768+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
37769
37770 se_dev_set_default_attribs(dev, dev_limits);
37771
37772@@ -1517,7 +1517,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37773 * Used to determine when ORDERED commands should go from
37774 * Dormant to Active status.
37775 */
37776- cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37777+ cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37778 smp_mb__after_atomic_inc();
37779 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37780 cmd->se_ordered_id, cmd->sam_task_attr,
37781@@ -1862,7 +1862,7 @@ static void transport_generic_request_failure(struct se_cmd *cmd)
37782 " t_transport_active: %d t_transport_stop: %d"
37783 " t_transport_sent: %d\n", cmd->t_task_list_num,
37784 atomic_read(&cmd->t_task_cdbs_left),
37785- atomic_read(&cmd->t_task_cdbs_sent),
37786+ atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37787 atomic_read(&cmd->t_task_cdbs_ex_left),
37788 atomic_read(&cmd->t_transport_active),
37789 atomic_read(&cmd->t_transport_stop),
37790@@ -2121,9 +2121,9 @@ check_depth:
37791 cmd = task->task_se_cmd;
37792 spin_lock_irqsave(&cmd->t_state_lock, flags);
37793 task->task_flags |= (TF_ACTIVE | TF_SENT);
37794- atomic_inc(&cmd->t_task_cdbs_sent);
37795+ atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
37796
37797- if (atomic_read(&cmd->t_task_cdbs_sent) ==
37798+ if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
37799 cmd->t_task_list_num)
37800 atomic_set(&cmd->t_transport_sent, 1);
37801
37802@@ -4348,7 +4348,7 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
37803 atomic_set(&cmd->transport_lun_stop, 0);
37804 }
37805 if (!atomic_read(&cmd->t_transport_active) ||
37806- atomic_read(&cmd->t_transport_aborted)) {
37807+ atomic_read_unchecked(&cmd->t_transport_aborted)) {
37808 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37809 return false;
37810 }
37811@@ -4597,7 +4597,7 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
37812 {
37813 int ret = 0;
37814
37815- if (atomic_read(&cmd->t_transport_aborted) != 0) {
37816+ if (atomic_read_unchecked(&cmd->t_transport_aborted) != 0) {
37817 if (!send_status ||
37818 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
37819 return 1;
37820@@ -4634,7 +4634,7 @@ void transport_send_task_abort(struct se_cmd *cmd)
37821 */
37822 if (cmd->data_direction == DMA_TO_DEVICE) {
37823 if (cmd->se_tfo->write_pending_status(cmd) != 0) {
37824- atomic_inc(&cmd->t_transport_aborted);
37825+ atomic_inc_unchecked(&cmd->t_transport_aborted);
37826 smp_mb__after_atomic_inc();
37827 }
37828 }
37829diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37830index b9040be..e3f5aab 100644
37831--- a/drivers/tty/hvc/hvcs.c
37832+++ b/drivers/tty/hvc/hvcs.c
37833@@ -83,6 +83,7 @@
37834 #include <asm/hvcserver.h>
37835 #include <asm/uaccess.h>
37836 #include <asm/vio.h>
37837+#include <asm/local.h>
37838
37839 /*
37840 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37841@@ -270,7 +271,7 @@ struct hvcs_struct {
37842 unsigned int index;
37843
37844 struct tty_struct *tty;
37845- int open_count;
37846+ local_t open_count;
37847
37848 /*
37849 * Used to tell the driver kernel_thread what operations need to take
37850@@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37851
37852 spin_lock_irqsave(&hvcsd->lock, flags);
37853
37854- if (hvcsd->open_count > 0) {
37855+ if (local_read(&hvcsd->open_count) > 0) {
37856 spin_unlock_irqrestore(&hvcsd->lock, flags);
37857 printk(KERN_INFO "HVCS: vterm state unchanged. "
37858 "The hvcs device node is still in use.\n");
37859@@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37860 if ((retval = hvcs_partner_connect(hvcsd)))
37861 goto error_release;
37862
37863- hvcsd->open_count = 1;
37864+ local_set(&hvcsd->open_count, 1);
37865 hvcsd->tty = tty;
37866 tty->driver_data = hvcsd;
37867
37868@@ -1179,7 +1180,7 @@ fast_open:
37869
37870 spin_lock_irqsave(&hvcsd->lock, flags);
37871 kref_get(&hvcsd->kref);
37872- hvcsd->open_count++;
37873+ local_inc(&hvcsd->open_count);
37874 hvcsd->todo_mask |= HVCS_SCHED_READ;
37875 spin_unlock_irqrestore(&hvcsd->lock, flags);
37876
37877@@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37878 hvcsd = tty->driver_data;
37879
37880 spin_lock_irqsave(&hvcsd->lock, flags);
37881- if (--hvcsd->open_count == 0) {
37882+ if (local_dec_and_test(&hvcsd->open_count)) {
37883
37884 vio_disable_interrupts(hvcsd->vdev);
37885
37886@@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37887 free_irq(irq, hvcsd);
37888 kref_put(&hvcsd->kref, destroy_hvcs_struct);
37889 return;
37890- } else if (hvcsd->open_count < 0) {
37891+ } else if (local_read(&hvcsd->open_count) < 0) {
37892 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37893 " is missmanaged.\n",
37894- hvcsd->vdev->unit_address, hvcsd->open_count);
37895+ hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
37896 }
37897
37898 spin_unlock_irqrestore(&hvcsd->lock, flags);
37899@@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37900
37901 spin_lock_irqsave(&hvcsd->lock, flags);
37902 /* Preserve this so that we know how many kref refs to put */
37903- temp_open_count = hvcsd->open_count;
37904+ temp_open_count = local_read(&hvcsd->open_count);
37905
37906 /*
37907 * Don't kref put inside the spinlock because the destruction
37908@@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37909 hvcsd->tty->driver_data = NULL;
37910 hvcsd->tty = NULL;
37911
37912- hvcsd->open_count = 0;
37913+ local_set(&hvcsd->open_count, 0);
37914
37915 /* This will drop any buffered data on the floor which is OK in a hangup
37916 * scenario. */
37917@@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct *tty,
37918 * the middle of a write operation? This is a crummy place to do this
37919 * but we want to keep it all in the spinlock.
37920 */
37921- if (hvcsd->open_count <= 0) {
37922+ if (local_read(&hvcsd->open_count) <= 0) {
37923 spin_unlock_irqrestore(&hvcsd->lock, flags);
37924 return -ENODEV;
37925 }
37926@@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37927 {
37928 struct hvcs_struct *hvcsd = tty->driver_data;
37929
37930- if (!hvcsd || hvcsd->open_count <= 0)
37931+ if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
37932 return 0;
37933
37934 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37935diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37936index ef92869..f4ebd88 100644
37937--- a/drivers/tty/ipwireless/tty.c
37938+++ b/drivers/tty/ipwireless/tty.c
37939@@ -29,6 +29,7 @@
37940 #include <linux/tty_driver.h>
37941 #include <linux/tty_flip.h>
37942 #include <linux/uaccess.h>
37943+#include <asm/local.h>
37944
37945 #include "tty.h"
37946 #include "network.h"
37947@@ -51,7 +52,7 @@ struct ipw_tty {
37948 int tty_type;
37949 struct ipw_network *network;
37950 struct tty_struct *linux_tty;
37951- int open_count;
37952+ local_t open_count;
37953 unsigned int control_lines;
37954 struct mutex ipw_tty_mutex;
37955 int tx_bytes_queued;
37956@@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37957 mutex_unlock(&tty->ipw_tty_mutex);
37958 return -ENODEV;
37959 }
37960- if (tty->open_count == 0)
37961+ if (local_read(&tty->open_count) == 0)
37962 tty->tx_bytes_queued = 0;
37963
37964- tty->open_count++;
37965+ local_inc(&tty->open_count);
37966
37967 tty->linux_tty = linux_tty;
37968 linux_tty->driver_data = tty;
37969@@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37970
37971 static void do_ipw_close(struct ipw_tty *tty)
37972 {
37973- tty->open_count--;
37974-
37975- if (tty->open_count == 0) {
37976+ if (local_dec_return(&tty->open_count) == 0) {
37977 struct tty_struct *linux_tty = tty->linux_tty;
37978
37979 if (linux_tty != NULL) {
37980@@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37981 return;
37982
37983 mutex_lock(&tty->ipw_tty_mutex);
37984- if (tty->open_count == 0) {
37985+ if (local_read(&tty->open_count) == 0) {
37986 mutex_unlock(&tty->ipw_tty_mutex);
37987 return;
37988 }
37989@@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37990 return;
37991 }
37992
37993- if (!tty->open_count) {
37994+ if (!local_read(&tty->open_count)) {
37995 mutex_unlock(&tty->ipw_tty_mutex);
37996 return;
37997 }
37998@@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37999 return -ENODEV;
38000
38001 mutex_lock(&tty->ipw_tty_mutex);
38002- if (!tty->open_count) {
38003+ if (!local_read(&tty->open_count)) {
38004 mutex_unlock(&tty->ipw_tty_mutex);
38005 return -EINVAL;
38006 }
38007@@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38008 if (!tty)
38009 return -ENODEV;
38010
38011- if (!tty->open_count)
38012+ if (!local_read(&tty->open_count))
38013 return -EINVAL;
38014
38015 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38016@@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38017 if (!tty)
38018 return 0;
38019
38020- if (!tty->open_count)
38021+ if (!local_read(&tty->open_count))
38022 return 0;
38023
38024 return tty->tx_bytes_queued;
38025@@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38026 if (!tty)
38027 return -ENODEV;
38028
38029- if (!tty->open_count)
38030+ if (!local_read(&tty->open_count))
38031 return -EINVAL;
38032
38033 return get_control_lines(tty);
38034@@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38035 if (!tty)
38036 return -ENODEV;
38037
38038- if (!tty->open_count)
38039+ if (!local_read(&tty->open_count))
38040 return -EINVAL;
38041
38042 return set_control_lines(tty, set, clear);
38043@@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38044 if (!tty)
38045 return -ENODEV;
38046
38047- if (!tty->open_count)
38048+ if (!local_read(&tty->open_count))
38049 return -EINVAL;
38050
38051 /* FIXME: Exactly how is the tty object locked here .. */
38052@@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38053 against a parallel ioctl etc */
38054 mutex_lock(&ttyj->ipw_tty_mutex);
38055 }
38056- while (ttyj->open_count)
38057+ while (local_read(&ttyj->open_count))
38058 do_ipw_close(ttyj);
38059 ipwireless_disassociate_network_ttys(network,
38060 ttyj->channel_idx);
38061diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38062index fc7bbba..9527e93 100644
38063--- a/drivers/tty/n_gsm.c
38064+++ b/drivers/tty/n_gsm.c
38065@@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38066 kref_init(&dlci->ref);
38067 mutex_init(&dlci->mutex);
38068 dlci->fifo = &dlci->_fifo;
38069- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38070+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38071 kfree(dlci);
38072 return NULL;
38073 }
38074diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38075index d2256d0..97476fa 100644
38076--- a/drivers/tty/n_tty.c
38077+++ b/drivers/tty/n_tty.c
38078@@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38079 {
38080 *ops = tty_ldisc_N_TTY;
38081 ops->owner = NULL;
38082- ops->refcount = ops->flags = 0;
38083+ atomic_set(&ops->refcount, 0);
38084+ ops->flags = 0;
38085 }
38086 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38087diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38088index d8653ab..f8afd9d 100644
38089--- a/drivers/tty/pty.c
38090+++ b/drivers/tty/pty.c
38091@@ -765,8 +765,10 @@ static void __init unix98_pty_init(void)
38092 register_sysctl_table(pty_root_table);
38093
38094 /* Now create the /dev/ptmx special device */
38095+ pax_open_kernel();
38096 tty_default_fops(&ptmx_fops);
38097- ptmx_fops.open = ptmx_open;
38098+ *(void **)&ptmx_fops.open = ptmx_open;
38099+ pax_close_kernel();
38100
38101 cdev_init(&ptmx_cdev, &ptmx_fops);
38102 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38103diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38104index 2b42a01..32a2ed3 100644
38105--- a/drivers/tty/serial/kgdboc.c
38106+++ b/drivers/tty/serial/kgdboc.c
38107@@ -24,8 +24,9 @@
38108 #define MAX_CONFIG_LEN 40
38109
38110 static struct kgdb_io kgdboc_io_ops;
38111+static struct kgdb_io kgdboc_io_ops_console;
38112
38113-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38114+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38115 static int configured = -1;
38116
38117 static char config[MAX_CONFIG_LEN];
38118@@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38119 kgdboc_unregister_kbd();
38120 if (configured == 1)
38121 kgdb_unregister_io_module(&kgdboc_io_ops);
38122+ else if (configured == 2)
38123+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
38124 }
38125
38126 static int configure_kgdboc(void)
38127@@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38128 int err;
38129 char *cptr = config;
38130 struct console *cons;
38131+ int is_console = 0;
38132
38133 err = kgdboc_option_setup(config);
38134 if (err || !strlen(config) || isspace(config[0]))
38135 goto noconfig;
38136
38137 err = -ENODEV;
38138- kgdboc_io_ops.is_console = 0;
38139 kgdb_tty_driver = NULL;
38140
38141 kgdboc_use_kms = 0;
38142@@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38143 int idx;
38144 if (cons->device && cons->device(cons, &idx) == p &&
38145 idx == tty_line) {
38146- kgdboc_io_ops.is_console = 1;
38147+ is_console = 1;
38148 break;
38149 }
38150 cons = cons->next;
38151@@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38152 kgdb_tty_line = tty_line;
38153
38154 do_register:
38155- err = kgdb_register_io_module(&kgdboc_io_ops);
38156+ if (is_console) {
38157+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
38158+ configured = 2;
38159+ } else {
38160+ err = kgdb_register_io_module(&kgdboc_io_ops);
38161+ configured = 1;
38162+ }
38163 if (err)
38164 goto noconfig;
38165
38166- configured = 1;
38167-
38168 return 0;
38169
38170 noconfig:
38171@@ -213,7 +220,7 @@ noconfig:
38172 static int __init init_kgdboc(void)
38173 {
38174 /* Already configured? */
38175- if (configured == 1)
38176+ if (configured >= 1)
38177 return 0;
38178
38179 return configure_kgdboc();
38180@@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38181 if (config[len - 1] == '\n')
38182 config[len - 1] = '\0';
38183
38184- if (configured == 1)
38185+ if (configured >= 1)
38186 cleanup_kgdboc();
38187
38188 /* Go and configure with the new params. */
38189@@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38190 .post_exception = kgdboc_post_exp_handler,
38191 };
38192
38193+static struct kgdb_io kgdboc_io_ops_console = {
38194+ .name = "kgdboc",
38195+ .read_char = kgdboc_get_char,
38196+ .write_char = kgdboc_put_char,
38197+ .pre_exception = kgdboc_pre_exp_handler,
38198+ .post_exception = kgdboc_post_exp_handler,
38199+ .is_console = 1
38200+};
38201+
38202 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38203 /* This is only available if kgdboc is a built in for early debugging */
38204 static int __init kgdboc_early_init(char *opt)
38205diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38206index 7867b7c..b3c119d 100644
38207--- a/drivers/tty/sysrq.c
38208+++ b/drivers/tty/sysrq.c
38209@@ -862,7 +862,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38210 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38211 size_t count, loff_t *ppos)
38212 {
38213- if (count) {
38214+ if (count && capable(CAP_SYS_ADMIN)) {
38215 char c;
38216
38217 if (get_user(c, buf))
38218diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38219index e41b9bb..84002fb 100644
38220--- a/drivers/tty/tty_io.c
38221+++ b/drivers/tty/tty_io.c
38222@@ -3291,7 +3291,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38223
38224 void tty_default_fops(struct file_operations *fops)
38225 {
38226- *fops = tty_fops;
38227+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38228 }
38229
38230 /*
38231diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38232index 24b95db..9c078d0 100644
38233--- a/drivers/tty/tty_ldisc.c
38234+++ b/drivers/tty/tty_ldisc.c
38235@@ -57,7 +57,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38236 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38237 struct tty_ldisc_ops *ldo = ld->ops;
38238
38239- ldo->refcount--;
38240+ atomic_dec(&ldo->refcount);
38241 module_put(ldo->owner);
38242 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38243
38244@@ -92,7 +92,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38245 spin_lock_irqsave(&tty_ldisc_lock, flags);
38246 tty_ldiscs[disc] = new_ldisc;
38247 new_ldisc->num = disc;
38248- new_ldisc->refcount = 0;
38249+ atomic_set(&new_ldisc->refcount, 0);
38250 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38251
38252 return ret;
38253@@ -120,7 +120,7 @@ int tty_unregister_ldisc(int disc)
38254 return -EINVAL;
38255
38256 spin_lock_irqsave(&tty_ldisc_lock, flags);
38257- if (tty_ldiscs[disc]->refcount)
38258+ if (atomic_read(&tty_ldiscs[disc]->refcount))
38259 ret = -EBUSY;
38260 else
38261 tty_ldiscs[disc] = NULL;
38262@@ -141,7 +141,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38263 if (ldops) {
38264 ret = ERR_PTR(-EAGAIN);
38265 if (try_module_get(ldops->owner)) {
38266- ldops->refcount++;
38267+ atomic_inc(&ldops->refcount);
38268 ret = ldops;
38269 }
38270 }
38271@@ -154,7 +154,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38272 unsigned long flags;
38273
38274 spin_lock_irqsave(&tty_ldisc_lock, flags);
38275- ldops->refcount--;
38276+ atomic_dec(&ldops->refcount);
38277 module_put(ldops->owner);
38278 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38279 }
38280diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38281index a605549..6bd3c96 100644
38282--- a/drivers/tty/vt/keyboard.c
38283+++ b/drivers/tty/vt/keyboard.c
38284@@ -657,6 +657,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38285 kbd->kbdmode == VC_OFF) &&
38286 value != KVAL(K_SAK))
38287 return; /* SAK is allowed even in raw mode */
38288+
38289+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38290+ {
38291+ void *func = fn_handler[value];
38292+ if (func == fn_show_state || func == fn_show_ptregs ||
38293+ func == fn_show_mem)
38294+ return;
38295+ }
38296+#endif
38297+
38298 fn_handler[value](vc);
38299 }
38300
38301diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
38302index 65447c5..0526f0a 100644
38303--- a/drivers/tty/vt/vt_ioctl.c
38304+++ b/drivers/tty/vt/vt_ioctl.c
38305@@ -207,9 +207,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38306 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38307 return -EFAULT;
38308
38309- if (!capable(CAP_SYS_TTY_CONFIG))
38310- perm = 0;
38311-
38312 switch (cmd) {
38313 case KDGKBENT:
38314 key_map = key_maps[s];
38315@@ -221,6 +218,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38316 val = (i ? K_HOLE : K_NOSUCHMAP);
38317 return put_user(val, &user_kbe->kb_value);
38318 case KDSKBENT:
38319+ if (!capable(CAP_SYS_TTY_CONFIG))
38320+ perm = 0;
38321+
38322 if (!perm)
38323 return -EPERM;
38324 if (!i && v == K_NOSUCHMAP) {
38325@@ -322,9 +322,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38326 int i, j, k;
38327 int ret;
38328
38329- if (!capable(CAP_SYS_TTY_CONFIG))
38330- perm = 0;
38331-
38332 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38333 if (!kbs) {
38334 ret = -ENOMEM;
38335@@ -358,6 +355,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38336 kfree(kbs);
38337 return ((p && *p) ? -EOVERFLOW : 0);
38338 case KDSKBSENT:
38339+ if (!capable(CAP_SYS_TTY_CONFIG))
38340+ perm = 0;
38341+
38342 if (!perm) {
38343 ret = -EPERM;
38344 goto reterr;
38345diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38346index a783d53..cb30d94 100644
38347--- a/drivers/uio/uio.c
38348+++ b/drivers/uio/uio.c
38349@@ -25,6 +25,7 @@
38350 #include <linux/kobject.h>
38351 #include <linux/cdev.h>
38352 #include <linux/uio_driver.h>
38353+#include <asm/local.h>
38354
38355 #define UIO_MAX_DEVICES (1U << MINORBITS)
38356
38357@@ -32,10 +33,10 @@ struct uio_device {
38358 struct module *owner;
38359 struct device *dev;
38360 int minor;
38361- atomic_t event;
38362+ atomic_unchecked_t event;
38363 struct fasync_struct *async_queue;
38364 wait_queue_head_t wait;
38365- int vma_count;
38366+ local_t vma_count;
38367 struct uio_info *info;
38368 struct kobject *map_dir;
38369 struct kobject *portio_dir;
38370@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38371 struct device_attribute *attr, char *buf)
38372 {
38373 struct uio_device *idev = dev_get_drvdata(dev);
38374- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38375+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38376 }
38377
38378 static struct device_attribute uio_class_attributes[] = {
38379@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38380 {
38381 struct uio_device *idev = info->uio_dev;
38382
38383- atomic_inc(&idev->event);
38384+ atomic_inc_unchecked(&idev->event);
38385 wake_up_interruptible(&idev->wait);
38386 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38387 }
38388@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38389 }
38390
38391 listener->dev = idev;
38392- listener->event_count = atomic_read(&idev->event);
38393+ listener->event_count = atomic_read_unchecked(&idev->event);
38394 filep->private_data = listener;
38395
38396 if (idev->info->open) {
38397@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38398 return -EIO;
38399
38400 poll_wait(filep, &idev->wait, wait);
38401- if (listener->event_count != atomic_read(&idev->event))
38402+ if (listener->event_count != atomic_read_unchecked(&idev->event))
38403 return POLLIN | POLLRDNORM;
38404 return 0;
38405 }
38406@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38407 do {
38408 set_current_state(TASK_INTERRUPTIBLE);
38409
38410- event_count = atomic_read(&idev->event);
38411+ event_count = atomic_read_unchecked(&idev->event);
38412 if (event_count != listener->event_count) {
38413 if (copy_to_user(buf, &event_count, count))
38414 retval = -EFAULT;
38415@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38416 static void uio_vma_open(struct vm_area_struct *vma)
38417 {
38418 struct uio_device *idev = vma->vm_private_data;
38419- idev->vma_count++;
38420+ local_inc(&idev->vma_count);
38421 }
38422
38423 static void uio_vma_close(struct vm_area_struct *vma)
38424 {
38425 struct uio_device *idev = vma->vm_private_data;
38426- idev->vma_count--;
38427+ local_dec(&idev->vma_count);
38428 }
38429
38430 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38431@@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38432 idev->owner = owner;
38433 idev->info = info;
38434 init_waitqueue_head(&idev->wait);
38435- atomic_set(&idev->event, 0);
38436+ atomic_set_unchecked(&idev->event, 0);
38437
38438 ret = uio_get_minor(idev);
38439 if (ret)
38440diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38441index 98b89fe..aff824e 100644
38442--- a/drivers/usb/atm/cxacru.c
38443+++ b/drivers/usb/atm/cxacru.c
38444@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38445 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38446 if (ret < 2)
38447 return -EINVAL;
38448- if (index < 0 || index > 0x7f)
38449+ if (index > 0x7f)
38450 return -EINVAL;
38451 pos += tmp;
38452
38453diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38454index d3448ca..d2864ca 100644
38455--- a/drivers/usb/atm/usbatm.c
38456+++ b/drivers/usb/atm/usbatm.c
38457@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38458 if (printk_ratelimit())
38459 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38460 __func__, vpi, vci);
38461- atomic_inc(&vcc->stats->rx_err);
38462+ atomic_inc_unchecked(&vcc->stats->rx_err);
38463 return;
38464 }
38465
38466@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38467 if (length > ATM_MAX_AAL5_PDU) {
38468 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38469 __func__, length, vcc);
38470- atomic_inc(&vcc->stats->rx_err);
38471+ atomic_inc_unchecked(&vcc->stats->rx_err);
38472 goto out;
38473 }
38474
38475@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38476 if (sarb->len < pdu_length) {
38477 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38478 __func__, pdu_length, sarb->len, vcc);
38479- atomic_inc(&vcc->stats->rx_err);
38480+ atomic_inc_unchecked(&vcc->stats->rx_err);
38481 goto out;
38482 }
38483
38484 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38485 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38486 __func__, vcc);
38487- atomic_inc(&vcc->stats->rx_err);
38488+ atomic_inc_unchecked(&vcc->stats->rx_err);
38489 goto out;
38490 }
38491
38492@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38493 if (printk_ratelimit())
38494 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38495 __func__, length);
38496- atomic_inc(&vcc->stats->rx_drop);
38497+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38498 goto out;
38499 }
38500
38501@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38502
38503 vcc->push(vcc, skb);
38504
38505- atomic_inc(&vcc->stats->rx);
38506+ atomic_inc_unchecked(&vcc->stats->rx);
38507 out:
38508 skb_trim(sarb, 0);
38509 }
38510@@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38511 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38512
38513 usbatm_pop(vcc, skb);
38514- atomic_inc(&vcc->stats->tx);
38515+ atomic_inc_unchecked(&vcc->stats->tx);
38516
38517 skb = skb_dequeue(&instance->sndqueue);
38518 }
38519@@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38520 if (!left--)
38521 return sprintf(page,
38522 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38523- atomic_read(&atm_dev->stats.aal5.tx),
38524- atomic_read(&atm_dev->stats.aal5.tx_err),
38525- atomic_read(&atm_dev->stats.aal5.rx),
38526- atomic_read(&atm_dev->stats.aal5.rx_err),
38527- atomic_read(&atm_dev->stats.aal5.rx_drop));
38528+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38529+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38530+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38531+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38532+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38533
38534 if (!left--) {
38535 if (instance->disconnected)
38536diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38537index d956965..4179a77 100644
38538--- a/drivers/usb/core/devices.c
38539+++ b/drivers/usb/core/devices.c
38540@@ -126,7 +126,7 @@ static const char format_endpt[] =
38541 * time it gets called.
38542 */
38543 static struct device_connect_event {
38544- atomic_t count;
38545+ atomic_unchecked_t count;
38546 wait_queue_head_t wait;
38547 } device_event = {
38548 .count = ATOMIC_INIT(1),
38549@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38550
38551 void usbfs_conn_disc_event(void)
38552 {
38553- atomic_add(2, &device_event.count);
38554+ atomic_add_unchecked(2, &device_event.count);
38555 wake_up(&device_event.wait);
38556 }
38557
38558@@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38559
38560 poll_wait(file, &device_event.wait, wait);
38561
38562- event_count = atomic_read(&device_event.count);
38563+ event_count = atomic_read_unchecked(&device_event.count);
38564 if (file->f_version != event_count) {
38565 file->f_version = event_count;
38566 return POLLIN | POLLRDNORM;
38567diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38568index 1fc8f12..20647c1 100644
38569--- a/drivers/usb/early/ehci-dbgp.c
38570+++ b/drivers/usb/early/ehci-dbgp.c
38571@@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38572
38573 #ifdef CONFIG_KGDB
38574 static struct kgdb_io kgdbdbgp_io_ops;
38575-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38576+static struct kgdb_io kgdbdbgp_io_ops_console;
38577+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38578 #else
38579 #define dbgp_kgdb_mode (0)
38580 #endif
38581@@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38582 .write_char = kgdbdbgp_write_char,
38583 };
38584
38585+static struct kgdb_io kgdbdbgp_io_ops_console = {
38586+ .name = "kgdbdbgp",
38587+ .read_char = kgdbdbgp_read_char,
38588+ .write_char = kgdbdbgp_write_char,
38589+ .is_console = 1
38590+};
38591+
38592 static int kgdbdbgp_wait_time;
38593
38594 static int __init kgdbdbgp_parse_config(char *str)
38595@@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38596 ptr++;
38597 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38598 }
38599- kgdb_register_io_module(&kgdbdbgp_io_ops);
38600- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38601+ if (early_dbgp_console.index != -1)
38602+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38603+ else
38604+ kgdb_register_io_module(&kgdbdbgp_io_ops);
38605
38606 return 0;
38607 }
38608diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38609index d6bea3e..60b250e 100644
38610--- a/drivers/usb/wusbcore/wa-hc.h
38611+++ b/drivers/usb/wusbcore/wa-hc.h
38612@@ -192,7 +192,7 @@ struct wahc {
38613 struct list_head xfer_delayed_list;
38614 spinlock_t xfer_list_lock;
38615 struct work_struct xfer_work;
38616- atomic_t xfer_id_count;
38617+ atomic_unchecked_t xfer_id_count;
38618 };
38619
38620
38621@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38622 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38623 spin_lock_init(&wa->xfer_list_lock);
38624 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38625- atomic_set(&wa->xfer_id_count, 1);
38626+ atomic_set_unchecked(&wa->xfer_id_count, 1);
38627 }
38628
38629 /**
38630diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38631index 57c01ab..8a05959 100644
38632--- a/drivers/usb/wusbcore/wa-xfer.c
38633+++ b/drivers/usb/wusbcore/wa-xfer.c
38634@@ -296,7 +296,7 @@ out:
38635 */
38636 static void wa_xfer_id_init(struct wa_xfer *xfer)
38637 {
38638- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38639+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38640 }
38641
38642 /*
38643diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38644index c14c42b..f955cc2 100644
38645--- a/drivers/vhost/vhost.c
38646+++ b/drivers/vhost/vhost.c
38647@@ -629,7 +629,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38648 return 0;
38649 }
38650
38651-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38652+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38653 {
38654 struct file *eventfp, *filep = NULL,
38655 *pollstart = NULL, *pollstop = NULL;
38656diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38657index b0b2ac3..89a4399 100644
38658--- a/drivers/video/aty/aty128fb.c
38659+++ b/drivers/video/aty/aty128fb.c
38660@@ -148,7 +148,7 @@ enum {
38661 };
38662
38663 /* Must match above enum */
38664-static const char *r128_family[] __devinitdata = {
38665+static const char *r128_family[] __devinitconst = {
38666 "AGP",
38667 "PCI",
38668 "PRO AGP",
38669diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38670index 5c3960d..15cf8fc 100644
38671--- a/drivers/video/fbcmap.c
38672+++ b/drivers/video/fbcmap.c
38673@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38674 rc = -ENODEV;
38675 goto out;
38676 }
38677- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38678- !info->fbops->fb_setcmap)) {
38679+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38680 rc = -EINVAL;
38681 goto out1;
38682 }
38683diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
38684index c6ce416..3b9b642 100644
38685--- a/drivers/video/fbmem.c
38686+++ b/drivers/video/fbmem.c
38687@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38688 image->dx += image->width + 8;
38689 }
38690 } else if (rotate == FB_ROTATE_UD) {
38691- for (x = 0; x < num && image->dx >= 0; x++) {
38692+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
38693 info->fbops->fb_imageblit(info, image);
38694 image->dx -= image->width + 8;
38695 }
38696@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38697 image->dy += image->height + 8;
38698 }
38699 } else if (rotate == FB_ROTATE_CCW) {
38700- for (x = 0; x < num && image->dy >= 0; x++) {
38701+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
38702 info->fbops->fb_imageblit(info, image);
38703 image->dy -= image->height + 8;
38704 }
38705@@ -1157,7 +1157,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
38706 return -EFAULT;
38707 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
38708 return -EINVAL;
38709- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
38710+ if (con2fb.framebuffer >= FB_MAX)
38711 return -EINVAL;
38712 if (!registered_fb[con2fb.framebuffer])
38713 request_module("fb%d", con2fb.framebuffer);
38714diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
38715index 5a5d092..265c5ed 100644
38716--- a/drivers/video/geode/gx1fb_core.c
38717+++ b/drivers/video/geode/gx1fb_core.c
38718@@ -29,7 +29,7 @@ static int crt_option = 1;
38719 static char panel_option[32] = "";
38720
38721 /* Modes relevant to the GX1 (taken from modedb.c) */
38722-static const struct fb_videomode __devinitdata gx1_modedb[] = {
38723+static const struct fb_videomode __devinitconst gx1_modedb[] = {
38724 /* 640x480-60 VESA */
38725 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
38726 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
38727diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
38728index 0fad23f..0e9afa4 100644
38729--- a/drivers/video/gxt4500.c
38730+++ b/drivers/video/gxt4500.c
38731@@ -156,7 +156,7 @@ struct gxt4500_par {
38732 static char *mode_option;
38733
38734 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
38735-static const struct fb_videomode defaultmode __devinitdata = {
38736+static const struct fb_videomode defaultmode __devinitconst = {
38737 .refresh = 60,
38738 .xres = 1280,
38739 .yres = 1024,
38740@@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
38741 return 0;
38742 }
38743
38744-static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
38745+static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
38746 .id = "IBM GXT4500P",
38747 .type = FB_TYPE_PACKED_PIXELS,
38748 .visual = FB_VISUAL_PSEUDOCOLOR,
38749diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
38750index 7672d2e..b56437f 100644
38751--- a/drivers/video/i810/i810_accel.c
38752+++ b/drivers/video/i810/i810_accel.c
38753@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
38754 }
38755 }
38756 printk("ringbuffer lockup!!!\n");
38757+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
38758 i810_report_error(mmio);
38759 par->dev_flags |= LOCKUP;
38760 info->pixmap.scan_align = 1;
38761diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
38762index b83f361..2b05a91 100644
38763--- a/drivers/video/i810/i810_main.c
38764+++ b/drivers/video/i810/i810_main.c
38765@@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
38766 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
38767
38768 /* PCI */
38769-static const char *i810_pci_list[] __devinitdata = {
38770+static const char *i810_pci_list[] __devinitconst = {
38771 "Intel(R) 810 Framebuffer Device" ,
38772 "Intel(R) 810-DC100 Framebuffer Device" ,
38773 "Intel(R) 810E Framebuffer Device" ,
38774diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
38775index de36693..3c63fc2 100644
38776--- a/drivers/video/jz4740_fb.c
38777+++ b/drivers/video/jz4740_fb.c
38778@@ -136,7 +136,7 @@ struct jzfb {
38779 uint32_t pseudo_palette[16];
38780 };
38781
38782-static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
38783+static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
38784 .id = "JZ4740 FB",
38785 .type = FB_TYPE_PACKED_PIXELS,
38786 .visual = FB_VISUAL_TRUECOLOR,
38787diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
38788index 3c14e43..eafa544 100644
38789--- a/drivers/video/logo/logo_linux_clut224.ppm
38790+++ b/drivers/video/logo/logo_linux_clut224.ppm
38791@@ -1,1604 +1,1123 @@
38792 P3
38793-# Standard 224-color Linux logo
38794 80 80
38795 255
38796- 0 0 0 0 0 0 0 0 0 0 0 0
38797- 0 0 0 0 0 0 0 0 0 0 0 0
38798- 0 0 0 0 0 0 0 0 0 0 0 0
38799- 0 0 0 0 0 0 0 0 0 0 0 0
38800- 0 0 0 0 0 0 0 0 0 0 0 0
38801- 0 0 0 0 0 0 0 0 0 0 0 0
38802- 0 0 0 0 0 0 0 0 0 0 0 0
38803- 0 0 0 0 0 0 0 0 0 0 0 0
38804- 0 0 0 0 0 0 0 0 0 0 0 0
38805- 6 6 6 6 6 6 10 10 10 10 10 10
38806- 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0
38813- 0 0 0 0 0 0 0 0 0 0 0 0
38814- 0 0 0 0 0 0 0 0 0 0 0 0
38815- 0 0 0 0 0 0 0 0 0 0 0 0
38816- 0 0 0 0 0 0 0 0 0 0 0 0
38817- 0 0 0 0 0 0 0 0 0 0 0 0
38818- 0 0 0 0 0 0 0 0 0 0 0 0
38819- 0 0 0 0 0 0 0 0 0 0 0 0
38820- 0 0 0 0 0 0 0 0 0 0 0 0
38821- 0 0 0 0 0 0 0 0 0 0 0 0
38822- 0 0 0 0 0 0 0 0 0 0 0 0
38823- 0 0 0 0 0 0 0 0 0 0 0 0
38824- 0 0 0 6 6 6 10 10 10 14 14 14
38825- 22 22 22 26 26 26 30 30 30 34 34 34
38826- 30 30 30 30 30 30 26 26 26 18 18 18
38827- 14 14 14 10 10 10 6 6 6 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 0 0 0 0 0 0
38833- 0 0 0 0 0 0 0 0 0 0 0 0
38834- 0 0 0 0 0 0 0 0 0 0 0 0
38835- 0 0 0 0 0 0 0 0 0 0 0 0
38836- 0 0 0 0 0 0 0 0 0 0 0 0
38837- 0 0 0 0 0 1 0 0 1 0 0 0
38838- 0 0 0 0 0 0 0 0 0 0 0 0
38839- 0 0 0 0 0 0 0 0 0 0 0 0
38840- 0 0 0 0 0 0 0 0 0 0 0 0
38841- 0 0 0 0 0 0 0 0 0 0 0 0
38842- 0 0 0 0 0 0 0 0 0 0 0 0
38843- 0 0 0 0 0 0 0 0 0 0 0 0
38844- 6 6 6 14 14 14 26 26 26 42 42 42
38845- 54 54 54 66 66 66 78 78 78 78 78 78
38846- 78 78 78 74 74 74 66 66 66 54 54 54
38847- 42 42 42 26 26 26 18 18 18 10 10 10
38848- 6 6 6 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 0 0 0 0 0 0
38853- 0 0 0 0 0 0 0 0 0 0 0 0
38854- 0 0 0 0 0 0 0 0 0 0 0 0
38855- 0 0 0 0 0 0 0 0 0 0 0 0
38856- 0 0 0 0 0 0 0 0 0 0 0 0
38857- 0 0 1 0 0 0 0 0 0 0 0 0
38858- 0 0 0 0 0 0 0 0 0 0 0 0
38859- 0 0 0 0 0 0 0 0 0 0 0 0
38860- 0 0 0 0 0 0 0 0 0 0 0 0
38861- 0 0 0 0 0 0 0 0 0 0 0 0
38862- 0 0 0 0 0 0 0 0 0 0 0 0
38863- 0 0 0 0 0 0 0 0 0 10 10 10
38864- 22 22 22 42 42 42 66 66 66 86 86 86
38865- 66 66 66 38 38 38 38 38 38 22 22 22
38866- 26 26 26 34 34 34 54 54 54 66 66 66
38867- 86 86 86 70 70 70 46 46 46 26 26 26
38868- 14 14 14 6 6 6 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 0 0 0 0 0 0
38873- 0 0 0 0 0 0 0 0 0 0 0 0
38874- 0 0 0 0 0 0 0 0 0 0 0 0
38875- 0 0 0 0 0 0 0 0 0 0 0 0
38876- 0 0 0 0 0 0 0 0 0 0 0 0
38877- 0 0 1 0 0 1 0 0 1 0 0 0
38878- 0 0 0 0 0 0 0 0 0 0 0 0
38879- 0 0 0 0 0 0 0 0 0 0 0 0
38880- 0 0 0 0 0 0 0 0 0 0 0 0
38881- 0 0 0 0 0 0 0 0 0 0 0 0
38882- 0 0 0 0 0 0 0 0 0 0 0 0
38883- 0 0 0 0 0 0 10 10 10 26 26 26
38884- 50 50 50 82 82 82 58 58 58 6 6 6
38885- 2 2 6 2 2 6 2 2 6 2 2 6
38886- 2 2 6 2 2 6 2 2 6 2 2 6
38887- 6 6 6 54 54 54 86 86 86 66 66 66
38888- 38 38 38 18 18 18 6 6 6 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 0 0 0 0 0 0
38893- 0 0 0 0 0 0 0 0 0 0 0 0
38894- 0 0 0 0 0 0 0 0 0 0 0 0
38895- 0 0 0 0 0 0 0 0 0 0 0 0
38896- 0 0 0 0 0 0 0 0 0 0 0 0
38897- 0 0 0 0 0 0 0 0 0 0 0 0
38898- 0 0 0 0 0 0 0 0 0 0 0 0
38899- 0 0 0 0 0 0 0 0 0 0 0 0
38900- 0 0 0 0 0 0 0 0 0 0 0 0
38901- 0 0 0 0 0 0 0 0 0 0 0 0
38902- 0 0 0 0 0 0 0 0 0 0 0 0
38903- 0 0 0 6 6 6 22 22 22 50 50 50
38904- 78 78 78 34 34 34 2 2 6 2 2 6
38905- 2 2 6 2 2 6 2 2 6 2 2 6
38906- 2 2 6 2 2 6 2 2 6 2 2 6
38907- 2 2 6 2 2 6 6 6 6 70 70 70
38908- 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0
38912- 0 0 0 0 0 0 0 0 0 0 0 0
38913- 0 0 0 0 0 0 0 0 0 0 0 0
38914- 0 0 0 0 0 0 0 0 0 0 0 0
38915- 0 0 0 0 0 0 0 0 0 0 0 0
38916- 0 0 0 0 0 0 0 0 0 0 0 0
38917- 0 0 1 0 0 1 0 0 1 0 0 0
38918- 0 0 0 0 0 0 0 0 0 0 0 0
38919- 0 0 0 0 0 0 0 0 0 0 0 0
38920- 0 0 0 0 0 0 0 0 0 0 0 0
38921- 0 0 0 0 0 0 0 0 0 0 0 0
38922- 0 0 0 0 0 0 0 0 0 0 0 0
38923- 6 6 6 18 18 18 42 42 42 82 82 82
38924- 26 26 26 2 2 6 2 2 6 2 2 6
38925- 2 2 6 2 2 6 2 2 6 2 2 6
38926- 2 2 6 2 2 6 2 2 6 14 14 14
38927- 46 46 46 34 34 34 6 6 6 2 2 6
38928- 42 42 42 78 78 78 42 42 42 18 18 18
38929- 6 6 6 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 0 0 0 0 0 0 0 0 0
38932- 0 0 0 0 0 0 0 0 0 0 0 0
38933- 0 0 0 0 0 0 0 0 0 0 0 0
38934- 0 0 0 0 0 0 0 0 0 0 0 0
38935- 0 0 0 0 0 0 0 0 0 0 0 0
38936- 0 0 0 0 0 0 0 0 0 0 0 0
38937- 0 0 1 0 0 0 0 0 1 0 0 0
38938- 0 0 0 0 0 0 0 0 0 0 0 0
38939- 0 0 0 0 0 0 0 0 0 0 0 0
38940- 0 0 0 0 0 0 0 0 0 0 0 0
38941- 0 0 0 0 0 0 0 0 0 0 0 0
38942- 0 0 0 0 0 0 0 0 0 0 0 0
38943- 10 10 10 30 30 30 66 66 66 58 58 58
38944- 2 2 6 2 2 6 2 2 6 2 2 6
38945- 2 2 6 2 2 6 2 2 6 2 2 6
38946- 2 2 6 2 2 6 2 2 6 26 26 26
38947- 86 86 86 101 101 101 46 46 46 10 10 10
38948- 2 2 6 58 58 58 70 70 70 34 34 34
38949- 10 10 10 0 0 0 0 0 0 0 0 0
38950- 0 0 0 0 0 0 0 0 0 0 0 0
38951- 0 0 0 0 0 0 0 0 0 0 0 0
38952- 0 0 0 0 0 0 0 0 0 0 0 0
38953- 0 0 0 0 0 0 0 0 0 0 0 0
38954- 0 0 0 0 0 0 0 0 0 0 0 0
38955- 0 0 0 0 0 0 0 0 0 0 0 0
38956- 0 0 0 0 0 0 0 0 0 0 0 0
38957- 0 0 1 0 0 1 0 0 1 0 0 0
38958- 0 0 0 0 0 0 0 0 0 0 0 0
38959- 0 0 0 0 0 0 0 0 0 0 0 0
38960- 0 0 0 0 0 0 0 0 0 0 0 0
38961- 0 0 0 0 0 0 0 0 0 0 0 0
38962- 0 0 0 0 0 0 0 0 0 0 0 0
38963- 14 14 14 42 42 42 86 86 86 10 10 10
38964- 2 2 6 2 2 6 2 2 6 2 2 6
38965- 2 2 6 2 2 6 2 2 6 2 2 6
38966- 2 2 6 2 2 6 2 2 6 30 30 30
38967- 94 94 94 94 94 94 58 58 58 26 26 26
38968- 2 2 6 6 6 6 78 78 78 54 54 54
38969- 22 22 22 6 6 6 0 0 0 0 0 0
38970- 0 0 0 0 0 0 0 0 0 0 0 0
38971- 0 0 0 0 0 0 0 0 0 0 0 0
38972- 0 0 0 0 0 0 0 0 0 0 0 0
38973- 0 0 0 0 0 0 0 0 0 0 0 0
38974- 0 0 0 0 0 0 0 0 0 0 0 0
38975- 0 0 0 0 0 0 0 0 0 0 0 0
38976- 0 0 0 0 0 0 0 0 0 0 0 0
38977- 0 0 0 0 0 0 0 0 0 0 0 0
38978- 0 0 0 0 0 0 0 0 0 0 0 0
38979- 0 0 0 0 0 0 0 0 0 0 0 0
38980- 0 0 0 0 0 0 0 0 0 0 0 0
38981- 0 0 0 0 0 0 0 0 0 0 0 0
38982- 0 0 0 0 0 0 0 0 0 6 6 6
38983- 22 22 22 62 62 62 62 62 62 2 2 6
38984- 2 2 6 2 2 6 2 2 6 2 2 6
38985- 2 2 6 2 2 6 2 2 6 2 2 6
38986- 2 2 6 2 2 6 2 2 6 26 26 26
38987- 54 54 54 38 38 38 18 18 18 10 10 10
38988- 2 2 6 2 2 6 34 34 34 82 82 82
38989- 38 38 38 14 14 14 0 0 0 0 0 0
38990- 0 0 0 0 0 0 0 0 0 0 0 0
38991- 0 0 0 0 0 0 0 0 0 0 0 0
38992- 0 0 0 0 0 0 0 0 0 0 0 0
38993- 0 0 0 0 0 0 0 0 0 0 0 0
38994- 0 0 0 0 0 0 0 0 0 0 0 0
38995- 0 0 0 0 0 0 0 0 0 0 0 0
38996- 0 0 0 0 0 0 0 0 0 0 0 0
38997- 0 0 0 0 0 1 0 0 1 0 0 0
38998- 0 0 0 0 0 0 0 0 0 0 0 0
38999- 0 0 0 0 0 0 0 0 0 0 0 0
39000- 0 0 0 0 0 0 0 0 0 0 0 0
39001- 0 0 0 0 0 0 0 0 0 0 0 0
39002- 0 0 0 0 0 0 0 0 0 6 6 6
39003- 30 30 30 78 78 78 30 30 30 2 2 6
39004- 2 2 6 2 2 6 2 2 6 2 2 6
39005- 2 2 6 2 2 6 2 2 6 2 2 6
39006- 2 2 6 2 2 6 2 2 6 10 10 10
39007- 10 10 10 2 2 6 2 2 6 2 2 6
39008- 2 2 6 2 2 6 2 2 6 78 78 78
39009- 50 50 50 18 18 18 6 6 6 0 0 0
39010- 0 0 0 0 0 0 0 0 0 0 0 0
39011- 0 0 0 0 0 0 0 0 0 0 0 0
39012- 0 0 0 0 0 0 0 0 0 0 0 0
39013- 0 0 0 0 0 0 0 0 0 0 0 0
39014- 0 0 0 0 0 0 0 0 0 0 0 0
39015- 0 0 0 0 0 0 0 0 0 0 0 0
39016- 0 0 0 0 0 0 0 0 0 0 0 0
39017- 0 0 1 0 0 0 0 0 0 0 0 0
39018- 0 0 0 0 0 0 0 0 0 0 0 0
39019- 0 0 0 0 0 0 0 0 0 0 0 0
39020- 0 0 0 0 0 0 0 0 0 0 0 0
39021- 0 0 0 0 0 0 0 0 0 0 0 0
39022- 0 0 0 0 0 0 0 0 0 10 10 10
39023- 38 38 38 86 86 86 14 14 14 2 2 6
39024- 2 2 6 2 2 6 2 2 6 2 2 6
39025- 2 2 6 2 2 6 2 2 6 2 2 6
39026- 2 2 6 2 2 6 2 2 6 2 2 6
39027- 2 2 6 2 2 6 2 2 6 2 2 6
39028- 2 2 6 2 2 6 2 2 6 54 54 54
39029- 66 66 66 26 26 26 6 6 6 0 0 0
39030- 0 0 0 0 0 0 0 0 0 0 0 0
39031- 0 0 0 0 0 0 0 0 0 0 0 0
39032- 0 0 0 0 0 0 0 0 0 0 0 0
39033- 0 0 0 0 0 0 0 0 0 0 0 0
39034- 0 0 0 0 0 0 0 0 0 0 0 0
39035- 0 0 0 0 0 0 0 0 0 0 0 0
39036- 0 0 0 0 0 0 0 0 0 0 0 0
39037- 0 0 0 0 0 1 0 0 1 0 0 0
39038- 0 0 0 0 0 0 0 0 0 0 0 0
39039- 0 0 0 0 0 0 0 0 0 0 0 0
39040- 0 0 0 0 0 0 0 0 0 0 0 0
39041- 0 0 0 0 0 0 0 0 0 0 0 0
39042- 0 0 0 0 0 0 0 0 0 14 14 14
39043- 42 42 42 82 82 82 2 2 6 2 2 6
39044- 2 2 6 6 6 6 10 10 10 2 2 6
39045- 2 2 6 2 2 6 2 2 6 2 2 6
39046- 2 2 6 2 2 6 2 2 6 6 6 6
39047- 14 14 14 10 10 10 2 2 6 2 2 6
39048- 2 2 6 2 2 6 2 2 6 18 18 18
39049- 82 82 82 34 34 34 10 10 10 0 0 0
39050- 0 0 0 0 0 0 0 0 0 0 0 0
39051- 0 0 0 0 0 0 0 0 0 0 0 0
39052- 0 0 0 0 0 0 0 0 0 0 0 0
39053- 0 0 0 0 0 0 0 0 0 0 0 0
39054- 0 0 0 0 0 0 0 0 0 0 0 0
39055- 0 0 0 0 0 0 0 0 0 0 0 0
39056- 0 0 0 0 0 0 0 0 0 0 0 0
39057- 0 0 1 0 0 0 0 0 0 0 0 0
39058- 0 0 0 0 0 0 0 0 0 0 0 0
39059- 0 0 0 0 0 0 0 0 0 0 0 0
39060- 0 0 0 0 0 0 0 0 0 0 0 0
39061- 0 0 0 0 0 0 0 0 0 0 0 0
39062- 0 0 0 0 0 0 0 0 0 14 14 14
39063- 46 46 46 86 86 86 2 2 6 2 2 6
39064- 6 6 6 6 6 6 22 22 22 34 34 34
39065- 6 6 6 2 2 6 2 2 6 2 2 6
39066- 2 2 6 2 2 6 18 18 18 34 34 34
39067- 10 10 10 50 50 50 22 22 22 2 2 6
39068- 2 2 6 2 2 6 2 2 6 10 10 10
39069- 86 86 86 42 42 42 14 14 14 0 0 0
39070- 0 0 0 0 0 0 0 0 0 0 0 0
39071- 0 0 0 0 0 0 0 0 0 0 0 0
39072- 0 0 0 0 0 0 0 0 0 0 0 0
39073- 0 0 0 0 0 0 0 0 0 0 0 0
39074- 0 0 0 0 0 0 0 0 0 0 0 0
39075- 0 0 0 0 0 0 0 0 0 0 0 0
39076- 0 0 0 0 0 0 0 0 0 0 0 0
39077- 0 0 1 0 0 1 0 0 1 0 0 0
39078- 0 0 0 0 0 0 0 0 0 0 0 0
39079- 0 0 0 0 0 0 0 0 0 0 0 0
39080- 0 0 0 0 0 0 0 0 0 0 0 0
39081- 0 0 0 0 0 0 0 0 0 0 0 0
39082- 0 0 0 0 0 0 0 0 0 14 14 14
39083- 46 46 46 86 86 86 2 2 6 2 2 6
39084- 38 38 38 116 116 116 94 94 94 22 22 22
39085- 22 22 22 2 2 6 2 2 6 2 2 6
39086- 14 14 14 86 86 86 138 138 138 162 162 162
39087-154 154 154 38 38 38 26 26 26 6 6 6
39088- 2 2 6 2 2 6 2 2 6 2 2 6
39089- 86 86 86 46 46 46 14 14 14 0 0 0
39090- 0 0 0 0 0 0 0 0 0 0 0 0
39091- 0 0 0 0 0 0 0 0 0 0 0 0
39092- 0 0 0 0 0 0 0 0 0 0 0 0
39093- 0 0 0 0 0 0 0 0 0 0 0 0
39094- 0 0 0 0 0 0 0 0 0 0 0 0
39095- 0 0 0 0 0 0 0 0 0 0 0 0
39096- 0 0 0 0 0 0 0 0 0 0 0 0
39097- 0 0 0 0 0 0 0 0 0 0 0 0
39098- 0 0 0 0 0 0 0 0 0 0 0 0
39099- 0 0 0 0 0 0 0 0 0 0 0 0
39100- 0 0 0 0 0 0 0 0 0 0 0 0
39101- 0 0 0 0 0 0 0 0 0 0 0 0
39102- 0 0 0 0 0 0 0 0 0 14 14 14
39103- 46 46 46 86 86 86 2 2 6 14 14 14
39104-134 134 134 198 198 198 195 195 195 116 116 116
39105- 10 10 10 2 2 6 2 2 6 6 6 6
39106-101 98 89 187 187 187 210 210 210 218 218 218
39107-214 214 214 134 134 134 14 14 14 6 6 6
39108- 2 2 6 2 2 6 2 2 6 2 2 6
39109- 86 86 86 50 50 50 18 18 18 6 6 6
39110- 0 0 0 0 0 0 0 0 0 0 0 0
39111- 0 0 0 0 0 0 0 0 0 0 0 0
39112- 0 0 0 0 0 0 0 0 0 0 0 0
39113- 0 0 0 0 0 0 0 0 0 0 0 0
39114- 0 0 0 0 0 0 0 0 0 0 0 0
39115- 0 0 0 0 0 0 0 0 0 0 0 0
39116- 0 0 0 0 0 0 0 0 1 0 0 0
39117- 0 0 1 0 0 1 0 0 1 0 0 0
39118- 0 0 0 0 0 0 0 0 0 0 0 0
39119- 0 0 0 0 0 0 0 0 0 0 0 0
39120- 0 0 0 0 0 0 0 0 0 0 0 0
39121- 0 0 0 0 0 0 0 0 0 0 0 0
39122- 0 0 0 0 0 0 0 0 0 14 14 14
39123- 46 46 46 86 86 86 2 2 6 54 54 54
39124-218 218 218 195 195 195 226 226 226 246 246 246
39125- 58 58 58 2 2 6 2 2 6 30 30 30
39126-210 210 210 253 253 253 174 174 174 123 123 123
39127-221 221 221 234 234 234 74 74 74 2 2 6
39128- 2 2 6 2 2 6 2 2 6 2 2 6
39129- 70 70 70 58 58 58 22 22 22 6 6 6
39130- 0 0 0 0 0 0 0 0 0 0 0 0
39131- 0 0 0 0 0 0 0 0 0 0 0 0
39132- 0 0 0 0 0 0 0 0 0 0 0 0
39133- 0 0 0 0 0 0 0 0 0 0 0 0
39134- 0 0 0 0 0 0 0 0 0 0 0 0
39135- 0 0 0 0 0 0 0 0 0 0 0 0
39136- 0 0 0 0 0 0 0 0 0 0 0 0
39137- 0 0 0 0 0 0 0 0 0 0 0 0
39138- 0 0 0 0 0 0 0 0 0 0 0 0
39139- 0 0 0 0 0 0 0 0 0 0 0 0
39140- 0 0 0 0 0 0 0 0 0 0 0 0
39141- 0 0 0 0 0 0 0 0 0 0 0 0
39142- 0 0 0 0 0 0 0 0 0 14 14 14
39143- 46 46 46 82 82 82 2 2 6 106 106 106
39144-170 170 170 26 26 26 86 86 86 226 226 226
39145-123 123 123 10 10 10 14 14 14 46 46 46
39146-231 231 231 190 190 190 6 6 6 70 70 70
39147- 90 90 90 238 238 238 158 158 158 2 2 6
39148- 2 2 6 2 2 6 2 2 6 2 2 6
39149- 70 70 70 58 58 58 22 22 22 6 6 6
39150- 0 0 0 0 0 0 0 0 0 0 0 0
39151- 0 0 0 0 0 0 0 0 0 0 0 0
39152- 0 0 0 0 0 0 0 0 0 0 0 0
39153- 0 0 0 0 0 0 0 0 0 0 0 0
39154- 0 0 0 0 0 0 0 0 0 0 0 0
39155- 0 0 0 0 0 0 0 0 0 0 0 0
39156- 0 0 0 0 0 0 0 0 1 0 0 0
39157- 0 0 1 0 0 1 0 0 1 0 0 0
39158- 0 0 0 0 0 0 0 0 0 0 0 0
39159- 0 0 0 0 0 0 0 0 0 0 0 0
39160- 0 0 0 0 0 0 0 0 0 0 0 0
39161- 0 0 0 0 0 0 0 0 0 0 0 0
39162- 0 0 0 0 0 0 0 0 0 14 14 14
39163- 42 42 42 86 86 86 6 6 6 116 116 116
39164-106 106 106 6 6 6 70 70 70 149 149 149
39165-128 128 128 18 18 18 38 38 38 54 54 54
39166-221 221 221 106 106 106 2 2 6 14 14 14
39167- 46 46 46 190 190 190 198 198 198 2 2 6
39168- 2 2 6 2 2 6 2 2 6 2 2 6
39169- 74 74 74 62 62 62 22 22 22 6 6 6
39170- 0 0 0 0 0 0 0 0 0 0 0 0
39171- 0 0 0 0 0 0 0 0 0 0 0 0
39172- 0 0 0 0 0 0 0 0 0 0 0 0
39173- 0 0 0 0 0 0 0 0 0 0 0 0
39174- 0 0 0 0 0 0 0 0 0 0 0 0
39175- 0 0 0 0 0 0 0 0 0 0 0 0
39176- 0 0 0 0 0 0 0 0 1 0 0 0
39177- 0 0 1 0 0 0 0 0 1 0 0 0
39178- 0 0 0 0 0 0 0 0 0 0 0 0
39179- 0 0 0 0 0 0 0 0 0 0 0 0
39180- 0 0 0 0 0 0 0 0 0 0 0 0
39181- 0 0 0 0 0 0 0 0 0 0 0 0
39182- 0 0 0 0 0 0 0 0 0 14 14 14
39183- 42 42 42 94 94 94 14 14 14 101 101 101
39184-128 128 128 2 2 6 18 18 18 116 116 116
39185-118 98 46 121 92 8 121 92 8 98 78 10
39186-162 162 162 106 106 106 2 2 6 2 2 6
39187- 2 2 6 195 195 195 195 195 195 6 6 6
39188- 2 2 6 2 2 6 2 2 6 2 2 6
39189- 74 74 74 62 62 62 22 22 22 6 6 6
39190- 0 0 0 0 0 0 0 0 0 0 0 0
39191- 0 0 0 0 0 0 0 0 0 0 0 0
39192- 0 0 0 0 0 0 0 0 0 0 0 0
39193- 0 0 0 0 0 0 0 0 0 0 0 0
39194- 0 0 0 0 0 0 0 0 0 0 0 0
39195- 0 0 0 0 0 0 0 0 0 0 0 0
39196- 0 0 0 0 0 0 0 0 1 0 0 1
39197- 0 0 1 0 0 0 0 0 1 0 0 0
39198- 0 0 0 0 0 0 0 0 0 0 0 0
39199- 0 0 0 0 0 0 0 0 0 0 0 0
39200- 0 0 0 0 0 0 0 0 0 0 0 0
39201- 0 0 0 0 0 0 0 0 0 0 0 0
39202- 0 0 0 0 0 0 0 0 0 10 10 10
39203- 38 38 38 90 90 90 14 14 14 58 58 58
39204-210 210 210 26 26 26 54 38 6 154 114 10
39205-226 170 11 236 186 11 225 175 15 184 144 12
39206-215 174 15 175 146 61 37 26 9 2 2 6
39207- 70 70 70 246 246 246 138 138 138 2 2 6
39208- 2 2 6 2 2 6 2 2 6 2 2 6
39209- 70 70 70 66 66 66 26 26 26 6 6 6
39210- 0 0 0 0 0 0 0 0 0 0 0 0
39211- 0 0 0 0 0 0 0 0 0 0 0 0
39212- 0 0 0 0 0 0 0 0 0 0 0 0
39213- 0 0 0 0 0 0 0 0 0 0 0 0
39214- 0 0 0 0 0 0 0 0 0 0 0 0
39215- 0 0 0 0 0 0 0 0 0 0 0 0
39216- 0 0 0 0 0 0 0 0 0 0 0 0
39217- 0 0 0 0 0 0 0 0 0 0 0 0
39218- 0 0 0 0 0 0 0 0 0 0 0 0
39219- 0 0 0 0 0 0 0 0 0 0 0 0
39220- 0 0 0 0 0 0 0 0 0 0 0 0
39221- 0 0 0 0 0 0 0 0 0 0 0 0
39222- 0 0 0 0 0 0 0 0 0 10 10 10
39223- 38 38 38 86 86 86 14 14 14 10 10 10
39224-195 195 195 188 164 115 192 133 9 225 175 15
39225-239 182 13 234 190 10 232 195 16 232 200 30
39226-245 207 45 241 208 19 232 195 16 184 144 12
39227-218 194 134 211 206 186 42 42 42 2 2 6
39228- 2 2 6 2 2 6 2 2 6 2 2 6
39229- 50 50 50 74 74 74 30 30 30 6 6 6
39230- 0 0 0 0 0 0 0 0 0 0 0 0
39231- 0 0 0 0 0 0 0 0 0 0 0 0
39232- 0 0 0 0 0 0 0 0 0 0 0 0
39233- 0 0 0 0 0 0 0 0 0 0 0 0
39234- 0 0 0 0 0 0 0 0 0 0 0 0
39235- 0 0 0 0 0 0 0 0 0 0 0 0
39236- 0 0 0 0 0 0 0 0 0 0 0 0
39237- 0 0 0 0 0 0 0 0 0 0 0 0
39238- 0 0 0 0 0 0 0 0 0 0 0 0
39239- 0 0 0 0 0 0 0 0 0 0 0 0
39240- 0 0 0 0 0 0 0 0 0 0 0 0
39241- 0 0 0 0 0 0 0 0 0 0 0 0
39242- 0 0 0 0 0 0 0 0 0 10 10 10
39243- 34 34 34 86 86 86 14 14 14 2 2 6
39244-121 87 25 192 133 9 219 162 10 239 182 13
39245-236 186 11 232 195 16 241 208 19 244 214 54
39246-246 218 60 246 218 38 246 215 20 241 208 19
39247-241 208 19 226 184 13 121 87 25 2 2 6
39248- 2 2 6 2 2 6 2 2 6 2 2 6
39249- 50 50 50 82 82 82 34 34 34 10 10 10
39250- 0 0 0 0 0 0 0 0 0 0 0 0
39251- 0 0 0 0 0 0 0 0 0 0 0 0
39252- 0 0 0 0 0 0 0 0 0 0 0 0
39253- 0 0 0 0 0 0 0 0 0 0 0 0
39254- 0 0 0 0 0 0 0 0 0 0 0 0
39255- 0 0 0 0 0 0 0 0 0 0 0 0
39256- 0 0 0 0 0 0 0 0 0 0 0 0
39257- 0 0 0 0 0 0 0 0 0 0 0 0
39258- 0 0 0 0 0 0 0 0 0 0 0 0
39259- 0 0 0 0 0 0 0 0 0 0 0 0
39260- 0 0 0 0 0 0 0 0 0 0 0 0
39261- 0 0 0 0 0 0 0 0 0 0 0 0
39262- 0 0 0 0 0 0 0 0 0 10 10 10
39263- 34 34 34 82 82 82 30 30 30 61 42 6
39264-180 123 7 206 145 10 230 174 11 239 182 13
39265-234 190 10 238 202 15 241 208 19 246 218 74
39266-246 218 38 246 215 20 246 215 20 246 215 20
39267-226 184 13 215 174 15 184 144 12 6 6 6
39268- 2 2 6 2 2 6 2 2 6 2 2 6
39269- 26 26 26 94 94 94 42 42 42 14 14 14
39270- 0 0 0 0 0 0 0 0 0 0 0 0
39271- 0 0 0 0 0 0 0 0 0 0 0 0
39272- 0 0 0 0 0 0 0 0 0 0 0 0
39273- 0 0 0 0 0 0 0 0 0 0 0 0
39274- 0 0 0 0 0 0 0 0 0 0 0 0
39275- 0 0 0 0 0 0 0 0 0 0 0 0
39276- 0 0 0 0 0 0 0 0 0 0 0 0
39277- 0 0 0 0 0 0 0 0 0 0 0 0
39278- 0 0 0 0 0 0 0 0 0 0 0 0
39279- 0 0 0 0 0 0 0 0 0 0 0 0
39280- 0 0 0 0 0 0 0 0 0 0 0 0
39281- 0 0 0 0 0 0 0 0 0 0 0 0
39282- 0 0 0 0 0 0 0 0 0 10 10 10
39283- 30 30 30 78 78 78 50 50 50 104 69 6
39284-192 133 9 216 158 10 236 178 12 236 186 11
39285-232 195 16 241 208 19 244 214 54 245 215 43
39286-246 215 20 246 215 20 241 208 19 198 155 10
39287-200 144 11 216 158 10 156 118 10 2 2 6
39288- 2 2 6 2 2 6 2 2 6 2 2 6
39289- 6 6 6 90 90 90 54 54 54 18 18 18
39290- 6 6 6 0 0 0 0 0 0 0 0 0
39291- 0 0 0 0 0 0 0 0 0 0 0 0
39292- 0 0 0 0 0 0 0 0 0 0 0 0
39293- 0 0 0 0 0 0 0 0 0 0 0 0
39294- 0 0 0 0 0 0 0 0 0 0 0 0
39295- 0 0 0 0 0 0 0 0 0 0 0 0
39296- 0 0 0 0 0 0 0 0 0 0 0 0
39297- 0 0 0 0 0 0 0 0 0 0 0 0
39298- 0 0 0 0 0 0 0 0 0 0 0 0
39299- 0 0 0 0 0 0 0 0 0 0 0 0
39300- 0 0 0 0 0 0 0 0 0 0 0 0
39301- 0 0 0 0 0 0 0 0 0 0 0 0
39302- 0 0 0 0 0 0 0 0 0 10 10 10
39303- 30 30 30 78 78 78 46 46 46 22 22 22
39304-137 92 6 210 162 10 239 182 13 238 190 10
39305-238 202 15 241 208 19 246 215 20 246 215 20
39306-241 208 19 203 166 17 185 133 11 210 150 10
39307-216 158 10 210 150 10 102 78 10 2 2 6
39308- 6 6 6 54 54 54 14 14 14 2 2 6
39309- 2 2 6 62 62 62 74 74 74 30 30 30
39310- 10 10 10 0 0 0 0 0 0 0 0 0
39311- 0 0 0 0 0 0 0 0 0 0 0 0
39312- 0 0 0 0 0 0 0 0 0 0 0 0
39313- 0 0 0 0 0 0 0 0 0 0 0 0
39314- 0 0 0 0 0 0 0 0 0 0 0 0
39315- 0 0 0 0 0 0 0 0 0 0 0 0
39316- 0 0 0 0 0 0 0 0 0 0 0 0
39317- 0 0 0 0 0 0 0 0 0 0 0 0
39318- 0 0 0 0 0 0 0 0 0 0 0 0
39319- 0 0 0 0 0 0 0 0 0 0 0 0
39320- 0 0 0 0 0 0 0 0 0 0 0 0
39321- 0 0 0 0 0 0 0 0 0 0 0 0
39322- 0 0 0 0 0 0 0 0 0 10 10 10
39323- 34 34 34 78 78 78 50 50 50 6 6 6
39324- 94 70 30 139 102 15 190 146 13 226 184 13
39325-232 200 30 232 195 16 215 174 15 190 146 13
39326-168 122 10 192 133 9 210 150 10 213 154 11
39327-202 150 34 182 157 106 101 98 89 2 2 6
39328- 2 2 6 78 78 78 116 116 116 58 58 58
39329- 2 2 6 22 22 22 90 90 90 46 46 46
39330- 18 18 18 6 6 6 0 0 0 0 0 0
39331- 0 0 0 0 0 0 0 0 0 0 0 0
39332- 0 0 0 0 0 0 0 0 0 0 0 0
39333- 0 0 0 0 0 0 0 0 0 0 0 0
39334- 0 0 0 0 0 0 0 0 0 0 0 0
39335- 0 0 0 0 0 0 0 0 0 0 0 0
39336- 0 0 0 0 0 0 0 0 0 0 0 0
39337- 0 0 0 0 0 0 0 0 0 0 0 0
39338- 0 0 0 0 0 0 0 0 0 0 0 0
39339- 0 0 0 0 0 0 0 0 0 0 0 0
39340- 0 0 0 0 0 0 0 0 0 0 0 0
39341- 0 0 0 0 0 0 0 0 0 0 0 0
39342- 0 0 0 0 0 0 0 0 0 10 10 10
39343- 38 38 38 86 86 86 50 50 50 6 6 6
39344-128 128 128 174 154 114 156 107 11 168 122 10
39345-198 155 10 184 144 12 197 138 11 200 144 11
39346-206 145 10 206 145 10 197 138 11 188 164 115
39347-195 195 195 198 198 198 174 174 174 14 14 14
39348- 2 2 6 22 22 22 116 116 116 116 116 116
39349- 22 22 22 2 2 6 74 74 74 70 70 70
39350- 30 30 30 10 10 10 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 0 0 0 0 0 0 0 0 0
39354- 0 0 0 0 0 0 0 0 0 0 0 0
39355- 0 0 0 0 0 0 0 0 0 0 0 0
39356- 0 0 0 0 0 0 0 0 0 0 0 0
39357- 0 0 0 0 0 0 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
39362- 0 0 0 0 0 0 6 6 6 18 18 18
39363- 50 50 50 101 101 101 26 26 26 10 10 10
39364-138 138 138 190 190 190 174 154 114 156 107 11
39365-197 138 11 200 144 11 197 138 11 192 133 9
39366-180 123 7 190 142 34 190 178 144 187 187 187
39367-202 202 202 221 221 221 214 214 214 66 66 66
39368- 2 2 6 2 2 6 50 50 50 62 62 62
39369- 6 6 6 2 2 6 10 10 10 90 90 90
39370- 50 50 50 18 18 18 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
39375- 0 0 0 0 0 0 0 0 0 0 0 0
39376- 0 0 0 0 0 0 0 0 0 0 0 0
39377- 0 0 0 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 0 0 0 0 0 0 0 0 0
39382- 0 0 0 0 0 0 10 10 10 34 34 34
39383- 74 74 74 74 74 74 2 2 6 6 6 6
39384-144 144 144 198 198 198 190 190 190 178 166 146
39385-154 121 60 156 107 11 156 107 11 168 124 44
39386-174 154 114 187 187 187 190 190 190 210 210 210
39387-246 246 246 253 253 253 253 253 253 182 182 182
39388- 6 6 6 2 2 6 2 2 6 2 2 6
39389- 2 2 6 2 2 6 2 2 6 62 62 62
39390- 74 74 74 34 34 34 14 14 14 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 0 0 0
39395- 0 0 0 0 0 0 0 0 0 0 0 0
39396- 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0
39402- 0 0 0 10 10 10 22 22 22 54 54 54
39403- 94 94 94 18 18 18 2 2 6 46 46 46
39404-234 234 234 221 221 221 190 190 190 190 190 190
39405-190 190 190 187 187 187 187 187 187 190 190 190
39406-190 190 190 195 195 195 214 214 214 242 242 242
39407-253 253 253 253 253 253 253 253 253 253 253 253
39408- 82 82 82 2 2 6 2 2 6 2 2 6
39409- 2 2 6 2 2 6 2 2 6 14 14 14
39410- 86 86 86 54 54 54 22 22 22 6 6 6
39411- 0 0 0 0 0 0 0 0 0 0 0 0
39412- 0 0 0 0 0 0 0 0 0 0 0 0
39413- 0 0 0 0 0 0 0 0 0 0 0 0
39414- 0 0 0 0 0 0 0 0 0 0 0 0
39415- 0 0 0 0 0 0 0 0 0 0 0 0
39416- 0 0 0 0 0 0 0 0 0 0 0 0
39417- 0 0 0 0 0 0 0 0 0 0 0 0
39418- 0 0 0 0 0 0 0 0 0 0 0 0
39419- 0 0 0 0 0 0 0 0 0 0 0 0
39420- 0 0 0 0 0 0 0 0 0 0 0 0
39421- 0 0 0 0 0 0 0 0 0 0 0 0
39422- 6 6 6 18 18 18 46 46 46 90 90 90
39423- 46 46 46 18 18 18 6 6 6 182 182 182
39424-253 253 253 246 246 246 206 206 206 190 190 190
39425-190 190 190 190 190 190 190 190 190 190 190 190
39426-206 206 206 231 231 231 250 250 250 253 253 253
39427-253 253 253 253 253 253 253 253 253 253 253 253
39428-202 202 202 14 14 14 2 2 6 2 2 6
39429- 2 2 6 2 2 6 2 2 6 2 2 6
39430- 42 42 42 86 86 86 42 42 42 18 18 18
39431- 6 6 6 0 0 0 0 0 0 0 0 0
39432- 0 0 0 0 0 0 0 0 0 0 0 0
39433- 0 0 0 0 0 0 0 0 0 0 0 0
39434- 0 0 0 0 0 0 0 0 0 0 0 0
39435- 0 0 0 0 0 0 0 0 0 0 0 0
39436- 0 0 0 0 0 0 0 0 0 0 0 0
39437- 0 0 0 0 0 0 0 0 0 0 0 0
39438- 0 0 0 0 0 0 0 0 0 0 0 0
39439- 0 0 0 0 0 0 0 0 0 0 0 0
39440- 0 0 0 0 0 0 0 0 0 0 0 0
39441- 0 0 0 0 0 0 0 0 0 6 6 6
39442- 14 14 14 38 38 38 74 74 74 66 66 66
39443- 2 2 6 6 6 6 90 90 90 250 250 250
39444-253 253 253 253 253 253 238 238 238 198 198 198
39445-190 190 190 190 190 190 195 195 195 221 221 221
39446-246 246 246 253 253 253 253 253 253 253 253 253
39447-253 253 253 253 253 253 253 253 253 253 253 253
39448-253 253 253 82 82 82 2 2 6 2 2 6
39449- 2 2 6 2 2 6 2 2 6 2 2 6
39450- 2 2 6 78 78 78 70 70 70 34 34 34
39451- 14 14 14 6 6 6 0 0 0 0 0 0
39452- 0 0 0 0 0 0 0 0 0 0 0 0
39453- 0 0 0 0 0 0 0 0 0 0 0 0
39454- 0 0 0 0 0 0 0 0 0 0 0 0
39455- 0 0 0 0 0 0 0 0 0 0 0 0
39456- 0 0 0 0 0 0 0 0 0 0 0 0
39457- 0 0 0 0 0 0 0 0 0 0 0 0
39458- 0 0 0 0 0 0 0 0 0 0 0 0
39459- 0 0 0 0 0 0 0 0 0 0 0 0
39460- 0 0 0 0 0 0 0 0 0 0 0 0
39461- 0 0 0 0 0 0 0 0 0 14 14 14
39462- 34 34 34 66 66 66 78 78 78 6 6 6
39463- 2 2 6 18 18 18 218 218 218 253 253 253
39464-253 253 253 253 253 253 253 253 253 246 246 246
39465-226 226 226 231 231 231 246 246 246 253 253 253
39466-253 253 253 253 253 253 253 253 253 253 253 253
39467-253 253 253 253 253 253 253 253 253 253 253 253
39468-253 253 253 178 178 178 2 2 6 2 2 6
39469- 2 2 6 2 2 6 2 2 6 2 2 6
39470- 2 2 6 18 18 18 90 90 90 62 62 62
39471- 30 30 30 10 10 10 0 0 0 0 0 0
39472- 0 0 0 0 0 0 0 0 0 0 0 0
39473- 0 0 0 0 0 0 0 0 0 0 0 0
39474- 0 0 0 0 0 0 0 0 0 0 0 0
39475- 0 0 0 0 0 0 0 0 0 0 0 0
39476- 0 0 0 0 0 0 0 0 0 0 0 0
39477- 0 0 0 0 0 0 0 0 0 0 0 0
39478- 0 0 0 0 0 0 0 0 0 0 0 0
39479- 0 0 0 0 0 0 0 0 0 0 0 0
39480- 0 0 0 0 0 0 0 0 0 0 0 0
39481- 0 0 0 0 0 0 10 10 10 26 26 26
39482- 58 58 58 90 90 90 18 18 18 2 2 6
39483- 2 2 6 110 110 110 253 253 253 253 253 253
39484-253 253 253 253 253 253 253 253 253 253 253 253
39485-250 250 250 253 253 253 253 253 253 253 253 253
39486-253 253 253 253 253 253 253 253 253 253 253 253
39487-253 253 253 253 253 253 253 253 253 253 253 253
39488-253 253 253 231 231 231 18 18 18 2 2 6
39489- 2 2 6 2 2 6 2 2 6 2 2 6
39490- 2 2 6 2 2 6 18 18 18 94 94 94
39491- 54 54 54 26 26 26 10 10 10 0 0 0
39492- 0 0 0 0 0 0 0 0 0 0 0 0
39493- 0 0 0 0 0 0 0 0 0 0 0 0
39494- 0 0 0 0 0 0 0 0 0 0 0 0
39495- 0 0 0 0 0 0 0 0 0 0 0 0
39496- 0 0 0 0 0 0 0 0 0 0 0 0
39497- 0 0 0 0 0 0 0 0 0 0 0 0
39498- 0 0 0 0 0 0 0 0 0 0 0 0
39499- 0 0 0 0 0 0 0 0 0 0 0 0
39500- 0 0 0 0 0 0 0 0 0 0 0 0
39501- 0 0 0 6 6 6 22 22 22 50 50 50
39502- 90 90 90 26 26 26 2 2 6 2 2 6
39503- 14 14 14 195 195 195 250 250 250 253 253 253
39504-253 253 253 253 253 253 253 253 253 253 253 253
39505-253 253 253 253 253 253 253 253 253 253 253 253
39506-253 253 253 253 253 253 253 253 253 253 253 253
39507-253 253 253 253 253 253 253 253 253 253 253 253
39508-250 250 250 242 242 242 54 54 54 2 2 6
39509- 2 2 6 2 2 6 2 2 6 2 2 6
39510- 2 2 6 2 2 6 2 2 6 38 38 38
39511- 86 86 86 50 50 50 22 22 22 6 6 6
39512- 0 0 0 0 0 0 0 0 0 0 0 0
39513- 0 0 0 0 0 0 0 0 0 0 0 0
39514- 0 0 0 0 0 0 0 0 0 0 0 0
39515- 0 0 0 0 0 0 0 0 0 0 0 0
39516- 0 0 0 0 0 0 0 0 0 0 0 0
39517- 0 0 0 0 0 0 0 0 0 0 0 0
39518- 0 0 0 0 0 0 0 0 0 0 0 0
39519- 0 0 0 0 0 0 0 0 0 0 0 0
39520- 0 0 0 0 0 0 0 0 0 0 0 0
39521- 6 6 6 14 14 14 38 38 38 82 82 82
39522- 34 34 34 2 2 6 2 2 6 2 2 6
39523- 42 42 42 195 195 195 246 246 246 253 253 253
39524-253 253 253 253 253 253 253 253 253 250 250 250
39525-242 242 242 242 242 242 250 250 250 253 253 253
39526-253 253 253 253 253 253 253 253 253 253 253 253
39527-253 253 253 250 250 250 246 246 246 238 238 238
39528-226 226 226 231 231 231 101 101 101 6 6 6
39529- 2 2 6 2 2 6 2 2 6 2 2 6
39530- 2 2 6 2 2 6 2 2 6 2 2 6
39531- 38 38 38 82 82 82 42 42 42 14 14 14
39532- 6 6 6 0 0 0 0 0 0 0 0 0
39533- 0 0 0 0 0 0 0 0 0 0 0 0
39534- 0 0 0 0 0 0 0 0 0 0 0 0
39535- 0 0 0 0 0 0 0 0 0 0 0 0
39536- 0 0 0 0 0 0 0 0 0 0 0 0
39537- 0 0 0 0 0 0 0 0 0 0 0 0
39538- 0 0 0 0 0 0 0 0 0 0 0 0
39539- 0 0 0 0 0 0 0 0 0 0 0 0
39540- 0 0 0 0 0 0 0 0 0 0 0 0
39541- 10 10 10 26 26 26 62 62 62 66 66 66
39542- 2 2 6 2 2 6 2 2 6 6 6 6
39543- 70 70 70 170 170 170 206 206 206 234 234 234
39544-246 246 246 250 250 250 250 250 250 238 238 238
39545-226 226 226 231 231 231 238 238 238 250 250 250
39546-250 250 250 250 250 250 246 246 246 231 231 231
39547-214 214 214 206 206 206 202 202 202 202 202 202
39548-198 198 198 202 202 202 182 182 182 18 18 18
39549- 2 2 6 2 2 6 2 2 6 2 2 6
39550- 2 2 6 2 2 6 2 2 6 2 2 6
39551- 2 2 6 62 62 62 66 66 66 30 30 30
39552- 10 10 10 0 0 0 0 0 0 0 0 0
39553- 0 0 0 0 0 0 0 0 0 0 0 0
39554- 0 0 0 0 0 0 0 0 0 0 0 0
39555- 0 0 0 0 0 0 0 0 0 0 0 0
39556- 0 0 0 0 0 0 0 0 0 0 0 0
39557- 0 0 0 0 0 0 0 0 0 0 0 0
39558- 0 0 0 0 0 0 0 0 0 0 0 0
39559- 0 0 0 0 0 0 0 0 0 0 0 0
39560- 0 0 0 0 0 0 0 0 0 0 0 0
39561- 14 14 14 42 42 42 82 82 82 18 18 18
39562- 2 2 6 2 2 6 2 2 6 10 10 10
39563- 94 94 94 182 182 182 218 218 218 242 242 242
39564-250 250 250 253 253 253 253 253 253 250 250 250
39565-234 234 234 253 253 253 253 253 253 253 253 253
39566-253 253 253 253 253 253 253 253 253 246 246 246
39567-238 238 238 226 226 226 210 210 210 202 202 202
39568-195 195 195 195 195 195 210 210 210 158 158 158
39569- 6 6 6 14 14 14 50 50 50 14 14 14
39570- 2 2 6 2 2 6 2 2 6 2 2 6
39571- 2 2 6 6 6 6 86 86 86 46 46 46
39572- 18 18 18 6 6 6 0 0 0 0 0 0
39573- 0 0 0 0 0 0 0 0 0 0 0 0
39574- 0 0 0 0 0 0 0 0 0 0 0 0
39575- 0 0 0 0 0 0 0 0 0 0 0 0
39576- 0 0 0 0 0 0 0 0 0 0 0 0
39577- 0 0 0 0 0 0 0 0 0 0 0 0
39578- 0 0 0 0 0 0 0 0 0 0 0 0
39579- 0 0 0 0 0 0 0 0 0 0 0 0
39580- 0 0 0 0 0 0 0 0 0 6 6 6
39581- 22 22 22 54 54 54 70 70 70 2 2 6
39582- 2 2 6 10 10 10 2 2 6 22 22 22
39583-166 166 166 231 231 231 250 250 250 253 253 253
39584-253 253 253 253 253 253 253 253 253 250 250 250
39585-242 242 242 253 253 253 253 253 253 253 253 253
39586-253 253 253 253 253 253 253 253 253 253 253 253
39587-253 253 253 253 253 253 253 253 253 246 246 246
39588-231 231 231 206 206 206 198 198 198 226 226 226
39589- 94 94 94 2 2 6 6 6 6 38 38 38
39590- 30 30 30 2 2 6 2 2 6 2 2 6
39591- 2 2 6 2 2 6 62 62 62 66 66 66
39592- 26 26 26 10 10 10 0 0 0 0 0 0
39593- 0 0 0 0 0 0 0 0 0 0 0 0
39594- 0 0 0 0 0 0 0 0 0 0 0 0
39595- 0 0 0 0 0 0 0 0 0 0 0 0
39596- 0 0 0 0 0 0 0 0 0 0 0 0
39597- 0 0 0 0 0 0 0 0 0 0 0 0
39598- 0 0 0 0 0 0 0 0 0 0 0 0
39599- 0 0 0 0 0 0 0 0 0 0 0 0
39600- 0 0 0 0 0 0 0 0 0 10 10 10
39601- 30 30 30 74 74 74 50 50 50 2 2 6
39602- 26 26 26 26 26 26 2 2 6 106 106 106
39603-238 238 238 253 253 253 253 253 253 253 253 253
39604-253 253 253 253 253 253 253 253 253 253 253 253
39605-253 253 253 253 253 253 253 253 253 253 253 253
39606-253 253 253 253 253 253 253 253 253 253 253 253
39607-253 253 253 253 253 253 253 253 253 253 253 253
39608-253 253 253 246 246 246 218 218 218 202 202 202
39609-210 210 210 14 14 14 2 2 6 2 2 6
39610- 30 30 30 22 22 22 2 2 6 2 2 6
39611- 2 2 6 2 2 6 18 18 18 86 86 86
39612- 42 42 42 14 14 14 0 0 0 0 0 0
39613- 0 0 0 0 0 0 0 0 0 0 0 0
39614- 0 0 0 0 0 0 0 0 0 0 0 0
39615- 0 0 0 0 0 0 0 0 0 0 0 0
39616- 0 0 0 0 0 0 0 0 0 0 0 0
39617- 0 0 0 0 0 0 0 0 0 0 0 0
39618- 0 0 0 0 0 0 0 0 0 0 0 0
39619- 0 0 0 0 0 0 0 0 0 0 0 0
39620- 0 0 0 0 0 0 0 0 0 14 14 14
39621- 42 42 42 90 90 90 22 22 22 2 2 6
39622- 42 42 42 2 2 6 18 18 18 218 218 218
39623-253 253 253 253 253 253 253 253 253 253 253 253
39624-253 253 253 253 253 253 253 253 253 253 253 253
39625-253 253 253 253 253 253 253 253 253 253 253 253
39626-253 253 253 253 253 253 253 253 253 253 253 253
39627-253 253 253 253 253 253 253 253 253 253 253 253
39628-253 253 253 253 253 253 250 250 250 221 221 221
39629-218 218 218 101 101 101 2 2 6 14 14 14
39630- 18 18 18 38 38 38 10 10 10 2 2 6
39631- 2 2 6 2 2 6 2 2 6 78 78 78
39632- 58 58 58 22 22 22 6 6 6 0 0 0
39633- 0 0 0 0 0 0 0 0 0 0 0 0
39634- 0 0 0 0 0 0 0 0 0 0 0 0
39635- 0 0 0 0 0 0 0 0 0 0 0 0
39636- 0 0 0 0 0 0 0 0 0 0 0 0
39637- 0 0 0 0 0 0 0 0 0 0 0 0
39638- 0 0 0 0 0 0 0 0 0 0 0 0
39639- 0 0 0 0 0 0 0 0 0 0 0 0
39640- 0 0 0 0 0 0 6 6 6 18 18 18
39641- 54 54 54 82 82 82 2 2 6 26 26 26
39642- 22 22 22 2 2 6 123 123 123 253 253 253
39643-253 253 253 253 253 253 253 253 253 253 253 253
39644-253 253 253 253 253 253 253 253 253 253 253 253
39645-253 253 253 253 253 253 253 253 253 253 253 253
39646-253 253 253 253 253 253 253 253 253 253 253 253
39647-253 253 253 253 253 253 253 253 253 253 253 253
39648-253 253 253 253 253 253 253 253 253 250 250 250
39649-238 238 238 198 198 198 6 6 6 38 38 38
39650- 58 58 58 26 26 26 38 38 38 2 2 6
39651- 2 2 6 2 2 6 2 2 6 46 46 46
39652- 78 78 78 30 30 30 10 10 10 0 0 0
39653- 0 0 0 0 0 0 0 0 0 0 0 0
39654- 0 0 0 0 0 0 0 0 0 0 0 0
39655- 0 0 0 0 0 0 0 0 0 0 0 0
39656- 0 0 0 0 0 0 0 0 0 0 0 0
39657- 0 0 0 0 0 0 0 0 0 0 0 0
39658- 0 0 0 0 0 0 0 0 0 0 0 0
39659- 0 0 0 0 0 0 0 0 0 0 0 0
39660- 0 0 0 0 0 0 10 10 10 30 30 30
39661- 74 74 74 58 58 58 2 2 6 42 42 42
39662- 2 2 6 22 22 22 231 231 231 253 253 253
39663-253 253 253 253 253 253 253 253 253 253 253 253
39664-253 253 253 253 253 253 253 253 253 250 250 250
39665-253 253 253 253 253 253 253 253 253 253 253 253
39666-253 253 253 253 253 253 253 253 253 253 253 253
39667-253 253 253 253 253 253 253 253 253 253 253 253
39668-253 253 253 253 253 253 253 253 253 253 253 253
39669-253 253 253 246 246 246 46 46 46 38 38 38
39670- 42 42 42 14 14 14 38 38 38 14 14 14
39671- 2 2 6 2 2 6 2 2 6 6 6 6
39672- 86 86 86 46 46 46 14 14 14 0 0 0
39673- 0 0 0 0 0 0 0 0 0 0 0 0
39674- 0 0 0 0 0 0 0 0 0 0 0 0
39675- 0 0 0 0 0 0 0 0 0 0 0 0
39676- 0 0 0 0 0 0 0 0 0 0 0 0
39677- 0 0 0 0 0 0 0 0 0 0 0 0
39678- 0 0 0 0 0 0 0 0 0 0 0 0
39679- 0 0 0 0 0 0 0 0 0 0 0 0
39680- 0 0 0 6 6 6 14 14 14 42 42 42
39681- 90 90 90 18 18 18 18 18 18 26 26 26
39682- 2 2 6 116 116 116 253 253 253 253 253 253
39683-253 253 253 253 253 253 253 253 253 253 253 253
39684-253 253 253 253 253 253 250 250 250 238 238 238
39685-253 253 253 253 253 253 253 253 253 253 253 253
39686-253 253 253 253 253 253 253 253 253 253 253 253
39687-253 253 253 253 253 253 253 253 253 253 253 253
39688-253 253 253 253 253 253 253 253 253 253 253 253
39689-253 253 253 253 253 253 94 94 94 6 6 6
39690- 2 2 6 2 2 6 10 10 10 34 34 34
39691- 2 2 6 2 2 6 2 2 6 2 2 6
39692- 74 74 74 58 58 58 22 22 22 6 6 6
39693- 0 0 0 0 0 0 0 0 0 0 0 0
39694- 0 0 0 0 0 0 0 0 0 0 0 0
39695- 0 0 0 0 0 0 0 0 0 0 0 0
39696- 0 0 0 0 0 0 0 0 0 0 0 0
39697- 0 0 0 0 0 0 0 0 0 0 0 0
39698- 0 0 0 0 0 0 0 0 0 0 0 0
39699- 0 0 0 0 0 0 0 0 0 0 0 0
39700- 0 0 0 10 10 10 26 26 26 66 66 66
39701- 82 82 82 2 2 6 38 38 38 6 6 6
39702- 14 14 14 210 210 210 253 253 253 253 253 253
39703-253 253 253 253 253 253 253 253 253 253 253 253
39704-253 253 253 253 253 253 246 246 246 242 242 242
39705-253 253 253 253 253 253 253 253 253 253 253 253
39706-253 253 253 253 253 253 253 253 253 253 253 253
39707-253 253 253 253 253 253 253 253 253 253 253 253
39708-253 253 253 253 253 253 253 253 253 253 253 253
39709-253 253 253 253 253 253 144 144 144 2 2 6
39710- 2 2 6 2 2 6 2 2 6 46 46 46
39711- 2 2 6 2 2 6 2 2 6 2 2 6
39712- 42 42 42 74 74 74 30 30 30 10 10 10
39713- 0 0 0 0 0 0 0 0 0 0 0 0
39714- 0 0 0 0 0 0 0 0 0 0 0 0
39715- 0 0 0 0 0 0 0 0 0 0 0 0
39716- 0 0 0 0 0 0 0 0 0 0 0 0
39717- 0 0 0 0 0 0 0 0 0 0 0 0
39718- 0 0 0 0 0 0 0 0 0 0 0 0
39719- 0 0 0 0 0 0 0 0 0 0 0 0
39720- 6 6 6 14 14 14 42 42 42 90 90 90
39721- 26 26 26 6 6 6 42 42 42 2 2 6
39722- 74 74 74 250 250 250 253 253 253 253 253 253
39723-253 253 253 253 253 253 253 253 253 253 253 253
39724-253 253 253 253 253 253 242 242 242 242 242 242
39725-253 253 253 253 253 253 253 253 253 253 253 253
39726-253 253 253 253 253 253 253 253 253 253 253 253
39727-253 253 253 253 253 253 253 253 253 253 253 253
39728-253 253 253 253 253 253 253 253 253 253 253 253
39729-253 253 253 253 253 253 182 182 182 2 2 6
39730- 2 2 6 2 2 6 2 2 6 46 46 46
39731- 2 2 6 2 2 6 2 2 6 2 2 6
39732- 10 10 10 86 86 86 38 38 38 10 10 10
39733- 0 0 0 0 0 0 0 0 0 0 0 0
39734- 0 0 0 0 0 0 0 0 0 0 0 0
39735- 0 0 0 0 0 0 0 0 0 0 0 0
39736- 0 0 0 0 0 0 0 0 0 0 0 0
39737- 0 0 0 0 0 0 0 0 0 0 0 0
39738- 0 0 0 0 0 0 0 0 0 0 0 0
39739- 0 0 0 0 0 0 0 0 0 0 0 0
39740- 10 10 10 26 26 26 66 66 66 82 82 82
39741- 2 2 6 22 22 22 18 18 18 2 2 6
39742-149 149 149 253 253 253 253 253 253 253 253 253
39743-253 253 253 253 253 253 253 253 253 253 253 253
39744-253 253 253 253 253 253 234 234 234 242 242 242
39745-253 253 253 253 253 253 253 253 253 253 253 253
39746-253 253 253 253 253 253 253 253 253 253 253 253
39747-253 253 253 253 253 253 253 253 253 253 253 253
39748-253 253 253 253 253 253 253 253 253 253 253 253
39749-253 253 253 253 253 253 206 206 206 2 2 6
39750- 2 2 6 2 2 6 2 2 6 38 38 38
39751- 2 2 6 2 2 6 2 2 6 2 2 6
39752- 6 6 6 86 86 86 46 46 46 14 14 14
39753- 0 0 0 0 0 0 0 0 0 0 0 0
39754- 0 0 0 0 0 0 0 0 0 0 0 0
39755- 0 0 0 0 0 0 0 0 0 0 0 0
39756- 0 0 0 0 0 0 0 0 0 0 0 0
39757- 0 0 0 0 0 0 0 0 0 0 0 0
39758- 0 0 0 0 0 0 0 0 0 0 0 0
39759- 0 0 0 0 0 0 0 0 0 6 6 6
39760- 18 18 18 46 46 46 86 86 86 18 18 18
39761- 2 2 6 34 34 34 10 10 10 6 6 6
39762-210 210 210 253 253 253 253 253 253 253 253 253
39763-253 253 253 253 253 253 253 253 253 253 253 253
39764-253 253 253 253 253 253 234 234 234 242 242 242
39765-253 253 253 253 253 253 253 253 253 253 253 253
39766-253 253 253 253 253 253 253 253 253 253 253 253
39767-253 253 253 253 253 253 253 253 253 253 253 253
39768-253 253 253 253 253 253 253 253 253 253 253 253
39769-253 253 253 253 253 253 221 221 221 6 6 6
39770- 2 2 6 2 2 6 6 6 6 30 30 30
39771- 2 2 6 2 2 6 2 2 6 2 2 6
39772- 2 2 6 82 82 82 54 54 54 18 18 18
39773- 6 6 6 0 0 0 0 0 0 0 0 0
39774- 0 0 0 0 0 0 0 0 0 0 0 0
39775- 0 0 0 0 0 0 0 0 0 0 0 0
39776- 0 0 0 0 0 0 0 0 0 0 0 0
39777- 0 0 0 0 0 0 0 0 0 0 0 0
39778- 0 0 0 0 0 0 0 0 0 0 0 0
39779- 0 0 0 0 0 0 0 0 0 10 10 10
39780- 26 26 26 66 66 66 62 62 62 2 2 6
39781- 2 2 6 38 38 38 10 10 10 26 26 26
39782-238 238 238 253 253 253 253 253 253 253 253 253
39783-253 253 253 253 253 253 253 253 253 253 253 253
39784-253 253 253 253 253 253 231 231 231 238 238 238
39785-253 253 253 253 253 253 253 253 253 253 253 253
39786-253 253 253 253 253 253 253 253 253 253 253 253
39787-253 253 253 253 253 253 253 253 253 253 253 253
39788-253 253 253 253 253 253 253 253 253 253 253 253
39789-253 253 253 253 253 253 231 231 231 6 6 6
39790- 2 2 6 2 2 6 10 10 10 30 30 30
39791- 2 2 6 2 2 6 2 2 6 2 2 6
39792- 2 2 6 66 66 66 58 58 58 22 22 22
39793- 6 6 6 0 0 0 0 0 0 0 0 0
39794- 0 0 0 0 0 0 0 0 0 0 0 0
39795- 0 0 0 0 0 0 0 0 0 0 0 0
39796- 0 0 0 0 0 0 0 0 0 0 0 0
39797- 0 0 0 0 0 0 0 0 0 0 0 0
39798- 0 0 0 0 0 0 0 0 0 0 0 0
39799- 0 0 0 0 0 0 0 0 0 10 10 10
39800- 38 38 38 78 78 78 6 6 6 2 2 6
39801- 2 2 6 46 46 46 14 14 14 42 42 42
39802-246 246 246 253 253 253 253 253 253 253 253 253
39803-253 253 253 253 253 253 253 253 253 253 253 253
39804-253 253 253 253 253 253 231 231 231 242 242 242
39805-253 253 253 253 253 253 253 253 253 253 253 253
39806-253 253 253 253 253 253 253 253 253 253 253 253
39807-253 253 253 253 253 253 253 253 253 253 253 253
39808-253 253 253 253 253 253 253 253 253 253 253 253
39809-253 253 253 253 253 253 234 234 234 10 10 10
39810- 2 2 6 2 2 6 22 22 22 14 14 14
39811- 2 2 6 2 2 6 2 2 6 2 2 6
39812- 2 2 6 66 66 66 62 62 62 22 22 22
39813- 6 6 6 0 0 0 0 0 0 0 0 0
39814- 0 0 0 0 0 0 0 0 0 0 0 0
39815- 0 0 0 0 0 0 0 0 0 0 0 0
39816- 0 0 0 0 0 0 0 0 0 0 0 0
39817- 0 0 0 0 0 0 0 0 0 0 0 0
39818- 0 0 0 0 0 0 0 0 0 0 0 0
39819- 0 0 0 0 0 0 6 6 6 18 18 18
39820- 50 50 50 74 74 74 2 2 6 2 2 6
39821- 14 14 14 70 70 70 34 34 34 62 62 62
39822-250 250 250 253 253 253 253 253 253 253 253 253
39823-253 253 253 253 253 253 253 253 253 253 253 253
39824-253 253 253 253 253 253 231 231 231 246 246 246
39825-253 253 253 253 253 253 253 253 253 253 253 253
39826-253 253 253 253 253 253 253 253 253 253 253 253
39827-253 253 253 253 253 253 253 253 253 253 253 253
39828-253 253 253 253 253 253 253 253 253 253 253 253
39829-253 253 253 253 253 253 234 234 234 14 14 14
39830- 2 2 6 2 2 6 30 30 30 2 2 6
39831- 2 2 6 2 2 6 2 2 6 2 2 6
39832- 2 2 6 66 66 66 62 62 62 22 22 22
39833- 6 6 6 0 0 0 0 0 0 0 0 0
39834- 0 0 0 0 0 0 0 0 0 0 0 0
39835- 0 0 0 0 0 0 0 0 0 0 0 0
39836- 0 0 0 0 0 0 0 0 0 0 0 0
39837- 0 0 0 0 0 0 0 0 0 0 0 0
39838- 0 0 0 0 0 0 0 0 0 0 0 0
39839- 0 0 0 0 0 0 6 6 6 18 18 18
39840- 54 54 54 62 62 62 2 2 6 2 2 6
39841- 2 2 6 30 30 30 46 46 46 70 70 70
39842-250 250 250 253 253 253 253 253 253 253 253 253
39843-253 253 253 253 253 253 253 253 253 253 253 253
39844-253 253 253 253 253 253 231 231 231 246 246 246
39845-253 253 253 253 253 253 253 253 253 253 253 253
39846-253 253 253 253 253 253 253 253 253 253 253 253
39847-253 253 253 253 253 253 253 253 253 253 253 253
39848-253 253 253 253 253 253 253 253 253 253 253 253
39849-253 253 253 253 253 253 226 226 226 10 10 10
39850- 2 2 6 6 6 6 30 30 30 2 2 6
39851- 2 2 6 2 2 6 2 2 6 2 2 6
39852- 2 2 6 66 66 66 58 58 58 22 22 22
39853- 6 6 6 0 0 0 0 0 0 0 0 0
39854- 0 0 0 0 0 0 0 0 0 0 0 0
39855- 0 0 0 0 0 0 0 0 0 0 0 0
39856- 0 0 0 0 0 0 0 0 0 0 0 0
39857- 0 0 0 0 0 0 0 0 0 0 0 0
39858- 0 0 0 0 0 0 0 0 0 0 0 0
39859- 0 0 0 0 0 0 6 6 6 22 22 22
39860- 58 58 58 62 62 62 2 2 6 2 2 6
39861- 2 2 6 2 2 6 30 30 30 78 78 78
39862-250 250 250 253 253 253 253 253 253 253 253 253
39863-253 253 253 253 253 253 253 253 253 253 253 253
39864-253 253 253 253 253 253 231 231 231 246 246 246
39865-253 253 253 253 253 253 253 253 253 253 253 253
39866-253 253 253 253 253 253 253 253 253 253 253 253
39867-253 253 253 253 253 253 253 253 253 253 253 253
39868-253 253 253 253 253 253 253 253 253 253 253 253
39869-253 253 253 253 253 253 206 206 206 2 2 6
39870- 22 22 22 34 34 34 18 14 6 22 22 22
39871- 26 26 26 18 18 18 6 6 6 2 2 6
39872- 2 2 6 82 82 82 54 54 54 18 18 18
39873- 6 6 6 0 0 0 0 0 0 0 0 0
39874- 0 0 0 0 0 0 0 0 0 0 0 0
39875- 0 0 0 0 0 0 0 0 0 0 0 0
39876- 0 0 0 0 0 0 0 0 0 0 0 0
39877- 0 0 0 0 0 0 0 0 0 0 0 0
39878- 0 0 0 0 0 0 0 0 0 0 0 0
39879- 0 0 0 0 0 0 6 6 6 26 26 26
39880- 62 62 62 106 106 106 74 54 14 185 133 11
39881-210 162 10 121 92 8 6 6 6 62 62 62
39882-238 238 238 253 253 253 253 253 253 253 253 253
39883-253 253 253 253 253 253 253 253 253 253 253 253
39884-253 253 253 253 253 253 231 231 231 246 246 246
39885-253 253 253 253 253 253 253 253 253 253 253 253
39886-253 253 253 253 253 253 253 253 253 253 253 253
39887-253 253 253 253 253 253 253 253 253 253 253 253
39888-253 253 253 253 253 253 253 253 253 253 253 253
39889-253 253 253 253 253 253 158 158 158 18 18 18
39890- 14 14 14 2 2 6 2 2 6 2 2 6
39891- 6 6 6 18 18 18 66 66 66 38 38 38
39892- 6 6 6 94 94 94 50 50 50 18 18 18
39893- 6 6 6 0 0 0 0 0 0 0 0 0
39894- 0 0 0 0 0 0 0 0 0 0 0 0
39895- 0 0 0 0 0 0 0 0 0 0 0 0
39896- 0 0 0 0 0 0 0 0 0 0 0 0
39897- 0 0 0 0 0 0 0 0 0 0 0 0
39898- 0 0 0 0 0 0 0 0 0 6 6 6
39899- 10 10 10 10 10 10 18 18 18 38 38 38
39900- 78 78 78 142 134 106 216 158 10 242 186 14
39901-246 190 14 246 190 14 156 118 10 10 10 10
39902- 90 90 90 238 238 238 253 253 253 253 253 253
39903-253 253 253 253 253 253 253 253 253 253 253 253
39904-253 253 253 253 253 253 231 231 231 250 250 250
39905-253 253 253 253 253 253 253 253 253 253 253 253
39906-253 253 253 253 253 253 253 253 253 253 253 253
39907-253 253 253 253 253 253 253 253 253 253 253 253
39908-253 253 253 253 253 253 253 253 253 246 230 190
39909-238 204 91 238 204 91 181 142 44 37 26 9
39910- 2 2 6 2 2 6 2 2 6 2 2 6
39911- 2 2 6 2 2 6 38 38 38 46 46 46
39912- 26 26 26 106 106 106 54 54 54 18 18 18
39913- 6 6 6 0 0 0 0 0 0 0 0 0
39914- 0 0 0 0 0 0 0 0 0 0 0 0
39915- 0 0 0 0 0 0 0 0 0 0 0 0
39916- 0 0 0 0 0 0 0 0 0 0 0 0
39917- 0 0 0 0 0 0 0 0 0 0 0 0
39918- 0 0 0 6 6 6 14 14 14 22 22 22
39919- 30 30 30 38 38 38 50 50 50 70 70 70
39920-106 106 106 190 142 34 226 170 11 242 186 14
39921-246 190 14 246 190 14 246 190 14 154 114 10
39922- 6 6 6 74 74 74 226 226 226 253 253 253
39923-253 253 253 253 253 253 253 253 253 253 253 253
39924-253 253 253 253 253 253 231 231 231 250 250 250
39925-253 253 253 253 253 253 253 253 253 253 253 253
39926-253 253 253 253 253 253 253 253 253 253 253 253
39927-253 253 253 253 253 253 253 253 253 253 253 253
39928-253 253 253 253 253 253 253 253 253 228 184 62
39929-241 196 14 241 208 19 232 195 16 38 30 10
39930- 2 2 6 2 2 6 2 2 6 2 2 6
39931- 2 2 6 6 6 6 30 30 30 26 26 26
39932-203 166 17 154 142 90 66 66 66 26 26 26
39933- 6 6 6 0 0 0 0 0 0 0 0 0
39934- 0 0 0 0 0 0 0 0 0 0 0 0
39935- 0 0 0 0 0 0 0 0 0 0 0 0
39936- 0 0 0 0 0 0 0 0 0 0 0 0
39937- 0 0 0 0 0 0 0 0 0 0 0 0
39938- 6 6 6 18 18 18 38 38 38 58 58 58
39939- 78 78 78 86 86 86 101 101 101 123 123 123
39940-175 146 61 210 150 10 234 174 13 246 186 14
39941-246 190 14 246 190 14 246 190 14 238 190 10
39942-102 78 10 2 2 6 46 46 46 198 198 198
39943-253 253 253 253 253 253 253 253 253 253 253 253
39944-253 253 253 253 253 253 234 234 234 242 242 242
39945-253 253 253 253 253 253 253 253 253 253 253 253
39946-253 253 253 253 253 253 253 253 253 253 253 253
39947-253 253 253 253 253 253 253 253 253 253 253 253
39948-253 253 253 253 253 253 253 253 253 224 178 62
39949-242 186 14 241 196 14 210 166 10 22 18 6
39950- 2 2 6 2 2 6 2 2 6 2 2 6
39951- 2 2 6 2 2 6 6 6 6 121 92 8
39952-238 202 15 232 195 16 82 82 82 34 34 34
39953- 10 10 10 0 0 0 0 0 0 0 0 0
39954- 0 0 0 0 0 0 0 0 0 0 0 0
39955- 0 0 0 0 0 0 0 0 0 0 0 0
39956- 0 0 0 0 0 0 0 0 0 0 0 0
39957- 0 0 0 0 0 0 0 0 0 0 0 0
39958- 14 14 14 38 38 38 70 70 70 154 122 46
39959-190 142 34 200 144 11 197 138 11 197 138 11
39960-213 154 11 226 170 11 242 186 14 246 190 14
39961-246 190 14 246 190 14 246 190 14 246 190 14
39962-225 175 15 46 32 6 2 2 6 22 22 22
39963-158 158 158 250 250 250 253 253 253 253 253 253
39964-253 253 253 253 253 253 253 253 253 253 253 253
39965-253 253 253 253 253 253 253 253 253 253 253 253
39966-253 253 253 253 253 253 253 253 253 253 253 253
39967-253 253 253 253 253 253 253 253 253 253 253 253
39968-253 253 253 250 250 250 242 242 242 224 178 62
39969-239 182 13 236 186 11 213 154 11 46 32 6
39970- 2 2 6 2 2 6 2 2 6 2 2 6
39971- 2 2 6 2 2 6 61 42 6 225 175 15
39972-238 190 10 236 186 11 112 100 78 42 42 42
39973- 14 14 14 0 0 0 0 0 0 0 0 0
39974- 0 0 0 0 0 0 0 0 0 0 0 0
39975- 0 0 0 0 0 0 0 0 0 0 0 0
39976- 0 0 0 0 0 0 0 0 0 0 0 0
39977- 0 0 0 0 0 0 0 0 0 6 6 6
39978- 22 22 22 54 54 54 154 122 46 213 154 11
39979-226 170 11 230 174 11 226 170 11 226 170 11
39980-236 178 12 242 186 14 246 190 14 246 190 14
39981-246 190 14 246 190 14 246 190 14 246 190 14
39982-241 196 14 184 144 12 10 10 10 2 2 6
39983- 6 6 6 116 116 116 242 242 242 253 253 253
39984-253 253 253 253 253 253 253 253 253 253 253 253
39985-253 253 253 253 253 253 253 253 253 253 253 253
39986-253 253 253 253 253 253 253 253 253 253 253 253
39987-253 253 253 253 253 253 253 253 253 253 253 253
39988-253 253 253 231 231 231 198 198 198 214 170 54
39989-236 178 12 236 178 12 210 150 10 137 92 6
39990- 18 14 6 2 2 6 2 2 6 2 2 6
39991- 6 6 6 70 47 6 200 144 11 236 178 12
39992-239 182 13 239 182 13 124 112 88 58 58 58
39993- 22 22 22 6 6 6 0 0 0 0 0 0
39994- 0 0 0 0 0 0 0 0 0 0 0 0
39995- 0 0 0 0 0 0 0 0 0 0 0 0
39996- 0 0 0 0 0 0 0 0 0 0 0 0
39997- 0 0 0 0 0 0 0 0 0 10 10 10
39998- 30 30 30 70 70 70 180 133 36 226 170 11
39999-239 182 13 242 186 14 242 186 14 246 186 14
40000-246 190 14 246 190 14 246 190 14 246 190 14
40001-246 190 14 246 190 14 246 190 14 246 190 14
40002-246 190 14 232 195 16 98 70 6 2 2 6
40003- 2 2 6 2 2 6 66 66 66 221 221 221
40004-253 253 253 253 253 253 253 253 253 253 253 253
40005-253 253 253 253 253 253 253 253 253 253 253 253
40006-253 253 253 253 253 253 253 253 253 253 253 253
40007-253 253 253 253 253 253 253 253 253 253 253 253
40008-253 253 253 206 206 206 198 198 198 214 166 58
40009-230 174 11 230 174 11 216 158 10 192 133 9
40010-163 110 8 116 81 8 102 78 10 116 81 8
40011-167 114 7 197 138 11 226 170 11 239 182 13
40012-242 186 14 242 186 14 162 146 94 78 78 78
40013- 34 34 34 14 14 14 6 6 6 0 0 0
40014- 0 0 0 0 0 0 0 0 0 0 0 0
40015- 0 0 0 0 0 0 0 0 0 0 0 0
40016- 0 0 0 0 0 0 0 0 0 0 0 0
40017- 0 0 0 0 0 0 0 0 0 6 6 6
40018- 30 30 30 78 78 78 190 142 34 226 170 11
40019-239 182 13 246 190 14 246 190 14 246 190 14
40020-246 190 14 246 190 14 246 190 14 246 190 14
40021-246 190 14 246 190 14 246 190 14 246 190 14
40022-246 190 14 241 196 14 203 166 17 22 18 6
40023- 2 2 6 2 2 6 2 2 6 38 38 38
40024-218 218 218 253 253 253 253 253 253 253 253 253
40025-253 253 253 253 253 253 253 253 253 253 253 253
40026-253 253 253 253 253 253 253 253 253 253 253 253
40027-253 253 253 253 253 253 253 253 253 253 253 253
40028-250 250 250 206 206 206 198 198 198 202 162 69
40029-226 170 11 236 178 12 224 166 10 210 150 10
40030-200 144 11 197 138 11 192 133 9 197 138 11
40031-210 150 10 226 170 11 242 186 14 246 190 14
40032-246 190 14 246 186 14 225 175 15 124 112 88
40033- 62 62 62 30 30 30 14 14 14 6 6 6
40034- 0 0 0 0 0 0 0 0 0 0 0 0
40035- 0 0 0 0 0 0 0 0 0 0 0 0
40036- 0 0 0 0 0 0 0 0 0 0 0 0
40037- 0 0 0 0 0 0 0 0 0 10 10 10
40038- 30 30 30 78 78 78 174 135 50 224 166 10
40039-239 182 13 246 190 14 246 190 14 246 190 14
40040-246 190 14 246 190 14 246 190 14 246 190 14
40041-246 190 14 246 190 14 246 190 14 246 190 14
40042-246 190 14 246 190 14 241 196 14 139 102 15
40043- 2 2 6 2 2 6 2 2 6 2 2 6
40044- 78 78 78 250 250 250 253 253 253 253 253 253
40045-253 253 253 253 253 253 253 253 253 253 253 253
40046-253 253 253 253 253 253 253 253 253 253 253 253
40047-253 253 253 253 253 253 253 253 253 253 253 253
40048-250 250 250 214 214 214 198 198 198 190 150 46
40049-219 162 10 236 178 12 234 174 13 224 166 10
40050-216 158 10 213 154 11 213 154 11 216 158 10
40051-226 170 11 239 182 13 246 190 14 246 190 14
40052-246 190 14 246 190 14 242 186 14 206 162 42
40053-101 101 101 58 58 58 30 30 30 14 14 14
40054- 6 6 6 0 0 0 0 0 0 0 0 0
40055- 0 0 0 0 0 0 0 0 0 0 0 0
40056- 0 0 0 0 0 0 0 0 0 0 0 0
40057- 0 0 0 0 0 0 0 0 0 10 10 10
40058- 30 30 30 74 74 74 174 135 50 216 158 10
40059-236 178 12 246 190 14 246 190 14 246 190 14
40060-246 190 14 246 190 14 246 190 14 246 190 14
40061-246 190 14 246 190 14 246 190 14 246 190 14
40062-246 190 14 246 190 14 241 196 14 226 184 13
40063- 61 42 6 2 2 6 2 2 6 2 2 6
40064- 22 22 22 238 238 238 253 253 253 253 253 253
40065-253 253 253 253 253 253 253 253 253 253 253 253
40066-253 253 253 253 253 253 253 253 253 253 253 253
40067-253 253 253 253 253 253 253 253 253 253 253 253
40068-253 253 253 226 226 226 187 187 187 180 133 36
40069-216 158 10 236 178 12 239 182 13 236 178 12
40070-230 174 11 226 170 11 226 170 11 230 174 11
40071-236 178 12 242 186 14 246 190 14 246 190 14
40072-246 190 14 246 190 14 246 186 14 239 182 13
40073-206 162 42 106 106 106 66 66 66 34 34 34
40074- 14 14 14 6 6 6 0 0 0 0 0 0
40075- 0 0 0 0 0 0 0 0 0 0 0 0
40076- 0 0 0 0 0 0 0 0 0 0 0 0
40077- 0 0 0 0 0 0 0 0 0 6 6 6
40078- 26 26 26 70 70 70 163 133 67 213 154 11
40079-236 178 12 246 190 14 246 190 14 246 190 14
40080-246 190 14 246 190 14 246 190 14 246 190 14
40081-246 190 14 246 190 14 246 190 14 246 190 14
40082-246 190 14 246 190 14 246 190 14 241 196 14
40083-190 146 13 18 14 6 2 2 6 2 2 6
40084- 46 46 46 246 246 246 253 253 253 253 253 253
40085-253 253 253 253 253 253 253 253 253 253 253 253
40086-253 253 253 253 253 253 253 253 253 253 253 253
40087-253 253 253 253 253 253 253 253 253 253 253 253
40088-253 253 253 221 221 221 86 86 86 156 107 11
40089-216 158 10 236 178 12 242 186 14 246 186 14
40090-242 186 14 239 182 13 239 182 13 242 186 14
40091-242 186 14 246 186 14 246 190 14 246 190 14
40092-246 190 14 246 190 14 246 190 14 246 190 14
40093-242 186 14 225 175 15 142 122 72 66 66 66
40094- 30 30 30 10 10 10 0 0 0 0 0 0
40095- 0 0 0 0 0 0 0 0 0 0 0 0
40096- 0 0 0 0 0 0 0 0 0 0 0 0
40097- 0 0 0 0 0 0 0 0 0 6 6 6
40098- 26 26 26 70 70 70 163 133 67 210 150 10
40099-236 178 12 246 190 14 246 190 14 246 190 14
40100-246 190 14 246 190 14 246 190 14 246 190 14
40101-246 190 14 246 190 14 246 190 14 246 190 14
40102-246 190 14 246 190 14 246 190 14 246 190 14
40103-232 195 16 121 92 8 34 34 34 106 106 106
40104-221 221 221 253 253 253 253 253 253 253 253 253
40105-253 253 253 253 253 253 253 253 253 253 253 253
40106-253 253 253 253 253 253 253 253 253 253 253 253
40107-253 253 253 253 253 253 253 253 253 253 253 253
40108-242 242 242 82 82 82 18 14 6 163 110 8
40109-216 158 10 236 178 12 242 186 14 246 190 14
40110-246 190 14 246 190 14 246 190 14 246 190 14
40111-246 190 14 246 190 14 246 190 14 246 190 14
40112-246 190 14 246 190 14 246 190 14 246 190 14
40113-246 190 14 246 190 14 242 186 14 163 133 67
40114- 46 46 46 18 18 18 6 6 6 0 0 0
40115- 0 0 0 0 0 0 0 0 0 0 0 0
40116- 0 0 0 0 0 0 0 0 0 0 0 0
40117- 0 0 0 0 0 0 0 0 0 10 10 10
40118- 30 30 30 78 78 78 163 133 67 210 150 10
40119-236 178 12 246 186 14 246 190 14 246 190 14
40120-246 190 14 246 190 14 246 190 14 246 190 14
40121-246 190 14 246 190 14 246 190 14 246 190 14
40122-246 190 14 246 190 14 246 190 14 246 190 14
40123-241 196 14 215 174 15 190 178 144 253 253 253
40124-253 253 253 253 253 253 253 253 253 253 253 253
40125-253 253 253 253 253 253 253 253 253 253 253 253
40126-253 253 253 253 253 253 253 253 253 253 253 253
40127-253 253 253 253 253 253 253 253 253 218 218 218
40128- 58 58 58 2 2 6 22 18 6 167 114 7
40129-216 158 10 236 178 12 246 186 14 246 190 14
40130-246 190 14 246 190 14 246 190 14 246 190 14
40131-246 190 14 246 190 14 246 190 14 246 190 14
40132-246 190 14 246 190 14 246 190 14 246 190 14
40133-246 190 14 246 186 14 242 186 14 190 150 46
40134- 54 54 54 22 22 22 6 6 6 0 0 0
40135- 0 0 0 0 0 0 0 0 0 0 0 0
40136- 0 0 0 0 0 0 0 0 0 0 0 0
40137- 0 0 0 0 0 0 0 0 0 14 14 14
40138- 38 38 38 86 86 86 180 133 36 213 154 11
40139-236 178 12 246 186 14 246 190 14 246 190 14
40140-246 190 14 246 190 14 246 190 14 246 190 14
40141-246 190 14 246 190 14 246 190 14 246 190 14
40142-246 190 14 246 190 14 246 190 14 246 190 14
40143-246 190 14 232 195 16 190 146 13 214 214 214
40144-253 253 253 253 253 253 253 253 253 253 253 253
40145-253 253 253 253 253 253 253 253 253 253 253 253
40146-253 253 253 253 253 253 253 253 253 253 253 253
40147-253 253 253 250 250 250 170 170 170 26 26 26
40148- 2 2 6 2 2 6 37 26 9 163 110 8
40149-219 162 10 239 182 13 246 186 14 246 190 14
40150-246 190 14 246 190 14 246 190 14 246 190 14
40151-246 190 14 246 190 14 246 190 14 246 190 14
40152-246 190 14 246 190 14 246 190 14 246 190 14
40153-246 186 14 236 178 12 224 166 10 142 122 72
40154- 46 46 46 18 18 18 6 6 6 0 0 0
40155- 0 0 0 0 0 0 0 0 0 0 0 0
40156- 0 0 0 0 0 0 0 0 0 0 0 0
40157- 0 0 0 0 0 0 6 6 6 18 18 18
40158- 50 50 50 109 106 95 192 133 9 224 166 10
40159-242 186 14 246 190 14 246 190 14 246 190 14
40160-246 190 14 246 190 14 246 190 14 246 190 14
40161-246 190 14 246 190 14 246 190 14 246 190 14
40162-246 190 14 246 190 14 246 190 14 246 190 14
40163-242 186 14 226 184 13 210 162 10 142 110 46
40164-226 226 226 253 253 253 253 253 253 253 253 253
40165-253 253 253 253 253 253 253 253 253 253 253 253
40166-253 253 253 253 253 253 253 253 253 253 253 253
40167-198 198 198 66 66 66 2 2 6 2 2 6
40168- 2 2 6 2 2 6 50 34 6 156 107 11
40169-219 162 10 239 182 13 246 186 14 246 190 14
40170-246 190 14 246 190 14 246 190 14 246 190 14
40171-246 190 14 246 190 14 246 190 14 246 190 14
40172-246 190 14 246 190 14 246 190 14 242 186 14
40173-234 174 13 213 154 11 154 122 46 66 66 66
40174- 30 30 30 10 10 10 0 0 0 0 0 0
40175- 0 0 0 0 0 0 0 0 0 0 0 0
40176- 0 0 0 0 0 0 0 0 0 0 0 0
40177- 0 0 0 0 0 0 6 6 6 22 22 22
40178- 58 58 58 154 121 60 206 145 10 234 174 13
40179-242 186 14 246 186 14 246 190 14 246 190 14
40180-246 190 14 246 190 14 246 190 14 246 190 14
40181-246 190 14 246 190 14 246 190 14 246 190 14
40182-246 190 14 246 190 14 246 190 14 246 190 14
40183-246 186 14 236 178 12 210 162 10 163 110 8
40184- 61 42 6 138 138 138 218 218 218 250 250 250
40185-253 253 253 253 253 253 253 253 253 250 250 250
40186-242 242 242 210 210 210 144 144 144 66 66 66
40187- 6 6 6 2 2 6 2 2 6 2 2 6
40188- 2 2 6 2 2 6 61 42 6 163 110 8
40189-216 158 10 236 178 12 246 190 14 246 190 14
40190-246 190 14 246 190 14 246 190 14 246 190 14
40191-246 190 14 246 190 14 246 190 14 246 190 14
40192-246 190 14 239 182 13 230 174 11 216 158 10
40193-190 142 34 124 112 88 70 70 70 38 38 38
40194- 18 18 18 6 6 6 0 0 0 0 0 0
40195- 0 0 0 0 0 0 0 0 0 0 0 0
40196- 0 0 0 0 0 0 0 0 0 0 0 0
40197- 0 0 0 0 0 0 6 6 6 22 22 22
40198- 62 62 62 168 124 44 206 145 10 224 166 10
40199-236 178 12 239 182 13 242 186 14 242 186 14
40200-246 186 14 246 190 14 246 190 14 246 190 14
40201-246 190 14 246 190 14 246 190 14 246 190 14
40202-246 190 14 246 190 14 246 190 14 246 190 14
40203-246 190 14 236 178 12 216 158 10 175 118 6
40204- 80 54 7 2 2 6 6 6 6 30 30 30
40205- 54 54 54 62 62 62 50 50 50 38 38 38
40206- 14 14 14 2 2 6 2 2 6 2 2 6
40207- 2 2 6 2 2 6 2 2 6 2 2 6
40208- 2 2 6 6 6 6 80 54 7 167 114 7
40209-213 154 11 236 178 12 246 190 14 246 190 14
40210-246 190 14 246 190 14 246 190 14 246 190 14
40211-246 190 14 242 186 14 239 182 13 239 182 13
40212-230 174 11 210 150 10 174 135 50 124 112 88
40213- 82 82 82 54 54 54 34 34 34 18 18 18
40214- 6 6 6 0 0 0 0 0 0 0 0 0
40215- 0 0 0 0 0 0 0 0 0 0 0 0
40216- 0 0 0 0 0 0 0 0 0 0 0 0
40217- 0 0 0 0 0 0 6 6 6 18 18 18
40218- 50 50 50 158 118 36 192 133 9 200 144 11
40219-216 158 10 219 162 10 224 166 10 226 170 11
40220-230 174 11 236 178 12 239 182 13 239 182 13
40221-242 186 14 246 186 14 246 190 14 246 190 14
40222-246 190 14 246 190 14 246 190 14 246 190 14
40223-246 186 14 230 174 11 210 150 10 163 110 8
40224-104 69 6 10 10 10 2 2 6 2 2 6
40225- 2 2 6 2 2 6 2 2 6 2 2 6
40226- 2 2 6 2 2 6 2 2 6 2 2 6
40227- 2 2 6 2 2 6 2 2 6 2 2 6
40228- 2 2 6 6 6 6 91 60 6 167 114 7
40229-206 145 10 230 174 11 242 186 14 246 190 14
40230-246 190 14 246 190 14 246 186 14 242 186 14
40231-239 182 13 230 174 11 224 166 10 213 154 11
40232-180 133 36 124 112 88 86 86 86 58 58 58
40233- 38 38 38 22 22 22 10 10 10 6 6 6
40234- 0 0 0 0 0 0 0 0 0 0 0 0
40235- 0 0 0 0 0 0 0 0 0 0 0 0
40236- 0 0 0 0 0 0 0 0 0 0 0 0
40237- 0 0 0 0 0 0 0 0 0 14 14 14
40238- 34 34 34 70 70 70 138 110 50 158 118 36
40239-167 114 7 180 123 7 192 133 9 197 138 11
40240-200 144 11 206 145 10 213 154 11 219 162 10
40241-224 166 10 230 174 11 239 182 13 242 186 14
40242-246 186 14 246 186 14 246 186 14 246 186 14
40243-239 182 13 216 158 10 185 133 11 152 99 6
40244-104 69 6 18 14 6 2 2 6 2 2 6
40245- 2 2 6 2 2 6 2 2 6 2 2 6
40246- 2 2 6 2 2 6 2 2 6 2 2 6
40247- 2 2 6 2 2 6 2 2 6 2 2 6
40248- 2 2 6 6 6 6 80 54 7 152 99 6
40249-192 133 9 219 162 10 236 178 12 239 182 13
40250-246 186 14 242 186 14 239 182 13 236 178 12
40251-224 166 10 206 145 10 192 133 9 154 121 60
40252- 94 94 94 62 62 62 42 42 42 22 22 22
40253- 14 14 14 6 6 6 0 0 0 0 0 0
40254- 0 0 0 0 0 0 0 0 0 0 0 0
40255- 0 0 0 0 0 0 0 0 0 0 0 0
40256- 0 0 0 0 0 0 0 0 0 0 0 0
40257- 0 0 0 0 0 0 0 0 0 6 6 6
40258- 18 18 18 34 34 34 58 58 58 78 78 78
40259-101 98 89 124 112 88 142 110 46 156 107 11
40260-163 110 8 167 114 7 175 118 6 180 123 7
40261-185 133 11 197 138 11 210 150 10 219 162 10
40262-226 170 11 236 178 12 236 178 12 234 174 13
40263-219 162 10 197 138 11 163 110 8 130 83 6
40264- 91 60 6 10 10 10 2 2 6 2 2 6
40265- 18 18 18 38 38 38 38 38 38 38 38 38
40266- 38 38 38 38 38 38 38 38 38 38 38 38
40267- 38 38 38 38 38 38 26 26 26 2 2 6
40268- 2 2 6 6 6 6 70 47 6 137 92 6
40269-175 118 6 200 144 11 219 162 10 230 174 11
40270-234 174 13 230 174 11 219 162 10 210 150 10
40271-192 133 9 163 110 8 124 112 88 82 82 82
40272- 50 50 50 30 30 30 14 14 14 6 6 6
40273- 0 0 0 0 0 0 0 0 0 0 0 0
40274- 0 0 0 0 0 0 0 0 0 0 0 0
40275- 0 0 0 0 0 0 0 0 0 0 0 0
40276- 0 0 0 0 0 0 0 0 0 0 0 0
40277- 0 0 0 0 0 0 0 0 0 0 0 0
40278- 6 6 6 14 14 14 22 22 22 34 34 34
40279- 42 42 42 58 58 58 74 74 74 86 86 86
40280-101 98 89 122 102 70 130 98 46 121 87 25
40281-137 92 6 152 99 6 163 110 8 180 123 7
40282-185 133 11 197 138 11 206 145 10 200 144 11
40283-180 123 7 156 107 11 130 83 6 104 69 6
40284- 50 34 6 54 54 54 110 110 110 101 98 89
40285- 86 86 86 82 82 82 78 78 78 78 78 78
40286- 78 78 78 78 78 78 78 78 78 78 78 78
40287- 78 78 78 82 82 82 86 86 86 94 94 94
40288-106 106 106 101 101 101 86 66 34 124 80 6
40289-156 107 11 180 123 7 192 133 9 200 144 11
40290-206 145 10 200 144 11 192 133 9 175 118 6
40291-139 102 15 109 106 95 70 70 70 42 42 42
40292- 22 22 22 10 10 10 0 0 0 0 0 0
40293- 0 0 0 0 0 0 0 0 0 0 0 0
40294- 0 0 0 0 0 0 0 0 0 0 0 0
40295- 0 0 0 0 0 0 0 0 0 0 0 0
40296- 0 0 0 0 0 0 0 0 0 0 0 0
40297- 0 0 0 0 0 0 0 0 0 0 0 0
40298- 0 0 0 0 0 0 6 6 6 10 10 10
40299- 14 14 14 22 22 22 30 30 30 38 38 38
40300- 50 50 50 62 62 62 74 74 74 90 90 90
40301-101 98 89 112 100 78 121 87 25 124 80 6
40302-137 92 6 152 99 6 152 99 6 152 99 6
40303-138 86 6 124 80 6 98 70 6 86 66 30
40304-101 98 89 82 82 82 58 58 58 46 46 46
40305- 38 38 38 34 34 34 34 34 34 34 34 34
40306- 34 34 34 34 34 34 34 34 34 34 34 34
40307- 34 34 34 34 34 34 38 38 38 42 42 42
40308- 54 54 54 82 82 82 94 86 76 91 60 6
40309-134 86 6 156 107 11 167 114 7 175 118 6
40310-175 118 6 167 114 7 152 99 6 121 87 25
40311-101 98 89 62 62 62 34 34 34 18 18 18
40312- 6 6 6 0 0 0 0 0 0 0 0 0
40313- 0 0 0 0 0 0 0 0 0 0 0 0
40314- 0 0 0 0 0 0 0 0 0 0 0 0
40315- 0 0 0 0 0 0 0 0 0 0 0 0
40316- 0 0 0 0 0 0 0 0 0 0 0 0
40317- 0 0 0 0 0 0 0 0 0 0 0 0
40318- 0 0 0 0 0 0 0 0 0 0 0 0
40319- 0 0 0 6 6 6 6 6 6 10 10 10
40320- 18 18 18 22 22 22 30 30 30 42 42 42
40321- 50 50 50 66 66 66 86 86 86 101 98 89
40322-106 86 58 98 70 6 104 69 6 104 69 6
40323-104 69 6 91 60 6 82 62 34 90 90 90
40324- 62 62 62 38 38 38 22 22 22 14 14 14
40325- 10 10 10 10 10 10 10 10 10 10 10 10
40326- 10 10 10 10 10 10 6 6 6 10 10 10
40327- 10 10 10 10 10 10 10 10 10 14 14 14
40328- 22 22 22 42 42 42 70 70 70 89 81 66
40329- 80 54 7 104 69 6 124 80 6 137 92 6
40330-134 86 6 116 81 8 100 82 52 86 86 86
40331- 58 58 58 30 30 30 14 14 14 6 6 6
40332- 0 0 0 0 0 0 0 0 0 0 0 0
40333- 0 0 0 0 0 0 0 0 0 0 0 0
40334- 0 0 0 0 0 0 0 0 0 0 0 0
40335- 0 0 0 0 0 0 0 0 0 0 0 0
40336- 0 0 0 0 0 0 0 0 0 0 0 0
40337- 0 0 0 0 0 0 0 0 0 0 0 0
40338- 0 0 0 0 0 0 0 0 0 0 0 0
40339- 0 0 0 0 0 0 0 0 0 0 0 0
40340- 0 0 0 6 6 6 10 10 10 14 14 14
40341- 18 18 18 26 26 26 38 38 38 54 54 54
40342- 70 70 70 86 86 86 94 86 76 89 81 66
40343- 89 81 66 86 86 86 74 74 74 50 50 50
40344- 30 30 30 14 14 14 6 6 6 0 0 0
40345- 0 0 0 0 0 0 0 0 0 0 0 0
40346- 0 0 0 0 0 0 0 0 0 0 0 0
40347- 0 0 0 0 0 0 0 0 0 0 0 0
40348- 6 6 6 18 18 18 34 34 34 58 58 58
40349- 82 82 82 89 81 66 89 81 66 89 81 66
40350- 94 86 66 94 86 76 74 74 74 50 50 50
40351- 26 26 26 14 14 14 6 6 6 0 0 0
40352- 0 0 0 0 0 0 0 0 0 0 0 0
40353- 0 0 0 0 0 0 0 0 0 0 0 0
40354- 0 0 0 0 0 0 0 0 0 0 0 0
40355- 0 0 0 0 0 0 0 0 0 0 0 0
40356- 0 0 0 0 0 0 0 0 0 0 0 0
40357- 0 0 0 0 0 0 0 0 0 0 0 0
40358- 0 0 0 0 0 0 0 0 0 0 0 0
40359- 0 0 0 0 0 0 0 0 0 0 0 0
40360- 0 0 0 0 0 0 0 0 0 0 0 0
40361- 6 6 6 6 6 6 14 14 14 18 18 18
40362- 30 30 30 38 38 38 46 46 46 54 54 54
40363- 50 50 50 42 42 42 30 30 30 18 18 18
40364- 10 10 10 0 0 0 0 0 0 0 0 0
40365- 0 0 0 0 0 0 0 0 0 0 0 0
40366- 0 0 0 0 0 0 0 0 0 0 0 0
40367- 0 0 0 0 0 0 0 0 0 0 0 0
40368- 0 0 0 6 6 6 14 14 14 26 26 26
40369- 38 38 38 50 50 50 58 58 58 58 58 58
40370- 54 54 54 42 42 42 30 30 30 18 18 18
40371- 10 10 10 0 0 0 0 0 0 0 0 0
40372- 0 0 0 0 0 0 0 0 0 0 0 0
40373- 0 0 0 0 0 0 0 0 0 0 0 0
40374- 0 0 0 0 0 0 0 0 0 0 0 0
40375- 0 0 0 0 0 0 0 0 0 0 0 0
40376- 0 0 0 0 0 0 0 0 0 0 0 0
40377- 0 0 0 0 0 0 0 0 0 0 0 0
40378- 0 0 0 0 0 0 0 0 0 0 0 0
40379- 0 0 0 0 0 0 0 0 0 0 0 0
40380- 0 0 0 0 0 0 0 0 0 0 0 0
40381- 0 0 0 0 0 0 0 0 0 6 6 6
40382- 6 6 6 10 10 10 14 14 14 18 18 18
40383- 18 18 18 14 14 14 10 10 10 6 6 6
40384- 0 0 0 0 0 0 0 0 0 0 0 0
40385- 0 0 0 0 0 0 0 0 0 0 0 0
40386- 0 0 0 0 0 0 0 0 0 0 0 0
40387- 0 0 0 0 0 0 0 0 0 0 0 0
40388- 0 0 0 0 0 0 0 0 0 6 6 6
40389- 14 14 14 18 18 18 22 22 22 22 22 22
40390- 18 18 18 14 14 14 10 10 10 6 6 6
40391- 0 0 0 0 0 0 0 0 0 0 0 0
40392- 0 0 0 0 0 0 0 0 0 0 0 0
40393- 0 0 0 0 0 0 0 0 0 0 0 0
40394- 0 0 0 0 0 0 0 0 0 0 0 0
40395- 0 0 0 0 0 0 0 0 0 0 0 0
40396+4 4 4 4 4 4 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 4 4 4 4 4 4 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 4 4 4
40406+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40407+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40408+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40409+4 4 4 4 4 4
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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40421+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40423+4 4 4 4 4 4
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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
40435+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40436+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40437+4 4 4 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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
40449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40450+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40451+4 4 4 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 4 4 4 4 4 4 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 4 4 4
40463+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40464+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40465+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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40478+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40479+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 3 3 3 0 0 0 0 0 0
40485+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40486+4 4 4 4 4 4 4 4 4 4 4 4 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 1 1 1 0 0 0
40490+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40491+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40492+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40493+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 2 2 2 0 0 0 3 4 3 26 28 28
40499+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40500+5 5 5 4 4 4 4 4 4 4 4 4 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 3 3 3 0 0 0 1 1 1 6 6 6
40504+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40505+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40506+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40507+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+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40513+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40514+0 0 0 3 3 3 4 4 4 4 4 4 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 0 0 0 4 4 4 41 54 63 125 124 125
40518+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40519+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40520+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40521+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 5 5 5 5 5 5 2 2 2 0 0 0
40526+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40527+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40528+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40530+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40531+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40532+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40533+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40534+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40535+4 4 4 4 4 4
40536+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40537+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40538+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40539+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40540+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40541+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40542+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40543+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40544+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40545+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40546+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40547+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40548+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40549+4 4 4 4 4 4
40550+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40551+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40552+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40553+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40554+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40555+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40556+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40557+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40558+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40559+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40560+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40561+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40562+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40563+4 4 4 4 4 4
40564+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40565+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40566+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40567+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40568+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40569+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40570+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40571+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40572+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40573+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40574+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40575+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40576+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40577+4 4 4 4 4 4
40578+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40579+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40580+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40581+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40582+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40583+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40584+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40585+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40586+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40587+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40588+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40589+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40590+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40591+4 4 4 4 4 4
40592+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40593+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40594+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40595+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40596+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40597+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40598+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40599+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40600+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40601+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40602+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40603+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40604+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40605+4 4 4 4 4 4
40606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40608+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40609+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40610+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40611+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40612+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40613+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40614+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40615+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40616+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40617+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40618+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40619+4 4 4 4 4 4
40620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40621+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40622+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40623+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40624+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40625+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40626+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40627+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40628+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40629+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40630+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40631+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40632+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40633+4 4 4 4 4 4
40634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40635+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40636+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40637+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40638+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40639+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40640+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40641+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40642+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40643+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40644+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40645+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40646+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40647+0 0 0 4 4 4
40648+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40649+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40650+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40651+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40652+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40653+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40654+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40655+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40656+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40657+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40658+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40659+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40660+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40661+2 0 0 0 0 0
40662+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40663+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40664+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40665+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40666+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40667+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40668+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40669+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40670+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40671+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40672+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40673+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40674+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40675+37 38 37 0 0 0
40676+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40677+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
40678+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
40679+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
40680+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
40681+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
40682+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
40683+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
40684+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
40685+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
40686+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
40687+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
40688+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
40689+85 115 134 4 0 0
40690+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
40691+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
40692+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
40693+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
40694+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
40695+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
40696+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
40697+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
40698+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
40699+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
40700+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
40701+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
40702+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
40703+60 73 81 4 0 0
40704+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
40705+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
40706+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
40707+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
40708+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
40709+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
40710+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
40711+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
40712+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
40713+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
40714+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
40715+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
40716+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
40717+16 19 21 4 0 0
40718+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
40719+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
40720+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
40721+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
40722+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
40723+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
40724+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
40725+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
40726+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
40727+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
40728+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
40729+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
40730+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
40731+4 0 0 4 3 3
40732+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
40733+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
40734+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
40735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
40736+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
40737+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
40738+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
40739+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
40740+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
40741+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
40742+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
40743+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
40744+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
40745+3 2 2 4 4 4
40746+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
40747+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
40748+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
40749+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40750+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
40751+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
40752+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
40753+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
40754+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
40755+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
40756+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
40757+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
40758+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
40759+4 4 4 4 4 4
40760+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
40761+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
40762+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
40763+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
40764+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
40765+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
40766+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
40767+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
40768+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
40769+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
40770+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
40771+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
40772+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
40773+4 4 4 4 4 4
40774+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
40775+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
40776+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
40777+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
40778+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
40779+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40780+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
40781+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
40782+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
40783+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
40784+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
40785+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
40786+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
40787+5 5 5 5 5 5
40788+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
40789+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
40790+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
40791+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
40792+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
40793+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40794+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
40795+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
40796+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
40797+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
40798+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
40799+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
40800+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40801+5 5 5 4 4 4
40802+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
40803+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
40804+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
40805+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
40806+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40807+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
40808+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
40809+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
40810+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
40811+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
40812+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
40813+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
40814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40815+4 4 4 4 4 4
40816+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
40817+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
40818+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
40819+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
40820+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
40821+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40822+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40823+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
40824+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
40825+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
40826+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
40827+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
40828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40829+4 4 4 4 4 4
40830+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
40831+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
40832+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
40833+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
40834+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40835+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
40836+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
40837+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
40838+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
40839+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
40840+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
40841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40843+4 4 4 4 4 4
40844+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
40845+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
40846+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
40847+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
40848+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40849+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40850+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40851+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
40852+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
40853+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
40854+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
40855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40857+4 4 4 4 4 4
40858+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
40859+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
40860+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
40861+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
40862+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40863+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
40864+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40865+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
40866+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
40867+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
40868+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40871+4 4 4 4 4 4
40872+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
40873+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
40874+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
40875+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
40876+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40877+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
40878+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
40879+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
40880+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
40881+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
40882+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
40883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40885+4 4 4 4 4 4
40886+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
40887+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
40888+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
40889+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
40890+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40891+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
40892+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
40893+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
40894+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
40895+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
40896+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
40897+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40898+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40899+4 4 4 4 4 4
40900+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
40901+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
40902+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
40903+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40904+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
40905+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
40906+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
40907+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
40908+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
40909+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
40910+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40911+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40912+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40913+4 4 4 4 4 4
40914+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
40915+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
40916+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
40917+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40918+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40919+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
40920+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
40921+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
40922+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
40923+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
40924+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40925+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40926+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40927+4 4 4 4 4 4
40928+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
40929+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
40930+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40931+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40932+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40933+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
40934+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
40935+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
40936+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
40937+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
40938+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40939+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40940+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40941+4 4 4 4 4 4
40942+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
40943+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
40944+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40945+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40946+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40947+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
40948+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
40949+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
40950+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40951+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40952+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40953+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40954+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40955+4 4 4 4 4 4
40956+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40957+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
40958+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40959+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
40960+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
40961+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
40962+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
40963+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
40964+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40965+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40966+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40967+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40968+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40969+4 4 4 4 4 4
40970+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40971+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
40972+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40973+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
40974+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40975+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
40976+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
40977+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
40978+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40979+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40980+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40981+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40982+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40983+4 4 4 4 4 4
40984+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
40985+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
40986+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40987+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
40988+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
40989+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
40990+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
40991+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
40992+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40993+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40994+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40995+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40996+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40997+4 4 4 4 4 4
40998+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
40999+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41000+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41001+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41002+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41003+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41004+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41005+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41006+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41007+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41008+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41009+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41011+4 4 4 4 4 4
41012+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41013+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41014+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41015+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41016+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41017+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41018+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41019+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41020+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41021+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41022+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41023+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41025+4 4 4 4 4 4
41026+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41027+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41028+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41029+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41030+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41031+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41032+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41033+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41034+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41035+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41036+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41037+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41039+4 4 4 4 4 4
41040+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41041+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41042+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41043+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41044+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41045+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41046+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41047+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41048+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41049+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41050+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41051+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41052+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41053+4 4 4 4 4 4
41054+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41055+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41056+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41057+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41058+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41059+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41060+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41061+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41062+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41063+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41064+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41065+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41066+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41067+4 4 4 4 4 4
41068+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41069+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41070+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41071+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41072+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41073+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41074+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41075+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41076+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41077+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41078+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41079+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41080+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41081+4 4 4 4 4 4
41082+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41083+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41084+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41085+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41086+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41087+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41088+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41089+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41090+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41091+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41092+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41093+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41094+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41095+4 4 4 4 4 4
41096+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41097+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41098+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41099+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41100+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41101+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41102+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41103+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41104+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41105+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41106+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41108+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41109+4 4 4 4 4 4
41110+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41111+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41112+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41113+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41114+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41115+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41116+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41117+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41118+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41119+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41120+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41122+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41123+4 4 4 4 4 4
41124+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41125+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41126+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41127+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41128+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41129+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41130+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41131+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41132+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41133+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41134+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41136+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41137+4 4 4 4 4 4
41138+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41139+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41140+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41141+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41142+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41143+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41144+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41145+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41146+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41147+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41148+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41151+4 4 4 4 4 4
41152+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41153+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41154+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41155+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41156+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41157+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41158+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41159+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41160+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41161+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41162+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41164+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41165+4 4 4 4 4 4
41166+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41167+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41168+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41169+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41170+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41171+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41172+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41173+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41174+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41175+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41176+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41179+4 4 4 4 4 4
41180+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41181+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41182+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41183+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41184+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41185+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41186+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41187+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41188+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41189+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41190+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41192+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41193+4 4 4 4 4 4
41194+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41195+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41196+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41197+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41198+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41199+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41200+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41201+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41202+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41203+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41204+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41206+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41207+4 4 4 4 4 4
41208+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41209+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41210+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41211+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41212+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41213+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41214+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41215+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41216+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41217+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41220+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41221+4 4 4 4 4 4
41222+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41223+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41224+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41225+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41226+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41227+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41228+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41229+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41230+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41231+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41232+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41234+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41235+4 4 4 4 4 4
41236+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41237+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41238+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41239+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41240+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41241+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41242+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41243+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41244+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41245+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41246+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41248+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41249+4 4 4 4 4 4
41250+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41251+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41252+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41253+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41254+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41255+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41256+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41257+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41258+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41259+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41260+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41261+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41262+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41263+4 4 4 4 4 4
41264+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41265+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41266+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41267+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41268+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41269+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41270+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41271+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41272+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
41273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41274+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41276+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41277+4 4 4 4 4 4
41278+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41279+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41280+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41281+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41282+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41283+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41284+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41285+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41286+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
41287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41288+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41290+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41291+4 4 4 4 4 4
41292+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41293+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41294+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41295+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41296+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41297+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41298+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41299+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41300+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41302+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41305+4 4 4 4 4 4
41306+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41307+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41308+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41309+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41310+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41311+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41312+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41313+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
41314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41316+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41318+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41319+4 4 4 4 4 4
41320+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41321+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41322+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41323+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41324+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41325+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41326+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41327+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41329+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41330+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41333+4 4 4 4 4 4
41334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41335+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41336+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41337+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41338+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41339+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41340+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41341+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
41342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41346+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41347+4 4 4 4 4 4
41348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41349+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41350+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41351+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41352+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41353+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41354+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41355+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
41356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41357+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41358+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41359+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41360+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41361+4 4 4 4 4 4
41362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41363+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41364+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41365+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41366+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41367+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41368+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41369+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41372+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41373+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41374+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41375+4 4 4 4 4 4
41376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41377+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41378+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41379+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41380+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41381+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41382+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41383+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41386+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41387+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41388+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41389+4 4 4 4 4 4
41390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41391+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41392+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41393+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41394+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41395+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41396+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
41397+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41400+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41401+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41402+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41403+4 4 4 4 4 4
41404+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41405+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41406+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41407+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41408+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41409+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41410+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
41411+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41412+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41415+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41416+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41417+4 4 4 4 4 4
41418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41419+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41420+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41421+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41422+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41423+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41424+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
41425+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41426+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41428+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41429+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41430+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41431+4 4 4 4 4 4
41432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41433+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41434+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41435+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
41436+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41437+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41438+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
41439+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41442+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41443+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41444+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41445+4 4 4 4 4 4
41446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41447+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41448+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41450+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41451+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41452+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41453+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41454+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41455+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41456+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41457+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41458+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41459+4 4 4 4 4 4
41460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41461+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41462+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41463+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41464+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41465+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41466+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41467+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41468+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41469+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41470+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41471+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41472+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41473+4 4 4 4 4 4
41474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41475+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41476+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41477+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41478+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41479+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41480+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41481+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41482+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41483+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41484+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41485+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41486+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41487+4 4 4 4 4 4
41488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41489+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41490+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41491+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41492+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41493+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
41494+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41495+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41496+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41497+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41498+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41499+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41501+4 4 4 4 4 4
41502+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41503+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41504+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41505+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41506+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41507+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41508+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41509+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41510+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41511+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41512+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41513+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41515+4 4 4 4 4 4
41516diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41517index a40c05e..785c583 100644
41518--- a/drivers/video/udlfb.c
41519+++ b/drivers/video/udlfb.c
41520@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41521 dlfb_urb_completion(urb);
41522
41523 error:
41524- atomic_add(bytes_sent, &dev->bytes_sent);
41525- atomic_add(bytes_identical, &dev->bytes_identical);
41526- atomic_add(width*height*2, &dev->bytes_rendered);
41527+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41528+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41529+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41530 end_cycles = get_cycles();
41531- atomic_add(((unsigned int) ((end_cycles - start_cycles)
41532+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41533 >> 10)), /* Kcycles */
41534 &dev->cpu_kcycles_used);
41535
41536@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41537 dlfb_urb_completion(urb);
41538
41539 error:
41540- atomic_add(bytes_sent, &dev->bytes_sent);
41541- atomic_add(bytes_identical, &dev->bytes_identical);
41542- atomic_add(bytes_rendered, &dev->bytes_rendered);
41543+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41544+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41545+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41546 end_cycles = get_cycles();
41547- atomic_add(((unsigned int) ((end_cycles - start_cycles)
41548+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41549 >> 10)), /* Kcycles */
41550 &dev->cpu_kcycles_used);
41551 }
41552@@ -1368,7 +1368,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41553 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41554 struct dlfb_data *dev = fb_info->par;
41555 return snprintf(buf, PAGE_SIZE, "%u\n",
41556- atomic_read(&dev->bytes_rendered));
41557+ atomic_read_unchecked(&dev->bytes_rendered));
41558 }
41559
41560 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41561@@ -1376,7 +1376,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41562 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41563 struct dlfb_data *dev = fb_info->par;
41564 return snprintf(buf, PAGE_SIZE, "%u\n",
41565- atomic_read(&dev->bytes_identical));
41566+ atomic_read_unchecked(&dev->bytes_identical));
41567 }
41568
41569 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41570@@ -1384,7 +1384,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41571 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41572 struct dlfb_data *dev = fb_info->par;
41573 return snprintf(buf, PAGE_SIZE, "%u\n",
41574- atomic_read(&dev->bytes_sent));
41575+ atomic_read_unchecked(&dev->bytes_sent));
41576 }
41577
41578 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41579@@ -1392,7 +1392,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41580 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41581 struct dlfb_data *dev = fb_info->par;
41582 return snprintf(buf, PAGE_SIZE, "%u\n",
41583- atomic_read(&dev->cpu_kcycles_used));
41584+ atomic_read_unchecked(&dev->cpu_kcycles_used));
41585 }
41586
41587 static ssize_t edid_show(
41588@@ -1449,10 +1449,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41589 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41590 struct dlfb_data *dev = fb_info->par;
41591
41592- atomic_set(&dev->bytes_rendered, 0);
41593- atomic_set(&dev->bytes_identical, 0);
41594- atomic_set(&dev->bytes_sent, 0);
41595- atomic_set(&dev->cpu_kcycles_used, 0);
41596+ atomic_set_unchecked(&dev->bytes_rendered, 0);
41597+ atomic_set_unchecked(&dev->bytes_identical, 0);
41598+ atomic_set_unchecked(&dev->bytes_sent, 0);
41599+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41600
41601 return count;
41602 }
41603diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41604index 8408543..d6f20f1 100644
41605--- a/drivers/video/uvesafb.c
41606+++ b/drivers/video/uvesafb.c
41607@@ -19,6 +19,7 @@
41608 #include <linux/io.h>
41609 #include <linux/mutex.h>
41610 #include <linux/slab.h>
41611+#include <linux/moduleloader.h>
41612 #include <video/edid.h>
41613 #include <video/uvesafb.h>
41614 #ifdef CONFIG_X86
41615@@ -73,7 +74,7 @@ static void uvesafb_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *ns
41616 struct uvesafb_task *utask;
41617 struct uvesafb_ktask *task;
41618
41619- if (!cap_raised(current_cap(), CAP_SYS_ADMIN))
41620+ if (!capable(CAP_SYS_ADMIN))
41621 return;
41622
41623 if (msg->seq >= UVESAFB_TASKS_MAX)
41624@@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
41625 NULL,
41626 };
41627
41628- return call_usermodehelper(v86d_path, argv, envp, 1);
41629+ return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
41630 }
41631
41632 /*
41633@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41634 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41635 par->pmi_setpal = par->ypan = 0;
41636 } else {
41637+
41638+#ifdef CONFIG_PAX_KERNEXEC
41639+#ifdef CONFIG_MODULES
41640+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41641+#endif
41642+ if (!par->pmi_code) {
41643+ par->pmi_setpal = par->ypan = 0;
41644+ return 0;
41645+ }
41646+#endif
41647+
41648 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41649 + task->t.regs.edi);
41650+
41651+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41652+ pax_open_kernel();
41653+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41654+ pax_close_kernel();
41655+
41656+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41657+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41658+#else
41659 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41660 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41661+#endif
41662+
41663 printk(KERN_INFO "uvesafb: protected mode interface info at "
41664 "%04x:%04x\n",
41665 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41666@@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
41667 par->ypan = ypan;
41668
41669 if (par->pmi_setpal || par->ypan) {
41670+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
41671 if (__supported_pte_mask & _PAGE_NX) {
41672 par->pmi_setpal = par->ypan = 0;
41673 printk(KERN_WARNING "uvesafb: NX protection is actively."
41674 "We have better not to use the PMI.\n");
41675- } else {
41676+ } else
41677+#endif
41678 uvesafb_vbe_getpmi(task, par);
41679- }
41680 }
41681 #else
41682 /* The protected mode interface is not available on non-x86. */
41683@@ -1828,6 +1852,11 @@ out:
41684 if (par->vbe_modes)
41685 kfree(par->vbe_modes);
41686
41687+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41688+ if (par->pmi_code)
41689+ module_free_exec(NULL, par->pmi_code);
41690+#endif
41691+
41692 framebuffer_release(info);
41693 return err;
41694 }
41695@@ -1854,6 +1883,12 @@ static int uvesafb_remove(struct platform_device *dev)
41696 kfree(par->vbe_state_orig);
41697 if (par->vbe_state_saved)
41698 kfree(par->vbe_state_saved);
41699+
41700+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41701+ if (par->pmi_code)
41702+ module_free_exec(NULL, par->pmi_code);
41703+#endif
41704+
41705 }
41706
41707 framebuffer_release(info);
41708diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
41709index 501b340..86bd4cf 100644
41710--- a/drivers/video/vesafb.c
41711+++ b/drivers/video/vesafb.c
41712@@ -9,6 +9,7 @@
41713 */
41714
41715 #include <linux/module.h>
41716+#include <linux/moduleloader.h>
41717 #include <linux/kernel.h>
41718 #include <linux/errno.h>
41719 #include <linux/string.h>
41720@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
41721 static int vram_total __initdata; /* Set total amount of memory */
41722 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
41723 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
41724-static void (*pmi_start)(void) __read_mostly;
41725-static void (*pmi_pal) (void) __read_mostly;
41726+static void (*pmi_start)(void) __read_only;
41727+static void (*pmi_pal) (void) __read_only;
41728 static int depth __read_mostly;
41729 static int vga_compat __read_mostly;
41730 /* --------------------------------------------------------------------- */
41731@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
41732 unsigned int size_vmode;
41733 unsigned int size_remap;
41734 unsigned int size_total;
41735+ void *pmi_code = NULL;
41736
41737 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
41738 return -ENODEV;
41739@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
41740 size_remap = size_total;
41741 vesafb_fix.smem_len = size_remap;
41742
41743-#ifndef __i386__
41744- screen_info.vesapm_seg = 0;
41745-#endif
41746-
41747 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
41748 printk(KERN_WARNING
41749 "vesafb: cannot reserve video memory at 0x%lx\n",
41750@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
41751 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
41752 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
41753
41754+#ifdef __i386__
41755+
41756+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41757+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
41758+ if (!pmi_code)
41759+#elif !defined(CONFIG_PAX_KERNEXEC)
41760+ if (0)
41761+#endif
41762+
41763+#endif
41764+ screen_info.vesapm_seg = 0;
41765+
41766 if (screen_info.vesapm_seg) {
41767- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
41768- screen_info.vesapm_seg,screen_info.vesapm_off);
41769+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
41770+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
41771 }
41772
41773 if (screen_info.vesapm_seg < 0xc000)
41774@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
41775
41776 if (ypan || pmi_setpal) {
41777 unsigned short *pmi_base;
41778+
41779 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
41780- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
41781- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
41782+
41783+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41784+ pax_open_kernel();
41785+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
41786+#else
41787+ pmi_code = pmi_base;
41788+#endif
41789+
41790+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
41791+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
41792+
41793+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41794+ pmi_start = ktva_ktla(pmi_start);
41795+ pmi_pal = ktva_ktla(pmi_pal);
41796+ pax_close_kernel();
41797+#endif
41798+
41799 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
41800 if (pmi_base[3]) {
41801 printk(KERN_INFO "vesafb: pmi: ports = ");
41802@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
41803 info->node, info->fix.id);
41804 return 0;
41805 err:
41806+
41807+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41808+ module_free_exec(NULL, pmi_code);
41809+#endif
41810+
41811 if (info->screen_base)
41812 iounmap(info->screen_base);
41813 framebuffer_release(info);
41814diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
41815index 88714ae..16c2e11 100644
41816--- a/drivers/video/via/via_clock.h
41817+++ b/drivers/video/via/via_clock.h
41818@@ -56,7 +56,7 @@ struct via_clock {
41819
41820 void (*set_engine_pll_state)(u8 state);
41821 void (*set_engine_pll)(struct via_pll_config config);
41822-};
41823+} __no_const;
41824
41825
41826 static inline u32 get_pll_internal_frequency(u32 ref_freq,
41827diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
41828index e56c934..fc22f4b 100644
41829--- a/drivers/xen/xen-pciback/conf_space.h
41830+++ b/drivers/xen/xen-pciback/conf_space.h
41831@@ -44,15 +44,15 @@ struct config_field {
41832 struct {
41833 conf_dword_write write;
41834 conf_dword_read read;
41835- } dw;
41836+ } __no_const dw;
41837 struct {
41838 conf_word_write write;
41839 conf_word_read read;
41840- } w;
41841+ } __no_const w;
41842 struct {
41843 conf_byte_write write;
41844 conf_byte_read read;
41845- } b;
41846+ } __no_const b;
41847 } u;
41848 struct list_head list;
41849 };
41850diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
41851index 014c8dd..6f3dfe6 100644
41852--- a/fs/9p/vfs_inode.c
41853+++ b/fs/9p/vfs_inode.c
41854@@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
41855 void
41856 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41857 {
41858- char *s = nd_get_link(nd);
41859+ const char *s = nd_get_link(nd);
41860
41861 p9_debug(P9_DEBUG_VFS, " %s %s\n",
41862 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
41863diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
41864index e95d1b6..3454244 100644
41865--- a/fs/Kconfig.binfmt
41866+++ b/fs/Kconfig.binfmt
41867@@ -89,7 +89,7 @@ config HAVE_AOUT
41868
41869 config BINFMT_AOUT
41870 tristate "Kernel support for a.out and ECOFF binaries"
41871- depends on HAVE_AOUT
41872+ depends on HAVE_AOUT && BROKEN
41873 ---help---
41874 A.out (Assembler.OUTput) is a set of formats for libraries and
41875 executables used in the earliest versions of UNIX. Linux used
41876diff --git a/fs/aio.c b/fs/aio.c
41877index b9d64d8..86cb1d5 100644
41878--- a/fs/aio.c
41879+++ b/fs/aio.c
41880@@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx *ctx)
41881 size += sizeof(struct io_event) * nr_events;
41882 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
41883
41884- if (nr_pages < 0)
41885+ if (nr_pages <= 0)
41886 return -EINVAL;
41887
41888 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
41889@@ -1461,22 +1461,27 @@ static ssize_t aio_fsync(struct kiocb *iocb)
41890 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41891 {
41892 ssize_t ret;
41893+ struct iovec iovstack;
41894
41895 #ifdef CONFIG_COMPAT
41896 if (compat)
41897 ret = compat_rw_copy_check_uvector(type,
41898 (struct compat_iovec __user *)kiocb->ki_buf,
41899- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41900+ kiocb->ki_nbytes, 1, &iovstack,
41901 &kiocb->ki_iovec, 1);
41902 else
41903 #endif
41904 ret = rw_copy_check_uvector(type,
41905 (struct iovec __user *)kiocb->ki_buf,
41906- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41907+ kiocb->ki_nbytes, 1, &iovstack,
41908 &kiocb->ki_iovec, 1);
41909 if (ret < 0)
41910 goto out;
41911
41912+ if (kiocb->ki_iovec == &iovstack) {
41913+ kiocb->ki_inline_vec = iovstack;
41914+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
41915+ }
41916 kiocb->ki_nr_segs = kiocb->ki_nbytes;
41917 kiocb->ki_cur_seg = 0;
41918 /* ki_nbytes/left now reflect bytes instead of segs */
41919diff --git a/fs/attr.c b/fs/attr.c
41920index 95053ad..2cc93ca 100644
41921--- a/fs/attr.c
41922+++ b/fs/attr.c
41923@@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
41924 unsigned long limit;
41925
41926 limit = rlimit(RLIMIT_FSIZE);
41927+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
41928 if (limit != RLIM_INFINITY && offset > limit)
41929 goto out_sig;
41930 if (offset > inode->i_sb->s_maxbytes)
41931diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
41932index f624cd0..3d9a559 100644
41933--- a/fs/autofs4/waitq.c
41934+++ b/fs/autofs4/waitq.c
41935@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
41936 {
41937 unsigned long sigpipe, flags;
41938 mm_segment_t fs;
41939- const char *data = (const char *)addr;
41940+ const char __user *data = (const char __force_user *)addr;
41941 ssize_t wr = 0;
41942
41943 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
41944diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
41945index 6e6d536..457113a 100644
41946--- a/fs/befs/linuxvfs.c
41947+++ b/fs/befs/linuxvfs.c
41948@@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41949 {
41950 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
41951 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
41952- char *link = nd_get_link(nd);
41953+ const char *link = nd_get_link(nd);
41954 if (!IS_ERR(link))
41955 kfree(link);
41956 }
41957diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
41958index 1ff9405..f1e376a 100644
41959--- a/fs/binfmt_aout.c
41960+++ b/fs/binfmt_aout.c
41961@@ -16,6 +16,7 @@
41962 #include <linux/string.h>
41963 #include <linux/fs.h>
41964 #include <linux/file.h>
41965+#include <linux/security.h>
41966 #include <linux/stat.h>
41967 #include <linux/fcntl.h>
41968 #include <linux/ptrace.h>
41969@@ -86,6 +87,8 @@ static int aout_core_dump(struct coredump_params *cprm)
41970 #endif
41971 # define START_STACK(u) ((void __user *)u.start_stack)
41972
41973+ memset(&dump, 0, sizeof(dump));
41974+
41975 fs = get_fs();
41976 set_fs(KERNEL_DS);
41977 has_dumped = 1;
41978@@ -97,10 +100,12 @@ static int aout_core_dump(struct coredump_params *cprm)
41979
41980 /* If the size of the dump file exceeds the rlimit, then see what would happen
41981 if we wrote the stack, but not the data area. */
41982+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
41983 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
41984 dump.u_dsize = 0;
41985
41986 /* Make sure we have enough room to write the stack and data areas. */
41987+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
41988 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
41989 dump.u_ssize = 0;
41990
41991@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41992 rlim = rlimit(RLIMIT_DATA);
41993 if (rlim >= RLIM_INFINITY)
41994 rlim = ~0;
41995+
41996+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
41997 if (ex.a_data + ex.a_bss > rlim)
41998 return -ENOMEM;
41999
42000@@ -269,6 +276,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42001 install_exec_creds(bprm);
42002 current->flags &= ~PF_FORKNOEXEC;
42003
42004+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42005+ current->mm->pax_flags = 0UL;
42006+#endif
42007+
42008+#ifdef CONFIG_PAX_PAGEEXEC
42009+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42010+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42011+
42012+#ifdef CONFIG_PAX_EMUTRAMP
42013+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42014+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42015+#endif
42016+
42017+#ifdef CONFIG_PAX_MPROTECT
42018+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42019+ current->mm->pax_flags |= MF_PAX_MPROTECT;
42020+#endif
42021+
42022+ }
42023+#endif
42024+
42025 if (N_MAGIC(ex) == OMAGIC) {
42026 unsigned long text_addr, map_size;
42027 loff_t pos;
42028@@ -341,7 +369,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42029
42030 down_write(&current->mm->mmap_sem);
42031 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42032- PROT_READ | PROT_WRITE | PROT_EXEC,
42033+ PROT_READ | PROT_WRITE,
42034 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42035 fd_offset + ex.a_text);
42036 up_write(&current->mm->mmap_sem);
42037diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42038index 07d096c..25762af 100644
42039--- a/fs/binfmt_elf.c
42040+++ b/fs/binfmt_elf.c
42041@@ -32,6 +32,7 @@
42042 #include <linux/elf.h>
42043 #include <linux/utsname.h>
42044 #include <linux/coredump.h>
42045+#include <linux/xattr.h>
42046 #include <asm/uaccess.h>
42047 #include <asm/param.h>
42048 #include <asm/page.h>
42049@@ -51,6 +52,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42050 #define elf_core_dump NULL
42051 #endif
42052
42053+#ifdef CONFIG_PAX_MPROTECT
42054+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42055+#endif
42056+
42057 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42058 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42059 #else
42060@@ -70,6 +75,11 @@ static struct linux_binfmt elf_format = {
42061 .load_binary = load_elf_binary,
42062 .load_shlib = load_elf_library,
42063 .core_dump = elf_core_dump,
42064+
42065+#ifdef CONFIG_PAX_MPROTECT
42066+ .handle_mprotect= elf_handle_mprotect,
42067+#endif
42068+
42069 .min_coredump = ELF_EXEC_PAGESIZE,
42070 };
42071
42072@@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
42073
42074 static int set_brk(unsigned long start, unsigned long end)
42075 {
42076+ unsigned long e = end;
42077+
42078 start = ELF_PAGEALIGN(start);
42079 end = ELF_PAGEALIGN(end);
42080 if (end > start) {
42081@@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
42082 if (BAD_ADDR(addr))
42083 return addr;
42084 }
42085- current->mm->start_brk = current->mm->brk = end;
42086+ current->mm->start_brk = current->mm->brk = e;
42087 return 0;
42088 }
42089
42090@@ -148,12 +160,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42091 elf_addr_t __user *u_rand_bytes;
42092 const char *k_platform = ELF_PLATFORM;
42093 const char *k_base_platform = ELF_BASE_PLATFORM;
42094- unsigned char k_rand_bytes[16];
42095+ u32 k_rand_bytes[4];
42096 int items;
42097 elf_addr_t *elf_info;
42098 int ei_index = 0;
42099 const struct cred *cred = current_cred();
42100 struct vm_area_struct *vma;
42101+ unsigned long saved_auxv[AT_VECTOR_SIZE];
42102
42103 /*
42104 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42105@@ -195,8 +208,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42106 * Generate 16 random bytes for userspace PRNG seeding.
42107 */
42108 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42109- u_rand_bytes = (elf_addr_t __user *)
42110- STACK_ALLOC(p, sizeof(k_rand_bytes));
42111+ srandom32(k_rand_bytes[0] ^ random32());
42112+ srandom32(k_rand_bytes[1] ^ random32());
42113+ srandom32(k_rand_bytes[2] ^ random32());
42114+ srandom32(k_rand_bytes[3] ^ random32());
42115+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
42116+ u_rand_bytes = (elf_addr_t __user *) p;
42117 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42118 return -EFAULT;
42119
42120@@ -308,9 +325,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42121 return -EFAULT;
42122 current->mm->env_end = p;
42123
42124+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42125+
42126 /* Put the elf_info on the stack in the right place. */
42127 sp = (elf_addr_t __user *)envp + 1;
42128- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42129+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42130 return -EFAULT;
42131 return 0;
42132 }
42133@@ -381,10 +400,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42134 {
42135 struct elf_phdr *elf_phdata;
42136 struct elf_phdr *eppnt;
42137- unsigned long load_addr = 0;
42138+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42139 int load_addr_set = 0;
42140 unsigned long last_bss = 0, elf_bss = 0;
42141- unsigned long error = ~0UL;
42142+ unsigned long error = -EINVAL;
42143 unsigned long total_size;
42144 int retval, i, size;
42145
42146@@ -430,6 +449,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42147 goto out_close;
42148 }
42149
42150+#ifdef CONFIG_PAX_SEGMEXEC
42151+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42152+ pax_task_size = SEGMEXEC_TASK_SIZE;
42153+#endif
42154+
42155 eppnt = elf_phdata;
42156 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42157 if (eppnt->p_type == PT_LOAD) {
42158@@ -473,8 +497,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42159 k = load_addr + eppnt->p_vaddr;
42160 if (BAD_ADDR(k) ||
42161 eppnt->p_filesz > eppnt->p_memsz ||
42162- eppnt->p_memsz > TASK_SIZE ||
42163- TASK_SIZE - eppnt->p_memsz < k) {
42164+ eppnt->p_memsz > pax_task_size ||
42165+ pax_task_size - eppnt->p_memsz < k) {
42166 error = -ENOMEM;
42167 goto out_close;
42168 }
42169@@ -528,6 +552,351 @@ out:
42170 return error;
42171 }
42172
42173+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42174+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42175+{
42176+ unsigned long pax_flags = 0UL;
42177+
42178+#ifdef CONFIG_PAX_PT_PAX_FLAGS
42179+
42180+#ifdef CONFIG_PAX_PAGEEXEC
42181+ if (elf_phdata->p_flags & PF_PAGEEXEC)
42182+ pax_flags |= MF_PAX_PAGEEXEC;
42183+#endif
42184+
42185+#ifdef CONFIG_PAX_SEGMEXEC
42186+ if (elf_phdata->p_flags & PF_SEGMEXEC)
42187+ pax_flags |= MF_PAX_SEGMEXEC;
42188+#endif
42189+
42190+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42191+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42192+ if ((__supported_pte_mask & _PAGE_NX))
42193+ pax_flags &= ~MF_PAX_SEGMEXEC;
42194+ else
42195+ pax_flags &= ~MF_PAX_PAGEEXEC;
42196+ }
42197+#endif
42198+
42199+#ifdef CONFIG_PAX_EMUTRAMP
42200+ if (elf_phdata->p_flags & PF_EMUTRAMP)
42201+ pax_flags |= MF_PAX_EMUTRAMP;
42202+#endif
42203+
42204+#ifdef CONFIG_PAX_MPROTECT
42205+ if (elf_phdata->p_flags & PF_MPROTECT)
42206+ pax_flags |= MF_PAX_MPROTECT;
42207+#endif
42208+
42209+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42210+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42211+ pax_flags |= MF_PAX_RANDMMAP;
42212+#endif
42213+
42214+#endif
42215+
42216+ return pax_flags;
42217+}
42218+
42219+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42220+{
42221+ unsigned long pax_flags = 0UL;
42222+
42223+#ifdef CONFIG_PAX_PT_PAX_FLAGS
42224+
42225+#ifdef CONFIG_PAX_PAGEEXEC
42226+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42227+ pax_flags |= MF_PAX_PAGEEXEC;
42228+#endif
42229+
42230+#ifdef CONFIG_PAX_SEGMEXEC
42231+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42232+ pax_flags |= MF_PAX_SEGMEXEC;
42233+#endif
42234+
42235+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42236+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42237+ if ((__supported_pte_mask & _PAGE_NX))
42238+ pax_flags &= ~MF_PAX_SEGMEXEC;
42239+ else
42240+ pax_flags &= ~MF_PAX_PAGEEXEC;
42241+ }
42242+#endif
42243+
42244+#ifdef CONFIG_PAX_EMUTRAMP
42245+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42246+ pax_flags |= MF_PAX_EMUTRAMP;
42247+#endif
42248+
42249+#ifdef CONFIG_PAX_MPROTECT
42250+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42251+ pax_flags |= MF_PAX_MPROTECT;
42252+#endif
42253+
42254+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42255+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42256+ pax_flags |= MF_PAX_RANDMMAP;
42257+#endif
42258+
42259+#endif
42260+
42261+ return pax_flags;
42262+}
42263+
42264+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42265+{
42266+ unsigned long pax_flags = 0UL;
42267+
42268+#ifdef CONFIG_PAX_EI_PAX
42269+
42270+#ifdef CONFIG_PAX_PAGEEXEC
42271+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42272+ pax_flags |= MF_PAX_PAGEEXEC;
42273+#endif
42274+
42275+#ifdef CONFIG_PAX_SEGMEXEC
42276+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42277+ pax_flags |= MF_PAX_SEGMEXEC;
42278+#endif
42279+
42280+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42281+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42282+ if ((__supported_pte_mask & _PAGE_NX))
42283+ pax_flags &= ~MF_PAX_SEGMEXEC;
42284+ else
42285+ pax_flags &= ~MF_PAX_PAGEEXEC;
42286+ }
42287+#endif
42288+
42289+#ifdef CONFIG_PAX_EMUTRAMP
42290+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42291+ pax_flags |= MF_PAX_EMUTRAMP;
42292+#endif
42293+
42294+#ifdef CONFIG_PAX_MPROTECT
42295+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42296+ pax_flags |= MF_PAX_MPROTECT;
42297+#endif
42298+
42299+#ifdef CONFIG_PAX_ASLR
42300+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42301+ pax_flags |= MF_PAX_RANDMMAP;
42302+#endif
42303+
42304+#else
42305+
42306+#ifdef CONFIG_PAX_PAGEEXEC
42307+ pax_flags |= MF_PAX_PAGEEXEC;
42308+#endif
42309+
42310+#ifdef CONFIG_PAX_MPROTECT
42311+ pax_flags |= MF_PAX_MPROTECT;
42312+#endif
42313+
42314+#ifdef CONFIG_PAX_RANDMMAP
42315+ pax_flags |= MF_PAX_RANDMMAP;
42316+#endif
42317+
42318+#ifdef CONFIG_PAX_SEGMEXEC
42319+ if (!(pax_flags & MF_PAX_PAGEEXEC) || !(__supported_pte_mask & _PAGE_NX)) {
42320+ pax_flags &= ~MF_PAX_PAGEEXEC;
42321+ pax_flags |= MF_PAX_SEGMEXEC;
42322+ }
42323+#endif
42324+
42325+#endif
42326+
42327+ return pax_flags;
42328+}
42329+
42330+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42331+{
42332+
42333+#ifdef CONFIG_PAX_PT_PAX_FLAGS
42334+ unsigned long i;
42335+
42336+ for (i = 0UL; i < elf_ex->e_phnum; i++)
42337+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42338+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42339+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42340+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42341+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42342+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42343+ return ~0UL;
42344+
42345+#ifdef CONFIG_PAX_SOFTMODE
42346+ if (pax_softmode)
42347+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42348+ else
42349+#endif
42350+
42351+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42352+ break;
42353+ }
42354+#endif
42355+
42356+ return ~0UL;
42357+}
42358+
42359+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42360+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42361+{
42362+ unsigned long pax_flags = 0UL;
42363+
42364+#ifdef CONFIG_PAX_PAGEEXEC
42365+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42366+ pax_flags |= MF_PAX_PAGEEXEC;
42367+#endif
42368+
42369+#ifdef CONFIG_PAX_SEGMEXEC
42370+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42371+ pax_flags |= MF_PAX_SEGMEXEC;
42372+#endif
42373+
42374+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42375+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42376+ if ((__supported_pte_mask & _PAGE_NX))
42377+ pax_flags &= ~MF_PAX_SEGMEXEC;
42378+ else
42379+ pax_flags &= ~MF_PAX_PAGEEXEC;
42380+ }
42381+#endif
42382+
42383+#ifdef CONFIG_PAX_EMUTRAMP
42384+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42385+ pax_flags |= MF_PAX_EMUTRAMP;
42386+#endif
42387+
42388+#ifdef CONFIG_PAX_MPROTECT
42389+ if (pax_flags_softmode & MF_PAX_MPROTECT)
42390+ pax_flags |= MF_PAX_MPROTECT;
42391+#endif
42392+
42393+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42394+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42395+ pax_flags |= MF_PAX_RANDMMAP;
42396+#endif
42397+
42398+ return pax_flags;
42399+}
42400+
42401+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42402+{
42403+ unsigned long pax_flags = 0UL;
42404+
42405+#ifdef CONFIG_PAX_PAGEEXEC
42406+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42407+ pax_flags |= MF_PAX_PAGEEXEC;
42408+#endif
42409+
42410+#ifdef CONFIG_PAX_SEGMEXEC
42411+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42412+ pax_flags |= MF_PAX_SEGMEXEC;
42413+#endif
42414+
42415+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42416+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42417+ if ((__supported_pte_mask & _PAGE_NX))
42418+ pax_flags &= ~MF_PAX_SEGMEXEC;
42419+ else
42420+ pax_flags &= ~MF_PAX_PAGEEXEC;
42421+ }
42422+#endif
42423+
42424+#ifdef CONFIG_PAX_EMUTRAMP
42425+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42426+ pax_flags |= MF_PAX_EMUTRAMP;
42427+#endif
42428+
42429+#ifdef CONFIG_PAX_MPROTECT
42430+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42431+ pax_flags |= MF_PAX_MPROTECT;
42432+#endif
42433+
42434+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42435+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42436+ pax_flags |= MF_PAX_RANDMMAP;
42437+#endif
42438+
42439+ return pax_flags;
42440+}
42441+#endif
42442+
42443+static unsigned long pax_parse_xattr_pax(struct file * const file)
42444+{
42445+
42446+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42447+ ssize_t xattr_size, i;
42448+ unsigned char xattr_value[5];
42449+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42450+
42451+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42452+ if (xattr_size <= 0)
42453+ return ~0UL;
42454+
42455+ for (i = 0; i < xattr_size; i++)
42456+ switch (xattr_value[i]) {
42457+ default:
42458+ return ~0UL;
42459+
42460+#define parse_flag(option1, option2, flag) \
42461+ case option1: \
42462+ pax_flags_hardmode |= MF_PAX_##flag; \
42463+ break; \
42464+ case option2: \
42465+ pax_flags_softmode |= MF_PAX_##flag; \
42466+ break;
42467+
42468+ parse_flag('p', 'P', PAGEEXEC);
42469+ parse_flag('e', 'E', EMUTRAMP);
42470+ parse_flag('m', 'M', MPROTECT);
42471+ parse_flag('r', 'R', RANDMMAP);
42472+ parse_flag('s', 'S', SEGMEXEC);
42473+
42474+#undef parse_flag
42475+ }
42476+
42477+ if (pax_flags_hardmode & pax_flags_softmode)
42478+ return ~0UL;
42479+
42480+#ifdef CONFIG_PAX_SOFTMODE
42481+ if (pax_softmode)
42482+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42483+ else
42484+#endif
42485+
42486+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42487+#else
42488+ return ~0UL;
42489+#endif
42490+
42491+}
42492+
42493+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42494+{
42495+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42496+
42497+ pax_flags = pax_parse_ei_pax(elf_ex);
42498+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42499+ xattr_pax_flags = pax_parse_xattr_pax(file);
42500+
42501+ if (pt_pax_flags == ~0UL)
42502+ pt_pax_flags = xattr_pax_flags;
42503+ else if (xattr_pax_flags == ~0UL)
42504+ xattr_pax_flags = pt_pax_flags;
42505+ if (pt_pax_flags != xattr_pax_flags)
42506+ return -EINVAL;
42507+ if (pt_pax_flags != ~0UL)
42508+ pax_flags = pt_pax_flags;
42509+
42510+ if (0 > pax_check_flags(&pax_flags))
42511+ return -EINVAL;
42512+
42513+ current->mm->pax_flags = pax_flags;
42514+ return 0;
42515+}
42516+#endif
42517+
42518 /*
42519 * These are the functions used to load ELF style executables and shared
42520 * libraries. There is no binary dependent code anywhere else.
42521@@ -544,6 +913,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42522 {
42523 unsigned int random_variable = 0;
42524
42525+#ifdef CONFIG_PAX_RANDUSTACK
42526+ if (randomize_va_space)
42527+ return stack_top - current->mm->delta_stack;
42528+#endif
42529+
42530 if ((current->flags & PF_RANDOMIZE) &&
42531 !(current->personality & ADDR_NO_RANDOMIZE)) {
42532 random_variable = get_random_int() & STACK_RND_MASK;
42533@@ -562,7 +936,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42534 unsigned long load_addr = 0, load_bias = 0;
42535 int load_addr_set = 0;
42536 char * elf_interpreter = NULL;
42537- unsigned long error;
42538+ unsigned long error = 0;
42539 struct elf_phdr *elf_ppnt, *elf_phdata;
42540 unsigned long elf_bss, elf_brk;
42541 int retval, i;
42542@@ -572,11 +946,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42543 unsigned long start_code, end_code, start_data, end_data;
42544 unsigned long reloc_func_desc __maybe_unused = 0;
42545 int executable_stack = EXSTACK_DEFAULT;
42546- unsigned long def_flags = 0;
42547 struct {
42548 struct elfhdr elf_ex;
42549 struct elfhdr interp_elf_ex;
42550 } *loc;
42551+ unsigned long pax_task_size = TASK_SIZE;
42552
42553 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42554 if (!loc) {
42555@@ -713,11 +1087,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42556
42557 /* OK, This is the point of no return */
42558 current->flags &= ~PF_FORKNOEXEC;
42559- current->mm->def_flags = def_flags;
42560+
42561+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42562+ current->mm->pax_flags = 0UL;
42563+#endif
42564+
42565+#ifdef CONFIG_PAX_DLRESOLVE
42566+ current->mm->call_dl_resolve = 0UL;
42567+#endif
42568+
42569+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42570+ current->mm->call_syscall = 0UL;
42571+#endif
42572+
42573+#ifdef CONFIG_PAX_ASLR
42574+ current->mm->delta_mmap = 0UL;
42575+ current->mm->delta_stack = 0UL;
42576+#endif
42577+
42578+ current->mm->def_flags = 0;
42579+
42580+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42581+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42582+ send_sig(SIGKILL, current, 0);
42583+ goto out_free_dentry;
42584+ }
42585+#endif
42586+
42587+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42588+ pax_set_initial_flags(bprm);
42589+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42590+ if (pax_set_initial_flags_func)
42591+ (pax_set_initial_flags_func)(bprm);
42592+#endif
42593+
42594+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42595+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42596+ current->mm->context.user_cs_limit = PAGE_SIZE;
42597+ current->mm->def_flags |= VM_PAGEEXEC;
42598+ }
42599+#endif
42600+
42601+#ifdef CONFIG_PAX_SEGMEXEC
42602+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42603+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42604+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42605+ pax_task_size = SEGMEXEC_TASK_SIZE;
42606+ current->mm->def_flags |= VM_NOHUGEPAGE;
42607+ }
42608+#endif
42609+
42610+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42611+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42612+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42613+ put_cpu();
42614+ }
42615+#endif
42616
42617 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42618 may depend on the personality. */
42619 SET_PERSONALITY(loc->elf_ex);
42620+
42621+#ifdef CONFIG_PAX_ASLR
42622+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42623+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42624+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42625+ }
42626+#endif
42627+
42628+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42629+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42630+ executable_stack = EXSTACK_DISABLE_X;
42631+ current->personality &= ~READ_IMPLIES_EXEC;
42632+ } else
42633+#endif
42634+
42635 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42636 current->personality |= READ_IMPLIES_EXEC;
42637
42638@@ -808,6 +1252,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42639 #else
42640 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42641 #endif
42642+
42643+#ifdef CONFIG_PAX_RANDMMAP
42644+ /* PaX: randomize base address at the default exe base if requested */
42645+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42646+#ifdef CONFIG_SPARC64
42647+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42648+#else
42649+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42650+#endif
42651+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42652+ elf_flags |= MAP_FIXED;
42653+ }
42654+#endif
42655+
42656 }
42657
42658 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42659@@ -840,9 +1298,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42660 * allowed task size. Note that p_filesz must always be
42661 * <= p_memsz so it is only necessary to check p_memsz.
42662 */
42663- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42664- elf_ppnt->p_memsz > TASK_SIZE ||
42665- TASK_SIZE - elf_ppnt->p_memsz < k) {
42666+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42667+ elf_ppnt->p_memsz > pax_task_size ||
42668+ pax_task_size - elf_ppnt->p_memsz < k) {
42669 /* set_brk can never work. Avoid overflows. */
42670 send_sig(SIGKILL, current, 0);
42671 retval = -EINVAL;
42672@@ -881,11 +1339,40 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42673 goto out_free_dentry;
42674 }
42675 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42676- send_sig(SIGSEGV, current, 0);
42677- retval = -EFAULT; /* Nobody gets to see this, but.. */
42678- goto out_free_dentry;
42679+ /*
42680+ * This bss-zeroing can fail if the ELF
42681+ * file specifies odd protections. So
42682+ * we don't check the return value
42683+ */
42684 }
42685
42686+#ifdef CONFIG_PAX_RANDMMAP
42687+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42688+ unsigned long start, size;
42689+
42690+ start = ELF_PAGEALIGN(elf_brk);
42691+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
42692+ down_write(&current->mm->mmap_sem);
42693+ retval = -ENOMEM;
42694+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
42695+ unsigned long prot = PROT_NONE;
42696+
42697+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
42698+// if (current->personality & ADDR_NO_RANDOMIZE)
42699+// prot = PROT_READ;
42700+ start = do_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
42701+ retval = IS_ERR_VALUE(start) ? start : 0;
42702+ }
42703+ up_write(&current->mm->mmap_sem);
42704+ if (retval == 0)
42705+ retval = set_brk(start + size, start + size + PAGE_SIZE);
42706+ if (retval < 0) {
42707+ send_sig(SIGKILL, current, 0);
42708+ goto out_free_dentry;
42709+ }
42710+ }
42711+#endif
42712+
42713 if (elf_interpreter) {
42714 unsigned long uninitialized_var(interp_map_addr);
42715
42716@@ -1098,7 +1585,7 @@ out:
42717 * Decide what to dump of a segment, part, all or none.
42718 */
42719 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42720- unsigned long mm_flags)
42721+ unsigned long mm_flags, long signr)
42722 {
42723 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42724
42725@@ -1132,7 +1619,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42726 if (vma->vm_file == NULL)
42727 return 0;
42728
42729- if (FILTER(MAPPED_PRIVATE))
42730+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42731 goto whole;
42732
42733 /*
42734@@ -1354,9 +1841,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
42735 {
42736 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
42737 int i = 0;
42738- do
42739+ do {
42740 i += 2;
42741- while (auxv[i - 2] != AT_NULL);
42742+ } while (auxv[i - 2] != AT_NULL);
42743 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
42744 }
42745
42746@@ -1862,14 +2349,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
42747 }
42748
42749 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
42750- unsigned long mm_flags)
42751+ struct coredump_params *cprm)
42752 {
42753 struct vm_area_struct *vma;
42754 size_t size = 0;
42755
42756 for (vma = first_vma(current, gate_vma); vma != NULL;
42757 vma = next_vma(vma, gate_vma))
42758- size += vma_dump_size(vma, mm_flags);
42759+ size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42760 return size;
42761 }
42762
42763@@ -1963,7 +2450,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42764
42765 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
42766
42767- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
42768+ offset += elf_core_vma_data_size(gate_vma, cprm);
42769 offset += elf_core_extra_data_size();
42770 e_shoff = offset;
42771
42772@@ -1977,10 +2464,12 @@ static int elf_core_dump(struct coredump_params *cprm)
42773 offset = dataoff;
42774
42775 size += sizeof(*elf);
42776+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
42777 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
42778 goto end_coredump;
42779
42780 size += sizeof(*phdr4note);
42781+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
42782 if (size > cprm->limit
42783 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
42784 goto end_coredump;
42785@@ -1994,7 +2483,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42786 phdr.p_offset = offset;
42787 phdr.p_vaddr = vma->vm_start;
42788 phdr.p_paddr = 0;
42789- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
42790+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42791 phdr.p_memsz = vma->vm_end - vma->vm_start;
42792 offset += phdr.p_filesz;
42793 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
42794@@ -2005,6 +2494,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42795 phdr.p_align = ELF_EXEC_PAGESIZE;
42796
42797 size += sizeof(phdr);
42798+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
42799 if (size > cprm->limit
42800 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
42801 goto end_coredump;
42802@@ -2029,7 +2519,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42803 unsigned long addr;
42804 unsigned long end;
42805
42806- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
42807+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42808
42809 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
42810 struct page *page;
42811@@ -2038,6 +2528,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42812 page = get_dump_page(addr);
42813 if (page) {
42814 void *kaddr = kmap(page);
42815+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
42816 stop = ((size += PAGE_SIZE) > cprm->limit) ||
42817 !dump_write(cprm->file, kaddr,
42818 PAGE_SIZE);
42819@@ -2055,6 +2546,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42820
42821 if (e_phnum == PN_XNUM) {
42822 size += sizeof(*shdr4extnum);
42823+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
42824 if (size > cprm->limit
42825 || !dump_write(cprm->file, shdr4extnum,
42826 sizeof(*shdr4extnum)))
42827@@ -2075,6 +2567,97 @@ out:
42828
42829 #endif /* CONFIG_ELF_CORE */
42830
42831+#ifdef CONFIG_PAX_MPROTECT
42832+/* PaX: non-PIC ELF libraries need relocations on their executable segments
42833+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
42834+ * we'll remove VM_MAYWRITE for good on RELRO segments.
42835+ *
42836+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
42837+ * basis because we want to allow the common case and not the special ones.
42838+ */
42839+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
42840+{
42841+ struct elfhdr elf_h;
42842+ struct elf_phdr elf_p;
42843+ unsigned long i;
42844+ unsigned long oldflags;
42845+ bool is_textrel_rw, is_textrel_rx, is_relro;
42846+
42847+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
42848+ return;
42849+
42850+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
42851+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
42852+
42853+#ifdef CONFIG_PAX_ELFRELOCS
42854+ /* possible TEXTREL */
42855+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
42856+ 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);
42857+#else
42858+ is_textrel_rw = false;
42859+ is_textrel_rx = false;
42860+#endif
42861+
42862+ /* possible RELRO */
42863+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
42864+
42865+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
42866+ return;
42867+
42868+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
42869+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
42870+
42871+#ifdef CONFIG_PAX_ETEXECRELOCS
42872+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42873+#else
42874+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
42875+#endif
42876+
42877+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42878+ !elf_check_arch(&elf_h) ||
42879+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
42880+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
42881+ return;
42882+
42883+ for (i = 0UL; i < elf_h.e_phnum; i++) {
42884+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
42885+ return;
42886+ switch (elf_p.p_type) {
42887+ case PT_DYNAMIC:
42888+ if (!is_textrel_rw && !is_textrel_rx)
42889+ continue;
42890+ i = 0UL;
42891+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
42892+ elf_dyn dyn;
42893+
42894+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
42895+ return;
42896+ if (dyn.d_tag == DT_NULL)
42897+ return;
42898+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
42899+ gr_log_textrel(vma);
42900+ if (is_textrel_rw)
42901+ vma->vm_flags |= VM_MAYWRITE;
42902+ else
42903+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
42904+ vma->vm_flags &= ~VM_MAYWRITE;
42905+ return;
42906+ }
42907+ i++;
42908+ }
42909+ return;
42910+
42911+ case PT_GNU_RELRO:
42912+ if (!is_relro)
42913+ continue;
42914+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
42915+ vma->vm_flags &= ~VM_MAYWRITE;
42916+ return;
42917+ }
42918+ }
42919+}
42920+#endif
42921+
42922 static int __init init_elf_binfmt(void)
42923 {
42924 return register_binfmt(&elf_format);
42925diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
42926index 1bffbe0..c8c283e 100644
42927--- a/fs/binfmt_flat.c
42928+++ b/fs/binfmt_flat.c
42929@@ -567,7 +567,9 @@ static int load_flat_file(struct linux_binprm * bprm,
42930 realdatastart = (unsigned long) -ENOMEM;
42931 printk("Unable to allocate RAM for process data, errno %d\n",
42932 (int)-realdatastart);
42933+ down_write(&current->mm->mmap_sem);
42934 do_munmap(current->mm, textpos, text_len);
42935+ up_write(&current->mm->mmap_sem);
42936 ret = realdatastart;
42937 goto err;
42938 }
42939@@ -591,8 +593,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42940 }
42941 if (IS_ERR_VALUE(result)) {
42942 printk("Unable to read data+bss, errno %d\n", (int)-result);
42943+ down_write(&current->mm->mmap_sem);
42944 do_munmap(current->mm, textpos, text_len);
42945 do_munmap(current->mm, realdatastart, len);
42946+ up_write(&current->mm->mmap_sem);
42947 ret = result;
42948 goto err;
42949 }
42950@@ -661,8 +665,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42951 }
42952 if (IS_ERR_VALUE(result)) {
42953 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
42954+ down_write(&current->mm->mmap_sem);
42955 do_munmap(current->mm, textpos, text_len + data_len + extra +
42956 MAX_SHARED_LIBS * sizeof(unsigned long));
42957+ up_write(&current->mm->mmap_sem);
42958 ret = result;
42959 goto err;
42960 }
42961diff --git a/fs/bio.c b/fs/bio.c
42962index b980ecd..74800bf 100644
42963--- a/fs/bio.c
42964+++ b/fs/bio.c
42965@@ -833,7 +833,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
42966 /*
42967 * Overflow, abort
42968 */
42969- if (end < start)
42970+ if (end < start || end - start > INT_MAX - nr_pages)
42971 return ERR_PTR(-EINVAL);
42972
42973 nr_pages += end - start;
42974@@ -1229,7 +1229,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
42975 const int read = bio_data_dir(bio) == READ;
42976 struct bio_map_data *bmd = bio->bi_private;
42977 int i;
42978- char *p = bmd->sgvecs[0].iov_base;
42979+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
42980
42981 __bio_for_each_segment(bvec, bio, i, 0) {
42982 char *addr = page_address(bvec->bv_page);
42983diff --git a/fs/block_dev.c b/fs/block_dev.c
42984index 5e9f198..6bf9b1c 100644
42985--- a/fs/block_dev.c
42986+++ b/fs/block_dev.c
42987@@ -703,7 +703,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
42988 else if (bdev->bd_contains == bdev)
42989 return true; /* is a whole device which isn't held */
42990
42991- else if (whole->bd_holder == bd_may_claim)
42992+ else if (whole->bd_holder == (void *)bd_may_claim)
42993 return true; /* is a partition of a device that is being partitioned */
42994 else if (whole->bd_holder != NULL)
42995 return false; /* is a partition of a held device */
42996diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
42997index d986824..af1befd 100644
42998--- a/fs/btrfs/check-integrity.c
42999+++ b/fs/btrfs/check-integrity.c
43000@@ -157,7 +157,7 @@ struct btrfsic_block {
43001 union {
43002 bio_end_io_t *bio;
43003 bh_end_io_t *bh;
43004- } orig_bio_bh_end_io;
43005+ } __no_const orig_bio_bh_end_io;
43006 int submit_bio_bh_rw;
43007 u64 flush_gen; /* only valid if !never_written */
43008 };
43009diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43010index 0639a55..7d9e07f 100644
43011--- a/fs/btrfs/ctree.c
43012+++ b/fs/btrfs/ctree.c
43013@@ -488,9 +488,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43014 free_extent_buffer(buf);
43015 add_root_to_dirty_list(root);
43016 } else {
43017- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43018- parent_start = parent->start;
43019- else
43020+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43021+ if (parent)
43022+ parent_start = parent->start;
43023+ else
43024+ parent_start = 0;
43025+ } else
43026 parent_start = 0;
43027
43028 WARN_ON(trans->transid != btrfs_header_generation(parent));
43029diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43030index 892b347..b3db246 100644
43031--- a/fs/btrfs/inode.c
43032+++ b/fs/btrfs/inode.c
43033@@ -6930,7 +6930,7 @@ fail:
43034 return -ENOMEM;
43035 }
43036
43037-static int btrfs_getattr(struct vfsmount *mnt,
43038+int btrfs_getattr(struct vfsmount *mnt,
43039 struct dentry *dentry, struct kstat *stat)
43040 {
43041 struct inode *inode = dentry->d_inode;
43042@@ -6944,6 +6944,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43043 return 0;
43044 }
43045
43046+EXPORT_SYMBOL(btrfs_getattr);
43047+
43048+dev_t get_btrfs_dev_from_inode(struct inode *inode)
43049+{
43050+ return BTRFS_I(inode)->root->anon_dev;
43051+}
43052+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43053+
43054 /*
43055 * If a file is moved, it will inherit the cow and compression flags of the new
43056 * directory.
43057diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43058index 1b36f19..5ac7360 100644
43059--- a/fs/btrfs/ioctl.c
43060+++ b/fs/btrfs/ioctl.c
43061@@ -2783,9 +2783,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43062 for (i = 0; i < num_types; i++) {
43063 struct btrfs_space_info *tmp;
43064
43065+ /* Don't copy in more than we allocated */
43066 if (!slot_count)
43067 break;
43068
43069+ slot_count--;
43070+
43071 info = NULL;
43072 rcu_read_lock();
43073 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43074@@ -2807,15 +2810,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43075 memcpy(dest, &space, sizeof(space));
43076 dest++;
43077 space_args.total_spaces++;
43078- slot_count--;
43079 }
43080- if (!slot_count)
43081- break;
43082 }
43083 up_read(&info->groups_sem);
43084 }
43085
43086- user_dest = (struct btrfs_ioctl_space_info *)
43087+ user_dest = (struct btrfs_ioctl_space_info __user *)
43088 (arg + sizeof(struct btrfs_ioctl_space_args));
43089
43090 if (copy_to_user(user_dest, dest_orig, alloc_size))
43091diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43092index 8c1aae2..1e46446 100644
43093--- a/fs/btrfs/relocation.c
43094+++ b/fs/btrfs/relocation.c
43095@@ -1244,7 +1244,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43096 }
43097 spin_unlock(&rc->reloc_root_tree.lock);
43098
43099- BUG_ON((struct btrfs_root *)node->data != root);
43100+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
43101
43102 if (!del) {
43103 spin_lock(&rc->reloc_root_tree.lock);
43104diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43105index 622f469..e8d2d55 100644
43106--- a/fs/cachefiles/bind.c
43107+++ b/fs/cachefiles/bind.c
43108@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43109 args);
43110
43111 /* start by checking things over */
43112- ASSERT(cache->fstop_percent >= 0 &&
43113- cache->fstop_percent < cache->fcull_percent &&
43114+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
43115 cache->fcull_percent < cache->frun_percent &&
43116 cache->frun_percent < 100);
43117
43118- ASSERT(cache->bstop_percent >= 0 &&
43119- cache->bstop_percent < cache->bcull_percent &&
43120+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
43121 cache->bcull_percent < cache->brun_percent &&
43122 cache->brun_percent < 100);
43123
43124diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43125index 0a1467b..6a53245 100644
43126--- a/fs/cachefiles/daemon.c
43127+++ b/fs/cachefiles/daemon.c
43128@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43129 if (n > buflen)
43130 return -EMSGSIZE;
43131
43132- if (copy_to_user(_buffer, buffer, n) != 0)
43133+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43134 return -EFAULT;
43135
43136 return n;
43137@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43138 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43139 return -EIO;
43140
43141- if (datalen < 0 || datalen > PAGE_SIZE - 1)
43142+ if (datalen > PAGE_SIZE - 1)
43143 return -EOPNOTSUPP;
43144
43145 /* drag the command string into the kernel so we can parse it */
43146@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43147 if (args[0] != '%' || args[1] != '\0')
43148 return -EINVAL;
43149
43150- if (fstop < 0 || fstop >= cache->fcull_percent)
43151+ if (fstop >= cache->fcull_percent)
43152 return cachefiles_daemon_range_error(cache, args);
43153
43154 cache->fstop_percent = fstop;
43155@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43156 if (args[0] != '%' || args[1] != '\0')
43157 return -EINVAL;
43158
43159- if (bstop < 0 || bstop >= cache->bcull_percent)
43160+ if (bstop >= cache->bcull_percent)
43161 return cachefiles_daemon_range_error(cache, args);
43162
43163 cache->bstop_percent = bstop;
43164diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43165index bd6bc1b..b627b53 100644
43166--- a/fs/cachefiles/internal.h
43167+++ b/fs/cachefiles/internal.h
43168@@ -57,7 +57,7 @@ struct cachefiles_cache {
43169 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43170 struct rb_root active_nodes; /* active nodes (can't be culled) */
43171 rwlock_t active_lock; /* lock for active_nodes */
43172- atomic_t gravecounter; /* graveyard uniquifier */
43173+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43174 unsigned frun_percent; /* when to stop culling (% files) */
43175 unsigned fcull_percent; /* when to start culling (% files) */
43176 unsigned fstop_percent; /* when to stop allocating (% files) */
43177@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43178 * proc.c
43179 */
43180 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43181-extern atomic_t cachefiles_lookup_histogram[HZ];
43182-extern atomic_t cachefiles_mkdir_histogram[HZ];
43183-extern atomic_t cachefiles_create_histogram[HZ];
43184+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43185+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43186+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43187
43188 extern int __init cachefiles_proc_init(void);
43189 extern void cachefiles_proc_cleanup(void);
43190 static inline
43191-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43192+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43193 {
43194 unsigned long jif = jiffies - start_jif;
43195 if (jif >= HZ)
43196 jif = HZ - 1;
43197- atomic_inc(&histogram[jif]);
43198+ atomic_inc_unchecked(&histogram[jif]);
43199 }
43200
43201 #else
43202diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43203index a0358c2..d6137f2 100644
43204--- a/fs/cachefiles/namei.c
43205+++ b/fs/cachefiles/namei.c
43206@@ -318,7 +318,7 @@ try_again:
43207 /* first step is to make up a grave dentry in the graveyard */
43208 sprintf(nbuffer, "%08x%08x",
43209 (uint32_t) get_seconds(),
43210- (uint32_t) atomic_inc_return(&cache->gravecounter));
43211+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43212
43213 /* do the multiway lock magic */
43214 trap = lock_rename(cache->graveyard, dir);
43215diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43216index eccd339..4c1d995 100644
43217--- a/fs/cachefiles/proc.c
43218+++ b/fs/cachefiles/proc.c
43219@@ -14,9 +14,9 @@
43220 #include <linux/seq_file.h>
43221 #include "internal.h"
43222
43223-atomic_t cachefiles_lookup_histogram[HZ];
43224-atomic_t cachefiles_mkdir_histogram[HZ];
43225-atomic_t cachefiles_create_histogram[HZ];
43226+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43227+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43228+atomic_unchecked_t cachefiles_create_histogram[HZ];
43229
43230 /*
43231 * display the latency histogram
43232@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43233 return 0;
43234 default:
43235 index = (unsigned long) v - 3;
43236- x = atomic_read(&cachefiles_lookup_histogram[index]);
43237- y = atomic_read(&cachefiles_mkdir_histogram[index]);
43238- z = atomic_read(&cachefiles_create_histogram[index]);
43239+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43240+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43241+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43242 if (x == 0 && y == 0 && z == 0)
43243 return 0;
43244
43245diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43246index 0e3c092..818480e 100644
43247--- a/fs/cachefiles/rdwr.c
43248+++ b/fs/cachefiles/rdwr.c
43249@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43250 old_fs = get_fs();
43251 set_fs(KERNEL_DS);
43252 ret = file->f_op->write(
43253- file, (const void __user *) data, len, &pos);
43254+ file, (const void __force_user *) data, len, &pos);
43255 set_fs(old_fs);
43256 kunmap(page);
43257 if (ret != len)
43258diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43259index 3e8094b..cb3ff3d 100644
43260--- a/fs/ceph/dir.c
43261+++ b/fs/ceph/dir.c
43262@@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43263 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43264 struct ceph_mds_client *mdsc = fsc->mdsc;
43265 unsigned frag = fpos_frag(filp->f_pos);
43266- int off = fpos_off(filp->f_pos);
43267+ unsigned int off = fpos_off(filp->f_pos);
43268 int err;
43269 u32 ftype;
43270 struct ceph_mds_reply_info_parsed *rinfo;
43271@@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
43272 if (nd &&
43273 (nd->flags & LOOKUP_OPEN) &&
43274 !(nd->intent.open.flags & O_CREAT)) {
43275- int mode = nd->intent.open.create_mode & ~current->fs->umask;
43276+ int mode = nd->intent.open.create_mode & ~current_umask();
43277 return ceph_lookup_open(dir, dentry, nd, mode, 1);
43278 }
43279
43280diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43281index 24b3dfc..3cd5454 100644
43282--- a/fs/cifs/cifs_debug.c
43283+++ b/fs/cifs/cifs_debug.c
43284@@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43285
43286 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43287 #ifdef CONFIG_CIFS_STATS2
43288- atomic_set(&totBufAllocCount, 0);
43289- atomic_set(&totSmBufAllocCount, 0);
43290+ atomic_set_unchecked(&totBufAllocCount, 0);
43291+ atomic_set_unchecked(&totSmBufAllocCount, 0);
43292 #endif /* CONFIG_CIFS_STATS2 */
43293 spin_lock(&cifs_tcp_ses_lock);
43294 list_for_each(tmp1, &cifs_tcp_ses_list) {
43295@@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43296 tcon = list_entry(tmp3,
43297 struct cifs_tcon,
43298 tcon_list);
43299- atomic_set(&tcon->num_smbs_sent, 0);
43300- atomic_set(&tcon->num_writes, 0);
43301- atomic_set(&tcon->num_reads, 0);
43302- atomic_set(&tcon->num_oplock_brks, 0);
43303- atomic_set(&tcon->num_opens, 0);
43304- atomic_set(&tcon->num_posixopens, 0);
43305- atomic_set(&tcon->num_posixmkdirs, 0);
43306- atomic_set(&tcon->num_closes, 0);
43307- atomic_set(&tcon->num_deletes, 0);
43308- atomic_set(&tcon->num_mkdirs, 0);
43309- atomic_set(&tcon->num_rmdirs, 0);
43310- atomic_set(&tcon->num_renames, 0);
43311- atomic_set(&tcon->num_t2renames, 0);
43312- atomic_set(&tcon->num_ffirst, 0);
43313- atomic_set(&tcon->num_fnext, 0);
43314- atomic_set(&tcon->num_fclose, 0);
43315- atomic_set(&tcon->num_hardlinks, 0);
43316- atomic_set(&tcon->num_symlinks, 0);
43317- atomic_set(&tcon->num_locks, 0);
43318+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43319+ atomic_set_unchecked(&tcon->num_writes, 0);
43320+ atomic_set_unchecked(&tcon->num_reads, 0);
43321+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43322+ atomic_set_unchecked(&tcon->num_opens, 0);
43323+ atomic_set_unchecked(&tcon->num_posixopens, 0);
43324+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43325+ atomic_set_unchecked(&tcon->num_closes, 0);
43326+ atomic_set_unchecked(&tcon->num_deletes, 0);
43327+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
43328+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
43329+ atomic_set_unchecked(&tcon->num_renames, 0);
43330+ atomic_set_unchecked(&tcon->num_t2renames, 0);
43331+ atomic_set_unchecked(&tcon->num_ffirst, 0);
43332+ atomic_set_unchecked(&tcon->num_fnext, 0);
43333+ atomic_set_unchecked(&tcon->num_fclose, 0);
43334+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
43335+ atomic_set_unchecked(&tcon->num_symlinks, 0);
43336+ atomic_set_unchecked(&tcon->num_locks, 0);
43337 }
43338 }
43339 }
43340@@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43341 smBufAllocCount.counter, cifs_min_small);
43342 #ifdef CONFIG_CIFS_STATS2
43343 seq_printf(m, "Total Large %d Small %d Allocations\n",
43344- atomic_read(&totBufAllocCount),
43345- atomic_read(&totSmBufAllocCount));
43346+ atomic_read_unchecked(&totBufAllocCount),
43347+ atomic_read_unchecked(&totSmBufAllocCount));
43348 #endif /* CONFIG_CIFS_STATS2 */
43349
43350 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43351@@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43352 if (tcon->need_reconnect)
43353 seq_puts(m, "\tDISCONNECTED ");
43354 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43355- atomic_read(&tcon->num_smbs_sent),
43356- atomic_read(&tcon->num_oplock_brks));
43357+ atomic_read_unchecked(&tcon->num_smbs_sent),
43358+ atomic_read_unchecked(&tcon->num_oplock_brks));
43359 seq_printf(m, "\nReads: %d Bytes: %lld",
43360- atomic_read(&tcon->num_reads),
43361+ atomic_read_unchecked(&tcon->num_reads),
43362 (long long)(tcon->bytes_read));
43363 seq_printf(m, "\nWrites: %d Bytes: %lld",
43364- atomic_read(&tcon->num_writes),
43365+ atomic_read_unchecked(&tcon->num_writes),
43366 (long long)(tcon->bytes_written));
43367 seq_printf(m, "\nFlushes: %d",
43368- atomic_read(&tcon->num_flushes));
43369+ atomic_read_unchecked(&tcon->num_flushes));
43370 seq_printf(m, "\nLocks: %d HardLinks: %d "
43371 "Symlinks: %d",
43372- atomic_read(&tcon->num_locks),
43373- atomic_read(&tcon->num_hardlinks),
43374- atomic_read(&tcon->num_symlinks));
43375+ atomic_read_unchecked(&tcon->num_locks),
43376+ atomic_read_unchecked(&tcon->num_hardlinks),
43377+ atomic_read_unchecked(&tcon->num_symlinks));
43378 seq_printf(m, "\nOpens: %d Closes: %d "
43379 "Deletes: %d",
43380- atomic_read(&tcon->num_opens),
43381- atomic_read(&tcon->num_closes),
43382- atomic_read(&tcon->num_deletes));
43383+ atomic_read_unchecked(&tcon->num_opens),
43384+ atomic_read_unchecked(&tcon->num_closes),
43385+ atomic_read_unchecked(&tcon->num_deletes));
43386 seq_printf(m, "\nPosix Opens: %d "
43387 "Posix Mkdirs: %d",
43388- atomic_read(&tcon->num_posixopens),
43389- atomic_read(&tcon->num_posixmkdirs));
43390+ atomic_read_unchecked(&tcon->num_posixopens),
43391+ atomic_read_unchecked(&tcon->num_posixmkdirs));
43392 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43393- atomic_read(&tcon->num_mkdirs),
43394- atomic_read(&tcon->num_rmdirs));
43395+ atomic_read_unchecked(&tcon->num_mkdirs),
43396+ atomic_read_unchecked(&tcon->num_rmdirs));
43397 seq_printf(m, "\nRenames: %d T2 Renames %d",
43398- atomic_read(&tcon->num_renames),
43399- atomic_read(&tcon->num_t2renames));
43400+ atomic_read_unchecked(&tcon->num_renames),
43401+ atomic_read_unchecked(&tcon->num_t2renames));
43402 seq_printf(m, "\nFindFirst: %d FNext %d "
43403 "FClose %d",
43404- atomic_read(&tcon->num_ffirst),
43405- atomic_read(&tcon->num_fnext),
43406- atomic_read(&tcon->num_fclose));
43407+ atomic_read_unchecked(&tcon->num_ffirst),
43408+ atomic_read_unchecked(&tcon->num_fnext),
43409+ atomic_read_unchecked(&tcon->num_fclose));
43410 }
43411 }
43412 }
43413diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43414index 70dd381..b8ce03b 100644
43415--- a/fs/cifs/cifsfs.c
43416+++ b/fs/cifs/cifsfs.c
43417@@ -989,7 +989,7 @@ cifs_init_request_bufs(void)
43418 cifs_req_cachep = kmem_cache_create("cifs_request",
43419 CIFSMaxBufSize +
43420 MAX_CIFS_HDR_SIZE, 0,
43421- SLAB_HWCACHE_ALIGN, NULL);
43422+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43423 if (cifs_req_cachep == NULL)
43424 return -ENOMEM;
43425
43426@@ -1016,7 +1016,7 @@ cifs_init_request_bufs(void)
43427 efficient to alloc 1 per page off the slab compared to 17K (5page)
43428 alloc of large cifs buffers even when page debugging is on */
43429 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43430- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43431+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43432 NULL);
43433 if (cifs_sm_req_cachep == NULL) {
43434 mempool_destroy(cifs_req_poolp);
43435@@ -1101,8 +1101,8 @@ init_cifs(void)
43436 atomic_set(&bufAllocCount, 0);
43437 atomic_set(&smBufAllocCount, 0);
43438 #ifdef CONFIG_CIFS_STATS2
43439- atomic_set(&totBufAllocCount, 0);
43440- atomic_set(&totSmBufAllocCount, 0);
43441+ atomic_set_unchecked(&totBufAllocCount, 0);
43442+ atomic_set_unchecked(&totSmBufAllocCount, 0);
43443 #endif /* CONFIG_CIFS_STATS2 */
43444
43445 atomic_set(&midCount, 0);
43446diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43447index d47d20a..77e8b33 100644
43448--- a/fs/cifs/cifsglob.h
43449+++ b/fs/cifs/cifsglob.h
43450@@ -388,28 +388,28 @@ struct cifs_tcon {
43451 __u16 Flags; /* optional support bits */
43452 enum statusEnum tidStatus;
43453 #ifdef CONFIG_CIFS_STATS
43454- atomic_t num_smbs_sent;
43455- atomic_t num_writes;
43456- atomic_t num_reads;
43457- atomic_t num_flushes;
43458- atomic_t num_oplock_brks;
43459- atomic_t num_opens;
43460- atomic_t num_closes;
43461- atomic_t num_deletes;
43462- atomic_t num_mkdirs;
43463- atomic_t num_posixopens;
43464- atomic_t num_posixmkdirs;
43465- atomic_t num_rmdirs;
43466- atomic_t num_renames;
43467- atomic_t num_t2renames;
43468- atomic_t num_ffirst;
43469- atomic_t num_fnext;
43470- atomic_t num_fclose;
43471- atomic_t num_hardlinks;
43472- atomic_t num_symlinks;
43473- atomic_t num_locks;
43474- atomic_t num_acl_get;
43475- atomic_t num_acl_set;
43476+ atomic_unchecked_t num_smbs_sent;
43477+ atomic_unchecked_t num_writes;
43478+ atomic_unchecked_t num_reads;
43479+ atomic_unchecked_t num_flushes;
43480+ atomic_unchecked_t num_oplock_brks;
43481+ atomic_unchecked_t num_opens;
43482+ atomic_unchecked_t num_closes;
43483+ atomic_unchecked_t num_deletes;
43484+ atomic_unchecked_t num_mkdirs;
43485+ atomic_unchecked_t num_posixopens;
43486+ atomic_unchecked_t num_posixmkdirs;
43487+ atomic_unchecked_t num_rmdirs;
43488+ atomic_unchecked_t num_renames;
43489+ atomic_unchecked_t num_t2renames;
43490+ atomic_unchecked_t num_ffirst;
43491+ atomic_unchecked_t num_fnext;
43492+ atomic_unchecked_t num_fclose;
43493+ atomic_unchecked_t num_hardlinks;
43494+ atomic_unchecked_t num_symlinks;
43495+ atomic_unchecked_t num_locks;
43496+ atomic_unchecked_t num_acl_get;
43497+ atomic_unchecked_t num_acl_set;
43498 #ifdef CONFIG_CIFS_STATS2
43499 unsigned long long time_writes;
43500 unsigned long long time_reads;
43501@@ -624,7 +624,7 @@ convert_delimiter(char *path, char delim)
43502 }
43503
43504 #ifdef CONFIG_CIFS_STATS
43505-#define cifs_stats_inc atomic_inc
43506+#define cifs_stats_inc atomic_inc_unchecked
43507
43508 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43509 unsigned int bytes)
43510@@ -983,8 +983,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43511 /* Various Debug counters */
43512 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43513 #ifdef CONFIG_CIFS_STATS2
43514-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43515-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43516+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43517+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43518 #endif
43519 GLOBAL_EXTERN atomic_t smBufAllocCount;
43520 GLOBAL_EXTERN atomic_t midCount;
43521diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43522index 6b0e064..94e6c3c 100644
43523--- a/fs/cifs/link.c
43524+++ b/fs/cifs/link.c
43525@@ -600,7 +600,7 @@ symlink_exit:
43526
43527 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43528 {
43529- char *p = nd_get_link(nd);
43530+ const char *p = nd_get_link(nd);
43531 if (!IS_ERR(p))
43532 kfree(p);
43533 }
43534diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43535index 703ef5c..2a44ed5 100644
43536--- a/fs/cifs/misc.c
43537+++ b/fs/cifs/misc.c
43538@@ -156,7 +156,7 @@ cifs_buf_get(void)
43539 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43540 atomic_inc(&bufAllocCount);
43541 #ifdef CONFIG_CIFS_STATS2
43542- atomic_inc(&totBufAllocCount);
43543+ atomic_inc_unchecked(&totBufAllocCount);
43544 #endif /* CONFIG_CIFS_STATS2 */
43545 }
43546
43547@@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43548 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43549 atomic_inc(&smBufAllocCount);
43550 #ifdef CONFIG_CIFS_STATS2
43551- atomic_inc(&totSmBufAllocCount);
43552+ atomic_inc_unchecked(&totSmBufAllocCount);
43553 #endif /* CONFIG_CIFS_STATS2 */
43554
43555 }
43556diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43557index 6901578..d402eb5 100644
43558--- a/fs/coda/cache.c
43559+++ b/fs/coda/cache.c
43560@@ -24,7 +24,7 @@
43561 #include "coda_linux.h"
43562 #include "coda_cache.h"
43563
43564-static atomic_t permission_epoch = ATOMIC_INIT(0);
43565+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43566
43567 /* replace or extend an acl cache hit */
43568 void coda_cache_enter(struct inode *inode, int mask)
43569@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43570 struct coda_inode_info *cii = ITOC(inode);
43571
43572 spin_lock(&cii->c_lock);
43573- cii->c_cached_epoch = atomic_read(&permission_epoch);
43574+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43575 if (cii->c_uid != current_fsuid()) {
43576 cii->c_uid = current_fsuid();
43577 cii->c_cached_perm = mask;
43578@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43579 {
43580 struct coda_inode_info *cii = ITOC(inode);
43581 spin_lock(&cii->c_lock);
43582- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43583+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43584 spin_unlock(&cii->c_lock);
43585 }
43586
43587 /* remove all acl caches */
43588 void coda_cache_clear_all(struct super_block *sb)
43589 {
43590- atomic_inc(&permission_epoch);
43591+ atomic_inc_unchecked(&permission_epoch);
43592 }
43593
43594
43595@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43596 spin_lock(&cii->c_lock);
43597 hit = (mask & cii->c_cached_perm) == mask &&
43598 cii->c_uid == current_fsuid() &&
43599- cii->c_cached_epoch == atomic_read(&permission_epoch);
43600+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43601 spin_unlock(&cii->c_lock);
43602
43603 return hit;
43604diff --git a/fs/compat.c b/fs/compat.c
43605index 07880ba..3fb2862 100644
43606--- a/fs/compat.c
43607+++ b/fs/compat.c
43608@@ -491,7 +491,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43609
43610 set_fs(KERNEL_DS);
43611 /* The __user pointer cast is valid because of the set_fs() */
43612- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43613+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43614 set_fs(oldfs);
43615 /* truncating is ok because it's a user address */
43616 if (!ret)
43617@@ -549,7 +549,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43618 goto out;
43619
43620 ret = -EINVAL;
43621- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43622+ if (nr_segs > UIO_MAXIOV)
43623 goto out;
43624 if (nr_segs > fast_segs) {
43625 ret = -ENOMEM;
43626@@ -832,6 +832,7 @@ struct compat_old_linux_dirent {
43627
43628 struct compat_readdir_callback {
43629 struct compat_old_linux_dirent __user *dirent;
43630+ struct file * file;
43631 int result;
43632 };
43633
43634@@ -849,6 +850,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43635 buf->result = -EOVERFLOW;
43636 return -EOVERFLOW;
43637 }
43638+
43639+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43640+ return 0;
43641+
43642 buf->result++;
43643 dirent = buf->dirent;
43644 if (!access_ok(VERIFY_WRITE, dirent,
43645@@ -881,6 +886,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43646
43647 buf.result = 0;
43648 buf.dirent = dirent;
43649+ buf.file = file;
43650
43651 error = vfs_readdir(file, compat_fillonedir, &buf);
43652 if (buf.result)
43653@@ -901,6 +907,7 @@ struct compat_linux_dirent {
43654 struct compat_getdents_callback {
43655 struct compat_linux_dirent __user *current_dir;
43656 struct compat_linux_dirent __user *previous;
43657+ struct file * file;
43658 int count;
43659 int error;
43660 };
43661@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43662 buf->error = -EOVERFLOW;
43663 return -EOVERFLOW;
43664 }
43665+
43666+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43667+ return 0;
43668+
43669 dirent = buf->previous;
43670 if (dirent) {
43671 if (__put_user(offset, &dirent->d_off))
43672@@ -969,6 +980,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43673 buf.previous = NULL;
43674 buf.count = count;
43675 buf.error = 0;
43676+ buf.file = file;
43677
43678 error = vfs_readdir(file, compat_filldir, &buf);
43679 if (error >= 0)
43680@@ -990,6 +1002,7 @@ out:
43681 struct compat_getdents_callback64 {
43682 struct linux_dirent64 __user *current_dir;
43683 struct linux_dirent64 __user *previous;
43684+ struct file * file;
43685 int count;
43686 int error;
43687 };
43688@@ -1006,6 +1019,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43689 buf->error = -EINVAL; /* only used if we fail.. */
43690 if (reclen > buf->count)
43691 return -EINVAL;
43692+
43693+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43694+ return 0;
43695+
43696 dirent = buf->previous;
43697
43698 if (dirent) {
43699@@ -1057,13 +1074,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43700 buf.previous = NULL;
43701 buf.count = count;
43702 buf.error = 0;
43703+ buf.file = file;
43704
43705 error = vfs_readdir(file, compat_filldir64, &buf);
43706 if (error >= 0)
43707 error = buf.error;
43708 lastdirent = buf.previous;
43709 if (lastdirent) {
43710- typeof(lastdirent->d_off) d_off = file->f_pos;
43711+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43712 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43713 error = -EFAULT;
43714 else
43715diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
43716index 112e45a..b59845b 100644
43717--- a/fs/compat_binfmt_elf.c
43718+++ b/fs/compat_binfmt_elf.c
43719@@ -30,11 +30,13 @@
43720 #undef elf_phdr
43721 #undef elf_shdr
43722 #undef elf_note
43723+#undef elf_dyn
43724 #undef elf_addr_t
43725 #define elfhdr elf32_hdr
43726 #define elf_phdr elf32_phdr
43727 #define elf_shdr elf32_shdr
43728 #define elf_note elf32_note
43729+#define elf_dyn Elf32_Dyn
43730 #define elf_addr_t Elf32_Addr
43731
43732 /*
43733diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
43734index a26bea1..ae23e72 100644
43735--- a/fs/compat_ioctl.c
43736+++ b/fs/compat_ioctl.c
43737@@ -211,6 +211,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
43738
43739 err = get_user(palp, &up->palette);
43740 err |= get_user(length, &up->length);
43741+ if (err)
43742+ return -EFAULT;
43743
43744 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
43745 err = put_user(compat_ptr(palp), &up_native->palette);
43746@@ -622,7 +624,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
43747 return -EFAULT;
43748 if (__get_user(udata, &ss32->iomem_base))
43749 return -EFAULT;
43750- ss.iomem_base = compat_ptr(udata);
43751+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
43752 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
43753 __get_user(ss.port_high, &ss32->port_high))
43754 return -EFAULT;
43755@@ -797,7 +799,7 @@ static int compat_ioctl_preallocate(struct file *file,
43756 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
43757 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
43758 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
43759- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43760+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43761 return -EFAULT;
43762
43763 return ioctl_preallocate(file, p);
43764@@ -1611,8 +1613,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
43765 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
43766 {
43767 unsigned int a, b;
43768- a = *(unsigned int *)p;
43769- b = *(unsigned int *)q;
43770+ a = *(const unsigned int *)p;
43771+ b = *(const unsigned int *)q;
43772 if (a > b)
43773 return 1;
43774 if (a < b)
43775diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
43776index 5ddd7eb..c18bf04 100644
43777--- a/fs/configfs/dir.c
43778+++ b/fs/configfs/dir.c
43779@@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43780 }
43781 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
43782 struct configfs_dirent *next;
43783- const char * name;
43784+ const unsigned char * name;
43785+ char d_name[sizeof(next->s_dentry->d_iname)];
43786 int len;
43787 struct inode *inode = NULL;
43788
43789@@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43790 continue;
43791
43792 name = configfs_get_name(next);
43793- len = strlen(name);
43794+ if (next->s_dentry && name == next->s_dentry->d_iname) {
43795+ len = next->s_dentry->d_name.len;
43796+ memcpy(d_name, name, len);
43797+ name = d_name;
43798+ } else
43799+ len = strlen(name);
43800
43801 /*
43802 * We'll have a dentry and an inode for
43803diff --git a/fs/dcache.c b/fs/dcache.c
43804index 2576d14..0cec38d 100644
43805--- a/fs/dcache.c
43806+++ b/fs/dcache.c
43807@@ -105,10 +105,10 @@ static unsigned int d_hash_shift __read_mostly;
43808 static struct hlist_bl_head *dentry_hashtable __read_mostly;
43809
43810 static inline struct hlist_bl_head *d_hash(const struct dentry *parent,
43811- unsigned long hash)
43812+ unsigned int hash)
43813 {
43814- hash += ((unsigned long) parent ^ GOLDEN_RATIO_PRIME) / L1_CACHE_BYTES;
43815- hash = hash ^ ((hash ^ GOLDEN_RATIO_PRIME) >> D_HASHBITS);
43816+ hash += (unsigned long) parent / L1_CACHE_BYTES;
43817+ hash = hash + (hash >> D_HASHBITS);
43818 return dentry_hashtable + (hash & D_HASHMASK);
43819 }
43820
43821@@ -3067,7 +3067,7 @@ void __init vfs_caches_init(unsigned long mempages)
43822 mempages -= reserve;
43823
43824 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
43825- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
43826+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
43827
43828 dcache_init();
43829 inode_init();
43830diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
43831index 956d5dd..e755e04 100644
43832--- a/fs/debugfs/inode.c
43833+++ b/fs/debugfs/inode.c
43834@@ -261,7 +261,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
43835 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
43836 {
43837 return debugfs_create_file(name,
43838+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
43839+ S_IFDIR | S_IRWXU,
43840+#else
43841 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
43842+#endif
43843 parent, NULL, NULL);
43844 }
43845 EXPORT_SYMBOL_GPL(debugfs_create_dir);
43846diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
43847index ab35b11..b30af66 100644
43848--- a/fs/ecryptfs/inode.c
43849+++ b/fs/ecryptfs/inode.c
43850@@ -672,7 +672,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
43851 old_fs = get_fs();
43852 set_fs(get_ds());
43853 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
43854- (char __user *)lower_buf,
43855+ (char __force_user *)lower_buf,
43856 lower_bufsiz);
43857 set_fs(old_fs);
43858 if (rc < 0)
43859@@ -718,7 +718,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
43860 }
43861 old_fs = get_fs();
43862 set_fs(get_ds());
43863- rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
43864+ rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
43865 set_fs(old_fs);
43866 if (rc < 0) {
43867 kfree(buf);
43868@@ -733,7 +733,7 @@ out:
43869 static void
43870 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
43871 {
43872- char *buf = nd_get_link(nd);
43873+ const char *buf = nd_get_link(nd);
43874 if (!IS_ERR(buf)) {
43875 /* Free the char* */
43876 kfree(buf);
43877diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
43878index 3a06f40..f7af544 100644
43879--- a/fs/ecryptfs/miscdev.c
43880+++ b/fs/ecryptfs/miscdev.c
43881@@ -345,7 +345,7 @@ check_list:
43882 goto out_unlock_msg_ctx;
43883 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
43884 if (msg_ctx->msg) {
43885- if (copy_to_user(&buf[i], packet_length, packet_length_size))
43886+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
43887 goto out_unlock_msg_ctx;
43888 i += packet_length_size;
43889 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
43890diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
43891index b2a34a1..162fa69 100644
43892--- a/fs/ecryptfs/read_write.c
43893+++ b/fs/ecryptfs/read_write.c
43894@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
43895 return -EIO;
43896 fs_save = get_fs();
43897 set_fs(get_ds());
43898- rc = vfs_write(lower_file, data, size, &offset);
43899+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
43900 set_fs(fs_save);
43901 mark_inode_dirty_sync(ecryptfs_inode);
43902 return rc;
43903@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
43904 return -EIO;
43905 fs_save = get_fs();
43906 set_fs(get_ds());
43907- rc = vfs_read(lower_file, data, size, &offset);
43908+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
43909 set_fs(fs_save);
43910 return rc;
43911 }
43912diff --git a/fs/exec.c b/fs/exec.c
43913index ae42277..32c9035 100644
43914--- a/fs/exec.c
43915+++ b/fs/exec.c
43916@@ -55,6 +55,13 @@
43917 #include <linux/pipe_fs_i.h>
43918 #include <linux/oom.h>
43919 #include <linux/compat.h>
43920+#include <linux/random.h>
43921+#include <linux/seq_file.h>
43922+
43923+#ifdef CONFIG_PAX_REFCOUNT
43924+#include <linux/kallsyms.h>
43925+#include <linux/kdebug.h>
43926+#endif
43927
43928 #include <asm/uaccess.h>
43929 #include <asm/mmu_context.h>
43930@@ -63,6 +70,15 @@
43931 #include <trace/events/task.h>
43932 #include "internal.h"
43933
43934+#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
43935+void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
43936+#endif
43937+
43938+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
43939+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
43940+EXPORT_SYMBOL(pax_set_initial_flags_func);
43941+#endif
43942+
43943 int core_uses_pid;
43944 char core_pattern[CORENAME_MAX_SIZE] = "core";
43945 unsigned int core_pipe_limit;
43946@@ -72,7 +88,7 @@ struct core_name {
43947 char *corename;
43948 int used, size;
43949 };
43950-static atomic_t call_count = ATOMIC_INIT(1);
43951+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
43952
43953 /* The maximal length of core_pattern is also specified in sysctl.c */
43954
43955@@ -190,18 +206,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43956 int write)
43957 {
43958 struct page *page;
43959- int ret;
43960
43961-#ifdef CONFIG_STACK_GROWSUP
43962- if (write) {
43963- ret = expand_downwards(bprm->vma, pos);
43964- if (ret < 0)
43965- return NULL;
43966- }
43967-#endif
43968- ret = get_user_pages(current, bprm->mm, pos,
43969- 1, write, 1, &page, NULL);
43970- if (ret <= 0)
43971+ if (0 > expand_downwards(bprm->vma, pos))
43972+ return NULL;
43973+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
43974 return NULL;
43975
43976 if (write) {
43977@@ -217,6 +225,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43978 if (size <= ARG_MAX)
43979 return page;
43980
43981+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43982+ // only allow 512KB for argv+env on suid/sgid binaries
43983+ // to prevent easy ASLR exhaustion
43984+ if (((bprm->cred->euid != current_euid()) ||
43985+ (bprm->cred->egid != current_egid())) &&
43986+ (size > (512 * 1024))) {
43987+ put_page(page);
43988+ return NULL;
43989+ }
43990+#endif
43991+
43992 /*
43993 * Limit to 1/4-th the stack size for the argv+env strings.
43994 * This ensures that:
43995@@ -276,6 +295,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
43996 vma->vm_end = STACK_TOP_MAX;
43997 vma->vm_start = vma->vm_end - PAGE_SIZE;
43998 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
43999+
44000+#ifdef CONFIG_PAX_SEGMEXEC
44001+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44002+#endif
44003+
44004 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44005 INIT_LIST_HEAD(&vma->anon_vma_chain);
44006
44007@@ -290,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44008 mm->stack_vm = mm->total_vm = 1;
44009 up_write(&mm->mmap_sem);
44010 bprm->p = vma->vm_end - sizeof(void *);
44011+
44012+#ifdef CONFIG_PAX_RANDUSTACK
44013+ if (randomize_va_space)
44014+ bprm->p ^= random32() & ~PAGE_MASK;
44015+#endif
44016+
44017 return 0;
44018 err:
44019 up_write(&mm->mmap_sem);
44020@@ -398,19 +428,7 @@ err:
44021 return err;
44022 }
44023
44024-struct user_arg_ptr {
44025-#ifdef CONFIG_COMPAT
44026- bool is_compat;
44027-#endif
44028- union {
44029- const char __user *const __user *native;
44030-#ifdef CONFIG_COMPAT
44031- compat_uptr_t __user *compat;
44032-#endif
44033- } ptr;
44034-};
44035-
44036-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44037+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44038 {
44039 const char __user *native;
44040
44041@@ -419,14 +437,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44042 compat_uptr_t compat;
44043
44044 if (get_user(compat, argv.ptr.compat + nr))
44045- return ERR_PTR(-EFAULT);
44046+ return (const char __force_user *)ERR_PTR(-EFAULT);
44047
44048 return compat_ptr(compat);
44049 }
44050 #endif
44051
44052 if (get_user(native, argv.ptr.native + nr))
44053- return ERR_PTR(-EFAULT);
44054+ return (const char __force_user *)ERR_PTR(-EFAULT);
44055
44056 return native;
44057 }
44058@@ -445,7 +463,7 @@ static int count(struct user_arg_ptr argv, int max)
44059 if (!p)
44060 break;
44061
44062- if (IS_ERR(p))
44063+ if (IS_ERR((const char __force_kernel *)p))
44064 return -EFAULT;
44065
44066 if (i++ >= max)
44067@@ -479,7 +497,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44068
44069 ret = -EFAULT;
44070 str = get_user_arg_ptr(argv, argc);
44071- if (IS_ERR(str))
44072+ if (IS_ERR((const char __force_kernel *)str))
44073 goto out;
44074
44075 len = strnlen_user(str, MAX_ARG_STRLEN);
44076@@ -561,7 +579,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44077 int r;
44078 mm_segment_t oldfs = get_fs();
44079 struct user_arg_ptr argv = {
44080- .ptr.native = (const char __user *const __user *)__argv,
44081+ .ptr.native = (const char __force_user *const __force_user *)__argv,
44082 };
44083
44084 set_fs(KERNEL_DS);
44085@@ -596,7 +614,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44086 unsigned long new_end = old_end - shift;
44087 struct mmu_gather tlb;
44088
44089- BUG_ON(new_start > new_end);
44090+ if (new_start >= new_end || new_start < mmap_min_addr)
44091+ return -ENOMEM;
44092
44093 /*
44094 * ensure there are no vmas between where we want to go
44095@@ -605,6 +624,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44096 if (vma != find_vma(mm, new_start))
44097 return -EFAULT;
44098
44099+#ifdef CONFIG_PAX_SEGMEXEC
44100+ BUG_ON(pax_find_mirror_vma(vma));
44101+#endif
44102+
44103 /*
44104 * cover the whole range: [new_start, old_end)
44105 */
44106@@ -685,10 +708,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44107 stack_top = arch_align_stack(stack_top);
44108 stack_top = PAGE_ALIGN(stack_top);
44109
44110- if (unlikely(stack_top < mmap_min_addr) ||
44111- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44112- return -ENOMEM;
44113-
44114 stack_shift = vma->vm_end - stack_top;
44115
44116 bprm->p -= stack_shift;
44117@@ -700,8 +719,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44118 bprm->exec -= stack_shift;
44119
44120 down_write(&mm->mmap_sem);
44121+
44122+ /* Move stack pages down in memory. */
44123+ if (stack_shift) {
44124+ ret = shift_arg_pages(vma, stack_shift);
44125+ if (ret)
44126+ goto out_unlock;
44127+ }
44128+
44129 vm_flags = VM_STACK_FLAGS;
44130
44131+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44132+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44133+ vm_flags &= ~VM_EXEC;
44134+
44135+#ifdef CONFIG_PAX_MPROTECT
44136+ if (mm->pax_flags & MF_PAX_MPROTECT)
44137+ vm_flags &= ~VM_MAYEXEC;
44138+#endif
44139+
44140+ }
44141+#endif
44142+
44143 /*
44144 * Adjust stack execute permissions; explicitly enable for
44145 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44146@@ -720,13 +759,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44147 goto out_unlock;
44148 BUG_ON(prev != vma);
44149
44150- /* Move stack pages down in memory. */
44151- if (stack_shift) {
44152- ret = shift_arg_pages(vma, stack_shift);
44153- if (ret)
44154- goto out_unlock;
44155- }
44156-
44157 /* mprotect_fixup is overkill to remove the temporary stack flags */
44158 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44159
44160@@ -807,7 +839,7 @@ int kernel_read(struct file *file, loff_t offset,
44161 old_fs = get_fs();
44162 set_fs(get_ds());
44163 /* The cast to a user pointer is valid due to the set_fs() */
44164- result = vfs_read(file, (void __user *)addr, count, &pos);
44165+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
44166 set_fs(old_fs);
44167 return result;
44168 }
44169@@ -1255,7 +1287,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
44170 }
44171 rcu_read_unlock();
44172
44173- if (p->fs->users > n_fs) {
44174+ if (atomic_read(&p->fs->users) > n_fs) {
44175 bprm->unsafe |= LSM_UNSAFE_SHARE;
44176 } else {
44177 res = -EAGAIN;
44178@@ -1450,6 +1482,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
44179
44180 EXPORT_SYMBOL(search_binary_handler);
44181
44182+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44183+static DEFINE_PER_CPU(u64, exec_counter);
44184+static int __init init_exec_counters(void)
44185+{
44186+ unsigned int cpu;
44187+
44188+ for_each_possible_cpu(cpu) {
44189+ per_cpu(exec_counter, cpu) = (u64)cpu;
44190+ }
44191+
44192+ return 0;
44193+}
44194+early_initcall(init_exec_counters);
44195+static inline void increment_exec_counter(void)
44196+{
44197+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
44198+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
44199+}
44200+#else
44201+static inline void increment_exec_counter(void) {}
44202+#endif
44203+
44204 /*
44205 * sys_execve() executes a new program.
44206 */
44207@@ -1458,6 +1512,11 @@ static int do_execve_common(const char *filename,
44208 struct user_arg_ptr envp,
44209 struct pt_regs *regs)
44210 {
44211+#ifdef CONFIG_GRKERNSEC
44212+ struct file *old_exec_file;
44213+ struct acl_subject_label *old_acl;
44214+ struct rlimit old_rlim[RLIM_NLIMITS];
44215+#endif
44216 struct linux_binprm *bprm;
44217 struct file *file;
44218 struct files_struct *displaced;
44219@@ -1465,6 +1524,8 @@ static int do_execve_common(const char *filename,
44220 int retval;
44221 const struct cred *cred = current_cred();
44222
44223+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44224+
44225 /*
44226 * We move the actual failure in case of RLIMIT_NPROC excess from
44227 * set*uid() to execve() because too many poorly written programs
44228@@ -1505,12 +1566,27 @@ static int do_execve_common(const char *filename,
44229 if (IS_ERR(file))
44230 goto out_unmark;
44231
44232+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
44233+ retval = -EPERM;
44234+ goto out_file;
44235+ }
44236+
44237 sched_exec();
44238
44239 bprm->file = file;
44240 bprm->filename = filename;
44241 bprm->interp = filename;
44242
44243+ if (gr_process_user_ban()) {
44244+ retval = -EPERM;
44245+ goto out_file;
44246+ }
44247+
44248+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44249+ retval = -EACCES;
44250+ goto out_file;
44251+ }
44252+
44253 retval = bprm_mm_init(bprm);
44254 if (retval)
44255 goto out_file;
44256@@ -1527,24 +1603,65 @@ static int do_execve_common(const char *filename,
44257 if (retval < 0)
44258 goto out;
44259
44260+#ifdef CONFIG_GRKERNSEC
44261+ old_acl = current->acl;
44262+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44263+ old_exec_file = current->exec_file;
44264+ get_file(file);
44265+ current->exec_file = file;
44266+#endif
44267+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44268+ /* limit suid stack to 8MB
44269+ we saved the old limits above and will restore them if this exec fails
44270+ */
44271+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
44272+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
44273+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
44274+#endif
44275+
44276+ if (!gr_tpe_allow(file)) {
44277+ retval = -EACCES;
44278+ goto out_fail;
44279+ }
44280+
44281+ if (gr_check_crash_exec(file)) {
44282+ retval = -EACCES;
44283+ goto out_fail;
44284+ }
44285+
44286+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44287+ bprm->unsafe);
44288+ if (retval < 0)
44289+ goto out_fail;
44290+
44291 retval = copy_strings_kernel(1, &bprm->filename, bprm);
44292 if (retval < 0)
44293- goto out;
44294+ goto out_fail;
44295
44296 bprm->exec = bprm->p;
44297 retval = copy_strings(bprm->envc, envp, bprm);
44298 if (retval < 0)
44299- goto out;
44300+ goto out_fail;
44301
44302 retval = copy_strings(bprm->argc, argv, bprm);
44303 if (retval < 0)
44304- goto out;
44305+ goto out_fail;
44306+
44307+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44308+
44309+ gr_handle_exec_args(bprm, argv);
44310
44311 retval = search_binary_handler(bprm,regs);
44312 if (retval < 0)
44313- goto out;
44314+ goto out_fail;
44315+#ifdef CONFIG_GRKERNSEC
44316+ if (old_exec_file)
44317+ fput(old_exec_file);
44318+#endif
44319
44320 /* execve succeeded */
44321+
44322+ increment_exec_counter();
44323 current->fs->in_exec = 0;
44324 current->in_execve = 0;
44325 acct_update_integrals(current);
44326@@ -1553,6 +1670,14 @@ static int do_execve_common(const char *filename,
44327 put_files_struct(displaced);
44328 return retval;
44329
44330+out_fail:
44331+#ifdef CONFIG_GRKERNSEC
44332+ current->acl = old_acl;
44333+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44334+ fput(current->exec_file);
44335+ current->exec_file = old_exec_file;
44336+#endif
44337+
44338 out:
44339 if (bprm->mm) {
44340 acct_arg_size(bprm, 0);
44341@@ -1626,7 +1751,7 @@ static int expand_corename(struct core_name *cn)
44342 {
44343 char *old_corename = cn->corename;
44344
44345- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44346+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44347 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44348
44349 if (!cn->corename) {
44350@@ -1723,7 +1848,7 @@ static int format_corename(struct core_name *cn, long signr)
44351 int pid_in_pattern = 0;
44352 int err = 0;
44353
44354- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44355+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44356 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44357 cn->used = 0;
44358
44359@@ -1820,6 +1945,228 @@ out:
44360 return ispipe;
44361 }
44362
44363+int pax_check_flags(unsigned long *flags)
44364+{
44365+ int retval = 0;
44366+
44367+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44368+ if (*flags & MF_PAX_SEGMEXEC)
44369+ {
44370+ *flags &= ~MF_PAX_SEGMEXEC;
44371+ retval = -EINVAL;
44372+ }
44373+#endif
44374+
44375+ if ((*flags & MF_PAX_PAGEEXEC)
44376+
44377+#ifdef CONFIG_PAX_PAGEEXEC
44378+ && (*flags & MF_PAX_SEGMEXEC)
44379+#endif
44380+
44381+ )
44382+ {
44383+ *flags &= ~MF_PAX_PAGEEXEC;
44384+ retval = -EINVAL;
44385+ }
44386+
44387+ if ((*flags & MF_PAX_MPROTECT)
44388+
44389+#ifdef CONFIG_PAX_MPROTECT
44390+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44391+#endif
44392+
44393+ )
44394+ {
44395+ *flags &= ~MF_PAX_MPROTECT;
44396+ retval = -EINVAL;
44397+ }
44398+
44399+ if ((*flags & MF_PAX_EMUTRAMP)
44400+
44401+#ifdef CONFIG_PAX_EMUTRAMP
44402+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44403+#endif
44404+
44405+ )
44406+ {
44407+ *flags &= ~MF_PAX_EMUTRAMP;
44408+ retval = -EINVAL;
44409+ }
44410+
44411+ return retval;
44412+}
44413+
44414+EXPORT_SYMBOL(pax_check_flags);
44415+
44416+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44417+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44418+{
44419+ struct task_struct *tsk = current;
44420+ struct mm_struct *mm = current->mm;
44421+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44422+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44423+ char *path_exec = NULL;
44424+ char *path_fault = NULL;
44425+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
44426+
44427+ if (buffer_exec && buffer_fault) {
44428+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44429+
44430+ down_read(&mm->mmap_sem);
44431+ vma = mm->mmap;
44432+ while (vma && (!vma_exec || !vma_fault)) {
44433+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44434+ vma_exec = vma;
44435+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44436+ vma_fault = vma;
44437+ vma = vma->vm_next;
44438+ }
44439+ if (vma_exec) {
44440+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44441+ if (IS_ERR(path_exec))
44442+ path_exec = "<path too long>";
44443+ else {
44444+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44445+ if (path_exec) {
44446+ *path_exec = 0;
44447+ path_exec = buffer_exec;
44448+ } else
44449+ path_exec = "<path too long>";
44450+ }
44451+ }
44452+ if (vma_fault) {
44453+ start = vma_fault->vm_start;
44454+ end = vma_fault->vm_end;
44455+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44456+ if (vma_fault->vm_file) {
44457+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44458+ if (IS_ERR(path_fault))
44459+ path_fault = "<path too long>";
44460+ else {
44461+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44462+ if (path_fault) {
44463+ *path_fault = 0;
44464+ path_fault = buffer_fault;
44465+ } else
44466+ path_fault = "<path too long>";
44467+ }
44468+ } else
44469+ path_fault = "<anonymous mapping>";
44470+ }
44471+ up_read(&mm->mmap_sem);
44472+ }
44473+ if (tsk->signal->curr_ip)
44474+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44475+ else
44476+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44477+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44478+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44479+ task_uid(tsk), task_euid(tsk), pc, sp);
44480+ free_page((unsigned long)buffer_exec);
44481+ free_page((unsigned long)buffer_fault);
44482+ pax_report_insns(regs, pc, sp);
44483+ do_coredump(SIGKILL, SIGKILL, regs);
44484+}
44485+#endif
44486+
44487+#ifdef CONFIG_PAX_REFCOUNT
44488+void pax_report_refcount_overflow(struct pt_regs *regs)
44489+{
44490+ if (current->signal->curr_ip)
44491+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44492+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44493+ else
44494+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44495+ current->comm, task_pid_nr(current), current_uid(), current_euid());
44496+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44497+ show_regs(regs);
44498+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44499+}
44500+#endif
44501+
44502+#ifdef CONFIG_PAX_USERCOPY
44503+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44504+int object_is_on_stack(const void *obj, unsigned long len)
44505+{
44506+ const void * const stack = task_stack_page(current);
44507+ const void * const stackend = stack + THREAD_SIZE;
44508+
44509+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44510+ const void *frame = NULL;
44511+ const void *oldframe;
44512+#endif
44513+
44514+ if (obj + len < obj)
44515+ return -1;
44516+
44517+ if (obj + len <= stack || stackend <= obj)
44518+ return 0;
44519+
44520+ if (obj < stack || stackend < obj + len)
44521+ return -1;
44522+
44523+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44524+ oldframe = __builtin_frame_address(1);
44525+ if (oldframe)
44526+ frame = __builtin_frame_address(2);
44527+ /*
44528+ low ----------------------------------------------> high
44529+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
44530+ ^----------------^
44531+ allow copies only within here
44532+ */
44533+ while (stack <= frame && frame < stackend) {
44534+ /* if obj + len extends past the last frame, this
44535+ check won't pass and the next frame will be 0,
44536+ causing us to bail out and correctly report
44537+ the copy as invalid
44538+ */
44539+ if (obj + len <= frame)
44540+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44541+ oldframe = frame;
44542+ frame = *(const void * const *)frame;
44543+ }
44544+ return -1;
44545+#else
44546+ return 1;
44547+#endif
44548+}
44549+
44550+__noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44551+{
44552+ if (current->signal->curr_ip)
44553+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44554+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44555+ else
44556+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44557+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44558+ dump_stack();
44559+ gr_handle_kernel_exploit();
44560+ do_group_exit(SIGKILL);
44561+}
44562+#endif
44563+
44564+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44565+void pax_track_stack(void)
44566+{
44567+ unsigned long sp = (unsigned long)&sp;
44568+ if (sp < current_thread_info()->lowest_stack &&
44569+ sp > (unsigned long)task_stack_page(current))
44570+ current_thread_info()->lowest_stack = sp;
44571+}
44572+EXPORT_SYMBOL(pax_track_stack);
44573+#endif
44574+
44575+#ifdef CONFIG_PAX_SIZE_OVERFLOW
44576+void report_size_overflow(const char *file, unsigned int line, const char *func)
44577+{
44578+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u\n", func, file, line);
44579+ dump_stack();
44580+ do_group_exit(SIGKILL);
44581+}
44582+EXPORT_SYMBOL(report_size_overflow);
44583+#endif
44584+
44585 static int zap_process(struct task_struct *start, int exit_code)
44586 {
44587 struct task_struct *t;
44588@@ -2017,17 +2364,17 @@ static void wait_for_dump_helpers(struct file *file)
44589 pipe = file->f_path.dentry->d_inode->i_pipe;
44590
44591 pipe_lock(pipe);
44592- pipe->readers++;
44593- pipe->writers--;
44594+ atomic_inc(&pipe->readers);
44595+ atomic_dec(&pipe->writers);
44596
44597- while ((pipe->readers > 1) && (!signal_pending(current))) {
44598+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44599 wake_up_interruptible_sync(&pipe->wait);
44600 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44601 pipe_wait(pipe);
44602 }
44603
44604- pipe->readers--;
44605- pipe->writers++;
44606+ atomic_dec(&pipe->readers);
44607+ atomic_inc(&pipe->writers);
44608 pipe_unlock(pipe);
44609
44610 }
44611@@ -2088,7 +2435,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44612 int retval = 0;
44613 int flag = 0;
44614 int ispipe;
44615- static atomic_t core_dump_count = ATOMIC_INIT(0);
44616+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44617 struct coredump_params cprm = {
44618 .signr = signr,
44619 .regs = regs,
44620@@ -2103,6 +2450,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44621
44622 audit_core_dumps(signr);
44623
44624+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44625+ gr_handle_brute_attach(current, cprm.mm_flags);
44626+
44627 binfmt = mm->binfmt;
44628 if (!binfmt || !binfmt->core_dump)
44629 goto fail;
44630@@ -2170,7 +2520,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44631 }
44632 cprm.limit = RLIM_INFINITY;
44633
44634- dump_count = atomic_inc_return(&core_dump_count);
44635+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
44636 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44637 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44638 task_tgid_vnr(current), current->comm);
44639@@ -2197,6 +2547,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44640 } else {
44641 struct inode *inode;
44642
44643+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44644+
44645 if (cprm.limit < binfmt->min_coredump)
44646 goto fail_unlock;
44647
44648@@ -2240,7 +2592,7 @@ close_fail:
44649 filp_close(cprm.file, NULL);
44650 fail_dropcount:
44651 if (ispipe)
44652- atomic_dec(&core_dump_count);
44653+ atomic_dec_unchecked(&core_dump_count);
44654 fail_unlock:
44655 kfree(cn.corename);
44656 fail_corename:
44657@@ -2259,7 +2611,7 @@ fail:
44658 */
44659 int dump_write(struct file *file, const void *addr, int nr)
44660 {
44661- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44662+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44663 }
44664 EXPORT_SYMBOL(dump_write);
44665
44666diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
44667index a8cbe1b..fed04cb 100644
44668--- a/fs/ext2/balloc.c
44669+++ b/fs/ext2/balloc.c
44670@@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
44671
44672 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44673 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44674- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44675+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
44676 sbi->s_resuid != current_fsuid() &&
44677 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44678 return 0;
44679diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
44680index a203892..4e64db5 100644
44681--- a/fs/ext3/balloc.c
44682+++ b/fs/ext3/balloc.c
44683@@ -1446,9 +1446,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
44684
44685 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44686 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44687- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44688+ if (free_blocks < root_blocks + 1 &&
44689 !use_reservation && sbi->s_resuid != current_fsuid() &&
44690- (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44691+ (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
44692+ !capable_nolog(CAP_SYS_RESOURCE)) {
44693 return 0;
44694 }
44695 return 1;
44696diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
44697index f9e2cd8..bfdc476 100644
44698--- a/fs/ext4/balloc.c
44699+++ b/fs/ext4/balloc.c
44700@@ -438,8 +438,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
44701 /* Hm, nope. Are (enough) root reserved clusters available? */
44702 if (sbi->s_resuid == current_fsuid() ||
44703 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
44704- capable(CAP_SYS_RESOURCE) ||
44705- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
44706+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
44707+ capable_nolog(CAP_SYS_RESOURCE)) {
44708
44709 if (free_clusters >= (nclusters + dirty_clusters))
44710 return 1;
44711diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
44712index 9983ba8..2a5272c 100644
44713--- a/fs/ext4/ext4.h
44714+++ b/fs/ext4/ext4.h
44715@@ -1217,19 +1217,19 @@ struct ext4_sb_info {
44716 unsigned long s_mb_last_start;
44717
44718 /* stats for buddy allocator */
44719- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
44720- atomic_t s_bal_success; /* we found long enough chunks */
44721- atomic_t s_bal_allocated; /* in blocks */
44722- atomic_t s_bal_ex_scanned; /* total extents scanned */
44723- atomic_t s_bal_goals; /* goal hits */
44724- atomic_t s_bal_breaks; /* too long searches */
44725- atomic_t s_bal_2orders; /* 2^order hits */
44726+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
44727+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
44728+ atomic_unchecked_t s_bal_allocated; /* in blocks */
44729+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
44730+ atomic_unchecked_t s_bal_goals; /* goal hits */
44731+ atomic_unchecked_t s_bal_breaks; /* too long searches */
44732+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
44733 spinlock_t s_bal_lock;
44734 unsigned long s_mb_buddies_generated;
44735 unsigned long long s_mb_generation_time;
44736- atomic_t s_mb_lost_chunks;
44737- atomic_t s_mb_preallocated;
44738- atomic_t s_mb_discarded;
44739+ atomic_unchecked_t s_mb_lost_chunks;
44740+ atomic_unchecked_t s_mb_preallocated;
44741+ atomic_unchecked_t s_mb_discarded;
44742 atomic_t s_lock_busy;
44743
44744 /* locality groups */
44745diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
44746index cb990b2..4820141 100644
44747--- a/fs/ext4/mballoc.c
44748+++ b/fs/ext4/mballoc.c
44749@@ -1794,7 +1794,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
44750 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
44751
44752 if (EXT4_SB(sb)->s_mb_stats)
44753- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
44754+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
44755
44756 break;
44757 }
44758@@ -2088,7 +2088,7 @@ repeat:
44759 ac->ac_status = AC_STATUS_CONTINUE;
44760 ac->ac_flags |= EXT4_MB_HINT_FIRST;
44761 cr = 3;
44762- atomic_inc(&sbi->s_mb_lost_chunks);
44763+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
44764 goto repeat;
44765 }
44766 }
44767@@ -2592,25 +2592,25 @@ int ext4_mb_release(struct super_block *sb)
44768 if (sbi->s_mb_stats) {
44769 ext4_msg(sb, KERN_INFO,
44770 "mballoc: %u blocks %u reqs (%u success)",
44771- atomic_read(&sbi->s_bal_allocated),
44772- atomic_read(&sbi->s_bal_reqs),
44773- atomic_read(&sbi->s_bal_success));
44774+ atomic_read_unchecked(&sbi->s_bal_allocated),
44775+ atomic_read_unchecked(&sbi->s_bal_reqs),
44776+ atomic_read_unchecked(&sbi->s_bal_success));
44777 ext4_msg(sb, KERN_INFO,
44778 "mballoc: %u extents scanned, %u goal hits, "
44779 "%u 2^N hits, %u breaks, %u lost",
44780- atomic_read(&sbi->s_bal_ex_scanned),
44781- atomic_read(&sbi->s_bal_goals),
44782- atomic_read(&sbi->s_bal_2orders),
44783- atomic_read(&sbi->s_bal_breaks),
44784- atomic_read(&sbi->s_mb_lost_chunks));
44785+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
44786+ atomic_read_unchecked(&sbi->s_bal_goals),
44787+ atomic_read_unchecked(&sbi->s_bal_2orders),
44788+ atomic_read_unchecked(&sbi->s_bal_breaks),
44789+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
44790 ext4_msg(sb, KERN_INFO,
44791 "mballoc: %lu generated and it took %Lu",
44792 sbi->s_mb_buddies_generated,
44793 sbi->s_mb_generation_time);
44794 ext4_msg(sb, KERN_INFO,
44795 "mballoc: %u preallocated, %u discarded",
44796- atomic_read(&sbi->s_mb_preallocated),
44797- atomic_read(&sbi->s_mb_discarded));
44798+ atomic_read_unchecked(&sbi->s_mb_preallocated),
44799+ atomic_read_unchecked(&sbi->s_mb_discarded));
44800 }
44801
44802 free_percpu(sbi->s_locality_groups);
44803@@ -3096,16 +3096,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
44804 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
44805
44806 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
44807- atomic_inc(&sbi->s_bal_reqs);
44808- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44809+ atomic_inc_unchecked(&sbi->s_bal_reqs);
44810+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44811 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
44812- atomic_inc(&sbi->s_bal_success);
44813- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
44814+ atomic_inc_unchecked(&sbi->s_bal_success);
44815+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
44816 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
44817 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
44818- atomic_inc(&sbi->s_bal_goals);
44819+ atomic_inc_unchecked(&sbi->s_bal_goals);
44820 if (ac->ac_found > sbi->s_mb_max_to_scan)
44821- atomic_inc(&sbi->s_bal_breaks);
44822+ atomic_inc_unchecked(&sbi->s_bal_breaks);
44823 }
44824
44825 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
44826@@ -3509,7 +3509,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
44827 trace_ext4_mb_new_inode_pa(ac, pa);
44828
44829 ext4_mb_use_inode_pa(ac, pa);
44830- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
44831+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
44832
44833 ei = EXT4_I(ac->ac_inode);
44834 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44835@@ -3569,7 +3569,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
44836 trace_ext4_mb_new_group_pa(ac, pa);
44837
44838 ext4_mb_use_group_pa(ac, pa);
44839- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44840+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44841
44842 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44843 lg = ac->ac_lg;
44844@@ -3658,7 +3658,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
44845 * from the bitmap and continue.
44846 */
44847 }
44848- atomic_add(free, &sbi->s_mb_discarded);
44849+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
44850
44851 return err;
44852 }
44853@@ -3676,7 +3676,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
44854 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
44855 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
44856 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
44857- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44858+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44859 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
44860
44861 return 0;
44862diff --git a/fs/fcntl.c b/fs/fcntl.c
44863index 22764c7..86372c9 100644
44864--- a/fs/fcntl.c
44865+++ b/fs/fcntl.c
44866@@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
44867 if (err)
44868 return err;
44869
44870+ if (gr_handle_chroot_fowner(pid, type))
44871+ return -ENOENT;
44872+ if (gr_check_protected_task_fowner(pid, type))
44873+ return -EACCES;
44874+
44875 f_modown(filp, pid, type, force);
44876 return 0;
44877 }
44878@@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
44879
44880 static int f_setown_ex(struct file *filp, unsigned long arg)
44881 {
44882- struct f_owner_ex * __user owner_p = (void * __user)arg;
44883+ struct f_owner_ex __user *owner_p = (void __user *)arg;
44884 struct f_owner_ex owner;
44885 struct pid *pid;
44886 int type;
44887@@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
44888
44889 static int f_getown_ex(struct file *filp, unsigned long arg)
44890 {
44891- struct f_owner_ex * __user owner_p = (void * __user)arg;
44892+ struct f_owner_ex __user *owner_p = (void __user *)arg;
44893 struct f_owner_ex owner;
44894 int ret = 0;
44895
44896@@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
44897 switch (cmd) {
44898 case F_DUPFD:
44899 case F_DUPFD_CLOEXEC:
44900+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
44901 if (arg >= rlimit(RLIMIT_NOFILE))
44902 break;
44903 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
44904diff --git a/fs/fifo.c b/fs/fifo.c
44905index b1a524d..4ee270e 100644
44906--- a/fs/fifo.c
44907+++ b/fs/fifo.c
44908@@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
44909 */
44910 filp->f_op = &read_pipefifo_fops;
44911 pipe->r_counter++;
44912- if (pipe->readers++ == 0)
44913+ if (atomic_inc_return(&pipe->readers) == 1)
44914 wake_up_partner(inode);
44915
44916- if (!pipe->writers) {
44917+ if (!atomic_read(&pipe->writers)) {
44918 if ((filp->f_flags & O_NONBLOCK)) {
44919 /* suppress POLLHUP until we have
44920 * seen a writer */
44921@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
44922 * errno=ENXIO when there is no process reading the FIFO.
44923 */
44924 ret = -ENXIO;
44925- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
44926+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
44927 goto err;
44928
44929 filp->f_op = &write_pipefifo_fops;
44930 pipe->w_counter++;
44931- if (!pipe->writers++)
44932+ if (atomic_inc_return(&pipe->writers) == 1)
44933 wake_up_partner(inode);
44934
44935- if (!pipe->readers) {
44936+ if (!atomic_read(&pipe->readers)) {
44937 wait_for_partner(inode, &pipe->r_counter);
44938 if (signal_pending(current))
44939 goto err_wr;
44940@@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
44941 */
44942 filp->f_op = &rdwr_pipefifo_fops;
44943
44944- pipe->readers++;
44945- pipe->writers++;
44946+ atomic_inc(&pipe->readers);
44947+ atomic_inc(&pipe->writers);
44948 pipe->r_counter++;
44949 pipe->w_counter++;
44950- if (pipe->readers == 1 || pipe->writers == 1)
44951+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
44952 wake_up_partner(inode);
44953 break;
44954
44955@@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
44956 return 0;
44957
44958 err_rd:
44959- if (!--pipe->readers)
44960+ if (atomic_dec_and_test(&pipe->readers))
44961 wake_up_interruptible(&pipe->wait);
44962 ret = -ERESTARTSYS;
44963 goto err;
44964
44965 err_wr:
44966- if (!--pipe->writers)
44967+ if (atomic_dec_and_test(&pipe->writers))
44968 wake_up_interruptible(&pipe->wait);
44969 ret = -ERESTARTSYS;
44970 goto err;
44971
44972 err:
44973- if (!pipe->readers && !pipe->writers)
44974+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
44975 free_pipe_info(inode);
44976
44977 err_nocleanup:
44978diff --git a/fs/file.c b/fs/file.c
44979index 4c6992d..104cdea 100644
44980--- a/fs/file.c
44981+++ b/fs/file.c
44982@@ -15,6 +15,7 @@
44983 #include <linux/slab.h>
44984 #include <linux/vmalloc.h>
44985 #include <linux/file.h>
44986+#include <linux/security.h>
44987 #include <linux/fdtable.h>
44988 #include <linux/bitops.h>
44989 #include <linux/interrupt.h>
44990@@ -254,6 +255,7 @@ int expand_files(struct files_struct *files, int nr)
44991 * N.B. For clone tasks sharing a files structure, this test
44992 * will limit the total number of files that can be opened.
44993 */
44994+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
44995 if (nr >= rlimit(RLIMIT_NOFILE))
44996 return -EMFILE;
44997
44998diff --git a/fs/filesystems.c b/fs/filesystems.c
44999index 96f2428..f5eeb8e 100644
45000--- a/fs/filesystems.c
45001+++ b/fs/filesystems.c
45002@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45003 int len = dot ? dot - name : strlen(name);
45004
45005 fs = __get_fs_type(name, len);
45006+
45007+#ifdef CONFIG_GRKERNSEC_MODHARDEN
45008+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45009+#else
45010 if (!fs && (request_module("%.*s", len, name) == 0))
45011+#endif
45012 fs = __get_fs_type(name, len);
45013
45014 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45015diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45016index 78b519c..a8b4979 100644
45017--- a/fs/fs_struct.c
45018+++ b/fs/fs_struct.c
45019@@ -4,6 +4,7 @@
45020 #include <linux/path.h>
45021 #include <linux/slab.h>
45022 #include <linux/fs_struct.h>
45023+#include <linux/grsecurity.h>
45024 #include "internal.h"
45025
45026 static inline void path_get_longterm(struct path *path)
45027@@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45028 old_root = fs->root;
45029 fs->root = *path;
45030 path_get_longterm(path);
45031+ gr_set_chroot_entries(current, path);
45032 write_seqcount_end(&fs->seq);
45033 spin_unlock(&fs->lock);
45034 if (old_root.dentry)
45035@@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45036 && fs->root.mnt == old_root->mnt) {
45037 path_get_longterm(new_root);
45038 fs->root = *new_root;
45039+ gr_set_chroot_entries(p, new_root);
45040 count++;
45041 }
45042 if (fs->pwd.dentry == old_root->dentry
45043@@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
45044 spin_lock(&fs->lock);
45045 write_seqcount_begin(&fs->seq);
45046 tsk->fs = NULL;
45047- kill = !--fs->users;
45048+ gr_clear_chroot_entries(tsk);
45049+ kill = !atomic_dec_return(&fs->users);
45050 write_seqcount_end(&fs->seq);
45051 spin_unlock(&fs->lock);
45052 task_unlock(tsk);
45053@@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45054 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45055 /* We don't need to lock fs - think why ;-) */
45056 if (fs) {
45057- fs->users = 1;
45058+ atomic_set(&fs->users, 1);
45059 fs->in_exec = 0;
45060 spin_lock_init(&fs->lock);
45061 seqcount_init(&fs->seq);
45062@@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45063 spin_lock(&old->lock);
45064 fs->root = old->root;
45065 path_get_longterm(&fs->root);
45066+ /* instead of calling gr_set_chroot_entries here,
45067+ we call it from every caller of this function
45068+ */
45069 fs->pwd = old->pwd;
45070 path_get_longterm(&fs->pwd);
45071 spin_unlock(&old->lock);
45072@@ -150,8 +157,9 @@ int unshare_fs_struct(void)
45073
45074 task_lock(current);
45075 spin_lock(&fs->lock);
45076- kill = !--fs->users;
45077+ kill = !atomic_dec_return(&fs->users);
45078 current->fs = new_fs;
45079+ gr_set_chroot_entries(current, &new_fs->root);
45080 spin_unlock(&fs->lock);
45081 task_unlock(current);
45082
45083@@ -164,13 +172,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
45084
45085 int current_umask(void)
45086 {
45087- return current->fs->umask;
45088+ return current->fs->umask | gr_acl_umask();
45089 }
45090 EXPORT_SYMBOL(current_umask);
45091
45092 /* to be mentioned only in INIT_TASK */
45093 struct fs_struct init_fs = {
45094- .users = 1,
45095+ .users = ATOMIC_INIT(1),
45096 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
45097 .seq = SEQCNT_ZERO,
45098 .umask = 0022,
45099@@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
45100 task_lock(current);
45101
45102 spin_lock(&init_fs.lock);
45103- init_fs.users++;
45104+ atomic_inc(&init_fs.users);
45105 spin_unlock(&init_fs.lock);
45106
45107 spin_lock(&fs->lock);
45108 current->fs = &init_fs;
45109- kill = !--fs->users;
45110+ gr_set_chroot_entries(current, &current->fs->root);
45111+ kill = !atomic_dec_return(&fs->users);
45112 spin_unlock(&fs->lock);
45113
45114 task_unlock(current);
45115diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
45116index 9905350..02eaec4 100644
45117--- a/fs/fscache/cookie.c
45118+++ b/fs/fscache/cookie.c
45119@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
45120 parent ? (char *) parent->def->name : "<no-parent>",
45121 def->name, netfs_data);
45122
45123- fscache_stat(&fscache_n_acquires);
45124+ fscache_stat_unchecked(&fscache_n_acquires);
45125
45126 /* if there's no parent cookie, then we don't create one here either */
45127 if (!parent) {
45128- fscache_stat(&fscache_n_acquires_null);
45129+ fscache_stat_unchecked(&fscache_n_acquires_null);
45130 _leave(" [no parent]");
45131 return NULL;
45132 }
45133@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
45134 /* allocate and initialise a cookie */
45135 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
45136 if (!cookie) {
45137- fscache_stat(&fscache_n_acquires_oom);
45138+ fscache_stat_unchecked(&fscache_n_acquires_oom);
45139 _leave(" [ENOMEM]");
45140 return NULL;
45141 }
45142@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45143
45144 switch (cookie->def->type) {
45145 case FSCACHE_COOKIE_TYPE_INDEX:
45146- fscache_stat(&fscache_n_cookie_index);
45147+ fscache_stat_unchecked(&fscache_n_cookie_index);
45148 break;
45149 case FSCACHE_COOKIE_TYPE_DATAFILE:
45150- fscache_stat(&fscache_n_cookie_data);
45151+ fscache_stat_unchecked(&fscache_n_cookie_data);
45152 break;
45153 default:
45154- fscache_stat(&fscache_n_cookie_special);
45155+ fscache_stat_unchecked(&fscache_n_cookie_special);
45156 break;
45157 }
45158
45159@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45160 if (fscache_acquire_non_index_cookie(cookie) < 0) {
45161 atomic_dec(&parent->n_children);
45162 __fscache_cookie_put(cookie);
45163- fscache_stat(&fscache_n_acquires_nobufs);
45164+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
45165 _leave(" = NULL");
45166 return NULL;
45167 }
45168 }
45169
45170- fscache_stat(&fscache_n_acquires_ok);
45171+ fscache_stat_unchecked(&fscache_n_acquires_ok);
45172 _leave(" = %p", cookie);
45173 return cookie;
45174 }
45175@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
45176 cache = fscache_select_cache_for_object(cookie->parent);
45177 if (!cache) {
45178 up_read(&fscache_addremove_sem);
45179- fscache_stat(&fscache_n_acquires_no_cache);
45180+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45181 _leave(" = -ENOMEDIUM [no cache]");
45182 return -ENOMEDIUM;
45183 }
45184@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
45185 object = cache->ops->alloc_object(cache, cookie);
45186 fscache_stat_d(&fscache_n_cop_alloc_object);
45187 if (IS_ERR(object)) {
45188- fscache_stat(&fscache_n_object_no_alloc);
45189+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
45190 ret = PTR_ERR(object);
45191 goto error;
45192 }
45193
45194- fscache_stat(&fscache_n_object_alloc);
45195+ fscache_stat_unchecked(&fscache_n_object_alloc);
45196
45197 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45198
45199@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45200 struct fscache_object *object;
45201 struct hlist_node *_p;
45202
45203- fscache_stat(&fscache_n_updates);
45204+ fscache_stat_unchecked(&fscache_n_updates);
45205
45206 if (!cookie) {
45207- fscache_stat(&fscache_n_updates_null);
45208+ fscache_stat_unchecked(&fscache_n_updates_null);
45209 _leave(" [no cookie]");
45210 return;
45211 }
45212@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45213 struct fscache_object *object;
45214 unsigned long event;
45215
45216- fscache_stat(&fscache_n_relinquishes);
45217+ fscache_stat_unchecked(&fscache_n_relinquishes);
45218 if (retire)
45219- fscache_stat(&fscache_n_relinquishes_retire);
45220+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45221
45222 if (!cookie) {
45223- fscache_stat(&fscache_n_relinquishes_null);
45224+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
45225 _leave(" [no cookie]");
45226 return;
45227 }
45228@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45229
45230 /* wait for the cookie to finish being instantiated (or to fail) */
45231 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45232- fscache_stat(&fscache_n_relinquishes_waitcrt);
45233+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45234 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45235 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45236 }
45237diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45238index f6aad48..88dcf26 100644
45239--- a/fs/fscache/internal.h
45240+++ b/fs/fscache/internal.h
45241@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45242 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45243 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45244
45245-extern atomic_t fscache_n_op_pend;
45246-extern atomic_t fscache_n_op_run;
45247-extern atomic_t fscache_n_op_enqueue;
45248-extern atomic_t fscache_n_op_deferred_release;
45249-extern atomic_t fscache_n_op_release;
45250-extern atomic_t fscache_n_op_gc;
45251-extern atomic_t fscache_n_op_cancelled;
45252-extern atomic_t fscache_n_op_rejected;
45253+extern atomic_unchecked_t fscache_n_op_pend;
45254+extern atomic_unchecked_t fscache_n_op_run;
45255+extern atomic_unchecked_t fscache_n_op_enqueue;
45256+extern atomic_unchecked_t fscache_n_op_deferred_release;
45257+extern atomic_unchecked_t fscache_n_op_release;
45258+extern atomic_unchecked_t fscache_n_op_gc;
45259+extern atomic_unchecked_t fscache_n_op_cancelled;
45260+extern atomic_unchecked_t fscache_n_op_rejected;
45261
45262-extern atomic_t fscache_n_attr_changed;
45263-extern atomic_t fscache_n_attr_changed_ok;
45264-extern atomic_t fscache_n_attr_changed_nobufs;
45265-extern atomic_t fscache_n_attr_changed_nomem;
45266-extern atomic_t fscache_n_attr_changed_calls;
45267+extern atomic_unchecked_t fscache_n_attr_changed;
45268+extern atomic_unchecked_t fscache_n_attr_changed_ok;
45269+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45270+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45271+extern atomic_unchecked_t fscache_n_attr_changed_calls;
45272
45273-extern atomic_t fscache_n_allocs;
45274-extern atomic_t fscache_n_allocs_ok;
45275-extern atomic_t fscache_n_allocs_wait;
45276-extern atomic_t fscache_n_allocs_nobufs;
45277-extern atomic_t fscache_n_allocs_intr;
45278-extern atomic_t fscache_n_allocs_object_dead;
45279-extern atomic_t fscache_n_alloc_ops;
45280-extern atomic_t fscache_n_alloc_op_waits;
45281+extern atomic_unchecked_t fscache_n_allocs;
45282+extern atomic_unchecked_t fscache_n_allocs_ok;
45283+extern atomic_unchecked_t fscache_n_allocs_wait;
45284+extern atomic_unchecked_t fscache_n_allocs_nobufs;
45285+extern atomic_unchecked_t fscache_n_allocs_intr;
45286+extern atomic_unchecked_t fscache_n_allocs_object_dead;
45287+extern atomic_unchecked_t fscache_n_alloc_ops;
45288+extern atomic_unchecked_t fscache_n_alloc_op_waits;
45289
45290-extern atomic_t fscache_n_retrievals;
45291-extern atomic_t fscache_n_retrievals_ok;
45292-extern atomic_t fscache_n_retrievals_wait;
45293-extern atomic_t fscache_n_retrievals_nodata;
45294-extern atomic_t fscache_n_retrievals_nobufs;
45295-extern atomic_t fscache_n_retrievals_intr;
45296-extern atomic_t fscache_n_retrievals_nomem;
45297-extern atomic_t fscache_n_retrievals_object_dead;
45298-extern atomic_t fscache_n_retrieval_ops;
45299-extern atomic_t fscache_n_retrieval_op_waits;
45300+extern atomic_unchecked_t fscache_n_retrievals;
45301+extern atomic_unchecked_t fscache_n_retrievals_ok;
45302+extern atomic_unchecked_t fscache_n_retrievals_wait;
45303+extern atomic_unchecked_t fscache_n_retrievals_nodata;
45304+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45305+extern atomic_unchecked_t fscache_n_retrievals_intr;
45306+extern atomic_unchecked_t fscache_n_retrievals_nomem;
45307+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45308+extern atomic_unchecked_t fscache_n_retrieval_ops;
45309+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45310
45311-extern atomic_t fscache_n_stores;
45312-extern atomic_t fscache_n_stores_ok;
45313-extern atomic_t fscache_n_stores_again;
45314-extern atomic_t fscache_n_stores_nobufs;
45315-extern atomic_t fscache_n_stores_oom;
45316-extern atomic_t fscache_n_store_ops;
45317-extern atomic_t fscache_n_store_calls;
45318-extern atomic_t fscache_n_store_pages;
45319-extern atomic_t fscache_n_store_radix_deletes;
45320-extern atomic_t fscache_n_store_pages_over_limit;
45321+extern atomic_unchecked_t fscache_n_stores;
45322+extern atomic_unchecked_t fscache_n_stores_ok;
45323+extern atomic_unchecked_t fscache_n_stores_again;
45324+extern atomic_unchecked_t fscache_n_stores_nobufs;
45325+extern atomic_unchecked_t fscache_n_stores_oom;
45326+extern atomic_unchecked_t fscache_n_store_ops;
45327+extern atomic_unchecked_t fscache_n_store_calls;
45328+extern atomic_unchecked_t fscache_n_store_pages;
45329+extern atomic_unchecked_t fscache_n_store_radix_deletes;
45330+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45331
45332-extern atomic_t fscache_n_store_vmscan_not_storing;
45333-extern atomic_t fscache_n_store_vmscan_gone;
45334-extern atomic_t fscache_n_store_vmscan_busy;
45335-extern atomic_t fscache_n_store_vmscan_cancelled;
45336+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45337+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45338+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45339+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45340
45341-extern atomic_t fscache_n_marks;
45342-extern atomic_t fscache_n_uncaches;
45343+extern atomic_unchecked_t fscache_n_marks;
45344+extern atomic_unchecked_t fscache_n_uncaches;
45345
45346-extern atomic_t fscache_n_acquires;
45347-extern atomic_t fscache_n_acquires_null;
45348-extern atomic_t fscache_n_acquires_no_cache;
45349-extern atomic_t fscache_n_acquires_ok;
45350-extern atomic_t fscache_n_acquires_nobufs;
45351-extern atomic_t fscache_n_acquires_oom;
45352+extern atomic_unchecked_t fscache_n_acquires;
45353+extern atomic_unchecked_t fscache_n_acquires_null;
45354+extern atomic_unchecked_t fscache_n_acquires_no_cache;
45355+extern atomic_unchecked_t fscache_n_acquires_ok;
45356+extern atomic_unchecked_t fscache_n_acquires_nobufs;
45357+extern atomic_unchecked_t fscache_n_acquires_oom;
45358
45359-extern atomic_t fscache_n_updates;
45360-extern atomic_t fscache_n_updates_null;
45361-extern atomic_t fscache_n_updates_run;
45362+extern atomic_unchecked_t fscache_n_updates;
45363+extern atomic_unchecked_t fscache_n_updates_null;
45364+extern atomic_unchecked_t fscache_n_updates_run;
45365
45366-extern atomic_t fscache_n_relinquishes;
45367-extern atomic_t fscache_n_relinquishes_null;
45368-extern atomic_t fscache_n_relinquishes_waitcrt;
45369-extern atomic_t fscache_n_relinquishes_retire;
45370+extern atomic_unchecked_t fscache_n_relinquishes;
45371+extern atomic_unchecked_t fscache_n_relinquishes_null;
45372+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45373+extern atomic_unchecked_t fscache_n_relinquishes_retire;
45374
45375-extern atomic_t fscache_n_cookie_index;
45376-extern atomic_t fscache_n_cookie_data;
45377-extern atomic_t fscache_n_cookie_special;
45378+extern atomic_unchecked_t fscache_n_cookie_index;
45379+extern atomic_unchecked_t fscache_n_cookie_data;
45380+extern atomic_unchecked_t fscache_n_cookie_special;
45381
45382-extern atomic_t fscache_n_object_alloc;
45383-extern atomic_t fscache_n_object_no_alloc;
45384-extern atomic_t fscache_n_object_lookups;
45385-extern atomic_t fscache_n_object_lookups_negative;
45386-extern atomic_t fscache_n_object_lookups_positive;
45387-extern atomic_t fscache_n_object_lookups_timed_out;
45388-extern atomic_t fscache_n_object_created;
45389-extern atomic_t fscache_n_object_avail;
45390-extern atomic_t fscache_n_object_dead;
45391+extern atomic_unchecked_t fscache_n_object_alloc;
45392+extern atomic_unchecked_t fscache_n_object_no_alloc;
45393+extern atomic_unchecked_t fscache_n_object_lookups;
45394+extern atomic_unchecked_t fscache_n_object_lookups_negative;
45395+extern atomic_unchecked_t fscache_n_object_lookups_positive;
45396+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45397+extern atomic_unchecked_t fscache_n_object_created;
45398+extern atomic_unchecked_t fscache_n_object_avail;
45399+extern atomic_unchecked_t fscache_n_object_dead;
45400
45401-extern atomic_t fscache_n_checkaux_none;
45402-extern atomic_t fscache_n_checkaux_okay;
45403-extern atomic_t fscache_n_checkaux_update;
45404-extern atomic_t fscache_n_checkaux_obsolete;
45405+extern atomic_unchecked_t fscache_n_checkaux_none;
45406+extern atomic_unchecked_t fscache_n_checkaux_okay;
45407+extern atomic_unchecked_t fscache_n_checkaux_update;
45408+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45409
45410 extern atomic_t fscache_n_cop_alloc_object;
45411 extern atomic_t fscache_n_cop_lookup_object;
45412@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45413 atomic_inc(stat);
45414 }
45415
45416+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45417+{
45418+ atomic_inc_unchecked(stat);
45419+}
45420+
45421 static inline void fscache_stat_d(atomic_t *stat)
45422 {
45423 atomic_dec(stat);
45424@@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45425
45426 #define __fscache_stat(stat) (NULL)
45427 #define fscache_stat(stat) do {} while (0)
45428+#define fscache_stat_unchecked(stat) do {} while (0)
45429 #define fscache_stat_d(stat) do {} while (0)
45430 #endif
45431
45432diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45433index b6b897c..0ffff9c 100644
45434--- a/fs/fscache/object.c
45435+++ b/fs/fscache/object.c
45436@@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45437 /* update the object metadata on disk */
45438 case FSCACHE_OBJECT_UPDATING:
45439 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45440- fscache_stat(&fscache_n_updates_run);
45441+ fscache_stat_unchecked(&fscache_n_updates_run);
45442 fscache_stat(&fscache_n_cop_update_object);
45443 object->cache->ops->update_object(object);
45444 fscache_stat_d(&fscache_n_cop_update_object);
45445@@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45446 spin_lock(&object->lock);
45447 object->state = FSCACHE_OBJECT_DEAD;
45448 spin_unlock(&object->lock);
45449- fscache_stat(&fscache_n_object_dead);
45450+ fscache_stat_unchecked(&fscache_n_object_dead);
45451 goto terminal_transit;
45452
45453 /* handle the parent cache of this object being withdrawn from
45454@@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45455 spin_lock(&object->lock);
45456 object->state = FSCACHE_OBJECT_DEAD;
45457 spin_unlock(&object->lock);
45458- fscache_stat(&fscache_n_object_dead);
45459+ fscache_stat_unchecked(&fscache_n_object_dead);
45460 goto terminal_transit;
45461
45462 /* complain about the object being woken up once it is
45463@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45464 parent->cookie->def->name, cookie->def->name,
45465 object->cache->tag->name);
45466
45467- fscache_stat(&fscache_n_object_lookups);
45468+ fscache_stat_unchecked(&fscache_n_object_lookups);
45469 fscache_stat(&fscache_n_cop_lookup_object);
45470 ret = object->cache->ops->lookup_object(object);
45471 fscache_stat_d(&fscache_n_cop_lookup_object);
45472@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45473 if (ret == -ETIMEDOUT) {
45474 /* probably stuck behind another object, so move this one to
45475 * the back of the queue */
45476- fscache_stat(&fscache_n_object_lookups_timed_out);
45477+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45478 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45479 }
45480
45481@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45482
45483 spin_lock(&object->lock);
45484 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45485- fscache_stat(&fscache_n_object_lookups_negative);
45486+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45487
45488 /* transit here to allow write requests to begin stacking up
45489 * and read requests to begin returning ENODATA */
45490@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45491 * result, in which case there may be data available */
45492 spin_lock(&object->lock);
45493 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45494- fscache_stat(&fscache_n_object_lookups_positive);
45495+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45496
45497 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45498
45499@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45500 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45501 } else {
45502 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45503- fscache_stat(&fscache_n_object_created);
45504+ fscache_stat_unchecked(&fscache_n_object_created);
45505
45506 object->state = FSCACHE_OBJECT_AVAILABLE;
45507 spin_unlock(&object->lock);
45508@@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45509 fscache_enqueue_dependents(object);
45510
45511 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45512- fscache_stat(&fscache_n_object_avail);
45513+ fscache_stat_unchecked(&fscache_n_object_avail);
45514
45515 _leave("");
45516 }
45517@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45518 enum fscache_checkaux result;
45519
45520 if (!object->cookie->def->check_aux) {
45521- fscache_stat(&fscache_n_checkaux_none);
45522+ fscache_stat_unchecked(&fscache_n_checkaux_none);
45523 return FSCACHE_CHECKAUX_OKAY;
45524 }
45525
45526@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45527 switch (result) {
45528 /* entry okay as is */
45529 case FSCACHE_CHECKAUX_OKAY:
45530- fscache_stat(&fscache_n_checkaux_okay);
45531+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
45532 break;
45533
45534 /* entry requires update */
45535 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45536- fscache_stat(&fscache_n_checkaux_update);
45537+ fscache_stat_unchecked(&fscache_n_checkaux_update);
45538 break;
45539
45540 /* entry requires deletion */
45541 case FSCACHE_CHECKAUX_OBSOLETE:
45542- fscache_stat(&fscache_n_checkaux_obsolete);
45543+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45544 break;
45545
45546 default:
45547diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45548index 30afdfa..2256596 100644
45549--- a/fs/fscache/operation.c
45550+++ b/fs/fscache/operation.c
45551@@ -17,7 +17,7 @@
45552 #include <linux/slab.h>
45553 #include "internal.h"
45554
45555-atomic_t fscache_op_debug_id;
45556+atomic_unchecked_t fscache_op_debug_id;
45557 EXPORT_SYMBOL(fscache_op_debug_id);
45558
45559 /**
45560@@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45561 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45562 ASSERTCMP(atomic_read(&op->usage), >, 0);
45563
45564- fscache_stat(&fscache_n_op_enqueue);
45565+ fscache_stat_unchecked(&fscache_n_op_enqueue);
45566 switch (op->flags & FSCACHE_OP_TYPE) {
45567 case FSCACHE_OP_ASYNC:
45568 _debug("queue async");
45569@@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45570 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45571 if (op->processor)
45572 fscache_enqueue_operation(op);
45573- fscache_stat(&fscache_n_op_run);
45574+ fscache_stat_unchecked(&fscache_n_op_run);
45575 }
45576
45577 /*
45578@@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45579 if (object->n_ops > 1) {
45580 atomic_inc(&op->usage);
45581 list_add_tail(&op->pend_link, &object->pending_ops);
45582- fscache_stat(&fscache_n_op_pend);
45583+ fscache_stat_unchecked(&fscache_n_op_pend);
45584 } else if (!list_empty(&object->pending_ops)) {
45585 atomic_inc(&op->usage);
45586 list_add_tail(&op->pend_link, &object->pending_ops);
45587- fscache_stat(&fscache_n_op_pend);
45588+ fscache_stat_unchecked(&fscache_n_op_pend);
45589 fscache_start_operations(object);
45590 } else {
45591 ASSERTCMP(object->n_in_progress, ==, 0);
45592@@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45593 object->n_exclusive++; /* reads and writes must wait */
45594 atomic_inc(&op->usage);
45595 list_add_tail(&op->pend_link, &object->pending_ops);
45596- fscache_stat(&fscache_n_op_pend);
45597+ fscache_stat_unchecked(&fscache_n_op_pend);
45598 ret = 0;
45599 } else {
45600 /* not allowed to submit ops in any other state */
45601@@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45602 if (object->n_exclusive > 0) {
45603 atomic_inc(&op->usage);
45604 list_add_tail(&op->pend_link, &object->pending_ops);
45605- fscache_stat(&fscache_n_op_pend);
45606+ fscache_stat_unchecked(&fscache_n_op_pend);
45607 } else if (!list_empty(&object->pending_ops)) {
45608 atomic_inc(&op->usage);
45609 list_add_tail(&op->pend_link, &object->pending_ops);
45610- fscache_stat(&fscache_n_op_pend);
45611+ fscache_stat_unchecked(&fscache_n_op_pend);
45612 fscache_start_operations(object);
45613 } else {
45614 ASSERTCMP(object->n_exclusive, ==, 0);
45615@@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45616 object->n_ops++;
45617 atomic_inc(&op->usage);
45618 list_add_tail(&op->pend_link, &object->pending_ops);
45619- fscache_stat(&fscache_n_op_pend);
45620+ fscache_stat_unchecked(&fscache_n_op_pend);
45621 ret = 0;
45622 } else if (object->state == FSCACHE_OBJECT_DYING ||
45623 object->state == FSCACHE_OBJECT_LC_DYING ||
45624 object->state == FSCACHE_OBJECT_WITHDRAWING) {
45625- fscache_stat(&fscache_n_op_rejected);
45626+ fscache_stat_unchecked(&fscache_n_op_rejected);
45627 ret = -ENOBUFS;
45628 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
45629 fscache_report_unexpected_submission(object, op, ostate);
45630@@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
45631
45632 ret = -EBUSY;
45633 if (!list_empty(&op->pend_link)) {
45634- fscache_stat(&fscache_n_op_cancelled);
45635+ fscache_stat_unchecked(&fscache_n_op_cancelled);
45636 list_del_init(&op->pend_link);
45637 object->n_ops--;
45638 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
45639@@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
45640 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
45641 BUG();
45642
45643- fscache_stat(&fscache_n_op_release);
45644+ fscache_stat_unchecked(&fscache_n_op_release);
45645
45646 if (op->release) {
45647 op->release(op);
45648@@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
45649 * lock, and defer it otherwise */
45650 if (!spin_trylock(&object->lock)) {
45651 _debug("defer put");
45652- fscache_stat(&fscache_n_op_deferred_release);
45653+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
45654
45655 cache = object->cache;
45656 spin_lock(&cache->op_gc_list_lock);
45657@@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
45658
45659 _debug("GC DEFERRED REL OBJ%x OP%x",
45660 object->debug_id, op->debug_id);
45661- fscache_stat(&fscache_n_op_gc);
45662+ fscache_stat_unchecked(&fscache_n_op_gc);
45663
45664 ASSERTCMP(atomic_read(&op->usage), ==, 0);
45665
45666diff --git a/fs/fscache/page.c b/fs/fscache/page.c
45667index 3f7a59b..cf196cc 100644
45668--- a/fs/fscache/page.c
45669+++ b/fs/fscache/page.c
45670@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45671 val = radix_tree_lookup(&cookie->stores, page->index);
45672 if (!val) {
45673 rcu_read_unlock();
45674- fscache_stat(&fscache_n_store_vmscan_not_storing);
45675+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
45676 __fscache_uncache_page(cookie, page);
45677 return true;
45678 }
45679@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45680 spin_unlock(&cookie->stores_lock);
45681
45682 if (xpage) {
45683- fscache_stat(&fscache_n_store_vmscan_cancelled);
45684- fscache_stat(&fscache_n_store_radix_deletes);
45685+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
45686+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45687 ASSERTCMP(xpage, ==, page);
45688 } else {
45689- fscache_stat(&fscache_n_store_vmscan_gone);
45690+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
45691 }
45692
45693 wake_up_bit(&cookie->flags, 0);
45694@@ -107,7 +107,7 @@ page_busy:
45695 /* we might want to wait here, but that could deadlock the allocator as
45696 * the work threads writing to the cache may all end up sleeping
45697 * on memory allocation */
45698- fscache_stat(&fscache_n_store_vmscan_busy);
45699+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
45700 return false;
45701 }
45702 EXPORT_SYMBOL(__fscache_maybe_release_page);
45703@@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
45704 FSCACHE_COOKIE_STORING_TAG);
45705 if (!radix_tree_tag_get(&cookie->stores, page->index,
45706 FSCACHE_COOKIE_PENDING_TAG)) {
45707- fscache_stat(&fscache_n_store_radix_deletes);
45708+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45709 xpage = radix_tree_delete(&cookie->stores, page->index);
45710 }
45711 spin_unlock(&cookie->stores_lock);
45712@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
45713
45714 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
45715
45716- fscache_stat(&fscache_n_attr_changed_calls);
45717+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
45718
45719 if (fscache_object_is_active(object)) {
45720 fscache_stat(&fscache_n_cop_attr_changed);
45721@@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45722
45723 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45724
45725- fscache_stat(&fscache_n_attr_changed);
45726+ fscache_stat_unchecked(&fscache_n_attr_changed);
45727
45728 op = kzalloc(sizeof(*op), GFP_KERNEL);
45729 if (!op) {
45730- fscache_stat(&fscache_n_attr_changed_nomem);
45731+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
45732 _leave(" = -ENOMEM");
45733 return -ENOMEM;
45734 }
45735@@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45736 if (fscache_submit_exclusive_op(object, op) < 0)
45737 goto nobufs;
45738 spin_unlock(&cookie->lock);
45739- fscache_stat(&fscache_n_attr_changed_ok);
45740+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
45741 fscache_put_operation(op);
45742 _leave(" = 0");
45743 return 0;
45744@@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45745 nobufs:
45746 spin_unlock(&cookie->lock);
45747 kfree(op);
45748- fscache_stat(&fscache_n_attr_changed_nobufs);
45749+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
45750 _leave(" = %d", -ENOBUFS);
45751 return -ENOBUFS;
45752 }
45753@@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
45754 /* allocate a retrieval operation and attempt to submit it */
45755 op = kzalloc(sizeof(*op), GFP_NOIO);
45756 if (!op) {
45757- fscache_stat(&fscache_n_retrievals_nomem);
45758+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45759 return NULL;
45760 }
45761
45762@@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45763 return 0;
45764 }
45765
45766- fscache_stat(&fscache_n_retrievals_wait);
45767+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
45768
45769 jif = jiffies;
45770 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
45771 fscache_wait_bit_interruptible,
45772 TASK_INTERRUPTIBLE) != 0) {
45773- fscache_stat(&fscache_n_retrievals_intr);
45774+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
45775 _leave(" = -ERESTARTSYS");
45776 return -ERESTARTSYS;
45777 }
45778@@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45779 */
45780 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45781 struct fscache_retrieval *op,
45782- atomic_t *stat_op_waits,
45783- atomic_t *stat_object_dead)
45784+ atomic_unchecked_t *stat_op_waits,
45785+ atomic_unchecked_t *stat_object_dead)
45786 {
45787 int ret;
45788
45789@@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45790 goto check_if_dead;
45791
45792 _debug(">>> WT");
45793- fscache_stat(stat_op_waits);
45794+ fscache_stat_unchecked(stat_op_waits);
45795 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
45796 fscache_wait_bit_interruptible,
45797 TASK_INTERRUPTIBLE) < 0) {
45798@@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45799
45800 check_if_dead:
45801 if (unlikely(fscache_object_is_dead(object))) {
45802- fscache_stat(stat_object_dead);
45803+ fscache_stat_unchecked(stat_object_dead);
45804 return -ENOBUFS;
45805 }
45806 return 0;
45807@@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45808
45809 _enter("%p,%p,,,", cookie, page);
45810
45811- fscache_stat(&fscache_n_retrievals);
45812+ fscache_stat_unchecked(&fscache_n_retrievals);
45813
45814 if (hlist_empty(&cookie->backing_objects))
45815 goto nobufs;
45816@@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45817 goto nobufs_unlock;
45818 spin_unlock(&cookie->lock);
45819
45820- fscache_stat(&fscache_n_retrieval_ops);
45821+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
45822
45823 /* pin the netfs read context in case we need to do the actual netfs
45824 * read because we've encountered a cache read failure */
45825@@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45826
45827 error:
45828 if (ret == -ENOMEM)
45829- fscache_stat(&fscache_n_retrievals_nomem);
45830+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45831 else if (ret == -ERESTARTSYS)
45832- fscache_stat(&fscache_n_retrievals_intr);
45833+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
45834 else if (ret == -ENODATA)
45835- fscache_stat(&fscache_n_retrievals_nodata);
45836+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45837 else if (ret < 0)
45838- fscache_stat(&fscache_n_retrievals_nobufs);
45839+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45840 else
45841- fscache_stat(&fscache_n_retrievals_ok);
45842+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
45843
45844 fscache_put_retrieval(op);
45845 _leave(" = %d", ret);
45846@@ -429,7 +429,7 @@ nobufs_unlock:
45847 spin_unlock(&cookie->lock);
45848 kfree(op);
45849 nobufs:
45850- fscache_stat(&fscache_n_retrievals_nobufs);
45851+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45852 _leave(" = -ENOBUFS");
45853 return -ENOBUFS;
45854 }
45855@@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45856
45857 _enter("%p,,%d,,,", cookie, *nr_pages);
45858
45859- fscache_stat(&fscache_n_retrievals);
45860+ fscache_stat_unchecked(&fscache_n_retrievals);
45861
45862 if (hlist_empty(&cookie->backing_objects))
45863 goto nobufs;
45864@@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45865 goto nobufs_unlock;
45866 spin_unlock(&cookie->lock);
45867
45868- fscache_stat(&fscache_n_retrieval_ops);
45869+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
45870
45871 /* pin the netfs read context in case we need to do the actual netfs
45872 * read because we've encountered a cache read failure */
45873@@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45874
45875 error:
45876 if (ret == -ENOMEM)
45877- fscache_stat(&fscache_n_retrievals_nomem);
45878+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45879 else if (ret == -ERESTARTSYS)
45880- fscache_stat(&fscache_n_retrievals_intr);
45881+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
45882 else if (ret == -ENODATA)
45883- fscache_stat(&fscache_n_retrievals_nodata);
45884+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45885 else if (ret < 0)
45886- fscache_stat(&fscache_n_retrievals_nobufs);
45887+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45888 else
45889- fscache_stat(&fscache_n_retrievals_ok);
45890+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
45891
45892 fscache_put_retrieval(op);
45893 _leave(" = %d", ret);
45894@@ -545,7 +545,7 @@ nobufs_unlock:
45895 spin_unlock(&cookie->lock);
45896 kfree(op);
45897 nobufs:
45898- fscache_stat(&fscache_n_retrievals_nobufs);
45899+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45900 _leave(" = -ENOBUFS");
45901 return -ENOBUFS;
45902 }
45903@@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45904
45905 _enter("%p,%p,,,", cookie, page);
45906
45907- fscache_stat(&fscache_n_allocs);
45908+ fscache_stat_unchecked(&fscache_n_allocs);
45909
45910 if (hlist_empty(&cookie->backing_objects))
45911 goto nobufs;
45912@@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45913 goto nobufs_unlock;
45914 spin_unlock(&cookie->lock);
45915
45916- fscache_stat(&fscache_n_alloc_ops);
45917+ fscache_stat_unchecked(&fscache_n_alloc_ops);
45918
45919 ret = fscache_wait_for_retrieval_activation(
45920 object, op,
45921@@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45922
45923 error:
45924 if (ret == -ERESTARTSYS)
45925- fscache_stat(&fscache_n_allocs_intr);
45926+ fscache_stat_unchecked(&fscache_n_allocs_intr);
45927 else if (ret < 0)
45928- fscache_stat(&fscache_n_allocs_nobufs);
45929+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45930 else
45931- fscache_stat(&fscache_n_allocs_ok);
45932+ fscache_stat_unchecked(&fscache_n_allocs_ok);
45933
45934 fscache_put_retrieval(op);
45935 _leave(" = %d", ret);
45936@@ -625,7 +625,7 @@ nobufs_unlock:
45937 spin_unlock(&cookie->lock);
45938 kfree(op);
45939 nobufs:
45940- fscache_stat(&fscache_n_allocs_nobufs);
45941+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45942 _leave(" = -ENOBUFS");
45943 return -ENOBUFS;
45944 }
45945@@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45946
45947 spin_lock(&cookie->stores_lock);
45948
45949- fscache_stat(&fscache_n_store_calls);
45950+ fscache_stat_unchecked(&fscache_n_store_calls);
45951
45952 /* find a page to store */
45953 page = NULL;
45954@@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45955 page = results[0];
45956 _debug("gang %d [%lx]", n, page->index);
45957 if (page->index > op->store_limit) {
45958- fscache_stat(&fscache_n_store_pages_over_limit);
45959+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
45960 goto superseded;
45961 }
45962
45963@@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45964 spin_unlock(&cookie->stores_lock);
45965 spin_unlock(&object->lock);
45966
45967- fscache_stat(&fscache_n_store_pages);
45968+ fscache_stat_unchecked(&fscache_n_store_pages);
45969 fscache_stat(&fscache_n_cop_write_page);
45970 ret = object->cache->ops->write_page(op, page);
45971 fscache_stat_d(&fscache_n_cop_write_page);
45972@@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45973 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45974 ASSERT(PageFsCache(page));
45975
45976- fscache_stat(&fscache_n_stores);
45977+ fscache_stat_unchecked(&fscache_n_stores);
45978
45979 op = kzalloc(sizeof(*op), GFP_NOIO);
45980 if (!op)
45981@@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45982 spin_unlock(&cookie->stores_lock);
45983 spin_unlock(&object->lock);
45984
45985- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
45986+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
45987 op->store_limit = object->store_limit;
45988
45989 if (fscache_submit_op(object, &op->op) < 0)
45990@@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45991
45992 spin_unlock(&cookie->lock);
45993 radix_tree_preload_end();
45994- fscache_stat(&fscache_n_store_ops);
45995- fscache_stat(&fscache_n_stores_ok);
45996+ fscache_stat_unchecked(&fscache_n_store_ops);
45997+ fscache_stat_unchecked(&fscache_n_stores_ok);
45998
45999 /* the work queue now carries its own ref on the object */
46000 fscache_put_operation(&op->op);
46001@@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46002 return 0;
46003
46004 already_queued:
46005- fscache_stat(&fscache_n_stores_again);
46006+ fscache_stat_unchecked(&fscache_n_stores_again);
46007 already_pending:
46008 spin_unlock(&cookie->stores_lock);
46009 spin_unlock(&object->lock);
46010 spin_unlock(&cookie->lock);
46011 radix_tree_preload_end();
46012 kfree(op);
46013- fscache_stat(&fscache_n_stores_ok);
46014+ fscache_stat_unchecked(&fscache_n_stores_ok);
46015 _leave(" = 0");
46016 return 0;
46017
46018@@ -851,14 +851,14 @@ nobufs:
46019 spin_unlock(&cookie->lock);
46020 radix_tree_preload_end();
46021 kfree(op);
46022- fscache_stat(&fscache_n_stores_nobufs);
46023+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
46024 _leave(" = -ENOBUFS");
46025 return -ENOBUFS;
46026
46027 nomem_free:
46028 kfree(op);
46029 nomem:
46030- fscache_stat(&fscache_n_stores_oom);
46031+ fscache_stat_unchecked(&fscache_n_stores_oom);
46032 _leave(" = -ENOMEM");
46033 return -ENOMEM;
46034 }
46035@@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46036 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46037 ASSERTCMP(page, !=, NULL);
46038
46039- fscache_stat(&fscache_n_uncaches);
46040+ fscache_stat_unchecked(&fscache_n_uncaches);
46041
46042 /* cache withdrawal may beat us to it */
46043 if (!PageFsCache(page))
46044@@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46045 unsigned long loop;
46046
46047 #ifdef CONFIG_FSCACHE_STATS
46048- atomic_add(pagevec->nr, &fscache_n_marks);
46049+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46050 #endif
46051
46052 for (loop = 0; loop < pagevec->nr; loop++) {
46053diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46054index 4765190..2a067f2 100644
46055--- a/fs/fscache/stats.c
46056+++ b/fs/fscache/stats.c
46057@@ -18,95 +18,95 @@
46058 /*
46059 * operation counters
46060 */
46061-atomic_t fscache_n_op_pend;
46062-atomic_t fscache_n_op_run;
46063-atomic_t fscache_n_op_enqueue;
46064-atomic_t fscache_n_op_requeue;
46065-atomic_t fscache_n_op_deferred_release;
46066-atomic_t fscache_n_op_release;
46067-atomic_t fscache_n_op_gc;
46068-atomic_t fscache_n_op_cancelled;
46069-atomic_t fscache_n_op_rejected;
46070+atomic_unchecked_t fscache_n_op_pend;
46071+atomic_unchecked_t fscache_n_op_run;
46072+atomic_unchecked_t fscache_n_op_enqueue;
46073+atomic_unchecked_t fscache_n_op_requeue;
46074+atomic_unchecked_t fscache_n_op_deferred_release;
46075+atomic_unchecked_t fscache_n_op_release;
46076+atomic_unchecked_t fscache_n_op_gc;
46077+atomic_unchecked_t fscache_n_op_cancelled;
46078+atomic_unchecked_t fscache_n_op_rejected;
46079
46080-atomic_t fscache_n_attr_changed;
46081-atomic_t fscache_n_attr_changed_ok;
46082-atomic_t fscache_n_attr_changed_nobufs;
46083-atomic_t fscache_n_attr_changed_nomem;
46084-atomic_t fscache_n_attr_changed_calls;
46085+atomic_unchecked_t fscache_n_attr_changed;
46086+atomic_unchecked_t fscache_n_attr_changed_ok;
46087+atomic_unchecked_t fscache_n_attr_changed_nobufs;
46088+atomic_unchecked_t fscache_n_attr_changed_nomem;
46089+atomic_unchecked_t fscache_n_attr_changed_calls;
46090
46091-atomic_t fscache_n_allocs;
46092-atomic_t fscache_n_allocs_ok;
46093-atomic_t fscache_n_allocs_wait;
46094-atomic_t fscache_n_allocs_nobufs;
46095-atomic_t fscache_n_allocs_intr;
46096-atomic_t fscache_n_allocs_object_dead;
46097-atomic_t fscache_n_alloc_ops;
46098-atomic_t fscache_n_alloc_op_waits;
46099+atomic_unchecked_t fscache_n_allocs;
46100+atomic_unchecked_t fscache_n_allocs_ok;
46101+atomic_unchecked_t fscache_n_allocs_wait;
46102+atomic_unchecked_t fscache_n_allocs_nobufs;
46103+atomic_unchecked_t fscache_n_allocs_intr;
46104+atomic_unchecked_t fscache_n_allocs_object_dead;
46105+atomic_unchecked_t fscache_n_alloc_ops;
46106+atomic_unchecked_t fscache_n_alloc_op_waits;
46107
46108-atomic_t fscache_n_retrievals;
46109-atomic_t fscache_n_retrievals_ok;
46110-atomic_t fscache_n_retrievals_wait;
46111-atomic_t fscache_n_retrievals_nodata;
46112-atomic_t fscache_n_retrievals_nobufs;
46113-atomic_t fscache_n_retrievals_intr;
46114-atomic_t fscache_n_retrievals_nomem;
46115-atomic_t fscache_n_retrievals_object_dead;
46116-atomic_t fscache_n_retrieval_ops;
46117-atomic_t fscache_n_retrieval_op_waits;
46118+atomic_unchecked_t fscache_n_retrievals;
46119+atomic_unchecked_t fscache_n_retrievals_ok;
46120+atomic_unchecked_t fscache_n_retrievals_wait;
46121+atomic_unchecked_t fscache_n_retrievals_nodata;
46122+atomic_unchecked_t fscache_n_retrievals_nobufs;
46123+atomic_unchecked_t fscache_n_retrievals_intr;
46124+atomic_unchecked_t fscache_n_retrievals_nomem;
46125+atomic_unchecked_t fscache_n_retrievals_object_dead;
46126+atomic_unchecked_t fscache_n_retrieval_ops;
46127+atomic_unchecked_t fscache_n_retrieval_op_waits;
46128
46129-atomic_t fscache_n_stores;
46130-atomic_t fscache_n_stores_ok;
46131-atomic_t fscache_n_stores_again;
46132-atomic_t fscache_n_stores_nobufs;
46133-atomic_t fscache_n_stores_oom;
46134-atomic_t fscache_n_store_ops;
46135-atomic_t fscache_n_store_calls;
46136-atomic_t fscache_n_store_pages;
46137-atomic_t fscache_n_store_radix_deletes;
46138-atomic_t fscache_n_store_pages_over_limit;
46139+atomic_unchecked_t fscache_n_stores;
46140+atomic_unchecked_t fscache_n_stores_ok;
46141+atomic_unchecked_t fscache_n_stores_again;
46142+atomic_unchecked_t fscache_n_stores_nobufs;
46143+atomic_unchecked_t fscache_n_stores_oom;
46144+atomic_unchecked_t fscache_n_store_ops;
46145+atomic_unchecked_t fscache_n_store_calls;
46146+atomic_unchecked_t fscache_n_store_pages;
46147+atomic_unchecked_t fscache_n_store_radix_deletes;
46148+atomic_unchecked_t fscache_n_store_pages_over_limit;
46149
46150-atomic_t fscache_n_store_vmscan_not_storing;
46151-atomic_t fscache_n_store_vmscan_gone;
46152-atomic_t fscache_n_store_vmscan_busy;
46153-atomic_t fscache_n_store_vmscan_cancelled;
46154+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46155+atomic_unchecked_t fscache_n_store_vmscan_gone;
46156+atomic_unchecked_t fscache_n_store_vmscan_busy;
46157+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46158
46159-atomic_t fscache_n_marks;
46160-atomic_t fscache_n_uncaches;
46161+atomic_unchecked_t fscache_n_marks;
46162+atomic_unchecked_t fscache_n_uncaches;
46163
46164-atomic_t fscache_n_acquires;
46165-atomic_t fscache_n_acquires_null;
46166-atomic_t fscache_n_acquires_no_cache;
46167-atomic_t fscache_n_acquires_ok;
46168-atomic_t fscache_n_acquires_nobufs;
46169-atomic_t fscache_n_acquires_oom;
46170+atomic_unchecked_t fscache_n_acquires;
46171+atomic_unchecked_t fscache_n_acquires_null;
46172+atomic_unchecked_t fscache_n_acquires_no_cache;
46173+atomic_unchecked_t fscache_n_acquires_ok;
46174+atomic_unchecked_t fscache_n_acquires_nobufs;
46175+atomic_unchecked_t fscache_n_acquires_oom;
46176
46177-atomic_t fscache_n_updates;
46178-atomic_t fscache_n_updates_null;
46179-atomic_t fscache_n_updates_run;
46180+atomic_unchecked_t fscache_n_updates;
46181+atomic_unchecked_t fscache_n_updates_null;
46182+atomic_unchecked_t fscache_n_updates_run;
46183
46184-atomic_t fscache_n_relinquishes;
46185-atomic_t fscache_n_relinquishes_null;
46186-atomic_t fscache_n_relinquishes_waitcrt;
46187-atomic_t fscache_n_relinquishes_retire;
46188+atomic_unchecked_t fscache_n_relinquishes;
46189+atomic_unchecked_t fscache_n_relinquishes_null;
46190+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46191+atomic_unchecked_t fscache_n_relinquishes_retire;
46192
46193-atomic_t fscache_n_cookie_index;
46194-atomic_t fscache_n_cookie_data;
46195-atomic_t fscache_n_cookie_special;
46196+atomic_unchecked_t fscache_n_cookie_index;
46197+atomic_unchecked_t fscache_n_cookie_data;
46198+atomic_unchecked_t fscache_n_cookie_special;
46199
46200-atomic_t fscache_n_object_alloc;
46201-atomic_t fscache_n_object_no_alloc;
46202-atomic_t fscache_n_object_lookups;
46203-atomic_t fscache_n_object_lookups_negative;
46204-atomic_t fscache_n_object_lookups_positive;
46205-atomic_t fscache_n_object_lookups_timed_out;
46206-atomic_t fscache_n_object_created;
46207-atomic_t fscache_n_object_avail;
46208-atomic_t fscache_n_object_dead;
46209+atomic_unchecked_t fscache_n_object_alloc;
46210+atomic_unchecked_t fscache_n_object_no_alloc;
46211+atomic_unchecked_t fscache_n_object_lookups;
46212+atomic_unchecked_t fscache_n_object_lookups_negative;
46213+atomic_unchecked_t fscache_n_object_lookups_positive;
46214+atomic_unchecked_t fscache_n_object_lookups_timed_out;
46215+atomic_unchecked_t fscache_n_object_created;
46216+atomic_unchecked_t fscache_n_object_avail;
46217+atomic_unchecked_t fscache_n_object_dead;
46218
46219-atomic_t fscache_n_checkaux_none;
46220-atomic_t fscache_n_checkaux_okay;
46221-atomic_t fscache_n_checkaux_update;
46222-atomic_t fscache_n_checkaux_obsolete;
46223+atomic_unchecked_t fscache_n_checkaux_none;
46224+atomic_unchecked_t fscache_n_checkaux_okay;
46225+atomic_unchecked_t fscache_n_checkaux_update;
46226+atomic_unchecked_t fscache_n_checkaux_obsolete;
46227
46228 atomic_t fscache_n_cop_alloc_object;
46229 atomic_t fscache_n_cop_lookup_object;
46230@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46231 seq_puts(m, "FS-Cache statistics\n");
46232
46233 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46234- atomic_read(&fscache_n_cookie_index),
46235- atomic_read(&fscache_n_cookie_data),
46236- atomic_read(&fscache_n_cookie_special));
46237+ atomic_read_unchecked(&fscache_n_cookie_index),
46238+ atomic_read_unchecked(&fscache_n_cookie_data),
46239+ atomic_read_unchecked(&fscache_n_cookie_special));
46240
46241 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46242- atomic_read(&fscache_n_object_alloc),
46243- atomic_read(&fscache_n_object_no_alloc),
46244- atomic_read(&fscache_n_object_avail),
46245- atomic_read(&fscache_n_object_dead));
46246+ atomic_read_unchecked(&fscache_n_object_alloc),
46247+ atomic_read_unchecked(&fscache_n_object_no_alloc),
46248+ atomic_read_unchecked(&fscache_n_object_avail),
46249+ atomic_read_unchecked(&fscache_n_object_dead));
46250 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46251- atomic_read(&fscache_n_checkaux_none),
46252- atomic_read(&fscache_n_checkaux_okay),
46253- atomic_read(&fscache_n_checkaux_update),
46254- atomic_read(&fscache_n_checkaux_obsolete));
46255+ atomic_read_unchecked(&fscache_n_checkaux_none),
46256+ atomic_read_unchecked(&fscache_n_checkaux_okay),
46257+ atomic_read_unchecked(&fscache_n_checkaux_update),
46258+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46259
46260 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46261- atomic_read(&fscache_n_marks),
46262- atomic_read(&fscache_n_uncaches));
46263+ atomic_read_unchecked(&fscache_n_marks),
46264+ atomic_read_unchecked(&fscache_n_uncaches));
46265
46266 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46267 " oom=%u\n",
46268- atomic_read(&fscache_n_acquires),
46269- atomic_read(&fscache_n_acquires_null),
46270- atomic_read(&fscache_n_acquires_no_cache),
46271- atomic_read(&fscache_n_acquires_ok),
46272- atomic_read(&fscache_n_acquires_nobufs),
46273- atomic_read(&fscache_n_acquires_oom));
46274+ atomic_read_unchecked(&fscache_n_acquires),
46275+ atomic_read_unchecked(&fscache_n_acquires_null),
46276+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
46277+ atomic_read_unchecked(&fscache_n_acquires_ok),
46278+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
46279+ atomic_read_unchecked(&fscache_n_acquires_oom));
46280
46281 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46282- atomic_read(&fscache_n_object_lookups),
46283- atomic_read(&fscache_n_object_lookups_negative),
46284- atomic_read(&fscache_n_object_lookups_positive),
46285- atomic_read(&fscache_n_object_created),
46286- atomic_read(&fscache_n_object_lookups_timed_out));
46287+ atomic_read_unchecked(&fscache_n_object_lookups),
46288+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
46289+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
46290+ atomic_read_unchecked(&fscache_n_object_created),
46291+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46292
46293 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46294- atomic_read(&fscache_n_updates),
46295- atomic_read(&fscache_n_updates_null),
46296- atomic_read(&fscache_n_updates_run));
46297+ atomic_read_unchecked(&fscache_n_updates),
46298+ atomic_read_unchecked(&fscache_n_updates_null),
46299+ atomic_read_unchecked(&fscache_n_updates_run));
46300
46301 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46302- atomic_read(&fscache_n_relinquishes),
46303- atomic_read(&fscache_n_relinquishes_null),
46304- atomic_read(&fscache_n_relinquishes_waitcrt),
46305- atomic_read(&fscache_n_relinquishes_retire));
46306+ atomic_read_unchecked(&fscache_n_relinquishes),
46307+ atomic_read_unchecked(&fscache_n_relinquishes_null),
46308+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46309+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
46310
46311 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46312- atomic_read(&fscache_n_attr_changed),
46313- atomic_read(&fscache_n_attr_changed_ok),
46314- atomic_read(&fscache_n_attr_changed_nobufs),
46315- atomic_read(&fscache_n_attr_changed_nomem),
46316- atomic_read(&fscache_n_attr_changed_calls));
46317+ atomic_read_unchecked(&fscache_n_attr_changed),
46318+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
46319+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46320+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46321+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
46322
46323 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46324- atomic_read(&fscache_n_allocs),
46325- atomic_read(&fscache_n_allocs_ok),
46326- atomic_read(&fscache_n_allocs_wait),
46327- atomic_read(&fscache_n_allocs_nobufs),
46328- atomic_read(&fscache_n_allocs_intr));
46329+ atomic_read_unchecked(&fscache_n_allocs),
46330+ atomic_read_unchecked(&fscache_n_allocs_ok),
46331+ atomic_read_unchecked(&fscache_n_allocs_wait),
46332+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
46333+ atomic_read_unchecked(&fscache_n_allocs_intr));
46334 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46335- atomic_read(&fscache_n_alloc_ops),
46336- atomic_read(&fscache_n_alloc_op_waits),
46337- atomic_read(&fscache_n_allocs_object_dead));
46338+ atomic_read_unchecked(&fscache_n_alloc_ops),
46339+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
46340+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
46341
46342 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46343 " int=%u oom=%u\n",
46344- atomic_read(&fscache_n_retrievals),
46345- atomic_read(&fscache_n_retrievals_ok),
46346- atomic_read(&fscache_n_retrievals_wait),
46347- atomic_read(&fscache_n_retrievals_nodata),
46348- atomic_read(&fscache_n_retrievals_nobufs),
46349- atomic_read(&fscache_n_retrievals_intr),
46350- atomic_read(&fscache_n_retrievals_nomem));
46351+ atomic_read_unchecked(&fscache_n_retrievals),
46352+ atomic_read_unchecked(&fscache_n_retrievals_ok),
46353+ atomic_read_unchecked(&fscache_n_retrievals_wait),
46354+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
46355+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46356+ atomic_read_unchecked(&fscache_n_retrievals_intr),
46357+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
46358 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46359- atomic_read(&fscache_n_retrieval_ops),
46360- atomic_read(&fscache_n_retrieval_op_waits),
46361- atomic_read(&fscache_n_retrievals_object_dead));
46362+ atomic_read_unchecked(&fscache_n_retrieval_ops),
46363+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46364+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46365
46366 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46367- atomic_read(&fscache_n_stores),
46368- atomic_read(&fscache_n_stores_ok),
46369- atomic_read(&fscache_n_stores_again),
46370- atomic_read(&fscache_n_stores_nobufs),
46371- atomic_read(&fscache_n_stores_oom));
46372+ atomic_read_unchecked(&fscache_n_stores),
46373+ atomic_read_unchecked(&fscache_n_stores_ok),
46374+ atomic_read_unchecked(&fscache_n_stores_again),
46375+ atomic_read_unchecked(&fscache_n_stores_nobufs),
46376+ atomic_read_unchecked(&fscache_n_stores_oom));
46377 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46378- atomic_read(&fscache_n_store_ops),
46379- atomic_read(&fscache_n_store_calls),
46380- atomic_read(&fscache_n_store_pages),
46381- atomic_read(&fscache_n_store_radix_deletes),
46382- atomic_read(&fscache_n_store_pages_over_limit));
46383+ atomic_read_unchecked(&fscache_n_store_ops),
46384+ atomic_read_unchecked(&fscache_n_store_calls),
46385+ atomic_read_unchecked(&fscache_n_store_pages),
46386+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
46387+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46388
46389 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46390- atomic_read(&fscache_n_store_vmscan_not_storing),
46391- atomic_read(&fscache_n_store_vmscan_gone),
46392- atomic_read(&fscache_n_store_vmscan_busy),
46393- atomic_read(&fscache_n_store_vmscan_cancelled));
46394+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46395+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46396+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46397+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46398
46399 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46400- atomic_read(&fscache_n_op_pend),
46401- atomic_read(&fscache_n_op_run),
46402- atomic_read(&fscache_n_op_enqueue),
46403- atomic_read(&fscache_n_op_cancelled),
46404- atomic_read(&fscache_n_op_rejected));
46405+ atomic_read_unchecked(&fscache_n_op_pend),
46406+ atomic_read_unchecked(&fscache_n_op_run),
46407+ atomic_read_unchecked(&fscache_n_op_enqueue),
46408+ atomic_read_unchecked(&fscache_n_op_cancelled),
46409+ atomic_read_unchecked(&fscache_n_op_rejected));
46410 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46411- atomic_read(&fscache_n_op_deferred_release),
46412- atomic_read(&fscache_n_op_release),
46413- atomic_read(&fscache_n_op_gc));
46414+ atomic_read_unchecked(&fscache_n_op_deferred_release),
46415+ atomic_read_unchecked(&fscache_n_op_release),
46416+ atomic_read_unchecked(&fscache_n_op_gc));
46417
46418 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46419 atomic_read(&fscache_n_cop_alloc_object),
46420diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46421index 3426521..3b75162 100644
46422--- a/fs/fuse/cuse.c
46423+++ b/fs/fuse/cuse.c
46424@@ -587,10 +587,12 @@ static int __init cuse_init(void)
46425 INIT_LIST_HEAD(&cuse_conntbl[i]);
46426
46427 /* inherit and extend fuse_dev_operations */
46428- cuse_channel_fops = fuse_dev_operations;
46429- cuse_channel_fops.owner = THIS_MODULE;
46430- cuse_channel_fops.open = cuse_channel_open;
46431- cuse_channel_fops.release = cuse_channel_release;
46432+ pax_open_kernel();
46433+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46434+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46435+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
46436+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
46437+ pax_close_kernel();
46438
46439 cuse_class = class_create(THIS_MODULE, "cuse");
46440 if (IS_ERR(cuse_class))
46441diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46442index 5f3368a..8306426 100644
46443--- a/fs/fuse/dev.c
46444+++ b/fs/fuse/dev.c
46445@@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46446 ret = 0;
46447 pipe_lock(pipe);
46448
46449- if (!pipe->readers) {
46450+ if (!atomic_read(&pipe->readers)) {
46451 send_sig(SIGPIPE, current, 0);
46452 if (!ret)
46453 ret = -EPIPE;
46454diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46455index 2066328..f5add3b 100644
46456--- a/fs/fuse/dir.c
46457+++ b/fs/fuse/dir.c
46458@@ -1175,7 +1175,7 @@ static char *read_link(struct dentry *dentry)
46459 return link;
46460 }
46461
46462-static void free_link(char *link)
46463+static void free_link(const char *link)
46464 {
46465 if (!IS_ERR(link))
46466 free_page((unsigned long) link);
46467diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46468index 5698746..6086012 100644
46469--- a/fs/gfs2/inode.c
46470+++ b/fs/gfs2/inode.c
46471@@ -1487,7 +1487,7 @@ out:
46472
46473 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46474 {
46475- char *s = nd_get_link(nd);
46476+ const char *s = nd_get_link(nd);
46477 if (!IS_ERR(s))
46478 kfree(s);
46479 }
46480diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46481index c60267e..193d9e4 100644
46482--- a/fs/hugetlbfs/inode.c
46483+++ b/fs/hugetlbfs/inode.c
46484@@ -902,7 +902,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46485 .kill_sb = kill_litter_super,
46486 };
46487
46488-static struct vfsmount *hugetlbfs_vfsmount;
46489+struct vfsmount *hugetlbfs_vfsmount;
46490
46491 static int can_do_hugetlb_shm(void)
46492 {
46493diff --git a/fs/inode.c b/fs/inode.c
46494index 83ab215..8842101 100644
46495--- a/fs/inode.c
46496+++ b/fs/inode.c
46497@@ -870,8 +870,8 @@ unsigned int get_next_ino(void)
46498
46499 #ifdef CONFIG_SMP
46500 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46501- static atomic_t shared_last_ino;
46502- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46503+ static atomic_unchecked_t shared_last_ino;
46504+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46505
46506 res = next - LAST_INO_BATCH;
46507 }
46508diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46509index eafb8d3..f423d37 100644
46510--- a/fs/jffs2/erase.c
46511+++ b/fs/jffs2/erase.c
46512@@ -438,7 +438,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46513 struct jffs2_unknown_node marker = {
46514 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46515 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46516- .totlen = cpu_to_je32(c->cleanmarker_size)
46517+ .totlen = cpu_to_je32(c->cleanmarker_size),
46518+ .hdr_crc = cpu_to_je32(0)
46519 };
46520
46521 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46522diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46523index 30e8f47..21f600c 100644
46524--- a/fs/jffs2/wbuf.c
46525+++ b/fs/jffs2/wbuf.c
46526@@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46527 {
46528 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46529 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46530- .totlen = constant_cpu_to_je32(8)
46531+ .totlen = constant_cpu_to_je32(8),
46532+ .hdr_crc = constant_cpu_to_je32(0)
46533 };
46534
46535 /*
46536diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46537index 682bca6..86b8e6e 100644
46538--- a/fs/jfs/super.c
46539+++ b/fs/jfs/super.c
46540@@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
46541
46542 jfs_inode_cachep =
46543 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46544- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46545+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46546 init_once);
46547 if (jfs_inode_cachep == NULL)
46548 return -ENOMEM;
46549diff --git a/fs/libfs.c b/fs/libfs.c
46550index 5b2dbb3..7442d54 100644
46551--- a/fs/libfs.c
46552+++ b/fs/libfs.c
46553@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46554
46555 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46556 struct dentry *next;
46557+ char d_name[sizeof(next->d_iname)];
46558+ const unsigned char *name;
46559+
46560 next = list_entry(p, struct dentry, d_u.d_child);
46561 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46562 if (!simple_positive(next)) {
46563@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46564
46565 spin_unlock(&next->d_lock);
46566 spin_unlock(&dentry->d_lock);
46567- if (filldir(dirent, next->d_name.name,
46568+ name = next->d_name.name;
46569+ if (name == next->d_iname) {
46570+ memcpy(d_name, name, next->d_name.len);
46571+ name = d_name;
46572+ }
46573+ if (filldir(dirent, name,
46574 next->d_name.len, filp->f_pos,
46575 next->d_inode->i_ino,
46576 dt_type(next->d_inode)) < 0)
46577diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46578index 8392cb8..80d6193 100644
46579--- a/fs/lockd/clntproc.c
46580+++ b/fs/lockd/clntproc.c
46581@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46582 /*
46583 * Cookie counter for NLM requests
46584 */
46585-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46586+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46587
46588 void nlmclnt_next_cookie(struct nlm_cookie *c)
46589 {
46590- u32 cookie = atomic_inc_return(&nlm_cookie);
46591+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46592
46593 memcpy(c->data, &cookie, 4);
46594 c->len=4;
46595diff --git a/fs/locks.c b/fs/locks.c
46596index 0d68f1f..f216b79 100644
46597--- a/fs/locks.c
46598+++ b/fs/locks.c
46599@@ -2075,16 +2075,16 @@ void locks_remove_flock(struct file *filp)
46600 return;
46601
46602 if (filp->f_op && filp->f_op->flock) {
46603- struct file_lock fl = {
46604+ struct file_lock flock = {
46605 .fl_pid = current->tgid,
46606 .fl_file = filp,
46607 .fl_flags = FL_FLOCK,
46608 .fl_type = F_UNLCK,
46609 .fl_end = OFFSET_MAX,
46610 };
46611- filp->f_op->flock(filp, F_SETLKW, &fl);
46612- if (fl.fl_ops && fl.fl_ops->fl_release_private)
46613- fl.fl_ops->fl_release_private(&fl);
46614+ filp->f_op->flock(filp, F_SETLKW, &flock);
46615+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
46616+ flock.fl_ops->fl_release_private(&flock);
46617 }
46618
46619 lock_flocks();
46620diff --git a/fs/namei.c b/fs/namei.c
46621index 46ea9cc..c7cf3a3 100644
46622--- a/fs/namei.c
46623+++ b/fs/namei.c
46624@@ -278,16 +278,32 @@ int generic_permission(struct inode *inode, int mask)
46625 if (ret != -EACCES)
46626 return ret;
46627
46628+#ifdef CONFIG_GRKERNSEC
46629+ /* we'll block if we have to log due to a denied capability use */
46630+ if (mask & MAY_NOT_BLOCK)
46631+ return -ECHILD;
46632+#endif
46633+
46634 if (S_ISDIR(inode->i_mode)) {
46635 /* DACs are overridable for directories */
46636- if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46637- return 0;
46638 if (!(mask & MAY_WRITE))
46639- if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46640+ if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46641+ ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46642 return 0;
46643+ if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46644+ return 0;
46645 return -EACCES;
46646 }
46647 /*
46648+ * Searching includes executable on directories, else just read.
46649+ */
46650+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46651+ if (mask == MAY_READ)
46652+ if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46653+ ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46654+ return 0;
46655+
46656+ /*
46657 * Read/write DACs are always overridable.
46658 * Executable DACs are overridable when there is
46659 * at least one exec bit set.
46660@@ -296,14 +312,6 @@ int generic_permission(struct inode *inode, int mask)
46661 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46662 return 0;
46663
46664- /*
46665- * Searching includes executable on directories, else just read.
46666- */
46667- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46668- if (mask == MAY_READ)
46669- if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46670- return 0;
46671-
46672 return -EACCES;
46673 }
46674
46675@@ -652,11 +660,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
46676 return error;
46677 }
46678
46679+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
46680+ dentry->d_inode, dentry, nd->path.mnt)) {
46681+ error = -EACCES;
46682+ *p = ERR_PTR(error); /* no ->put_link(), please */
46683+ path_put(&nd->path);
46684+ return error;
46685+ }
46686+
46687 nd->last_type = LAST_BIND;
46688 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
46689 error = PTR_ERR(*p);
46690 if (!IS_ERR(*p)) {
46691- char *s = nd_get_link(nd);
46692+ const char *s = nd_get_link(nd);
46693 error = 0;
46694 if (s)
46695 error = __vfs_follow_link(nd, s);
46696@@ -1650,6 +1666,21 @@ static int path_lookupat(int dfd, const char *name,
46697 if (!err)
46698 err = complete_walk(nd);
46699
46700+ if (!(nd->flags & LOOKUP_PARENT)) {
46701+#ifdef CONFIG_GRKERNSEC
46702+ if (flags & LOOKUP_RCU) {
46703+ if (!err)
46704+ path_put(&nd->path);
46705+ err = -ECHILD;
46706+ } else
46707+#endif
46708+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46709+ if (!err)
46710+ path_put(&nd->path);
46711+ err = -ENOENT;
46712+ }
46713+ }
46714+
46715 if (!err && nd->flags & LOOKUP_DIRECTORY) {
46716 if (!nd->inode->i_op->lookup) {
46717 path_put(&nd->path);
46718@@ -1677,6 +1708,15 @@ static int do_path_lookup(int dfd, const char *name,
46719 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
46720
46721 if (likely(!retval)) {
46722+ if (*name != '/' && nd->path.dentry && nd->inode) {
46723+#ifdef CONFIG_GRKERNSEC
46724+ if (flags & LOOKUP_RCU)
46725+ return -ECHILD;
46726+#endif
46727+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
46728+ return -ENOENT;
46729+ }
46730+
46731 if (unlikely(!audit_dummy_context())) {
46732 if (nd->path.dentry && nd->inode)
46733 audit_inode(name, nd->path.dentry);
46734@@ -2071,6 +2111,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
46735 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
46736 return -EPERM;
46737
46738+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
46739+ return -EPERM;
46740+ if (gr_handle_rawio(inode))
46741+ return -EPERM;
46742+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
46743+ return -EACCES;
46744+
46745 return 0;
46746 }
46747
46748@@ -2132,6 +2179,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46749 error = complete_walk(nd);
46750 if (error)
46751 return ERR_PTR(error);
46752+#ifdef CONFIG_GRKERNSEC
46753+ if (nd->flags & LOOKUP_RCU) {
46754+ error = -ECHILD;
46755+ goto exit;
46756+ }
46757+#endif
46758+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46759+ error = -ENOENT;
46760+ goto exit;
46761+ }
46762 audit_inode(pathname, nd->path.dentry);
46763 if (open_flag & O_CREAT) {
46764 error = -EISDIR;
46765@@ -2142,6 +2199,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46766 error = complete_walk(nd);
46767 if (error)
46768 return ERR_PTR(error);
46769+#ifdef CONFIG_GRKERNSEC
46770+ if (nd->flags & LOOKUP_RCU) {
46771+ error = -ECHILD;
46772+ goto exit;
46773+ }
46774+#endif
46775+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
46776+ error = -ENOENT;
46777+ goto exit;
46778+ }
46779 audit_inode(pathname, dir);
46780 goto ok;
46781 }
46782@@ -2163,6 +2230,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46783 error = complete_walk(nd);
46784 if (error)
46785 return ERR_PTR(error);
46786+#ifdef CONFIG_GRKERNSEC
46787+ if (nd->flags & LOOKUP_RCU) {
46788+ error = -ECHILD;
46789+ goto exit;
46790+ }
46791+#endif
46792+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46793+ error = -ENOENT;
46794+ goto exit;
46795+ }
46796
46797 error = -ENOTDIR;
46798 if (nd->flags & LOOKUP_DIRECTORY) {
46799@@ -2203,6 +2280,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46800 /* Negative dentry, just create the file */
46801 if (!dentry->d_inode) {
46802 umode_t mode = op->mode;
46803+
46804+ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
46805+ error = -EACCES;
46806+ goto exit_mutex_unlock;
46807+ }
46808+
46809 if (!IS_POSIXACL(dir->d_inode))
46810 mode &= ~current_umask();
46811 /*
46812@@ -2226,6 +2309,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46813 error = vfs_create(dir->d_inode, dentry, mode, nd);
46814 if (error)
46815 goto exit_mutex_unlock;
46816+ else
46817+ gr_handle_create(path->dentry, path->mnt);
46818 mutex_unlock(&dir->d_inode->i_mutex);
46819 dput(nd->path.dentry);
46820 nd->path.dentry = dentry;
46821@@ -2235,6 +2320,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46822 /*
46823 * It already exists.
46824 */
46825+
46826+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
46827+ error = -ENOENT;
46828+ goto exit_mutex_unlock;
46829+ }
46830+
46831+ /* only check if O_CREAT is specified, all other checks need to go
46832+ into may_open */
46833+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
46834+ error = -EACCES;
46835+ goto exit_mutex_unlock;
46836+ }
46837+
46838 mutex_unlock(&dir->d_inode->i_mutex);
46839 audit_inode(pathname, path->dentry);
46840
46841@@ -2447,6 +2545,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
46842 *path = nd.path;
46843 return dentry;
46844 eexist:
46845+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
46846+ dput(dentry);
46847+ dentry = ERR_PTR(-ENOENT);
46848+ goto fail;
46849+ }
46850 dput(dentry);
46851 dentry = ERR_PTR(-EEXIST);
46852 fail:
46853@@ -2469,6 +2572,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
46854 }
46855 EXPORT_SYMBOL(user_path_create);
46856
46857+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
46858+{
46859+ char *tmp = getname(pathname);
46860+ struct dentry *res;
46861+ if (IS_ERR(tmp))
46862+ return ERR_CAST(tmp);
46863+ res = kern_path_create(dfd, tmp, path, is_dir);
46864+ if (IS_ERR(res))
46865+ putname(tmp);
46866+ else
46867+ *to = tmp;
46868+ return res;
46869+}
46870+
46871 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
46872 {
46873 int error = may_create(dir, dentry);
46874@@ -2536,6 +2653,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46875 error = mnt_want_write(path.mnt);
46876 if (error)
46877 goto out_dput;
46878+
46879+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
46880+ error = -EPERM;
46881+ goto out_drop_write;
46882+ }
46883+
46884+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
46885+ error = -EACCES;
46886+ goto out_drop_write;
46887+ }
46888+
46889 error = security_path_mknod(&path, dentry, mode, dev);
46890 if (error)
46891 goto out_drop_write;
46892@@ -2553,6 +2681,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46893 }
46894 out_drop_write:
46895 mnt_drop_write(path.mnt);
46896+
46897+ if (!error)
46898+ gr_handle_create(dentry, path.mnt);
46899 out_dput:
46900 dput(dentry);
46901 mutex_unlock(&path.dentry->d_inode->i_mutex);
46902@@ -2602,12 +2733,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
46903 error = mnt_want_write(path.mnt);
46904 if (error)
46905 goto out_dput;
46906+
46907+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
46908+ error = -EACCES;
46909+ goto out_drop_write;
46910+ }
46911+
46912 error = security_path_mkdir(&path, dentry, mode);
46913 if (error)
46914 goto out_drop_write;
46915 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
46916 out_drop_write:
46917 mnt_drop_write(path.mnt);
46918+
46919+ if (!error)
46920+ gr_handle_create(dentry, path.mnt);
46921 out_dput:
46922 dput(dentry);
46923 mutex_unlock(&path.dentry->d_inode->i_mutex);
46924@@ -2687,6 +2827,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46925 char * name;
46926 struct dentry *dentry;
46927 struct nameidata nd;
46928+ ino_t saved_ino = 0;
46929+ dev_t saved_dev = 0;
46930
46931 error = user_path_parent(dfd, pathname, &nd, &name);
46932 if (error)
46933@@ -2715,6 +2857,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
46934 error = -ENOENT;
46935 goto exit3;
46936 }
46937+
46938+ saved_ino = dentry->d_inode->i_ino;
46939+ saved_dev = gr_get_dev_from_dentry(dentry);
46940+
46941+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
46942+ error = -EACCES;
46943+ goto exit3;
46944+ }
46945+
46946 error = mnt_want_write(nd.path.mnt);
46947 if (error)
46948 goto exit3;
46949@@ -2722,6 +2873,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46950 if (error)
46951 goto exit4;
46952 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
46953+ if (!error && (saved_dev || saved_ino))
46954+ gr_handle_delete(saved_ino, saved_dev);
46955 exit4:
46956 mnt_drop_write(nd.path.mnt);
46957 exit3:
46958@@ -2784,6 +2937,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46959 struct dentry *dentry;
46960 struct nameidata nd;
46961 struct inode *inode = NULL;
46962+ ino_t saved_ino = 0;
46963+ dev_t saved_dev = 0;
46964
46965 error = user_path_parent(dfd, pathname, &nd, &name);
46966 if (error)
46967@@ -2806,6 +2961,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46968 if (!inode)
46969 goto slashes;
46970 ihold(inode);
46971+
46972+ if (inode->i_nlink <= 1) {
46973+ saved_ino = inode->i_ino;
46974+ saved_dev = gr_get_dev_from_dentry(dentry);
46975+ }
46976+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
46977+ error = -EACCES;
46978+ goto exit2;
46979+ }
46980+
46981 error = mnt_want_write(nd.path.mnt);
46982 if (error)
46983 goto exit2;
46984@@ -2813,6 +2978,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46985 if (error)
46986 goto exit3;
46987 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
46988+ if (!error && (saved_ino || saved_dev))
46989+ gr_handle_delete(saved_ino, saved_dev);
46990 exit3:
46991 mnt_drop_write(nd.path.mnt);
46992 exit2:
46993@@ -2888,10 +3055,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
46994 error = mnt_want_write(path.mnt);
46995 if (error)
46996 goto out_dput;
46997+
46998+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
46999+ error = -EACCES;
47000+ goto out_drop_write;
47001+ }
47002+
47003 error = security_path_symlink(&path, dentry, from);
47004 if (error)
47005 goto out_drop_write;
47006 error = vfs_symlink(path.dentry->d_inode, dentry, from);
47007+ if (!error)
47008+ gr_handle_create(dentry, path.mnt);
47009 out_drop_write:
47010 mnt_drop_write(path.mnt);
47011 out_dput:
47012@@ -2963,6 +3138,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47013 {
47014 struct dentry *new_dentry;
47015 struct path old_path, new_path;
47016+ char *to = NULL;
47017 int how = 0;
47018 int error;
47019
47020@@ -2986,7 +3162,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47021 if (error)
47022 return error;
47023
47024- new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47025+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47026 error = PTR_ERR(new_dentry);
47027 if (IS_ERR(new_dentry))
47028 goto out;
47029@@ -2997,13 +3173,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47030 error = mnt_want_write(new_path.mnt);
47031 if (error)
47032 goto out_dput;
47033+
47034+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47035+ old_path.dentry->d_inode,
47036+ old_path.dentry->d_inode->i_mode, to)) {
47037+ error = -EACCES;
47038+ goto out_drop_write;
47039+ }
47040+
47041+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47042+ old_path.dentry, old_path.mnt, to)) {
47043+ error = -EACCES;
47044+ goto out_drop_write;
47045+ }
47046+
47047 error = security_path_link(old_path.dentry, &new_path, new_dentry);
47048 if (error)
47049 goto out_drop_write;
47050 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
47051+ if (!error)
47052+ gr_handle_create(new_dentry, new_path.mnt);
47053 out_drop_write:
47054 mnt_drop_write(new_path.mnt);
47055 out_dput:
47056+ putname(to);
47057 dput(new_dentry);
47058 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
47059 path_put(&new_path);
47060@@ -3231,6 +3424,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47061 if (new_dentry == trap)
47062 goto exit5;
47063
47064+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47065+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
47066+ to);
47067+ if (error)
47068+ goto exit5;
47069+
47070 error = mnt_want_write(oldnd.path.mnt);
47071 if (error)
47072 goto exit5;
47073@@ -3240,6 +3439,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47074 goto exit6;
47075 error = vfs_rename(old_dir->d_inode, old_dentry,
47076 new_dir->d_inode, new_dentry);
47077+ if (!error)
47078+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47079+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47080 exit6:
47081 mnt_drop_write(oldnd.path.mnt);
47082 exit5:
47083@@ -3265,6 +3467,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
47084
47085 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47086 {
47087+ char tmpbuf[64];
47088+ const char *newlink;
47089 int len;
47090
47091 len = PTR_ERR(link);
47092@@ -3274,7 +3478,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
47093 len = strlen(link);
47094 if (len > (unsigned) buflen)
47095 len = buflen;
47096- if (copy_to_user(buffer, link, len))
47097+
47098+ if (len < sizeof(tmpbuf)) {
47099+ memcpy(tmpbuf, link, len);
47100+ newlink = tmpbuf;
47101+ } else
47102+ newlink = link;
47103+
47104+ if (copy_to_user(buffer, newlink, len))
47105 len = -EFAULT;
47106 out:
47107 return len;
47108diff --git a/fs/namespace.c b/fs/namespace.c
47109index e608199..9609cb9 100644
47110--- a/fs/namespace.c
47111+++ b/fs/namespace.c
47112@@ -1155,6 +1155,9 @@ static int do_umount(struct mount *mnt, int flags)
47113 if (!(sb->s_flags & MS_RDONLY))
47114 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47115 up_write(&sb->s_umount);
47116+
47117+ gr_log_remount(mnt->mnt_devname, retval);
47118+
47119 return retval;
47120 }
47121
47122@@ -1174,6 +1177,9 @@ static int do_umount(struct mount *mnt, int flags)
47123 br_write_unlock(vfsmount_lock);
47124 up_write(&namespace_sem);
47125 release_mounts(&umount_list);
47126+
47127+ gr_log_unmount(mnt->mnt_devname, retval);
47128+
47129 return retval;
47130 }
47131
47132@@ -2175,6 +2181,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47133 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47134 MS_STRICTATIME);
47135
47136+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47137+ retval = -EPERM;
47138+ goto dput_out;
47139+ }
47140+
47141+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47142+ retval = -EPERM;
47143+ goto dput_out;
47144+ }
47145+
47146 if (flags & MS_REMOUNT)
47147 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47148 data_page);
47149@@ -2189,6 +2205,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47150 dev_name, data_page);
47151 dput_out:
47152 path_put(&path);
47153+
47154+ gr_log_mount(dev_name, dir_name, retval);
47155+
47156 return retval;
47157 }
47158
47159@@ -2470,6 +2489,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47160 if (error)
47161 goto out2;
47162
47163+ if (gr_handle_chroot_pivot()) {
47164+ error = -EPERM;
47165+ goto out2;
47166+ }
47167+
47168 get_fs_root(current->fs, &root);
47169 error = lock_mount(&old);
47170 if (error)
47171diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47172index f649fba..236bf92 100644
47173--- a/fs/nfs/inode.c
47174+++ b/fs/nfs/inode.c
47175@@ -151,7 +151,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47176 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47177 nfsi->attrtimeo_timestamp = jiffies;
47178
47179- memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47180+ memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47181 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47182 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47183 else
47184@@ -1003,16 +1003,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47185 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47186 }
47187
47188-static atomic_long_t nfs_attr_generation_counter;
47189+static atomic_long_unchecked_t nfs_attr_generation_counter;
47190
47191 static unsigned long nfs_read_attr_generation_counter(void)
47192 {
47193- return atomic_long_read(&nfs_attr_generation_counter);
47194+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47195 }
47196
47197 unsigned long nfs_inc_attr_generation_counter(void)
47198 {
47199- return atomic_long_inc_return(&nfs_attr_generation_counter);
47200+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47201 }
47202
47203 void nfs_fattr_init(struct nfs_fattr *fattr)
47204diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47205index b96fe94..a4dbece 100644
47206--- a/fs/nfsd/vfs.c
47207+++ b/fs/nfsd/vfs.c
47208@@ -925,7 +925,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47209 } else {
47210 oldfs = get_fs();
47211 set_fs(KERNEL_DS);
47212- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47213+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47214 set_fs(oldfs);
47215 }
47216
47217@@ -1029,7 +1029,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47218
47219 /* Write the data. */
47220 oldfs = get_fs(); set_fs(KERNEL_DS);
47221- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47222+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47223 set_fs(oldfs);
47224 if (host_err < 0)
47225 goto out_nfserr;
47226@@ -1564,7 +1564,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47227 */
47228
47229 oldfs = get_fs(); set_fs(KERNEL_DS);
47230- host_err = inode->i_op->readlink(dentry, buf, *lenp);
47231+ host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
47232 set_fs(oldfs);
47233
47234 if (host_err < 0)
47235diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47236index 3568c8a..e0240d8 100644
47237--- a/fs/notify/fanotify/fanotify_user.c
47238+++ b/fs/notify/fanotify/fanotify_user.c
47239@@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47240 goto out_close_fd;
47241
47242 ret = -EFAULT;
47243- if (copy_to_user(buf, &fanotify_event_metadata,
47244+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47245+ copy_to_user(buf, &fanotify_event_metadata,
47246 fanotify_event_metadata.event_len))
47247 goto out_kill_access_response;
47248
47249diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47250index ee18815..7aa5d01 100644
47251--- a/fs/notify/notification.c
47252+++ b/fs/notify/notification.c
47253@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47254 * get set to 0 so it will never get 'freed'
47255 */
47256 static struct fsnotify_event *q_overflow_event;
47257-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47258+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47259
47260 /**
47261 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47262@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47263 */
47264 u32 fsnotify_get_cookie(void)
47265 {
47266- return atomic_inc_return(&fsnotify_sync_cookie);
47267+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47268 }
47269 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47270
47271diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47272index 99e3610..02c1068 100644
47273--- a/fs/ntfs/dir.c
47274+++ b/fs/ntfs/dir.c
47275@@ -1329,7 +1329,7 @@ find_next_index_buffer:
47276 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47277 ~(s64)(ndir->itype.index.block_size - 1)));
47278 /* Bounds checks. */
47279- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47280+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47281 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47282 "inode 0x%lx or driver bug.", vdir->i_ino);
47283 goto err_out;
47284diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47285index c587e2d..3641eaa 100644
47286--- a/fs/ntfs/file.c
47287+++ b/fs/ntfs/file.c
47288@@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47289 #endif /* NTFS_RW */
47290 };
47291
47292-const struct file_operations ntfs_empty_file_ops = {};
47293+const struct file_operations ntfs_empty_file_ops __read_only;
47294
47295-const struct inode_operations ntfs_empty_inode_ops = {};
47296+const struct inode_operations ntfs_empty_inode_ops __read_only;
47297diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47298index 210c352..a174f83 100644
47299--- a/fs/ocfs2/localalloc.c
47300+++ b/fs/ocfs2/localalloc.c
47301@@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47302 goto bail;
47303 }
47304
47305- atomic_inc(&osb->alloc_stats.moves);
47306+ atomic_inc_unchecked(&osb->alloc_stats.moves);
47307
47308 bail:
47309 if (handle)
47310diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47311index d355e6e..578d905 100644
47312--- a/fs/ocfs2/ocfs2.h
47313+++ b/fs/ocfs2/ocfs2.h
47314@@ -235,11 +235,11 @@ enum ocfs2_vol_state
47315
47316 struct ocfs2_alloc_stats
47317 {
47318- atomic_t moves;
47319- atomic_t local_data;
47320- atomic_t bitmap_data;
47321- atomic_t bg_allocs;
47322- atomic_t bg_extends;
47323+ atomic_unchecked_t moves;
47324+ atomic_unchecked_t local_data;
47325+ atomic_unchecked_t bitmap_data;
47326+ atomic_unchecked_t bg_allocs;
47327+ atomic_unchecked_t bg_extends;
47328 };
47329
47330 enum ocfs2_local_alloc_state
47331diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47332index f169da4..9112253 100644
47333--- a/fs/ocfs2/suballoc.c
47334+++ b/fs/ocfs2/suballoc.c
47335@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47336 mlog_errno(status);
47337 goto bail;
47338 }
47339- atomic_inc(&osb->alloc_stats.bg_extends);
47340+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47341
47342 /* You should never ask for this much metadata */
47343 BUG_ON(bits_wanted >
47344@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47345 mlog_errno(status);
47346 goto bail;
47347 }
47348- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47349+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47350
47351 *suballoc_loc = res.sr_bg_blkno;
47352 *suballoc_bit_start = res.sr_bit_offset;
47353@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47354 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47355 res->sr_bits);
47356
47357- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47358+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47359
47360 BUG_ON(res->sr_bits != 1);
47361
47362@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47363 mlog_errno(status);
47364 goto bail;
47365 }
47366- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47367+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47368
47369 BUG_ON(res.sr_bits != 1);
47370
47371@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47372 cluster_start,
47373 num_clusters);
47374 if (!status)
47375- atomic_inc(&osb->alloc_stats.local_data);
47376+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
47377 } else {
47378 if (min_clusters > (osb->bitmap_cpg - 1)) {
47379 /* The only paths asking for contiguousness
47380@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47381 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47382 res.sr_bg_blkno,
47383 res.sr_bit_offset);
47384- atomic_inc(&osb->alloc_stats.bitmap_data);
47385+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47386 *num_clusters = res.sr_bits;
47387 }
47388 }
47389diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47390index 604e12c..8426483 100644
47391--- a/fs/ocfs2/super.c
47392+++ b/fs/ocfs2/super.c
47393@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47394 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47395 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47396 "Stats",
47397- atomic_read(&osb->alloc_stats.bitmap_data),
47398- atomic_read(&osb->alloc_stats.local_data),
47399- atomic_read(&osb->alloc_stats.bg_allocs),
47400- atomic_read(&osb->alloc_stats.moves),
47401- atomic_read(&osb->alloc_stats.bg_extends));
47402+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47403+ atomic_read_unchecked(&osb->alloc_stats.local_data),
47404+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47405+ atomic_read_unchecked(&osb->alloc_stats.moves),
47406+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47407
47408 out += snprintf(buf + out, len - out,
47409 "%10s => State: %u Descriptor: %llu Size: %u bits "
47410@@ -2117,11 +2117,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47411 spin_lock_init(&osb->osb_xattr_lock);
47412 ocfs2_init_steal_slots(osb);
47413
47414- atomic_set(&osb->alloc_stats.moves, 0);
47415- atomic_set(&osb->alloc_stats.local_data, 0);
47416- atomic_set(&osb->alloc_stats.bitmap_data, 0);
47417- atomic_set(&osb->alloc_stats.bg_allocs, 0);
47418- atomic_set(&osb->alloc_stats.bg_extends, 0);
47419+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47420+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47421+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47422+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47423+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47424
47425 /* Copy the blockcheck stats from the superblock probe */
47426 osb->osb_ecc_stats = *stats;
47427diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
47428index 5d22872..523db20 100644
47429--- a/fs/ocfs2/symlink.c
47430+++ b/fs/ocfs2/symlink.c
47431@@ -142,7 +142,7 @@ bail:
47432
47433 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
47434 {
47435- char *link = nd_get_link(nd);
47436+ const char *link = nd_get_link(nd);
47437 if (!IS_ERR(link))
47438 kfree(link);
47439 }
47440diff --git a/fs/open.c b/fs/open.c
47441index 77becc0..aad7bd9 100644
47442--- a/fs/open.c
47443+++ b/fs/open.c
47444@@ -112,6 +112,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47445 error = locks_verify_truncate(inode, NULL, length);
47446 if (!error)
47447 error = security_path_truncate(&path);
47448+
47449+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47450+ error = -EACCES;
47451+
47452 if (!error)
47453 error = do_truncate(path.dentry, length, 0, NULL);
47454
47455@@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47456 if (__mnt_is_readonly(path.mnt))
47457 res = -EROFS;
47458
47459+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47460+ res = -EACCES;
47461+
47462 out_path_release:
47463 path_put(&path);
47464 out:
47465@@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47466 if (error)
47467 goto dput_and_out;
47468
47469+ gr_log_chdir(path.dentry, path.mnt);
47470+
47471 set_fs_pwd(current->fs, &path);
47472
47473 dput_and_out:
47474@@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47475 goto out_putf;
47476
47477 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47478+
47479+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47480+ error = -EPERM;
47481+
47482+ if (!error)
47483+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47484+
47485 if (!error)
47486 set_fs_pwd(current->fs, &file->f_path);
47487 out_putf:
47488@@ -438,7 +454,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47489 if (error)
47490 goto dput_and_out;
47491
47492+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47493+ goto dput_and_out;
47494+
47495 set_fs_root(current->fs, &path);
47496+
47497+ gr_handle_chroot_chdir(&path);
47498+
47499 error = 0;
47500 dput_and_out:
47501 path_put(&path);
47502@@ -456,6 +478,16 @@ static int chmod_common(struct path *path, umode_t mode)
47503 if (error)
47504 return error;
47505 mutex_lock(&inode->i_mutex);
47506+
47507+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
47508+ error = -EACCES;
47509+ goto out_unlock;
47510+ }
47511+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
47512+ error = -EACCES;
47513+ goto out_unlock;
47514+ }
47515+
47516 error = security_path_chmod(path, mode);
47517 if (error)
47518 goto out_unlock;
47519@@ -506,6 +538,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
47520 int error;
47521 struct iattr newattrs;
47522
47523+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
47524+ return -EACCES;
47525+
47526 newattrs.ia_valid = ATTR_CTIME;
47527 if (user != (uid_t) -1) {
47528 newattrs.ia_valid |= ATTR_UID;
47529diff --git a/fs/pipe.c b/fs/pipe.c
47530index 82e651b..8a68573 100644
47531--- a/fs/pipe.c
47532+++ b/fs/pipe.c
47533@@ -437,9 +437,9 @@ redo:
47534 }
47535 if (bufs) /* More to do? */
47536 continue;
47537- if (!pipe->writers)
47538+ if (!atomic_read(&pipe->writers))
47539 break;
47540- if (!pipe->waiting_writers) {
47541+ if (!atomic_read(&pipe->waiting_writers)) {
47542 /* syscall merging: Usually we must not sleep
47543 * if O_NONBLOCK is set, or if we got some data.
47544 * But if a writer sleeps in kernel space, then
47545@@ -503,7 +503,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
47546 mutex_lock(&inode->i_mutex);
47547 pipe = inode->i_pipe;
47548
47549- if (!pipe->readers) {
47550+ if (!atomic_read(&pipe->readers)) {
47551 send_sig(SIGPIPE, current, 0);
47552 ret = -EPIPE;
47553 goto out;
47554@@ -552,7 +552,7 @@ redo1:
47555 for (;;) {
47556 int bufs;
47557
47558- if (!pipe->readers) {
47559+ if (!atomic_read(&pipe->readers)) {
47560 send_sig(SIGPIPE, current, 0);
47561 if (!ret)
47562 ret = -EPIPE;
47563@@ -643,9 +643,9 @@ redo2:
47564 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47565 do_wakeup = 0;
47566 }
47567- pipe->waiting_writers++;
47568+ atomic_inc(&pipe->waiting_writers);
47569 pipe_wait(pipe);
47570- pipe->waiting_writers--;
47571+ atomic_dec(&pipe->waiting_writers);
47572 }
47573 out:
47574 mutex_unlock(&inode->i_mutex);
47575@@ -712,7 +712,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47576 mask = 0;
47577 if (filp->f_mode & FMODE_READ) {
47578 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
47579- if (!pipe->writers && filp->f_version != pipe->w_counter)
47580+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
47581 mask |= POLLHUP;
47582 }
47583
47584@@ -722,7 +722,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47585 * Most Unices do not set POLLERR for FIFOs but on Linux they
47586 * behave exactly like pipes for poll().
47587 */
47588- if (!pipe->readers)
47589+ if (!atomic_read(&pipe->readers))
47590 mask |= POLLERR;
47591 }
47592
47593@@ -736,10 +736,10 @@ pipe_release(struct inode *inode, int decr, int decw)
47594
47595 mutex_lock(&inode->i_mutex);
47596 pipe = inode->i_pipe;
47597- pipe->readers -= decr;
47598- pipe->writers -= decw;
47599+ atomic_sub(decr, &pipe->readers);
47600+ atomic_sub(decw, &pipe->writers);
47601
47602- if (!pipe->readers && !pipe->writers) {
47603+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
47604 free_pipe_info(inode);
47605 } else {
47606 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
47607@@ -829,7 +829,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
47608
47609 if (inode->i_pipe) {
47610 ret = 0;
47611- inode->i_pipe->readers++;
47612+ atomic_inc(&inode->i_pipe->readers);
47613 }
47614
47615 mutex_unlock(&inode->i_mutex);
47616@@ -846,7 +846,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
47617
47618 if (inode->i_pipe) {
47619 ret = 0;
47620- inode->i_pipe->writers++;
47621+ atomic_inc(&inode->i_pipe->writers);
47622 }
47623
47624 mutex_unlock(&inode->i_mutex);
47625@@ -864,9 +864,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
47626 if (inode->i_pipe) {
47627 ret = 0;
47628 if (filp->f_mode & FMODE_READ)
47629- inode->i_pipe->readers++;
47630+ atomic_inc(&inode->i_pipe->readers);
47631 if (filp->f_mode & FMODE_WRITE)
47632- inode->i_pipe->writers++;
47633+ atomic_inc(&inode->i_pipe->writers);
47634 }
47635
47636 mutex_unlock(&inode->i_mutex);
47637@@ -958,7 +958,7 @@ void free_pipe_info(struct inode *inode)
47638 inode->i_pipe = NULL;
47639 }
47640
47641-static struct vfsmount *pipe_mnt __read_mostly;
47642+struct vfsmount *pipe_mnt __read_mostly;
47643
47644 /*
47645 * pipefs_dname() is called from d_path().
47646@@ -988,7 +988,8 @@ static struct inode * get_pipe_inode(void)
47647 goto fail_iput;
47648 inode->i_pipe = pipe;
47649
47650- pipe->readers = pipe->writers = 1;
47651+ atomic_set(&pipe->readers, 1);
47652+ atomic_set(&pipe->writers, 1);
47653 inode->i_fop = &rdwr_pipefifo_fops;
47654
47655 /*
47656diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
47657index 15af622..0e9f4467 100644
47658--- a/fs/proc/Kconfig
47659+++ b/fs/proc/Kconfig
47660@@ -30,12 +30,12 @@ config PROC_FS
47661
47662 config PROC_KCORE
47663 bool "/proc/kcore support" if !ARM
47664- depends on PROC_FS && MMU
47665+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
47666
47667 config PROC_VMCORE
47668 bool "/proc/vmcore support"
47669- depends on PROC_FS && CRASH_DUMP
47670- default y
47671+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
47672+ default n
47673 help
47674 Exports the dump image of crashed kernel in ELF format.
47675
47676@@ -59,8 +59,8 @@ config PROC_SYSCTL
47677 limited in memory.
47678
47679 config PROC_PAGE_MONITOR
47680- default y
47681- depends on PROC_FS && MMU
47682+ default n
47683+ depends on PROC_FS && MMU && !GRKERNSEC
47684 bool "Enable /proc page monitoring" if EXPERT
47685 help
47686 Various /proc files exist to monitor process memory utilization:
47687diff --git a/fs/proc/array.c b/fs/proc/array.c
47688index c602b8d..a7de642 100644
47689--- a/fs/proc/array.c
47690+++ b/fs/proc/array.c
47691@@ -60,6 +60,7 @@
47692 #include <linux/tty.h>
47693 #include <linux/string.h>
47694 #include <linux/mman.h>
47695+#include <linux/grsecurity.h>
47696 #include <linux/proc_fs.h>
47697 #include <linux/ioport.h>
47698 #include <linux/uaccess.h>
47699@@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
47700 seq_putc(m, '\n');
47701 }
47702
47703+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47704+static inline void task_pax(struct seq_file *m, struct task_struct *p)
47705+{
47706+ if (p->mm)
47707+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
47708+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
47709+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
47710+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
47711+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
47712+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
47713+ else
47714+ seq_printf(m, "PaX:\t-----\n");
47715+}
47716+#endif
47717+
47718 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47719 struct pid *pid, struct task_struct *task)
47720 {
47721@@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47722 task_cpus_allowed(m, task);
47723 cpuset_task_status_allowed(m, task);
47724 task_context_switch_counts(m, task);
47725+
47726+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47727+ task_pax(m, task);
47728+#endif
47729+
47730+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
47731+ task_grsec_rbac(m, task);
47732+#endif
47733+
47734 return 0;
47735 }
47736
47737+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47738+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47739+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
47740+ _mm->pax_flags & MF_PAX_SEGMEXEC))
47741+#endif
47742+
47743 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47744 struct pid *pid, struct task_struct *task, int whole)
47745 {
47746@@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47747 char tcomm[sizeof(task->comm)];
47748 unsigned long flags;
47749
47750+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47751+ if (current->exec_id != m->exec_id) {
47752+ gr_log_badprocpid("stat");
47753+ return 0;
47754+ }
47755+#endif
47756+
47757 state = *get_task_state(task);
47758 vsize = eip = esp = 0;
47759 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47760@@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47761 gtime = task->gtime;
47762 }
47763
47764+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47765+ if (PAX_RAND_FLAGS(mm)) {
47766+ eip = 0;
47767+ esp = 0;
47768+ wchan = 0;
47769+ }
47770+#endif
47771+#ifdef CONFIG_GRKERNSEC_HIDESYM
47772+ wchan = 0;
47773+ eip =0;
47774+ esp =0;
47775+#endif
47776+
47777 /* scale priority and nice values from timeslices to -20..20 */
47778 /* to make it look like a "normal" Unix priority/nice value */
47779 priority = task_prio(task);
47780@@ -489,9 +540,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47781 vsize,
47782 mm ? get_mm_rss(mm) : 0,
47783 rsslim,
47784+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47785+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
47786+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
47787+ PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
47788+#else
47789 mm ? (permitted ? mm->start_code : 1) : 0,
47790 mm ? (permitted ? mm->end_code : 1) : 0,
47791 (permitted && mm) ? mm->start_stack : 0,
47792+#endif
47793 esp,
47794 eip,
47795 /* The signal information here is obsolete.
47796@@ -536,8 +593,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47797 struct pid *pid, struct task_struct *task)
47798 {
47799 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
47800- struct mm_struct *mm = get_task_mm(task);
47801+ struct mm_struct *mm;
47802
47803+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47804+ if (current->exec_id != m->exec_id) {
47805+ gr_log_badprocpid("statm");
47806+ return 0;
47807+ }
47808+#endif
47809+ mm = get_task_mm(task);
47810 if (mm) {
47811 size = task_statm(mm, &shared, &text, &data, &resident);
47812 mmput(mm);
47813@@ -547,3 +611,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47814
47815 return 0;
47816 }
47817+
47818+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47819+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
47820+{
47821+ u32 curr_ip = 0;
47822+ unsigned long flags;
47823+
47824+ if (lock_task_sighand(task, &flags)) {
47825+ curr_ip = task->signal->curr_ip;
47826+ unlock_task_sighand(task, &flags);
47827+ }
47828+
47829+ return sprintf(buffer, "%pI4\n", &curr_ip);
47830+}
47831+#endif
47832diff --git a/fs/proc/base.c b/fs/proc/base.c
47833index d4548dd..d101f84 100644
47834--- a/fs/proc/base.c
47835+++ b/fs/proc/base.c
47836@@ -109,6 +109,14 @@ struct pid_entry {
47837 union proc_op op;
47838 };
47839
47840+struct getdents_callback {
47841+ struct linux_dirent __user * current_dir;
47842+ struct linux_dirent __user * previous;
47843+ struct file * file;
47844+ int count;
47845+ int error;
47846+};
47847+
47848 #define NOD(NAME, MODE, IOP, FOP, OP) { \
47849 .name = (NAME), \
47850 .len = sizeof(NAME) - 1, \
47851@@ -213,6 +221,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
47852 if (!mm->arg_end)
47853 goto out_mm; /* Shh! No looking before we're done */
47854
47855+ if (gr_acl_handle_procpidmem(task))
47856+ goto out_mm;
47857+
47858 len = mm->arg_end - mm->arg_start;
47859
47860 if (len > PAGE_SIZE)
47861@@ -240,12 +251,28 @@ out:
47862 return res;
47863 }
47864
47865+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47866+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47867+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
47868+ _mm->pax_flags & MF_PAX_SEGMEXEC))
47869+#endif
47870+
47871 static int proc_pid_auxv(struct task_struct *task, char *buffer)
47872 {
47873 struct mm_struct *mm = mm_for_maps(task);
47874 int res = PTR_ERR(mm);
47875 if (mm && !IS_ERR(mm)) {
47876 unsigned int nwords = 0;
47877+
47878+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47879+ /* allow if we're currently ptracing this task */
47880+ if (PAX_RAND_FLAGS(mm) &&
47881+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
47882+ mmput(mm);
47883+ return 0;
47884+ }
47885+#endif
47886+
47887 do {
47888 nwords += 2;
47889 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
47890@@ -259,7 +286,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
47891 }
47892
47893
47894-#ifdef CONFIG_KALLSYMS
47895+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47896 /*
47897 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
47898 * Returns the resolved symbol. If that fails, simply return the address.
47899@@ -298,7 +325,7 @@ static void unlock_trace(struct task_struct *task)
47900 mutex_unlock(&task->signal->cred_guard_mutex);
47901 }
47902
47903-#ifdef CONFIG_STACKTRACE
47904+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47905
47906 #define MAX_STACK_TRACE_DEPTH 64
47907
47908@@ -489,7 +516,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
47909 return count;
47910 }
47911
47912-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47913+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47914 static int proc_pid_syscall(struct task_struct *task, char *buffer)
47915 {
47916 long nr;
47917@@ -518,7 +545,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
47918 /************************************************************************/
47919
47920 /* permission checks */
47921-static int proc_fd_access_allowed(struct inode *inode)
47922+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
47923 {
47924 struct task_struct *task;
47925 int allowed = 0;
47926@@ -528,7 +555,10 @@ static int proc_fd_access_allowed(struct inode *inode)
47927 */
47928 task = get_proc_task(inode);
47929 if (task) {
47930- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47931+ if (log)
47932+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47933+ else
47934+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47935 put_task_struct(task);
47936 }
47937 return allowed;
47938@@ -566,10 +596,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
47939 struct task_struct *task,
47940 int hide_pid_min)
47941 {
47942+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47943+ return false;
47944+
47945+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47946+ rcu_read_lock();
47947+ {
47948+ const struct cred *tmpcred = current_cred();
47949+ const struct cred *cred = __task_cred(task);
47950+
47951+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
47952+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47953+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
47954+#endif
47955+ ) {
47956+ rcu_read_unlock();
47957+ return true;
47958+ }
47959+ }
47960+ rcu_read_unlock();
47961+
47962+ if (!pid->hide_pid)
47963+ return false;
47964+#endif
47965+
47966 if (pid->hide_pid < hide_pid_min)
47967 return true;
47968 if (in_group_p(pid->pid_gid))
47969 return true;
47970+
47971 return ptrace_may_access(task, PTRACE_MODE_READ);
47972 }
47973
47974@@ -587,7 +642,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
47975 put_task_struct(task);
47976
47977 if (!has_perms) {
47978+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47979+ {
47980+#else
47981 if (pid->hide_pid == 2) {
47982+#endif
47983 /*
47984 * Let's make getdents(), stat(), and open()
47985 * consistent with each other. If a process
47986@@ -702,6 +761,10 @@ static int mem_open(struct inode* inode, struct file* file)
47987 file->f_mode |= FMODE_UNSIGNED_OFFSET;
47988 file->private_data = mm;
47989
47990+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47991+ file->f_version = current->exec_id;
47992+#endif
47993+
47994 return 0;
47995 }
47996
47997@@ -713,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
47998 ssize_t copied;
47999 char *page;
48000
48001+#ifdef CONFIG_GRKERNSEC
48002+ if (write)
48003+ return -EPERM;
48004+#endif
48005+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48006+ if (file->f_version != current->exec_id) {
48007+ gr_log_badprocpid("mem");
48008+ return 0;
48009+ }
48010+#endif
48011+
48012 if (!mm)
48013 return 0;
48014
48015@@ -813,6 +887,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48016 if (!task)
48017 goto out_no_task;
48018
48019+ if (gr_acl_handle_procpidmem(task))
48020+ goto out;
48021+
48022 ret = -ENOMEM;
48023 page = (char *)__get_free_page(GFP_TEMPORARY);
48024 if (!page)
48025@@ -1434,7 +1511,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48026 path_put(&nd->path);
48027
48028 /* Are we allowed to snoop on the tasks file descriptors? */
48029- if (!proc_fd_access_allowed(inode))
48030+ if (!proc_fd_access_allowed(inode, 0))
48031 goto out;
48032
48033 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
48034@@ -1473,8 +1550,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48035 struct path path;
48036
48037 /* Are we allowed to snoop on the tasks file descriptors? */
48038- if (!proc_fd_access_allowed(inode))
48039- goto out;
48040+ /* logging this is needed for learning on chromium to work properly,
48041+ but we don't want to flood the logs from 'ps' which does a readlink
48042+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48043+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
48044+ */
48045+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48046+ if (!proc_fd_access_allowed(inode,0))
48047+ goto out;
48048+ } else {
48049+ if (!proc_fd_access_allowed(inode,1))
48050+ goto out;
48051+ }
48052
48053 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
48054 if (error)
48055@@ -1539,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48056 rcu_read_lock();
48057 cred = __task_cred(task);
48058 inode->i_uid = cred->euid;
48059+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48060+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48061+#else
48062 inode->i_gid = cred->egid;
48063+#endif
48064 rcu_read_unlock();
48065 }
48066 security_task_to_inode(task, inode);
48067@@ -1575,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48068 return -ENOENT;
48069 }
48070 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48071+#ifdef CONFIG_GRKERNSEC_PROC_USER
48072+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48073+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48074+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48075+#endif
48076 task_dumpable(task)) {
48077 cred = __task_cred(task);
48078 stat->uid = cred->euid;
48079+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48080+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48081+#else
48082 stat->gid = cred->egid;
48083+#endif
48084 }
48085 }
48086 rcu_read_unlock();
48087@@ -1616,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48088
48089 if (task) {
48090 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48091+#ifdef CONFIG_GRKERNSEC_PROC_USER
48092+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48093+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48094+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48095+#endif
48096 task_dumpable(task)) {
48097 rcu_read_lock();
48098 cred = __task_cred(task);
48099 inode->i_uid = cred->euid;
48100+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48101+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48102+#else
48103 inode->i_gid = cred->egid;
48104+#endif
48105 rcu_read_unlock();
48106 } else {
48107 inode->i_uid = 0;
48108@@ -1738,7 +1847,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48109 int fd = proc_fd(inode);
48110
48111 if (task) {
48112- files = get_files_struct(task);
48113+ if (!gr_acl_handle_procpidmem(task))
48114+ files = get_files_struct(task);
48115 put_task_struct(task);
48116 }
48117 if (files) {
48118@@ -2355,11 +2465,21 @@ static const struct file_operations proc_map_files_operations = {
48119 */
48120 static int proc_fd_permission(struct inode *inode, int mask)
48121 {
48122+ struct task_struct *task;
48123 int rv = generic_permission(inode, mask);
48124- if (rv == 0)
48125- return 0;
48126+
48127 if (task_pid(current) == proc_pid(inode))
48128 rv = 0;
48129+
48130+ task = get_proc_task(inode);
48131+ if (task == NULL)
48132+ return rv;
48133+
48134+ if (gr_acl_handle_procpidmem(task))
48135+ rv = -EACCES;
48136+
48137+ put_task_struct(task);
48138+
48139 return rv;
48140 }
48141
48142@@ -2469,6 +2589,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48143 if (!task)
48144 goto out_no_task;
48145
48146+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48147+ goto out;
48148+
48149 /*
48150 * Yes, it does not scale. And it should not. Don't add
48151 * new entries into /proc/<tgid>/ without very good reasons.
48152@@ -2513,6 +2636,9 @@ static int proc_pident_readdir(struct file *filp,
48153 if (!task)
48154 goto out_no_task;
48155
48156+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48157+ goto out;
48158+
48159 ret = 0;
48160 i = filp->f_pos;
48161 switch (i) {
48162@@ -2783,7 +2909,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48163 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48164 void *cookie)
48165 {
48166- char *s = nd_get_link(nd);
48167+ const char *s = nd_get_link(nd);
48168 if (!IS_ERR(s))
48169 __putname(s);
48170 }
48171@@ -2984,7 +3110,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48172 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48173 #endif
48174 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48175-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48176+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48177 INF("syscall", S_IRUGO, proc_pid_syscall),
48178 #endif
48179 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48180@@ -3009,10 +3135,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48181 #ifdef CONFIG_SECURITY
48182 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48183 #endif
48184-#ifdef CONFIG_KALLSYMS
48185+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48186 INF("wchan", S_IRUGO, proc_pid_wchan),
48187 #endif
48188-#ifdef CONFIG_STACKTRACE
48189+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48190 ONE("stack", S_IRUGO, proc_pid_stack),
48191 #endif
48192 #ifdef CONFIG_SCHEDSTATS
48193@@ -3046,6 +3172,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48194 #ifdef CONFIG_HARDWALL
48195 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48196 #endif
48197+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48198+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48199+#endif
48200 };
48201
48202 static int proc_tgid_base_readdir(struct file * filp,
48203@@ -3172,7 +3301,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48204 if (!inode)
48205 goto out;
48206
48207+#ifdef CONFIG_GRKERNSEC_PROC_USER
48208+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48209+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48210+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48211+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48212+#else
48213 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48214+#endif
48215 inode->i_op = &proc_tgid_base_inode_operations;
48216 inode->i_fop = &proc_tgid_base_operations;
48217 inode->i_flags|=S_IMMUTABLE;
48218@@ -3214,7 +3350,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48219 if (!task)
48220 goto out;
48221
48222+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48223+ goto out_put_task;
48224+
48225 result = proc_pid_instantiate(dir, dentry, task, NULL);
48226+out_put_task:
48227 put_task_struct(task);
48228 out:
48229 return result;
48230@@ -3277,6 +3417,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
48231 static int fake_filldir(void *buf, const char *name, int namelen,
48232 loff_t offset, u64 ino, unsigned d_type)
48233 {
48234+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
48235+ __buf->error = -EINVAL;
48236 return 0;
48237 }
48238
48239@@ -3343,7 +3485,7 @@ static const struct pid_entry tid_base_stuff[] = {
48240 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48241 #endif
48242 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48243-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48244+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48245 INF("syscall", S_IRUGO, proc_pid_syscall),
48246 #endif
48247 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48248@@ -3367,10 +3509,10 @@ static const struct pid_entry tid_base_stuff[] = {
48249 #ifdef CONFIG_SECURITY
48250 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48251 #endif
48252-#ifdef CONFIG_KALLSYMS
48253+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48254 INF("wchan", S_IRUGO, proc_pid_wchan),
48255 #endif
48256-#ifdef CONFIG_STACKTRACE
48257+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48258 ONE("stack", S_IRUGO, proc_pid_stack),
48259 #endif
48260 #ifdef CONFIG_SCHEDSTATS
48261diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48262index 82676e3..5f8518a 100644
48263--- a/fs/proc/cmdline.c
48264+++ b/fs/proc/cmdline.c
48265@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48266
48267 static int __init proc_cmdline_init(void)
48268 {
48269+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48270+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48271+#else
48272 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48273+#endif
48274 return 0;
48275 }
48276 module_init(proc_cmdline_init);
48277diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48278index b143471..bb105e5 100644
48279--- a/fs/proc/devices.c
48280+++ b/fs/proc/devices.c
48281@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48282
48283 static int __init proc_devices_init(void)
48284 {
48285+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48286+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48287+#else
48288 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48289+#endif
48290 return 0;
48291 }
48292 module_init(proc_devices_init);
48293diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48294index 84fd323..f698a32 100644
48295--- a/fs/proc/inode.c
48296+++ b/fs/proc/inode.c
48297@@ -21,12 +21,18 @@
48298 #include <linux/seq_file.h>
48299 #include <linux/slab.h>
48300 #include <linux/mount.h>
48301+#include <linux/grsecurity.h>
48302
48303 #include <asm/system.h>
48304 #include <asm/uaccess.h>
48305
48306 #include "internal.h"
48307
48308+#ifdef CONFIG_PROC_SYSCTL
48309+extern const struct inode_operations proc_sys_inode_operations;
48310+extern const struct inode_operations proc_sys_dir_operations;
48311+#endif
48312+
48313 static void proc_evict_inode(struct inode *inode)
48314 {
48315 struct proc_dir_entry *de;
48316@@ -52,6 +58,13 @@ static void proc_evict_inode(struct inode *inode)
48317 ns_ops = PROC_I(inode)->ns_ops;
48318 if (ns_ops && ns_ops->put)
48319 ns_ops->put(PROC_I(inode)->ns);
48320+
48321+#ifdef CONFIG_PROC_SYSCTL
48322+ if (inode->i_op == &proc_sys_inode_operations ||
48323+ inode->i_op == &proc_sys_dir_operations)
48324+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
48325+#endif
48326+
48327 }
48328
48329 static struct kmem_cache * proc_inode_cachep;
48330@@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
48331 if (de->mode) {
48332 inode->i_mode = de->mode;
48333 inode->i_uid = de->uid;
48334+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48335+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48336+#else
48337 inode->i_gid = de->gid;
48338+#endif
48339 }
48340 if (de->size)
48341 inode->i_size = de->size;
48342diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48343index 2925775..4f08fae 100644
48344--- a/fs/proc/internal.h
48345+++ b/fs/proc/internal.h
48346@@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48347 struct pid *pid, struct task_struct *task);
48348 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48349 struct pid *pid, struct task_struct *task);
48350+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48351+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48352+#endif
48353 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48354
48355 extern const struct file_operations proc_maps_operations;
48356diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48357index d245cb2..f4e8498 100644
48358--- a/fs/proc/kcore.c
48359+++ b/fs/proc/kcore.c
48360@@ -478,9 +478,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48361 * the addresses in the elf_phdr on our list.
48362 */
48363 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48364- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48365+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48366+ if (tsz > buflen)
48367 tsz = buflen;
48368-
48369+
48370 while (buflen) {
48371 struct kcore_list *m;
48372
48373@@ -509,20 +510,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48374 kfree(elf_buf);
48375 } else {
48376 if (kern_addr_valid(start)) {
48377- unsigned long n;
48378+ char *elf_buf;
48379+ mm_segment_t oldfs;
48380
48381- n = copy_to_user(buffer, (char *)start, tsz);
48382- /*
48383- * We cannot distingush between fault on source
48384- * and fault on destination. When this happens
48385- * we clear too and hope it will trigger the
48386- * EFAULT again.
48387- */
48388- if (n) {
48389- if (clear_user(buffer + tsz - n,
48390- n))
48391+ elf_buf = kmalloc(tsz, GFP_KERNEL);
48392+ if (!elf_buf)
48393+ return -ENOMEM;
48394+ oldfs = get_fs();
48395+ set_fs(KERNEL_DS);
48396+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48397+ set_fs(oldfs);
48398+ if (copy_to_user(buffer, elf_buf, tsz)) {
48399+ kfree(elf_buf);
48400 return -EFAULT;
48401+ }
48402 }
48403+ set_fs(oldfs);
48404+ kfree(elf_buf);
48405 } else {
48406 if (clear_user(buffer, tsz))
48407 return -EFAULT;
48408@@ -542,6 +546,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48409
48410 static int open_kcore(struct inode *inode, struct file *filp)
48411 {
48412+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48413+ return -EPERM;
48414+#endif
48415 if (!capable(CAP_SYS_RAWIO))
48416 return -EPERM;
48417 if (kcore_need_update)
48418diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48419index 80e4645..53e5fcf 100644
48420--- a/fs/proc/meminfo.c
48421+++ b/fs/proc/meminfo.c
48422@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48423 vmi.used >> 10,
48424 vmi.largest_chunk >> 10
48425 #ifdef CONFIG_MEMORY_FAILURE
48426- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48427+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48428 #endif
48429 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48430 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48431diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48432index b1822dd..df622cb 100644
48433--- a/fs/proc/nommu.c
48434+++ b/fs/proc/nommu.c
48435@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48436 if (len < 1)
48437 len = 1;
48438 seq_printf(m, "%*c", len, ' ');
48439- seq_path(m, &file->f_path, "");
48440+ seq_path(m, &file->f_path, "\n\\");
48441 }
48442
48443 seq_putc(m, '\n');
48444diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
48445index 06e1cc1..177cd98 100644
48446--- a/fs/proc/proc_net.c
48447+++ b/fs/proc/proc_net.c
48448@@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
48449 struct task_struct *task;
48450 struct nsproxy *ns;
48451 struct net *net = NULL;
48452+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48453+ const struct cred *cred = current_cred();
48454+#endif
48455+
48456+#ifdef CONFIG_GRKERNSEC_PROC_USER
48457+ if (cred->fsuid)
48458+ return net;
48459+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48460+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
48461+ return net;
48462+#endif
48463
48464 rcu_read_lock();
48465 task = pid_task(proc_pid(dir), PIDTYPE_PID);
48466diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
48467index 53c3bce..10ad159 100644
48468--- a/fs/proc/proc_sysctl.c
48469+++ b/fs/proc/proc_sysctl.c
48470@@ -9,11 +9,13 @@
48471 #include <linux/namei.h>
48472 #include "internal.h"
48473
48474+extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
48475+
48476 static const struct dentry_operations proc_sys_dentry_operations;
48477 static const struct file_operations proc_sys_file_operations;
48478-static const struct inode_operations proc_sys_inode_operations;
48479+const struct inode_operations proc_sys_inode_operations;
48480 static const struct file_operations proc_sys_dir_file_operations;
48481-static const struct inode_operations proc_sys_dir_operations;
48482+const struct inode_operations proc_sys_dir_operations;
48483
48484 void proc_sys_poll_notify(struct ctl_table_poll *poll)
48485 {
48486@@ -131,8 +133,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
48487
48488 err = NULL;
48489 d_set_d_op(dentry, &proc_sys_dentry_operations);
48490+
48491+ gr_handle_proc_create(dentry, inode);
48492+
48493 d_add(dentry, inode);
48494
48495+ if (gr_handle_sysctl(p, MAY_EXEC))
48496+ err = ERR_PTR(-ENOENT);
48497+
48498 out:
48499 sysctl_head_finish(head);
48500 return err;
48501@@ -163,6 +171,12 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48502 if (!table->proc_handler)
48503 goto out;
48504
48505+#ifdef CONFIG_GRKERNSEC
48506+ error = -EPERM;
48507+ if (write && !capable(CAP_SYS_ADMIN))
48508+ goto out;
48509+#endif
48510+
48511 /* careful: calling conventions are nasty here */
48512 res = count;
48513 error = table->proc_handler(table, write, buf, &res, ppos);
48514@@ -260,6 +274,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
48515 return -ENOMEM;
48516 } else {
48517 d_set_d_op(child, &proc_sys_dentry_operations);
48518+
48519+ gr_handle_proc_create(child, inode);
48520+
48521 d_add(child, inode);
48522 }
48523 } else {
48524@@ -288,6 +305,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
48525 if (*pos < file->f_pos)
48526 continue;
48527
48528+ if (gr_handle_sysctl(table, 0))
48529+ continue;
48530+
48531 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
48532 if (res)
48533 return res;
48534@@ -413,6 +433,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
48535 if (IS_ERR(head))
48536 return PTR_ERR(head);
48537
48538+ if (table && gr_handle_sysctl(table, MAY_EXEC))
48539+ return -ENOENT;
48540+
48541 generic_fillattr(inode, stat);
48542 if (table)
48543 stat->mode = (stat->mode & S_IFMT) | table->mode;
48544@@ -435,13 +458,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
48545 .llseek = generic_file_llseek,
48546 };
48547
48548-static const struct inode_operations proc_sys_inode_operations = {
48549+const struct inode_operations proc_sys_inode_operations = {
48550 .permission = proc_sys_permission,
48551 .setattr = proc_sys_setattr,
48552 .getattr = proc_sys_getattr,
48553 };
48554
48555-static const struct inode_operations proc_sys_dir_operations = {
48556+const struct inode_operations proc_sys_dir_operations = {
48557 .lookup = proc_sys_lookup,
48558 .permission = proc_sys_permission,
48559 .setattr = proc_sys_setattr,
48560diff --git a/fs/proc/root.c b/fs/proc/root.c
48561index 46a15d8..335631a 100644
48562--- a/fs/proc/root.c
48563+++ b/fs/proc/root.c
48564@@ -187,7 +187,15 @@ void __init proc_root_init(void)
48565 #ifdef CONFIG_PROC_DEVICETREE
48566 proc_device_tree_init();
48567 #endif
48568+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48569+#ifdef CONFIG_GRKERNSEC_PROC_USER
48570+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
48571+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48572+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48573+#endif
48574+#else
48575 proc_mkdir("bus", NULL);
48576+#endif
48577 proc_sys_init();
48578 }
48579
48580diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
48581index 3efa725..23c925b 100644
48582--- a/fs/proc/task_mmu.c
48583+++ b/fs/proc/task_mmu.c
48584@@ -11,6 +11,7 @@
48585 #include <linux/rmap.h>
48586 #include <linux/swap.h>
48587 #include <linux/swapops.h>
48588+#include <linux/grsecurity.h>
48589
48590 #include <asm/elf.h>
48591 #include <asm/uaccess.h>
48592@@ -52,8 +53,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48593 "VmExe:\t%8lu kB\n"
48594 "VmLib:\t%8lu kB\n"
48595 "VmPTE:\t%8lu kB\n"
48596- "VmSwap:\t%8lu kB\n",
48597- hiwater_vm << (PAGE_SHIFT-10),
48598+ "VmSwap:\t%8lu kB\n"
48599+
48600+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48601+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
48602+#endif
48603+
48604+ ,hiwater_vm << (PAGE_SHIFT-10),
48605 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
48606 mm->locked_vm << (PAGE_SHIFT-10),
48607 mm->pinned_vm << (PAGE_SHIFT-10),
48608@@ -62,7 +68,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48609 data << (PAGE_SHIFT-10),
48610 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
48611 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
48612- swap << (PAGE_SHIFT-10));
48613+ swap << (PAGE_SHIFT-10)
48614+
48615+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48616+ , mm->context.user_cs_base, mm->context.user_cs_limit
48617+#endif
48618+
48619+ );
48620 }
48621
48622 unsigned long task_vsize(struct mm_struct *mm)
48623@@ -209,6 +221,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
48624 return ret;
48625 }
48626
48627+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48628+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48629+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
48630+ _mm->pax_flags & MF_PAX_SEGMEXEC))
48631+#endif
48632+
48633 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48634 {
48635 struct mm_struct *mm = vma->vm_mm;
48636@@ -227,13 +245,13 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48637 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
48638 }
48639
48640- /* We don't show the stack guard page in /proc/maps */
48641+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48642+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
48643+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
48644+#else
48645 start = vma->vm_start;
48646- if (stack_guard_page_start(vma, start))
48647- start += PAGE_SIZE;
48648 end = vma->vm_end;
48649- if (stack_guard_page_end(vma, end))
48650- end -= PAGE_SIZE;
48651+#endif
48652
48653 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
48654 start,
48655@@ -242,7 +260,11 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48656 flags & VM_WRITE ? 'w' : '-',
48657 flags & VM_EXEC ? 'x' : '-',
48658 flags & VM_MAYSHARE ? 's' : 'p',
48659+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48660+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
48661+#else
48662 pgoff,
48663+#endif
48664 MAJOR(dev), MINOR(dev), ino, &len);
48665
48666 /*
48667@@ -251,7 +273,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48668 */
48669 if (file) {
48670 pad_len_spaces(m, len);
48671- seq_path(m, &file->f_path, "\n");
48672+ seq_path(m, &file->f_path, "\n\\");
48673 } else {
48674 const char *name = arch_vma_name(vma);
48675 if (!name) {
48676@@ -259,8 +281,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48677 if (vma->vm_start <= mm->brk &&
48678 vma->vm_end >= mm->start_brk) {
48679 name = "[heap]";
48680- } else if (vma->vm_start <= mm->start_stack &&
48681- vma->vm_end >= mm->start_stack) {
48682+ } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
48683+ (vma->vm_start <= mm->start_stack &&
48684+ vma->vm_end >= mm->start_stack)) {
48685 name = "[stack]";
48686 }
48687 } else {
48688@@ -281,6 +304,13 @@ static int show_map(struct seq_file *m, void *v)
48689 struct proc_maps_private *priv = m->private;
48690 struct task_struct *task = priv->task;
48691
48692+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48693+ if (current->exec_id != m->exec_id) {
48694+ gr_log_badprocpid("maps");
48695+ return 0;
48696+ }
48697+#endif
48698+
48699 show_map_vma(m, vma);
48700
48701 if (m->count < m->size) /* vma is copied successfully */
48702@@ -437,12 +467,23 @@ static int show_smap(struct seq_file *m, void *v)
48703 .private = &mss,
48704 };
48705
48706+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48707+ if (current->exec_id != m->exec_id) {
48708+ gr_log_badprocpid("smaps");
48709+ return 0;
48710+ }
48711+#endif
48712 memset(&mss, 0, sizeof mss);
48713- mss.vma = vma;
48714- /* mmap_sem is held in m_start */
48715- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48716- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48717-
48718+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48719+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
48720+#endif
48721+ mss.vma = vma;
48722+ /* mmap_sem is held in m_start */
48723+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48724+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48725+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48726+ }
48727+#endif
48728 show_map_vma(m, vma);
48729
48730 seq_printf(m,
48731@@ -460,7 +501,11 @@ static int show_smap(struct seq_file *m, void *v)
48732 "KernelPageSize: %8lu kB\n"
48733 "MMUPageSize: %8lu kB\n"
48734 "Locked: %8lu kB\n",
48735+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48736+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
48737+#else
48738 (vma->vm_end - vma->vm_start) >> 10,
48739+#endif
48740 mss.resident >> 10,
48741 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
48742 mss.shared_clean >> 10,
48743@@ -1024,6 +1069,13 @@ static int show_numa_map(struct seq_file *m, void *v)
48744 int n;
48745 char buffer[50];
48746
48747+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48748+ if (current->exec_id != m->exec_id) {
48749+ gr_log_badprocpid("numa_maps");
48750+ return 0;
48751+ }
48752+#endif
48753+
48754 if (!mm)
48755 return 0;
48756
48757@@ -1041,11 +1093,15 @@ static int show_numa_map(struct seq_file *m, void *v)
48758 mpol_to_str(buffer, sizeof(buffer), pol, 0);
48759 mpol_cond_put(pol);
48760
48761+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48762+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
48763+#else
48764 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
48765+#endif
48766
48767 if (file) {
48768 seq_printf(m, " file=");
48769- seq_path(m, &file->f_path, "\n\t= ");
48770+ seq_path(m, &file->f_path, "\n\t\\= ");
48771 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
48772 seq_printf(m, " heap");
48773 } else if (vma->vm_start <= mm->start_stack &&
48774diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
48775index 980de54..2a4db5f 100644
48776--- a/fs/proc/task_nommu.c
48777+++ b/fs/proc/task_nommu.c
48778@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48779 else
48780 bytes += kobjsize(mm);
48781
48782- if (current->fs && current->fs->users > 1)
48783+ if (current->fs && atomic_read(&current->fs->users) > 1)
48784 sbytes += kobjsize(current->fs);
48785 else
48786 bytes += kobjsize(current->fs);
48787@@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
48788
48789 if (file) {
48790 pad_len_spaces(m, len);
48791- seq_path(m, &file->f_path, "");
48792+ seq_path(m, &file->f_path, "\n\\");
48793 } else if (mm) {
48794 if (vma->vm_start <= mm->start_stack &&
48795 vma->vm_end >= mm->start_stack) {
48796diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
48797index d67908b..d13f6a6 100644
48798--- a/fs/quota/netlink.c
48799+++ b/fs/quota/netlink.c
48800@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
48801 void quota_send_warning(short type, unsigned int id, dev_t dev,
48802 const char warntype)
48803 {
48804- static atomic_t seq;
48805+ static atomic_unchecked_t seq;
48806 struct sk_buff *skb;
48807 void *msg_head;
48808 int ret;
48809@@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
48810 "VFS: Not enough memory to send quota warning.\n");
48811 return;
48812 }
48813- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
48814+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
48815 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
48816 if (!msg_head) {
48817 printk(KERN_ERR
48818diff --git a/fs/readdir.c b/fs/readdir.c
48819index 356f715..c918d38 100644
48820--- a/fs/readdir.c
48821+++ b/fs/readdir.c
48822@@ -17,6 +17,7 @@
48823 #include <linux/security.h>
48824 #include <linux/syscalls.h>
48825 #include <linux/unistd.h>
48826+#include <linux/namei.h>
48827
48828 #include <asm/uaccess.h>
48829
48830@@ -67,6 +68,7 @@ struct old_linux_dirent {
48831
48832 struct readdir_callback {
48833 struct old_linux_dirent __user * dirent;
48834+ struct file * file;
48835 int result;
48836 };
48837
48838@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
48839 buf->result = -EOVERFLOW;
48840 return -EOVERFLOW;
48841 }
48842+
48843+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48844+ return 0;
48845+
48846 buf->result++;
48847 dirent = buf->dirent;
48848 if (!access_ok(VERIFY_WRITE, dirent,
48849@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
48850
48851 buf.result = 0;
48852 buf.dirent = dirent;
48853+ buf.file = file;
48854
48855 error = vfs_readdir(file, fillonedir, &buf);
48856 if (buf.result)
48857@@ -142,6 +149,7 @@ struct linux_dirent {
48858 struct getdents_callback {
48859 struct linux_dirent __user * current_dir;
48860 struct linux_dirent __user * previous;
48861+ struct file * file;
48862 int count;
48863 int error;
48864 };
48865@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
48866 buf->error = -EOVERFLOW;
48867 return -EOVERFLOW;
48868 }
48869+
48870+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48871+ return 0;
48872+
48873 dirent = buf->previous;
48874 if (dirent) {
48875 if (__put_user(offset, &dirent->d_off))
48876@@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
48877 buf.previous = NULL;
48878 buf.count = count;
48879 buf.error = 0;
48880+ buf.file = file;
48881
48882 error = vfs_readdir(file, filldir, &buf);
48883 if (error >= 0)
48884@@ -229,6 +242,7 @@ out:
48885 struct getdents_callback64 {
48886 struct linux_dirent64 __user * current_dir;
48887 struct linux_dirent64 __user * previous;
48888+ struct file *file;
48889 int count;
48890 int error;
48891 };
48892@@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
48893 buf->error = -EINVAL; /* only used if we fail.. */
48894 if (reclen > buf->count)
48895 return -EINVAL;
48896+
48897+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48898+ return 0;
48899+
48900 dirent = buf->previous;
48901 if (dirent) {
48902 if (__put_user(offset, &dirent->d_off))
48903@@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48904
48905 buf.current_dir = dirent;
48906 buf.previous = NULL;
48907+ buf.file = file;
48908 buf.count = count;
48909 buf.error = 0;
48910
48911@@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48912 error = buf.error;
48913 lastdirent = buf.previous;
48914 if (lastdirent) {
48915- typeof(lastdirent->d_off) d_off = file->f_pos;
48916+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
48917 if (__put_user(d_off, &lastdirent->d_off))
48918 error = -EFAULT;
48919 else
48920diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
48921index 60c0804..d814f98 100644
48922--- a/fs/reiserfs/do_balan.c
48923+++ b/fs/reiserfs/do_balan.c
48924@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
48925 return;
48926 }
48927
48928- atomic_inc(&(fs_generation(tb->tb_sb)));
48929+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
48930 do_balance_starts(tb);
48931
48932 /* balance leaf returns 0 except if combining L R and S into
48933diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
48934index 7a99811..a7c96c4 100644
48935--- a/fs/reiserfs/procfs.c
48936+++ b/fs/reiserfs/procfs.c
48937@@ -113,7 +113,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
48938 "SMALL_TAILS " : "NO_TAILS ",
48939 replay_only(sb) ? "REPLAY_ONLY " : "",
48940 convert_reiserfs(sb) ? "CONV " : "",
48941- atomic_read(&r->s_generation_counter),
48942+ atomic_read_unchecked(&r->s_generation_counter),
48943 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
48944 SF(s_do_balance), SF(s_unneeded_left_neighbor),
48945 SF(s_good_search_by_key_reada), SF(s_bmaps),
48946diff --git a/fs/select.c b/fs/select.c
48947index e782258..3b4b44c 100644
48948--- a/fs/select.c
48949+++ b/fs/select.c
48950@@ -20,6 +20,7 @@
48951 #include <linux/module.h>
48952 #include <linux/slab.h>
48953 #include <linux/poll.h>
48954+#include <linux/security.h>
48955 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
48956 #include <linux/file.h>
48957 #include <linux/fdtable.h>
48958@@ -837,6 +838,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
48959 struct poll_list *walk = head;
48960 unsigned long todo = nfds;
48961
48962+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
48963 if (nfds > rlimit(RLIMIT_NOFILE))
48964 return -EINVAL;
48965
48966diff --git a/fs/seq_file.c b/fs/seq_file.c
48967index 4023d6b..ab46c6a 100644
48968--- a/fs/seq_file.c
48969+++ b/fs/seq_file.c
48970@@ -9,6 +9,7 @@
48971 #include <linux/module.h>
48972 #include <linux/seq_file.h>
48973 #include <linux/slab.h>
48974+#include <linux/sched.h>
48975
48976 #include <asm/uaccess.h>
48977 #include <asm/page.h>
48978@@ -40,6 +41,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
48979 memset(p, 0, sizeof(*p));
48980 mutex_init(&p->lock);
48981 p->op = op;
48982+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48983+ p->exec_id = current->exec_id;
48984+#endif
48985
48986 /*
48987 * Wrappers around seq_open(e.g. swaps_open) need to be
48988@@ -549,7 +553,7 @@ static void single_stop(struct seq_file *p, void *v)
48989 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
48990 void *data)
48991 {
48992- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
48993+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
48994 int res = -ENOMEM;
48995
48996 if (op) {
48997diff --git a/fs/splice.c b/fs/splice.c
48998index 96d7b28..fd465ac 100644
48999--- a/fs/splice.c
49000+++ b/fs/splice.c
49001@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49002 pipe_lock(pipe);
49003
49004 for (;;) {
49005- if (!pipe->readers) {
49006+ if (!atomic_read(&pipe->readers)) {
49007 send_sig(SIGPIPE, current, 0);
49008 if (!ret)
49009 ret = -EPIPE;
49010@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49011 do_wakeup = 0;
49012 }
49013
49014- pipe->waiting_writers++;
49015+ atomic_inc(&pipe->waiting_writers);
49016 pipe_wait(pipe);
49017- pipe->waiting_writers--;
49018+ atomic_dec(&pipe->waiting_writers);
49019 }
49020
49021 pipe_unlock(pipe);
49022@@ -560,7 +560,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
49023 old_fs = get_fs();
49024 set_fs(get_ds());
49025 /* The cast to a user pointer is valid due to the set_fs() */
49026- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49027+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49028 set_fs(old_fs);
49029
49030 return res;
49031@@ -575,7 +575,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49032 old_fs = get_fs();
49033 set_fs(get_ds());
49034 /* The cast to a user pointer is valid due to the set_fs() */
49035- res = vfs_write(file, (const char __user *)buf, count, &pos);
49036+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49037 set_fs(old_fs);
49038
49039 return res;
49040@@ -626,7 +626,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49041 goto err;
49042
49043 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49044- vec[i].iov_base = (void __user *) page_address(page);
49045+ vec[i].iov_base = (void __force_user *) page_address(page);
49046 vec[i].iov_len = this_len;
49047 spd.pages[i] = page;
49048 spd.nr_pages++;
49049@@ -848,10 +848,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49050 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49051 {
49052 while (!pipe->nrbufs) {
49053- if (!pipe->writers)
49054+ if (!atomic_read(&pipe->writers))
49055 return 0;
49056
49057- if (!pipe->waiting_writers && sd->num_spliced)
49058+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49059 return 0;
49060
49061 if (sd->flags & SPLICE_F_NONBLOCK)
49062@@ -1184,7 +1184,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49063 * out of the pipe right after the splice_to_pipe(). So set
49064 * PIPE_READERS appropriately.
49065 */
49066- pipe->readers = 1;
49067+ atomic_set(&pipe->readers, 1);
49068
49069 current->splice_pipe = pipe;
49070 }
49071@@ -1736,9 +1736,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49072 ret = -ERESTARTSYS;
49073 break;
49074 }
49075- if (!pipe->writers)
49076+ if (!atomic_read(&pipe->writers))
49077 break;
49078- if (!pipe->waiting_writers) {
49079+ if (!atomic_read(&pipe->waiting_writers)) {
49080 if (flags & SPLICE_F_NONBLOCK) {
49081 ret = -EAGAIN;
49082 break;
49083@@ -1770,7 +1770,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49084 pipe_lock(pipe);
49085
49086 while (pipe->nrbufs >= pipe->buffers) {
49087- if (!pipe->readers) {
49088+ if (!atomic_read(&pipe->readers)) {
49089 send_sig(SIGPIPE, current, 0);
49090 ret = -EPIPE;
49091 break;
49092@@ -1783,9 +1783,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49093 ret = -ERESTARTSYS;
49094 break;
49095 }
49096- pipe->waiting_writers++;
49097+ atomic_inc(&pipe->waiting_writers);
49098 pipe_wait(pipe);
49099- pipe->waiting_writers--;
49100+ atomic_dec(&pipe->waiting_writers);
49101 }
49102
49103 pipe_unlock(pipe);
49104@@ -1821,14 +1821,14 @@ retry:
49105 pipe_double_lock(ipipe, opipe);
49106
49107 do {
49108- if (!opipe->readers) {
49109+ if (!atomic_read(&opipe->readers)) {
49110 send_sig(SIGPIPE, current, 0);
49111 if (!ret)
49112 ret = -EPIPE;
49113 break;
49114 }
49115
49116- if (!ipipe->nrbufs && !ipipe->writers)
49117+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49118 break;
49119
49120 /*
49121@@ -1925,7 +1925,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49122 pipe_double_lock(ipipe, opipe);
49123
49124 do {
49125- if (!opipe->readers) {
49126+ if (!atomic_read(&opipe->readers)) {
49127 send_sig(SIGPIPE, current, 0);
49128 if (!ret)
49129 ret = -EPIPE;
49130@@ -1970,7 +1970,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49131 * return EAGAIN if we have the potential of some data in the
49132 * future, otherwise just return 0
49133 */
49134- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49135+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49136 ret = -EAGAIN;
49137
49138 pipe_unlock(ipipe);
49139diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
49140index 7fdf6a7..e6cd8ad 100644
49141--- a/fs/sysfs/dir.c
49142+++ b/fs/sysfs/dir.c
49143@@ -642,6 +642,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
49144 struct sysfs_dirent *sd;
49145 int rc;
49146
49147+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49148+ const char *parent_name = parent_sd->s_name;
49149+
49150+ mode = S_IFDIR | S_IRWXU;
49151+
49152+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
49153+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
49154+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
49155+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
49156+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
49157+#endif
49158+
49159 /* allocate */
49160 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
49161 if (!sd)
49162diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49163index 00012e3..8392349 100644
49164--- a/fs/sysfs/file.c
49165+++ b/fs/sysfs/file.c
49166@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49167
49168 struct sysfs_open_dirent {
49169 atomic_t refcnt;
49170- atomic_t event;
49171+ atomic_unchecked_t event;
49172 wait_queue_head_t poll;
49173 struct list_head buffers; /* goes through sysfs_buffer.list */
49174 };
49175@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49176 if (!sysfs_get_active(attr_sd))
49177 return -ENODEV;
49178
49179- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49180+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49181 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49182
49183 sysfs_put_active(attr_sd);
49184@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49185 return -ENOMEM;
49186
49187 atomic_set(&new_od->refcnt, 0);
49188- atomic_set(&new_od->event, 1);
49189+ atomic_set_unchecked(&new_od->event, 1);
49190 init_waitqueue_head(&new_od->poll);
49191 INIT_LIST_HEAD(&new_od->buffers);
49192 goto retry;
49193@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49194
49195 sysfs_put_active(attr_sd);
49196
49197- if (buffer->event != atomic_read(&od->event))
49198+ if (buffer->event != atomic_read_unchecked(&od->event))
49199 goto trigger;
49200
49201 return DEFAULT_POLLMASK;
49202@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
49203
49204 od = sd->s_attr.open;
49205 if (od) {
49206- atomic_inc(&od->event);
49207+ atomic_inc_unchecked(&od->event);
49208 wake_up_interruptible(&od->poll);
49209 }
49210
49211diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
49212index a7ac78f..02158e1 100644
49213--- a/fs/sysfs/symlink.c
49214+++ b/fs/sysfs/symlink.c
49215@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
49216
49217 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49218 {
49219- char *page = nd_get_link(nd);
49220+ const char *page = nd_get_link(nd);
49221 if (!IS_ERR(page))
49222 free_page((unsigned long)page);
49223 }
49224diff --git a/fs/udf/misc.c b/fs/udf/misc.c
49225index c175b4d..8f36a16 100644
49226--- a/fs/udf/misc.c
49227+++ b/fs/udf/misc.c
49228@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
49229
49230 u8 udf_tag_checksum(const struct tag *t)
49231 {
49232- u8 *data = (u8 *)t;
49233+ const u8 *data = (const u8 *)t;
49234 u8 checksum = 0;
49235 int i;
49236 for (i = 0; i < sizeof(struct tag); ++i)
49237diff --git a/fs/utimes.c b/fs/utimes.c
49238index ba653f3..06ea4b1 100644
49239--- a/fs/utimes.c
49240+++ b/fs/utimes.c
49241@@ -1,6 +1,7 @@
49242 #include <linux/compiler.h>
49243 #include <linux/file.h>
49244 #include <linux/fs.h>
49245+#include <linux/security.h>
49246 #include <linux/linkage.h>
49247 #include <linux/mount.h>
49248 #include <linux/namei.h>
49249@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
49250 goto mnt_drop_write_and_out;
49251 }
49252 }
49253+
49254+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
49255+ error = -EACCES;
49256+ goto mnt_drop_write_and_out;
49257+ }
49258+
49259 mutex_lock(&inode->i_mutex);
49260 error = notify_change(path->dentry, &newattrs);
49261 mutex_unlock(&inode->i_mutex);
49262diff --git a/fs/xattr.c b/fs/xattr.c
49263index 82f4337..236473c 100644
49264--- a/fs/xattr.c
49265+++ b/fs/xattr.c
49266@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
49267 * Extended attribute SET operations
49268 */
49269 static long
49270-setxattr(struct dentry *d, const char __user *name, const void __user *value,
49271+setxattr(struct path *path, const char __user *name, const void __user *value,
49272 size_t size, int flags)
49273 {
49274 int error;
49275@@ -339,7 +339,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
49276 return PTR_ERR(kvalue);
49277 }
49278
49279- error = vfs_setxattr(d, kname, kvalue, size, flags);
49280+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
49281+ error = -EACCES;
49282+ goto out;
49283+ }
49284+
49285+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
49286+out:
49287 kfree(kvalue);
49288 return error;
49289 }
49290@@ -356,7 +362,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
49291 return error;
49292 error = mnt_want_write(path.mnt);
49293 if (!error) {
49294- error = setxattr(path.dentry, name, value, size, flags);
49295+ error = setxattr(&path, name, value, size, flags);
49296 mnt_drop_write(path.mnt);
49297 }
49298 path_put(&path);
49299@@ -375,7 +381,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
49300 return error;
49301 error = mnt_want_write(path.mnt);
49302 if (!error) {
49303- error = setxattr(path.dentry, name, value, size, flags);
49304+ error = setxattr(&path, name, value, size, flags);
49305 mnt_drop_write(path.mnt);
49306 }
49307 path_put(&path);
49308@@ -386,17 +392,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49309 const void __user *,value, size_t, size, int, flags)
49310 {
49311 struct file *f;
49312- struct dentry *dentry;
49313 int error = -EBADF;
49314
49315 f = fget(fd);
49316 if (!f)
49317 return error;
49318- dentry = f->f_path.dentry;
49319- audit_inode(NULL, dentry);
49320+ audit_inode(NULL, f->f_path.dentry);
49321 error = mnt_want_write_file(f);
49322 if (!error) {
49323- error = setxattr(dentry, name, value, size, flags);
49324+ error = setxattr(&f->f_path, name, value, size, flags);
49325 mnt_drop_write_file(f);
49326 }
49327 fput(f);
49328diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
49329index 8d5a506..7f62712 100644
49330--- a/fs/xattr_acl.c
49331+++ b/fs/xattr_acl.c
49332@@ -17,8 +17,8 @@
49333 struct posix_acl *
49334 posix_acl_from_xattr(const void *value, size_t size)
49335 {
49336- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
49337- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
49338+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
49339+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
49340 int count;
49341 struct posix_acl *acl;
49342 struct posix_acl_entry *acl_e;
49343diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
49344index 188ef2f..adcf864 100644
49345--- a/fs/xfs/xfs_bmap.c
49346+++ b/fs/xfs/xfs_bmap.c
49347@@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
49348 int nmap,
49349 int ret_nmap);
49350 #else
49351-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
49352+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
49353 #endif /* DEBUG */
49354
49355 STATIC int
49356diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
49357index 79d05e8..e3e5861 100644
49358--- a/fs/xfs/xfs_dir2_sf.c
49359+++ b/fs/xfs/xfs_dir2_sf.c
49360@@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
49361 }
49362
49363 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
49364- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49365+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
49366+ char name[sfep->namelen];
49367+ memcpy(name, sfep->name, sfep->namelen);
49368+ if (filldir(dirent, name, sfep->namelen,
49369+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
49370+ *offset = off & 0x7fffffff;
49371+ return 0;
49372+ }
49373+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49374 off & 0x7fffffff, ino, DT_UNKNOWN)) {
49375 *offset = off & 0x7fffffff;
49376 return 0;
49377diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
49378index 76f3ca5..f57f712 100644
49379--- a/fs/xfs/xfs_ioctl.c
49380+++ b/fs/xfs/xfs_ioctl.c
49381@@ -128,7 +128,7 @@ xfs_find_handle(
49382 }
49383
49384 error = -EFAULT;
49385- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
49386+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
49387 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
49388 goto out_put;
49389
49390diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
49391index ab30253..4d86958 100644
49392--- a/fs/xfs/xfs_iops.c
49393+++ b/fs/xfs/xfs_iops.c
49394@@ -447,7 +447,7 @@ xfs_vn_put_link(
49395 struct nameidata *nd,
49396 void *p)
49397 {
49398- char *s = nd_get_link(nd);
49399+ const char *s = nd_get_link(nd);
49400
49401 if (!IS_ERR(s))
49402 kfree(s);
49403diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
49404new file mode 100644
49405index 0000000..2645296
49406--- /dev/null
49407+++ b/grsecurity/Kconfig
49408@@ -0,0 +1,1079 @@
49409+#
49410+# grecurity configuration
49411+#
49412+
49413+menu "Grsecurity"
49414+
49415+config GRKERNSEC
49416+ bool "Grsecurity"
49417+ select CRYPTO
49418+ select CRYPTO_SHA256
49419+ help
49420+ If you say Y here, you will be able to configure many features
49421+ that will enhance the security of your system. It is highly
49422+ recommended that you say Y here and read through the help
49423+ for each option so that you fully understand the features and
49424+ can evaluate their usefulness for your machine.
49425+
49426+choice
49427+ prompt "Security Level"
49428+ depends on GRKERNSEC
49429+ default GRKERNSEC_CUSTOM
49430+
49431+config GRKERNSEC_LOW
49432+ bool "Low"
49433+ select GRKERNSEC_LINK
49434+ select GRKERNSEC_FIFO
49435+ select GRKERNSEC_RANDNET
49436+ select GRKERNSEC_DMESG
49437+ select GRKERNSEC_CHROOT
49438+ select GRKERNSEC_CHROOT_CHDIR
49439+
49440+ help
49441+ If you choose this option, several of the grsecurity options will
49442+ be enabled that will give you greater protection against a number
49443+ of attacks, while assuring that none of your software will have any
49444+ conflicts with the additional security measures. If you run a lot
49445+ of unusual software, or you are having problems with the higher
49446+ security levels, you should say Y here. With this option, the
49447+ following features are enabled:
49448+
49449+ - Linking restrictions
49450+ - FIFO restrictions
49451+ - Restricted dmesg
49452+ - Enforced chdir("/") on chroot
49453+ - Runtime module disabling
49454+
49455+config GRKERNSEC_MEDIUM
49456+ bool "Medium"
49457+ select PAX
49458+ select PAX_EI_PAX
49459+ select PAX_PT_PAX_FLAGS
49460+ select PAX_HAVE_ACL_FLAGS
49461+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49462+ select GRKERNSEC_CHROOT
49463+ select GRKERNSEC_CHROOT_SYSCTL
49464+ select GRKERNSEC_LINK
49465+ select GRKERNSEC_FIFO
49466+ select GRKERNSEC_DMESG
49467+ select GRKERNSEC_RANDNET
49468+ select GRKERNSEC_FORKFAIL
49469+ select GRKERNSEC_TIME
49470+ select GRKERNSEC_SIGNAL
49471+ select GRKERNSEC_CHROOT
49472+ select GRKERNSEC_CHROOT_UNIX
49473+ select GRKERNSEC_CHROOT_MOUNT
49474+ select GRKERNSEC_CHROOT_PIVOT
49475+ select GRKERNSEC_CHROOT_DOUBLE
49476+ select GRKERNSEC_CHROOT_CHDIR
49477+ select GRKERNSEC_CHROOT_MKNOD
49478+ select GRKERNSEC_PROC
49479+ select GRKERNSEC_PROC_USERGROUP
49480+ select PAX_RANDUSTACK
49481+ select PAX_ASLR
49482+ select PAX_RANDMMAP
49483+ select PAX_REFCOUNT if (X86 || SPARC64)
49484+ select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
49485+
49486+ help
49487+ If you say Y here, several features in addition to those included
49488+ in the low additional security level will be enabled. These
49489+ features provide even more security to your system, though in rare
49490+ cases they may be incompatible with very old or poorly written
49491+ software. If you enable this option, make sure that your auth
49492+ service (identd) is running as gid 1001. With this option,
49493+ the following features (in addition to those provided in the
49494+ low additional security level) will be enabled:
49495+
49496+ - Failed fork logging
49497+ - Time change logging
49498+ - Signal logging
49499+ - Deny mounts in chroot
49500+ - Deny double chrooting
49501+ - Deny sysctl writes in chroot
49502+ - Deny mknod in chroot
49503+ - Deny access to abstract AF_UNIX sockets out of chroot
49504+ - Deny pivot_root in chroot
49505+ - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
49506+ - /proc restrictions with special GID set to 10 (usually wheel)
49507+ - Address Space Layout Randomization (ASLR)
49508+ - Prevent exploitation of most refcount overflows
49509+ - Bounds checking of copying between the kernel and userland
49510+
49511+config GRKERNSEC_HIGH
49512+ bool "High"
49513+ select GRKERNSEC_LINK
49514+ select GRKERNSEC_FIFO
49515+ select GRKERNSEC_DMESG
49516+ select GRKERNSEC_FORKFAIL
49517+ select GRKERNSEC_TIME
49518+ select GRKERNSEC_SIGNAL
49519+ select GRKERNSEC_CHROOT
49520+ select GRKERNSEC_CHROOT_SHMAT
49521+ select GRKERNSEC_CHROOT_UNIX
49522+ select GRKERNSEC_CHROOT_MOUNT
49523+ select GRKERNSEC_CHROOT_FCHDIR
49524+ select GRKERNSEC_CHROOT_PIVOT
49525+ select GRKERNSEC_CHROOT_DOUBLE
49526+ select GRKERNSEC_CHROOT_CHDIR
49527+ select GRKERNSEC_CHROOT_MKNOD
49528+ select GRKERNSEC_CHROOT_CAPS
49529+ select GRKERNSEC_CHROOT_SYSCTL
49530+ select GRKERNSEC_CHROOT_FINDTASK
49531+ select GRKERNSEC_SYSFS_RESTRICT
49532+ select GRKERNSEC_PROC
49533+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49534+ select GRKERNSEC_HIDESYM
49535+ select GRKERNSEC_BRUTE
49536+ select GRKERNSEC_PROC_USERGROUP
49537+ select GRKERNSEC_KMEM
49538+ select GRKERNSEC_RESLOG
49539+ select GRKERNSEC_RANDNET
49540+ select GRKERNSEC_PROC_ADD
49541+ select GRKERNSEC_CHROOT_CHMOD
49542+ select GRKERNSEC_CHROOT_NICE
49543+ select GRKERNSEC_SETXID if (X86 || SPARC64 || PPC || ARM || MIPS)
49544+ select GRKERNSEC_AUDIT_MOUNT
49545+ select GRKERNSEC_MODHARDEN if (MODULES)
49546+ select GRKERNSEC_HARDEN_PTRACE
49547+ select GRKERNSEC_PTRACE_READEXEC
49548+ select GRKERNSEC_VM86 if (X86_32)
49549+ select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
49550+ select PAX
49551+ select PAX_RANDUSTACK
49552+ select PAX_ASLR
49553+ select PAX_RANDMMAP
49554+ select PAX_NOEXEC
49555+ select PAX_MPROTECT
49556+ select PAX_EI_PAX
49557+ select PAX_PT_PAX_FLAGS
49558+ select PAX_HAVE_ACL_FLAGS
49559+ select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
49560+ select PAX_MEMORY_UDEREF if (X86 && !XEN)
49561+ select PAX_RANDKSTACK if (X86_TSC && X86)
49562+ select PAX_SEGMEXEC if (X86_32)
49563+ select PAX_PAGEEXEC
49564+ select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
49565+ select PAX_EMUTRAMP if (PARISC)
49566+ select PAX_EMUSIGRT if (PARISC)
49567+ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
49568+ select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
49569+ select PAX_REFCOUNT if (X86 || SPARC64)
49570+ select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
49571+ help
49572+ If you say Y here, many of the features of grsecurity will be
49573+ enabled, which will protect you against many kinds of attacks
49574+ against your system. The heightened security comes at a cost
49575+ of an increased chance of incompatibilities with rare software
49576+ on your machine. Since this security level enables PaX, you should
49577+ view <http://pax.grsecurity.net> and read about the PaX
49578+ project. While you are there, download chpax and run it on
49579+ binaries that cause problems with PaX. Also remember that
49580+ since the /proc restrictions are enabled, you must run your
49581+ identd as gid 1001. This security level enables the following
49582+ features in addition to those listed in the low and medium
49583+ security levels:
49584+
49585+ - Additional /proc restrictions
49586+ - Chmod restrictions in chroot
49587+ - No signals, ptrace, or viewing of processes outside of chroot
49588+ - Capability restrictions in chroot
49589+ - Deny fchdir out of chroot
49590+ - Priority restrictions in chroot
49591+ - Segmentation-based implementation of PaX
49592+ - Mprotect restrictions
49593+ - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
49594+ - Kernel stack randomization
49595+ - Mount/unmount/remount logging
49596+ - Kernel symbol hiding
49597+ - Hardening of module auto-loading
49598+ - Ptrace restrictions
49599+ - Restricted vm86 mode
49600+ - Restricted sysfs/debugfs
49601+ - Active kernel exploit response
49602+
49603+config GRKERNSEC_CUSTOM
49604+ bool "Custom"
49605+ help
49606+ If you say Y here, you will be able to configure every grsecurity
49607+ option, which allows you to enable many more features that aren't
49608+ covered in the basic security levels. These additional features
49609+ include TPE, socket restrictions, and the sysctl system for
49610+ grsecurity. It is advised that you read through the help for
49611+ each option to determine its usefulness in your situation.
49612+
49613+endchoice
49614+
49615+menu "Memory Protections"
49616+depends on GRKERNSEC
49617+
49618+config GRKERNSEC_KMEM
49619+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
49620+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
49621+ help
49622+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
49623+ be written to or read from to modify or leak the contents of the running
49624+ kernel. /dev/port will also not be allowed to be opened. If you have module
49625+ support disabled, enabling this will close up four ways that are
49626+ currently used to insert malicious code into the running kernel.
49627+ Even with all these features enabled, we still highly recommend that
49628+ you use the RBAC system, as it is still possible for an attacker to
49629+ modify the running kernel through privileged I/O granted by ioperm/iopl.
49630+ If you are not using XFree86, you may be able to stop this additional
49631+ case by enabling the 'Disable privileged I/O' option. Though nothing
49632+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
49633+ but only to video memory, which is the only writing we allow in this
49634+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
49635+ not be allowed to mprotect it with PROT_WRITE later.
49636+ It is highly recommended that you say Y here if you meet all the
49637+ conditions above.
49638+
49639+config GRKERNSEC_VM86
49640+ bool "Restrict VM86 mode"
49641+ depends on X86_32
49642+
49643+ help
49644+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
49645+ make use of a special execution mode on 32bit x86 processors called
49646+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
49647+ video cards and will still work with this option enabled. The purpose
49648+ of the option is to prevent exploitation of emulation errors in
49649+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
49650+ Nearly all users should be able to enable this option.
49651+
49652+config GRKERNSEC_IO
49653+ bool "Disable privileged I/O"
49654+ depends on X86
49655+ select RTC_CLASS
49656+ select RTC_INTF_DEV
49657+ select RTC_DRV_CMOS
49658+
49659+ help
49660+ If you say Y here, all ioperm and iopl calls will return an error.
49661+ Ioperm and iopl can be used to modify the running kernel.
49662+ Unfortunately, some programs need this access to operate properly,
49663+ the most notable of which are XFree86 and hwclock. hwclock can be
49664+ remedied by having RTC support in the kernel, so real-time
49665+ clock support is enabled if this option is enabled, to ensure
49666+ that hwclock operates correctly. XFree86 still will not
49667+ operate correctly with this option enabled, so DO NOT CHOOSE Y
49668+ IF YOU USE XFree86. If you use XFree86 and you still want to
49669+ protect your kernel against modification, use the RBAC system.
49670+
49671+config GRKERNSEC_PROC_MEMMAP
49672+ bool "Harden ASLR against information leaks and entropy reduction"
49673+ default y if (PAX_NOEXEC || PAX_ASLR)
49674+ depends on PAX_NOEXEC || PAX_ASLR
49675+ help
49676+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
49677+ give no information about the addresses of its mappings if
49678+ PaX features that rely on random addresses are enabled on the task.
49679+ In addition to sanitizing this information and disabling other
49680+ dangerous sources of information, this option causes reads of sensitive
49681+ /proc/<pid> entries where the file descriptor was opened in a different
49682+ task than the one performing the read. Such attempts are logged.
49683+ This option also limits argv/env strings for suid/sgid binaries
49684+ to 512KB to prevent a complete exhaustion of the stack entropy provided
49685+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
49686+ binaries to prevent alternative mmap layouts from being abused.
49687+
49688+ If you use PaX it is essential that you say Y here as it closes up
49689+ several holes that make full ASLR useless locally.
49690+
49691+config GRKERNSEC_BRUTE
49692+ bool "Deter exploit bruteforcing"
49693+ help
49694+ If you say Y here, attempts to bruteforce exploits against forking
49695+ daemons such as apache or sshd, as well as against suid/sgid binaries
49696+ will be deterred. When a child of a forking daemon is killed by PaX
49697+ or crashes due to an illegal instruction or other suspicious signal,
49698+ the parent process will be delayed 30 seconds upon every subsequent
49699+ fork until the administrator is able to assess the situation and
49700+ restart the daemon.
49701+ In the suid/sgid case, the attempt is logged, the user has all their
49702+ processes terminated, and they are prevented from executing any further
49703+ processes for 15 minutes.
49704+ It is recommended that you also enable signal logging in the auditing
49705+ section so that logs are generated when a process triggers a suspicious
49706+ signal.
49707+ If the sysctl option is enabled, a sysctl option with name
49708+ "deter_bruteforce" is created.
49709+
49710+
49711+config GRKERNSEC_MODHARDEN
49712+ bool "Harden module auto-loading"
49713+ depends on MODULES
49714+ help
49715+ If you say Y here, module auto-loading in response to use of some
49716+ feature implemented by an unloaded module will be restricted to
49717+ root users. Enabling this option helps defend against attacks
49718+ by unprivileged users who abuse the auto-loading behavior to
49719+ cause a vulnerable module to load that is then exploited.
49720+
49721+ If this option prevents a legitimate use of auto-loading for a
49722+ non-root user, the administrator can execute modprobe manually
49723+ with the exact name of the module mentioned in the alert log.
49724+ Alternatively, the administrator can add the module to the list
49725+ of modules loaded at boot by modifying init scripts.
49726+
49727+ Modification of init scripts will most likely be needed on
49728+ Ubuntu servers with encrypted home directory support enabled,
49729+ as the first non-root user logging in will cause the ecb(aes),
49730+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
49731+
49732+config GRKERNSEC_HIDESYM
49733+ bool "Hide kernel symbols"
49734+ help
49735+ If you say Y here, getting information on loaded modules, and
49736+ displaying all kernel symbols through a syscall will be restricted
49737+ to users with CAP_SYS_MODULE. For software compatibility reasons,
49738+ /proc/kallsyms will be restricted to the root user. The RBAC
49739+ system can hide that entry even from root.
49740+
49741+ This option also prevents leaking of kernel addresses through
49742+ several /proc entries.
49743+
49744+ Note that this option is only effective provided the following
49745+ conditions are met:
49746+ 1) The kernel using grsecurity is not precompiled by some distribution
49747+ 2) You have also enabled GRKERNSEC_DMESG
49748+ 3) You are using the RBAC system and hiding other files such as your
49749+ kernel image and System.map. Alternatively, enabling this option
49750+ causes the permissions on /boot, /lib/modules, and the kernel
49751+ source directory to change at compile time to prevent
49752+ reading by non-root users.
49753+ If the above conditions are met, this option will aid in providing a
49754+ useful protection against local kernel exploitation of overflows
49755+ and arbitrary read/write vulnerabilities.
49756+
49757+config GRKERNSEC_KERN_LOCKOUT
49758+ bool "Active kernel exploit response"
49759+ depends on X86 || ARM || PPC || SPARC
49760+ help
49761+ If you say Y here, when a PaX alert is triggered due to suspicious
49762+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
49763+ or an OOPs occurs due to bad memory accesses, instead of just
49764+ terminating the offending process (and potentially allowing
49765+ a subsequent exploit from the same user), we will take one of two
49766+ actions:
49767+ If the user was root, we will panic the system
49768+ If the user was non-root, we will log the attempt, terminate
49769+ all processes owned by the user, then prevent them from creating
49770+ any new processes until the system is restarted
49771+ This deters repeated kernel exploitation/bruteforcing attempts
49772+ and is useful for later forensics.
49773+
49774+endmenu
49775+menu "Role Based Access Control Options"
49776+depends on GRKERNSEC
49777+
49778+config GRKERNSEC_RBAC_DEBUG
49779+ bool
49780+
49781+config GRKERNSEC_NO_RBAC
49782+ bool "Disable RBAC system"
49783+ help
49784+ If you say Y here, the /dev/grsec device will be removed from the kernel,
49785+ preventing the RBAC system from being enabled. You should only say Y
49786+ here if you have no intention of using the RBAC system, so as to prevent
49787+ an attacker with root access from misusing the RBAC system to hide files
49788+ and processes when loadable module support and /dev/[k]mem have been
49789+ locked down.
49790+
49791+config GRKERNSEC_ACL_HIDEKERN
49792+ bool "Hide kernel processes"
49793+ help
49794+ If you say Y here, all kernel threads will be hidden to all
49795+ processes but those whose subject has the "view hidden processes"
49796+ flag.
49797+
49798+config GRKERNSEC_ACL_MAXTRIES
49799+ int "Maximum tries before password lockout"
49800+ default 3
49801+ help
49802+ This option enforces the maximum number of times a user can attempt
49803+ to authorize themselves with the grsecurity RBAC system before being
49804+ denied the ability to attempt authorization again for a specified time.
49805+ The lower the number, the harder it will be to brute-force a password.
49806+
49807+config GRKERNSEC_ACL_TIMEOUT
49808+ int "Time to wait after max password tries, in seconds"
49809+ default 30
49810+ help
49811+ This option specifies the time the user must wait after attempting to
49812+ authorize to the RBAC system with the maximum number of invalid
49813+ passwords. The higher the number, the harder it will be to brute-force
49814+ a password.
49815+
49816+endmenu
49817+menu "Filesystem Protections"
49818+depends on GRKERNSEC
49819+
49820+config GRKERNSEC_PROC
49821+ bool "Proc restrictions"
49822+ help
49823+ If you say Y here, the permissions of the /proc filesystem
49824+ will be altered to enhance system security and privacy. You MUST
49825+ choose either a user only restriction or a user and group restriction.
49826+ Depending upon the option you choose, you can either restrict users to
49827+ see only the processes they themselves run, or choose a group that can
49828+ view all processes and files normally restricted to root if you choose
49829+ the "restrict to user only" option. NOTE: If you're running identd or
49830+ ntpd as a non-root user, you will have to run it as the group you
49831+ specify here.
49832+
49833+config GRKERNSEC_PROC_USER
49834+ bool "Restrict /proc to user only"
49835+ depends on GRKERNSEC_PROC
49836+ help
49837+ If you say Y here, non-root users will only be able to view their own
49838+ processes, and restricts them from viewing network-related information,
49839+ and viewing kernel symbol and module information.
49840+
49841+config GRKERNSEC_PROC_USERGROUP
49842+ bool "Allow special group"
49843+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
49844+ help
49845+ If you say Y here, you will be able to select a group that will be
49846+ able to view all processes and network-related information. If you've
49847+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
49848+ remain hidden. This option is useful if you want to run identd as
49849+ a non-root user.
49850+
49851+config GRKERNSEC_PROC_GID
49852+ int "GID for special group"
49853+ depends on GRKERNSEC_PROC_USERGROUP
49854+ default 1001
49855+
49856+config GRKERNSEC_PROC_ADD
49857+ bool "Additional restrictions"
49858+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
49859+ help
49860+ If you say Y here, additional restrictions will be placed on
49861+ /proc that keep normal users from viewing device information and
49862+ slabinfo information that could be useful for exploits.
49863+
49864+config GRKERNSEC_LINK
49865+ bool "Linking restrictions"
49866+ help
49867+ If you say Y here, /tmp race exploits will be prevented, since users
49868+ will no longer be able to follow symlinks owned by other users in
49869+ world-writable +t directories (e.g. /tmp), unless the owner of the
49870+ symlink is the owner of the directory. users will also not be
49871+ able to hardlink to files they do not own. If the sysctl option is
49872+ enabled, a sysctl option with name "linking_restrictions" is created.
49873+
49874+config GRKERNSEC_FIFO
49875+ bool "FIFO restrictions"
49876+ help
49877+ If you say Y here, users will not be able to write to FIFOs they don't
49878+ own in world-writable +t directories (e.g. /tmp), unless the owner of
49879+ the FIFO is the same owner of the directory it's held in. If the sysctl
49880+ option is enabled, a sysctl option with name "fifo_restrictions" is
49881+ created.
49882+
49883+config GRKERNSEC_SYSFS_RESTRICT
49884+ bool "Sysfs/debugfs restriction"
49885+ depends on SYSFS
49886+ help
49887+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
49888+ any filesystem normally mounted under it (e.g. debugfs) will be
49889+ mostly accessible only by root. These filesystems generally provide access
49890+ to hardware and debug information that isn't appropriate for unprivileged
49891+ users of the system. Sysfs and debugfs have also become a large source
49892+ of new vulnerabilities, ranging from infoleaks to local compromise.
49893+ There has been very little oversight with an eye toward security involved
49894+ in adding new exporters of information to these filesystems, so their
49895+ use is discouraged.
49896+ For reasons of compatibility, a few directories have been whitelisted
49897+ for access by non-root users:
49898+ /sys/fs/selinux
49899+ /sys/fs/fuse
49900+ /sys/devices/system/cpu
49901+
49902+config GRKERNSEC_ROFS
49903+ bool "Runtime read-only mount protection"
49904+ help
49905+ If you say Y here, a sysctl option with name "romount_protect" will
49906+ be created. By setting this option to 1 at runtime, filesystems
49907+ will be protected in the following ways:
49908+ * No new writable mounts will be allowed
49909+ * Existing read-only mounts won't be able to be remounted read/write
49910+ * Write operations will be denied on all block devices
49911+ This option acts independently of grsec_lock: once it is set to 1,
49912+ it cannot be turned off. Therefore, please be mindful of the resulting
49913+ behavior if this option is enabled in an init script on a read-only
49914+ filesystem. This feature is mainly intended for secure embedded systems.
49915+
49916+config GRKERNSEC_CHROOT
49917+ bool "Chroot jail restrictions"
49918+ help
49919+ If you say Y here, you will be able to choose several options that will
49920+ make breaking out of a chrooted jail much more difficult. If you
49921+ encounter no software incompatibilities with the following options, it
49922+ is recommended that you enable each one.
49923+
49924+config GRKERNSEC_CHROOT_MOUNT
49925+ bool "Deny mounts"
49926+ depends on GRKERNSEC_CHROOT
49927+ help
49928+ If you say Y here, processes inside a chroot will not be able to
49929+ mount or remount filesystems. If the sysctl option is enabled, a
49930+ sysctl option with name "chroot_deny_mount" is created.
49931+
49932+config GRKERNSEC_CHROOT_DOUBLE
49933+ bool "Deny double-chroots"
49934+ depends on GRKERNSEC_CHROOT
49935+ help
49936+ If you say Y here, processes inside a chroot will not be able to chroot
49937+ again outside the chroot. This is a widely used method of breaking
49938+ out of a chroot jail and should not be allowed. If the sysctl
49939+ option is enabled, a sysctl option with name
49940+ "chroot_deny_chroot" is created.
49941+
49942+config GRKERNSEC_CHROOT_PIVOT
49943+ bool "Deny pivot_root in chroot"
49944+ depends on GRKERNSEC_CHROOT
49945+ help
49946+ If you say Y here, processes inside a chroot will not be able to use
49947+ a function called pivot_root() that was introduced in Linux 2.3.41. It
49948+ works similar to chroot in that it changes the root filesystem. This
49949+ function could be misused in a chrooted process to attempt to break out
49950+ of the chroot, and therefore should not be allowed. If the sysctl
49951+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
49952+ created.
49953+
49954+config GRKERNSEC_CHROOT_CHDIR
49955+ bool "Enforce chdir(\"/\") on all chroots"
49956+ depends on GRKERNSEC_CHROOT
49957+ help
49958+ If you say Y here, the current working directory of all newly-chrooted
49959+ applications will be set to the the root directory of the chroot.
49960+ The man page on chroot(2) states:
49961+ Note that this call does not change the current working
49962+ directory, so that `.' can be outside the tree rooted at
49963+ `/'. In particular, the super-user can escape from a
49964+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
49965+
49966+ It is recommended that you say Y here, since it's not known to break
49967+ any software. If the sysctl option is enabled, a sysctl option with
49968+ name "chroot_enforce_chdir" is created.
49969+
49970+config GRKERNSEC_CHROOT_CHMOD
49971+ bool "Deny (f)chmod +s"
49972+ depends on GRKERNSEC_CHROOT
49973+ help
49974+ If you say Y here, processes inside a chroot will not be able to chmod
49975+ or fchmod files to make them have suid or sgid bits. This protects
49976+ against another published method of breaking a chroot. If the sysctl
49977+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
49978+ created.
49979+
49980+config GRKERNSEC_CHROOT_FCHDIR
49981+ bool "Deny fchdir out of chroot"
49982+ depends on GRKERNSEC_CHROOT
49983+ help
49984+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
49985+ to a file descriptor of the chrooting process that points to a directory
49986+ outside the filesystem will be stopped. If the sysctl option
49987+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
49988+
49989+config GRKERNSEC_CHROOT_MKNOD
49990+ bool "Deny mknod"
49991+ depends on GRKERNSEC_CHROOT
49992+ help
49993+ If you say Y here, processes inside a chroot will not be allowed to
49994+ mknod. The problem with using mknod inside a chroot is that it
49995+ would allow an attacker to create a device entry that is the same
49996+ as one on the physical root of your system, which could range from
49997+ anything from the console device to a device for your harddrive (which
49998+ they could then use to wipe the drive or steal data). It is recommended
49999+ that you say Y here, unless you run into software incompatibilities.
50000+ If the sysctl option is enabled, a sysctl option with name
50001+ "chroot_deny_mknod" is created.
50002+
50003+config GRKERNSEC_CHROOT_SHMAT
50004+ bool "Deny shmat() out of chroot"
50005+ depends on GRKERNSEC_CHROOT
50006+ help
50007+ If you say Y here, processes inside a chroot will not be able to attach
50008+ to shared memory segments that were created outside of the chroot jail.
50009+ It is recommended that you say Y here. If the sysctl option is enabled,
50010+ a sysctl option with name "chroot_deny_shmat" is created.
50011+
50012+config GRKERNSEC_CHROOT_UNIX
50013+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
50014+ depends on GRKERNSEC_CHROOT
50015+ help
50016+ If you say Y here, processes inside a chroot will not be able to
50017+ connect to abstract (meaning not belonging to a filesystem) Unix
50018+ domain sockets that were bound outside of a chroot. It is recommended
50019+ that you say Y here. If the sysctl option is enabled, a sysctl option
50020+ with name "chroot_deny_unix" is created.
50021+
50022+config GRKERNSEC_CHROOT_FINDTASK
50023+ bool "Protect outside processes"
50024+ depends on GRKERNSEC_CHROOT
50025+ help
50026+ If you say Y here, processes inside a chroot will not be able to
50027+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50028+ getsid, or view any process outside of the chroot. If the sysctl
50029+ option is enabled, a sysctl option with name "chroot_findtask" is
50030+ created.
50031+
50032+config GRKERNSEC_CHROOT_NICE
50033+ bool "Restrict priority changes"
50034+ depends on GRKERNSEC_CHROOT
50035+ help
50036+ If you say Y here, processes inside a chroot will not be able to raise
50037+ the priority of processes in the chroot, or alter the priority of
50038+ processes outside the chroot. This provides more security than simply
50039+ removing CAP_SYS_NICE from the process' capability set. If the
50040+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50041+ is created.
50042+
50043+config GRKERNSEC_CHROOT_SYSCTL
50044+ bool "Deny sysctl writes"
50045+ depends on GRKERNSEC_CHROOT
50046+ help
50047+ If you say Y here, an attacker in a chroot will not be able to
50048+ write to sysctl entries, either by sysctl(2) or through a /proc
50049+ interface. It is strongly recommended that you say Y here. If the
50050+ sysctl option is enabled, a sysctl option with name
50051+ "chroot_deny_sysctl" is created.
50052+
50053+config GRKERNSEC_CHROOT_CAPS
50054+ bool "Capability restrictions"
50055+ depends on GRKERNSEC_CHROOT
50056+ help
50057+ If you say Y here, the capabilities on all processes within a
50058+ chroot jail will be lowered to stop module insertion, raw i/o,
50059+ system and net admin tasks, rebooting the system, modifying immutable
50060+ files, modifying IPC owned by another, and changing the system time.
50061+ This is left an option because it can break some apps. Disable this
50062+ if your chrooted apps are having problems performing those kinds of
50063+ tasks. If the sysctl option is enabled, a sysctl option with
50064+ name "chroot_caps" is created.
50065+
50066+endmenu
50067+menu "Kernel Auditing"
50068+depends on GRKERNSEC
50069+
50070+config GRKERNSEC_AUDIT_GROUP
50071+ bool "Single group for auditing"
50072+ help
50073+ If you say Y here, the exec, chdir, and (un)mount logging features
50074+ will only operate on a group you specify. This option is recommended
50075+ if you only want to watch certain users instead of having a large
50076+ amount of logs from the entire system. If the sysctl option is enabled,
50077+ a sysctl option with name "audit_group" is created.
50078+
50079+config GRKERNSEC_AUDIT_GID
50080+ int "GID for auditing"
50081+ depends on GRKERNSEC_AUDIT_GROUP
50082+ default 1007
50083+
50084+config GRKERNSEC_EXECLOG
50085+ bool "Exec logging"
50086+ help
50087+ If you say Y here, all execve() calls will be logged (since the
50088+ other exec*() calls are frontends to execve(), all execution
50089+ will be logged). Useful for shell-servers that like to keep track
50090+ of their users. If the sysctl option is enabled, a sysctl option with
50091+ name "exec_logging" is created.
50092+ WARNING: This option when enabled will produce a LOT of logs, especially
50093+ on an active system.
50094+
50095+config GRKERNSEC_RESLOG
50096+ bool "Resource logging"
50097+ help
50098+ If you say Y here, all attempts to overstep resource limits will
50099+ be logged with the resource name, the requested size, and the current
50100+ limit. It is highly recommended that you say Y here. If the sysctl
50101+ option is enabled, a sysctl option with name "resource_logging" is
50102+ created. If the RBAC system is enabled, the sysctl value is ignored.
50103+
50104+config GRKERNSEC_CHROOT_EXECLOG
50105+ bool "Log execs within chroot"
50106+ help
50107+ If you say Y here, all executions inside a chroot jail will be logged
50108+ to syslog. This can cause a large amount of logs if certain
50109+ applications (eg. djb's daemontools) are installed on the system, and
50110+ is therefore left as an option. If the sysctl option is enabled, a
50111+ sysctl option with name "chroot_execlog" is created.
50112+
50113+config GRKERNSEC_AUDIT_PTRACE
50114+ bool "Ptrace logging"
50115+ help
50116+ If you say Y here, all attempts to attach to a process via ptrace
50117+ will be logged. If the sysctl option is enabled, a sysctl option
50118+ with name "audit_ptrace" is created.
50119+
50120+config GRKERNSEC_AUDIT_CHDIR
50121+ bool "Chdir logging"
50122+ help
50123+ If you say Y here, all chdir() calls will be logged. If the sysctl
50124+ option is enabled, a sysctl option with name "audit_chdir" is created.
50125+
50126+config GRKERNSEC_AUDIT_MOUNT
50127+ bool "(Un)Mount logging"
50128+ help
50129+ If you say Y here, all mounts and unmounts will be logged. If the
50130+ sysctl option is enabled, a sysctl option with name "audit_mount" is
50131+ created.
50132+
50133+config GRKERNSEC_SIGNAL
50134+ bool "Signal logging"
50135+ help
50136+ If you say Y here, certain important signals will be logged, such as
50137+ SIGSEGV, which will as a result inform you of when a error in a program
50138+ occurred, which in some cases could mean a possible exploit attempt.
50139+ If the sysctl option is enabled, a sysctl option with name
50140+ "signal_logging" is created.
50141+
50142+config GRKERNSEC_FORKFAIL
50143+ bool "Fork failure logging"
50144+ help
50145+ If you say Y here, all failed fork() attempts will be logged.
50146+ This could suggest a fork bomb, or someone attempting to overstep
50147+ their process limit. If the sysctl option is enabled, a sysctl option
50148+ with name "forkfail_logging" is created.
50149+
50150+config GRKERNSEC_TIME
50151+ bool "Time change logging"
50152+ help
50153+ If you say Y here, any changes of the system clock will be logged.
50154+ If the sysctl option is enabled, a sysctl option with name
50155+ "timechange_logging" is created.
50156+
50157+config GRKERNSEC_PROC_IPADDR
50158+ bool "/proc/<pid>/ipaddr support"
50159+ help
50160+ If you say Y here, a new entry will be added to each /proc/<pid>
50161+ directory that contains the IP address of the person using the task.
50162+ The IP is carried across local TCP and AF_UNIX stream sockets.
50163+ This information can be useful for IDS/IPSes to perform remote response
50164+ to a local attack. The entry is readable by only the owner of the
50165+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50166+ the RBAC system), and thus does not create privacy concerns.
50167+
50168+config GRKERNSEC_RWXMAP_LOG
50169+ bool 'Denied RWX mmap/mprotect logging'
50170+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50171+ help
50172+ If you say Y here, calls to mmap() and mprotect() with explicit
50173+ usage of PROT_WRITE and PROT_EXEC together will be logged when
50174+ denied by the PAX_MPROTECT feature. If the sysctl option is
50175+ enabled, a sysctl option with name "rwxmap_logging" is created.
50176+
50177+config GRKERNSEC_AUDIT_TEXTREL
50178+ bool 'ELF text relocations logging (READ HELP)'
50179+ depends on PAX_MPROTECT
50180+ help
50181+ If you say Y here, text relocations will be logged with the filename
50182+ of the offending library or binary. The purpose of the feature is
50183+ to help Linux distribution developers get rid of libraries and
50184+ binaries that need text relocations which hinder the future progress
50185+ of PaX. Only Linux distribution developers should say Y here, and
50186+ never on a production machine, as this option creates an information
50187+ leak that could aid an attacker in defeating the randomization of
50188+ a single memory region. If the sysctl option is enabled, a sysctl
50189+ option with name "audit_textrel" is created.
50190+
50191+endmenu
50192+
50193+menu "Executable Protections"
50194+depends on GRKERNSEC
50195+
50196+config GRKERNSEC_DMESG
50197+ bool "Dmesg(8) restriction"
50198+ help
50199+ If you say Y here, non-root users will not be able to use dmesg(8)
50200+ to view up to the last 4kb of messages in the kernel's log buffer.
50201+ The kernel's log buffer often contains kernel addresses and other
50202+ identifying information useful to an attacker in fingerprinting a
50203+ system for a targeted exploit.
50204+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
50205+ created.
50206+
50207+config GRKERNSEC_HARDEN_PTRACE
50208+ bool "Deter ptrace-based process snooping"
50209+ help
50210+ If you say Y here, TTY sniffers and other malicious monitoring
50211+ programs implemented through ptrace will be defeated. If you
50212+ have been using the RBAC system, this option has already been
50213+ enabled for several years for all users, with the ability to make
50214+ fine-grained exceptions.
50215+
50216+ This option only affects the ability of non-root users to ptrace
50217+ processes that are not a descendent of the ptracing process.
50218+ This means that strace ./binary and gdb ./binary will still work,
50219+ but attaching to arbitrary processes will not. If the sysctl
50220+ option is enabled, a sysctl option with name "harden_ptrace" is
50221+ created.
50222+
50223+config GRKERNSEC_PTRACE_READEXEC
50224+ bool "Require read access to ptrace sensitive binaries"
50225+ help
50226+ If you say Y here, unprivileged users will not be able to ptrace unreadable
50227+ binaries. This option is useful in environments that
50228+ remove the read bits (e.g. file mode 4711) from suid binaries to
50229+ prevent infoleaking of their contents. This option adds
50230+ consistency to the use of that file mode, as the binary could normally
50231+ be read out when run without privileges while ptracing.
50232+
50233+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
50234+ is created.
50235+
50236+config GRKERNSEC_SETXID
50237+ bool "Enforce consistent multithreaded privileges"
50238+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
50239+ help
50240+ If you say Y here, a change from a root uid to a non-root uid
50241+ in a multithreaded application will cause the resulting uids,
50242+ gids, supplementary groups, and capabilities in that thread
50243+ to be propagated to the other threads of the process. In most
50244+ cases this is unnecessary, as glibc will emulate this behavior
50245+ on behalf of the application. Other libcs do not act in the
50246+ same way, allowing the other threads of the process to continue
50247+ running with root privileges. If the sysctl option is enabled,
50248+ a sysctl option with name "consistent_setxid" is created.
50249+
50250+config GRKERNSEC_TPE
50251+ bool "Trusted Path Execution (TPE)"
50252+ help
50253+ If you say Y here, you will be able to choose a gid to add to the
50254+ supplementary groups of users you want to mark as "untrusted."
50255+ These users will not be able to execute any files that are not in
50256+ root-owned directories writable only by root. If the sysctl option
50257+ is enabled, a sysctl option with name "tpe" is created.
50258+
50259+config GRKERNSEC_TPE_ALL
50260+ bool "Partially restrict all non-root users"
50261+ depends on GRKERNSEC_TPE
50262+ help
50263+ If you say Y here, all non-root users will be covered under
50264+ a weaker TPE restriction. This is separate from, and in addition to,
50265+ the main TPE options that you have selected elsewhere. Thus, if a
50266+ "trusted" GID is chosen, this restriction applies to even that GID.
50267+ Under this restriction, all non-root users will only be allowed to
50268+ execute files in directories they own that are not group or
50269+ world-writable, or in directories owned by root and writable only by
50270+ root. If the sysctl option is enabled, a sysctl option with name
50271+ "tpe_restrict_all" is created.
50272+
50273+config GRKERNSEC_TPE_INVERT
50274+ bool "Invert GID option"
50275+ depends on GRKERNSEC_TPE
50276+ help
50277+ If you say Y here, the group you specify in the TPE configuration will
50278+ decide what group TPE restrictions will be *disabled* for. This
50279+ option is useful if you want TPE restrictions to be applied to most
50280+ users on the system. If the sysctl option is enabled, a sysctl option
50281+ with name "tpe_invert" is created. Unlike other sysctl options, this
50282+ entry will default to on for backward-compatibility.
50283+
50284+config GRKERNSEC_TPE_GID
50285+ int "GID for untrusted users"
50286+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
50287+ default 1005
50288+ help
50289+ Setting this GID determines what group TPE restrictions will be
50290+ *enabled* for. If the sysctl option is enabled, a sysctl option
50291+ with name "tpe_gid" is created.
50292+
50293+config GRKERNSEC_TPE_GID
50294+ int "GID for trusted users"
50295+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50296+ default 1005
50297+ help
50298+ Setting this GID determines what group TPE restrictions will be
50299+ *disabled* for. If the sysctl option is enabled, a sysctl option
50300+ with name "tpe_gid" is created.
50301+
50302+endmenu
50303+menu "Network Protections"
50304+depends on GRKERNSEC
50305+
50306+config GRKERNSEC_RANDNET
50307+ bool "Larger entropy pools"
50308+ help
50309+ If you say Y here, the entropy pools used for many features of Linux
50310+ and grsecurity will be doubled in size. Since several grsecurity
50311+ features use additional randomness, it is recommended that you say Y
50312+ here. Saying Y here has a similar effect as modifying
50313+ /proc/sys/kernel/random/poolsize.
50314+
50315+config GRKERNSEC_BLACKHOLE
50316+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50317+ depends on NET
50318+ help
50319+ If you say Y here, neither TCP resets nor ICMP
50320+ destination-unreachable packets will be sent in response to packets
50321+ sent to ports for which no associated listening process exists.
50322+ This feature supports both IPV4 and IPV6 and exempts the
50323+ loopback interface from blackholing. Enabling this feature
50324+ makes a host more resilient to DoS attacks and reduces network
50325+ visibility against scanners.
50326+
50327+ The blackhole feature as-implemented is equivalent to the FreeBSD
50328+ blackhole feature, as it prevents RST responses to all packets, not
50329+ just SYNs. Under most application behavior this causes no
50330+ problems, but applications (like haproxy) may not close certain
50331+ connections in a way that cleanly terminates them on the remote
50332+ end, leaving the remote host in LAST_ACK state. Because of this
50333+ side-effect and to prevent intentional LAST_ACK DoSes, this
50334+ feature also adds automatic mitigation against such attacks.
50335+ The mitigation drastically reduces the amount of time a socket
50336+ can spend in LAST_ACK state. If you're using haproxy and not
50337+ all servers it connects to have this option enabled, consider
50338+ disabling this feature on the haproxy host.
50339+
50340+ If the sysctl option is enabled, two sysctl options with names
50341+ "ip_blackhole" and "lastack_retries" will be created.
50342+ While "ip_blackhole" takes the standard zero/non-zero on/off
50343+ toggle, "lastack_retries" uses the same kinds of values as
50344+ "tcp_retries1" and "tcp_retries2". The default value of 4
50345+ prevents a socket from lasting more than 45 seconds in LAST_ACK
50346+ state.
50347+
50348+config GRKERNSEC_SOCKET
50349+ bool "Socket restrictions"
50350+ depends on NET
50351+ help
50352+ If you say Y here, you will be able to choose from several options.
50353+ If you assign a GID on your system and add it to the supplementary
50354+ groups of users you want to restrict socket access to, this patch
50355+ will perform up to three things, based on the option(s) you choose.
50356+
50357+config GRKERNSEC_SOCKET_ALL
50358+ bool "Deny any sockets to group"
50359+ depends on GRKERNSEC_SOCKET
50360+ help
50361+ If you say Y here, you will be able to choose a GID of whose users will
50362+ be unable to connect to other hosts from your machine or run server
50363+ applications from your machine. If the sysctl option is enabled, a
50364+ sysctl option with name "socket_all" is created.
50365+
50366+config GRKERNSEC_SOCKET_ALL_GID
50367+ int "GID to deny all sockets for"
50368+ depends on GRKERNSEC_SOCKET_ALL
50369+ default 1004
50370+ help
50371+ Here you can choose the GID to disable socket access for. Remember to
50372+ add the users you want socket access disabled for to the GID
50373+ specified here. If the sysctl option is enabled, a sysctl option
50374+ with name "socket_all_gid" is created.
50375+
50376+config GRKERNSEC_SOCKET_CLIENT
50377+ bool "Deny client sockets to group"
50378+ depends on GRKERNSEC_SOCKET
50379+ help
50380+ If you say Y here, you will be able to choose a GID of whose users will
50381+ be unable to connect to other hosts from your machine, but will be
50382+ able to run servers. If this option is enabled, all users in the group
50383+ you specify will have to use passive mode when initiating ftp transfers
50384+ from the shell on your machine. If the sysctl option is enabled, a
50385+ sysctl option with name "socket_client" is created.
50386+
50387+config GRKERNSEC_SOCKET_CLIENT_GID
50388+ int "GID to deny client sockets for"
50389+ depends on GRKERNSEC_SOCKET_CLIENT
50390+ default 1003
50391+ help
50392+ Here you can choose the GID to disable client socket access for.
50393+ Remember to add the users you want client socket access disabled for to
50394+ the GID specified here. If the sysctl option is enabled, a sysctl
50395+ option with name "socket_client_gid" is created.
50396+
50397+config GRKERNSEC_SOCKET_SERVER
50398+ bool "Deny server sockets to group"
50399+ depends on GRKERNSEC_SOCKET
50400+ help
50401+ If you say Y here, you will be able to choose a GID of whose users will
50402+ be unable to run server applications from your machine. If the sysctl
50403+ option is enabled, a sysctl option with name "socket_server" is created.
50404+
50405+config GRKERNSEC_SOCKET_SERVER_GID
50406+ int "GID to deny server sockets for"
50407+ depends on GRKERNSEC_SOCKET_SERVER
50408+ default 1002
50409+ help
50410+ Here you can choose the GID to disable server socket access for.
50411+ Remember to add the users you want server socket access disabled for to
50412+ the GID specified here. If the sysctl option is enabled, a sysctl
50413+ option with name "socket_server_gid" is created.
50414+
50415+endmenu
50416+menu "Sysctl support"
50417+depends on GRKERNSEC && SYSCTL
50418+
50419+config GRKERNSEC_SYSCTL
50420+ bool "Sysctl support"
50421+ help
50422+ If you say Y here, you will be able to change the options that
50423+ grsecurity runs with at bootup, without having to recompile your
50424+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50425+ to enable (1) or disable (0) various features. All the sysctl entries
50426+ are mutable until the "grsec_lock" entry is set to a non-zero value.
50427+ All features enabled in the kernel configuration are disabled at boot
50428+ if you do not say Y to the "Turn on features by default" option.
50429+ All options should be set at startup, and the grsec_lock entry should
50430+ be set to a non-zero value after all the options are set.
50431+ *THIS IS EXTREMELY IMPORTANT*
50432+
50433+config GRKERNSEC_SYSCTL_DISTRO
50434+ bool "Extra sysctl support for distro makers (READ HELP)"
50435+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50436+ help
50437+ If you say Y here, additional sysctl options will be created
50438+ for features that affect processes running as root. Therefore,
50439+ it is critical when using this option that the grsec_lock entry be
50440+ enabled after boot. Only distros with prebuilt kernel packages
50441+ with this option enabled that can ensure grsec_lock is enabled
50442+ after boot should use this option.
50443+ *Failure to set grsec_lock after boot makes all grsec features
50444+ this option covers useless*
50445+
50446+ Currently this option creates the following sysctl entries:
50447+ "Disable Privileged I/O": "disable_priv_io"
50448+
50449+config GRKERNSEC_SYSCTL_ON
50450+ bool "Turn on features by default"
50451+ depends on GRKERNSEC_SYSCTL
50452+ help
50453+ If you say Y here, instead of having all features enabled in the
50454+ kernel configuration disabled at boot time, the features will be
50455+ enabled at boot time. It is recommended you say Y here unless
50456+ there is some reason you would want all sysctl-tunable features to
50457+ be disabled by default. As mentioned elsewhere, it is important
50458+ to enable the grsec_lock entry once you have finished modifying
50459+ the sysctl entries.
50460+
50461+endmenu
50462+menu "Logging Options"
50463+depends on GRKERNSEC
50464+
50465+config GRKERNSEC_FLOODTIME
50466+ int "Seconds in between log messages (minimum)"
50467+ default 10
50468+ help
50469+ This option allows you to enforce the number of seconds between
50470+ grsecurity log messages. The default should be suitable for most
50471+ people, however, if you choose to change it, choose a value small enough
50472+ to allow informative logs to be produced, but large enough to
50473+ prevent flooding.
50474+
50475+config GRKERNSEC_FLOODBURST
50476+ int "Number of messages in a burst (maximum)"
50477+ default 6
50478+ help
50479+ This option allows you to choose the maximum number of messages allowed
50480+ within the flood time interval you chose in a separate option. The
50481+ default should be suitable for most people, however if you find that
50482+ many of your logs are being interpreted as flooding, you may want to
50483+ raise this value.
50484+
50485+endmenu
50486+
50487+endmenu
50488diff --git a/grsecurity/Makefile b/grsecurity/Makefile
50489new file mode 100644
50490index 0000000..1b9afa9
50491--- /dev/null
50492+++ b/grsecurity/Makefile
50493@@ -0,0 +1,38 @@
50494+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
50495+# during 2001-2009 it has been completely redesigned by Brad Spengler
50496+# into an RBAC system
50497+#
50498+# All code in this directory and various hooks inserted throughout the kernel
50499+# are copyright Brad Spengler - Open Source Security, Inc., and released
50500+# under the GPL v2 or higher
50501+
50502+KBUILD_CFLAGS += -Werror
50503+
50504+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
50505+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
50506+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
50507+
50508+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
50509+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
50510+ gracl_learn.o grsec_log.o
50511+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
50512+
50513+ifdef CONFIG_NET
50514+obj-y += grsec_sock.o
50515+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
50516+endif
50517+
50518+ifndef CONFIG_GRKERNSEC
50519+obj-y += grsec_disabled.o
50520+endif
50521+
50522+ifdef CONFIG_GRKERNSEC_HIDESYM
50523+extra-y := grsec_hidesym.o
50524+$(obj)/grsec_hidesym.o:
50525+ @-chmod -f 500 /boot
50526+ @-chmod -f 500 /lib/modules
50527+ @-chmod -f 500 /lib64/modules
50528+ @-chmod -f 500 /lib32/modules
50529+ @-chmod -f 700 .
50530+ @echo ' grsec: protected kernel image paths'
50531+endif
50532diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
50533new file mode 100644
50534index 0000000..a6d83f0
50535--- /dev/null
50536+++ b/grsecurity/gracl.c
50537@@ -0,0 +1,4193 @@
50538+#include <linux/kernel.h>
50539+#include <linux/module.h>
50540+#include <linux/sched.h>
50541+#include <linux/mm.h>
50542+#include <linux/file.h>
50543+#include <linux/fs.h>
50544+#include <linux/namei.h>
50545+#include <linux/mount.h>
50546+#include <linux/tty.h>
50547+#include <linux/proc_fs.h>
50548+#include <linux/lglock.h>
50549+#include <linux/slab.h>
50550+#include <linux/vmalloc.h>
50551+#include <linux/types.h>
50552+#include <linux/sysctl.h>
50553+#include <linux/netdevice.h>
50554+#include <linux/ptrace.h>
50555+#include <linux/gracl.h>
50556+#include <linux/gralloc.h>
50557+#include <linux/security.h>
50558+#include <linux/grinternal.h>
50559+#include <linux/pid_namespace.h>
50560+#include <linux/fdtable.h>
50561+#include <linux/percpu.h>
50562+#include "../fs/mount.h"
50563+
50564+#include <asm/uaccess.h>
50565+#include <asm/errno.h>
50566+#include <asm/mman.h>
50567+
50568+static struct acl_role_db acl_role_set;
50569+static struct name_db name_set;
50570+static struct inodev_db inodev_set;
50571+
50572+/* for keeping track of userspace pointers used for subjects, so we
50573+ can share references in the kernel as well
50574+*/
50575+
50576+static struct path real_root;
50577+
50578+static struct acl_subj_map_db subj_map_set;
50579+
50580+static struct acl_role_label *default_role;
50581+
50582+static struct acl_role_label *role_list;
50583+
50584+static u16 acl_sp_role_value;
50585+
50586+extern char *gr_shared_page[4];
50587+static DEFINE_MUTEX(gr_dev_mutex);
50588+DEFINE_RWLOCK(gr_inode_lock);
50589+
50590+struct gr_arg *gr_usermode;
50591+
50592+static unsigned int gr_status __read_only = GR_STATUS_INIT;
50593+
50594+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
50595+extern void gr_clear_learn_entries(void);
50596+
50597+#ifdef CONFIG_GRKERNSEC_RESLOG
50598+extern void gr_log_resource(const struct task_struct *task,
50599+ const int res, const unsigned long wanted, const int gt);
50600+#endif
50601+
50602+unsigned char *gr_system_salt;
50603+unsigned char *gr_system_sum;
50604+
50605+static struct sprole_pw **acl_special_roles = NULL;
50606+static __u16 num_sprole_pws = 0;
50607+
50608+static struct acl_role_label *kernel_role = NULL;
50609+
50610+static unsigned int gr_auth_attempts = 0;
50611+static unsigned long gr_auth_expires = 0UL;
50612+
50613+#ifdef CONFIG_NET
50614+extern struct vfsmount *sock_mnt;
50615+#endif
50616+
50617+extern struct vfsmount *pipe_mnt;
50618+extern struct vfsmount *shm_mnt;
50619+#ifdef CONFIG_HUGETLBFS
50620+extern struct vfsmount *hugetlbfs_vfsmount;
50621+#endif
50622+
50623+static struct acl_object_label *fakefs_obj_rw;
50624+static struct acl_object_label *fakefs_obj_rwx;
50625+
50626+extern int gr_init_uidset(void);
50627+extern void gr_free_uidset(void);
50628+extern void gr_remove_uid(uid_t uid);
50629+extern int gr_find_uid(uid_t uid);
50630+
50631+DECLARE_BRLOCK(vfsmount_lock);
50632+
50633+__inline__ int
50634+gr_acl_is_enabled(void)
50635+{
50636+ return (gr_status & GR_READY);
50637+}
50638+
50639+#ifdef CONFIG_BTRFS_FS
50640+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
50641+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
50642+#endif
50643+
50644+static inline dev_t __get_dev(const struct dentry *dentry)
50645+{
50646+#ifdef CONFIG_BTRFS_FS
50647+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
50648+ return get_btrfs_dev_from_inode(dentry->d_inode);
50649+ else
50650+#endif
50651+ return dentry->d_inode->i_sb->s_dev;
50652+}
50653+
50654+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
50655+{
50656+ return __get_dev(dentry);
50657+}
50658+
50659+static char gr_task_roletype_to_char(struct task_struct *task)
50660+{
50661+ switch (task->role->roletype &
50662+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
50663+ GR_ROLE_SPECIAL)) {
50664+ case GR_ROLE_DEFAULT:
50665+ return 'D';
50666+ case GR_ROLE_USER:
50667+ return 'U';
50668+ case GR_ROLE_GROUP:
50669+ return 'G';
50670+ case GR_ROLE_SPECIAL:
50671+ return 'S';
50672+ }
50673+
50674+ return 'X';
50675+}
50676+
50677+char gr_roletype_to_char(void)
50678+{
50679+ return gr_task_roletype_to_char(current);
50680+}
50681+
50682+__inline__ int
50683+gr_acl_tpe_check(void)
50684+{
50685+ if (unlikely(!(gr_status & GR_READY)))
50686+ return 0;
50687+ if (current->role->roletype & GR_ROLE_TPE)
50688+ return 1;
50689+ else
50690+ return 0;
50691+}
50692+
50693+int
50694+gr_handle_rawio(const struct inode *inode)
50695+{
50696+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
50697+ if (inode && S_ISBLK(inode->i_mode) &&
50698+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
50699+ !capable(CAP_SYS_RAWIO))
50700+ return 1;
50701+#endif
50702+ return 0;
50703+}
50704+
50705+static int
50706+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
50707+{
50708+ if (likely(lena != lenb))
50709+ return 0;
50710+
50711+ return !memcmp(a, b, lena);
50712+}
50713+
50714+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
50715+{
50716+ *buflen -= namelen;
50717+ if (*buflen < 0)
50718+ return -ENAMETOOLONG;
50719+ *buffer -= namelen;
50720+ memcpy(*buffer, str, namelen);
50721+ return 0;
50722+}
50723+
50724+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
50725+{
50726+ return prepend(buffer, buflen, name->name, name->len);
50727+}
50728+
50729+static int prepend_path(const struct path *path, struct path *root,
50730+ char **buffer, int *buflen)
50731+{
50732+ struct dentry *dentry = path->dentry;
50733+ struct vfsmount *vfsmnt = path->mnt;
50734+ struct mount *mnt = real_mount(vfsmnt);
50735+ bool slash = false;
50736+ int error = 0;
50737+
50738+ while (dentry != root->dentry || vfsmnt != root->mnt) {
50739+ struct dentry * parent;
50740+
50741+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
50742+ /* Global root? */
50743+ if (!mnt_has_parent(mnt)) {
50744+ goto out;
50745+ }
50746+ dentry = mnt->mnt_mountpoint;
50747+ mnt = mnt->mnt_parent;
50748+ vfsmnt = &mnt->mnt;
50749+ continue;
50750+ }
50751+ parent = dentry->d_parent;
50752+ prefetch(parent);
50753+ spin_lock(&dentry->d_lock);
50754+ error = prepend_name(buffer, buflen, &dentry->d_name);
50755+ spin_unlock(&dentry->d_lock);
50756+ if (!error)
50757+ error = prepend(buffer, buflen, "/", 1);
50758+ if (error)
50759+ break;
50760+
50761+ slash = true;
50762+ dentry = parent;
50763+ }
50764+
50765+out:
50766+ if (!error && !slash)
50767+ error = prepend(buffer, buflen, "/", 1);
50768+
50769+ return error;
50770+}
50771+
50772+/* this must be called with vfsmount_lock and rename_lock held */
50773+
50774+static char *__our_d_path(const struct path *path, struct path *root,
50775+ char *buf, int buflen)
50776+{
50777+ char *res = buf + buflen;
50778+ int error;
50779+
50780+ prepend(&res, &buflen, "\0", 1);
50781+ error = prepend_path(path, root, &res, &buflen);
50782+ if (error)
50783+ return ERR_PTR(error);
50784+
50785+ return res;
50786+}
50787+
50788+static char *
50789+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
50790+{
50791+ char *retval;
50792+
50793+ retval = __our_d_path(path, root, buf, buflen);
50794+ if (unlikely(IS_ERR(retval)))
50795+ retval = strcpy(buf, "<path too long>");
50796+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
50797+ retval[1] = '\0';
50798+
50799+ return retval;
50800+}
50801+
50802+static char *
50803+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50804+ char *buf, int buflen)
50805+{
50806+ struct path path;
50807+ char *res;
50808+
50809+ path.dentry = (struct dentry *)dentry;
50810+ path.mnt = (struct vfsmount *)vfsmnt;
50811+
50812+ /* we can use real_root.dentry, real_root.mnt, because this is only called
50813+ by the RBAC system */
50814+ res = gen_full_path(&path, &real_root, buf, buflen);
50815+
50816+ return res;
50817+}
50818+
50819+static char *
50820+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50821+ char *buf, int buflen)
50822+{
50823+ char *res;
50824+ struct path path;
50825+ struct path root;
50826+ struct task_struct *reaper = &init_task;
50827+
50828+ path.dentry = (struct dentry *)dentry;
50829+ path.mnt = (struct vfsmount *)vfsmnt;
50830+
50831+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
50832+ get_fs_root(reaper->fs, &root);
50833+
50834+ write_seqlock(&rename_lock);
50835+ br_read_lock(vfsmount_lock);
50836+ res = gen_full_path(&path, &root, buf, buflen);
50837+ br_read_unlock(vfsmount_lock);
50838+ write_sequnlock(&rename_lock);
50839+
50840+ path_put(&root);
50841+ return res;
50842+}
50843+
50844+static char *
50845+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50846+{
50847+ char *ret;
50848+ write_seqlock(&rename_lock);
50849+ br_read_lock(vfsmount_lock);
50850+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50851+ PAGE_SIZE);
50852+ br_read_unlock(vfsmount_lock);
50853+ write_sequnlock(&rename_lock);
50854+ return ret;
50855+}
50856+
50857+static char *
50858+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50859+{
50860+ char *ret;
50861+ char *buf;
50862+ int buflen;
50863+
50864+ write_seqlock(&rename_lock);
50865+ br_read_lock(vfsmount_lock);
50866+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
50867+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
50868+ buflen = (int)(ret - buf);
50869+ if (buflen >= 5)
50870+ prepend(&ret, &buflen, "/proc", 5);
50871+ else
50872+ ret = strcpy(buf, "<path too long>");
50873+ br_read_unlock(vfsmount_lock);
50874+ write_sequnlock(&rename_lock);
50875+ return ret;
50876+}
50877+
50878+char *
50879+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
50880+{
50881+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50882+ PAGE_SIZE);
50883+}
50884+
50885+char *
50886+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
50887+{
50888+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
50889+ PAGE_SIZE);
50890+}
50891+
50892+char *
50893+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
50894+{
50895+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
50896+ PAGE_SIZE);
50897+}
50898+
50899+char *
50900+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
50901+{
50902+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
50903+ PAGE_SIZE);
50904+}
50905+
50906+char *
50907+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
50908+{
50909+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
50910+ PAGE_SIZE);
50911+}
50912+
50913+__inline__ __u32
50914+to_gr_audit(const __u32 reqmode)
50915+{
50916+ /* masks off auditable permission flags, then shifts them to create
50917+ auditing flags, and adds the special case of append auditing if
50918+ we're requesting write */
50919+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
50920+}
50921+
50922+struct acl_subject_label *
50923+lookup_subject_map(const struct acl_subject_label *userp)
50924+{
50925+ unsigned int index = shash(userp, subj_map_set.s_size);
50926+ struct subject_map *match;
50927+
50928+ match = subj_map_set.s_hash[index];
50929+
50930+ while (match && match->user != userp)
50931+ match = match->next;
50932+
50933+ if (match != NULL)
50934+ return match->kernel;
50935+ else
50936+ return NULL;
50937+}
50938+
50939+static void
50940+insert_subj_map_entry(struct subject_map *subjmap)
50941+{
50942+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
50943+ struct subject_map **curr;
50944+
50945+ subjmap->prev = NULL;
50946+
50947+ curr = &subj_map_set.s_hash[index];
50948+ if (*curr != NULL)
50949+ (*curr)->prev = subjmap;
50950+
50951+ subjmap->next = *curr;
50952+ *curr = subjmap;
50953+
50954+ return;
50955+}
50956+
50957+static struct acl_role_label *
50958+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
50959+ const gid_t gid)
50960+{
50961+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
50962+ struct acl_role_label *match;
50963+ struct role_allowed_ip *ipp;
50964+ unsigned int x;
50965+ u32 curr_ip = task->signal->curr_ip;
50966+
50967+ task->signal->saved_ip = curr_ip;
50968+
50969+ match = acl_role_set.r_hash[index];
50970+
50971+ while (match) {
50972+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
50973+ for (x = 0; x < match->domain_child_num; x++) {
50974+ if (match->domain_children[x] == uid)
50975+ goto found;
50976+ }
50977+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
50978+ break;
50979+ match = match->next;
50980+ }
50981+found:
50982+ if (match == NULL) {
50983+ try_group:
50984+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
50985+ match = acl_role_set.r_hash[index];
50986+
50987+ while (match) {
50988+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
50989+ for (x = 0; x < match->domain_child_num; x++) {
50990+ if (match->domain_children[x] == gid)
50991+ goto found2;
50992+ }
50993+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
50994+ break;
50995+ match = match->next;
50996+ }
50997+found2:
50998+ if (match == NULL)
50999+ match = default_role;
51000+ if (match->allowed_ips == NULL)
51001+ return match;
51002+ else {
51003+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51004+ if (likely
51005+ ((ntohl(curr_ip) & ipp->netmask) ==
51006+ (ntohl(ipp->addr) & ipp->netmask)))
51007+ return match;
51008+ }
51009+ match = default_role;
51010+ }
51011+ } else if (match->allowed_ips == NULL) {
51012+ return match;
51013+ } else {
51014+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51015+ if (likely
51016+ ((ntohl(curr_ip) & ipp->netmask) ==
51017+ (ntohl(ipp->addr) & ipp->netmask)))
51018+ return match;
51019+ }
51020+ goto try_group;
51021+ }
51022+
51023+ return match;
51024+}
51025+
51026+struct acl_subject_label *
51027+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51028+ const struct acl_role_label *role)
51029+{
51030+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
51031+ struct acl_subject_label *match;
51032+
51033+ match = role->subj_hash[index];
51034+
51035+ while (match && (match->inode != ino || match->device != dev ||
51036+ (match->mode & GR_DELETED))) {
51037+ match = match->next;
51038+ }
51039+
51040+ if (match && !(match->mode & GR_DELETED))
51041+ return match;
51042+ else
51043+ return NULL;
51044+}
51045+
51046+struct acl_subject_label *
51047+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51048+ const struct acl_role_label *role)
51049+{
51050+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
51051+ struct acl_subject_label *match;
51052+
51053+ match = role->subj_hash[index];
51054+
51055+ while (match && (match->inode != ino || match->device != dev ||
51056+ !(match->mode & GR_DELETED))) {
51057+ match = match->next;
51058+ }
51059+
51060+ if (match && (match->mode & GR_DELETED))
51061+ return match;
51062+ else
51063+ return NULL;
51064+}
51065+
51066+static struct acl_object_label *
51067+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51068+ const struct acl_subject_label *subj)
51069+{
51070+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51071+ struct acl_object_label *match;
51072+
51073+ match = subj->obj_hash[index];
51074+
51075+ while (match && (match->inode != ino || match->device != dev ||
51076+ (match->mode & GR_DELETED))) {
51077+ match = match->next;
51078+ }
51079+
51080+ if (match && !(match->mode & GR_DELETED))
51081+ return match;
51082+ else
51083+ return NULL;
51084+}
51085+
51086+static struct acl_object_label *
51087+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51088+ const struct acl_subject_label *subj)
51089+{
51090+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51091+ struct acl_object_label *match;
51092+
51093+ match = subj->obj_hash[index];
51094+
51095+ while (match && (match->inode != ino || match->device != dev ||
51096+ !(match->mode & GR_DELETED))) {
51097+ match = match->next;
51098+ }
51099+
51100+ if (match && (match->mode & GR_DELETED))
51101+ return match;
51102+
51103+ match = subj->obj_hash[index];
51104+
51105+ while (match && (match->inode != ino || match->device != dev ||
51106+ (match->mode & GR_DELETED))) {
51107+ match = match->next;
51108+ }
51109+
51110+ if (match && !(match->mode & GR_DELETED))
51111+ return match;
51112+ else
51113+ return NULL;
51114+}
51115+
51116+static struct name_entry *
51117+lookup_name_entry(const char *name)
51118+{
51119+ unsigned int len = strlen(name);
51120+ unsigned int key = full_name_hash(name, len);
51121+ unsigned int index = key % name_set.n_size;
51122+ struct name_entry *match;
51123+
51124+ match = name_set.n_hash[index];
51125+
51126+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51127+ match = match->next;
51128+
51129+ return match;
51130+}
51131+
51132+static struct name_entry *
51133+lookup_name_entry_create(const char *name)
51134+{
51135+ unsigned int len = strlen(name);
51136+ unsigned int key = full_name_hash(name, len);
51137+ unsigned int index = key % name_set.n_size;
51138+ struct name_entry *match;
51139+
51140+ match = name_set.n_hash[index];
51141+
51142+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51143+ !match->deleted))
51144+ match = match->next;
51145+
51146+ if (match && match->deleted)
51147+ return match;
51148+
51149+ match = name_set.n_hash[index];
51150+
51151+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51152+ match->deleted))
51153+ match = match->next;
51154+
51155+ if (match && !match->deleted)
51156+ return match;
51157+ else
51158+ return NULL;
51159+}
51160+
51161+static struct inodev_entry *
51162+lookup_inodev_entry(const ino_t ino, const dev_t dev)
51163+{
51164+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
51165+ struct inodev_entry *match;
51166+
51167+ match = inodev_set.i_hash[index];
51168+
51169+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51170+ match = match->next;
51171+
51172+ return match;
51173+}
51174+
51175+static void
51176+insert_inodev_entry(struct inodev_entry *entry)
51177+{
51178+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51179+ inodev_set.i_size);
51180+ struct inodev_entry **curr;
51181+
51182+ entry->prev = NULL;
51183+
51184+ curr = &inodev_set.i_hash[index];
51185+ if (*curr != NULL)
51186+ (*curr)->prev = entry;
51187+
51188+ entry->next = *curr;
51189+ *curr = entry;
51190+
51191+ return;
51192+}
51193+
51194+static void
51195+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51196+{
51197+ unsigned int index =
51198+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51199+ struct acl_role_label **curr;
51200+ struct acl_role_label *tmp, *tmp2;
51201+
51202+ curr = &acl_role_set.r_hash[index];
51203+
51204+ /* simple case, slot is empty, just set it to our role */
51205+ if (*curr == NULL) {
51206+ *curr = role;
51207+ } else {
51208+ /* example:
51209+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
51210+ 2 -> 3
51211+ */
51212+ /* first check to see if we can already be reached via this slot */
51213+ tmp = *curr;
51214+ while (tmp && tmp != role)
51215+ tmp = tmp->next;
51216+ if (tmp == role) {
51217+ /* we don't need to add ourselves to this slot's chain */
51218+ return;
51219+ }
51220+ /* we need to add ourselves to this chain, two cases */
51221+ if (role->next == NULL) {
51222+ /* simple case, append the current chain to our role */
51223+ role->next = *curr;
51224+ *curr = role;
51225+ } else {
51226+ /* 1 -> 2 -> 3 -> 4
51227+ 2 -> 3 -> 4
51228+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
51229+ */
51230+ /* trickier case: walk our role's chain until we find
51231+ the role for the start of the current slot's chain */
51232+ tmp = role;
51233+ tmp2 = *curr;
51234+ while (tmp->next && tmp->next != tmp2)
51235+ tmp = tmp->next;
51236+ if (tmp->next == tmp2) {
51237+ /* from example above, we found 3, so just
51238+ replace this slot's chain with ours */
51239+ *curr = role;
51240+ } else {
51241+ /* we didn't find a subset of our role's chain
51242+ in the current slot's chain, so append their
51243+ chain to ours, and set us as the first role in
51244+ the slot's chain
51245+
51246+ we could fold this case with the case above,
51247+ but making it explicit for clarity
51248+ */
51249+ tmp->next = tmp2;
51250+ *curr = role;
51251+ }
51252+ }
51253+ }
51254+
51255+ return;
51256+}
51257+
51258+static void
51259+insert_acl_role_label(struct acl_role_label *role)
51260+{
51261+ int i;
51262+
51263+ if (role_list == NULL) {
51264+ role_list = role;
51265+ role->prev = NULL;
51266+ } else {
51267+ role->prev = role_list;
51268+ role_list = role;
51269+ }
51270+
51271+ /* used for hash chains */
51272+ role->next = NULL;
51273+
51274+ if (role->roletype & GR_ROLE_DOMAIN) {
51275+ for (i = 0; i < role->domain_child_num; i++)
51276+ __insert_acl_role_label(role, role->domain_children[i]);
51277+ } else
51278+ __insert_acl_role_label(role, role->uidgid);
51279+}
51280+
51281+static int
51282+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51283+{
51284+ struct name_entry **curr, *nentry;
51285+ struct inodev_entry *ientry;
51286+ unsigned int len = strlen(name);
51287+ unsigned int key = full_name_hash(name, len);
51288+ unsigned int index = key % name_set.n_size;
51289+
51290+ curr = &name_set.n_hash[index];
51291+
51292+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51293+ curr = &((*curr)->next);
51294+
51295+ if (*curr != NULL)
51296+ return 1;
51297+
51298+ nentry = acl_alloc(sizeof (struct name_entry));
51299+ if (nentry == NULL)
51300+ return 0;
51301+ ientry = acl_alloc(sizeof (struct inodev_entry));
51302+ if (ientry == NULL)
51303+ return 0;
51304+ ientry->nentry = nentry;
51305+
51306+ nentry->key = key;
51307+ nentry->name = name;
51308+ nentry->inode = inode;
51309+ nentry->device = device;
51310+ nentry->len = len;
51311+ nentry->deleted = deleted;
51312+
51313+ nentry->prev = NULL;
51314+ curr = &name_set.n_hash[index];
51315+ if (*curr != NULL)
51316+ (*curr)->prev = nentry;
51317+ nentry->next = *curr;
51318+ *curr = nentry;
51319+
51320+ /* insert us into the table searchable by inode/dev */
51321+ insert_inodev_entry(ientry);
51322+
51323+ return 1;
51324+}
51325+
51326+static void
51327+insert_acl_obj_label(struct acl_object_label *obj,
51328+ struct acl_subject_label *subj)
51329+{
51330+ unsigned int index =
51331+ fhash(obj->inode, obj->device, subj->obj_hash_size);
51332+ struct acl_object_label **curr;
51333+
51334+
51335+ obj->prev = NULL;
51336+
51337+ curr = &subj->obj_hash[index];
51338+ if (*curr != NULL)
51339+ (*curr)->prev = obj;
51340+
51341+ obj->next = *curr;
51342+ *curr = obj;
51343+
51344+ return;
51345+}
51346+
51347+static void
51348+insert_acl_subj_label(struct acl_subject_label *obj,
51349+ struct acl_role_label *role)
51350+{
51351+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51352+ struct acl_subject_label **curr;
51353+
51354+ obj->prev = NULL;
51355+
51356+ curr = &role->subj_hash[index];
51357+ if (*curr != NULL)
51358+ (*curr)->prev = obj;
51359+
51360+ obj->next = *curr;
51361+ *curr = obj;
51362+
51363+ return;
51364+}
51365+
51366+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51367+
51368+static void *
51369+create_table(__u32 * len, int elementsize)
51370+{
51371+ unsigned int table_sizes[] = {
51372+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51373+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51374+ 4194301, 8388593, 16777213, 33554393, 67108859
51375+ };
51376+ void *newtable = NULL;
51377+ unsigned int pwr = 0;
51378+
51379+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51380+ table_sizes[pwr] <= *len)
51381+ pwr++;
51382+
51383+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
51384+ return newtable;
51385+
51386+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
51387+ newtable =
51388+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
51389+ else
51390+ newtable = vmalloc(table_sizes[pwr] * elementsize);
51391+
51392+ *len = table_sizes[pwr];
51393+
51394+ return newtable;
51395+}
51396+
51397+static int
51398+init_variables(const struct gr_arg *arg)
51399+{
51400+ struct task_struct *reaper = &init_task;
51401+ unsigned int stacksize;
51402+
51403+ subj_map_set.s_size = arg->role_db.num_subjects;
51404+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
51405+ name_set.n_size = arg->role_db.num_objects;
51406+ inodev_set.i_size = arg->role_db.num_objects;
51407+
51408+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
51409+ !name_set.n_size || !inodev_set.i_size)
51410+ return 1;
51411+
51412+ if (!gr_init_uidset())
51413+ return 1;
51414+
51415+ /* set up the stack that holds allocation info */
51416+
51417+ stacksize = arg->role_db.num_pointers + 5;
51418+
51419+ if (!acl_alloc_stack_init(stacksize))
51420+ return 1;
51421+
51422+ /* grab reference for the real root dentry and vfsmount */
51423+ get_fs_root(reaper->fs, &real_root);
51424+
51425+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51426+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51427+#endif
51428+
51429+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51430+ if (fakefs_obj_rw == NULL)
51431+ return 1;
51432+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51433+
51434+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51435+ if (fakefs_obj_rwx == NULL)
51436+ return 1;
51437+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51438+
51439+ subj_map_set.s_hash =
51440+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51441+ acl_role_set.r_hash =
51442+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51443+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51444+ inodev_set.i_hash =
51445+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51446+
51447+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51448+ !name_set.n_hash || !inodev_set.i_hash)
51449+ return 1;
51450+
51451+ memset(subj_map_set.s_hash, 0,
51452+ sizeof(struct subject_map *) * subj_map_set.s_size);
51453+ memset(acl_role_set.r_hash, 0,
51454+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
51455+ memset(name_set.n_hash, 0,
51456+ sizeof (struct name_entry *) * name_set.n_size);
51457+ memset(inodev_set.i_hash, 0,
51458+ sizeof (struct inodev_entry *) * inodev_set.i_size);
51459+
51460+ return 0;
51461+}
51462+
51463+/* free information not needed after startup
51464+ currently contains user->kernel pointer mappings for subjects
51465+*/
51466+
51467+static void
51468+free_init_variables(void)
51469+{
51470+ __u32 i;
51471+
51472+ if (subj_map_set.s_hash) {
51473+ for (i = 0; i < subj_map_set.s_size; i++) {
51474+ if (subj_map_set.s_hash[i]) {
51475+ kfree(subj_map_set.s_hash[i]);
51476+ subj_map_set.s_hash[i] = NULL;
51477+ }
51478+ }
51479+
51480+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
51481+ PAGE_SIZE)
51482+ kfree(subj_map_set.s_hash);
51483+ else
51484+ vfree(subj_map_set.s_hash);
51485+ }
51486+
51487+ return;
51488+}
51489+
51490+static void
51491+free_variables(void)
51492+{
51493+ struct acl_subject_label *s;
51494+ struct acl_role_label *r;
51495+ struct task_struct *task, *task2;
51496+ unsigned int x;
51497+
51498+ gr_clear_learn_entries();
51499+
51500+ read_lock(&tasklist_lock);
51501+ do_each_thread(task2, task) {
51502+ task->acl_sp_role = 0;
51503+ task->acl_role_id = 0;
51504+ task->acl = NULL;
51505+ task->role = NULL;
51506+ } while_each_thread(task2, task);
51507+ read_unlock(&tasklist_lock);
51508+
51509+ /* release the reference to the real root dentry and vfsmount */
51510+ path_put(&real_root);
51511+ memset(&real_root, 0, sizeof(real_root));
51512+
51513+ /* free all object hash tables */
51514+
51515+ FOR_EACH_ROLE_START(r)
51516+ if (r->subj_hash == NULL)
51517+ goto next_role;
51518+ FOR_EACH_SUBJECT_START(r, s, x)
51519+ if (s->obj_hash == NULL)
51520+ break;
51521+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51522+ kfree(s->obj_hash);
51523+ else
51524+ vfree(s->obj_hash);
51525+ FOR_EACH_SUBJECT_END(s, x)
51526+ FOR_EACH_NESTED_SUBJECT_START(r, s)
51527+ if (s->obj_hash == NULL)
51528+ break;
51529+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51530+ kfree(s->obj_hash);
51531+ else
51532+ vfree(s->obj_hash);
51533+ FOR_EACH_NESTED_SUBJECT_END(s)
51534+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
51535+ kfree(r->subj_hash);
51536+ else
51537+ vfree(r->subj_hash);
51538+ r->subj_hash = NULL;
51539+next_role:
51540+ FOR_EACH_ROLE_END(r)
51541+
51542+ acl_free_all();
51543+
51544+ if (acl_role_set.r_hash) {
51545+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
51546+ PAGE_SIZE)
51547+ kfree(acl_role_set.r_hash);
51548+ else
51549+ vfree(acl_role_set.r_hash);
51550+ }
51551+ if (name_set.n_hash) {
51552+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
51553+ PAGE_SIZE)
51554+ kfree(name_set.n_hash);
51555+ else
51556+ vfree(name_set.n_hash);
51557+ }
51558+
51559+ if (inodev_set.i_hash) {
51560+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
51561+ PAGE_SIZE)
51562+ kfree(inodev_set.i_hash);
51563+ else
51564+ vfree(inodev_set.i_hash);
51565+ }
51566+
51567+ gr_free_uidset();
51568+
51569+ memset(&name_set, 0, sizeof (struct name_db));
51570+ memset(&inodev_set, 0, sizeof (struct inodev_db));
51571+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
51572+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
51573+
51574+ default_role = NULL;
51575+ kernel_role = NULL;
51576+ role_list = NULL;
51577+
51578+ return;
51579+}
51580+
51581+static __u32
51582+count_user_objs(struct acl_object_label *userp)
51583+{
51584+ struct acl_object_label o_tmp;
51585+ __u32 num = 0;
51586+
51587+ while (userp) {
51588+ if (copy_from_user(&o_tmp, userp,
51589+ sizeof (struct acl_object_label)))
51590+ break;
51591+
51592+ userp = o_tmp.prev;
51593+ num++;
51594+ }
51595+
51596+ return num;
51597+}
51598+
51599+static struct acl_subject_label *
51600+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
51601+
51602+static int
51603+copy_user_glob(struct acl_object_label *obj)
51604+{
51605+ struct acl_object_label *g_tmp, **guser;
51606+ unsigned int len;
51607+ char *tmp;
51608+
51609+ if (obj->globbed == NULL)
51610+ return 0;
51611+
51612+ guser = &obj->globbed;
51613+ while (*guser) {
51614+ g_tmp = (struct acl_object_label *)
51615+ acl_alloc(sizeof (struct acl_object_label));
51616+ if (g_tmp == NULL)
51617+ return -ENOMEM;
51618+
51619+ if (copy_from_user(g_tmp, *guser,
51620+ sizeof (struct acl_object_label)))
51621+ return -EFAULT;
51622+
51623+ len = strnlen_user(g_tmp->filename, PATH_MAX);
51624+
51625+ if (!len || len >= PATH_MAX)
51626+ return -EINVAL;
51627+
51628+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51629+ return -ENOMEM;
51630+
51631+ if (copy_from_user(tmp, g_tmp->filename, len))
51632+ return -EFAULT;
51633+ tmp[len-1] = '\0';
51634+ g_tmp->filename = tmp;
51635+
51636+ *guser = g_tmp;
51637+ guser = &(g_tmp->next);
51638+ }
51639+
51640+ return 0;
51641+}
51642+
51643+static int
51644+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
51645+ struct acl_role_label *role)
51646+{
51647+ struct acl_object_label *o_tmp;
51648+ unsigned int len;
51649+ int ret;
51650+ char *tmp;
51651+
51652+ while (userp) {
51653+ if ((o_tmp = (struct acl_object_label *)
51654+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
51655+ return -ENOMEM;
51656+
51657+ if (copy_from_user(o_tmp, userp,
51658+ sizeof (struct acl_object_label)))
51659+ return -EFAULT;
51660+
51661+ userp = o_tmp->prev;
51662+
51663+ len = strnlen_user(o_tmp->filename, PATH_MAX);
51664+
51665+ if (!len || len >= PATH_MAX)
51666+ return -EINVAL;
51667+
51668+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51669+ return -ENOMEM;
51670+
51671+ if (copy_from_user(tmp, o_tmp->filename, len))
51672+ return -EFAULT;
51673+ tmp[len-1] = '\0';
51674+ o_tmp->filename = tmp;
51675+
51676+ insert_acl_obj_label(o_tmp, subj);
51677+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
51678+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
51679+ return -ENOMEM;
51680+
51681+ ret = copy_user_glob(o_tmp);
51682+ if (ret)
51683+ return ret;
51684+
51685+ if (o_tmp->nested) {
51686+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
51687+ if (IS_ERR(o_tmp->nested))
51688+ return PTR_ERR(o_tmp->nested);
51689+
51690+ /* insert into nested subject list */
51691+ o_tmp->nested->next = role->hash->first;
51692+ role->hash->first = o_tmp->nested;
51693+ }
51694+ }
51695+
51696+ return 0;
51697+}
51698+
51699+static __u32
51700+count_user_subjs(struct acl_subject_label *userp)
51701+{
51702+ struct acl_subject_label s_tmp;
51703+ __u32 num = 0;
51704+
51705+ while (userp) {
51706+ if (copy_from_user(&s_tmp, userp,
51707+ sizeof (struct acl_subject_label)))
51708+ break;
51709+
51710+ userp = s_tmp.prev;
51711+ /* do not count nested subjects against this count, since
51712+ they are not included in the hash table, but are
51713+ attached to objects. We have already counted
51714+ the subjects in userspace for the allocation
51715+ stack
51716+ */
51717+ if (!(s_tmp.mode & GR_NESTED))
51718+ num++;
51719+ }
51720+
51721+ return num;
51722+}
51723+
51724+static int
51725+copy_user_allowedips(struct acl_role_label *rolep)
51726+{
51727+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
51728+
51729+ ruserip = rolep->allowed_ips;
51730+
51731+ while (ruserip) {
51732+ rlast = rtmp;
51733+
51734+ if ((rtmp = (struct role_allowed_ip *)
51735+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
51736+ return -ENOMEM;
51737+
51738+ if (copy_from_user(rtmp, ruserip,
51739+ sizeof (struct role_allowed_ip)))
51740+ return -EFAULT;
51741+
51742+ ruserip = rtmp->prev;
51743+
51744+ if (!rlast) {
51745+ rtmp->prev = NULL;
51746+ rolep->allowed_ips = rtmp;
51747+ } else {
51748+ rlast->next = rtmp;
51749+ rtmp->prev = rlast;
51750+ }
51751+
51752+ if (!ruserip)
51753+ rtmp->next = NULL;
51754+ }
51755+
51756+ return 0;
51757+}
51758+
51759+static int
51760+copy_user_transitions(struct acl_role_label *rolep)
51761+{
51762+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
51763+
51764+ unsigned int len;
51765+ char *tmp;
51766+
51767+ rusertp = rolep->transitions;
51768+
51769+ while (rusertp) {
51770+ rlast = rtmp;
51771+
51772+ if ((rtmp = (struct role_transition *)
51773+ acl_alloc(sizeof (struct role_transition))) == NULL)
51774+ return -ENOMEM;
51775+
51776+ if (copy_from_user(rtmp, rusertp,
51777+ sizeof (struct role_transition)))
51778+ return -EFAULT;
51779+
51780+ rusertp = rtmp->prev;
51781+
51782+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
51783+
51784+ if (!len || len >= GR_SPROLE_LEN)
51785+ return -EINVAL;
51786+
51787+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51788+ return -ENOMEM;
51789+
51790+ if (copy_from_user(tmp, rtmp->rolename, len))
51791+ return -EFAULT;
51792+ tmp[len-1] = '\0';
51793+ rtmp->rolename = tmp;
51794+
51795+ if (!rlast) {
51796+ rtmp->prev = NULL;
51797+ rolep->transitions = rtmp;
51798+ } else {
51799+ rlast->next = rtmp;
51800+ rtmp->prev = rlast;
51801+ }
51802+
51803+ if (!rusertp)
51804+ rtmp->next = NULL;
51805+ }
51806+
51807+ return 0;
51808+}
51809+
51810+static struct acl_subject_label *
51811+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
51812+{
51813+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
51814+ unsigned int len;
51815+ char *tmp;
51816+ __u32 num_objs;
51817+ struct acl_ip_label **i_tmp, *i_utmp2;
51818+ struct gr_hash_struct ghash;
51819+ struct subject_map *subjmap;
51820+ unsigned int i_num;
51821+ int err;
51822+
51823+ s_tmp = lookup_subject_map(userp);
51824+
51825+ /* we've already copied this subject into the kernel, just return
51826+ the reference to it, and don't copy it over again
51827+ */
51828+ if (s_tmp)
51829+ return(s_tmp);
51830+
51831+ if ((s_tmp = (struct acl_subject_label *)
51832+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
51833+ return ERR_PTR(-ENOMEM);
51834+
51835+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
51836+ if (subjmap == NULL)
51837+ return ERR_PTR(-ENOMEM);
51838+
51839+ subjmap->user = userp;
51840+ subjmap->kernel = s_tmp;
51841+ insert_subj_map_entry(subjmap);
51842+
51843+ if (copy_from_user(s_tmp, userp,
51844+ sizeof (struct acl_subject_label)))
51845+ return ERR_PTR(-EFAULT);
51846+
51847+ len = strnlen_user(s_tmp->filename, PATH_MAX);
51848+
51849+ if (!len || len >= PATH_MAX)
51850+ return ERR_PTR(-EINVAL);
51851+
51852+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51853+ return ERR_PTR(-ENOMEM);
51854+
51855+ if (copy_from_user(tmp, s_tmp->filename, len))
51856+ return ERR_PTR(-EFAULT);
51857+ tmp[len-1] = '\0';
51858+ s_tmp->filename = tmp;
51859+
51860+ if (!strcmp(s_tmp->filename, "/"))
51861+ role->root_label = s_tmp;
51862+
51863+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
51864+ return ERR_PTR(-EFAULT);
51865+
51866+ /* copy user and group transition tables */
51867+
51868+ if (s_tmp->user_trans_num) {
51869+ uid_t *uidlist;
51870+
51871+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
51872+ if (uidlist == NULL)
51873+ return ERR_PTR(-ENOMEM);
51874+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
51875+ return ERR_PTR(-EFAULT);
51876+
51877+ s_tmp->user_transitions = uidlist;
51878+ }
51879+
51880+ if (s_tmp->group_trans_num) {
51881+ gid_t *gidlist;
51882+
51883+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
51884+ if (gidlist == NULL)
51885+ return ERR_PTR(-ENOMEM);
51886+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
51887+ return ERR_PTR(-EFAULT);
51888+
51889+ s_tmp->group_transitions = gidlist;
51890+ }
51891+
51892+ /* set up object hash table */
51893+ num_objs = count_user_objs(ghash.first);
51894+
51895+ s_tmp->obj_hash_size = num_objs;
51896+ s_tmp->obj_hash =
51897+ (struct acl_object_label **)
51898+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
51899+
51900+ if (!s_tmp->obj_hash)
51901+ return ERR_PTR(-ENOMEM);
51902+
51903+ memset(s_tmp->obj_hash, 0,
51904+ s_tmp->obj_hash_size *
51905+ sizeof (struct acl_object_label *));
51906+
51907+ /* add in objects */
51908+ err = copy_user_objs(ghash.first, s_tmp, role);
51909+
51910+ if (err)
51911+ return ERR_PTR(err);
51912+
51913+ /* set pointer for parent subject */
51914+ if (s_tmp->parent_subject) {
51915+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
51916+
51917+ if (IS_ERR(s_tmp2))
51918+ return s_tmp2;
51919+
51920+ s_tmp->parent_subject = s_tmp2;
51921+ }
51922+
51923+ /* add in ip acls */
51924+
51925+ if (!s_tmp->ip_num) {
51926+ s_tmp->ips = NULL;
51927+ goto insert;
51928+ }
51929+
51930+ i_tmp =
51931+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
51932+ sizeof (struct acl_ip_label *));
51933+
51934+ if (!i_tmp)
51935+ return ERR_PTR(-ENOMEM);
51936+
51937+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
51938+ *(i_tmp + i_num) =
51939+ (struct acl_ip_label *)
51940+ acl_alloc(sizeof (struct acl_ip_label));
51941+ if (!*(i_tmp + i_num))
51942+ return ERR_PTR(-ENOMEM);
51943+
51944+ if (copy_from_user
51945+ (&i_utmp2, s_tmp->ips + i_num,
51946+ sizeof (struct acl_ip_label *)))
51947+ return ERR_PTR(-EFAULT);
51948+
51949+ if (copy_from_user
51950+ (*(i_tmp + i_num), i_utmp2,
51951+ sizeof (struct acl_ip_label)))
51952+ return ERR_PTR(-EFAULT);
51953+
51954+ if ((*(i_tmp + i_num))->iface == NULL)
51955+ continue;
51956+
51957+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
51958+ if (!len || len >= IFNAMSIZ)
51959+ return ERR_PTR(-EINVAL);
51960+ tmp = acl_alloc(len);
51961+ if (tmp == NULL)
51962+ return ERR_PTR(-ENOMEM);
51963+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
51964+ return ERR_PTR(-EFAULT);
51965+ (*(i_tmp + i_num))->iface = tmp;
51966+ }
51967+
51968+ s_tmp->ips = i_tmp;
51969+
51970+insert:
51971+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
51972+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
51973+ return ERR_PTR(-ENOMEM);
51974+
51975+ return s_tmp;
51976+}
51977+
51978+static int
51979+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
51980+{
51981+ struct acl_subject_label s_pre;
51982+ struct acl_subject_label * ret;
51983+ int err;
51984+
51985+ while (userp) {
51986+ if (copy_from_user(&s_pre, userp,
51987+ sizeof (struct acl_subject_label)))
51988+ return -EFAULT;
51989+
51990+ /* do not add nested subjects here, add
51991+ while parsing objects
51992+ */
51993+
51994+ if (s_pre.mode & GR_NESTED) {
51995+ userp = s_pre.prev;
51996+ continue;
51997+ }
51998+
51999+ ret = do_copy_user_subj(userp, role);
52000+
52001+ err = PTR_ERR(ret);
52002+ if (IS_ERR(ret))
52003+ return err;
52004+
52005+ insert_acl_subj_label(ret, role);
52006+
52007+ userp = s_pre.prev;
52008+ }
52009+
52010+ return 0;
52011+}
52012+
52013+static int
52014+copy_user_acl(struct gr_arg *arg)
52015+{
52016+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52017+ struct sprole_pw *sptmp;
52018+ struct gr_hash_struct *ghash;
52019+ uid_t *domainlist;
52020+ unsigned int r_num;
52021+ unsigned int len;
52022+ char *tmp;
52023+ int err = 0;
52024+ __u16 i;
52025+ __u32 num_subjs;
52026+
52027+ /* we need a default and kernel role */
52028+ if (arg->role_db.num_roles < 2)
52029+ return -EINVAL;
52030+
52031+ /* copy special role authentication info from userspace */
52032+
52033+ num_sprole_pws = arg->num_sprole_pws;
52034+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52035+
52036+ if (!acl_special_roles && num_sprole_pws)
52037+ return -ENOMEM;
52038+
52039+ for (i = 0; i < num_sprole_pws; i++) {
52040+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52041+ if (!sptmp)
52042+ return -ENOMEM;
52043+ if (copy_from_user(sptmp, arg->sprole_pws + i,
52044+ sizeof (struct sprole_pw)))
52045+ return -EFAULT;
52046+
52047+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52048+
52049+ if (!len || len >= GR_SPROLE_LEN)
52050+ return -EINVAL;
52051+
52052+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52053+ return -ENOMEM;
52054+
52055+ if (copy_from_user(tmp, sptmp->rolename, len))
52056+ return -EFAULT;
52057+
52058+ tmp[len-1] = '\0';
52059+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52060+ printk(KERN_ALERT "Copying special role %s\n", tmp);
52061+#endif
52062+ sptmp->rolename = tmp;
52063+ acl_special_roles[i] = sptmp;
52064+ }
52065+
52066+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52067+
52068+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52069+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
52070+
52071+ if (!r_tmp)
52072+ return -ENOMEM;
52073+
52074+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
52075+ sizeof (struct acl_role_label *)))
52076+ return -EFAULT;
52077+
52078+ if (copy_from_user(r_tmp, r_utmp2,
52079+ sizeof (struct acl_role_label)))
52080+ return -EFAULT;
52081+
52082+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52083+
52084+ if (!len || len >= PATH_MAX)
52085+ return -EINVAL;
52086+
52087+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52088+ return -ENOMEM;
52089+
52090+ if (copy_from_user(tmp, r_tmp->rolename, len))
52091+ return -EFAULT;
52092+
52093+ tmp[len-1] = '\0';
52094+ r_tmp->rolename = tmp;
52095+
52096+ if (!strcmp(r_tmp->rolename, "default")
52097+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52098+ default_role = r_tmp;
52099+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52100+ kernel_role = r_tmp;
52101+ }
52102+
52103+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
52104+ return -ENOMEM;
52105+
52106+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
52107+ return -EFAULT;
52108+
52109+ r_tmp->hash = ghash;
52110+
52111+ num_subjs = count_user_subjs(r_tmp->hash->first);
52112+
52113+ r_tmp->subj_hash_size = num_subjs;
52114+ r_tmp->subj_hash =
52115+ (struct acl_subject_label **)
52116+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52117+
52118+ if (!r_tmp->subj_hash)
52119+ return -ENOMEM;
52120+
52121+ err = copy_user_allowedips(r_tmp);
52122+ if (err)
52123+ return err;
52124+
52125+ /* copy domain info */
52126+ if (r_tmp->domain_children != NULL) {
52127+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52128+ if (domainlist == NULL)
52129+ return -ENOMEM;
52130+
52131+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
52132+ return -EFAULT;
52133+
52134+ r_tmp->domain_children = domainlist;
52135+ }
52136+
52137+ err = copy_user_transitions(r_tmp);
52138+ if (err)
52139+ return err;
52140+
52141+ memset(r_tmp->subj_hash, 0,
52142+ r_tmp->subj_hash_size *
52143+ sizeof (struct acl_subject_label *));
52144+
52145+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52146+
52147+ if (err)
52148+ return err;
52149+
52150+ /* set nested subject list to null */
52151+ r_tmp->hash->first = NULL;
52152+
52153+ insert_acl_role_label(r_tmp);
52154+ }
52155+
52156+ if (default_role == NULL || kernel_role == NULL)
52157+ return -EINVAL;
52158+
52159+ return err;
52160+}
52161+
52162+static int
52163+gracl_init(struct gr_arg *args)
52164+{
52165+ int error = 0;
52166+
52167+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52168+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52169+
52170+ if (init_variables(args)) {
52171+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52172+ error = -ENOMEM;
52173+ free_variables();
52174+ goto out;
52175+ }
52176+
52177+ error = copy_user_acl(args);
52178+ free_init_variables();
52179+ if (error) {
52180+ free_variables();
52181+ goto out;
52182+ }
52183+
52184+ if ((error = gr_set_acls(0))) {
52185+ free_variables();
52186+ goto out;
52187+ }
52188+
52189+ pax_open_kernel();
52190+ gr_status |= GR_READY;
52191+ pax_close_kernel();
52192+
52193+ out:
52194+ return error;
52195+}
52196+
52197+/* derived from glibc fnmatch() 0: match, 1: no match*/
52198+
52199+static int
52200+glob_match(const char *p, const char *n)
52201+{
52202+ char c;
52203+
52204+ while ((c = *p++) != '\0') {
52205+ switch (c) {
52206+ case '?':
52207+ if (*n == '\0')
52208+ return 1;
52209+ else if (*n == '/')
52210+ return 1;
52211+ break;
52212+ case '\\':
52213+ if (*n != c)
52214+ return 1;
52215+ break;
52216+ case '*':
52217+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
52218+ if (*n == '/')
52219+ return 1;
52220+ else if (c == '?') {
52221+ if (*n == '\0')
52222+ return 1;
52223+ else
52224+ ++n;
52225+ }
52226+ }
52227+ if (c == '\0') {
52228+ return 0;
52229+ } else {
52230+ const char *endp;
52231+
52232+ if ((endp = strchr(n, '/')) == NULL)
52233+ endp = n + strlen(n);
52234+
52235+ if (c == '[') {
52236+ for (--p; n < endp; ++n)
52237+ if (!glob_match(p, n))
52238+ return 0;
52239+ } else if (c == '/') {
52240+ while (*n != '\0' && *n != '/')
52241+ ++n;
52242+ if (*n == '/' && !glob_match(p, n + 1))
52243+ return 0;
52244+ } else {
52245+ for (--p; n < endp; ++n)
52246+ if (*n == c && !glob_match(p, n))
52247+ return 0;
52248+ }
52249+
52250+ return 1;
52251+ }
52252+ case '[':
52253+ {
52254+ int not;
52255+ char cold;
52256+
52257+ if (*n == '\0' || *n == '/')
52258+ return 1;
52259+
52260+ not = (*p == '!' || *p == '^');
52261+ if (not)
52262+ ++p;
52263+
52264+ c = *p++;
52265+ for (;;) {
52266+ unsigned char fn = (unsigned char)*n;
52267+
52268+ if (c == '\0')
52269+ return 1;
52270+ else {
52271+ if (c == fn)
52272+ goto matched;
52273+ cold = c;
52274+ c = *p++;
52275+
52276+ if (c == '-' && *p != ']') {
52277+ unsigned char cend = *p++;
52278+
52279+ if (cend == '\0')
52280+ return 1;
52281+
52282+ if (cold <= fn && fn <= cend)
52283+ goto matched;
52284+
52285+ c = *p++;
52286+ }
52287+ }
52288+
52289+ if (c == ']')
52290+ break;
52291+ }
52292+ if (!not)
52293+ return 1;
52294+ break;
52295+ matched:
52296+ while (c != ']') {
52297+ if (c == '\0')
52298+ return 1;
52299+
52300+ c = *p++;
52301+ }
52302+ if (not)
52303+ return 1;
52304+ }
52305+ break;
52306+ default:
52307+ if (c != *n)
52308+ return 1;
52309+ }
52310+
52311+ ++n;
52312+ }
52313+
52314+ if (*n == '\0')
52315+ return 0;
52316+
52317+ if (*n == '/')
52318+ return 0;
52319+
52320+ return 1;
52321+}
52322+
52323+static struct acl_object_label *
52324+chk_glob_label(struct acl_object_label *globbed,
52325+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
52326+{
52327+ struct acl_object_label *tmp;
52328+
52329+ if (*path == NULL)
52330+ *path = gr_to_filename_nolock(dentry, mnt);
52331+
52332+ tmp = globbed;
52333+
52334+ while (tmp) {
52335+ if (!glob_match(tmp->filename, *path))
52336+ return tmp;
52337+ tmp = tmp->next;
52338+ }
52339+
52340+ return NULL;
52341+}
52342+
52343+static struct acl_object_label *
52344+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52345+ const ino_t curr_ino, const dev_t curr_dev,
52346+ const struct acl_subject_label *subj, char **path, const int checkglob)
52347+{
52348+ struct acl_subject_label *tmpsubj;
52349+ struct acl_object_label *retval;
52350+ struct acl_object_label *retval2;
52351+
52352+ tmpsubj = (struct acl_subject_label *) subj;
52353+ read_lock(&gr_inode_lock);
52354+ do {
52355+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
52356+ if (retval) {
52357+ if (checkglob && retval->globbed) {
52358+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
52359+ if (retval2)
52360+ retval = retval2;
52361+ }
52362+ break;
52363+ }
52364+ } while ((tmpsubj = tmpsubj->parent_subject));
52365+ read_unlock(&gr_inode_lock);
52366+
52367+ return retval;
52368+}
52369+
52370+static __inline__ struct acl_object_label *
52371+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52372+ struct dentry *curr_dentry,
52373+ const struct acl_subject_label *subj, char **path, const int checkglob)
52374+{
52375+ int newglob = checkglob;
52376+ ino_t inode;
52377+ dev_t device;
52378+
52379+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
52380+ as we don't want a / * rule to match instead of the / object
52381+ don't do this for create lookups that call this function though, since they're looking up
52382+ on the parent and thus need globbing checks on all paths
52383+ */
52384+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
52385+ newglob = GR_NO_GLOB;
52386+
52387+ spin_lock(&curr_dentry->d_lock);
52388+ inode = curr_dentry->d_inode->i_ino;
52389+ device = __get_dev(curr_dentry);
52390+ spin_unlock(&curr_dentry->d_lock);
52391+
52392+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
52393+}
52394+
52395+static struct acl_object_label *
52396+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52397+ const struct acl_subject_label *subj, char *path, const int checkglob)
52398+{
52399+ struct dentry *dentry = (struct dentry *) l_dentry;
52400+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52401+ struct mount *real_mnt = real_mount(mnt);
52402+ struct acl_object_label *retval;
52403+ struct dentry *parent;
52404+
52405+ write_seqlock(&rename_lock);
52406+ br_read_lock(vfsmount_lock);
52407+
52408+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
52409+#ifdef CONFIG_NET
52410+ mnt == sock_mnt ||
52411+#endif
52412+#ifdef CONFIG_HUGETLBFS
52413+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52414+#endif
52415+ /* ignore Eric Biederman */
52416+ IS_PRIVATE(l_dentry->d_inode))) {
52417+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52418+ goto out;
52419+ }
52420+
52421+ for (;;) {
52422+ if (dentry == real_root.dentry && mnt == real_root.mnt)
52423+ break;
52424+
52425+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52426+ if (!mnt_has_parent(real_mnt))
52427+ break;
52428+
52429+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52430+ if (retval != NULL)
52431+ goto out;
52432+
52433+ dentry = real_mnt->mnt_mountpoint;
52434+ real_mnt = real_mnt->mnt_parent;
52435+ mnt = &real_mnt->mnt;
52436+ continue;
52437+ }
52438+
52439+ parent = dentry->d_parent;
52440+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52441+ if (retval != NULL)
52442+ goto out;
52443+
52444+ dentry = parent;
52445+ }
52446+
52447+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52448+
52449+ /* real_root is pinned so we don't have to hold a reference */
52450+ if (retval == NULL)
52451+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52452+out:
52453+ br_read_unlock(vfsmount_lock);
52454+ write_sequnlock(&rename_lock);
52455+
52456+ BUG_ON(retval == NULL);
52457+
52458+ return retval;
52459+}
52460+
52461+static __inline__ struct acl_object_label *
52462+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52463+ const struct acl_subject_label *subj)
52464+{
52465+ char *path = NULL;
52466+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
52467+}
52468+
52469+static __inline__ struct acl_object_label *
52470+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52471+ const struct acl_subject_label *subj)
52472+{
52473+ char *path = NULL;
52474+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
52475+}
52476+
52477+static __inline__ struct acl_object_label *
52478+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52479+ const struct acl_subject_label *subj, char *path)
52480+{
52481+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
52482+}
52483+
52484+static struct acl_subject_label *
52485+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52486+ const struct acl_role_label *role)
52487+{
52488+ struct dentry *dentry = (struct dentry *) l_dentry;
52489+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52490+ struct mount *real_mnt = real_mount(mnt);
52491+ struct acl_subject_label *retval;
52492+ struct dentry *parent;
52493+
52494+ write_seqlock(&rename_lock);
52495+ br_read_lock(vfsmount_lock);
52496+
52497+ for (;;) {
52498+ if (dentry == real_root.dentry && mnt == real_root.mnt)
52499+ break;
52500+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52501+ if (!mnt_has_parent(real_mnt))
52502+ break;
52503+
52504+ spin_lock(&dentry->d_lock);
52505+ read_lock(&gr_inode_lock);
52506+ retval =
52507+ lookup_acl_subj_label(dentry->d_inode->i_ino,
52508+ __get_dev(dentry), role);
52509+ read_unlock(&gr_inode_lock);
52510+ spin_unlock(&dentry->d_lock);
52511+ if (retval != NULL)
52512+ goto out;
52513+
52514+ dentry = real_mnt->mnt_mountpoint;
52515+ real_mnt = real_mnt->mnt_parent;
52516+ mnt = &real_mnt->mnt;
52517+ continue;
52518+ }
52519+
52520+ spin_lock(&dentry->d_lock);
52521+ read_lock(&gr_inode_lock);
52522+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52523+ __get_dev(dentry), role);
52524+ read_unlock(&gr_inode_lock);
52525+ parent = dentry->d_parent;
52526+ spin_unlock(&dentry->d_lock);
52527+
52528+ if (retval != NULL)
52529+ goto out;
52530+
52531+ dentry = parent;
52532+ }
52533+
52534+ spin_lock(&dentry->d_lock);
52535+ read_lock(&gr_inode_lock);
52536+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52537+ __get_dev(dentry), role);
52538+ read_unlock(&gr_inode_lock);
52539+ spin_unlock(&dentry->d_lock);
52540+
52541+ if (unlikely(retval == NULL)) {
52542+ /* real_root is pinned, we don't need to hold a reference */
52543+ read_lock(&gr_inode_lock);
52544+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
52545+ __get_dev(real_root.dentry), role);
52546+ read_unlock(&gr_inode_lock);
52547+ }
52548+out:
52549+ br_read_unlock(vfsmount_lock);
52550+ write_sequnlock(&rename_lock);
52551+
52552+ BUG_ON(retval == NULL);
52553+
52554+ return retval;
52555+}
52556+
52557+static void
52558+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
52559+{
52560+ struct task_struct *task = current;
52561+ const struct cred *cred = current_cred();
52562+
52563+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52564+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52565+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52566+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
52567+
52568+ return;
52569+}
52570+
52571+static void
52572+gr_log_learn_sysctl(const char *path, const __u32 mode)
52573+{
52574+ struct task_struct *task = current;
52575+ const struct cred *cred = current_cred();
52576+
52577+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52578+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52579+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52580+ 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
52581+
52582+ return;
52583+}
52584+
52585+static void
52586+gr_log_learn_id_change(const char type, const unsigned int real,
52587+ const unsigned int effective, const unsigned int fs)
52588+{
52589+ struct task_struct *task = current;
52590+ const struct cred *cred = current_cred();
52591+
52592+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
52593+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52594+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52595+ type, real, effective, fs, &task->signal->saved_ip);
52596+
52597+ return;
52598+}
52599+
52600+__u32
52601+gr_search_file(const struct dentry * dentry, const __u32 mode,
52602+ const struct vfsmount * mnt)
52603+{
52604+ __u32 retval = mode;
52605+ struct acl_subject_label *curracl;
52606+ struct acl_object_label *currobj;
52607+
52608+ if (unlikely(!(gr_status & GR_READY)))
52609+ return (mode & ~GR_AUDITS);
52610+
52611+ curracl = current->acl;
52612+
52613+ currobj = chk_obj_label(dentry, mnt, curracl);
52614+ retval = currobj->mode & mode;
52615+
52616+ /* if we're opening a specified transfer file for writing
52617+ (e.g. /dev/initctl), then transfer our role to init
52618+ */
52619+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
52620+ current->role->roletype & GR_ROLE_PERSIST)) {
52621+ struct task_struct *task = init_pid_ns.child_reaper;
52622+
52623+ if (task->role != current->role) {
52624+ task->acl_sp_role = 0;
52625+ task->acl_role_id = current->acl_role_id;
52626+ task->role = current->role;
52627+ rcu_read_lock();
52628+ read_lock(&grsec_exec_file_lock);
52629+ gr_apply_subject_to_task(task);
52630+ read_unlock(&grsec_exec_file_lock);
52631+ rcu_read_unlock();
52632+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
52633+ }
52634+ }
52635+
52636+ if (unlikely
52637+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
52638+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
52639+ __u32 new_mode = mode;
52640+
52641+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52642+
52643+ retval = new_mode;
52644+
52645+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
52646+ new_mode |= GR_INHERIT;
52647+
52648+ if (!(mode & GR_NOLEARN))
52649+ gr_log_learn(dentry, mnt, new_mode);
52650+ }
52651+
52652+ return retval;
52653+}
52654+
52655+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
52656+ const struct dentry *parent,
52657+ const struct vfsmount *mnt)
52658+{
52659+ struct name_entry *match;
52660+ struct acl_object_label *matchpo;
52661+ struct acl_subject_label *curracl;
52662+ char *path;
52663+
52664+ if (unlikely(!(gr_status & GR_READY)))
52665+ return NULL;
52666+
52667+ preempt_disable();
52668+ path = gr_to_filename_rbac(new_dentry, mnt);
52669+ match = lookup_name_entry_create(path);
52670+
52671+ curracl = current->acl;
52672+
52673+ if (match) {
52674+ read_lock(&gr_inode_lock);
52675+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
52676+ read_unlock(&gr_inode_lock);
52677+
52678+ if (matchpo) {
52679+ preempt_enable();
52680+ return matchpo;
52681+ }
52682+ }
52683+
52684+ // lookup parent
52685+
52686+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
52687+
52688+ preempt_enable();
52689+ return matchpo;
52690+}
52691+
52692+__u32
52693+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
52694+ const struct vfsmount * mnt, const __u32 mode)
52695+{
52696+ struct acl_object_label *matchpo;
52697+ __u32 retval;
52698+
52699+ if (unlikely(!(gr_status & GR_READY)))
52700+ return (mode & ~GR_AUDITS);
52701+
52702+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
52703+
52704+ retval = matchpo->mode & mode;
52705+
52706+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
52707+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52708+ __u32 new_mode = mode;
52709+
52710+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52711+
52712+ gr_log_learn(new_dentry, mnt, new_mode);
52713+ return new_mode;
52714+ }
52715+
52716+ return retval;
52717+}
52718+
52719+__u32
52720+gr_check_link(const struct dentry * new_dentry,
52721+ const struct dentry * parent_dentry,
52722+ const struct vfsmount * parent_mnt,
52723+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
52724+{
52725+ struct acl_object_label *obj;
52726+ __u32 oldmode, newmode;
52727+ __u32 needmode;
52728+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
52729+ GR_DELETE | GR_INHERIT;
52730+
52731+ if (unlikely(!(gr_status & GR_READY)))
52732+ return (GR_CREATE | GR_LINK);
52733+
52734+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
52735+ oldmode = obj->mode;
52736+
52737+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
52738+ newmode = obj->mode;
52739+
52740+ needmode = newmode & checkmodes;
52741+
52742+ // old name for hardlink must have at least the permissions of the new name
52743+ if ((oldmode & needmode) != needmode)
52744+ goto bad;
52745+
52746+ // if old name had restrictions/auditing, make sure the new name does as well
52747+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
52748+
52749+ // don't allow hardlinking of suid/sgid files without permission
52750+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52751+ needmode |= GR_SETID;
52752+
52753+ if ((newmode & needmode) != needmode)
52754+ goto bad;
52755+
52756+ // enforce minimum permissions
52757+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
52758+ return newmode;
52759+bad:
52760+ needmode = oldmode;
52761+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52762+ needmode |= GR_SETID;
52763+
52764+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
52765+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
52766+ return (GR_CREATE | GR_LINK);
52767+ } else if (newmode & GR_SUPPRESS)
52768+ return GR_SUPPRESS;
52769+ else
52770+ return 0;
52771+}
52772+
52773+int
52774+gr_check_hidden_task(const struct task_struct *task)
52775+{
52776+ if (unlikely(!(gr_status & GR_READY)))
52777+ return 0;
52778+
52779+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
52780+ return 1;
52781+
52782+ return 0;
52783+}
52784+
52785+int
52786+gr_check_protected_task(const struct task_struct *task)
52787+{
52788+ if (unlikely(!(gr_status & GR_READY) || !task))
52789+ return 0;
52790+
52791+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52792+ task->acl != current->acl)
52793+ return 1;
52794+
52795+ return 0;
52796+}
52797+
52798+int
52799+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
52800+{
52801+ struct task_struct *p;
52802+ int ret = 0;
52803+
52804+ if (unlikely(!(gr_status & GR_READY) || !pid))
52805+ return ret;
52806+
52807+ read_lock(&tasklist_lock);
52808+ do_each_pid_task(pid, type, p) {
52809+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52810+ p->acl != current->acl) {
52811+ ret = 1;
52812+ goto out;
52813+ }
52814+ } while_each_pid_task(pid, type, p);
52815+out:
52816+ read_unlock(&tasklist_lock);
52817+
52818+ return ret;
52819+}
52820+
52821+void
52822+gr_copy_label(struct task_struct *tsk)
52823+{
52824+ /* plain copying of fields is already done by dup_task_struct */
52825+ tsk->signal->used_accept = 0;
52826+ tsk->acl_sp_role = 0;
52827+ //tsk->acl_role_id = current->acl_role_id;
52828+ //tsk->acl = current->acl;
52829+ //tsk->role = current->role;
52830+ tsk->signal->curr_ip = current->signal->curr_ip;
52831+ tsk->signal->saved_ip = current->signal->saved_ip;
52832+ if (current->exec_file)
52833+ get_file(current->exec_file);
52834+ //tsk->exec_file = current->exec_file;
52835+ //tsk->is_writable = current->is_writable;
52836+ if (unlikely(current->signal->used_accept)) {
52837+ current->signal->curr_ip = 0;
52838+ current->signal->saved_ip = 0;
52839+ }
52840+
52841+ return;
52842+}
52843+
52844+static void
52845+gr_set_proc_res(struct task_struct *task)
52846+{
52847+ struct acl_subject_label *proc;
52848+ unsigned short i;
52849+
52850+ proc = task->acl;
52851+
52852+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
52853+ return;
52854+
52855+ for (i = 0; i < RLIM_NLIMITS; i++) {
52856+ if (!(proc->resmask & (1 << i)))
52857+ continue;
52858+
52859+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
52860+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
52861+ }
52862+
52863+ return;
52864+}
52865+
52866+extern int __gr_process_user_ban(struct user_struct *user);
52867+
52868+int
52869+gr_check_user_change(int real, int effective, int fs)
52870+{
52871+ unsigned int i;
52872+ __u16 num;
52873+ uid_t *uidlist;
52874+ int curuid;
52875+ int realok = 0;
52876+ int effectiveok = 0;
52877+ int fsok = 0;
52878+
52879+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
52880+ struct user_struct *user;
52881+
52882+ if (real == -1)
52883+ goto skipit;
52884+
52885+ user = find_user(real);
52886+ if (user == NULL)
52887+ goto skipit;
52888+
52889+ if (__gr_process_user_ban(user)) {
52890+ /* for find_user */
52891+ free_uid(user);
52892+ return 1;
52893+ }
52894+
52895+ /* for find_user */
52896+ free_uid(user);
52897+
52898+skipit:
52899+#endif
52900+
52901+ if (unlikely(!(gr_status & GR_READY)))
52902+ return 0;
52903+
52904+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52905+ gr_log_learn_id_change('u', real, effective, fs);
52906+
52907+ num = current->acl->user_trans_num;
52908+ uidlist = current->acl->user_transitions;
52909+
52910+ if (uidlist == NULL)
52911+ return 0;
52912+
52913+ if (real == -1)
52914+ realok = 1;
52915+ if (effective == -1)
52916+ effectiveok = 1;
52917+ if (fs == -1)
52918+ fsok = 1;
52919+
52920+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
52921+ for (i = 0; i < num; i++) {
52922+ curuid = (int)uidlist[i];
52923+ if (real == curuid)
52924+ realok = 1;
52925+ if (effective == curuid)
52926+ effectiveok = 1;
52927+ if (fs == curuid)
52928+ fsok = 1;
52929+ }
52930+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
52931+ for (i = 0; i < num; i++) {
52932+ curuid = (int)uidlist[i];
52933+ if (real == curuid)
52934+ break;
52935+ if (effective == curuid)
52936+ break;
52937+ if (fs == curuid)
52938+ break;
52939+ }
52940+ /* not in deny list */
52941+ if (i == num) {
52942+ realok = 1;
52943+ effectiveok = 1;
52944+ fsok = 1;
52945+ }
52946+ }
52947+
52948+ if (realok && effectiveok && fsok)
52949+ return 0;
52950+ else {
52951+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
52952+ return 1;
52953+ }
52954+}
52955+
52956+int
52957+gr_check_group_change(int real, int effective, int fs)
52958+{
52959+ unsigned int i;
52960+ __u16 num;
52961+ gid_t *gidlist;
52962+ int curgid;
52963+ int realok = 0;
52964+ int effectiveok = 0;
52965+ int fsok = 0;
52966+
52967+ if (unlikely(!(gr_status & GR_READY)))
52968+ return 0;
52969+
52970+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52971+ gr_log_learn_id_change('g', real, effective, fs);
52972+
52973+ num = current->acl->group_trans_num;
52974+ gidlist = current->acl->group_transitions;
52975+
52976+ if (gidlist == NULL)
52977+ return 0;
52978+
52979+ if (real == -1)
52980+ realok = 1;
52981+ if (effective == -1)
52982+ effectiveok = 1;
52983+ if (fs == -1)
52984+ fsok = 1;
52985+
52986+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
52987+ for (i = 0; i < num; i++) {
52988+ curgid = (int)gidlist[i];
52989+ if (real == curgid)
52990+ realok = 1;
52991+ if (effective == curgid)
52992+ effectiveok = 1;
52993+ if (fs == curgid)
52994+ fsok = 1;
52995+ }
52996+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
52997+ for (i = 0; i < num; i++) {
52998+ curgid = (int)gidlist[i];
52999+ if (real == curgid)
53000+ break;
53001+ if (effective == curgid)
53002+ break;
53003+ if (fs == curgid)
53004+ break;
53005+ }
53006+ /* not in deny list */
53007+ if (i == num) {
53008+ realok = 1;
53009+ effectiveok = 1;
53010+ fsok = 1;
53011+ }
53012+ }
53013+
53014+ if (realok && effectiveok && fsok)
53015+ return 0;
53016+ else {
53017+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53018+ return 1;
53019+ }
53020+}
53021+
53022+extern int gr_acl_is_capable(const int cap);
53023+
53024+void
53025+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53026+{
53027+ struct acl_role_label *role = task->role;
53028+ struct acl_subject_label *subj = NULL;
53029+ struct acl_object_label *obj;
53030+ struct file *filp;
53031+
53032+ if (unlikely(!(gr_status & GR_READY)))
53033+ return;
53034+
53035+ filp = task->exec_file;
53036+
53037+ /* kernel process, we'll give them the kernel role */
53038+ if (unlikely(!filp)) {
53039+ task->role = kernel_role;
53040+ task->acl = kernel_role->root_label;
53041+ return;
53042+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53043+ role = lookup_acl_role_label(task, uid, gid);
53044+
53045+ /* don't change the role if we're not a privileged process */
53046+ if (role && task->role != role &&
53047+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
53048+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
53049+ return;
53050+
53051+ /* perform subject lookup in possibly new role
53052+ we can use this result below in the case where role == task->role
53053+ */
53054+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53055+
53056+ /* if we changed uid/gid, but result in the same role
53057+ and are using inheritance, don't lose the inherited subject
53058+ if current subject is other than what normal lookup
53059+ would result in, we arrived via inheritance, don't
53060+ lose subject
53061+ */
53062+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53063+ (subj == task->acl)))
53064+ task->acl = subj;
53065+
53066+ task->role = role;
53067+
53068+ task->is_writable = 0;
53069+
53070+ /* ignore additional mmap checks for processes that are writable
53071+ by the default ACL */
53072+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53073+ if (unlikely(obj->mode & GR_WRITE))
53074+ task->is_writable = 1;
53075+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53076+ if (unlikely(obj->mode & GR_WRITE))
53077+ task->is_writable = 1;
53078+
53079+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53080+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53081+#endif
53082+
53083+ gr_set_proc_res(task);
53084+
53085+ return;
53086+}
53087+
53088+int
53089+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53090+ const int unsafe_flags)
53091+{
53092+ struct task_struct *task = current;
53093+ struct acl_subject_label *newacl;
53094+ struct acl_object_label *obj;
53095+ __u32 retmode;
53096+
53097+ if (unlikely(!(gr_status & GR_READY)))
53098+ return 0;
53099+
53100+ newacl = chk_subj_label(dentry, mnt, task->role);
53101+
53102+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
53103+ did an exec
53104+ */
53105+ rcu_read_lock();
53106+ read_lock(&tasklist_lock);
53107+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
53108+ (task->parent->acl->mode & GR_POVERRIDE))) {
53109+ read_unlock(&tasklist_lock);
53110+ rcu_read_unlock();
53111+ goto skip_check;
53112+ }
53113+ read_unlock(&tasklist_lock);
53114+ rcu_read_unlock();
53115+
53116+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53117+ !(task->role->roletype & GR_ROLE_GOD) &&
53118+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53119+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53120+ if (unsafe_flags & LSM_UNSAFE_SHARE)
53121+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53122+ else
53123+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53124+ return -EACCES;
53125+ }
53126+
53127+skip_check:
53128+
53129+ obj = chk_obj_label(dentry, mnt, task->acl);
53130+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53131+
53132+ if (!(task->acl->mode & GR_INHERITLEARN) &&
53133+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53134+ if (obj->nested)
53135+ task->acl = obj->nested;
53136+ else
53137+ task->acl = newacl;
53138+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53139+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53140+
53141+ task->is_writable = 0;
53142+
53143+ /* ignore additional mmap checks for processes that are writable
53144+ by the default ACL */
53145+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
53146+ if (unlikely(obj->mode & GR_WRITE))
53147+ task->is_writable = 1;
53148+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
53149+ if (unlikely(obj->mode & GR_WRITE))
53150+ task->is_writable = 1;
53151+
53152+ gr_set_proc_res(task);
53153+
53154+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53155+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53156+#endif
53157+ return 0;
53158+}
53159+
53160+/* always called with valid inodev ptr */
53161+static void
53162+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53163+{
53164+ struct acl_object_label *matchpo;
53165+ struct acl_subject_label *matchps;
53166+ struct acl_subject_label *subj;
53167+ struct acl_role_label *role;
53168+ unsigned int x;
53169+
53170+ FOR_EACH_ROLE_START(role)
53171+ FOR_EACH_SUBJECT_START(role, subj, x)
53172+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53173+ matchpo->mode |= GR_DELETED;
53174+ FOR_EACH_SUBJECT_END(subj,x)
53175+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
53176+ if (subj->inode == ino && subj->device == dev)
53177+ subj->mode |= GR_DELETED;
53178+ FOR_EACH_NESTED_SUBJECT_END(subj)
53179+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53180+ matchps->mode |= GR_DELETED;
53181+ FOR_EACH_ROLE_END(role)
53182+
53183+ inodev->nentry->deleted = 1;
53184+
53185+ return;
53186+}
53187+
53188+void
53189+gr_handle_delete(const ino_t ino, const dev_t dev)
53190+{
53191+ struct inodev_entry *inodev;
53192+
53193+ if (unlikely(!(gr_status & GR_READY)))
53194+ return;
53195+
53196+ write_lock(&gr_inode_lock);
53197+ inodev = lookup_inodev_entry(ino, dev);
53198+ if (inodev != NULL)
53199+ do_handle_delete(inodev, ino, dev);
53200+ write_unlock(&gr_inode_lock);
53201+
53202+ return;
53203+}
53204+
53205+static void
53206+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53207+ const ino_t newinode, const dev_t newdevice,
53208+ struct acl_subject_label *subj)
53209+{
53210+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53211+ struct acl_object_label *match;
53212+
53213+ match = subj->obj_hash[index];
53214+
53215+ while (match && (match->inode != oldinode ||
53216+ match->device != olddevice ||
53217+ !(match->mode & GR_DELETED)))
53218+ match = match->next;
53219+
53220+ if (match && (match->inode == oldinode)
53221+ && (match->device == olddevice)
53222+ && (match->mode & GR_DELETED)) {
53223+ if (match->prev == NULL) {
53224+ subj->obj_hash[index] = match->next;
53225+ if (match->next != NULL)
53226+ match->next->prev = NULL;
53227+ } else {
53228+ match->prev->next = match->next;
53229+ if (match->next != NULL)
53230+ match->next->prev = match->prev;
53231+ }
53232+ match->prev = NULL;
53233+ match->next = NULL;
53234+ match->inode = newinode;
53235+ match->device = newdevice;
53236+ match->mode &= ~GR_DELETED;
53237+
53238+ insert_acl_obj_label(match, subj);
53239+ }
53240+
53241+ return;
53242+}
53243+
53244+static void
53245+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53246+ const ino_t newinode, const dev_t newdevice,
53247+ struct acl_role_label *role)
53248+{
53249+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53250+ struct acl_subject_label *match;
53251+
53252+ match = role->subj_hash[index];
53253+
53254+ while (match && (match->inode != oldinode ||
53255+ match->device != olddevice ||
53256+ !(match->mode & GR_DELETED)))
53257+ match = match->next;
53258+
53259+ if (match && (match->inode == oldinode)
53260+ && (match->device == olddevice)
53261+ && (match->mode & GR_DELETED)) {
53262+ if (match->prev == NULL) {
53263+ role->subj_hash[index] = match->next;
53264+ if (match->next != NULL)
53265+ match->next->prev = NULL;
53266+ } else {
53267+ match->prev->next = match->next;
53268+ if (match->next != NULL)
53269+ match->next->prev = match->prev;
53270+ }
53271+ match->prev = NULL;
53272+ match->next = NULL;
53273+ match->inode = newinode;
53274+ match->device = newdevice;
53275+ match->mode &= ~GR_DELETED;
53276+
53277+ insert_acl_subj_label(match, role);
53278+ }
53279+
53280+ return;
53281+}
53282+
53283+static void
53284+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53285+ const ino_t newinode, const dev_t newdevice)
53286+{
53287+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53288+ struct inodev_entry *match;
53289+
53290+ match = inodev_set.i_hash[index];
53291+
53292+ while (match && (match->nentry->inode != oldinode ||
53293+ match->nentry->device != olddevice || !match->nentry->deleted))
53294+ match = match->next;
53295+
53296+ if (match && (match->nentry->inode == oldinode)
53297+ && (match->nentry->device == olddevice) &&
53298+ match->nentry->deleted) {
53299+ if (match->prev == NULL) {
53300+ inodev_set.i_hash[index] = match->next;
53301+ if (match->next != NULL)
53302+ match->next->prev = NULL;
53303+ } else {
53304+ match->prev->next = match->next;
53305+ if (match->next != NULL)
53306+ match->next->prev = match->prev;
53307+ }
53308+ match->prev = NULL;
53309+ match->next = NULL;
53310+ match->nentry->inode = newinode;
53311+ match->nentry->device = newdevice;
53312+ match->nentry->deleted = 0;
53313+
53314+ insert_inodev_entry(match);
53315+ }
53316+
53317+ return;
53318+}
53319+
53320+static void
53321+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53322+{
53323+ struct acl_subject_label *subj;
53324+ struct acl_role_label *role;
53325+ unsigned int x;
53326+
53327+ FOR_EACH_ROLE_START(role)
53328+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53329+
53330+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
53331+ if ((subj->inode == ino) && (subj->device == dev)) {
53332+ subj->inode = ino;
53333+ subj->device = dev;
53334+ }
53335+ FOR_EACH_NESTED_SUBJECT_END(subj)
53336+ FOR_EACH_SUBJECT_START(role, subj, x)
53337+ update_acl_obj_label(matchn->inode, matchn->device,
53338+ ino, dev, subj);
53339+ FOR_EACH_SUBJECT_END(subj,x)
53340+ FOR_EACH_ROLE_END(role)
53341+
53342+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53343+
53344+ return;
53345+}
53346+
53347+static void
53348+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53349+ const struct vfsmount *mnt)
53350+{
53351+ ino_t ino = dentry->d_inode->i_ino;
53352+ dev_t dev = __get_dev(dentry);
53353+
53354+ __do_handle_create(matchn, ino, dev);
53355+
53356+ return;
53357+}
53358+
53359+void
53360+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53361+{
53362+ struct name_entry *matchn;
53363+
53364+ if (unlikely(!(gr_status & GR_READY)))
53365+ return;
53366+
53367+ preempt_disable();
53368+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53369+
53370+ if (unlikely((unsigned long)matchn)) {
53371+ write_lock(&gr_inode_lock);
53372+ do_handle_create(matchn, dentry, mnt);
53373+ write_unlock(&gr_inode_lock);
53374+ }
53375+ preempt_enable();
53376+
53377+ return;
53378+}
53379+
53380+void
53381+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
53382+{
53383+ struct name_entry *matchn;
53384+
53385+ if (unlikely(!(gr_status & GR_READY)))
53386+ return;
53387+
53388+ preempt_disable();
53389+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
53390+
53391+ if (unlikely((unsigned long)matchn)) {
53392+ write_lock(&gr_inode_lock);
53393+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
53394+ write_unlock(&gr_inode_lock);
53395+ }
53396+ preempt_enable();
53397+
53398+ return;
53399+}
53400+
53401+void
53402+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53403+ struct dentry *old_dentry,
53404+ struct dentry *new_dentry,
53405+ struct vfsmount *mnt, const __u8 replace)
53406+{
53407+ struct name_entry *matchn;
53408+ struct inodev_entry *inodev;
53409+ struct inode *inode = new_dentry->d_inode;
53410+ ino_t old_ino = old_dentry->d_inode->i_ino;
53411+ dev_t old_dev = __get_dev(old_dentry);
53412+
53413+ /* vfs_rename swaps the name and parent link for old_dentry and
53414+ new_dentry
53415+ at this point, old_dentry has the new name, parent link, and inode
53416+ for the renamed file
53417+ if a file is being replaced by a rename, new_dentry has the inode
53418+ and name for the replaced file
53419+ */
53420+
53421+ if (unlikely(!(gr_status & GR_READY)))
53422+ return;
53423+
53424+ preempt_disable();
53425+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
53426+
53427+ /* we wouldn't have to check d_inode if it weren't for
53428+ NFS silly-renaming
53429+ */
53430+
53431+ write_lock(&gr_inode_lock);
53432+ if (unlikely(replace && inode)) {
53433+ ino_t new_ino = inode->i_ino;
53434+ dev_t new_dev = __get_dev(new_dentry);
53435+
53436+ inodev = lookup_inodev_entry(new_ino, new_dev);
53437+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53438+ do_handle_delete(inodev, new_ino, new_dev);
53439+ }
53440+
53441+ inodev = lookup_inodev_entry(old_ino, old_dev);
53442+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53443+ do_handle_delete(inodev, old_ino, old_dev);
53444+
53445+ if (unlikely((unsigned long)matchn))
53446+ do_handle_create(matchn, old_dentry, mnt);
53447+
53448+ write_unlock(&gr_inode_lock);
53449+ preempt_enable();
53450+
53451+ return;
53452+}
53453+
53454+static int
53455+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53456+ unsigned char **sum)
53457+{
53458+ struct acl_role_label *r;
53459+ struct role_allowed_ip *ipp;
53460+ struct role_transition *trans;
53461+ unsigned int i;
53462+ int found = 0;
53463+ u32 curr_ip = current->signal->curr_ip;
53464+
53465+ current->signal->saved_ip = curr_ip;
53466+
53467+ /* check transition table */
53468+
53469+ for (trans = current->role->transitions; trans; trans = trans->next) {
53470+ if (!strcmp(rolename, trans->rolename)) {
53471+ found = 1;
53472+ break;
53473+ }
53474+ }
53475+
53476+ if (!found)
53477+ return 0;
53478+
53479+ /* handle special roles that do not require authentication
53480+ and check ip */
53481+
53482+ FOR_EACH_ROLE_START(r)
53483+ if (!strcmp(rolename, r->rolename) &&
53484+ (r->roletype & GR_ROLE_SPECIAL)) {
53485+ found = 0;
53486+ if (r->allowed_ips != NULL) {
53487+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
53488+ if ((ntohl(curr_ip) & ipp->netmask) ==
53489+ (ntohl(ipp->addr) & ipp->netmask))
53490+ found = 1;
53491+ }
53492+ } else
53493+ found = 2;
53494+ if (!found)
53495+ return 0;
53496+
53497+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
53498+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
53499+ *salt = NULL;
53500+ *sum = NULL;
53501+ return 1;
53502+ }
53503+ }
53504+ FOR_EACH_ROLE_END(r)
53505+
53506+ for (i = 0; i < num_sprole_pws; i++) {
53507+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
53508+ *salt = acl_special_roles[i]->salt;
53509+ *sum = acl_special_roles[i]->sum;
53510+ return 1;
53511+ }
53512+ }
53513+
53514+ return 0;
53515+}
53516+
53517+static void
53518+assign_special_role(char *rolename)
53519+{
53520+ struct acl_object_label *obj;
53521+ struct acl_role_label *r;
53522+ struct acl_role_label *assigned = NULL;
53523+ struct task_struct *tsk;
53524+ struct file *filp;
53525+
53526+ FOR_EACH_ROLE_START(r)
53527+ if (!strcmp(rolename, r->rolename) &&
53528+ (r->roletype & GR_ROLE_SPECIAL)) {
53529+ assigned = r;
53530+ break;
53531+ }
53532+ FOR_EACH_ROLE_END(r)
53533+
53534+ if (!assigned)
53535+ return;
53536+
53537+ read_lock(&tasklist_lock);
53538+ read_lock(&grsec_exec_file_lock);
53539+
53540+ tsk = current->real_parent;
53541+ if (tsk == NULL)
53542+ goto out_unlock;
53543+
53544+ filp = tsk->exec_file;
53545+ if (filp == NULL)
53546+ goto out_unlock;
53547+
53548+ tsk->is_writable = 0;
53549+
53550+ tsk->acl_sp_role = 1;
53551+ tsk->acl_role_id = ++acl_sp_role_value;
53552+ tsk->role = assigned;
53553+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
53554+
53555+ /* ignore additional mmap checks for processes that are writable
53556+ by the default ACL */
53557+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53558+ if (unlikely(obj->mode & GR_WRITE))
53559+ tsk->is_writable = 1;
53560+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
53561+ if (unlikely(obj->mode & GR_WRITE))
53562+ tsk->is_writable = 1;
53563+
53564+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53565+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
53566+#endif
53567+
53568+out_unlock:
53569+ read_unlock(&grsec_exec_file_lock);
53570+ read_unlock(&tasklist_lock);
53571+ return;
53572+}
53573+
53574+int gr_check_secure_terminal(struct task_struct *task)
53575+{
53576+ struct task_struct *p, *p2, *p3;
53577+ struct files_struct *files;
53578+ struct fdtable *fdt;
53579+ struct file *our_file = NULL, *file;
53580+ int i;
53581+
53582+ if (task->signal->tty == NULL)
53583+ return 1;
53584+
53585+ files = get_files_struct(task);
53586+ if (files != NULL) {
53587+ rcu_read_lock();
53588+ fdt = files_fdtable(files);
53589+ for (i=0; i < fdt->max_fds; i++) {
53590+ file = fcheck_files(files, i);
53591+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
53592+ get_file(file);
53593+ our_file = file;
53594+ }
53595+ }
53596+ rcu_read_unlock();
53597+ put_files_struct(files);
53598+ }
53599+
53600+ if (our_file == NULL)
53601+ return 1;
53602+
53603+ read_lock(&tasklist_lock);
53604+ do_each_thread(p2, p) {
53605+ files = get_files_struct(p);
53606+ if (files == NULL ||
53607+ (p->signal && p->signal->tty == task->signal->tty)) {
53608+ if (files != NULL)
53609+ put_files_struct(files);
53610+ continue;
53611+ }
53612+ rcu_read_lock();
53613+ fdt = files_fdtable(files);
53614+ for (i=0; i < fdt->max_fds; i++) {
53615+ file = fcheck_files(files, i);
53616+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
53617+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
53618+ p3 = task;
53619+ while (p3->pid > 0) {
53620+ if (p3 == p)
53621+ break;
53622+ p3 = p3->real_parent;
53623+ }
53624+ if (p3 == p)
53625+ break;
53626+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
53627+ gr_handle_alertkill(p);
53628+ rcu_read_unlock();
53629+ put_files_struct(files);
53630+ read_unlock(&tasklist_lock);
53631+ fput(our_file);
53632+ return 0;
53633+ }
53634+ }
53635+ rcu_read_unlock();
53636+ put_files_struct(files);
53637+ } while_each_thread(p2, p);
53638+ read_unlock(&tasklist_lock);
53639+
53640+ fput(our_file);
53641+ return 1;
53642+}
53643+
53644+ssize_t
53645+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
53646+{
53647+ struct gr_arg_wrapper uwrap;
53648+ unsigned char *sprole_salt = NULL;
53649+ unsigned char *sprole_sum = NULL;
53650+ int error = sizeof (struct gr_arg_wrapper);
53651+ int error2 = 0;
53652+
53653+ mutex_lock(&gr_dev_mutex);
53654+
53655+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
53656+ error = -EPERM;
53657+ goto out;
53658+ }
53659+
53660+ if (count != sizeof (struct gr_arg_wrapper)) {
53661+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
53662+ error = -EINVAL;
53663+ goto out;
53664+ }
53665+
53666+
53667+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
53668+ gr_auth_expires = 0;
53669+ gr_auth_attempts = 0;
53670+ }
53671+
53672+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
53673+ error = -EFAULT;
53674+ goto out;
53675+ }
53676+
53677+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
53678+ error = -EINVAL;
53679+ goto out;
53680+ }
53681+
53682+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
53683+ error = -EFAULT;
53684+ goto out;
53685+ }
53686+
53687+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53688+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53689+ time_after(gr_auth_expires, get_seconds())) {
53690+ error = -EBUSY;
53691+ goto out;
53692+ }
53693+
53694+ /* if non-root trying to do anything other than use a special role,
53695+ do not attempt authentication, do not count towards authentication
53696+ locking
53697+ */
53698+
53699+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
53700+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53701+ current_uid()) {
53702+ error = -EPERM;
53703+ goto out;
53704+ }
53705+
53706+ /* ensure pw and special role name are null terminated */
53707+
53708+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
53709+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
53710+
53711+ /* Okay.
53712+ * We have our enough of the argument structure..(we have yet
53713+ * to copy_from_user the tables themselves) . Copy the tables
53714+ * only if we need them, i.e. for loading operations. */
53715+
53716+ switch (gr_usermode->mode) {
53717+ case GR_STATUS:
53718+ if (gr_status & GR_READY) {
53719+ error = 1;
53720+ if (!gr_check_secure_terminal(current))
53721+ error = 3;
53722+ } else
53723+ error = 2;
53724+ goto out;
53725+ case GR_SHUTDOWN:
53726+ if ((gr_status & GR_READY)
53727+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53728+ pax_open_kernel();
53729+ gr_status &= ~GR_READY;
53730+ pax_close_kernel();
53731+
53732+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
53733+ free_variables();
53734+ memset(gr_usermode, 0, sizeof (struct gr_arg));
53735+ memset(gr_system_salt, 0, GR_SALT_LEN);
53736+ memset(gr_system_sum, 0, GR_SHA_LEN);
53737+ } else if (gr_status & GR_READY) {
53738+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
53739+ error = -EPERM;
53740+ } else {
53741+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
53742+ error = -EAGAIN;
53743+ }
53744+ break;
53745+ case GR_ENABLE:
53746+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
53747+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
53748+ else {
53749+ if (gr_status & GR_READY)
53750+ error = -EAGAIN;
53751+ else
53752+ error = error2;
53753+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
53754+ }
53755+ break;
53756+ case GR_RELOAD:
53757+ if (!(gr_status & GR_READY)) {
53758+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
53759+ error = -EAGAIN;
53760+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53761+ preempt_disable();
53762+
53763+ pax_open_kernel();
53764+ gr_status &= ~GR_READY;
53765+ pax_close_kernel();
53766+
53767+ free_variables();
53768+ if (!(error2 = gracl_init(gr_usermode))) {
53769+ preempt_enable();
53770+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
53771+ } else {
53772+ preempt_enable();
53773+ error = error2;
53774+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53775+ }
53776+ } else {
53777+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53778+ error = -EPERM;
53779+ }
53780+ break;
53781+ case GR_SEGVMOD:
53782+ if (unlikely(!(gr_status & GR_READY))) {
53783+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
53784+ error = -EAGAIN;
53785+ break;
53786+ }
53787+
53788+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53789+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
53790+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
53791+ struct acl_subject_label *segvacl;
53792+ segvacl =
53793+ lookup_acl_subj_label(gr_usermode->segv_inode,
53794+ gr_usermode->segv_device,
53795+ current->role);
53796+ if (segvacl) {
53797+ segvacl->crashes = 0;
53798+ segvacl->expires = 0;
53799+ }
53800+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
53801+ gr_remove_uid(gr_usermode->segv_uid);
53802+ }
53803+ } else {
53804+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
53805+ error = -EPERM;
53806+ }
53807+ break;
53808+ case GR_SPROLE:
53809+ case GR_SPROLEPAM:
53810+ if (unlikely(!(gr_status & GR_READY))) {
53811+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
53812+ error = -EAGAIN;
53813+ break;
53814+ }
53815+
53816+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
53817+ current->role->expires = 0;
53818+ current->role->auth_attempts = 0;
53819+ }
53820+
53821+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53822+ time_after(current->role->expires, get_seconds())) {
53823+ error = -EBUSY;
53824+ goto out;
53825+ }
53826+
53827+ if (lookup_special_role_auth
53828+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
53829+ && ((!sprole_salt && !sprole_sum)
53830+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
53831+ char *p = "";
53832+ assign_special_role(gr_usermode->sp_role);
53833+ read_lock(&tasklist_lock);
53834+ if (current->real_parent)
53835+ p = current->real_parent->role->rolename;
53836+ read_unlock(&tasklist_lock);
53837+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
53838+ p, acl_sp_role_value);
53839+ } else {
53840+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
53841+ error = -EPERM;
53842+ if(!(current->role->auth_attempts++))
53843+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53844+
53845+ goto out;
53846+ }
53847+ break;
53848+ case GR_UNSPROLE:
53849+ if (unlikely(!(gr_status & GR_READY))) {
53850+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
53851+ error = -EAGAIN;
53852+ break;
53853+ }
53854+
53855+ if (current->role->roletype & GR_ROLE_SPECIAL) {
53856+ char *p = "";
53857+ int i = 0;
53858+
53859+ read_lock(&tasklist_lock);
53860+ if (current->real_parent) {
53861+ p = current->real_parent->role->rolename;
53862+ i = current->real_parent->acl_role_id;
53863+ }
53864+ read_unlock(&tasklist_lock);
53865+
53866+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
53867+ gr_set_acls(1);
53868+ } else {
53869+ error = -EPERM;
53870+ goto out;
53871+ }
53872+ break;
53873+ default:
53874+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
53875+ error = -EINVAL;
53876+ break;
53877+ }
53878+
53879+ if (error != -EPERM)
53880+ goto out;
53881+
53882+ if(!(gr_auth_attempts++))
53883+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53884+
53885+ out:
53886+ mutex_unlock(&gr_dev_mutex);
53887+ return error;
53888+}
53889+
53890+/* must be called with
53891+ rcu_read_lock();
53892+ read_lock(&tasklist_lock);
53893+ read_lock(&grsec_exec_file_lock);
53894+*/
53895+int gr_apply_subject_to_task(struct task_struct *task)
53896+{
53897+ struct acl_object_label *obj;
53898+ char *tmpname;
53899+ struct acl_subject_label *tmpsubj;
53900+ struct file *filp;
53901+ struct name_entry *nmatch;
53902+
53903+ filp = task->exec_file;
53904+ if (filp == NULL)
53905+ return 0;
53906+
53907+ /* the following is to apply the correct subject
53908+ on binaries running when the RBAC system
53909+ is enabled, when the binaries have been
53910+ replaced or deleted since their execution
53911+ -----
53912+ when the RBAC system starts, the inode/dev
53913+ from exec_file will be one the RBAC system
53914+ is unaware of. It only knows the inode/dev
53915+ of the present file on disk, or the absence
53916+ of it.
53917+ */
53918+ preempt_disable();
53919+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
53920+
53921+ nmatch = lookup_name_entry(tmpname);
53922+ preempt_enable();
53923+ tmpsubj = NULL;
53924+ if (nmatch) {
53925+ if (nmatch->deleted)
53926+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
53927+ else
53928+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
53929+ if (tmpsubj != NULL)
53930+ task->acl = tmpsubj;
53931+ }
53932+ if (tmpsubj == NULL)
53933+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
53934+ task->role);
53935+ if (task->acl) {
53936+ task->is_writable = 0;
53937+ /* ignore additional mmap checks for processes that are writable
53938+ by the default ACL */
53939+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53940+ if (unlikely(obj->mode & GR_WRITE))
53941+ task->is_writable = 1;
53942+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53943+ if (unlikely(obj->mode & GR_WRITE))
53944+ task->is_writable = 1;
53945+
53946+ gr_set_proc_res(task);
53947+
53948+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53949+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53950+#endif
53951+ } else {
53952+ return 1;
53953+ }
53954+
53955+ return 0;
53956+}
53957+
53958+int
53959+gr_set_acls(const int type)
53960+{
53961+ struct task_struct *task, *task2;
53962+ struct acl_role_label *role = current->role;
53963+ __u16 acl_role_id = current->acl_role_id;
53964+ const struct cred *cred;
53965+ int ret;
53966+
53967+ rcu_read_lock();
53968+ read_lock(&tasklist_lock);
53969+ read_lock(&grsec_exec_file_lock);
53970+ do_each_thread(task2, task) {
53971+ /* check to see if we're called from the exit handler,
53972+ if so, only replace ACLs that have inherited the admin
53973+ ACL */
53974+
53975+ if (type && (task->role != role ||
53976+ task->acl_role_id != acl_role_id))
53977+ continue;
53978+
53979+ task->acl_role_id = 0;
53980+ task->acl_sp_role = 0;
53981+
53982+ if (task->exec_file) {
53983+ cred = __task_cred(task);
53984+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
53985+ ret = gr_apply_subject_to_task(task);
53986+ if (ret) {
53987+ read_unlock(&grsec_exec_file_lock);
53988+ read_unlock(&tasklist_lock);
53989+ rcu_read_unlock();
53990+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
53991+ return ret;
53992+ }
53993+ } else {
53994+ // it's a kernel process
53995+ task->role = kernel_role;
53996+ task->acl = kernel_role->root_label;
53997+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
53998+ task->acl->mode &= ~GR_PROCFIND;
53999+#endif
54000+ }
54001+ } while_each_thread(task2, task);
54002+ read_unlock(&grsec_exec_file_lock);
54003+ read_unlock(&tasklist_lock);
54004+ rcu_read_unlock();
54005+
54006+ return 0;
54007+}
54008+
54009+void
54010+gr_learn_resource(const struct task_struct *task,
54011+ const int res, const unsigned long wanted, const int gt)
54012+{
54013+ struct acl_subject_label *acl;
54014+ const struct cred *cred;
54015+
54016+ if (unlikely((gr_status & GR_READY) &&
54017+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54018+ goto skip_reslog;
54019+
54020+#ifdef CONFIG_GRKERNSEC_RESLOG
54021+ gr_log_resource(task, res, wanted, gt);
54022+#endif
54023+ skip_reslog:
54024+
54025+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54026+ return;
54027+
54028+ acl = task->acl;
54029+
54030+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54031+ !(acl->resmask & (1 << (unsigned short) res))))
54032+ return;
54033+
54034+ if (wanted >= acl->res[res].rlim_cur) {
54035+ unsigned long res_add;
54036+
54037+ res_add = wanted;
54038+ switch (res) {
54039+ case RLIMIT_CPU:
54040+ res_add += GR_RLIM_CPU_BUMP;
54041+ break;
54042+ case RLIMIT_FSIZE:
54043+ res_add += GR_RLIM_FSIZE_BUMP;
54044+ break;
54045+ case RLIMIT_DATA:
54046+ res_add += GR_RLIM_DATA_BUMP;
54047+ break;
54048+ case RLIMIT_STACK:
54049+ res_add += GR_RLIM_STACK_BUMP;
54050+ break;
54051+ case RLIMIT_CORE:
54052+ res_add += GR_RLIM_CORE_BUMP;
54053+ break;
54054+ case RLIMIT_RSS:
54055+ res_add += GR_RLIM_RSS_BUMP;
54056+ break;
54057+ case RLIMIT_NPROC:
54058+ res_add += GR_RLIM_NPROC_BUMP;
54059+ break;
54060+ case RLIMIT_NOFILE:
54061+ res_add += GR_RLIM_NOFILE_BUMP;
54062+ break;
54063+ case RLIMIT_MEMLOCK:
54064+ res_add += GR_RLIM_MEMLOCK_BUMP;
54065+ break;
54066+ case RLIMIT_AS:
54067+ res_add += GR_RLIM_AS_BUMP;
54068+ break;
54069+ case RLIMIT_LOCKS:
54070+ res_add += GR_RLIM_LOCKS_BUMP;
54071+ break;
54072+ case RLIMIT_SIGPENDING:
54073+ res_add += GR_RLIM_SIGPENDING_BUMP;
54074+ break;
54075+ case RLIMIT_MSGQUEUE:
54076+ res_add += GR_RLIM_MSGQUEUE_BUMP;
54077+ break;
54078+ case RLIMIT_NICE:
54079+ res_add += GR_RLIM_NICE_BUMP;
54080+ break;
54081+ case RLIMIT_RTPRIO:
54082+ res_add += GR_RLIM_RTPRIO_BUMP;
54083+ break;
54084+ case RLIMIT_RTTIME:
54085+ res_add += GR_RLIM_RTTIME_BUMP;
54086+ break;
54087+ }
54088+
54089+ acl->res[res].rlim_cur = res_add;
54090+
54091+ if (wanted > acl->res[res].rlim_max)
54092+ acl->res[res].rlim_max = res_add;
54093+
54094+ /* only log the subject filename, since resource logging is supported for
54095+ single-subject learning only */
54096+ rcu_read_lock();
54097+ cred = __task_cred(task);
54098+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54099+ task->role->roletype, cred->uid, cred->gid, acl->filename,
54100+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54101+ "", (unsigned long) res, &task->signal->saved_ip);
54102+ rcu_read_unlock();
54103+ }
54104+
54105+ return;
54106+}
54107+
54108+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54109+void
54110+pax_set_initial_flags(struct linux_binprm *bprm)
54111+{
54112+ struct task_struct *task = current;
54113+ struct acl_subject_label *proc;
54114+ unsigned long flags;
54115+
54116+ if (unlikely(!(gr_status & GR_READY)))
54117+ return;
54118+
54119+ flags = pax_get_flags(task);
54120+
54121+ proc = task->acl;
54122+
54123+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54124+ flags &= ~MF_PAX_PAGEEXEC;
54125+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54126+ flags &= ~MF_PAX_SEGMEXEC;
54127+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54128+ flags &= ~MF_PAX_RANDMMAP;
54129+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54130+ flags &= ~MF_PAX_EMUTRAMP;
54131+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54132+ flags &= ~MF_PAX_MPROTECT;
54133+
54134+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54135+ flags |= MF_PAX_PAGEEXEC;
54136+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54137+ flags |= MF_PAX_SEGMEXEC;
54138+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54139+ flags |= MF_PAX_RANDMMAP;
54140+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54141+ flags |= MF_PAX_EMUTRAMP;
54142+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54143+ flags |= MF_PAX_MPROTECT;
54144+
54145+ pax_set_flags(task, flags);
54146+
54147+ return;
54148+}
54149+#endif
54150+
54151+#ifdef CONFIG_SYSCTL
54152+/* Eric Biederman likes breaking userland ABI and every inode-based security
54153+ system to save 35kb of memory */
54154+
54155+/* we modify the passed in filename, but adjust it back before returning */
54156+static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
54157+{
54158+ struct name_entry *nmatch;
54159+ char *p, *lastp = NULL;
54160+ struct acl_object_label *obj = NULL, *tmp;
54161+ struct acl_subject_label *tmpsubj;
54162+ char c = '\0';
54163+
54164+ read_lock(&gr_inode_lock);
54165+
54166+ p = name + len - 1;
54167+ do {
54168+ nmatch = lookup_name_entry(name);
54169+ if (lastp != NULL)
54170+ *lastp = c;
54171+
54172+ if (nmatch == NULL)
54173+ goto next_component;
54174+ tmpsubj = current->acl;
54175+ do {
54176+ obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
54177+ if (obj != NULL) {
54178+ tmp = obj->globbed;
54179+ while (tmp) {
54180+ if (!glob_match(tmp->filename, name)) {
54181+ obj = tmp;
54182+ goto found_obj;
54183+ }
54184+ tmp = tmp->next;
54185+ }
54186+ goto found_obj;
54187+ }
54188+ } while ((tmpsubj = tmpsubj->parent_subject));
54189+next_component:
54190+ /* end case */
54191+ if (p == name)
54192+ break;
54193+
54194+ while (*p != '/')
54195+ p--;
54196+ if (p == name)
54197+ lastp = p + 1;
54198+ else {
54199+ lastp = p;
54200+ p--;
54201+ }
54202+ c = *lastp;
54203+ *lastp = '\0';
54204+ } while (1);
54205+found_obj:
54206+ read_unlock(&gr_inode_lock);
54207+ /* obj returned will always be non-null */
54208+ return obj;
54209+}
54210+
54211+/* returns 0 when allowing, non-zero on error
54212+ op of 0 is used for readdir, so we don't log the names of hidden files
54213+*/
54214+__u32
54215+gr_handle_sysctl(const struct ctl_table *table, const int op)
54216+{
54217+ struct ctl_table *tmp;
54218+ const char *proc_sys = "/proc/sys";
54219+ char *path;
54220+ struct acl_object_label *obj;
54221+ unsigned short len = 0, pos = 0, depth = 0, i;
54222+ __u32 err = 0;
54223+ __u32 mode = 0;
54224+
54225+ if (unlikely(!(gr_status & GR_READY)))
54226+ return 0;
54227+
54228+ /* for now, ignore operations on non-sysctl entries if it's not a
54229+ readdir*/
54230+ if (table->child != NULL && op != 0)
54231+ return 0;
54232+
54233+ mode |= GR_FIND;
54234+ /* it's only a read if it's an entry, read on dirs is for readdir */
54235+ if (op & MAY_READ)
54236+ mode |= GR_READ;
54237+ if (op & MAY_WRITE)
54238+ mode |= GR_WRITE;
54239+
54240+ preempt_disable();
54241+
54242+ path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54243+
54244+ /* it's only a read/write if it's an actual entry, not a dir
54245+ (which are opened for readdir)
54246+ */
54247+
54248+ /* convert the requested sysctl entry into a pathname */
54249+
54250+ for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54251+ len += strlen(tmp->procname);
54252+ len++;
54253+ depth++;
54254+ }
54255+
54256+ if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
54257+ /* deny */
54258+ goto out;
54259+ }
54260+
54261+ memset(path, 0, PAGE_SIZE);
54262+
54263+ memcpy(path, proc_sys, strlen(proc_sys));
54264+
54265+ pos += strlen(proc_sys);
54266+
54267+ for (; depth > 0; depth--) {
54268+ path[pos] = '/';
54269+ pos++;
54270+ for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54271+ if (depth == i) {
54272+ memcpy(path + pos, tmp->procname,
54273+ strlen(tmp->procname));
54274+ pos += strlen(tmp->procname);
54275+ }
54276+ i++;
54277+ }
54278+ }
54279+
54280+ obj = gr_lookup_by_name(path, pos);
54281+ err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
54282+
54283+ if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
54284+ ((err & mode) != mode))) {
54285+ __u32 new_mode = mode;
54286+
54287+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54288+
54289+ err = 0;
54290+ gr_log_learn_sysctl(path, new_mode);
54291+ } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
54292+ gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
54293+ err = -ENOENT;
54294+ } else if (!(err & GR_FIND)) {
54295+ err = -ENOENT;
54296+ } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
54297+ gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
54298+ path, (mode & GR_READ) ? " reading" : "",
54299+ (mode & GR_WRITE) ? " writing" : "");
54300+ err = -EACCES;
54301+ } else if ((err & mode) != mode) {
54302+ err = -EACCES;
54303+ } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
54304+ gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
54305+ path, (mode & GR_READ) ? " reading" : "",
54306+ (mode & GR_WRITE) ? " writing" : "");
54307+ err = 0;
54308+ } else
54309+ err = 0;
54310+
54311+ out:
54312+ preempt_enable();
54313+
54314+ return err;
54315+}
54316+#endif
54317+
54318+int
54319+gr_handle_proc_ptrace(struct task_struct *task)
54320+{
54321+ struct file *filp;
54322+ struct task_struct *tmp = task;
54323+ struct task_struct *curtemp = current;
54324+ __u32 retmode;
54325+
54326+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54327+ if (unlikely(!(gr_status & GR_READY)))
54328+ return 0;
54329+#endif
54330+
54331+ read_lock(&tasklist_lock);
54332+ read_lock(&grsec_exec_file_lock);
54333+ filp = task->exec_file;
54334+
54335+ while (tmp->pid > 0) {
54336+ if (tmp == curtemp)
54337+ break;
54338+ tmp = tmp->real_parent;
54339+ }
54340+
54341+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54342+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54343+ read_unlock(&grsec_exec_file_lock);
54344+ read_unlock(&tasklist_lock);
54345+ return 1;
54346+ }
54347+
54348+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54349+ if (!(gr_status & GR_READY)) {
54350+ read_unlock(&grsec_exec_file_lock);
54351+ read_unlock(&tasklist_lock);
54352+ return 0;
54353+ }
54354+#endif
54355+
54356+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54357+ read_unlock(&grsec_exec_file_lock);
54358+ read_unlock(&tasklist_lock);
54359+
54360+ if (retmode & GR_NOPTRACE)
54361+ return 1;
54362+
54363+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54364+ && (current->acl != task->acl || (current->acl != current->role->root_label
54365+ && current->pid != task->pid)))
54366+ return 1;
54367+
54368+ return 0;
54369+}
54370+
54371+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54372+{
54373+ if (unlikely(!(gr_status & GR_READY)))
54374+ return;
54375+
54376+ if (!(current->role->roletype & GR_ROLE_GOD))
54377+ return;
54378+
54379+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
54380+ p->role->rolename, gr_task_roletype_to_char(p),
54381+ p->acl->filename);
54382+}
54383+
54384+int
54385+gr_handle_ptrace(struct task_struct *task, const long request)
54386+{
54387+ struct task_struct *tmp = task;
54388+ struct task_struct *curtemp = current;
54389+ __u32 retmode;
54390+
54391+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54392+ if (unlikely(!(gr_status & GR_READY)))
54393+ return 0;
54394+#endif
54395+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
54396+ read_lock(&tasklist_lock);
54397+ while (tmp->pid > 0) {
54398+ if (tmp == curtemp)
54399+ break;
54400+ tmp = tmp->real_parent;
54401+ }
54402+
54403+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54404+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54405+ read_unlock(&tasklist_lock);
54406+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54407+ return 1;
54408+ }
54409+ read_unlock(&tasklist_lock);
54410+ }
54411+
54412+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54413+ if (!(gr_status & GR_READY))
54414+ return 0;
54415+#endif
54416+
54417+ read_lock(&grsec_exec_file_lock);
54418+ if (unlikely(!task->exec_file)) {
54419+ read_unlock(&grsec_exec_file_lock);
54420+ return 0;
54421+ }
54422+
54423+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54424+ read_unlock(&grsec_exec_file_lock);
54425+
54426+ if (retmode & GR_NOPTRACE) {
54427+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54428+ return 1;
54429+ }
54430+
54431+ if (retmode & GR_PTRACERD) {
54432+ switch (request) {
54433+ case PTRACE_SEIZE:
54434+ case PTRACE_POKETEXT:
54435+ case PTRACE_POKEDATA:
54436+ case PTRACE_POKEUSR:
54437+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54438+ case PTRACE_SETREGS:
54439+ case PTRACE_SETFPREGS:
54440+#endif
54441+#ifdef CONFIG_X86
54442+ case PTRACE_SETFPXREGS:
54443+#endif
54444+#ifdef CONFIG_ALTIVEC
54445+ case PTRACE_SETVRREGS:
54446+#endif
54447+ return 1;
54448+ default:
54449+ return 0;
54450+ }
54451+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
54452+ !(current->role->roletype & GR_ROLE_GOD) &&
54453+ (current->acl != task->acl)) {
54454+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54455+ return 1;
54456+ }
54457+
54458+ return 0;
54459+}
54460+
54461+static int is_writable_mmap(const struct file *filp)
54462+{
54463+ struct task_struct *task = current;
54464+ struct acl_object_label *obj, *obj2;
54465+
54466+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
54467+ !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))) {
54468+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54469+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
54470+ task->role->root_label);
54471+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
54472+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
54473+ return 1;
54474+ }
54475+ }
54476+ return 0;
54477+}
54478+
54479+int
54480+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
54481+{
54482+ __u32 mode;
54483+
54484+ if (unlikely(!file || !(prot & PROT_EXEC)))
54485+ return 1;
54486+
54487+ if (is_writable_mmap(file))
54488+ return 0;
54489+
54490+ mode =
54491+ gr_search_file(file->f_path.dentry,
54492+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54493+ file->f_path.mnt);
54494+
54495+ if (!gr_tpe_allow(file))
54496+ return 0;
54497+
54498+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54499+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54500+ return 0;
54501+ } else if (unlikely(!(mode & GR_EXEC))) {
54502+ return 0;
54503+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54504+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54505+ return 1;
54506+ }
54507+
54508+ return 1;
54509+}
54510+
54511+int
54512+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54513+{
54514+ __u32 mode;
54515+
54516+ if (unlikely(!file || !(prot & PROT_EXEC)))
54517+ return 1;
54518+
54519+ if (is_writable_mmap(file))
54520+ return 0;
54521+
54522+ mode =
54523+ gr_search_file(file->f_path.dentry,
54524+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54525+ file->f_path.mnt);
54526+
54527+ if (!gr_tpe_allow(file))
54528+ return 0;
54529+
54530+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54531+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54532+ return 0;
54533+ } else if (unlikely(!(mode & GR_EXEC))) {
54534+ return 0;
54535+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54536+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54537+ return 1;
54538+ }
54539+
54540+ return 1;
54541+}
54542+
54543+void
54544+gr_acl_handle_psacct(struct task_struct *task, const long code)
54545+{
54546+ unsigned long runtime;
54547+ unsigned long cputime;
54548+ unsigned int wday, cday;
54549+ __u8 whr, chr;
54550+ __u8 wmin, cmin;
54551+ __u8 wsec, csec;
54552+ struct timespec timeval;
54553+
54554+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
54555+ !(task->acl->mode & GR_PROCACCT)))
54556+ return;
54557+
54558+ do_posix_clock_monotonic_gettime(&timeval);
54559+ runtime = timeval.tv_sec - task->start_time.tv_sec;
54560+ wday = runtime / (3600 * 24);
54561+ runtime -= wday * (3600 * 24);
54562+ whr = runtime / 3600;
54563+ runtime -= whr * 3600;
54564+ wmin = runtime / 60;
54565+ runtime -= wmin * 60;
54566+ wsec = runtime;
54567+
54568+ cputime = (task->utime + task->stime) / HZ;
54569+ cday = cputime / (3600 * 24);
54570+ cputime -= cday * (3600 * 24);
54571+ chr = cputime / 3600;
54572+ cputime -= chr * 3600;
54573+ cmin = cputime / 60;
54574+ cputime -= cmin * 60;
54575+ csec = cputime;
54576+
54577+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
54578+
54579+ return;
54580+}
54581+
54582+void gr_set_kernel_label(struct task_struct *task)
54583+{
54584+ if (gr_status & GR_READY) {
54585+ task->role = kernel_role;
54586+ task->acl = kernel_role->root_label;
54587+ }
54588+ return;
54589+}
54590+
54591+#ifdef CONFIG_TASKSTATS
54592+int gr_is_taskstats_denied(int pid)
54593+{
54594+ struct task_struct *task;
54595+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54596+ const struct cred *cred;
54597+#endif
54598+ int ret = 0;
54599+
54600+ /* restrict taskstats viewing to un-chrooted root users
54601+ who have the 'view' subject flag if the RBAC system is enabled
54602+ */
54603+
54604+ rcu_read_lock();
54605+ read_lock(&tasklist_lock);
54606+ task = find_task_by_vpid(pid);
54607+ if (task) {
54608+#ifdef CONFIG_GRKERNSEC_CHROOT
54609+ if (proc_is_chrooted(task))
54610+ ret = -EACCES;
54611+#endif
54612+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54613+ cred = __task_cred(task);
54614+#ifdef CONFIG_GRKERNSEC_PROC_USER
54615+ if (cred->uid != 0)
54616+ ret = -EACCES;
54617+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54618+ if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
54619+ ret = -EACCES;
54620+#endif
54621+#endif
54622+ if (gr_status & GR_READY) {
54623+ if (!(task->acl->mode & GR_VIEW))
54624+ ret = -EACCES;
54625+ }
54626+ } else
54627+ ret = -ENOENT;
54628+
54629+ read_unlock(&tasklist_lock);
54630+ rcu_read_unlock();
54631+
54632+ return ret;
54633+}
54634+#endif
54635+
54636+/* AUXV entries are filled via a descendant of search_binary_handler
54637+ after we've already applied the subject for the target
54638+*/
54639+int gr_acl_enable_at_secure(void)
54640+{
54641+ if (unlikely(!(gr_status & GR_READY)))
54642+ return 0;
54643+
54644+ if (current->acl->mode & GR_ATSECURE)
54645+ return 1;
54646+
54647+ return 0;
54648+}
54649+
54650+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
54651+{
54652+ struct task_struct *task = current;
54653+ struct dentry *dentry = file->f_path.dentry;
54654+ struct vfsmount *mnt = file->f_path.mnt;
54655+ struct acl_object_label *obj, *tmp;
54656+ struct acl_subject_label *subj;
54657+ unsigned int bufsize;
54658+ int is_not_root;
54659+ char *path;
54660+ dev_t dev = __get_dev(dentry);
54661+
54662+ if (unlikely(!(gr_status & GR_READY)))
54663+ return 1;
54664+
54665+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54666+ return 1;
54667+
54668+ /* ignore Eric Biederman */
54669+ if (IS_PRIVATE(dentry->d_inode))
54670+ return 1;
54671+
54672+ subj = task->acl;
54673+ do {
54674+ obj = lookup_acl_obj_label(ino, dev, subj);
54675+ if (obj != NULL)
54676+ return (obj->mode & GR_FIND) ? 1 : 0;
54677+ } while ((subj = subj->parent_subject));
54678+
54679+ /* this is purely an optimization since we're looking for an object
54680+ for the directory we're doing a readdir on
54681+ if it's possible for any globbed object to match the entry we're
54682+ filling into the directory, then the object we find here will be
54683+ an anchor point with attached globbed objects
54684+ */
54685+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
54686+ if (obj->globbed == NULL)
54687+ return (obj->mode & GR_FIND) ? 1 : 0;
54688+
54689+ is_not_root = ((obj->filename[0] == '/') &&
54690+ (obj->filename[1] == '\0')) ? 0 : 1;
54691+ bufsize = PAGE_SIZE - namelen - is_not_root;
54692+
54693+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
54694+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
54695+ return 1;
54696+
54697+ preempt_disable();
54698+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54699+ bufsize);
54700+
54701+ bufsize = strlen(path);
54702+
54703+ /* if base is "/", don't append an additional slash */
54704+ if (is_not_root)
54705+ *(path + bufsize) = '/';
54706+ memcpy(path + bufsize + is_not_root, name, namelen);
54707+ *(path + bufsize + namelen + is_not_root) = '\0';
54708+
54709+ tmp = obj->globbed;
54710+ while (tmp) {
54711+ if (!glob_match(tmp->filename, path)) {
54712+ preempt_enable();
54713+ return (tmp->mode & GR_FIND) ? 1 : 0;
54714+ }
54715+ tmp = tmp->next;
54716+ }
54717+ preempt_enable();
54718+ return (obj->mode & GR_FIND) ? 1 : 0;
54719+}
54720+
54721+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
54722+EXPORT_SYMBOL(gr_acl_is_enabled);
54723+#endif
54724+EXPORT_SYMBOL(gr_learn_resource);
54725+EXPORT_SYMBOL(gr_set_kernel_label);
54726+#ifdef CONFIG_SECURITY
54727+EXPORT_SYMBOL(gr_check_user_change);
54728+EXPORT_SYMBOL(gr_check_group_change);
54729+#endif
54730+
54731diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
54732new file mode 100644
54733index 0000000..34fefda
54734--- /dev/null
54735+++ b/grsecurity/gracl_alloc.c
54736@@ -0,0 +1,105 @@
54737+#include <linux/kernel.h>
54738+#include <linux/mm.h>
54739+#include <linux/slab.h>
54740+#include <linux/vmalloc.h>
54741+#include <linux/gracl.h>
54742+#include <linux/grsecurity.h>
54743+
54744+static unsigned long alloc_stack_next = 1;
54745+static unsigned long alloc_stack_size = 1;
54746+static void **alloc_stack;
54747+
54748+static __inline__ int
54749+alloc_pop(void)
54750+{
54751+ if (alloc_stack_next == 1)
54752+ return 0;
54753+
54754+ kfree(alloc_stack[alloc_stack_next - 2]);
54755+
54756+ alloc_stack_next--;
54757+
54758+ return 1;
54759+}
54760+
54761+static __inline__ int
54762+alloc_push(void *buf)
54763+{
54764+ if (alloc_stack_next >= alloc_stack_size)
54765+ return 1;
54766+
54767+ alloc_stack[alloc_stack_next - 1] = buf;
54768+
54769+ alloc_stack_next++;
54770+
54771+ return 0;
54772+}
54773+
54774+void *
54775+acl_alloc(unsigned long len)
54776+{
54777+ void *ret = NULL;
54778+
54779+ if (!len || len > PAGE_SIZE)
54780+ goto out;
54781+
54782+ ret = kmalloc(len, GFP_KERNEL);
54783+
54784+ if (ret) {
54785+ if (alloc_push(ret)) {
54786+ kfree(ret);
54787+ ret = NULL;
54788+ }
54789+ }
54790+
54791+out:
54792+ return ret;
54793+}
54794+
54795+void *
54796+acl_alloc_num(unsigned long num, unsigned long len)
54797+{
54798+ if (!len || (num > (PAGE_SIZE / len)))
54799+ return NULL;
54800+
54801+ return acl_alloc(num * len);
54802+}
54803+
54804+void
54805+acl_free_all(void)
54806+{
54807+ if (gr_acl_is_enabled() || !alloc_stack)
54808+ return;
54809+
54810+ while (alloc_pop()) ;
54811+
54812+ if (alloc_stack) {
54813+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
54814+ kfree(alloc_stack);
54815+ else
54816+ vfree(alloc_stack);
54817+ }
54818+
54819+ alloc_stack = NULL;
54820+ alloc_stack_size = 1;
54821+ alloc_stack_next = 1;
54822+
54823+ return;
54824+}
54825+
54826+int
54827+acl_alloc_stack_init(unsigned long size)
54828+{
54829+ if ((size * sizeof (void *)) <= PAGE_SIZE)
54830+ alloc_stack =
54831+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
54832+ else
54833+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
54834+
54835+ alloc_stack_size = size;
54836+
54837+ if (!alloc_stack)
54838+ return 0;
54839+ else
54840+ return 1;
54841+}
54842diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
54843new file mode 100644
54844index 0000000..6d21049
54845--- /dev/null
54846+++ b/grsecurity/gracl_cap.c
54847@@ -0,0 +1,110 @@
54848+#include <linux/kernel.h>
54849+#include <linux/module.h>
54850+#include <linux/sched.h>
54851+#include <linux/gracl.h>
54852+#include <linux/grsecurity.h>
54853+#include <linux/grinternal.h>
54854+
54855+extern const char *captab_log[];
54856+extern int captab_log_entries;
54857+
54858+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
54859+{
54860+ struct acl_subject_label *curracl;
54861+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54862+ kernel_cap_t cap_audit = __cap_empty_set;
54863+
54864+ if (!gr_acl_is_enabled())
54865+ return 1;
54866+
54867+ curracl = task->acl;
54868+
54869+ cap_drop = curracl->cap_lower;
54870+ cap_mask = curracl->cap_mask;
54871+ cap_audit = curracl->cap_invert_audit;
54872+
54873+ while ((curracl = curracl->parent_subject)) {
54874+ /* if the cap isn't specified in the current computed mask but is specified in the
54875+ current level subject, and is lowered in the current level subject, then add
54876+ it to the set of dropped capabilities
54877+ otherwise, add the current level subject's mask to the current computed mask
54878+ */
54879+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54880+ cap_raise(cap_mask, cap);
54881+ if (cap_raised(curracl->cap_lower, cap))
54882+ cap_raise(cap_drop, cap);
54883+ if (cap_raised(curracl->cap_invert_audit, cap))
54884+ cap_raise(cap_audit, cap);
54885+ }
54886+ }
54887+
54888+ if (!cap_raised(cap_drop, cap)) {
54889+ if (cap_raised(cap_audit, cap))
54890+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
54891+ return 1;
54892+ }
54893+
54894+ curracl = task->acl;
54895+
54896+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
54897+ && cap_raised(cred->cap_effective, cap)) {
54898+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54899+ task->role->roletype, cred->uid,
54900+ cred->gid, task->exec_file ?
54901+ gr_to_filename(task->exec_file->f_path.dentry,
54902+ task->exec_file->f_path.mnt) : curracl->filename,
54903+ curracl->filename, 0UL,
54904+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
54905+ return 1;
54906+ }
54907+
54908+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
54909+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
54910+
54911+ return 0;
54912+}
54913+
54914+int
54915+gr_acl_is_capable(const int cap)
54916+{
54917+ return gr_task_acl_is_capable(current, current_cred(), cap);
54918+}
54919+
54920+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
54921+{
54922+ struct acl_subject_label *curracl;
54923+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54924+
54925+ if (!gr_acl_is_enabled())
54926+ return 1;
54927+
54928+ curracl = task->acl;
54929+
54930+ cap_drop = curracl->cap_lower;
54931+ cap_mask = curracl->cap_mask;
54932+
54933+ while ((curracl = curracl->parent_subject)) {
54934+ /* if the cap isn't specified in the current computed mask but is specified in the
54935+ current level subject, and is lowered in the current level subject, then add
54936+ it to the set of dropped capabilities
54937+ otherwise, add the current level subject's mask to the current computed mask
54938+ */
54939+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54940+ cap_raise(cap_mask, cap);
54941+ if (cap_raised(curracl->cap_lower, cap))
54942+ cap_raise(cap_drop, cap);
54943+ }
54944+ }
54945+
54946+ if (!cap_raised(cap_drop, cap))
54947+ return 1;
54948+
54949+ return 0;
54950+}
54951+
54952+int
54953+gr_acl_is_capable_nolog(const int cap)
54954+{
54955+ return gr_task_acl_is_capable_nolog(current, cap);
54956+}
54957+
54958diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
54959new file mode 100644
54960index 0000000..88d0e87
54961--- /dev/null
54962+++ b/grsecurity/gracl_fs.c
54963@@ -0,0 +1,435 @@
54964+#include <linux/kernel.h>
54965+#include <linux/sched.h>
54966+#include <linux/types.h>
54967+#include <linux/fs.h>
54968+#include <linux/file.h>
54969+#include <linux/stat.h>
54970+#include <linux/grsecurity.h>
54971+#include <linux/grinternal.h>
54972+#include <linux/gracl.h>
54973+
54974+umode_t
54975+gr_acl_umask(void)
54976+{
54977+ if (unlikely(!gr_acl_is_enabled()))
54978+ return 0;
54979+
54980+ return current->role->umask;
54981+}
54982+
54983+__u32
54984+gr_acl_handle_hidden_file(const struct dentry * dentry,
54985+ const struct vfsmount * mnt)
54986+{
54987+ __u32 mode;
54988+
54989+ if (unlikely(!dentry->d_inode))
54990+ return GR_FIND;
54991+
54992+ mode =
54993+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
54994+
54995+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
54996+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
54997+ return mode;
54998+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
54999+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55000+ return 0;
55001+ } else if (unlikely(!(mode & GR_FIND)))
55002+ return 0;
55003+
55004+ return GR_FIND;
55005+}
55006+
55007+__u32
55008+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55009+ int acc_mode)
55010+{
55011+ __u32 reqmode = GR_FIND;
55012+ __u32 mode;
55013+
55014+ if (unlikely(!dentry->d_inode))
55015+ return reqmode;
55016+
55017+ if (acc_mode & MAY_APPEND)
55018+ reqmode |= GR_APPEND;
55019+ else if (acc_mode & MAY_WRITE)
55020+ reqmode |= GR_WRITE;
55021+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55022+ reqmode |= GR_READ;
55023+
55024+ mode =
55025+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55026+ mnt);
55027+
55028+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55029+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55030+ reqmode & GR_READ ? " reading" : "",
55031+ reqmode & GR_WRITE ? " writing" : reqmode &
55032+ GR_APPEND ? " appending" : "");
55033+ return reqmode;
55034+ } else
55035+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55036+ {
55037+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55038+ reqmode & GR_READ ? " reading" : "",
55039+ reqmode & GR_WRITE ? " writing" : reqmode &
55040+ GR_APPEND ? " appending" : "");
55041+ return 0;
55042+ } else if (unlikely((mode & reqmode) != reqmode))
55043+ return 0;
55044+
55045+ return reqmode;
55046+}
55047+
55048+__u32
55049+gr_acl_handle_creat(const struct dentry * dentry,
55050+ const struct dentry * p_dentry,
55051+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55052+ const int imode)
55053+{
55054+ __u32 reqmode = GR_WRITE | GR_CREATE;
55055+ __u32 mode;
55056+
55057+ if (acc_mode & MAY_APPEND)
55058+ reqmode |= GR_APPEND;
55059+ // if a directory was required or the directory already exists, then
55060+ // don't count this open as a read
55061+ if ((acc_mode & MAY_READ) &&
55062+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55063+ reqmode |= GR_READ;
55064+ if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
55065+ reqmode |= GR_SETID;
55066+
55067+ mode =
55068+ gr_check_create(dentry, p_dentry, p_mnt,
55069+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55070+
55071+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55072+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55073+ reqmode & GR_READ ? " reading" : "",
55074+ reqmode & GR_WRITE ? " writing" : reqmode &
55075+ GR_APPEND ? " appending" : "");
55076+ return reqmode;
55077+ } else
55078+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55079+ {
55080+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55081+ reqmode & GR_READ ? " reading" : "",
55082+ reqmode & GR_WRITE ? " writing" : reqmode &
55083+ GR_APPEND ? " appending" : "");
55084+ return 0;
55085+ } else if (unlikely((mode & reqmode) != reqmode))
55086+ return 0;
55087+
55088+ return reqmode;
55089+}
55090+
55091+__u32
55092+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55093+ const int fmode)
55094+{
55095+ __u32 mode, reqmode = GR_FIND;
55096+
55097+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55098+ reqmode |= GR_EXEC;
55099+ if (fmode & S_IWOTH)
55100+ reqmode |= GR_WRITE;
55101+ if (fmode & S_IROTH)
55102+ reqmode |= GR_READ;
55103+
55104+ mode =
55105+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55106+ mnt);
55107+
55108+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55109+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55110+ reqmode & GR_READ ? " reading" : "",
55111+ reqmode & GR_WRITE ? " writing" : "",
55112+ reqmode & GR_EXEC ? " executing" : "");
55113+ return reqmode;
55114+ } else
55115+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55116+ {
55117+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55118+ reqmode & GR_READ ? " reading" : "",
55119+ reqmode & GR_WRITE ? " writing" : "",
55120+ reqmode & GR_EXEC ? " executing" : "");
55121+ return 0;
55122+ } else if (unlikely((mode & reqmode) != reqmode))
55123+ return 0;
55124+
55125+ return reqmode;
55126+}
55127+
55128+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55129+{
55130+ __u32 mode;
55131+
55132+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55133+
55134+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55135+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55136+ return mode;
55137+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55138+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55139+ return 0;
55140+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55141+ return 0;
55142+
55143+ return (reqmode);
55144+}
55145+
55146+__u32
55147+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55148+{
55149+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55150+}
55151+
55152+__u32
55153+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55154+{
55155+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55156+}
55157+
55158+__u32
55159+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55160+{
55161+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55162+}
55163+
55164+__u32
55165+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55166+{
55167+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55168+}
55169+
55170+__u32
55171+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55172+ umode_t *modeptr)
55173+{
55174+ umode_t mode;
55175+
55176+ *modeptr &= ~gr_acl_umask();
55177+ mode = *modeptr;
55178+
55179+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55180+ return 1;
55181+
55182+ if (unlikely(mode & (S_ISUID | S_ISGID))) {
55183+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55184+ GR_CHMOD_ACL_MSG);
55185+ } else {
55186+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55187+ }
55188+}
55189+
55190+__u32
55191+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55192+{
55193+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55194+}
55195+
55196+__u32
55197+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55198+{
55199+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55200+}
55201+
55202+__u32
55203+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55204+{
55205+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55206+}
55207+
55208+__u32
55209+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55210+{
55211+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55212+ GR_UNIXCONNECT_ACL_MSG);
55213+}
55214+
55215+/* hardlinks require at minimum create and link permission,
55216+ any additional privilege required is based on the
55217+ privilege of the file being linked to
55218+*/
55219+__u32
55220+gr_acl_handle_link(const struct dentry * new_dentry,
55221+ const struct dentry * parent_dentry,
55222+ const struct vfsmount * parent_mnt,
55223+ const struct dentry * old_dentry,
55224+ const struct vfsmount * old_mnt, const char *to)
55225+{
55226+ __u32 mode;
55227+ __u32 needmode = GR_CREATE | GR_LINK;
55228+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55229+
55230+ mode =
55231+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55232+ old_mnt);
55233+
55234+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55235+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55236+ return mode;
55237+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55238+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55239+ return 0;
55240+ } else if (unlikely((mode & needmode) != needmode))
55241+ return 0;
55242+
55243+ return 1;
55244+}
55245+
55246+__u32
55247+gr_acl_handle_symlink(const struct dentry * new_dentry,
55248+ const struct dentry * parent_dentry,
55249+ const struct vfsmount * parent_mnt, const char *from)
55250+{
55251+ __u32 needmode = GR_WRITE | GR_CREATE;
55252+ __u32 mode;
55253+
55254+ mode =
55255+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
55256+ GR_CREATE | GR_AUDIT_CREATE |
55257+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55258+
55259+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55260+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55261+ return mode;
55262+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55263+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55264+ return 0;
55265+ } else if (unlikely((mode & needmode) != needmode))
55266+ return 0;
55267+
55268+ return (GR_WRITE | GR_CREATE);
55269+}
55270+
55271+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)
55272+{
55273+ __u32 mode;
55274+
55275+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55276+
55277+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55278+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55279+ return mode;
55280+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55281+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55282+ return 0;
55283+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55284+ return 0;
55285+
55286+ return (reqmode);
55287+}
55288+
55289+__u32
55290+gr_acl_handle_mknod(const struct dentry * new_dentry,
55291+ const struct dentry * parent_dentry,
55292+ const struct vfsmount * parent_mnt,
55293+ const int mode)
55294+{
55295+ __u32 reqmode = GR_WRITE | GR_CREATE;
55296+ if (unlikely(mode & (S_ISUID | S_ISGID)))
55297+ reqmode |= GR_SETID;
55298+
55299+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55300+ reqmode, GR_MKNOD_ACL_MSG);
55301+}
55302+
55303+__u32
55304+gr_acl_handle_mkdir(const struct dentry *new_dentry,
55305+ const struct dentry *parent_dentry,
55306+ const struct vfsmount *parent_mnt)
55307+{
55308+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55309+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55310+}
55311+
55312+#define RENAME_CHECK_SUCCESS(old, new) \
55313+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55314+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55315+
55316+int
55317+gr_acl_handle_rename(struct dentry *new_dentry,
55318+ struct dentry *parent_dentry,
55319+ const struct vfsmount *parent_mnt,
55320+ struct dentry *old_dentry,
55321+ struct inode *old_parent_inode,
55322+ struct vfsmount *old_mnt, const char *newname)
55323+{
55324+ __u32 comp1, comp2;
55325+ int error = 0;
55326+
55327+ if (unlikely(!gr_acl_is_enabled()))
55328+ return 0;
55329+
55330+ if (!new_dentry->d_inode) {
55331+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55332+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55333+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55334+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55335+ GR_DELETE | GR_AUDIT_DELETE |
55336+ GR_AUDIT_READ | GR_AUDIT_WRITE |
55337+ GR_SUPPRESS, old_mnt);
55338+ } else {
55339+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55340+ GR_CREATE | GR_DELETE |
55341+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55342+ GR_AUDIT_READ | GR_AUDIT_WRITE |
55343+ GR_SUPPRESS, parent_mnt);
55344+ comp2 =
55345+ gr_search_file(old_dentry,
55346+ GR_READ | GR_WRITE | GR_AUDIT_READ |
55347+ GR_DELETE | GR_AUDIT_DELETE |
55348+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55349+ }
55350+
55351+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55352+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55353+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55354+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55355+ && !(comp2 & GR_SUPPRESS)) {
55356+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55357+ error = -EACCES;
55358+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55359+ error = -EACCES;
55360+
55361+ return error;
55362+}
55363+
55364+void
55365+gr_acl_handle_exit(void)
55366+{
55367+ u16 id;
55368+ char *rolename;
55369+ struct file *exec_file;
55370+
55371+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55372+ !(current->role->roletype & GR_ROLE_PERSIST))) {
55373+ id = current->acl_role_id;
55374+ rolename = current->role->rolename;
55375+ gr_set_acls(1);
55376+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55377+ }
55378+
55379+ write_lock(&grsec_exec_file_lock);
55380+ exec_file = current->exec_file;
55381+ current->exec_file = NULL;
55382+ write_unlock(&grsec_exec_file_lock);
55383+
55384+ if (exec_file)
55385+ fput(exec_file);
55386+}
55387+
55388+int
55389+gr_acl_handle_procpidmem(const struct task_struct *task)
55390+{
55391+ if (unlikely(!gr_acl_is_enabled()))
55392+ return 0;
55393+
55394+ if (task != current && task->acl->mode & GR_PROTPROCFD)
55395+ return -EACCES;
55396+
55397+ return 0;
55398+}
55399diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55400new file mode 100644
55401index 0000000..58800a7
55402--- /dev/null
55403+++ b/grsecurity/gracl_ip.c
55404@@ -0,0 +1,384 @@
55405+#include <linux/kernel.h>
55406+#include <asm/uaccess.h>
55407+#include <asm/errno.h>
55408+#include <net/sock.h>
55409+#include <linux/file.h>
55410+#include <linux/fs.h>
55411+#include <linux/net.h>
55412+#include <linux/in.h>
55413+#include <linux/skbuff.h>
55414+#include <linux/ip.h>
55415+#include <linux/udp.h>
55416+#include <linux/types.h>
55417+#include <linux/sched.h>
55418+#include <linux/netdevice.h>
55419+#include <linux/inetdevice.h>
55420+#include <linux/gracl.h>
55421+#include <linux/grsecurity.h>
55422+#include <linux/grinternal.h>
55423+
55424+#define GR_BIND 0x01
55425+#define GR_CONNECT 0x02
55426+#define GR_INVERT 0x04
55427+#define GR_BINDOVERRIDE 0x08
55428+#define GR_CONNECTOVERRIDE 0x10
55429+#define GR_SOCK_FAMILY 0x20
55430+
55431+static const char * gr_protocols[IPPROTO_MAX] = {
55432+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55433+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55434+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55435+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55436+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55437+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55438+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55439+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55440+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55441+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55442+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55443+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55444+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55445+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55446+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55447+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55448+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55449+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
55450+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
55451+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
55452+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
55453+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
55454+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
55455+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
55456+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
55457+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55458+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
55459+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
55460+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
55461+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
55462+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
55463+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
55464+ };
55465+
55466+static const char * gr_socktypes[SOCK_MAX] = {
55467+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
55468+ "unknown:7", "unknown:8", "unknown:9", "packet"
55469+ };
55470+
55471+static const char * gr_sockfamilies[AF_MAX+1] = {
55472+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
55473+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
55474+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
55475+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
55476+ };
55477+
55478+const char *
55479+gr_proto_to_name(unsigned char proto)
55480+{
55481+ return gr_protocols[proto];
55482+}
55483+
55484+const char *
55485+gr_socktype_to_name(unsigned char type)
55486+{
55487+ return gr_socktypes[type];
55488+}
55489+
55490+const char *
55491+gr_sockfamily_to_name(unsigned char family)
55492+{
55493+ return gr_sockfamilies[family];
55494+}
55495+
55496+int
55497+gr_search_socket(const int domain, const int type, const int protocol)
55498+{
55499+ struct acl_subject_label *curr;
55500+ const struct cred *cred = current_cred();
55501+
55502+ if (unlikely(!gr_acl_is_enabled()))
55503+ goto exit;
55504+
55505+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
55506+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
55507+ goto exit; // let the kernel handle it
55508+
55509+ curr = current->acl;
55510+
55511+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
55512+ /* the family is allowed, if this is PF_INET allow it only if
55513+ the extra sock type/protocol checks pass */
55514+ if (domain == PF_INET)
55515+ goto inet_check;
55516+ goto exit;
55517+ } else {
55518+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55519+ __u32 fakeip = 0;
55520+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55521+ current->role->roletype, cred->uid,
55522+ cred->gid, current->exec_file ?
55523+ gr_to_filename(current->exec_file->f_path.dentry,
55524+ current->exec_file->f_path.mnt) :
55525+ curr->filename, curr->filename,
55526+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
55527+ &current->signal->saved_ip);
55528+ goto exit;
55529+ }
55530+ goto exit_fail;
55531+ }
55532+
55533+inet_check:
55534+ /* the rest of this checking is for IPv4 only */
55535+ if (!curr->ips)
55536+ goto exit;
55537+
55538+ if ((curr->ip_type & (1 << type)) &&
55539+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
55540+ goto exit;
55541+
55542+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55543+ /* we don't place acls on raw sockets , and sometimes
55544+ dgram/ip sockets are opened for ioctl and not
55545+ bind/connect, so we'll fake a bind learn log */
55546+ if (type == SOCK_RAW || type == SOCK_PACKET) {
55547+ __u32 fakeip = 0;
55548+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55549+ current->role->roletype, cred->uid,
55550+ cred->gid, current->exec_file ?
55551+ gr_to_filename(current->exec_file->f_path.dentry,
55552+ current->exec_file->f_path.mnt) :
55553+ curr->filename, curr->filename,
55554+ &fakeip, 0, type,
55555+ protocol, GR_CONNECT, &current->signal->saved_ip);
55556+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
55557+ __u32 fakeip = 0;
55558+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55559+ current->role->roletype, cred->uid,
55560+ cred->gid, current->exec_file ?
55561+ gr_to_filename(current->exec_file->f_path.dentry,
55562+ current->exec_file->f_path.mnt) :
55563+ curr->filename, curr->filename,
55564+ &fakeip, 0, type,
55565+ protocol, GR_BIND, &current->signal->saved_ip);
55566+ }
55567+ /* we'll log when they use connect or bind */
55568+ goto exit;
55569+ }
55570+
55571+exit_fail:
55572+ if (domain == PF_INET)
55573+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
55574+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
55575+ else
55576+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
55577+ gr_socktype_to_name(type), protocol);
55578+
55579+ return 0;
55580+exit:
55581+ return 1;
55582+}
55583+
55584+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)
55585+{
55586+ if ((ip->mode & mode) &&
55587+ (ip_port >= ip->low) &&
55588+ (ip_port <= ip->high) &&
55589+ ((ntohl(ip_addr) & our_netmask) ==
55590+ (ntohl(our_addr) & our_netmask))
55591+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
55592+ && (ip->type & (1 << type))) {
55593+ if (ip->mode & GR_INVERT)
55594+ return 2; // specifically denied
55595+ else
55596+ return 1; // allowed
55597+ }
55598+
55599+ return 0; // not specifically allowed, may continue parsing
55600+}
55601+
55602+static int
55603+gr_search_connectbind(const int full_mode, struct sock *sk,
55604+ struct sockaddr_in *addr, const int type)
55605+{
55606+ char iface[IFNAMSIZ] = {0};
55607+ struct acl_subject_label *curr;
55608+ struct acl_ip_label *ip;
55609+ struct inet_sock *isk;
55610+ struct net_device *dev;
55611+ struct in_device *idev;
55612+ unsigned long i;
55613+ int ret;
55614+ int mode = full_mode & (GR_BIND | GR_CONNECT);
55615+ __u32 ip_addr = 0;
55616+ __u32 our_addr;
55617+ __u32 our_netmask;
55618+ char *p;
55619+ __u16 ip_port = 0;
55620+ const struct cred *cred = current_cred();
55621+
55622+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
55623+ return 0;
55624+
55625+ curr = current->acl;
55626+ isk = inet_sk(sk);
55627+
55628+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
55629+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
55630+ addr->sin_addr.s_addr = curr->inaddr_any_override;
55631+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
55632+ struct sockaddr_in saddr;
55633+ int err;
55634+
55635+ saddr.sin_family = AF_INET;
55636+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
55637+ saddr.sin_port = isk->inet_sport;
55638+
55639+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55640+ if (err)
55641+ return err;
55642+
55643+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55644+ if (err)
55645+ return err;
55646+ }
55647+
55648+ if (!curr->ips)
55649+ return 0;
55650+
55651+ ip_addr = addr->sin_addr.s_addr;
55652+ ip_port = ntohs(addr->sin_port);
55653+
55654+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55655+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55656+ current->role->roletype, cred->uid,
55657+ cred->gid, current->exec_file ?
55658+ gr_to_filename(current->exec_file->f_path.dentry,
55659+ current->exec_file->f_path.mnt) :
55660+ curr->filename, curr->filename,
55661+ &ip_addr, ip_port, type,
55662+ sk->sk_protocol, mode, &current->signal->saved_ip);
55663+ return 0;
55664+ }
55665+
55666+ for (i = 0; i < curr->ip_num; i++) {
55667+ ip = *(curr->ips + i);
55668+ if (ip->iface != NULL) {
55669+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
55670+ p = strchr(iface, ':');
55671+ if (p != NULL)
55672+ *p = '\0';
55673+ dev = dev_get_by_name(sock_net(sk), iface);
55674+ if (dev == NULL)
55675+ continue;
55676+ idev = in_dev_get(dev);
55677+ if (idev == NULL) {
55678+ dev_put(dev);
55679+ continue;
55680+ }
55681+ rcu_read_lock();
55682+ for_ifa(idev) {
55683+ if (!strcmp(ip->iface, ifa->ifa_label)) {
55684+ our_addr = ifa->ifa_address;
55685+ our_netmask = 0xffffffff;
55686+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55687+ if (ret == 1) {
55688+ rcu_read_unlock();
55689+ in_dev_put(idev);
55690+ dev_put(dev);
55691+ return 0;
55692+ } else if (ret == 2) {
55693+ rcu_read_unlock();
55694+ in_dev_put(idev);
55695+ dev_put(dev);
55696+ goto denied;
55697+ }
55698+ }
55699+ } endfor_ifa(idev);
55700+ rcu_read_unlock();
55701+ in_dev_put(idev);
55702+ dev_put(dev);
55703+ } else {
55704+ our_addr = ip->addr;
55705+ our_netmask = ip->netmask;
55706+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55707+ if (ret == 1)
55708+ return 0;
55709+ else if (ret == 2)
55710+ goto denied;
55711+ }
55712+ }
55713+
55714+denied:
55715+ if (mode == GR_BIND)
55716+ 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));
55717+ else if (mode == GR_CONNECT)
55718+ 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));
55719+
55720+ return -EACCES;
55721+}
55722+
55723+int
55724+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
55725+{
55726+ /* always allow disconnection of dgram sockets with connect */
55727+ if (addr->sin_family == AF_UNSPEC)
55728+ return 0;
55729+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
55730+}
55731+
55732+int
55733+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
55734+{
55735+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
55736+}
55737+
55738+int gr_search_listen(struct socket *sock)
55739+{
55740+ struct sock *sk = sock->sk;
55741+ struct sockaddr_in addr;
55742+
55743+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55744+ addr.sin_port = inet_sk(sk)->inet_sport;
55745+
55746+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55747+}
55748+
55749+int gr_search_accept(struct socket *sock)
55750+{
55751+ struct sock *sk = sock->sk;
55752+ struct sockaddr_in addr;
55753+
55754+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55755+ addr.sin_port = inet_sk(sk)->inet_sport;
55756+
55757+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55758+}
55759+
55760+int
55761+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
55762+{
55763+ if (addr)
55764+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
55765+ else {
55766+ struct sockaddr_in sin;
55767+ const struct inet_sock *inet = inet_sk(sk);
55768+
55769+ sin.sin_addr.s_addr = inet->inet_daddr;
55770+ sin.sin_port = inet->inet_dport;
55771+
55772+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55773+ }
55774+}
55775+
55776+int
55777+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
55778+{
55779+ struct sockaddr_in sin;
55780+
55781+ if (unlikely(skb->len < sizeof (struct udphdr)))
55782+ return 0; // skip this packet
55783+
55784+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
55785+ sin.sin_port = udp_hdr(skb)->source;
55786+
55787+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55788+}
55789diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
55790new file mode 100644
55791index 0000000..25f54ef
55792--- /dev/null
55793+++ b/grsecurity/gracl_learn.c
55794@@ -0,0 +1,207 @@
55795+#include <linux/kernel.h>
55796+#include <linux/mm.h>
55797+#include <linux/sched.h>
55798+#include <linux/poll.h>
55799+#include <linux/string.h>
55800+#include <linux/file.h>
55801+#include <linux/types.h>
55802+#include <linux/vmalloc.h>
55803+#include <linux/grinternal.h>
55804+
55805+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
55806+ size_t count, loff_t *ppos);
55807+extern int gr_acl_is_enabled(void);
55808+
55809+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
55810+static int gr_learn_attached;
55811+
55812+/* use a 512k buffer */
55813+#define LEARN_BUFFER_SIZE (512 * 1024)
55814+
55815+static DEFINE_SPINLOCK(gr_learn_lock);
55816+static DEFINE_MUTEX(gr_learn_user_mutex);
55817+
55818+/* we need to maintain two buffers, so that the kernel context of grlearn
55819+ uses a semaphore around the userspace copying, and the other kernel contexts
55820+ use a spinlock when copying into the buffer, since they cannot sleep
55821+*/
55822+static char *learn_buffer;
55823+static char *learn_buffer_user;
55824+static int learn_buffer_len;
55825+static int learn_buffer_user_len;
55826+
55827+static ssize_t
55828+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
55829+{
55830+ DECLARE_WAITQUEUE(wait, current);
55831+ ssize_t retval = 0;
55832+
55833+ add_wait_queue(&learn_wait, &wait);
55834+ set_current_state(TASK_INTERRUPTIBLE);
55835+ do {
55836+ mutex_lock(&gr_learn_user_mutex);
55837+ spin_lock(&gr_learn_lock);
55838+ if (learn_buffer_len)
55839+ break;
55840+ spin_unlock(&gr_learn_lock);
55841+ mutex_unlock(&gr_learn_user_mutex);
55842+ if (file->f_flags & O_NONBLOCK) {
55843+ retval = -EAGAIN;
55844+ goto out;
55845+ }
55846+ if (signal_pending(current)) {
55847+ retval = -ERESTARTSYS;
55848+ goto out;
55849+ }
55850+
55851+ schedule();
55852+ } while (1);
55853+
55854+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
55855+ learn_buffer_user_len = learn_buffer_len;
55856+ retval = learn_buffer_len;
55857+ learn_buffer_len = 0;
55858+
55859+ spin_unlock(&gr_learn_lock);
55860+
55861+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
55862+ retval = -EFAULT;
55863+
55864+ mutex_unlock(&gr_learn_user_mutex);
55865+out:
55866+ set_current_state(TASK_RUNNING);
55867+ remove_wait_queue(&learn_wait, &wait);
55868+ return retval;
55869+}
55870+
55871+static unsigned int
55872+poll_learn(struct file * file, poll_table * wait)
55873+{
55874+ poll_wait(file, &learn_wait, wait);
55875+
55876+ if (learn_buffer_len)
55877+ return (POLLIN | POLLRDNORM);
55878+
55879+ return 0;
55880+}
55881+
55882+void
55883+gr_clear_learn_entries(void)
55884+{
55885+ char *tmp;
55886+
55887+ mutex_lock(&gr_learn_user_mutex);
55888+ spin_lock(&gr_learn_lock);
55889+ tmp = learn_buffer;
55890+ learn_buffer = NULL;
55891+ spin_unlock(&gr_learn_lock);
55892+ if (tmp)
55893+ vfree(tmp);
55894+ if (learn_buffer_user != NULL) {
55895+ vfree(learn_buffer_user);
55896+ learn_buffer_user = NULL;
55897+ }
55898+ learn_buffer_len = 0;
55899+ mutex_unlock(&gr_learn_user_mutex);
55900+
55901+ return;
55902+}
55903+
55904+void
55905+gr_add_learn_entry(const char *fmt, ...)
55906+{
55907+ va_list args;
55908+ unsigned int len;
55909+
55910+ if (!gr_learn_attached)
55911+ return;
55912+
55913+ spin_lock(&gr_learn_lock);
55914+
55915+ /* leave a gap at the end so we know when it's "full" but don't have to
55916+ compute the exact length of the string we're trying to append
55917+ */
55918+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
55919+ spin_unlock(&gr_learn_lock);
55920+ wake_up_interruptible(&learn_wait);
55921+ return;
55922+ }
55923+ if (learn_buffer == NULL) {
55924+ spin_unlock(&gr_learn_lock);
55925+ return;
55926+ }
55927+
55928+ va_start(args, fmt);
55929+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
55930+ va_end(args);
55931+
55932+ learn_buffer_len += len + 1;
55933+
55934+ spin_unlock(&gr_learn_lock);
55935+ wake_up_interruptible(&learn_wait);
55936+
55937+ return;
55938+}
55939+
55940+static int
55941+open_learn(struct inode *inode, struct file *file)
55942+{
55943+ if (file->f_mode & FMODE_READ && gr_learn_attached)
55944+ return -EBUSY;
55945+ if (file->f_mode & FMODE_READ) {
55946+ int retval = 0;
55947+ mutex_lock(&gr_learn_user_mutex);
55948+ if (learn_buffer == NULL)
55949+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
55950+ if (learn_buffer_user == NULL)
55951+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
55952+ if (learn_buffer == NULL) {
55953+ retval = -ENOMEM;
55954+ goto out_error;
55955+ }
55956+ if (learn_buffer_user == NULL) {
55957+ retval = -ENOMEM;
55958+ goto out_error;
55959+ }
55960+ learn_buffer_len = 0;
55961+ learn_buffer_user_len = 0;
55962+ gr_learn_attached = 1;
55963+out_error:
55964+ mutex_unlock(&gr_learn_user_mutex);
55965+ return retval;
55966+ }
55967+ return 0;
55968+}
55969+
55970+static int
55971+close_learn(struct inode *inode, struct file *file)
55972+{
55973+ if (file->f_mode & FMODE_READ) {
55974+ char *tmp = NULL;
55975+ mutex_lock(&gr_learn_user_mutex);
55976+ spin_lock(&gr_learn_lock);
55977+ tmp = learn_buffer;
55978+ learn_buffer = NULL;
55979+ spin_unlock(&gr_learn_lock);
55980+ if (tmp)
55981+ vfree(tmp);
55982+ if (learn_buffer_user != NULL) {
55983+ vfree(learn_buffer_user);
55984+ learn_buffer_user = NULL;
55985+ }
55986+ learn_buffer_len = 0;
55987+ learn_buffer_user_len = 0;
55988+ gr_learn_attached = 0;
55989+ mutex_unlock(&gr_learn_user_mutex);
55990+ }
55991+
55992+ return 0;
55993+}
55994+
55995+const struct file_operations grsec_fops = {
55996+ .read = read_learn,
55997+ .write = write_grsec_handler,
55998+ .open = open_learn,
55999+ .release = close_learn,
56000+ .poll = poll_learn,
56001+};
56002diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56003new file mode 100644
56004index 0000000..39645c9
56005--- /dev/null
56006+++ b/grsecurity/gracl_res.c
56007@@ -0,0 +1,68 @@
56008+#include <linux/kernel.h>
56009+#include <linux/sched.h>
56010+#include <linux/gracl.h>
56011+#include <linux/grinternal.h>
56012+
56013+static const char *restab_log[] = {
56014+ [RLIMIT_CPU] = "RLIMIT_CPU",
56015+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56016+ [RLIMIT_DATA] = "RLIMIT_DATA",
56017+ [RLIMIT_STACK] = "RLIMIT_STACK",
56018+ [RLIMIT_CORE] = "RLIMIT_CORE",
56019+ [RLIMIT_RSS] = "RLIMIT_RSS",
56020+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
56021+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56022+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56023+ [RLIMIT_AS] = "RLIMIT_AS",
56024+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56025+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56026+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56027+ [RLIMIT_NICE] = "RLIMIT_NICE",
56028+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56029+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56030+ [GR_CRASH_RES] = "RLIMIT_CRASH"
56031+};
56032+
56033+void
56034+gr_log_resource(const struct task_struct *task,
56035+ const int res, const unsigned long wanted, const int gt)
56036+{
56037+ const struct cred *cred;
56038+ unsigned long rlim;
56039+
56040+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
56041+ return;
56042+
56043+ // not yet supported resource
56044+ if (unlikely(!restab_log[res]))
56045+ return;
56046+
56047+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56048+ rlim = task_rlimit_max(task, res);
56049+ else
56050+ rlim = task_rlimit(task, res);
56051+
56052+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56053+ return;
56054+
56055+ rcu_read_lock();
56056+ cred = __task_cred(task);
56057+
56058+ if (res == RLIMIT_NPROC &&
56059+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56060+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56061+ goto out_rcu_unlock;
56062+ else if (res == RLIMIT_MEMLOCK &&
56063+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56064+ goto out_rcu_unlock;
56065+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56066+ goto out_rcu_unlock;
56067+ rcu_read_unlock();
56068+
56069+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56070+
56071+ return;
56072+out_rcu_unlock:
56073+ rcu_read_unlock();
56074+ return;
56075+}
56076diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56077new file mode 100644
56078index 0000000..5556be3
56079--- /dev/null
56080+++ b/grsecurity/gracl_segv.c
56081@@ -0,0 +1,299 @@
56082+#include <linux/kernel.h>
56083+#include <linux/mm.h>
56084+#include <asm/uaccess.h>
56085+#include <asm/errno.h>
56086+#include <asm/mman.h>
56087+#include <net/sock.h>
56088+#include <linux/file.h>
56089+#include <linux/fs.h>
56090+#include <linux/net.h>
56091+#include <linux/in.h>
56092+#include <linux/slab.h>
56093+#include <linux/types.h>
56094+#include <linux/sched.h>
56095+#include <linux/timer.h>
56096+#include <linux/gracl.h>
56097+#include <linux/grsecurity.h>
56098+#include <linux/grinternal.h>
56099+
56100+static struct crash_uid *uid_set;
56101+static unsigned short uid_used;
56102+static DEFINE_SPINLOCK(gr_uid_lock);
56103+extern rwlock_t gr_inode_lock;
56104+extern struct acl_subject_label *
56105+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56106+ struct acl_role_label *role);
56107+
56108+#ifdef CONFIG_BTRFS_FS
56109+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56110+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56111+#endif
56112+
56113+static inline dev_t __get_dev(const struct dentry *dentry)
56114+{
56115+#ifdef CONFIG_BTRFS_FS
56116+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56117+ return get_btrfs_dev_from_inode(dentry->d_inode);
56118+ else
56119+#endif
56120+ return dentry->d_inode->i_sb->s_dev;
56121+}
56122+
56123+int
56124+gr_init_uidset(void)
56125+{
56126+ uid_set =
56127+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56128+ uid_used = 0;
56129+
56130+ return uid_set ? 1 : 0;
56131+}
56132+
56133+void
56134+gr_free_uidset(void)
56135+{
56136+ if (uid_set)
56137+ kfree(uid_set);
56138+
56139+ return;
56140+}
56141+
56142+int
56143+gr_find_uid(const uid_t uid)
56144+{
56145+ struct crash_uid *tmp = uid_set;
56146+ uid_t buid;
56147+ int low = 0, high = uid_used - 1, mid;
56148+
56149+ while (high >= low) {
56150+ mid = (low + high) >> 1;
56151+ buid = tmp[mid].uid;
56152+ if (buid == uid)
56153+ return mid;
56154+ if (buid > uid)
56155+ high = mid - 1;
56156+ if (buid < uid)
56157+ low = mid + 1;
56158+ }
56159+
56160+ return -1;
56161+}
56162+
56163+static __inline__ void
56164+gr_insertsort(void)
56165+{
56166+ unsigned short i, j;
56167+ struct crash_uid index;
56168+
56169+ for (i = 1; i < uid_used; i++) {
56170+ index = uid_set[i];
56171+ j = i;
56172+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56173+ uid_set[j] = uid_set[j - 1];
56174+ j--;
56175+ }
56176+ uid_set[j] = index;
56177+ }
56178+
56179+ return;
56180+}
56181+
56182+static __inline__ void
56183+gr_insert_uid(const uid_t uid, const unsigned long expires)
56184+{
56185+ int loc;
56186+
56187+ if (uid_used == GR_UIDTABLE_MAX)
56188+ return;
56189+
56190+ loc = gr_find_uid(uid);
56191+
56192+ if (loc >= 0) {
56193+ uid_set[loc].expires = expires;
56194+ return;
56195+ }
56196+
56197+ uid_set[uid_used].uid = uid;
56198+ uid_set[uid_used].expires = expires;
56199+ uid_used++;
56200+
56201+ gr_insertsort();
56202+
56203+ return;
56204+}
56205+
56206+void
56207+gr_remove_uid(const unsigned short loc)
56208+{
56209+ unsigned short i;
56210+
56211+ for (i = loc + 1; i < uid_used; i++)
56212+ uid_set[i - 1] = uid_set[i];
56213+
56214+ uid_used--;
56215+
56216+ return;
56217+}
56218+
56219+int
56220+gr_check_crash_uid(const uid_t uid)
56221+{
56222+ int loc;
56223+ int ret = 0;
56224+
56225+ if (unlikely(!gr_acl_is_enabled()))
56226+ return 0;
56227+
56228+ spin_lock(&gr_uid_lock);
56229+ loc = gr_find_uid(uid);
56230+
56231+ if (loc < 0)
56232+ goto out_unlock;
56233+
56234+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
56235+ gr_remove_uid(loc);
56236+ else
56237+ ret = 1;
56238+
56239+out_unlock:
56240+ spin_unlock(&gr_uid_lock);
56241+ return ret;
56242+}
56243+
56244+static __inline__ int
56245+proc_is_setxid(const struct cred *cred)
56246+{
56247+ if (cred->uid != cred->euid || cred->uid != cred->suid ||
56248+ cred->uid != cred->fsuid)
56249+ return 1;
56250+ if (cred->gid != cred->egid || cred->gid != cred->sgid ||
56251+ cred->gid != cred->fsgid)
56252+ return 1;
56253+
56254+ return 0;
56255+}
56256+
56257+extern int gr_fake_force_sig(int sig, struct task_struct *t);
56258+
56259+void
56260+gr_handle_crash(struct task_struct *task, const int sig)
56261+{
56262+ struct acl_subject_label *curr;
56263+ struct task_struct *tsk, *tsk2;
56264+ const struct cred *cred;
56265+ const struct cred *cred2;
56266+
56267+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56268+ return;
56269+
56270+ if (unlikely(!gr_acl_is_enabled()))
56271+ return;
56272+
56273+ curr = task->acl;
56274+
56275+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
56276+ return;
56277+
56278+ if (time_before_eq(curr->expires, get_seconds())) {
56279+ curr->expires = 0;
56280+ curr->crashes = 0;
56281+ }
56282+
56283+ curr->crashes++;
56284+
56285+ if (!curr->expires)
56286+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56287+
56288+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56289+ time_after(curr->expires, get_seconds())) {
56290+ rcu_read_lock();
56291+ cred = __task_cred(task);
56292+ if (cred->uid && proc_is_setxid(cred)) {
56293+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56294+ spin_lock(&gr_uid_lock);
56295+ gr_insert_uid(cred->uid, curr->expires);
56296+ spin_unlock(&gr_uid_lock);
56297+ curr->expires = 0;
56298+ curr->crashes = 0;
56299+ read_lock(&tasklist_lock);
56300+ do_each_thread(tsk2, tsk) {
56301+ cred2 = __task_cred(tsk);
56302+ if (tsk != task && cred2->uid == cred->uid)
56303+ gr_fake_force_sig(SIGKILL, tsk);
56304+ } while_each_thread(tsk2, tsk);
56305+ read_unlock(&tasklist_lock);
56306+ } else {
56307+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56308+ read_lock(&tasklist_lock);
56309+ read_lock(&grsec_exec_file_lock);
56310+ do_each_thread(tsk2, tsk) {
56311+ if (likely(tsk != task)) {
56312+ // if this thread has the same subject as the one that triggered
56313+ // RES_CRASH and it's the same binary, kill it
56314+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56315+ gr_fake_force_sig(SIGKILL, tsk);
56316+ }
56317+ } while_each_thread(tsk2, tsk);
56318+ read_unlock(&grsec_exec_file_lock);
56319+ read_unlock(&tasklist_lock);
56320+ }
56321+ rcu_read_unlock();
56322+ }
56323+
56324+ return;
56325+}
56326+
56327+int
56328+gr_check_crash_exec(const struct file *filp)
56329+{
56330+ struct acl_subject_label *curr;
56331+
56332+ if (unlikely(!gr_acl_is_enabled()))
56333+ return 0;
56334+
56335+ read_lock(&gr_inode_lock);
56336+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56337+ __get_dev(filp->f_path.dentry),
56338+ current->role);
56339+ read_unlock(&gr_inode_lock);
56340+
56341+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56342+ (!curr->crashes && !curr->expires))
56343+ return 0;
56344+
56345+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56346+ time_after(curr->expires, get_seconds()))
56347+ return 1;
56348+ else if (time_before_eq(curr->expires, get_seconds())) {
56349+ curr->crashes = 0;
56350+ curr->expires = 0;
56351+ }
56352+
56353+ return 0;
56354+}
56355+
56356+void
56357+gr_handle_alertkill(struct task_struct *task)
56358+{
56359+ struct acl_subject_label *curracl;
56360+ __u32 curr_ip;
56361+ struct task_struct *p, *p2;
56362+
56363+ if (unlikely(!gr_acl_is_enabled()))
56364+ return;
56365+
56366+ curracl = task->acl;
56367+ curr_ip = task->signal->curr_ip;
56368+
56369+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56370+ read_lock(&tasklist_lock);
56371+ do_each_thread(p2, p) {
56372+ if (p->signal->curr_ip == curr_ip)
56373+ gr_fake_force_sig(SIGKILL, p);
56374+ } while_each_thread(p2, p);
56375+ read_unlock(&tasklist_lock);
56376+ } else if (curracl->mode & GR_KILLPROC)
56377+ gr_fake_force_sig(SIGKILL, task);
56378+
56379+ return;
56380+}
56381diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56382new file mode 100644
56383index 0000000..9d83a69
56384--- /dev/null
56385+++ b/grsecurity/gracl_shm.c
56386@@ -0,0 +1,40 @@
56387+#include <linux/kernel.h>
56388+#include <linux/mm.h>
56389+#include <linux/sched.h>
56390+#include <linux/file.h>
56391+#include <linux/ipc.h>
56392+#include <linux/gracl.h>
56393+#include <linux/grsecurity.h>
56394+#include <linux/grinternal.h>
56395+
56396+int
56397+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56398+ const time_t shm_createtime, const uid_t cuid, const int shmid)
56399+{
56400+ struct task_struct *task;
56401+
56402+ if (!gr_acl_is_enabled())
56403+ return 1;
56404+
56405+ rcu_read_lock();
56406+ read_lock(&tasklist_lock);
56407+
56408+ task = find_task_by_vpid(shm_cprid);
56409+
56410+ if (unlikely(!task))
56411+ task = find_task_by_vpid(shm_lapid);
56412+
56413+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56414+ (task->pid == shm_lapid)) &&
56415+ (task->acl->mode & GR_PROTSHM) &&
56416+ (task->acl != current->acl))) {
56417+ read_unlock(&tasklist_lock);
56418+ rcu_read_unlock();
56419+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56420+ return 0;
56421+ }
56422+ read_unlock(&tasklist_lock);
56423+ rcu_read_unlock();
56424+
56425+ return 1;
56426+}
56427diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56428new file mode 100644
56429index 0000000..bc0be01
56430--- /dev/null
56431+++ b/grsecurity/grsec_chdir.c
56432@@ -0,0 +1,19 @@
56433+#include <linux/kernel.h>
56434+#include <linux/sched.h>
56435+#include <linux/fs.h>
56436+#include <linux/file.h>
56437+#include <linux/grsecurity.h>
56438+#include <linux/grinternal.h>
56439+
56440+void
56441+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56442+{
56443+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56444+ if ((grsec_enable_chdir && grsec_enable_group &&
56445+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56446+ !grsec_enable_group)) {
56447+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56448+ }
56449+#endif
56450+ return;
56451+}
56452diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
56453new file mode 100644
56454index 0000000..9807ee2
56455--- /dev/null
56456+++ b/grsecurity/grsec_chroot.c
56457@@ -0,0 +1,368 @@
56458+#include <linux/kernel.h>
56459+#include <linux/module.h>
56460+#include <linux/sched.h>
56461+#include <linux/file.h>
56462+#include <linux/fs.h>
56463+#include <linux/mount.h>
56464+#include <linux/types.h>
56465+#include "../fs/mount.h"
56466+#include <linux/grsecurity.h>
56467+#include <linux/grinternal.h>
56468+
56469+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
56470+{
56471+#ifdef CONFIG_GRKERNSEC
56472+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
56473+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
56474+ task->gr_is_chrooted = 1;
56475+ else
56476+ task->gr_is_chrooted = 0;
56477+
56478+ task->gr_chroot_dentry = path->dentry;
56479+#endif
56480+ return;
56481+}
56482+
56483+void gr_clear_chroot_entries(struct task_struct *task)
56484+{
56485+#ifdef CONFIG_GRKERNSEC
56486+ task->gr_is_chrooted = 0;
56487+ task->gr_chroot_dentry = NULL;
56488+#endif
56489+ return;
56490+}
56491+
56492+int
56493+gr_handle_chroot_unix(const pid_t pid)
56494+{
56495+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56496+ struct task_struct *p;
56497+
56498+ if (unlikely(!grsec_enable_chroot_unix))
56499+ return 1;
56500+
56501+ if (likely(!proc_is_chrooted(current)))
56502+ return 1;
56503+
56504+ rcu_read_lock();
56505+ read_lock(&tasklist_lock);
56506+ p = find_task_by_vpid_unrestricted(pid);
56507+ if (unlikely(p && !have_same_root(current, p))) {
56508+ read_unlock(&tasklist_lock);
56509+ rcu_read_unlock();
56510+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
56511+ return 0;
56512+ }
56513+ read_unlock(&tasklist_lock);
56514+ rcu_read_unlock();
56515+#endif
56516+ return 1;
56517+}
56518+
56519+int
56520+gr_handle_chroot_nice(void)
56521+{
56522+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56523+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
56524+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
56525+ return -EPERM;
56526+ }
56527+#endif
56528+ return 0;
56529+}
56530+
56531+int
56532+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
56533+{
56534+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56535+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
56536+ && proc_is_chrooted(current)) {
56537+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
56538+ return -EACCES;
56539+ }
56540+#endif
56541+ return 0;
56542+}
56543+
56544+int
56545+gr_handle_chroot_rawio(const struct inode *inode)
56546+{
56547+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56548+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56549+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
56550+ return 1;
56551+#endif
56552+ return 0;
56553+}
56554+
56555+int
56556+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
56557+{
56558+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56559+ struct task_struct *p;
56560+ int ret = 0;
56561+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
56562+ return ret;
56563+
56564+ read_lock(&tasklist_lock);
56565+ do_each_pid_task(pid, type, p) {
56566+ if (!have_same_root(current, p)) {
56567+ ret = 1;
56568+ goto out;
56569+ }
56570+ } while_each_pid_task(pid, type, p);
56571+out:
56572+ read_unlock(&tasklist_lock);
56573+ return ret;
56574+#endif
56575+ return 0;
56576+}
56577+
56578+int
56579+gr_pid_is_chrooted(struct task_struct *p)
56580+{
56581+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56582+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
56583+ return 0;
56584+
56585+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
56586+ !have_same_root(current, p)) {
56587+ return 1;
56588+ }
56589+#endif
56590+ return 0;
56591+}
56592+
56593+EXPORT_SYMBOL(gr_pid_is_chrooted);
56594+
56595+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
56596+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
56597+{
56598+ struct path path, currentroot;
56599+ int ret = 0;
56600+
56601+ path.dentry = (struct dentry *)u_dentry;
56602+ path.mnt = (struct vfsmount *)u_mnt;
56603+ get_fs_root(current->fs, &currentroot);
56604+ if (path_is_under(&path, &currentroot))
56605+ ret = 1;
56606+ path_put(&currentroot);
56607+
56608+ return ret;
56609+}
56610+#endif
56611+
56612+int
56613+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
56614+{
56615+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56616+ if (!grsec_enable_chroot_fchdir)
56617+ return 1;
56618+
56619+ if (!proc_is_chrooted(current))
56620+ return 1;
56621+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
56622+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
56623+ return 0;
56624+ }
56625+#endif
56626+ return 1;
56627+}
56628+
56629+int
56630+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56631+ const time_t shm_createtime)
56632+{
56633+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56634+ struct task_struct *p;
56635+ time_t starttime;
56636+
56637+ if (unlikely(!grsec_enable_chroot_shmat))
56638+ return 1;
56639+
56640+ if (likely(!proc_is_chrooted(current)))
56641+ return 1;
56642+
56643+ rcu_read_lock();
56644+ read_lock(&tasklist_lock);
56645+
56646+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
56647+ starttime = p->start_time.tv_sec;
56648+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
56649+ if (have_same_root(current, p)) {
56650+ goto allow;
56651+ } else {
56652+ read_unlock(&tasklist_lock);
56653+ rcu_read_unlock();
56654+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56655+ return 0;
56656+ }
56657+ }
56658+ /* creator exited, pid reuse, fall through to next check */
56659+ }
56660+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
56661+ if (unlikely(!have_same_root(current, p))) {
56662+ read_unlock(&tasklist_lock);
56663+ rcu_read_unlock();
56664+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56665+ return 0;
56666+ }
56667+ }
56668+
56669+allow:
56670+ read_unlock(&tasklist_lock);
56671+ rcu_read_unlock();
56672+#endif
56673+ return 1;
56674+}
56675+
56676+void
56677+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
56678+{
56679+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56680+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
56681+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
56682+#endif
56683+ return;
56684+}
56685+
56686+int
56687+gr_handle_chroot_mknod(const struct dentry *dentry,
56688+ const struct vfsmount *mnt, const int mode)
56689+{
56690+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56691+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
56692+ proc_is_chrooted(current)) {
56693+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
56694+ return -EPERM;
56695+ }
56696+#endif
56697+ return 0;
56698+}
56699+
56700+int
56701+gr_handle_chroot_mount(const struct dentry *dentry,
56702+ const struct vfsmount *mnt, const char *dev_name)
56703+{
56704+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56705+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
56706+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
56707+ return -EPERM;
56708+ }
56709+#endif
56710+ return 0;
56711+}
56712+
56713+int
56714+gr_handle_chroot_pivot(void)
56715+{
56716+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56717+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
56718+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
56719+ return -EPERM;
56720+ }
56721+#endif
56722+ return 0;
56723+}
56724+
56725+int
56726+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
56727+{
56728+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56729+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
56730+ !gr_is_outside_chroot(dentry, mnt)) {
56731+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
56732+ return -EPERM;
56733+ }
56734+#endif
56735+ return 0;
56736+}
56737+
56738+extern const char *captab_log[];
56739+extern int captab_log_entries;
56740+
56741+int
56742+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56743+{
56744+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56745+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56746+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56747+ if (cap_raised(chroot_caps, cap)) {
56748+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
56749+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
56750+ }
56751+ return 0;
56752+ }
56753+ }
56754+#endif
56755+ return 1;
56756+}
56757+
56758+int
56759+gr_chroot_is_capable(const int cap)
56760+{
56761+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56762+ return gr_task_chroot_is_capable(current, current_cred(), cap);
56763+#endif
56764+ return 1;
56765+}
56766+
56767+int
56768+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
56769+{
56770+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56771+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56772+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56773+ if (cap_raised(chroot_caps, cap)) {
56774+ return 0;
56775+ }
56776+ }
56777+#endif
56778+ return 1;
56779+}
56780+
56781+int
56782+gr_chroot_is_capable_nolog(const int cap)
56783+{
56784+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56785+ return gr_task_chroot_is_capable_nolog(current, cap);
56786+#endif
56787+ return 1;
56788+}
56789+
56790+int
56791+gr_handle_chroot_sysctl(const int op)
56792+{
56793+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
56794+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
56795+ proc_is_chrooted(current))
56796+ return -EACCES;
56797+#endif
56798+ return 0;
56799+}
56800+
56801+void
56802+gr_handle_chroot_chdir(struct path *path)
56803+{
56804+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
56805+ if (grsec_enable_chroot_chdir)
56806+ set_fs_pwd(current->fs, path);
56807+#endif
56808+ return;
56809+}
56810+
56811+int
56812+gr_handle_chroot_chmod(const struct dentry *dentry,
56813+ const struct vfsmount *mnt, const int mode)
56814+{
56815+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
56816+ /* allow chmod +s on directories, but not files */
56817+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
56818+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
56819+ proc_is_chrooted(current)) {
56820+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
56821+ return -EPERM;
56822+ }
56823+#endif
56824+ return 0;
56825+}
56826diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
56827new file mode 100644
56828index 0000000..213ad8b
56829--- /dev/null
56830+++ b/grsecurity/grsec_disabled.c
56831@@ -0,0 +1,437 @@
56832+#include <linux/kernel.h>
56833+#include <linux/module.h>
56834+#include <linux/sched.h>
56835+#include <linux/file.h>
56836+#include <linux/fs.h>
56837+#include <linux/kdev_t.h>
56838+#include <linux/net.h>
56839+#include <linux/in.h>
56840+#include <linux/ip.h>
56841+#include <linux/skbuff.h>
56842+#include <linux/sysctl.h>
56843+
56844+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56845+void
56846+pax_set_initial_flags(struct linux_binprm *bprm)
56847+{
56848+ return;
56849+}
56850+#endif
56851+
56852+#ifdef CONFIG_SYSCTL
56853+__u32
56854+gr_handle_sysctl(const struct ctl_table * table, const int op)
56855+{
56856+ return 0;
56857+}
56858+#endif
56859+
56860+#ifdef CONFIG_TASKSTATS
56861+int gr_is_taskstats_denied(int pid)
56862+{
56863+ return 0;
56864+}
56865+#endif
56866+
56867+int
56868+gr_acl_is_enabled(void)
56869+{
56870+ return 0;
56871+}
56872+
56873+void
56874+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56875+{
56876+ return;
56877+}
56878+
56879+int
56880+gr_handle_rawio(const struct inode *inode)
56881+{
56882+ return 0;
56883+}
56884+
56885+void
56886+gr_acl_handle_psacct(struct task_struct *task, const long code)
56887+{
56888+ return;
56889+}
56890+
56891+int
56892+gr_handle_ptrace(struct task_struct *task, const long request)
56893+{
56894+ return 0;
56895+}
56896+
56897+int
56898+gr_handle_proc_ptrace(struct task_struct *task)
56899+{
56900+ return 0;
56901+}
56902+
56903+void
56904+gr_learn_resource(const struct task_struct *task,
56905+ const int res, const unsigned long wanted, const int gt)
56906+{
56907+ return;
56908+}
56909+
56910+int
56911+gr_set_acls(const int type)
56912+{
56913+ return 0;
56914+}
56915+
56916+int
56917+gr_check_hidden_task(const struct task_struct *tsk)
56918+{
56919+ return 0;
56920+}
56921+
56922+int
56923+gr_check_protected_task(const struct task_struct *task)
56924+{
56925+ return 0;
56926+}
56927+
56928+int
56929+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
56930+{
56931+ return 0;
56932+}
56933+
56934+void
56935+gr_copy_label(struct task_struct *tsk)
56936+{
56937+ return;
56938+}
56939+
56940+void
56941+gr_set_pax_flags(struct task_struct *task)
56942+{
56943+ return;
56944+}
56945+
56946+int
56947+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
56948+ const int unsafe_share)
56949+{
56950+ return 0;
56951+}
56952+
56953+void
56954+gr_handle_delete(const ino_t ino, const dev_t dev)
56955+{
56956+ return;
56957+}
56958+
56959+void
56960+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
56961+{
56962+ return;
56963+}
56964+
56965+void
56966+gr_handle_crash(struct task_struct *task, const int sig)
56967+{
56968+ return;
56969+}
56970+
56971+int
56972+gr_check_crash_exec(const struct file *filp)
56973+{
56974+ return 0;
56975+}
56976+
56977+int
56978+gr_check_crash_uid(const uid_t uid)
56979+{
56980+ return 0;
56981+}
56982+
56983+void
56984+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
56985+ struct dentry *old_dentry,
56986+ struct dentry *new_dentry,
56987+ struct vfsmount *mnt, const __u8 replace)
56988+{
56989+ return;
56990+}
56991+
56992+int
56993+gr_search_socket(const int family, const int type, const int protocol)
56994+{
56995+ return 1;
56996+}
56997+
56998+int
56999+gr_search_connectbind(const int mode, const struct socket *sock,
57000+ const struct sockaddr_in *addr)
57001+{
57002+ return 0;
57003+}
57004+
57005+void
57006+gr_handle_alertkill(struct task_struct *task)
57007+{
57008+ return;
57009+}
57010+
57011+__u32
57012+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57013+{
57014+ return 1;
57015+}
57016+
57017+__u32
57018+gr_acl_handle_hidden_file(const struct dentry * dentry,
57019+ const struct vfsmount * mnt)
57020+{
57021+ return 1;
57022+}
57023+
57024+__u32
57025+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57026+ int acc_mode)
57027+{
57028+ return 1;
57029+}
57030+
57031+__u32
57032+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57033+{
57034+ return 1;
57035+}
57036+
57037+__u32
57038+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57039+{
57040+ return 1;
57041+}
57042+
57043+int
57044+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57045+ unsigned int *vm_flags)
57046+{
57047+ return 1;
57048+}
57049+
57050+__u32
57051+gr_acl_handle_truncate(const struct dentry * dentry,
57052+ const struct vfsmount * mnt)
57053+{
57054+ return 1;
57055+}
57056+
57057+__u32
57058+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57059+{
57060+ return 1;
57061+}
57062+
57063+__u32
57064+gr_acl_handle_access(const struct dentry * dentry,
57065+ const struct vfsmount * mnt, const int fmode)
57066+{
57067+ return 1;
57068+}
57069+
57070+__u32
57071+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57072+ umode_t *mode)
57073+{
57074+ return 1;
57075+}
57076+
57077+__u32
57078+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57079+{
57080+ return 1;
57081+}
57082+
57083+__u32
57084+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57085+{
57086+ return 1;
57087+}
57088+
57089+void
57090+grsecurity_init(void)
57091+{
57092+ return;
57093+}
57094+
57095+umode_t gr_acl_umask(void)
57096+{
57097+ return 0;
57098+}
57099+
57100+__u32
57101+gr_acl_handle_mknod(const struct dentry * new_dentry,
57102+ const struct dentry * parent_dentry,
57103+ const struct vfsmount * parent_mnt,
57104+ const int mode)
57105+{
57106+ return 1;
57107+}
57108+
57109+__u32
57110+gr_acl_handle_mkdir(const struct dentry * new_dentry,
57111+ const struct dentry * parent_dentry,
57112+ const struct vfsmount * parent_mnt)
57113+{
57114+ return 1;
57115+}
57116+
57117+__u32
57118+gr_acl_handle_symlink(const struct dentry * new_dentry,
57119+ const struct dentry * parent_dentry,
57120+ const struct vfsmount * parent_mnt, const char *from)
57121+{
57122+ return 1;
57123+}
57124+
57125+__u32
57126+gr_acl_handle_link(const struct dentry * new_dentry,
57127+ const struct dentry * parent_dentry,
57128+ const struct vfsmount * parent_mnt,
57129+ const struct dentry * old_dentry,
57130+ const struct vfsmount * old_mnt, const char *to)
57131+{
57132+ return 1;
57133+}
57134+
57135+int
57136+gr_acl_handle_rename(const struct dentry *new_dentry,
57137+ const struct dentry *parent_dentry,
57138+ const struct vfsmount *parent_mnt,
57139+ const struct dentry *old_dentry,
57140+ const struct inode *old_parent_inode,
57141+ const struct vfsmount *old_mnt, const char *newname)
57142+{
57143+ return 0;
57144+}
57145+
57146+int
57147+gr_acl_handle_filldir(const struct file *file, const char *name,
57148+ const int namelen, const ino_t ino)
57149+{
57150+ return 1;
57151+}
57152+
57153+int
57154+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57155+ const time_t shm_createtime, const uid_t cuid, const int shmid)
57156+{
57157+ return 1;
57158+}
57159+
57160+int
57161+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57162+{
57163+ return 0;
57164+}
57165+
57166+int
57167+gr_search_accept(const struct socket *sock)
57168+{
57169+ return 0;
57170+}
57171+
57172+int
57173+gr_search_listen(const struct socket *sock)
57174+{
57175+ return 0;
57176+}
57177+
57178+int
57179+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57180+{
57181+ return 0;
57182+}
57183+
57184+__u32
57185+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57186+{
57187+ return 1;
57188+}
57189+
57190+__u32
57191+gr_acl_handle_creat(const struct dentry * dentry,
57192+ const struct dentry * p_dentry,
57193+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57194+ const int imode)
57195+{
57196+ return 1;
57197+}
57198+
57199+void
57200+gr_acl_handle_exit(void)
57201+{
57202+ return;
57203+}
57204+
57205+int
57206+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57207+{
57208+ return 1;
57209+}
57210+
57211+void
57212+gr_set_role_label(const uid_t uid, const gid_t gid)
57213+{
57214+ return;
57215+}
57216+
57217+int
57218+gr_acl_handle_procpidmem(const struct task_struct *task)
57219+{
57220+ return 0;
57221+}
57222+
57223+int
57224+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57225+{
57226+ return 0;
57227+}
57228+
57229+int
57230+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57231+{
57232+ return 0;
57233+}
57234+
57235+void
57236+gr_set_kernel_label(struct task_struct *task)
57237+{
57238+ return;
57239+}
57240+
57241+int
57242+gr_check_user_change(int real, int effective, int fs)
57243+{
57244+ return 0;
57245+}
57246+
57247+int
57248+gr_check_group_change(int real, int effective, int fs)
57249+{
57250+ return 0;
57251+}
57252+
57253+int gr_acl_enable_at_secure(void)
57254+{
57255+ return 0;
57256+}
57257+
57258+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57259+{
57260+ return dentry->d_inode->i_sb->s_dev;
57261+}
57262+
57263+EXPORT_SYMBOL(gr_learn_resource);
57264+EXPORT_SYMBOL(gr_set_kernel_label);
57265+#ifdef CONFIG_SECURITY
57266+EXPORT_SYMBOL(gr_check_user_change);
57267+EXPORT_SYMBOL(gr_check_group_change);
57268+#endif
57269diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57270new file mode 100644
57271index 0000000..abfa971
57272--- /dev/null
57273+++ b/grsecurity/grsec_exec.c
57274@@ -0,0 +1,174 @@
57275+#include <linux/kernel.h>
57276+#include <linux/sched.h>
57277+#include <linux/file.h>
57278+#include <linux/binfmts.h>
57279+#include <linux/fs.h>
57280+#include <linux/types.h>
57281+#include <linux/grdefs.h>
57282+#include <linux/grsecurity.h>
57283+#include <linux/grinternal.h>
57284+#include <linux/capability.h>
57285+#include <linux/module.h>
57286+
57287+#include <asm/uaccess.h>
57288+
57289+#ifdef CONFIG_GRKERNSEC_EXECLOG
57290+static char gr_exec_arg_buf[132];
57291+static DEFINE_MUTEX(gr_exec_arg_mutex);
57292+#endif
57293+
57294+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57295+
57296+void
57297+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57298+{
57299+#ifdef CONFIG_GRKERNSEC_EXECLOG
57300+ char *grarg = gr_exec_arg_buf;
57301+ unsigned int i, x, execlen = 0;
57302+ char c;
57303+
57304+ if (!((grsec_enable_execlog && grsec_enable_group &&
57305+ in_group_p(grsec_audit_gid))
57306+ || (grsec_enable_execlog && !grsec_enable_group)))
57307+ return;
57308+
57309+ mutex_lock(&gr_exec_arg_mutex);
57310+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
57311+
57312+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
57313+ const char __user *p;
57314+ unsigned int len;
57315+
57316+ p = get_user_arg_ptr(argv, i);
57317+ if (IS_ERR(p))
57318+ goto log;
57319+
57320+ len = strnlen_user(p, 128 - execlen);
57321+ if (len > 128 - execlen)
57322+ len = 128 - execlen;
57323+ else if (len > 0)
57324+ len--;
57325+ if (copy_from_user(grarg + execlen, p, len))
57326+ goto log;
57327+
57328+ /* rewrite unprintable characters */
57329+ for (x = 0; x < len; x++) {
57330+ c = *(grarg + execlen + x);
57331+ if (c < 32 || c > 126)
57332+ *(grarg + execlen + x) = ' ';
57333+ }
57334+
57335+ execlen += len;
57336+ *(grarg + execlen) = ' ';
57337+ *(grarg + execlen + 1) = '\0';
57338+ execlen++;
57339+ }
57340+
57341+ log:
57342+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57343+ bprm->file->f_path.mnt, grarg);
57344+ mutex_unlock(&gr_exec_arg_mutex);
57345+#endif
57346+ return;
57347+}
57348+
57349+#ifdef CONFIG_GRKERNSEC
57350+extern int gr_acl_is_capable(const int cap);
57351+extern int gr_acl_is_capable_nolog(const int cap);
57352+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57353+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
57354+extern int gr_chroot_is_capable(const int cap);
57355+extern int gr_chroot_is_capable_nolog(const int cap);
57356+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57357+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
57358+#endif
57359+
57360+const char *captab_log[] = {
57361+ "CAP_CHOWN",
57362+ "CAP_DAC_OVERRIDE",
57363+ "CAP_DAC_READ_SEARCH",
57364+ "CAP_FOWNER",
57365+ "CAP_FSETID",
57366+ "CAP_KILL",
57367+ "CAP_SETGID",
57368+ "CAP_SETUID",
57369+ "CAP_SETPCAP",
57370+ "CAP_LINUX_IMMUTABLE",
57371+ "CAP_NET_BIND_SERVICE",
57372+ "CAP_NET_BROADCAST",
57373+ "CAP_NET_ADMIN",
57374+ "CAP_NET_RAW",
57375+ "CAP_IPC_LOCK",
57376+ "CAP_IPC_OWNER",
57377+ "CAP_SYS_MODULE",
57378+ "CAP_SYS_RAWIO",
57379+ "CAP_SYS_CHROOT",
57380+ "CAP_SYS_PTRACE",
57381+ "CAP_SYS_PACCT",
57382+ "CAP_SYS_ADMIN",
57383+ "CAP_SYS_BOOT",
57384+ "CAP_SYS_NICE",
57385+ "CAP_SYS_RESOURCE",
57386+ "CAP_SYS_TIME",
57387+ "CAP_SYS_TTY_CONFIG",
57388+ "CAP_MKNOD",
57389+ "CAP_LEASE",
57390+ "CAP_AUDIT_WRITE",
57391+ "CAP_AUDIT_CONTROL",
57392+ "CAP_SETFCAP",
57393+ "CAP_MAC_OVERRIDE",
57394+ "CAP_MAC_ADMIN",
57395+ "CAP_SYSLOG",
57396+ "CAP_WAKE_ALARM"
57397+};
57398+
57399+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57400+
57401+int gr_is_capable(const int cap)
57402+{
57403+#ifdef CONFIG_GRKERNSEC
57404+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57405+ return 1;
57406+ return 0;
57407+#else
57408+ return 1;
57409+#endif
57410+}
57411+
57412+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57413+{
57414+#ifdef CONFIG_GRKERNSEC
57415+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
57416+ return 1;
57417+ return 0;
57418+#else
57419+ return 1;
57420+#endif
57421+}
57422+
57423+int gr_is_capable_nolog(const int cap)
57424+{
57425+#ifdef CONFIG_GRKERNSEC
57426+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57427+ return 1;
57428+ return 0;
57429+#else
57430+ return 1;
57431+#endif
57432+}
57433+
57434+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
57435+{
57436+#ifdef CONFIG_GRKERNSEC
57437+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
57438+ return 1;
57439+ return 0;
57440+#else
57441+ return 1;
57442+#endif
57443+}
57444+
57445+EXPORT_SYMBOL(gr_is_capable);
57446+EXPORT_SYMBOL(gr_is_capable_nolog);
57447+EXPORT_SYMBOL(gr_task_is_capable);
57448+EXPORT_SYMBOL(gr_task_is_capable_nolog);
57449diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
57450new file mode 100644
57451index 0000000..d3ee748
57452--- /dev/null
57453+++ b/grsecurity/grsec_fifo.c
57454@@ -0,0 +1,24 @@
57455+#include <linux/kernel.h>
57456+#include <linux/sched.h>
57457+#include <linux/fs.h>
57458+#include <linux/file.h>
57459+#include <linux/grinternal.h>
57460+
57461+int
57462+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57463+ const struct dentry *dir, const int flag, const int acc_mode)
57464+{
57465+#ifdef CONFIG_GRKERNSEC_FIFO
57466+ const struct cred *cred = current_cred();
57467+
57468+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57469+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57470+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57471+ (cred->fsuid != dentry->d_inode->i_uid)) {
57472+ if (!inode_permission(dentry->d_inode, acc_mode))
57473+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57474+ return -EACCES;
57475+ }
57476+#endif
57477+ return 0;
57478+}
57479diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
57480new file mode 100644
57481index 0000000..8ca18bf
57482--- /dev/null
57483+++ b/grsecurity/grsec_fork.c
57484@@ -0,0 +1,23 @@
57485+#include <linux/kernel.h>
57486+#include <linux/sched.h>
57487+#include <linux/grsecurity.h>
57488+#include <linux/grinternal.h>
57489+#include <linux/errno.h>
57490+
57491+void
57492+gr_log_forkfail(const int retval)
57493+{
57494+#ifdef CONFIG_GRKERNSEC_FORKFAIL
57495+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57496+ switch (retval) {
57497+ case -EAGAIN:
57498+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57499+ break;
57500+ case -ENOMEM:
57501+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
57502+ break;
57503+ }
57504+ }
57505+#endif
57506+ return;
57507+}
57508diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
57509new file mode 100644
57510index 0000000..01ddde4
57511--- /dev/null
57512+++ b/grsecurity/grsec_init.c
57513@@ -0,0 +1,277 @@
57514+#include <linux/kernel.h>
57515+#include <linux/sched.h>
57516+#include <linux/mm.h>
57517+#include <linux/gracl.h>
57518+#include <linux/slab.h>
57519+#include <linux/vmalloc.h>
57520+#include <linux/percpu.h>
57521+#include <linux/module.h>
57522+
57523+int grsec_enable_ptrace_readexec;
57524+int grsec_enable_setxid;
57525+int grsec_enable_brute;
57526+int grsec_enable_link;
57527+int grsec_enable_dmesg;
57528+int grsec_enable_harden_ptrace;
57529+int grsec_enable_fifo;
57530+int grsec_enable_execlog;
57531+int grsec_enable_signal;
57532+int grsec_enable_forkfail;
57533+int grsec_enable_audit_ptrace;
57534+int grsec_enable_time;
57535+int grsec_enable_audit_textrel;
57536+int grsec_enable_group;
57537+int grsec_audit_gid;
57538+int grsec_enable_chdir;
57539+int grsec_enable_mount;
57540+int grsec_enable_rofs;
57541+int grsec_enable_chroot_findtask;
57542+int grsec_enable_chroot_mount;
57543+int grsec_enable_chroot_shmat;
57544+int grsec_enable_chroot_fchdir;
57545+int grsec_enable_chroot_double;
57546+int grsec_enable_chroot_pivot;
57547+int grsec_enable_chroot_chdir;
57548+int grsec_enable_chroot_chmod;
57549+int grsec_enable_chroot_mknod;
57550+int grsec_enable_chroot_nice;
57551+int grsec_enable_chroot_execlog;
57552+int grsec_enable_chroot_caps;
57553+int grsec_enable_chroot_sysctl;
57554+int grsec_enable_chroot_unix;
57555+int grsec_enable_tpe;
57556+int grsec_tpe_gid;
57557+int grsec_enable_blackhole;
57558+#ifdef CONFIG_IPV6_MODULE
57559+EXPORT_SYMBOL(grsec_enable_blackhole);
57560+#endif
57561+int grsec_lastack_retries;
57562+int grsec_enable_tpe_all;
57563+int grsec_enable_tpe_invert;
57564+int grsec_enable_socket_all;
57565+int grsec_socket_all_gid;
57566+int grsec_enable_socket_client;
57567+int grsec_socket_client_gid;
57568+int grsec_enable_socket_server;
57569+int grsec_socket_server_gid;
57570+int grsec_resource_logging;
57571+int grsec_disable_privio;
57572+int grsec_enable_log_rwxmaps;
57573+int grsec_lock;
57574+
57575+DEFINE_SPINLOCK(grsec_alert_lock);
57576+unsigned long grsec_alert_wtime = 0;
57577+unsigned long grsec_alert_fyet = 0;
57578+
57579+DEFINE_SPINLOCK(grsec_audit_lock);
57580+
57581+DEFINE_RWLOCK(grsec_exec_file_lock);
57582+
57583+char *gr_shared_page[4];
57584+
57585+char *gr_alert_log_fmt;
57586+char *gr_audit_log_fmt;
57587+char *gr_alert_log_buf;
57588+char *gr_audit_log_buf;
57589+
57590+extern struct gr_arg *gr_usermode;
57591+extern unsigned char *gr_system_salt;
57592+extern unsigned char *gr_system_sum;
57593+
57594+void __init
57595+grsecurity_init(void)
57596+{
57597+ int j;
57598+ /* create the per-cpu shared pages */
57599+
57600+#ifdef CONFIG_X86
57601+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
57602+#endif
57603+
57604+ for (j = 0; j < 4; j++) {
57605+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
57606+ if (gr_shared_page[j] == NULL) {
57607+ panic("Unable to allocate grsecurity shared page");
57608+ return;
57609+ }
57610+ }
57611+
57612+ /* allocate log buffers */
57613+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
57614+ if (!gr_alert_log_fmt) {
57615+ panic("Unable to allocate grsecurity alert log format buffer");
57616+ return;
57617+ }
57618+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
57619+ if (!gr_audit_log_fmt) {
57620+ panic("Unable to allocate grsecurity audit log format buffer");
57621+ return;
57622+ }
57623+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57624+ if (!gr_alert_log_buf) {
57625+ panic("Unable to allocate grsecurity alert log buffer");
57626+ return;
57627+ }
57628+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57629+ if (!gr_audit_log_buf) {
57630+ panic("Unable to allocate grsecurity audit log buffer");
57631+ return;
57632+ }
57633+
57634+ /* allocate memory for authentication structure */
57635+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
57636+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
57637+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
57638+
57639+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
57640+ panic("Unable to allocate grsecurity authentication structure");
57641+ return;
57642+ }
57643+
57644+
57645+#ifdef CONFIG_GRKERNSEC_IO
57646+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
57647+ grsec_disable_privio = 1;
57648+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57649+ grsec_disable_privio = 1;
57650+#else
57651+ grsec_disable_privio = 0;
57652+#endif
57653+#endif
57654+
57655+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57656+ /* for backward compatibility, tpe_invert always defaults to on if
57657+ enabled in the kernel
57658+ */
57659+ grsec_enable_tpe_invert = 1;
57660+#endif
57661+
57662+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57663+#ifndef CONFIG_GRKERNSEC_SYSCTL
57664+ grsec_lock = 1;
57665+#endif
57666+
57667+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57668+ grsec_enable_audit_textrel = 1;
57669+#endif
57670+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57671+ grsec_enable_log_rwxmaps = 1;
57672+#endif
57673+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
57674+ grsec_enable_group = 1;
57675+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
57676+#endif
57677+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57678+ grsec_enable_ptrace_readexec = 1;
57679+#endif
57680+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57681+ grsec_enable_chdir = 1;
57682+#endif
57683+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57684+ grsec_enable_harden_ptrace = 1;
57685+#endif
57686+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57687+ grsec_enable_mount = 1;
57688+#endif
57689+#ifdef CONFIG_GRKERNSEC_LINK
57690+ grsec_enable_link = 1;
57691+#endif
57692+#ifdef CONFIG_GRKERNSEC_BRUTE
57693+ grsec_enable_brute = 1;
57694+#endif
57695+#ifdef CONFIG_GRKERNSEC_DMESG
57696+ grsec_enable_dmesg = 1;
57697+#endif
57698+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
57699+ grsec_enable_blackhole = 1;
57700+ grsec_lastack_retries = 4;
57701+#endif
57702+#ifdef CONFIG_GRKERNSEC_FIFO
57703+ grsec_enable_fifo = 1;
57704+#endif
57705+#ifdef CONFIG_GRKERNSEC_EXECLOG
57706+ grsec_enable_execlog = 1;
57707+#endif
57708+#ifdef CONFIG_GRKERNSEC_SETXID
57709+ grsec_enable_setxid = 1;
57710+#endif
57711+#ifdef CONFIG_GRKERNSEC_SIGNAL
57712+ grsec_enable_signal = 1;
57713+#endif
57714+#ifdef CONFIG_GRKERNSEC_FORKFAIL
57715+ grsec_enable_forkfail = 1;
57716+#endif
57717+#ifdef CONFIG_GRKERNSEC_TIME
57718+ grsec_enable_time = 1;
57719+#endif
57720+#ifdef CONFIG_GRKERNSEC_RESLOG
57721+ grsec_resource_logging = 1;
57722+#endif
57723+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57724+ grsec_enable_chroot_findtask = 1;
57725+#endif
57726+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57727+ grsec_enable_chroot_unix = 1;
57728+#endif
57729+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57730+ grsec_enable_chroot_mount = 1;
57731+#endif
57732+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57733+ grsec_enable_chroot_fchdir = 1;
57734+#endif
57735+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57736+ grsec_enable_chroot_shmat = 1;
57737+#endif
57738+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57739+ grsec_enable_audit_ptrace = 1;
57740+#endif
57741+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57742+ grsec_enable_chroot_double = 1;
57743+#endif
57744+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57745+ grsec_enable_chroot_pivot = 1;
57746+#endif
57747+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57748+ grsec_enable_chroot_chdir = 1;
57749+#endif
57750+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57751+ grsec_enable_chroot_chmod = 1;
57752+#endif
57753+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57754+ grsec_enable_chroot_mknod = 1;
57755+#endif
57756+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57757+ grsec_enable_chroot_nice = 1;
57758+#endif
57759+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57760+ grsec_enable_chroot_execlog = 1;
57761+#endif
57762+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57763+ grsec_enable_chroot_caps = 1;
57764+#endif
57765+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57766+ grsec_enable_chroot_sysctl = 1;
57767+#endif
57768+#ifdef CONFIG_GRKERNSEC_TPE
57769+ grsec_enable_tpe = 1;
57770+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
57771+#ifdef CONFIG_GRKERNSEC_TPE_ALL
57772+ grsec_enable_tpe_all = 1;
57773+#endif
57774+#endif
57775+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
57776+ grsec_enable_socket_all = 1;
57777+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
57778+#endif
57779+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
57780+ grsec_enable_socket_client = 1;
57781+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
57782+#endif
57783+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
57784+ grsec_enable_socket_server = 1;
57785+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
57786+#endif
57787+#endif
57788+
57789+ return;
57790+}
57791diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
57792new file mode 100644
57793index 0000000..3efe141
57794--- /dev/null
57795+++ b/grsecurity/grsec_link.c
57796@@ -0,0 +1,43 @@
57797+#include <linux/kernel.h>
57798+#include <linux/sched.h>
57799+#include <linux/fs.h>
57800+#include <linux/file.h>
57801+#include <linux/grinternal.h>
57802+
57803+int
57804+gr_handle_follow_link(const struct inode *parent,
57805+ const struct inode *inode,
57806+ const struct dentry *dentry, const struct vfsmount *mnt)
57807+{
57808+#ifdef CONFIG_GRKERNSEC_LINK
57809+ const struct cred *cred = current_cred();
57810+
57811+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
57812+ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
57813+ (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
57814+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
57815+ return -EACCES;
57816+ }
57817+#endif
57818+ return 0;
57819+}
57820+
57821+int
57822+gr_handle_hardlink(const struct dentry *dentry,
57823+ const struct vfsmount *mnt,
57824+ struct inode *inode, const int mode, const char *to)
57825+{
57826+#ifdef CONFIG_GRKERNSEC_LINK
57827+ const struct cred *cred = current_cred();
57828+
57829+ if (grsec_enable_link && cred->fsuid != inode->i_uid &&
57830+ (!S_ISREG(mode) || (mode & S_ISUID) ||
57831+ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
57832+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
57833+ !capable(CAP_FOWNER) && cred->uid) {
57834+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
57835+ return -EPERM;
57836+ }
57837+#endif
57838+ return 0;
57839+}
57840diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
57841new file mode 100644
57842index 0000000..a45d2e9
57843--- /dev/null
57844+++ b/grsecurity/grsec_log.c
57845@@ -0,0 +1,322 @@
57846+#include <linux/kernel.h>
57847+#include <linux/sched.h>
57848+#include <linux/file.h>
57849+#include <linux/tty.h>
57850+#include <linux/fs.h>
57851+#include <linux/grinternal.h>
57852+
57853+#ifdef CONFIG_TREE_PREEMPT_RCU
57854+#define DISABLE_PREEMPT() preempt_disable()
57855+#define ENABLE_PREEMPT() preempt_enable()
57856+#else
57857+#define DISABLE_PREEMPT()
57858+#define ENABLE_PREEMPT()
57859+#endif
57860+
57861+#define BEGIN_LOCKS(x) \
57862+ DISABLE_PREEMPT(); \
57863+ rcu_read_lock(); \
57864+ read_lock(&tasklist_lock); \
57865+ read_lock(&grsec_exec_file_lock); \
57866+ if (x != GR_DO_AUDIT) \
57867+ spin_lock(&grsec_alert_lock); \
57868+ else \
57869+ spin_lock(&grsec_audit_lock)
57870+
57871+#define END_LOCKS(x) \
57872+ if (x != GR_DO_AUDIT) \
57873+ spin_unlock(&grsec_alert_lock); \
57874+ else \
57875+ spin_unlock(&grsec_audit_lock); \
57876+ read_unlock(&grsec_exec_file_lock); \
57877+ read_unlock(&tasklist_lock); \
57878+ rcu_read_unlock(); \
57879+ ENABLE_PREEMPT(); \
57880+ if (x == GR_DONT_AUDIT) \
57881+ gr_handle_alertkill(current)
57882+
57883+enum {
57884+ FLOODING,
57885+ NO_FLOODING
57886+};
57887+
57888+extern char *gr_alert_log_fmt;
57889+extern char *gr_audit_log_fmt;
57890+extern char *gr_alert_log_buf;
57891+extern char *gr_audit_log_buf;
57892+
57893+static int gr_log_start(int audit)
57894+{
57895+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
57896+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
57897+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57898+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
57899+ unsigned long curr_secs = get_seconds();
57900+
57901+ if (audit == GR_DO_AUDIT)
57902+ goto set_fmt;
57903+
57904+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
57905+ grsec_alert_wtime = curr_secs;
57906+ grsec_alert_fyet = 0;
57907+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
57908+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
57909+ grsec_alert_fyet++;
57910+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
57911+ grsec_alert_wtime = curr_secs;
57912+ grsec_alert_fyet++;
57913+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
57914+ return FLOODING;
57915+ }
57916+ else return FLOODING;
57917+
57918+set_fmt:
57919+#endif
57920+ memset(buf, 0, PAGE_SIZE);
57921+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
57922+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
57923+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57924+ } else if (current->signal->curr_ip) {
57925+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
57926+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
57927+ } else if (gr_acl_is_enabled()) {
57928+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
57929+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57930+ } else {
57931+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
57932+ strcpy(buf, fmt);
57933+ }
57934+
57935+ return NO_FLOODING;
57936+}
57937+
57938+static void gr_log_middle(int audit, const char *msg, va_list ap)
57939+ __attribute__ ((format (printf, 2, 0)));
57940+
57941+static void gr_log_middle(int audit, const char *msg, va_list ap)
57942+{
57943+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57944+ unsigned int len = strlen(buf);
57945+
57946+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
57947+
57948+ return;
57949+}
57950+
57951+static void gr_log_middle_varargs(int audit, const char *msg, ...)
57952+ __attribute__ ((format (printf, 2, 3)));
57953+
57954+static void gr_log_middle_varargs(int audit, const char *msg, ...)
57955+{
57956+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57957+ unsigned int len = strlen(buf);
57958+ va_list ap;
57959+
57960+ va_start(ap, msg);
57961+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
57962+ va_end(ap);
57963+
57964+ return;
57965+}
57966+
57967+static void gr_log_end(int audit, int append_default)
57968+{
57969+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57970+
57971+ if (append_default) {
57972+ unsigned int len = strlen(buf);
57973+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
57974+ }
57975+
57976+ printk("%s\n", buf);
57977+
57978+ return;
57979+}
57980+
57981+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
57982+{
57983+ int logtype;
57984+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
57985+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
57986+ void *voidptr = NULL;
57987+ int num1 = 0, num2 = 0;
57988+ unsigned long ulong1 = 0, ulong2 = 0;
57989+ struct dentry *dentry = NULL;
57990+ struct vfsmount *mnt = NULL;
57991+ struct file *file = NULL;
57992+ struct task_struct *task = NULL;
57993+ const struct cred *cred, *pcred;
57994+ va_list ap;
57995+
57996+ BEGIN_LOCKS(audit);
57997+ logtype = gr_log_start(audit);
57998+ if (logtype == FLOODING) {
57999+ END_LOCKS(audit);
58000+ return;
58001+ }
58002+ va_start(ap, argtypes);
58003+ switch (argtypes) {
58004+ case GR_TTYSNIFF:
58005+ task = va_arg(ap, struct task_struct *);
58006+ 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);
58007+ break;
58008+ case GR_SYSCTL_HIDDEN:
58009+ str1 = va_arg(ap, char *);
58010+ gr_log_middle_varargs(audit, msg, result, str1);
58011+ break;
58012+ case GR_RBAC:
58013+ dentry = va_arg(ap, struct dentry *);
58014+ mnt = va_arg(ap, struct vfsmount *);
58015+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58016+ break;
58017+ case GR_RBAC_STR:
58018+ dentry = va_arg(ap, struct dentry *);
58019+ mnt = va_arg(ap, struct vfsmount *);
58020+ str1 = va_arg(ap, char *);
58021+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58022+ break;
58023+ case GR_STR_RBAC:
58024+ str1 = va_arg(ap, char *);
58025+ dentry = va_arg(ap, struct dentry *);
58026+ mnt = va_arg(ap, struct vfsmount *);
58027+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58028+ break;
58029+ case GR_RBAC_MODE2:
58030+ dentry = va_arg(ap, struct dentry *);
58031+ mnt = va_arg(ap, struct vfsmount *);
58032+ str1 = va_arg(ap, char *);
58033+ str2 = va_arg(ap, char *);
58034+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58035+ break;
58036+ case GR_RBAC_MODE3:
58037+ dentry = va_arg(ap, struct dentry *);
58038+ mnt = va_arg(ap, struct vfsmount *);
58039+ str1 = va_arg(ap, char *);
58040+ str2 = va_arg(ap, char *);
58041+ str3 = va_arg(ap, char *);
58042+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58043+ break;
58044+ case GR_FILENAME:
58045+ dentry = va_arg(ap, struct dentry *);
58046+ mnt = va_arg(ap, struct vfsmount *);
58047+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58048+ break;
58049+ case GR_STR_FILENAME:
58050+ str1 = va_arg(ap, char *);
58051+ dentry = va_arg(ap, struct dentry *);
58052+ mnt = va_arg(ap, struct vfsmount *);
58053+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58054+ break;
58055+ case GR_FILENAME_STR:
58056+ dentry = va_arg(ap, struct dentry *);
58057+ mnt = va_arg(ap, struct vfsmount *);
58058+ str1 = va_arg(ap, char *);
58059+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58060+ break;
58061+ case GR_FILENAME_TWO_INT:
58062+ dentry = va_arg(ap, struct dentry *);
58063+ mnt = va_arg(ap, struct vfsmount *);
58064+ num1 = va_arg(ap, int);
58065+ num2 = va_arg(ap, int);
58066+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58067+ break;
58068+ case GR_FILENAME_TWO_INT_STR:
58069+ dentry = va_arg(ap, struct dentry *);
58070+ mnt = va_arg(ap, struct vfsmount *);
58071+ num1 = va_arg(ap, int);
58072+ num2 = va_arg(ap, int);
58073+ str1 = va_arg(ap, char *);
58074+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58075+ break;
58076+ case GR_TEXTREL:
58077+ file = va_arg(ap, struct file *);
58078+ ulong1 = va_arg(ap, unsigned long);
58079+ ulong2 = va_arg(ap, unsigned long);
58080+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58081+ break;
58082+ case GR_PTRACE:
58083+ task = va_arg(ap, struct task_struct *);
58084+ 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);
58085+ break;
58086+ case GR_RESOURCE:
58087+ task = va_arg(ap, struct task_struct *);
58088+ cred = __task_cred(task);
58089+ pcred = __task_cred(task->real_parent);
58090+ ulong1 = va_arg(ap, unsigned long);
58091+ str1 = va_arg(ap, char *);
58092+ ulong2 = va_arg(ap, unsigned long);
58093+ 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);
58094+ break;
58095+ case GR_CAP:
58096+ task = va_arg(ap, struct task_struct *);
58097+ cred = __task_cred(task);
58098+ pcred = __task_cred(task->real_parent);
58099+ str1 = va_arg(ap, char *);
58100+ 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);
58101+ break;
58102+ case GR_SIG:
58103+ str1 = va_arg(ap, char *);
58104+ voidptr = va_arg(ap, void *);
58105+ gr_log_middle_varargs(audit, msg, str1, voidptr);
58106+ break;
58107+ case GR_SIG2:
58108+ task = va_arg(ap, struct task_struct *);
58109+ cred = __task_cred(task);
58110+ pcred = __task_cred(task->real_parent);
58111+ num1 = va_arg(ap, int);
58112+ 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);
58113+ break;
58114+ case GR_CRASH1:
58115+ task = va_arg(ap, struct task_struct *);
58116+ cred = __task_cred(task);
58117+ pcred = __task_cred(task->real_parent);
58118+ ulong1 = va_arg(ap, unsigned long);
58119+ 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);
58120+ break;
58121+ case GR_CRASH2:
58122+ task = va_arg(ap, struct task_struct *);
58123+ cred = __task_cred(task);
58124+ pcred = __task_cred(task->real_parent);
58125+ ulong1 = va_arg(ap, unsigned long);
58126+ 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);
58127+ break;
58128+ case GR_RWXMAP:
58129+ file = va_arg(ap, struct file *);
58130+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58131+ break;
58132+ case GR_PSACCT:
58133+ {
58134+ unsigned int wday, cday;
58135+ __u8 whr, chr;
58136+ __u8 wmin, cmin;
58137+ __u8 wsec, csec;
58138+ char cur_tty[64] = { 0 };
58139+ char parent_tty[64] = { 0 };
58140+
58141+ task = va_arg(ap, struct task_struct *);
58142+ wday = va_arg(ap, unsigned int);
58143+ cday = va_arg(ap, unsigned int);
58144+ whr = va_arg(ap, int);
58145+ chr = va_arg(ap, int);
58146+ wmin = va_arg(ap, int);
58147+ cmin = va_arg(ap, int);
58148+ wsec = va_arg(ap, int);
58149+ csec = va_arg(ap, int);
58150+ ulong1 = va_arg(ap, unsigned long);
58151+ cred = __task_cred(task);
58152+ pcred = __task_cred(task->real_parent);
58153+
58154+ 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);
58155+ }
58156+ break;
58157+ default:
58158+ gr_log_middle(audit, msg, ap);
58159+ }
58160+ va_end(ap);
58161+ // these don't need DEFAULTSECARGS printed on the end
58162+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58163+ gr_log_end(audit, 0);
58164+ else
58165+ gr_log_end(audit, 1);
58166+ END_LOCKS(audit);
58167+}
58168diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58169new file mode 100644
58170index 0000000..f536303
58171--- /dev/null
58172+++ b/grsecurity/grsec_mem.c
58173@@ -0,0 +1,40 @@
58174+#include <linux/kernel.h>
58175+#include <linux/sched.h>
58176+#include <linux/mm.h>
58177+#include <linux/mman.h>
58178+#include <linux/grinternal.h>
58179+
58180+void
58181+gr_handle_ioperm(void)
58182+{
58183+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58184+ return;
58185+}
58186+
58187+void
58188+gr_handle_iopl(void)
58189+{
58190+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58191+ return;
58192+}
58193+
58194+void
58195+gr_handle_mem_readwrite(u64 from, u64 to)
58196+{
58197+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58198+ return;
58199+}
58200+
58201+void
58202+gr_handle_vm86(void)
58203+{
58204+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58205+ return;
58206+}
58207+
58208+void
58209+gr_log_badprocpid(const char *entry)
58210+{
58211+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
58212+ return;
58213+}
58214diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58215new file mode 100644
58216index 0000000..2131422
58217--- /dev/null
58218+++ b/grsecurity/grsec_mount.c
58219@@ -0,0 +1,62 @@
58220+#include <linux/kernel.h>
58221+#include <linux/sched.h>
58222+#include <linux/mount.h>
58223+#include <linux/grsecurity.h>
58224+#include <linux/grinternal.h>
58225+
58226+void
58227+gr_log_remount(const char *devname, const int retval)
58228+{
58229+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58230+ if (grsec_enable_mount && (retval >= 0))
58231+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58232+#endif
58233+ return;
58234+}
58235+
58236+void
58237+gr_log_unmount(const char *devname, const int retval)
58238+{
58239+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58240+ if (grsec_enable_mount && (retval >= 0))
58241+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58242+#endif
58243+ return;
58244+}
58245+
58246+void
58247+gr_log_mount(const char *from, const char *to, const int retval)
58248+{
58249+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58250+ if (grsec_enable_mount && (retval >= 0))
58251+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58252+#endif
58253+ return;
58254+}
58255+
58256+int
58257+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58258+{
58259+#ifdef CONFIG_GRKERNSEC_ROFS
58260+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58261+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58262+ return -EPERM;
58263+ } else
58264+ return 0;
58265+#endif
58266+ return 0;
58267+}
58268+
58269+int
58270+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58271+{
58272+#ifdef CONFIG_GRKERNSEC_ROFS
58273+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58274+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58275+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58276+ return -EPERM;
58277+ } else
58278+ return 0;
58279+#endif
58280+ return 0;
58281+}
58282diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58283new file mode 100644
58284index 0000000..a3b12a0
58285--- /dev/null
58286+++ b/grsecurity/grsec_pax.c
58287@@ -0,0 +1,36 @@
58288+#include <linux/kernel.h>
58289+#include <linux/sched.h>
58290+#include <linux/mm.h>
58291+#include <linux/file.h>
58292+#include <linux/grinternal.h>
58293+#include <linux/grsecurity.h>
58294+
58295+void
58296+gr_log_textrel(struct vm_area_struct * vma)
58297+{
58298+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58299+ if (grsec_enable_audit_textrel)
58300+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58301+#endif
58302+ return;
58303+}
58304+
58305+void
58306+gr_log_rwxmmap(struct file *file)
58307+{
58308+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58309+ if (grsec_enable_log_rwxmaps)
58310+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58311+#endif
58312+ return;
58313+}
58314+
58315+void
58316+gr_log_rwxmprotect(struct file *file)
58317+{
58318+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58319+ if (grsec_enable_log_rwxmaps)
58320+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58321+#endif
58322+ return;
58323+}
58324diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58325new file mode 100644
58326index 0000000..f7f29aa
58327--- /dev/null
58328+++ b/grsecurity/grsec_ptrace.c
58329@@ -0,0 +1,30 @@
58330+#include <linux/kernel.h>
58331+#include <linux/sched.h>
58332+#include <linux/grinternal.h>
58333+#include <linux/security.h>
58334+
58335+void
58336+gr_audit_ptrace(struct task_struct *task)
58337+{
58338+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58339+ if (grsec_enable_audit_ptrace)
58340+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58341+#endif
58342+ return;
58343+}
58344+
58345+int
58346+gr_ptrace_readexec(struct file *file, int unsafe_flags)
58347+{
58348+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58349+ const struct dentry *dentry = file->f_path.dentry;
58350+ const struct vfsmount *mnt = file->f_path.mnt;
58351+
58352+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
58353+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
58354+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
58355+ return -EACCES;
58356+ }
58357+#endif
58358+ return 0;
58359+}
58360diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58361new file mode 100644
58362index 0000000..7a5b2de
58363--- /dev/null
58364+++ b/grsecurity/grsec_sig.c
58365@@ -0,0 +1,207 @@
58366+#include <linux/kernel.h>
58367+#include <linux/sched.h>
58368+#include <linux/delay.h>
58369+#include <linux/grsecurity.h>
58370+#include <linux/grinternal.h>
58371+#include <linux/hardirq.h>
58372+
58373+char *signames[] = {
58374+ [SIGSEGV] = "Segmentation fault",
58375+ [SIGILL] = "Illegal instruction",
58376+ [SIGABRT] = "Abort",
58377+ [SIGBUS] = "Invalid alignment/Bus error"
58378+};
58379+
58380+void
58381+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58382+{
58383+#ifdef CONFIG_GRKERNSEC_SIGNAL
58384+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58385+ (sig == SIGABRT) || (sig == SIGBUS))) {
58386+ if (t->pid == current->pid) {
58387+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58388+ } else {
58389+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58390+ }
58391+ }
58392+#endif
58393+ return;
58394+}
58395+
58396+int
58397+gr_handle_signal(const struct task_struct *p, const int sig)
58398+{
58399+#ifdef CONFIG_GRKERNSEC
58400+ /* ignore the 0 signal for protected task checks */
58401+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58402+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58403+ return -EPERM;
58404+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58405+ return -EPERM;
58406+ }
58407+#endif
58408+ return 0;
58409+}
58410+
58411+#ifdef CONFIG_GRKERNSEC
58412+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58413+
58414+int gr_fake_force_sig(int sig, struct task_struct *t)
58415+{
58416+ unsigned long int flags;
58417+ int ret, blocked, ignored;
58418+ struct k_sigaction *action;
58419+
58420+ spin_lock_irqsave(&t->sighand->siglock, flags);
58421+ action = &t->sighand->action[sig-1];
58422+ ignored = action->sa.sa_handler == SIG_IGN;
58423+ blocked = sigismember(&t->blocked, sig);
58424+ if (blocked || ignored) {
58425+ action->sa.sa_handler = SIG_DFL;
58426+ if (blocked) {
58427+ sigdelset(&t->blocked, sig);
58428+ recalc_sigpending_and_wake(t);
58429+ }
58430+ }
58431+ if (action->sa.sa_handler == SIG_DFL)
58432+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
58433+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58434+
58435+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
58436+
58437+ return ret;
58438+}
58439+#endif
58440+
58441+#ifdef CONFIG_GRKERNSEC_BRUTE
58442+#define GR_USER_BAN_TIME (15 * 60)
58443+
58444+static int __get_dumpable(unsigned long mm_flags)
58445+{
58446+ int ret;
58447+
58448+ ret = mm_flags & MMF_DUMPABLE_MASK;
58449+ return (ret >= 2) ? 2 : ret;
58450+}
58451+#endif
58452+
58453+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58454+{
58455+#ifdef CONFIG_GRKERNSEC_BRUTE
58456+ uid_t uid = 0;
58457+
58458+ if (!grsec_enable_brute)
58459+ return;
58460+
58461+ rcu_read_lock();
58462+ read_lock(&tasklist_lock);
58463+ read_lock(&grsec_exec_file_lock);
58464+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58465+ p->real_parent->brute = 1;
58466+ else {
58467+ const struct cred *cred = __task_cred(p), *cred2;
58468+ struct task_struct *tsk, *tsk2;
58469+
58470+ if (!__get_dumpable(mm_flags) && cred->uid) {
58471+ struct user_struct *user;
58472+
58473+ uid = cred->uid;
58474+
58475+ /* this is put upon execution past expiration */
58476+ user = find_user(uid);
58477+ if (user == NULL)
58478+ goto unlock;
58479+ user->banned = 1;
58480+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58481+ if (user->ban_expires == ~0UL)
58482+ user->ban_expires--;
58483+
58484+ do_each_thread(tsk2, tsk) {
58485+ cred2 = __task_cred(tsk);
58486+ if (tsk != p && cred2->uid == uid)
58487+ gr_fake_force_sig(SIGKILL, tsk);
58488+ } while_each_thread(tsk2, tsk);
58489+ }
58490+ }
58491+unlock:
58492+ read_unlock(&grsec_exec_file_lock);
58493+ read_unlock(&tasklist_lock);
58494+ rcu_read_unlock();
58495+
58496+ if (uid)
58497+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
58498+
58499+#endif
58500+ return;
58501+}
58502+
58503+void gr_handle_brute_check(void)
58504+{
58505+#ifdef CONFIG_GRKERNSEC_BRUTE
58506+ if (current->brute)
58507+ msleep(30 * 1000);
58508+#endif
58509+ return;
58510+}
58511+
58512+void gr_handle_kernel_exploit(void)
58513+{
58514+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58515+ const struct cred *cred;
58516+ struct task_struct *tsk, *tsk2;
58517+ struct user_struct *user;
58518+ uid_t uid;
58519+
58520+ if (in_irq() || in_serving_softirq() || in_nmi())
58521+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58522+
58523+ uid = current_uid();
58524+
58525+ if (uid == 0)
58526+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
58527+ else {
58528+ /* kill all the processes of this user, hold a reference
58529+ to their creds struct, and prevent them from creating
58530+ another process until system reset
58531+ */
58532+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
58533+ /* we intentionally leak this ref */
58534+ user = get_uid(current->cred->user);
58535+ if (user) {
58536+ user->banned = 1;
58537+ user->ban_expires = ~0UL;
58538+ }
58539+
58540+ read_lock(&tasklist_lock);
58541+ do_each_thread(tsk2, tsk) {
58542+ cred = __task_cred(tsk);
58543+ if (cred->uid == uid)
58544+ gr_fake_force_sig(SIGKILL, tsk);
58545+ } while_each_thread(tsk2, tsk);
58546+ read_unlock(&tasklist_lock);
58547+ }
58548+#endif
58549+}
58550+
58551+int __gr_process_user_ban(struct user_struct *user)
58552+{
58553+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58554+ if (unlikely(user->banned)) {
58555+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58556+ user->banned = 0;
58557+ user->ban_expires = 0;
58558+ free_uid(user);
58559+ } else
58560+ return -EPERM;
58561+ }
58562+#endif
58563+ return 0;
58564+}
58565+
58566+int gr_process_user_ban(void)
58567+{
58568+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58569+ return __gr_process_user_ban(current->cred->user);
58570+#endif
58571+ return 0;
58572+}
58573diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
58574new file mode 100644
58575index 0000000..4030d57
58576--- /dev/null
58577+++ b/grsecurity/grsec_sock.c
58578@@ -0,0 +1,244 @@
58579+#include <linux/kernel.h>
58580+#include <linux/module.h>
58581+#include <linux/sched.h>
58582+#include <linux/file.h>
58583+#include <linux/net.h>
58584+#include <linux/in.h>
58585+#include <linux/ip.h>
58586+#include <net/sock.h>
58587+#include <net/inet_sock.h>
58588+#include <linux/grsecurity.h>
58589+#include <linux/grinternal.h>
58590+#include <linux/gracl.h>
58591+
58592+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
58593+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
58594+
58595+EXPORT_SYMBOL(gr_search_udp_recvmsg);
58596+EXPORT_SYMBOL(gr_search_udp_sendmsg);
58597+
58598+#ifdef CONFIG_UNIX_MODULE
58599+EXPORT_SYMBOL(gr_acl_handle_unix);
58600+EXPORT_SYMBOL(gr_acl_handle_mknod);
58601+EXPORT_SYMBOL(gr_handle_chroot_unix);
58602+EXPORT_SYMBOL(gr_handle_create);
58603+#endif
58604+
58605+#ifdef CONFIG_GRKERNSEC
58606+#define gr_conn_table_size 32749
58607+struct conn_table_entry {
58608+ struct conn_table_entry *next;
58609+ struct signal_struct *sig;
58610+};
58611+
58612+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
58613+DEFINE_SPINLOCK(gr_conn_table_lock);
58614+
58615+extern const char * gr_socktype_to_name(unsigned char type);
58616+extern const char * gr_proto_to_name(unsigned char proto);
58617+extern const char * gr_sockfamily_to_name(unsigned char family);
58618+
58619+static __inline__ int
58620+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
58621+{
58622+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
58623+}
58624+
58625+static __inline__ int
58626+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
58627+ __u16 sport, __u16 dport)
58628+{
58629+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
58630+ sig->gr_sport == sport && sig->gr_dport == dport))
58631+ return 1;
58632+ else
58633+ return 0;
58634+}
58635+
58636+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
58637+{
58638+ struct conn_table_entry **match;
58639+ unsigned int index;
58640+
58641+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58642+ sig->gr_sport, sig->gr_dport,
58643+ gr_conn_table_size);
58644+
58645+ newent->sig = sig;
58646+
58647+ match = &gr_conn_table[index];
58648+ newent->next = *match;
58649+ *match = newent;
58650+
58651+ return;
58652+}
58653+
58654+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
58655+{
58656+ struct conn_table_entry *match, *last = NULL;
58657+ unsigned int index;
58658+
58659+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58660+ sig->gr_sport, sig->gr_dport,
58661+ gr_conn_table_size);
58662+
58663+ match = gr_conn_table[index];
58664+ while (match && !conn_match(match->sig,
58665+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
58666+ sig->gr_dport)) {
58667+ last = match;
58668+ match = match->next;
58669+ }
58670+
58671+ if (match) {
58672+ if (last)
58673+ last->next = match->next;
58674+ else
58675+ gr_conn_table[index] = NULL;
58676+ kfree(match);
58677+ }
58678+
58679+ return;
58680+}
58681+
58682+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
58683+ __u16 sport, __u16 dport)
58684+{
58685+ struct conn_table_entry *match;
58686+ unsigned int index;
58687+
58688+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
58689+
58690+ match = gr_conn_table[index];
58691+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
58692+ match = match->next;
58693+
58694+ if (match)
58695+ return match->sig;
58696+ else
58697+ return NULL;
58698+}
58699+
58700+#endif
58701+
58702+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
58703+{
58704+#ifdef CONFIG_GRKERNSEC
58705+ struct signal_struct *sig = task->signal;
58706+ struct conn_table_entry *newent;
58707+
58708+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
58709+ if (newent == NULL)
58710+ return;
58711+ /* no bh lock needed since we are called with bh disabled */
58712+ spin_lock(&gr_conn_table_lock);
58713+ gr_del_task_from_ip_table_nolock(sig);
58714+ sig->gr_saddr = inet->inet_rcv_saddr;
58715+ sig->gr_daddr = inet->inet_daddr;
58716+ sig->gr_sport = inet->inet_sport;
58717+ sig->gr_dport = inet->inet_dport;
58718+ gr_add_to_task_ip_table_nolock(sig, newent);
58719+ spin_unlock(&gr_conn_table_lock);
58720+#endif
58721+ return;
58722+}
58723+
58724+void gr_del_task_from_ip_table(struct task_struct *task)
58725+{
58726+#ifdef CONFIG_GRKERNSEC
58727+ spin_lock_bh(&gr_conn_table_lock);
58728+ gr_del_task_from_ip_table_nolock(task->signal);
58729+ spin_unlock_bh(&gr_conn_table_lock);
58730+#endif
58731+ return;
58732+}
58733+
58734+void
58735+gr_attach_curr_ip(const struct sock *sk)
58736+{
58737+#ifdef CONFIG_GRKERNSEC
58738+ struct signal_struct *p, *set;
58739+ const struct inet_sock *inet = inet_sk(sk);
58740+
58741+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
58742+ return;
58743+
58744+ set = current->signal;
58745+
58746+ spin_lock_bh(&gr_conn_table_lock);
58747+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
58748+ inet->inet_dport, inet->inet_sport);
58749+ if (unlikely(p != NULL)) {
58750+ set->curr_ip = p->curr_ip;
58751+ set->used_accept = 1;
58752+ gr_del_task_from_ip_table_nolock(p);
58753+ spin_unlock_bh(&gr_conn_table_lock);
58754+ return;
58755+ }
58756+ spin_unlock_bh(&gr_conn_table_lock);
58757+
58758+ set->curr_ip = inet->inet_daddr;
58759+ set->used_accept = 1;
58760+#endif
58761+ return;
58762+}
58763+
58764+int
58765+gr_handle_sock_all(const int family, const int type, const int protocol)
58766+{
58767+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58768+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
58769+ (family != AF_UNIX)) {
58770+ if (family == AF_INET)
58771+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
58772+ else
58773+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
58774+ return -EACCES;
58775+ }
58776+#endif
58777+ return 0;
58778+}
58779+
58780+int
58781+gr_handle_sock_server(const struct sockaddr *sck)
58782+{
58783+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58784+ if (grsec_enable_socket_server &&
58785+ in_group_p(grsec_socket_server_gid) &&
58786+ sck && (sck->sa_family != AF_UNIX) &&
58787+ (sck->sa_family != AF_LOCAL)) {
58788+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58789+ return -EACCES;
58790+ }
58791+#endif
58792+ return 0;
58793+}
58794+
58795+int
58796+gr_handle_sock_server_other(const struct sock *sck)
58797+{
58798+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58799+ if (grsec_enable_socket_server &&
58800+ in_group_p(grsec_socket_server_gid) &&
58801+ sck && (sck->sk_family != AF_UNIX) &&
58802+ (sck->sk_family != AF_LOCAL)) {
58803+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58804+ return -EACCES;
58805+ }
58806+#endif
58807+ return 0;
58808+}
58809+
58810+int
58811+gr_handle_sock_client(const struct sockaddr *sck)
58812+{
58813+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58814+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
58815+ sck && (sck->sa_family != AF_UNIX) &&
58816+ (sck->sa_family != AF_LOCAL)) {
58817+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
58818+ return -EACCES;
58819+ }
58820+#endif
58821+ return 0;
58822+}
58823diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
58824new file mode 100644
58825index 0000000..a1aedd7
58826--- /dev/null
58827+++ b/grsecurity/grsec_sysctl.c
58828@@ -0,0 +1,451 @@
58829+#include <linux/kernel.h>
58830+#include <linux/sched.h>
58831+#include <linux/sysctl.h>
58832+#include <linux/grsecurity.h>
58833+#include <linux/grinternal.h>
58834+
58835+int
58836+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
58837+{
58838+#ifdef CONFIG_GRKERNSEC_SYSCTL
58839+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
58840+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
58841+ return -EACCES;
58842+ }
58843+#endif
58844+ return 0;
58845+}
58846+
58847+#ifdef CONFIG_GRKERNSEC_ROFS
58848+static int __maybe_unused one = 1;
58849+#endif
58850+
58851+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
58852+struct ctl_table grsecurity_table[] = {
58853+#ifdef CONFIG_GRKERNSEC_SYSCTL
58854+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
58855+#ifdef CONFIG_GRKERNSEC_IO
58856+ {
58857+ .procname = "disable_priv_io",
58858+ .data = &grsec_disable_privio,
58859+ .maxlen = sizeof(int),
58860+ .mode = 0600,
58861+ .proc_handler = &proc_dointvec,
58862+ },
58863+#endif
58864+#endif
58865+#ifdef CONFIG_GRKERNSEC_LINK
58866+ {
58867+ .procname = "linking_restrictions",
58868+ .data = &grsec_enable_link,
58869+ .maxlen = sizeof(int),
58870+ .mode = 0600,
58871+ .proc_handler = &proc_dointvec,
58872+ },
58873+#endif
58874+#ifdef CONFIG_GRKERNSEC_BRUTE
58875+ {
58876+ .procname = "deter_bruteforce",
58877+ .data = &grsec_enable_brute,
58878+ .maxlen = sizeof(int),
58879+ .mode = 0600,
58880+ .proc_handler = &proc_dointvec,
58881+ },
58882+#endif
58883+#ifdef CONFIG_GRKERNSEC_FIFO
58884+ {
58885+ .procname = "fifo_restrictions",
58886+ .data = &grsec_enable_fifo,
58887+ .maxlen = sizeof(int),
58888+ .mode = 0600,
58889+ .proc_handler = &proc_dointvec,
58890+ },
58891+#endif
58892+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58893+ {
58894+ .procname = "ptrace_readexec",
58895+ .data = &grsec_enable_ptrace_readexec,
58896+ .maxlen = sizeof(int),
58897+ .mode = 0600,
58898+ .proc_handler = &proc_dointvec,
58899+ },
58900+#endif
58901+#ifdef CONFIG_GRKERNSEC_SETXID
58902+ {
58903+ .procname = "consistent_setxid",
58904+ .data = &grsec_enable_setxid,
58905+ .maxlen = sizeof(int),
58906+ .mode = 0600,
58907+ .proc_handler = &proc_dointvec,
58908+ },
58909+#endif
58910+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58911+ {
58912+ .procname = "ip_blackhole",
58913+ .data = &grsec_enable_blackhole,
58914+ .maxlen = sizeof(int),
58915+ .mode = 0600,
58916+ .proc_handler = &proc_dointvec,
58917+ },
58918+ {
58919+ .procname = "lastack_retries",
58920+ .data = &grsec_lastack_retries,
58921+ .maxlen = sizeof(int),
58922+ .mode = 0600,
58923+ .proc_handler = &proc_dointvec,
58924+ },
58925+#endif
58926+#ifdef CONFIG_GRKERNSEC_EXECLOG
58927+ {
58928+ .procname = "exec_logging",
58929+ .data = &grsec_enable_execlog,
58930+ .maxlen = sizeof(int),
58931+ .mode = 0600,
58932+ .proc_handler = &proc_dointvec,
58933+ },
58934+#endif
58935+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58936+ {
58937+ .procname = "rwxmap_logging",
58938+ .data = &grsec_enable_log_rwxmaps,
58939+ .maxlen = sizeof(int),
58940+ .mode = 0600,
58941+ .proc_handler = &proc_dointvec,
58942+ },
58943+#endif
58944+#ifdef CONFIG_GRKERNSEC_SIGNAL
58945+ {
58946+ .procname = "signal_logging",
58947+ .data = &grsec_enable_signal,
58948+ .maxlen = sizeof(int),
58949+ .mode = 0600,
58950+ .proc_handler = &proc_dointvec,
58951+ },
58952+#endif
58953+#ifdef CONFIG_GRKERNSEC_FORKFAIL
58954+ {
58955+ .procname = "forkfail_logging",
58956+ .data = &grsec_enable_forkfail,
58957+ .maxlen = sizeof(int),
58958+ .mode = 0600,
58959+ .proc_handler = &proc_dointvec,
58960+ },
58961+#endif
58962+#ifdef CONFIG_GRKERNSEC_TIME
58963+ {
58964+ .procname = "timechange_logging",
58965+ .data = &grsec_enable_time,
58966+ .maxlen = sizeof(int),
58967+ .mode = 0600,
58968+ .proc_handler = &proc_dointvec,
58969+ },
58970+#endif
58971+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58972+ {
58973+ .procname = "chroot_deny_shmat",
58974+ .data = &grsec_enable_chroot_shmat,
58975+ .maxlen = sizeof(int),
58976+ .mode = 0600,
58977+ .proc_handler = &proc_dointvec,
58978+ },
58979+#endif
58980+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58981+ {
58982+ .procname = "chroot_deny_unix",
58983+ .data = &grsec_enable_chroot_unix,
58984+ .maxlen = sizeof(int),
58985+ .mode = 0600,
58986+ .proc_handler = &proc_dointvec,
58987+ },
58988+#endif
58989+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58990+ {
58991+ .procname = "chroot_deny_mount",
58992+ .data = &grsec_enable_chroot_mount,
58993+ .maxlen = sizeof(int),
58994+ .mode = 0600,
58995+ .proc_handler = &proc_dointvec,
58996+ },
58997+#endif
58998+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58999+ {
59000+ .procname = "chroot_deny_fchdir",
59001+ .data = &grsec_enable_chroot_fchdir,
59002+ .maxlen = sizeof(int),
59003+ .mode = 0600,
59004+ .proc_handler = &proc_dointvec,
59005+ },
59006+#endif
59007+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59008+ {
59009+ .procname = "chroot_deny_chroot",
59010+ .data = &grsec_enable_chroot_double,
59011+ .maxlen = sizeof(int),
59012+ .mode = 0600,
59013+ .proc_handler = &proc_dointvec,
59014+ },
59015+#endif
59016+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59017+ {
59018+ .procname = "chroot_deny_pivot",
59019+ .data = &grsec_enable_chroot_pivot,
59020+ .maxlen = sizeof(int),
59021+ .mode = 0600,
59022+ .proc_handler = &proc_dointvec,
59023+ },
59024+#endif
59025+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59026+ {
59027+ .procname = "chroot_enforce_chdir",
59028+ .data = &grsec_enable_chroot_chdir,
59029+ .maxlen = sizeof(int),
59030+ .mode = 0600,
59031+ .proc_handler = &proc_dointvec,
59032+ },
59033+#endif
59034+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59035+ {
59036+ .procname = "chroot_deny_chmod",
59037+ .data = &grsec_enable_chroot_chmod,
59038+ .maxlen = sizeof(int),
59039+ .mode = 0600,
59040+ .proc_handler = &proc_dointvec,
59041+ },
59042+#endif
59043+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59044+ {
59045+ .procname = "chroot_deny_mknod",
59046+ .data = &grsec_enable_chroot_mknod,
59047+ .maxlen = sizeof(int),
59048+ .mode = 0600,
59049+ .proc_handler = &proc_dointvec,
59050+ },
59051+#endif
59052+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59053+ {
59054+ .procname = "chroot_restrict_nice",
59055+ .data = &grsec_enable_chroot_nice,
59056+ .maxlen = sizeof(int),
59057+ .mode = 0600,
59058+ .proc_handler = &proc_dointvec,
59059+ },
59060+#endif
59061+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59062+ {
59063+ .procname = "chroot_execlog",
59064+ .data = &grsec_enable_chroot_execlog,
59065+ .maxlen = sizeof(int),
59066+ .mode = 0600,
59067+ .proc_handler = &proc_dointvec,
59068+ },
59069+#endif
59070+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59071+ {
59072+ .procname = "chroot_caps",
59073+ .data = &grsec_enable_chroot_caps,
59074+ .maxlen = sizeof(int),
59075+ .mode = 0600,
59076+ .proc_handler = &proc_dointvec,
59077+ },
59078+#endif
59079+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59080+ {
59081+ .procname = "chroot_deny_sysctl",
59082+ .data = &grsec_enable_chroot_sysctl,
59083+ .maxlen = sizeof(int),
59084+ .mode = 0600,
59085+ .proc_handler = &proc_dointvec,
59086+ },
59087+#endif
59088+#ifdef CONFIG_GRKERNSEC_TPE
59089+ {
59090+ .procname = "tpe",
59091+ .data = &grsec_enable_tpe,
59092+ .maxlen = sizeof(int),
59093+ .mode = 0600,
59094+ .proc_handler = &proc_dointvec,
59095+ },
59096+ {
59097+ .procname = "tpe_gid",
59098+ .data = &grsec_tpe_gid,
59099+ .maxlen = sizeof(int),
59100+ .mode = 0600,
59101+ .proc_handler = &proc_dointvec,
59102+ },
59103+#endif
59104+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59105+ {
59106+ .procname = "tpe_invert",
59107+ .data = &grsec_enable_tpe_invert,
59108+ .maxlen = sizeof(int),
59109+ .mode = 0600,
59110+ .proc_handler = &proc_dointvec,
59111+ },
59112+#endif
59113+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59114+ {
59115+ .procname = "tpe_restrict_all",
59116+ .data = &grsec_enable_tpe_all,
59117+ .maxlen = sizeof(int),
59118+ .mode = 0600,
59119+ .proc_handler = &proc_dointvec,
59120+ },
59121+#endif
59122+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59123+ {
59124+ .procname = "socket_all",
59125+ .data = &grsec_enable_socket_all,
59126+ .maxlen = sizeof(int),
59127+ .mode = 0600,
59128+ .proc_handler = &proc_dointvec,
59129+ },
59130+ {
59131+ .procname = "socket_all_gid",
59132+ .data = &grsec_socket_all_gid,
59133+ .maxlen = sizeof(int),
59134+ .mode = 0600,
59135+ .proc_handler = &proc_dointvec,
59136+ },
59137+#endif
59138+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59139+ {
59140+ .procname = "socket_client",
59141+ .data = &grsec_enable_socket_client,
59142+ .maxlen = sizeof(int),
59143+ .mode = 0600,
59144+ .proc_handler = &proc_dointvec,
59145+ },
59146+ {
59147+ .procname = "socket_client_gid",
59148+ .data = &grsec_socket_client_gid,
59149+ .maxlen = sizeof(int),
59150+ .mode = 0600,
59151+ .proc_handler = &proc_dointvec,
59152+ },
59153+#endif
59154+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59155+ {
59156+ .procname = "socket_server",
59157+ .data = &grsec_enable_socket_server,
59158+ .maxlen = sizeof(int),
59159+ .mode = 0600,
59160+ .proc_handler = &proc_dointvec,
59161+ },
59162+ {
59163+ .procname = "socket_server_gid",
59164+ .data = &grsec_socket_server_gid,
59165+ .maxlen = sizeof(int),
59166+ .mode = 0600,
59167+ .proc_handler = &proc_dointvec,
59168+ },
59169+#endif
59170+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59171+ {
59172+ .procname = "audit_group",
59173+ .data = &grsec_enable_group,
59174+ .maxlen = sizeof(int),
59175+ .mode = 0600,
59176+ .proc_handler = &proc_dointvec,
59177+ },
59178+ {
59179+ .procname = "audit_gid",
59180+ .data = &grsec_audit_gid,
59181+ .maxlen = sizeof(int),
59182+ .mode = 0600,
59183+ .proc_handler = &proc_dointvec,
59184+ },
59185+#endif
59186+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59187+ {
59188+ .procname = "audit_chdir",
59189+ .data = &grsec_enable_chdir,
59190+ .maxlen = sizeof(int),
59191+ .mode = 0600,
59192+ .proc_handler = &proc_dointvec,
59193+ },
59194+#endif
59195+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59196+ {
59197+ .procname = "audit_mount",
59198+ .data = &grsec_enable_mount,
59199+ .maxlen = sizeof(int),
59200+ .mode = 0600,
59201+ .proc_handler = &proc_dointvec,
59202+ },
59203+#endif
59204+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59205+ {
59206+ .procname = "audit_textrel",
59207+ .data = &grsec_enable_audit_textrel,
59208+ .maxlen = sizeof(int),
59209+ .mode = 0600,
59210+ .proc_handler = &proc_dointvec,
59211+ },
59212+#endif
59213+#ifdef CONFIG_GRKERNSEC_DMESG
59214+ {
59215+ .procname = "dmesg",
59216+ .data = &grsec_enable_dmesg,
59217+ .maxlen = sizeof(int),
59218+ .mode = 0600,
59219+ .proc_handler = &proc_dointvec,
59220+ },
59221+#endif
59222+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59223+ {
59224+ .procname = "chroot_findtask",
59225+ .data = &grsec_enable_chroot_findtask,
59226+ .maxlen = sizeof(int),
59227+ .mode = 0600,
59228+ .proc_handler = &proc_dointvec,
59229+ },
59230+#endif
59231+#ifdef CONFIG_GRKERNSEC_RESLOG
59232+ {
59233+ .procname = "resource_logging",
59234+ .data = &grsec_resource_logging,
59235+ .maxlen = sizeof(int),
59236+ .mode = 0600,
59237+ .proc_handler = &proc_dointvec,
59238+ },
59239+#endif
59240+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59241+ {
59242+ .procname = "audit_ptrace",
59243+ .data = &grsec_enable_audit_ptrace,
59244+ .maxlen = sizeof(int),
59245+ .mode = 0600,
59246+ .proc_handler = &proc_dointvec,
59247+ },
59248+#endif
59249+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59250+ {
59251+ .procname = "harden_ptrace",
59252+ .data = &grsec_enable_harden_ptrace,
59253+ .maxlen = sizeof(int),
59254+ .mode = 0600,
59255+ .proc_handler = &proc_dointvec,
59256+ },
59257+#endif
59258+ {
59259+ .procname = "grsec_lock",
59260+ .data = &grsec_lock,
59261+ .maxlen = sizeof(int),
59262+ .mode = 0600,
59263+ .proc_handler = &proc_dointvec,
59264+ },
59265+#endif
59266+#ifdef CONFIG_GRKERNSEC_ROFS
59267+ {
59268+ .procname = "romount_protect",
59269+ .data = &grsec_enable_rofs,
59270+ .maxlen = sizeof(int),
59271+ .mode = 0600,
59272+ .proc_handler = &proc_dointvec_minmax,
59273+ .extra1 = &one,
59274+ .extra2 = &one,
59275+ },
59276+#endif
59277+ { }
59278+};
59279+#endif
59280diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59281new file mode 100644
59282index 0000000..0dc13c3
59283--- /dev/null
59284+++ b/grsecurity/grsec_time.c
59285@@ -0,0 +1,16 @@
59286+#include <linux/kernel.h>
59287+#include <linux/sched.h>
59288+#include <linux/grinternal.h>
59289+#include <linux/module.h>
59290+
59291+void
59292+gr_log_timechange(void)
59293+{
59294+#ifdef CONFIG_GRKERNSEC_TIME
59295+ if (grsec_enable_time)
59296+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59297+#endif
59298+ return;
59299+}
59300+
59301+EXPORT_SYMBOL(gr_log_timechange);
59302diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59303new file mode 100644
59304index 0000000..07e0dc0
59305--- /dev/null
59306+++ b/grsecurity/grsec_tpe.c
59307@@ -0,0 +1,73 @@
59308+#include <linux/kernel.h>
59309+#include <linux/sched.h>
59310+#include <linux/file.h>
59311+#include <linux/fs.h>
59312+#include <linux/grinternal.h>
59313+
59314+extern int gr_acl_tpe_check(void);
59315+
59316+int
59317+gr_tpe_allow(const struct file *file)
59318+{
59319+#ifdef CONFIG_GRKERNSEC
59320+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59321+ const struct cred *cred = current_cred();
59322+ char *msg = NULL;
59323+ char *msg2 = NULL;
59324+
59325+ // never restrict root
59326+ if (!cred->uid)
59327+ return 1;
59328+
59329+ if (grsec_enable_tpe) {
59330+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59331+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
59332+ msg = "not being in trusted group";
59333+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
59334+ msg = "being in untrusted group";
59335+#else
59336+ if (in_group_p(grsec_tpe_gid))
59337+ msg = "being in untrusted group";
59338+#endif
59339+ }
59340+ if (!msg && gr_acl_tpe_check())
59341+ msg = "being in untrusted role";
59342+
59343+ // not in any affected group/role
59344+ if (!msg)
59345+ goto next_check;
59346+
59347+ if (inode->i_uid)
59348+ msg2 = "file in non-root-owned directory";
59349+ else if (inode->i_mode & S_IWOTH)
59350+ msg2 = "file in world-writable directory";
59351+ else if (inode->i_mode & S_IWGRP)
59352+ msg2 = "file in group-writable directory";
59353+
59354+ if (msg && msg2) {
59355+ char fullmsg[70] = {0};
59356+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
59357+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
59358+ return 0;
59359+ }
59360+ msg = NULL;
59361+next_check:
59362+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59363+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
59364+ return 1;
59365+
59366+ if (inode->i_uid && (inode->i_uid != cred->uid))
59367+ msg = "directory not owned by user";
59368+ else if (inode->i_mode & S_IWOTH)
59369+ msg = "file in world-writable directory";
59370+ else if (inode->i_mode & S_IWGRP)
59371+ msg = "file in group-writable directory";
59372+
59373+ if (msg) {
59374+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
59375+ return 0;
59376+ }
59377+#endif
59378+#endif
59379+ return 1;
59380+}
59381diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59382new file mode 100644
59383index 0000000..9f7b1ac
59384--- /dev/null
59385+++ b/grsecurity/grsum.c
59386@@ -0,0 +1,61 @@
59387+#include <linux/err.h>
59388+#include <linux/kernel.h>
59389+#include <linux/sched.h>
59390+#include <linux/mm.h>
59391+#include <linux/scatterlist.h>
59392+#include <linux/crypto.h>
59393+#include <linux/gracl.h>
59394+
59395+
59396+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59397+#error "crypto and sha256 must be built into the kernel"
59398+#endif
59399+
59400+int
59401+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59402+{
59403+ char *p;
59404+ struct crypto_hash *tfm;
59405+ struct hash_desc desc;
59406+ struct scatterlist sg;
59407+ unsigned char temp_sum[GR_SHA_LEN];
59408+ volatile int retval = 0;
59409+ volatile int dummy = 0;
59410+ unsigned int i;
59411+
59412+ sg_init_table(&sg, 1);
59413+
59414+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59415+ if (IS_ERR(tfm)) {
59416+ /* should never happen, since sha256 should be built in */
59417+ return 1;
59418+ }
59419+
59420+ desc.tfm = tfm;
59421+ desc.flags = 0;
59422+
59423+ crypto_hash_init(&desc);
59424+
59425+ p = salt;
59426+ sg_set_buf(&sg, p, GR_SALT_LEN);
59427+ crypto_hash_update(&desc, &sg, sg.length);
59428+
59429+ p = entry->pw;
59430+ sg_set_buf(&sg, p, strlen(p));
59431+
59432+ crypto_hash_update(&desc, &sg, sg.length);
59433+
59434+ crypto_hash_final(&desc, temp_sum);
59435+
59436+ memset(entry->pw, 0, GR_PW_LEN);
59437+
59438+ for (i = 0; i < GR_SHA_LEN; i++)
59439+ if (sum[i] != temp_sum[i])
59440+ retval = 1;
59441+ else
59442+ dummy = 1; // waste a cycle
59443+
59444+ crypto_free_hash(tfm);
59445+
59446+ return retval;
59447+}
59448diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
59449index 6cd5b64..f620d2d 100644
59450--- a/include/acpi/acpi_bus.h
59451+++ b/include/acpi/acpi_bus.h
59452@@ -107,7 +107,7 @@ struct acpi_device_ops {
59453 acpi_op_bind bind;
59454 acpi_op_unbind unbind;
59455 acpi_op_notify notify;
59456-};
59457+} __no_const;
59458
59459 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
59460
59461diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
59462index b7babf0..71e4e74 100644
59463--- a/include/asm-generic/atomic-long.h
59464+++ b/include/asm-generic/atomic-long.h
59465@@ -22,6 +22,12 @@
59466
59467 typedef atomic64_t atomic_long_t;
59468
59469+#ifdef CONFIG_PAX_REFCOUNT
59470+typedef atomic64_unchecked_t atomic_long_unchecked_t;
59471+#else
59472+typedef atomic64_t atomic_long_unchecked_t;
59473+#endif
59474+
59475 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
59476
59477 static inline long atomic_long_read(atomic_long_t *l)
59478@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59479 return (long)atomic64_read(v);
59480 }
59481
59482+#ifdef CONFIG_PAX_REFCOUNT
59483+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59484+{
59485+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59486+
59487+ return (long)atomic64_read_unchecked(v);
59488+}
59489+#endif
59490+
59491 static inline void atomic_long_set(atomic_long_t *l, long i)
59492 {
59493 atomic64_t *v = (atomic64_t *)l;
59494@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59495 atomic64_set(v, i);
59496 }
59497
59498+#ifdef CONFIG_PAX_REFCOUNT
59499+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59500+{
59501+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59502+
59503+ atomic64_set_unchecked(v, i);
59504+}
59505+#endif
59506+
59507 static inline void atomic_long_inc(atomic_long_t *l)
59508 {
59509 atomic64_t *v = (atomic64_t *)l;
59510@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59511 atomic64_inc(v);
59512 }
59513
59514+#ifdef CONFIG_PAX_REFCOUNT
59515+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59516+{
59517+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59518+
59519+ atomic64_inc_unchecked(v);
59520+}
59521+#endif
59522+
59523 static inline void atomic_long_dec(atomic_long_t *l)
59524 {
59525 atomic64_t *v = (atomic64_t *)l;
59526@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59527 atomic64_dec(v);
59528 }
59529
59530+#ifdef CONFIG_PAX_REFCOUNT
59531+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59532+{
59533+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59534+
59535+ atomic64_dec_unchecked(v);
59536+}
59537+#endif
59538+
59539 static inline void atomic_long_add(long i, atomic_long_t *l)
59540 {
59541 atomic64_t *v = (atomic64_t *)l;
59542@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59543 atomic64_add(i, v);
59544 }
59545
59546+#ifdef CONFIG_PAX_REFCOUNT
59547+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59548+{
59549+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59550+
59551+ atomic64_add_unchecked(i, v);
59552+}
59553+#endif
59554+
59555 static inline void atomic_long_sub(long i, atomic_long_t *l)
59556 {
59557 atomic64_t *v = (atomic64_t *)l;
59558@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59559 atomic64_sub(i, v);
59560 }
59561
59562+#ifdef CONFIG_PAX_REFCOUNT
59563+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59564+{
59565+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59566+
59567+ atomic64_sub_unchecked(i, v);
59568+}
59569+#endif
59570+
59571 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59572 {
59573 atomic64_t *v = (atomic64_t *)l;
59574@@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59575 return (long)atomic64_inc_return(v);
59576 }
59577
59578+#ifdef CONFIG_PAX_REFCOUNT
59579+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59580+{
59581+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59582+
59583+ return (long)atomic64_inc_return_unchecked(v);
59584+}
59585+#endif
59586+
59587 static inline long atomic_long_dec_return(atomic_long_t *l)
59588 {
59589 atomic64_t *v = (atomic64_t *)l;
59590@@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59591
59592 typedef atomic_t atomic_long_t;
59593
59594+#ifdef CONFIG_PAX_REFCOUNT
59595+typedef atomic_unchecked_t atomic_long_unchecked_t;
59596+#else
59597+typedef atomic_t atomic_long_unchecked_t;
59598+#endif
59599+
59600 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
59601 static inline long atomic_long_read(atomic_long_t *l)
59602 {
59603@@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59604 return (long)atomic_read(v);
59605 }
59606
59607+#ifdef CONFIG_PAX_REFCOUNT
59608+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59609+{
59610+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59611+
59612+ return (long)atomic_read_unchecked(v);
59613+}
59614+#endif
59615+
59616 static inline void atomic_long_set(atomic_long_t *l, long i)
59617 {
59618 atomic_t *v = (atomic_t *)l;
59619@@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59620 atomic_set(v, i);
59621 }
59622
59623+#ifdef CONFIG_PAX_REFCOUNT
59624+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59625+{
59626+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59627+
59628+ atomic_set_unchecked(v, i);
59629+}
59630+#endif
59631+
59632 static inline void atomic_long_inc(atomic_long_t *l)
59633 {
59634 atomic_t *v = (atomic_t *)l;
59635@@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59636 atomic_inc(v);
59637 }
59638
59639+#ifdef CONFIG_PAX_REFCOUNT
59640+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59641+{
59642+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59643+
59644+ atomic_inc_unchecked(v);
59645+}
59646+#endif
59647+
59648 static inline void atomic_long_dec(atomic_long_t *l)
59649 {
59650 atomic_t *v = (atomic_t *)l;
59651@@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59652 atomic_dec(v);
59653 }
59654
59655+#ifdef CONFIG_PAX_REFCOUNT
59656+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59657+{
59658+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59659+
59660+ atomic_dec_unchecked(v);
59661+}
59662+#endif
59663+
59664 static inline void atomic_long_add(long i, atomic_long_t *l)
59665 {
59666 atomic_t *v = (atomic_t *)l;
59667@@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59668 atomic_add(i, v);
59669 }
59670
59671+#ifdef CONFIG_PAX_REFCOUNT
59672+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59673+{
59674+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59675+
59676+ atomic_add_unchecked(i, v);
59677+}
59678+#endif
59679+
59680 static inline void atomic_long_sub(long i, atomic_long_t *l)
59681 {
59682 atomic_t *v = (atomic_t *)l;
59683@@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59684 atomic_sub(i, v);
59685 }
59686
59687+#ifdef CONFIG_PAX_REFCOUNT
59688+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59689+{
59690+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59691+
59692+ atomic_sub_unchecked(i, v);
59693+}
59694+#endif
59695+
59696 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59697 {
59698 atomic_t *v = (atomic_t *)l;
59699@@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59700 return (long)atomic_inc_return(v);
59701 }
59702
59703+#ifdef CONFIG_PAX_REFCOUNT
59704+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59705+{
59706+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59707+
59708+ return (long)atomic_inc_return_unchecked(v);
59709+}
59710+#endif
59711+
59712 static inline long atomic_long_dec_return(atomic_long_t *l)
59713 {
59714 atomic_t *v = (atomic_t *)l;
59715@@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59716
59717 #endif /* BITS_PER_LONG == 64 */
59718
59719+#ifdef CONFIG_PAX_REFCOUNT
59720+static inline void pax_refcount_needs_these_functions(void)
59721+{
59722+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
59723+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
59724+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
59725+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
59726+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
59727+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
59728+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
59729+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
59730+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
59731+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
59732+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
59733+
59734+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
59735+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
59736+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
59737+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
59738+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
59739+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
59740+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
59741+}
59742+#else
59743+#define atomic_read_unchecked(v) atomic_read(v)
59744+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
59745+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
59746+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
59747+#define atomic_inc_unchecked(v) atomic_inc(v)
59748+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
59749+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
59750+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
59751+#define atomic_dec_unchecked(v) atomic_dec(v)
59752+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
59753+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
59754+
59755+#define atomic_long_read_unchecked(v) atomic_long_read(v)
59756+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
59757+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
59758+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
59759+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
59760+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
59761+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
59762+#endif
59763+
59764 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
59765diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
59766index b18ce4f..2ee2843 100644
59767--- a/include/asm-generic/atomic64.h
59768+++ b/include/asm-generic/atomic64.h
59769@@ -16,6 +16,8 @@ typedef struct {
59770 long long counter;
59771 } atomic64_t;
59772
59773+typedef atomic64_t atomic64_unchecked_t;
59774+
59775 #define ATOMIC64_INIT(i) { (i) }
59776
59777 extern long long atomic64_read(const atomic64_t *v);
59778@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
59779 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
59780 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
59781
59782+#define atomic64_read_unchecked(v) atomic64_read(v)
59783+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
59784+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
59785+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
59786+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
59787+#define atomic64_inc_unchecked(v) atomic64_inc(v)
59788+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
59789+#define atomic64_dec_unchecked(v) atomic64_dec(v)
59790+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
59791+
59792 #endif /* _ASM_GENERIC_ATOMIC64_H */
59793diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
59794index 1bfcfe5..e04c5c9 100644
59795--- a/include/asm-generic/cache.h
59796+++ b/include/asm-generic/cache.h
59797@@ -6,7 +6,7 @@
59798 * cache lines need to provide their own cache.h.
59799 */
59800
59801-#define L1_CACHE_SHIFT 5
59802-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
59803+#define L1_CACHE_SHIFT 5UL
59804+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
59805
59806 #endif /* __ASM_GENERIC_CACHE_H */
59807diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
59808index 0d68a1e..b74a761 100644
59809--- a/include/asm-generic/emergency-restart.h
59810+++ b/include/asm-generic/emergency-restart.h
59811@@ -1,7 +1,7 @@
59812 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
59813 #define _ASM_GENERIC_EMERGENCY_RESTART_H
59814
59815-static inline void machine_emergency_restart(void)
59816+static inline __noreturn void machine_emergency_restart(void)
59817 {
59818 machine_restart(NULL);
59819 }
59820diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
59821index 0232ccb..13d9165 100644
59822--- a/include/asm-generic/kmap_types.h
59823+++ b/include/asm-generic/kmap_types.h
59824@@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
59825 KMAP_D(17) KM_NMI,
59826 KMAP_D(18) KM_NMI_PTE,
59827 KMAP_D(19) KM_KDB,
59828+KMAP_D(20) KM_CLEARPAGE,
59829 /*
59830 * Remember to update debug_kmap_atomic() when adding new kmap types!
59831 */
59832-KMAP_D(20) KM_TYPE_NR
59833+KMAP_D(21) KM_TYPE_NR
59834 };
59835
59836 #undef KMAP_D
59837diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
59838index 9ceb03b..2efbcbd 100644
59839--- a/include/asm-generic/local.h
59840+++ b/include/asm-generic/local.h
59841@@ -39,6 +39,7 @@ typedef struct
59842 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
59843 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
59844 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
59845+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
59846
59847 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
59848 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
59849diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
59850index 725612b..9cc513a 100644
59851--- a/include/asm-generic/pgtable-nopmd.h
59852+++ b/include/asm-generic/pgtable-nopmd.h
59853@@ -1,14 +1,19 @@
59854 #ifndef _PGTABLE_NOPMD_H
59855 #define _PGTABLE_NOPMD_H
59856
59857-#ifndef __ASSEMBLY__
59858-
59859 #include <asm-generic/pgtable-nopud.h>
59860
59861-struct mm_struct;
59862-
59863 #define __PAGETABLE_PMD_FOLDED
59864
59865+#define PMD_SHIFT PUD_SHIFT
59866+#define PTRS_PER_PMD 1
59867+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
59868+#define PMD_MASK (~(PMD_SIZE-1))
59869+
59870+#ifndef __ASSEMBLY__
59871+
59872+struct mm_struct;
59873+
59874 /*
59875 * Having the pmd type consist of a pud gets the size right, and allows
59876 * us to conceptually access the pud entry that this pmd is folded into
59877@@ -16,11 +21,6 @@ struct mm_struct;
59878 */
59879 typedef struct { pud_t pud; } pmd_t;
59880
59881-#define PMD_SHIFT PUD_SHIFT
59882-#define PTRS_PER_PMD 1
59883-#define PMD_SIZE (1UL << PMD_SHIFT)
59884-#define PMD_MASK (~(PMD_SIZE-1))
59885-
59886 /*
59887 * The "pud_xxx()" functions here are trivial for a folded two-level
59888 * setup: the pmd is never bad, and a pmd always exists (as it's folded
59889diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
59890index 810431d..0ec4804f 100644
59891--- a/include/asm-generic/pgtable-nopud.h
59892+++ b/include/asm-generic/pgtable-nopud.h
59893@@ -1,10 +1,15 @@
59894 #ifndef _PGTABLE_NOPUD_H
59895 #define _PGTABLE_NOPUD_H
59896
59897-#ifndef __ASSEMBLY__
59898-
59899 #define __PAGETABLE_PUD_FOLDED
59900
59901+#define PUD_SHIFT PGDIR_SHIFT
59902+#define PTRS_PER_PUD 1
59903+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
59904+#define PUD_MASK (~(PUD_SIZE-1))
59905+
59906+#ifndef __ASSEMBLY__
59907+
59908 /*
59909 * Having the pud type consist of a pgd gets the size right, and allows
59910 * us to conceptually access the pgd entry that this pud is folded into
59911@@ -12,11 +17,6 @@
59912 */
59913 typedef struct { pgd_t pgd; } pud_t;
59914
59915-#define PUD_SHIFT PGDIR_SHIFT
59916-#define PTRS_PER_PUD 1
59917-#define PUD_SIZE (1UL << PUD_SHIFT)
59918-#define PUD_MASK (~(PUD_SIZE-1))
59919-
59920 /*
59921 * The "pgd_xxx()" functions here are trivial for a folded two-level
59922 * setup: the pud is never bad, and a pud always exists (as it's folded
59923@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
59924 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
59925
59926 #define pgd_populate(mm, pgd, pud) do { } while (0)
59927+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
59928 /*
59929 * (puds are folded into pgds so this doesn't get actually called,
59930 * but the define is needed for a generic inline function.)
59931diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
59932index a03c098..19751cf 100644
59933--- a/include/asm-generic/pgtable.h
59934+++ b/include/asm-generic/pgtable.h
59935@@ -445,6 +445,18 @@ static inline int pmd_write(pmd_t pmd)
59936 #endif /* __HAVE_ARCH_PMD_WRITE */
59937 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
59938
59939+#ifndef __HAVE_ARCH_READ_PMD_ATOMIC
59940+static inline pmd_t read_pmd_atomic(pmd_t *pmdp)
59941+{
59942+ /*
59943+ * Depend on compiler for an atomic pmd read. NOTE: this is
59944+ * only going to work, if the pmdval_t isn't larger than
59945+ * an unsigned long.
59946+ */
59947+ return *pmdp;
59948+}
59949+#endif /* __HAVE_ARCH_READ_PMD_ATOMIC */
59950+
59951 /*
59952 * This function is meant to be used by sites walking pagetables with
59953 * the mmap_sem hold in read mode to protect against MADV_DONTNEED and
59954@@ -458,11 +470,17 @@ static inline int pmd_write(pmd_t pmd)
59955 * undefined so behaving like if the pmd was none is safe (because it
59956 * can return none anyway). The compiler level barrier() is critically
59957 * important to compute the two checks atomically on the same pmdval.
59958+ *
59959+ * For 32bit kernels with a 64bit large pmd_t this automatically takes
59960+ * care of reading the pmd atomically to avoid SMP race conditions
59961+ * against pmd_populate() when the mmap_sem is hold for reading by the
59962+ * caller (a special atomic read not done by "gcc" as in the generic
59963+ * version above, is also needed when THP is disabled because the page
59964+ * fault can populate the pmd from under us).
59965 */
59966 static inline int pmd_none_or_trans_huge_or_clear_bad(pmd_t *pmd)
59967 {
59968- /* depend on compiler for an atomic pmd read */
59969- pmd_t pmdval = *pmd;
59970+ pmd_t pmdval = read_pmd_atomic(pmd);
59971 /*
59972 * The barrier will stabilize the pmdval in a register or on
59973 * the stack so that it will stop changing under the code.
59974@@ -502,6 +520,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
59975 #endif
59976 }
59977
59978+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
59979+static inline unsigned long pax_open_kernel(void) { return 0; }
59980+#endif
59981+
59982+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
59983+static inline unsigned long pax_close_kernel(void) { return 0; }
59984+#endif
59985+
59986 #endif /* CONFIG_MMU */
59987
59988 #endif /* !__ASSEMBLY__ */
59989diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
59990index b5e2e4c..6a5373e 100644
59991--- a/include/asm-generic/vmlinux.lds.h
59992+++ b/include/asm-generic/vmlinux.lds.h
59993@@ -217,6 +217,7 @@
59994 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
59995 VMLINUX_SYMBOL(__start_rodata) = .; \
59996 *(.rodata) *(.rodata.*) \
59997+ *(.data..read_only) \
59998 *(__vermagic) /* Kernel version magic */ \
59999 . = ALIGN(8); \
60000 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60001@@ -722,17 +723,18 @@
60002 * section in the linker script will go there too. @phdr should have
60003 * a leading colon.
60004 *
60005- * Note that this macros defines __per_cpu_load as an absolute symbol.
60006+ * Note that this macros defines per_cpu_load as an absolute symbol.
60007 * If there is no need to put the percpu section at a predetermined
60008 * address, use PERCPU_SECTION.
60009 */
60010 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60011- VMLINUX_SYMBOL(__per_cpu_load) = .; \
60012- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60013+ per_cpu_load = .; \
60014+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60015 - LOAD_OFFSET) { \
60016+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60017 PERCPU_INPUT(cacheline) \
60018 } phdr \
60019- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60020+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60021
60022 /**
60023 * PERCPU_SECTION - define output section for percpu area, simple version
60024diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60025index 92f0981..d44a37c 100644
60026--- a/include/drm/drmP.h
60027+++ b/include/drm/drmP.h
60028@@ -72,6 +72,7 @@
60029 #include <linux/workqueue.h>
60030 #include <linux/poll.h>
60031 #include <asm/pgalloc.h>
60032+#include <asm/local.h>
60033 #include "drm.h"
60034
60035 #include <linux/idr.h>
60036@@ -1038,7 +1039,7 @@ struct drm_device {
60037
60038 /** \name Usage Counters */
60039 /*@{ */
60040- int open_count; /**< Outstanding files open */
60041+ local_t open_count; /**< Outstanding files open */
60042 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60043 atomic_t vma_count; /**< Outstanding vma areas open */
60044 int buf_use; /**< Buffers in use -- cannot alloc */
60045@@ -1049,7 +1050,7 @@ struct drm_device {
60046 /*@{ */
60047 unsigned long counters;
60048 enum drm_stat_type types[15];
60049- atomic_t counts[15];
60050+ atomic_unchecked_t counts[15];
60051 /*@} */
60052
60053 struct list_head filelist;
60054diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60055index 37515d1..34fa8b0 100644
60056--- a/include/drm/drm_crtc_helper.h
60057+++ b/include/drm/drm_crtc_helper.h
60058@@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
60059
60060 /* disable crtc when not in use - more explicit than dpms off */
60061 void (*disable)(struct drm_crtc *crtc);
60062-};
60063+} __no_const;
60064
60065 struct drm_encoder_helper_funcs {
60066 void (*dpms)(struct drm_encoder *encoder, int mode);
60067@@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
60068 struct drm_connector *connector);
60069 /* disable encoder when not in use - more explicit than dpms off */
60070 void (*disable)(struct drm_encoder *encoder);
60071-};
60072+} __no_const;
60073
60074 struct drm_connector_helper_funcs {
60075 int (*get_modes)(struct drm_connector *connector);
60076diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60077index 26c1f78..6722682 100644
60078--- a/include/drm/ttm/ttm_memory.h
60079+++ b/include/drm/ttm/ttm_memory.h
60080@@ -47,7 +47,7 @@
60081
60082 struct ttm_mem_shrink {
60083 int (*do_shrink) (struct ttm_mem_shrink *);
60084-};
60085+} __no_const;
60086
60087 /**
60088 * struct ttm_mem_global - Global memory accounting structure.
60089diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60090index e86dfca..40cc55f 100644
60091--- a/include/linux/a.out.h
60092+++ b/include/linux/a.out.h
60093@@ -39,6 +39,14 @@ enum machine_type {
60094 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60095 };
60096
60097+/* Constants for the N_FLAGS field */
60098+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60099+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60100+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60101+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60102+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60103+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60104+
60105 #if !defined (N_MAGIC)
60106 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60107 #endif
60108diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60109index f4ff882..84b53a6 100644
60110--- a/include/linux/atmdev.h
60111+++ b/include/linux/atmdev.h
60112@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60113 #endif
60114
60115 struct k_atm_aal_stats {
60116-#define __HANDLE_ITEM(i) atomic_t i
60117+#define __HANDLE_ITEM(i) atomic_unchecked_t i
60118 __AAL_STAT_ITEMS
60119 #undef __HANDLE_ITEM
60120 };
60121diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60122index 0092102..8a801b4 100644
60123--- a/include/linux/binfmts.h
60124+++ b/include/linux/binfmts.h
60125@@ -89,6 +89,7 @@ struct linux_binfmt {
60126 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60127 int (*load_shlib)(struct file *);
60128 int (*core_dump)(struct coredump_params *cprm);
60129+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60130 unsigned long min_coredump; /* minimal dump size */
60131 };
60132
60133diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60134index 606cf33..b72c577 100644
60135--- a/include/linux/blkdev.h
60136+++ b/include/linux/blkdev.h
60137@@ -1379,7 +1379,7 @@ struct block_device_operations {
60138 /* this callback is with swap_lock and sometimes page table lock held */
60139 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60140 struct module *owner;
60141-};
60142+} __do_const;
60143
60144 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60145 unsigned long);
60146diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60147index 4d1a074..88f929a 100644
60148--- a/include/linux/blktrace_api.h
60149+++ b/include/linux/blktrace_api.h
60150@@ -162,7 +162,7 @@ struct blk_trace {
60151 struct dentry *dir;
60152 struct dentry *dropped_file;
60153 struct dentry *msg_file;
60154- atomic_t dropped;
60155+ atomic_unchecked_t dropped;
60156 };
60157
60158 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60159diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60160index 83195fb..0b0f77d 100644
60161--- a/include/linux/byteorder/little_endian.h
60162+++ b/include/linux/byteorder/little_endian.h
60163@@ -42,51 +42,51 @@
60164
60165 static inline __le64 __cpu_to_le64p(const __u64 *p)
60166 {
60167- return (__force __le64)*p;
60168+ return (__force const __le64)*p;
60169 }
60170 static inline __u64 __le64_to_cpup(const __le64 *p)
60171 {
60172- return (__force __u64)*p;
60173+ return (__force const __u64)*p;
60174 }
60175 static inline __le32 __cpu_to_le32p(const __u32 *p)
60176 {
60177- return (__force __le32)*p;
60178+ return (__force const __le32)*p;
60179 }
60180 static inline __u32 __le32_to_cpup(const __le32 *p)
60181 {
60182- return (__force __u32)*p;
60183+ return (__force const __u32)*p;
60184 }
60185 static inline __le16 __cpu_to_le16p(const __u16 *p)
60186 {
60187- return (__force __le16)*p;
60188+ return (__force const __le16)*p;
60189 }
60190 static inline __u16 __le16_to_cpup(const __le16 *p)
60191 {
60192- return (__force __u16)*p;
60193+ return (__force const __u16)*p;
60194 }
60195 static inline __be64 __cpu_to_be64p(const __u64 *p)
60196 {
60197- return (__force __be64)__swab64p(p);
60198+ return (__force const __be64)__swab64p(p);
60199 }
60200 static inline __u64 __be64_to_cpup(const __be64 *p)
60201 {
60202- return __swab64p((__u64 *)p);
60203+ return __swab64p((const __u64 *)p);
60204 }
60205 static inline __be32 __cpu_to_be32p(const __u32 *p)
60206 {
60207- return (__force __be32)__swab32p(p);
60208+ return (__force const __be32)__swab32p(p);
60209 }
60210 static inline __u32 __be32_to_cpup(const __be32 *p)
60211 {
60212- return __swab32p((__u32 *)p);
60213+ return __swab32p((const __u32 *)p);
60214 }
60215 static inline __be16 __cpu_to_be16p(const __u16 *p)
60216 {
60217- return (__force __be16)__swab16p(p);
60218+ return (__force const __be16)__swab16p(p);
60219 }
60220 static inline __u16 __be16_to_cpup(const __be16 *p)
60221 {
60222- return __swab16p((__u16 *)p);
60223+ return __swab16p((const __u16 *)p);
60224 }
60225 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60226 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60227diff --git a/include/linux/cache.h b/include/linux/cache.h
60228index 4c57065..4307975 100644
60229--- a/include/linux/cache.h
60230+++ b/include/linux/cache.h
60231@@ -16,6 +16,10 @@
60232 #define __read_mostly
60233 #endif
60234
60235+#ifndef __read_only
60236+#define __read_only __read_mostly
60237+#endif
60238+
60239 #ifndef ____cacheline_aligned
60240 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60241 #endif
60242diff --git a/include/linux/capability.h b/include/linux/capability.h
60243index 12d52de..b5f7fa7 100644
60244--- a/include/linux/capability.h
60245+++ b/include/linux/capability.h
60246@@ -548,6 +548,8 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
60247 extern bool capable(int cap);
60248 extern bool ns_capable(struct user_namespace *ns, int cap);
60249 extern bool nsown_capable(int cap);
60250+extern bool capable_nolog(int cap);
60251+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60252
60253 /* audit system wants to get cap info from files as well */
60254 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60255diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60256index 04ffb2e..6799180 100644
60257--- a/include/linux/cleancache.h
60258+++ b/include/linux/cleancache.h
60259@@ -31,7 +31,7 @@ struct cleancache_ops {
60260 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
60261 void (*flush_inode)(int, struct cleancache_filekey);
60262 void (*flush_fs)(int);
60263-};
60264+} __no_const;
60265
60266 extern struct cleancache_ops
60267 cleancache_register_ops(struct cleancache_ops *ops);
60268diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60269index 2f40791..a62d196 100644
60270--- a/include/linux/compiler-gcc4.h
60271+++ b/include/linux/compiler-gcc4.h
60272@@ -32,6 +32,16 @@
60273 #define __linktime_error(message) __attribute__((__error__(message)))
60274
60275 #if __GNUC_MINOR__ >= 5
60276+
60277+#ifdef CONSTIFY_PLUGIN
60278+#define __no_const __attribute__((no_const))
60279+#define __do_const __attribute__((do_const))
60280+#endif
60281+
60282+#ifdef SIZE_OVERFLOW_PLUGIN
60283+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
60284+#endif
60285+
60286 /*
60287 * Mark a position in code as unreachable. This can be used to
60288 * suppress control flow warnings after asm blocks that transfer
60289@@ -47,6 +57,11 @@
60290 #define __noclone __attribute__((__noclone__))
60291
60292 #endif
60293+
60294+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60295+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60296+#define __bos0(ptr) __bos((ptr), 0)
60297+#define __bos1(ptr) __bos((ptr), 1)
60298 #endif
60299
60300 #if __GNUC_MINOR__ > 0
60301diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60302index 4a24354..7149ac2 100644
60303--- a/include/linux/compiler.h
60304+++ b/include/linux/compiler.h
60305@@ -5,31 +5,62 @@
60306
60307 #ifdef __CHECKER__
60308 # define __user __attribute__((noderef, address_space(1)))
60309+# define __force_user __force __user
60310 # define __kernel __attribute__((address_space(0)))
60311+# define __force_kernel __force __kernel
60312 # define __safe __attribute__((safe))
60313 # define __force __attribute__((force))
60314 # define __nocast __attribute__((nocast))
60315 # define __iomem __attribute__((noderef, address_space(2)))
60316+# define __force_iomem __force __iomem
60317 # define __acquires(x) __attribute__((context(x,0,1)))
60318 # define __releases(x) __attribute__((context(x,1,0)))
60319 # define __acquire(x) __context__(x,1)
60320 # define __release(x) __context__(x,-1)
60321 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60322 # define __percpu __attribute__((noderef, address_space(3)))
60323+# define __force_percpu __force __percpu
60324 #ifdef CONFIG_SPARSE_RCU_POINTER
60325 # define __rcu __attribute__((noderef, address_space(4)))
60326+# define __force_rcu __force __rcu
60327 #else
60328 # define __rcu
60329+# define __force_rcu
60330 #endif
60331 extern void __chk_user_ptr(const volatile void __user *);
60332 extern void __chk_io_ptr(const volatile void __iomem *);
60333+#elif defined(CHECKER_PLUGIN)
60334+//# define __user
60335+//# define __force_user
60336+//# define __kernel
60337+//# define __force_kernel
60338+# define __safe
60339+# define __force
60340+# define __nocast
60341+# define __iomem
60342+# define __force_iomem
60343+# define __chk_user_ptr(x) (void)0
60344+# define __chk_io_ptr(x) (void)0
60345+# define __builtin_warning(x, y...) (1)
60346+# define __acquires(x)
60347+# define __releases(x)
60348+# define __acquire(x) (void)0
60349+# define __release(x) (void)0
60350+# define __cond_lock(x,c) (c)
60351+# define __percpu
60352+# define __force_percpu
60353+# define __rcu
60354+# define __force_rcu
60355 #else
60356 # define __user
60357+# define __force_user
60358 # define __kernel
60359+# define __force_kernel
60360 # define __safe
60361 # define __force
60362 # define __nocast
60363 # define __iomem
60364+# define __force_iomem
60365 # define __chk_user_ptr(x) (void)0
60366 # define __chk_io_ptr(x) (void)0
60367 # define __builtin_warning(x, y...) (1)
60368@@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60369 # define __release(x) (void)0
60370 # define __cond_lock(x,c) (c)
60371 # define __percpu
60372+# define __force_percpu
60373 # define __rcu
60374+# define __force_rcu
60375 #endif
60376
60377 #ifdef __KERNEL__
60378@@ -264,6 +297,18 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60379 # define __attribute_const__ /* unimplemented */
60380 #endif
60381
60382+#ifndef __no_const
60383+# define __no_const
60384+#endif
60385+
60386+#ifndef __do_const
60387+# define __do_const
60388+#endif
60389+
60390+#ifndef __size_overflow
60391+# define __size_overflow(...)
60392+#endif
60393+
60394 /*
60395 * Tell gcc if a function is cold. The compiler will assume any path
60396 * directly leading to the call is unlikely.
60397@@ -273,6 +318,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60398 #define __cold
60399 #endif
60400
60401+#ifndef __alloc_size
60402+#define __alloc_size(...)
60403+#endif
60404+
60405+#ifndef __bos
60406+#define __bos(ptr, arg)
60407+#endif
60408+
60409+#ifndef __bos0
60410+#define __bos0(ptr)
60411+#endif
60412+
60413+#ifndef __bos1
60414+#define __bos1(ptr)
60415+#endif
60416+
60417 /* Simple shorthand for a section definition */
60418 #ifndef __section
60419 # define __section(S) __attribute__ ((__section__(#S)))
60420@@ -308,6 +369,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60421 * use is to mediate communication between process-level code and irq/NMI
60422 * handlers, all running on the same CPU.
60423 */
60424-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
60425+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
60426+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
60427
60428 #endif /* __LINUX_COMPILER_H */
60429diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
60430index e9eaec5..bfeb9bb 100644
60431--- a/include/linux/cpuset.h
60432+++ b/include/linux/cpuset.h
60433@@ -118,7 +118,7 @@ static inline void put_mems_allowed(void)
60434 * nodemask.
60435 */
60436 smp_mb();
60437- --ACCESS_ONCE(current->mems_allowed_change_disable);
60438+ --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
60439 }
60440
60441 static inline void set_mems_allowed(nodemask_t nodemask)
60442diff --git a/include/linux/cred.h b/include/linux/cred.h
60443index adadf71..6af5560 100644
60444--- a/include/linux/cred.h
60445+++ b/include/linux/cred.h
60446@@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
60447 static inline void validate_process_creds(void)
60448 {
60449 }
60450+static inline void validate_task_creds(struct task_struct *task)
60451+{
60452+}
60453 #endif
60454
60455 /**
60456diff --git a/include/linux/crypto.h b/include/linux/crypto.h
60457index 8a94217..15d49e3 100644
60458--- a/include/linux/crypto.h
60459+++ b/include/linux/crypto.h
60460@@ -365,7 +365,7 @@ struct cipher_tfm {
60461 const u8 *key, unsigned int keylen);
60462 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60463 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60464-};
60465+} __no_const;
60466
60467 struct hash_tfm {
60468 int (*init)(struct hash_desc *desc);
60469@@ -386,13 +386,13 @@ struct compress_tfm {
60470 int (*cot_decompress)(struct crypto_tfm *tfm,
60471 const u8 *src, unsigned int slen,
60472 u8 *dst, unsigned int *dlen);
60473-};
60474+} __no_const;
60475
60476 struct rng_tfm {
60477 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
60478 unsigned int dlen);
60479 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
60480-};
60481+} __no_const;
60482
60483 #define crt_ablkcipher crt_u.ablkcipher
60484 #define crt_aead crt_u.aead
60485diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
60486index 7925bf0..d5143d2 100644
60487--- a/include/linux/decompress/mm.h
60488+++ b/include/linux/decompress/mm.h
60489@@ -77,7 +77,7 @@ static void free(void *where)
60490 * warnings when not needed (indeed large_malloc / large_free are not
60491 * needed by inflate */
60492
60493-#define malloc(a) kmalloc(a, GFP_KERNEL)
60494+#define malloc(a) kmalloc((a), GFP_KERNEL)
60495 #define free(a) kfree(a)
60496
60497 #define large_malloc(a) vmalloc(a)
60498diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
60499index e13117c..e9fc938 100644
60500--- a/include/linux/dma-mapping.h
60501+++ b/include/linux/dma-mapping.h
60502@@ -46,7 +46,7 @@ struct dma_map_ops {
60503 u64 (*get_required_mask)(struct device *dev);
60504 #endif
60505 int is_phys;
60506-};
60507+} __do_const;
60508
60509 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60510
60511diff --git a/include/linux/efi.h b/include/linux/efi.h
60512index 7cce0ea..c2085e4 100644
60513--- a/include/linux/efi.h
60514+++ b/include/linux/efi.h
60515@@ -591,7 +591,7 @@ struct efivar_operations {
60516 efi_get_variable_t *get_variable;
60517 efi_get_next_variable_t *get_next_variable;
60518 efi_set_variable_t *set_variable;
60519-};
60520+} __no_const;
60521
60522 struct efivars {
60523 /*
60524diff --git a/include/linux/elf.h b/include/linux/elf.h
60525index 999b4f5..57753b4 100644
60526--- a/include/linux/elf.h
60527+++ b/include/linux/elf.h
60528@@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
60529 #define PT_GNU_EH_FRAME 0x6474e550
60530
60531 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
60532+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
60533+
60534+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
60535+
60536+/* Constants for the e_flags field */
60537+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60538+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
60539+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
60540+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
60541+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60542+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60543
60544 /*
60545 * Extended Numbering
60546@@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
60547 #define DT_DEBUG 21
60548 #define DT_TEXTREL 22
60549 #define DT_JMPREL 23
60550+#define DT_FLAGS 30
60551+ #define DF_TEXTREL 0x00000004
60552 #define DT_ENCODING 32
60553 #define OLD_DT_LOOS 0x60000000
60554 #define DT_LOOS 0x6000000d
60555@@ -243,6 +256,19 @@ typedef struct elf64_hdr {
60556 #define PF_W 0x2
60557 #define PF_X 0x1
60558
60559+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
60560+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
60561+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
60562+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
60563+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
60564+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
60565+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
60566+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
60567+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
60568+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
60569+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
60570+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
60571+
60572 typedef struct elf32_phdr{
60573 Elf32_Word p_type;
60574 Elf32_Off p_offset;
60575@@ -335,6 +361,8 @@ typedef struct elf64_shdr {
60576 #define EI_OSABI 7
60577 #define EI_PAD 8
60578
60579+#define EI_PAX 14
60580+
60581 #define ELFMAG0 0x7f /* EI_MAG */
60582 #define ELFMAG1 'E'
60583 #define ELFMAG2 'L'
60584@@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
60585 #define elf_note elf32_note
60586 #define elf_addr_t Elf32_Off
60587 #define Elf_Half Elf32_Half
60588+#define elf_dyn Elf32_Dyn
60589
60590 #else
60591
60592@@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
60593 #define elf_note elf64_note
60594 #define elf_addr_t Elf64_Off
60595 #define Elf_Half Elf64_Half
60596+#define elf_dyn Elf64_Dyn
60597
60598 #endif
60599
60600diff --git a/include/linux/filter.h b/include/linux/filter.h
60601index 8eeb205..d59bfa2 100644
60602--- a/include/linux/filter.h
60603+++ b/include/linux/filter.h
60604@@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
60605
60606 struct sk_buff;
60607 struct sock;
60608+struct bpf_jit_work;
60609
60610 struct sk_filter
60611 {
60612@@ -141,6 +142,9 @@ struct sk_filter
60613 unsigned int len; /* Number of filter blocks */
60614 unsigned int (*bpf_func)(const struct sk_buff *skb,
60615 const struct sock_filter *filter);
60616+#ifdef CONFIG_BPF_JIT
60617+ struct bpf_jit_work *work;
60618+#endif
60619 struct rcu_head rcu;
60620 struct sock_filter insns[0];
60621 };
60622diff --git a/include/linux/firewire.h b/include/linux/firewire.h
60623index 84ccf8e..2e9b14c 100644
60624--- a/include/linux/firewire.h
60625+++ b/include/linux/firewire.h
60626@@ -428,7 +428,7 @@ struct fw_iso_context {
60627 union {
60628 fw_iso_callback_t sc;
60629 fw_iso_mc_callback_t mc;
60630- } callback;
60631+ } __no_const callback;
60632 void *callback_data;
60633 };
60634
60635diff --git a/include/linux/fs.h b/include/linux/fs.h
60636index f4b6e06..d6ba573 100644
60637--- a/include/linux/fs.h
60638+++ b/include/linux/fs.h
60639@@ -1628,7 +1628,8 @@ struct file_operations {
60640 int (*setlease)(struct file *, long, struct file_lock **);
60641 long (*fallocate)(struct file *file, int mode, loff_t offset,
60642 loff_t len);
60643-};
60644+} __do_const;
60645+typedef struct file_operations __no_const file_operations_no_const;
60646
60647 struct inode_operations {
60648 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
60649diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
60650index 003dc0f..3c4ea97 100644
60651--- a/include/linux/fs_struct.h
60652+++ b/include/linux/fs_struct.h
60653@@ -6,7 +6,7 @@
60654 #include <linux/seqlock.h>
60655
60656 struct fs_struct {
60657- int users;
60658+ atomic_t users;
60659 spinlock_t lock;
60660 seqcount_t seq;
60661 int umask;
60662diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
60663index ce31408..b1ad003 100644
60664--- a/include/linux/fscache-cache.h
60665+++ b/include/linux/fscache-cache.h
60666@@ -102,7 +102,7 @@ struct fscache_operation {
60667 fscache_operation_release_t release;
60668 };
60669
60670-extern atomic_t fscache_op_debug_id;
60671+extern atomic_unchecked_t fscache_op_debug_id;
60672 extern void fscache_op_work_func(struct work_struct *work);
60673
60674 extern void fscache_enqueue_operation(struct fscache_operation *);
60675@@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
60676 {
60677 INIT_WORK(&op->work, fscache_op_work_func);
60678 atomic_set(&op->usage, 1);
60679- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60680+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60681 op->processor = processor;
60682 op->release = release;
60683 INIT_LIST_HEAD(&op->pend_link);
60684diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
60685index 2a53f10..0187fdf 100644
60686--- a/include/linux/fsnotify.h
60687+++ b/include/linux/fsnotify.h
60688@@ -314,7 +314,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
60689 */
60690 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
60691 {
60692- return kstrdup(name, GFP_KERNEL);
60693+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
60694 }
60695
60696 /*
60697diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
60698index 91d0e0a3..035666b 100644
60699--- a/include/linux/fsnotify_backend.h
60700+++ b/include/linux/fsnotify_backend.h
60701@@ -105,6 +105,7 @@ struct fsnotify_ops {
60702 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
60703 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
60704 };
60705+typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
60706
60707 /*
60708 * A group is a "thing" that wants to receive notification about filesystem
60709diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
60710index c3da42d..c70e0df 100644
60711--- a/include/linux/ftrace_event.h
60712+++ b/include/linux/ftrace_event.h
60713@@ -97,7 +97,7 @@ struct trace_event_functions {
60714 trace_print_func raw;
60715 trace_print_func hex;
60716 trace_print_func binary;
60717-};
60718+} __no_const;
60719
60720 struct trace_event {
60721 struct hlist_node node;
60722@@ -254,7 +254,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
60723 extern int trace_add_event_call(struct ftrace_event_call *call);
60724 extern void trace_remove_event_call(struct ftrace_event_call *call);
60725
60726-#define is_signed_type(type) (((type)(-1)) < 0)
60727+#define is_signed_type(type) (((type)(-1)) < (type)1)
60728
60729 int trace_set_clr_event(const char *system, const char *event, int set);
60730
60731diff --git a/include/linux/genhd.h b/include/linux/genhd.h
60732index e61d319..0da8505 100644
60733--- a/include/linux/genhd.h
60734+++ b/include/linux/genhd.h
60735@@ -185,7 +185,7 @@ struct gendisk {
60736 struct kobject *slave_dir;
60737
60738 struct timer_rand_state *random;
60739- atomic_t sync_io; /* RAID */
60740+ atomic_unchecked_t sync_io; /* RAID */
60741 struct disk_events *ev;
60742 #ifdef CONFIG_BLK_DEV_INTEGRITY
60743 struct blk_integrity *integrity;
60744diff --git a/include/linux/gracl.h b/include/linux/gracl.h
60745new file mode 100644
60746index 0000000..8a130b6
60747--- /dev/null
60748+++ b/include/linux/gracl.h
60749@@ -0,0 +1,319 @@
60750+#ifndef GR_ACL_H
60751+#define GR_ACL_H
60752+
60753+#include <linux/grdefs.h>
60754+#include <linux/resource.h>
60755+#include <linux/capability.h>
60756+#include <linux/dcache.h>
60757+#include <asm/resource.h>
60758+
60759+/* Major status information */
60760+
60761+#define GR_VERSION "grsecurity 2.9"
60762+#define GRSECURITY_VERSION 0x2900
60763+
60764+enum {
60765+ GR_SHUTDOWN = 0,
60766+ GR_ENABLE = 1,
60767+ GR_SPROLE = 2,
60768+ GR_RELOAD = 3,
60769+ GR_SEGVMOD = 4,
60770+ GR_STATUS = 5,
60771+ GR_UNSPROLE = 6,
60772+ GR_PASSSET = 7,
60773+ GR_SPROLEPAM = 8,
60774+};
60775+
60776+/* Password setup definitions
60777+ * kernel/grhash.c */
60778+enum {
60779+ GR_PW_LEN = 128,
60780+ GR_SALT_LEN = 16,
60781+ GR_SHA_LEN = 32,
60782+};
60783+
60784+enum {
60785+ GR_SPROLE_LEN = 64,
60786+};
60787+
60788+enum {
60789+ GR_NO_GLOB = 0,
60790+ GR_REG_GLOB,
60791+ GR_CREATE_GLOB
60792+};
60793+
60794+#define GR_NLIMITS 32
60795+
60796+/* Begin Data Structures */
60797+
60798+struct sprole_pw {
60799+ unsigned char *rolename;
60800+ unsigned char salt[GR_SALT_LEN];
60801+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
60802+};
60803+
60804+struct name_entry {
60805+ __u32 key;
60806+ ino_t inode;
60807+ dev_t device;
60808+ char *name;
60809+ __u16 len;
60810+ __u8 deleted;
60811+ struct name_entry *prev;
60812+ struct name_entry *next;
60813+};
60814+
60815+struct inodev_entry {
60816+ struct name_entry *nentry;
60817+ struct inodev_entry *prev;
60818+ struct inodev_entry *next;
60819+};
60820+
60821+struct acl_role_db {
60822+ struct acl_role_label **r_hash;
60823+ __u32 r_size;
60824+};
60825+
60826+struct inodev_db {
60827+ struct inodev_entry **i_hash;
60828+ __u32 i_size;
60829+};
60830+
60831+struct name_db {
60832+ struct name_entry **n_hash;
60833+ __u32 n_size;
60834+};
60835+
60836+struct crash_uid {
60837+ uid_t uid;
60838+ unsigned long expires;
60839+};
60840+
60841+struct gr_hash_struct {
60842+ void **table;
60843+ void **nametable;
60844+ void *first;
60845+ __u32 table_size;
60846+ __u32 used_size;
60847+ int type;
60848+};
60849+
60850+/* Userspace Grsecurity ACL data structures */
60851+
60852+struct acl_subject_label {
60853+ char *filename;
60854+ ino_t inode;
60855+ dev_t device;
60856+ __u32 mode;
60857+ kernel_cap_t cap_mask;
60858+ kernel_cap_t cap_lower;
60859+ kernel_cap_t cap_invert_audit;
60860+
60861+ struct rlimit res[GR_NLIMITS];
60862+ __u32 resmask;
60863+
60864+ __u8 user_trans_type;
60865+ __u8 group_trans_type;
60866+ uid_t *user_transitions;
60867+ gid_t *group_transitions;
60868+ __u16 user_trans_num;
60869+ __u16 group_trans_num;
60870+
60871+ __u32 sock_families[2];
60872+ __u32 ip_proto[8];
60873+ __u32 ip_type;
60874+ struct acl_ip_label **ips;
60875+ __u32 ip_num;
60876+ __u32 inaddr_any_override;
60877+
60878+ __u32 crashes;
60879+ unsigned long expires;
60880+
60881+ struct acl_subject_label *parent_subject;
60882+ struct gr_hash_struct *hash;
60883+ struct acl_subject_label *prev;
60884+ struct acl_subject_label *next;
60885+
60886+ struct acl_object_label **obj_hash;
60887+ __u32 obj_hash_size;
60888+ __u16 pax_flags;
60889+};
60890+
60891+struct role_allowed_ip {
60892+ __u32 addr;
60893+ __u32 netmask;
60894+
60895+ struct role_allowed_ip *prev;
60896+ struct role_allowed_ip *next;
60897+};
60898+
60899+struct role_transition {
60900+ char *rolename;
60901+
60902+ struct role_transition *prev;
60903+ struct role_transition *next;
60904+};
60905+
60906+struct acl_role_label {
60907+ char *rolename;
60908+ uid_t uidgid;
60909+ __u16 roletype;
60910+
60911+ __u16 auth_attempts;
60912+ unsigned long expires;
60913+
60914+ struct acl_subject_label *root_label;
60915+ struct gr_hash_struct *hash;
60916+
60917+ struct acl_role_label *prev;
60918+ struct acl_role_label *next;
60919+
60920+ struct role_transition *transitions;
60921+ struct role_allowed_ip *allowed_ips;
60922+ uid_t *domain_children;
60923+ __u16 domain_child_num;
60924+
60925+ umode_t umask;
60926+
60927+ struct acl_subject_label **subj_hash;
60928+ __u32 subj_hash_size;
60929+};
60930+
60931+struct user_acl_role_db {
60932+ struct acl_role_label **r_table;
60933+ __u32 num_pointers; /* Number of allocations to track */
60934+ __u32 num_roles; /* Number of roles */
60935+ __u32 num_domain_children; /* Number of domain children */
60936+ __u32 num_subjects; /* Number of subjects */
60937+ __u32 num_objects; /* Number of objects */
60938+};
60939+
60940+struct acl_object_label {
60941+ char *filename;
60942+ ino_t inode;
60943+ dev_t device;
60944+ __u32 mode;
60945+
60946+ struct acl_subject_label *nested;
60947+ struct acl_object_label *globbed;
60948+
60949+ /* next two structures not used */
60950+
60951+ struct acl_object_label *prev;
60952+ struct acl_object_label *next;
60953+};
60954+
60955+struct acl_ip_label {
60956+ char *iface;
60957+ __u32 addr;
60958+ __u32 netmask;
60959+ __u16 low, high;
60960+ __u8 mode;
60961+ __u32 type;
60962+ __u32 proto[8];
60963+
60964+ /* next two structures not used */
60965+
60966+ struct acl_ip_label *prev;
60967+ struct acl_ip_label *next;
60968+};
60969+
60970+struct gr_arg {
60971+ struct user_acl_role_db role_db;
60972+ unsigned char pw[GR_PW_LEN];
60973+ unsigned char salt[GR_SALT_LEN];
60974+ unsigned char sum[GR_SHA_LEN];
60975+ unsigned char sp_role[GR_SPROLE_LEN];
60976+ struct sprole_pw *sprole_pws;
60977+ dev_t segv_device;
60978+ ino_t segv_inode;
60979+ uid_t segv_uid;
60980+ __u16 num_sprole_pws;
60981+ __u16 mode;
60982+};
60983+
60984+struct gr_arg_wrapper {
60985+ struct gr_arg *arg;
60986+ __u32 version;
60987+ __u32 size;
60988+};
60989+
60990+struct subject_map {
60991+ struct acl_subject_label *user;
60992+ struct acl_subject_label *kernel;
60993+ struct subject_map *prev;
60994+ struct subject_map *next;
60995+};
60996+
60997+struct acl_subj_map_db {
60998+ struct subject_map **s_hash;
60999+ __u32 s_size;
61000+};
61001+
61002+/* End Data Structures Section */
61003+
61004+/* Hash functions generated by empirical testing by Brad Spengler
61005+ Makes good use of the low bits of the inode. Generally 0-1 times
61006+ in loop for successful match. 0-3 for unsuccessful match.
61007+ Shift/add algorithm with modulus of table size and an XOR*/
61008+
61009+static __inline__ unsigned int
61010+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61011+{
61012+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
61013+}
61014+
61015+ static __inline__ unsigned int
61016+shash(const struct acl_subject_label *userp, const unsigned int sz)
61017+{
61018+ return ((const unsigned long)userp % sz);
61019+}
61020+
61021+static __inline__ unsigned int
61022+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61023+{
61024+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61025+}
61026+
61027+static __inline__ unsigned int
61028+nhash(const char *name, const __u16 len, const unsigned int sz)
61029+{
61030+ return full_name_hash((const unsigned char *)name, len) % sz;
61031+}
61032+
61033+#define FOR_EACH_ROLE_START(role) \
61034+ role = role_list; \
61035+ while (role) {
61036+
61037+#define FOR_EACH_ROLE_END(role) \
61038+ role = role->prev; \
61039+ }
61040+
61041+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
61042+ subj = NULL; \
61043+ iter = 0; \
61044+ while (iter < role->subj_hash_size) { \
61045+ if (subj == NULL) \
61046+ subj = role->subj_hash[iter]; \
61047+ if (subj == NULL) { \
61048+ iter++; \
61049+ continue; \
61050+ }
61051+
61052+#define FOR_EACH_SUBJECT_END(subj,iter) \
61053+ subj = subj->next; \
61054+ if (subj == NULL) \
61055+ iter++; \
61056+ }
61057+
61058+
61059+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
61060+ subj = role->hash->first; \
61061+ while (subj != NULL) {
61062+
61063+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
61064+ subj = subj->next; \
61065+ }
61066+
61067+#endif
61068+
61069diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61070new file mode 100644
61071index 0000000..323ecf2
61072--- /dev/null
61073+++ b/include/linux/gralloc.h
61074@@ -0,0 +1,9 @@
61075+#ifndef __GRALLOC_H
61076+#define __GRALLOC_H
61077+
61078+void acl_free_all(void);
61079+int acl_alloc_stack_init(unsigned long size);
61080+void *acl_alloc(unsigned long len);
61081+void *acl_alloc_num(unsigned long num, unsigned long len);
61082+
61083+#endif
61084diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61085new file mode 100644
61086index 0000000..b30e9bc
61087--- /dev/null
61088+++ b/include/linux/grdefs.h
61089@@ -0,0 +1,140 @@
61090+#ifndef GRDEFS_H
61091+#define GRDEFS_H
61092+
61093+/* Begin grsecurity status declarations */
61094+
61095+enum {
61096+ GR_READY = 0x01,
61097+ GR_STATUS_INIT = 0x00 // disabled state
61098+};
61099+
61100+/* Begin ACL declarations */
61101+
61102+/* Role flags */
61103+
61104+enum {
61105+ GR_ROLE_USER = 0x0001,
61106+ GR_ROLE_GROUP = 0x0002,
61107+ GR_ROLE_DEFAULT = 0x0004,
61108+ GR_ROLE_SPECIAL = 0x0008,
61109+ GR_ROLE_AUTH = 0x0010,
61110+ GR_ROLE_NOPW = 0x0020,
61111+ GR_ROLE_GOD = 0x0040,
61112+ GR_ROLE_LEARN = 0x0080,
61113+ GR_ROLE_TPE = 0x0100,
61114+ GR_ROLE_DOMAIN = 0x0200,
61115+ GR_ROLE_PAM = 0x0400,
61116+ GR_ROLE_PERSIST = 0x0800
61117+};
61118+
61119+/* ACL Subject and Object mode flags */
61120+enum {
61121+ GR_DELETED = 0x80000000
61122+};
61123+
61124+/* ACL Object-only mode flags */
61125+enum {
61126+ GR_READ = 0x00000001,
61127+ GR_APPEND = 0x00000002,
61128+ GR_WRITE = 0x00000004,
61129+ GR_EXEC = 0x00000008,
61130+ GR_FIND = 0x00000010,
61131+ GR_INHERIT = 0x00000020,
61132+ GR_SETID = 0x00000040,
61133+ GR_CREATE = 0x00000080,
61134+ GR_DELETE = 0x00000100,
61135+ GR_LINK = 0x00000200,
61136+ GR_AUDIT_READ = 0x00000400,
61137+ GR_AUDIT_APPEND = 0x00000800,
61138+ GR_AUDIT_WRITE = 0x00001000,
61139+ GR_AUDIT_EXEC = 0x00002000,
61140+ GR_AUDIT_FIND = 0x00004000,
61141+ GR_AUDIT_INHERIT= 0x00008000,
61142+ GR_AUDIT_SETID = 0x00010000,
61143+ GR_AUDIT_CREATE = 0x00020000,
61144+ GR_AUDIT_DELETE = 0x00040000,
61145+ GR_AUDIT_LINK = 0x00080000,
61146+ GR_PTRACERD = 0x00100000,
61147+ GR_NOPTRACE = 0x00200000,
61148+ GR_SUPPRESS = 0x00400000,
61149+ GR_NOLEARN = 0x00800000,
61150+ GR_INIT_TRANSFER= 0x01000000
61151+};
61152+
61153+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61154+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61155+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61156+
61157+/* ACL subject-only mode flags */
61158+enum {
61159+ GR_KILL = 0x00000001,
61160+ GR_VIEW = 0x00000002,
61161+ GR_PROTECTED = 0x00000004,
61162+ GR_LEARN = 0x00000008,
61163+ GR_OVERRIDE = 0x00000010,
61164+ /* just a placeholder, this mode is only used in userspace */
61165+ GR_DUMMY = 0x00000020,
61166+ GR_PROTSHM = 0x00000040,
61167+ GR_KILLPROC = 0x00000080,
61168+ GR_KILLIPPROC = 0x00000100,
61169+ /* just a placeholder, this mode is only used in userspace */
61170+ GR_NOTROJAN = 0x00000200,
61171+ GR_PROTPROCFD = 0x00000400,
61172+ GR_PROCACCT = 0x00000800,
61173+ GR_RELAXPTRACE = 0x00001000,
61174+ GR_NESTED = 0x00002000,
61175+ GR_INHERITLEARN = 0x00004000,
61176+ GR_PROCFIND = 0x00008000,
61177+ GR_POVERRIDE = 0x00010000,
61178+ GR_KERNELAUTH = 0x00020000,
61179+ GR_ATSECURE = 0x00040000,
61180+ GR_SHMEXEC = 0x00080000
61181+};
61182+
61183+enum {
61184+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61185+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61186+ GR_PAX_ENABLE_MPROTECT = 0x0004,
61187+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
61188+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61189+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61190+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61191+ GR_PAX_DISABLE_MPROTECT = 0x0400,
61192+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
61193+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61194+};
61195+
61196+enum {
61197+ GR_ID_USER = 0x01,
61198+ GR_ID_GROUP = 0x02,
61199+};
61200+
61201+enum {
61202+ GR_ID_ALLOW = 0x01,
61203+ GR_ID_DENY = 0x02,
61204+};
61205+
61206+#define GR_CRASH_RES 31
61207+#define GR_UIDTABLE_MAX 500
61208+
61209+/* begin resource learning section */
61210+enum {
61211+ GR_RLIM_CPU_BUMP = 60,
61212+ GR_RLIM_FSIZE_BUMP = 50000,
61213+ GR_RLIM_DATA_BUMP = 10000,
61214+ GR_RLIM_STACK_BUMP = 1000,
61215+ GR_RLIM_CORE_BUMP = 10000,
61216+ GR_RLIM_RSS_BUMP = 500000,
61217+ GR_RLIM_NPROC_BUMP = 1,
61218+ GR_RLIM_NOFILE_BUMP = 5,
61219+ GR_RLIM_MEMLOCK_BUMP = 50000,
61220+ GR_RLIM_AS_BUMP = 500000,
61221+ GR_RLIM_LOCKS_BUMP = 2,
61222+ GR_RLIM_SIGPENDING_BUMP = 5,
61223+ GR_RLIM_MSGQUEUE_BUMP = 10000,
61224+ GR_RLIM_NICE_BUMP = 1,
61225+ GR_RLIM_RTPRIO_BUMP = 1,
61226+ GR_RLIM_RTTIME_BUMP = 1000000
61227+};
61228+
61229+#endif
61230diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61231new file mode 100644
61232index 0000000..da390f1
61233--- /dev/null
61234+++ b/include/linux/grinternal.h
61235@@ -0,0 +1,221 @@
61236+#ifndef __GRINTERNAL_H
61237+#define __GRINTERNAL_H
61238+
61239+#ifdef CONFIG_GRKERNSEC
61240+
61241+#include <linux/fs.h>
61242+#include <linux/mnt_namespace.h>
61243+#include <linux/nsproxy.h>
61244+#include <linux/gracl.h>
61245+#include <linux/grdefs.h>
61246+#include <linux/grmsg.h>
61247+
61248+void gr_add_learn_entry(const char *fmt, ...)
61249+ __attribute__ ((format (printf, 1, 2)));
61250+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61251+ const struct vfsmount *mnt);
61252+__u32 gr_check_create(const struct dentry *new_dentry,
61253+ const struct dentry *parent,
61254+ const struct vfsmount *mnt, const __u32 mode);
61255+int gr_check_protected_task(const struct task_struct *task);
61256+__u32 to_gr_audit(const __u32 reqmode);
61257+int gr_set_acls(const int type);
61258+int gr_apply_subject_to_task(struct task_struct *task);
61259+int gr_acl_is_enabled(void);
61260+char gr_roletype_to_char(void);
61261+
61262+void gr_handle_alertkill(struct task_struct *task);
61263+char *gr_to_filename(const struct dentry *dentry,
61264+ const struct vfsmount *mnt);
61265+char *gr_to_filename1(const struct dentry *dentry,
61266+ const struct vfsmount *mnt);
61267+char *gr_to_filename2(const struct dentry *dentry,
61268+ const struct vfsmount *mnt);
61269+char *gr_to_filename3(const struct dentry *dentry,
61270+ const struct vfsmount *mnt);
61271+
61272+extern int grsec_enable_ptrace_readexec;
61273+extern int grsec_enable_harden_ptrace;
61274+extern int grsec_enable_link;
61275+extern int grsec_enable_fifo;
61276+extern int grsec_enable_execve;
61277+extern int grsec_enable_shm;
61278+extern int grsec_enable_execlog;
61279+extern int grsec_enable_signal;
61280+extern int grsec_enable_audit_ptrace;
61281+extern int grsec_enable_forkfail;
61282+extern int grsec_enable_time;
61283+extern int grsec_enable_rofs;
61284+extern int grsec_enable_chroot_shmat;
61285+extern int grsec_enable_chroot_mount;
61286+extern int grsec_enable_chroot_double;
61287+extern int grsec_enable_chroot_pivot;
61288+extern int grsec_enable_chroot_chdir;
61289+extern int grsec_enable_chroot_chmod;
61290+extern int grsec_enable_chroot_mknod;
61291+extern int grsec_enable_chroot_fchdir;
61292+extern int grsec_enable_chroot_nice;
61293+extern int grsec_enable_chroot_execlog;
61294+extern int grsec_enable_chroot_caps;
61295+extern int grsec_enable_chroot_sysctl;
61296+extern int grsec_enable_chroot_unix;
61297+extern int grsec_enable_tpe;
61298+extern int grsec_tpe_gid;
61299+extern int grsec_enable_tpe_all;
61300+extern int grsec_enable_tpe_invert;
61301+extern int grsec_enable_socket_all;
61302+extern int grsec_socket_all_gid;
61303+extern int grsec_enable_socket_client;
61304+extern int grsec_socket_client_gid;
61305+extern int grsec_enable_socket_server;
61306+extern int grsec_socket_server_gid;
61307+extern int grsec_audit_gid;
61308+extern int grsec_enable_group;
61309+extern int grsec_enable_audit_textrel;
61310+extern int grsec_enable_log_rwxmaps;
61311+extern int grsec_enable_mount;
61312+extern int grsec_enable_chdir;
61313+extern int grsec_resource_logging;
61314+extern int grsec_enable_blackhole;
61315+extern int grsec_lastack_retries;
61316+extern int grsec_enable_brute;
61317+extern int grsec_lock;
61318+
61319+extern spinlock_t grsec_alert_lock;
61320+extern unsigned long grsec_alert_wtime;
61321+extern unsigned long grsec_alert_fyet;
61322+
61323+extern spinlock_t grsec_audit_lock;
61324+
61325+extern rwlock_t grsec_exec_file_lock;
61326+
61327+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61328+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61329+ (tsk)->exec_file->f_vfsmnt) : "/")
61330+
61331+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61332+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61333+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61334+
61335+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61336+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
61337+ (tsk)->exec_file->f_vfsmnt) : "/")
61338+
61339+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61340+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61341+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61342+
61343+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
61344+
61345+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
61346+
61347+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
61348+ (task)->pid, (cred)->uid, \
61349+ (cred)->euid, (cred)->gid, (cred)->egid, \
61350+ gr_parent_task_fullpath(task), \
61351+ (task)->real_parent->comm, (task)->real_parent->pid, \
61352+ (pcred)->uid, (pcred)->euid, \
61353+ (pcred)->gid, (pcred)->egid
61354+
61355+#define GR_CHROOT_CAPS {{ \
61356+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
61357+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
61358+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
61359+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
61360+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
61361+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
61362+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
61363+
61364+#define security_learn(normal_msg,args...) \
61365+({ \
61366+ read_lock(&grsec_exec_file_lock); \
61367+ gr_add_learn_entry(normal_msg "\n", ## args); \
61368+ read_unlock(&grsec_exec_file_lock); \
61369+})
61370+
61371+enum {
61372+ GR_DO_AUDIT,
61373+ GR_DONT_AUDIT,
61374+ /* used for non-audit messages that we shouldn't kill the task on */
61375+ GR_DONT_AUDIT_GOOD
61376+};
61377+
61378+enum {
61379+ GR_TTYSNIFF,
61380+ GR_RBAC,
61381+ GR_RBAC_STR,
61382+ GR_STR_RBAC,
61383+ GR_RBAC_MODE2,
61384+ GR_RBAC_MODE3,
61385+ GR_FILENAME,
61386+ GR_SYSCTL_HIDDEN,
61387+ GR_NOARGS,
61388+ GR_ONE_INT,
61389+ GR_ONE_INT_TWO_STR,
61390+ GR_ONE_STR,
61391+ GR_STR_INT,
61392+ GR_TWO_STR_INT,
61393+ GR_TWO_INT,
61394+ GR_TWO_U64,
61395+ GR_THREE_INT,
61396+ GR_FIVE_INT_TWO_STR,
61397+ GR_TWO_STR,
61398+ GR_THREE_STR,
61399+ GR_FOUR_STR,
61400+ GR_STR_FILENAME,
61401+ GR_FILENAME_STR,
61402+ GR_FILENAME_TWO_INT,
61403+ GR_FILENAME_TWO_INT_STR,
61404+ GR_TEXTREL,
61405+ GR_PTRACE,
61406+ GR_RESOURCE,
61407+ GR_CAP,
61408+ GR_SIG,
61409+ GR_SIG2,
61410+ GR_CRASH1,
61411+ GR_CRASH2,
61412+ GR_PSACCT,
61413+ GR_RWXMAP
61414+};
61415+
61416+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
61417+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
61418+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
61419+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
61420+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
61421+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
61422+#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)
61423+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
61424+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
61425+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
61426+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
61427+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
61428+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
61429+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
61430+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
61431+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
61432+#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)
61433+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
61434+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
61435+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
61436+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
61437+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
61438+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
61439+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
61440+#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)
61441+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
61442+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
61443+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
61444+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
61445+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
61446+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
61447+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
61448+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
61449+#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)
61450+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
61451+
61452+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
61453+
61454+#endif
61455+
61456+#endif
61457diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
61458new file mode 100644
61459index 0000000..ae576a1
61460--- /dev/null
61461+++ b/include/linux/grmsg.h
61462@@ -0,0 +1,109 @@
61463+#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"
61464+#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"
61465+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
61466+#define GR_STOPMOD_MSG "denied modification of module state by "
61467+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
61468+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
61469+#define GR_IOPERM_MSG "denied use of ioperm() by "
61470+#define GR_IOPL_MSG "denied use of iopl() by "
61471+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
61472+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
61473+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
61474+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
61475+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
61476+#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"
61477+#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"
61478+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
61479+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
61480+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
61481+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
61482+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
61483+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
61484+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
61485+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
61486+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
61487+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
61488+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
61489+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
61490+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
61491+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
61492+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
61493+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
61494+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
61495+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
61496+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
61497+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
61498+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
61499+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
61500+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
61501+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
61502+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
61503+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
61504+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
61505+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
61506+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
61507+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
61508+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
61509+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
61510+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
61511+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
61512+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
61513+#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"
61514+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
61515+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
61516+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
61517+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
61518+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
61519+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
61520+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
61521+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
61522+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
61523+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
61524+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
61525+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
61526+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
61527+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
61528+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
61529+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
61530+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
61531+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
61532+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
61533+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
61534+#define GR_FAILFORK_MSG "failed fork with errno %s by "
61535+#define GR_NICE_CHROOT_MSG "denied priority change by "
61536+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
61537+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
61538+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
61539+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
61540+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
61541+#define GR_TIME_MSG "time set by "
61542+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
61543+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
61544+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
61545+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
61546+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
61547+#define GR_BIND_MSG "denied bind() by "
61548+#define GR_CONNECT_MSG "denied connect() by "
61549+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
61550+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
61551+#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"
61552+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
61553+#define GR_CAP_ACL_MSG "use of %s denied for "
61554+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
61555+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
61556+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
61557+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
61558+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
61559+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
61560+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
61561+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
61562+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
61563+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
61564+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
61565+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
61566+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
61567+#define GR_VM86_MSG "denied use of vm86 by "
61568+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
61569+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
61570+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
61571+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
61572diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
61573new file mode 100644
61574index 0000000..acd05db
61575--- /dev/null
61576+++ b/include/linux/grsecurity.h
61577@@ -0,0 +1,232 @@
61578+#ifndef GR_SECURITY_H
61579+#define GR_SECURITY_H
61580+#include <linux/fs.h>
61581+#include <linux/fs_struct.h>
61582+#include <linux/binfmts.h>
61583+#include <linux/gracl.h>
61584+
61585+/* notify of brain-dead configs */
61586+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61587+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
61588+#endif
61589+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
61590+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
61591+#endif
61592+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
61593+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
61594+#endif
61595+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
61596+#error "CONFIG_PAX enabled, but no PaX options are enabled."
61597+#endif
61598+
61599+#include <linux/compat.h>
61600+
61601+struct user_arg_ptr {
61602+#ifdef CONFIG_COMPAT
61603+ bool is_compat;
61604+#endif
61605+ union {
61606+ const char __user *const __user *native;
61607+#ifdef CONFIG_COMPAT
61608+ compat_uptr_t __user *compat;
61609+#endif
61610+ } ptr;
61611+};
61612+
61613+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
61614+void gr_handle_brute_check(void);
61615+void gr_handle_kernel_exploit(void);
61616+int gr_process_user_ban(void);
61617+
61618+char gr_roletype_to_char(void);
61619+
61620+int gr_acl_enable_at_secure(void);
61621+
61622+int gr_check_user_change(int real, int effective, int fs);
61623+int gr_check_group_change(int real, int effective, int fs);
61624+
61625+void gr_del_task_from_ip_table(struct task_struct *p);
61626+
61627+int gr_pid_is_chrooted(struct task_struct *p);
61628+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
61629+int gr_handle_chroot_nice(void);
61630+int gr_handle_chroot_sysctl(const int op);
61631+int gr_handle_chroot_setpriority(struct task_struct *p,
61632+ const int niceval);
61633+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
61634+int gr_handle_chroot_chroot(const struct dentry *dentry,
61635+ const struct vfsmount *mnt);
61636+void gr_handle_chroot_chdir(struct path *path);
61637+int gr_handle_chroot_chmod(const struct dentry *dentry,
61638+ const struct vfsmount *mnt, const int mode);
61639+int gr_handle_chroot_mknod(const struct dentry *dentry,
61640+ const struct vfsmount *mnt, const int mode);
61641+int gr_handle_chroot_mount(const struct dentry *dentry,
61642+ const struct vfsmount *mnt,
61643+ const char *dev_name);
61644+int gr_handle_chroot_pivot(void);
61645+int gr_handle_chroot_unix(const pid_t pid);
61646+
61647+int gr_handle_rawio(const struct inode *inode);
61648+
61649+void gr_handle_ioperm(void);
61650+void gr_handle_iopl(void);
61651+
61652+umode_t gr_acl_umask(void);
61653+
61654+int gr_tpe_allow(const struct file *file);
61655+
61656+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
61657+void gr_clear_chroot_entries(struct task_struct *task);
61658+
61659+void gr_log_forkfail(const int retval);
61660+void gr_log_timechange(void);
61661+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
61662+void gr_log_chdir(const struct dentry *dentry,
61663+ const struct vfsmount *mnt);
61664+void gr_log_chroot_exec(const struct dentry *dentry,
61665+ const struct vfsmount *mnt);
61666+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
61667+void gr_log_remount(const char *devname, const int retval);
61668+void gr_log_unmount(const char *devname, const int retval);
61669+void gr_log_mount(const char *from, const char *to, const int retval);
61670+void gr_log_textrel(struct vm_area_struct *vma);
61671+void gr_log_rwxmmap(struct file *file);
61672+void gr_log_rwxmprotect(struct file *file);
61673+
61674+int gr_handle_follow_link(const struct inode *parent,
61675+ const struct inode *inode,
61676+ const struct dentry *dentry,
61677+ const struct vfsmount *mnt);
61678+int gr_handle_fifo(const struct dentry *dentry,
61679+ const struct vfsmount *mnt,
61680+ const struct dentry *dir, const int flag,
61681+ const int acc_mode);
61682+int gr_handle_hardlink(const struct dentry *dentry,
61683+ const struct vfsmount *mnt,
61684+ struct inode *inode,
61685+ const int mode, const char *to);
61686+
61687+int gr_is_capable(const int cap);
61688+int gr_is_capable_nolog(const int cap);
61689+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
61690+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
61691+
61692+void gr_learn_resource(const struct task_struct *task, const int limit,
61693+ const unsigned long wanted, const int gt);
61694+void gr_copy_label(struct task_struct *tsk);
61695+void gr_handle_crash(struct task_struct *task, const int sig);
61696+int gr_handle_signal(const struct task_struct *p, const int sig);
61697+int gr_check_crash_uid(const uid_t uid);
61698+int gr_check_protected_task(const struct task_struct *task);
61699+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
61700+int gr_acl_handle_mmap(const struct file *file,
61701+ const unsigned long prot);
61702+int gr_acl_handle_mprotect(const struct file *file,
61703+ const unsigned long prot);
61704+int gr_check_hidden_task(const struct task_struct *tsk);
61705+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
61706+ const struct vfsmount *mnt);
61707+__u32 gr_acl_handle_utime(const struct dentry *dentry,
61708+ const struct vfsmount *mnt);
61709+__u32 gr_acl_handle_access(const struct dentry *dentry,
61710+ const struct vfsmount *mnt, const int fmode);
61711+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
61712+ const struct vfsmount *mnt, umode_t *mode);
61713+__u32 gr_acl_handle_chown(const struct dentry *dentry,
61714+ const struct vfsmount *mnt);
61715+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
61716+ const struct vfsmount *mnt);
61717+int gr_handle_ptrace(struct task_struct *task, const long request);
61718+int gr_handle_proc_ptrace(struct task_struct *task);
61719+__u32 gr_acl_handle_execve(const struct dentry *dentry,
61720+ const struct vfsmount *mnt);
61721+int gr_check_crash_exec(const struct file *filp);
61722+int gr_acl_is_enabled(void);
61723+void gr_set_kernel_label(struct task_struct *task);
61724+void gr_set_role_label(struct task_struct *task, const uid_t uid,
61725+ const gid_t gid);
61726+int gr_set_proc_label(const struct dentry *dentry,
61727+ const struct vfsmount *mnt,
61728+ const int unsafe_flags);
61729+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
61730+ const struct vfsmount *mnt);
61731+__u32 gr_acl_handle_open(const struct dentry *dentry,
61732+ const struct vfsmount *mnt, int acc_mode);
61733+__u32 gr_acl_handle_creat(const struct dentry *dentry,
61734+ const struct dentry *p_dentry,
61735+ const struct vfsmount *p_mnt,
61736+ int open_flags, int acc_mode, const int imode);
61737+void gr_handle_create(const struct dentry *dentry,
61738+ const struct vfsmount *mnt);
61739+void gr_handle_proc_create(const struct dentry *dentry,
61740+ const struct inode *inode);
61741+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
61742+ const struct dentry *parent_dentry,
61743+ const struct vfsmount *parent_mnt,
61744+ const int mode);
61745+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
61746+ const struct dentry *parent_dentry,
61747+ const struct vfsmount *parent_mnt);
61748+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
61749+ const struct vfsmount *mnt);
61750+void gr_handle_delete(const ino_t ino, const dev_t dev);
61751+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
61752+ const struct vfsmount *mnt);
61753+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
61754+ const struct dentry *parent_dentry,
61755+ const struct vfsmount *parent_mnt,
61756+ const char *from);
61757+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
61758+ const struct dentry *parent_dentry,
61759+ const struct vfsmount *parent_mnt,
61760+ const struct dentry *old_dentry,
61761+ const struct vfsmount *old_mnt, const char *to);
61762+int gr_acl_handle_rename(struct dentry *new_dentry,
61763+ struct dentry *parent_dentry,
61764+ const struct vfsmount *parent_mnt,
61765+ struct dentry *old_dentry,
61766+ struct inode *old_parent_inode,
61767+ struct vfsmount *old_mnt, const char *newname);
61768+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61769+ struct dentry *old_dentry,
61770+ struct dentry *new_dentry,
61771+ struct vfsmount *mnt, const __u8 replace);
61772+__u32 gr_check_link(const struct dentry *new_dentry,
61773+ const struct dentry *parent_dentry,
61774+ const struct vfsmount *parent_mnt,
61775+ const struct dentry *old_dentry,
61776+ const struct vfsmount *old_mnt);
61777+int gr_acl_handle_filldir(const struct file *file, const char *name,
61778+ const unsigned int namelen, const ino_t ino);
61779+
61780+__u32 gr_acl_handle_unix(const struct dentry *dentry,
61781+ const struct vfsmount *mnt);
61782+void gr_acl_handle_exit(void);
61783+void gr_acl_handle_psacct(struct task_struct *task, const long code);
61784+int gr_acl_handle_procpidmem(const struct task_struct *task);
61785+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
61786+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
61787+void gr_audit_ptrace(struct task_struct *task);
61788+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
61789+
61790+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
61791+
61792+#ifdef CONFIG_GRKERNSEC
61793+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
61794+void gr_handle_vm86(void);
61795+void gr_handle_mem_readwrite(u64 from, u64 to);
61796+
61797+void gr_log_badprocpid(const char *entry);
61798+
61799+extern int grsec_enable_dmesg;
61800+extern int grsec_disable_privio;
61801+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61802+extern int grsec_enable_chroot_findtask;
61803+#endif
61804+#ifdef CONFIG_GRKERNSEC_SETXID
61805+extern int grsec_enable_setxid;
61806+#endif
61807+#endif
61808+
61809+#endif
61810diff --git a/include/linux/grsock.h b/include/linux/grsock.h
61811new file mode 100644
61812index 0000000..e7ffaaf
61813--- /dev/null
61814+++ b/include/linux/grsock.h
61815@@ -0,0 +1,19 @@
61816+#ifndef __GRSOCK_H
61817+#define __GRSOCK_H
61818+
61819+extern void gr_attach_curr_ip(const struct sock *sk);
61820+extern int gr_handle_sock_all(const int family, const int type,
61821+ const int protocol);
61822+extern int gr_handle_sock_server(const struct sockaddr *sck);
61823+extern int gr_handle_sock_server_other(const struct sock *sck);
61824+extern int gr_handle_sock_client(const struct sockaddr *sck);
61825+extern int gr_search_connect(struct socket * sock,
61826+ struct sockaddr_in * addr);
61827+extern int gr_search_bind(struct socket * sock,
61828+ struct sockaddr_in * addr);
61829+extern int gr_search_listen(struct socket * sock);
61830+extern int gr_search_accept(struct socket * sock);
61831+extern int gr_search_socket(const int domain, const int type,
61832+ const int protocol);
61833+
61834+#endif
61835diff --git a/include/linux/hid.h b/include/linux/hid.h
61836index 3a95da6..51986f1 100644
61837--- a/include/linux/hid.h
61838+++ b/include/linux/hid.h
61839@@ -696,7 +696,7 @@ struct hid_ll_driver {
61840 unsigned int code, int value);
61841
61842 int (*parse)(struct hid_device *hdev);
61843-};
61844+} __no_const;
61845
61846 #define PM_HINT_FULLON 1<<5
61847 #define PM_HINT_NORMAL 1<<1
61848diff --git a/include/linux/highmem.h b/include/linux/highmem.h
61849index 3a93f73..b19d0b3 100644
61850--- a/include/linux/highmem.h
61851+++ b/include/linux/highmem.h
61852@@ -185,6 +185,18 @@ static inline void clear_highpage(struct page *page)
61853 kunmap_atomic(kaddr, KM_USER0);
61854 }
61855
61856+static inline void sanitize_highpage(struct page *page)
61857+{
61858+ void *kaddr;
61859+ unsigned long flags;
61860+
61861+ local_irq_save(flags);
61862+ kaddr = kmap_atomic(page, KM_CLEARPAGE);
61863+ clear_page(kaddr);
61864+ kunmap_atomic(kaddr, KM_CLEARPAGE);
61865+ local_irq_restore(flags);
61866+}
61867+
61868 static inline void zero_user_segments(struct page *page,
61869 unsigned start1, unsigned end1,
61870 unsigned start2, unsigned end2)
61871diff --git a/include/linux/i2c.h b/include/linux/i2c.h
61872index 8e25a91..551b161 100644
61873--- a/include/linux/i2c.h
61874+++ b/include/linux/i2c.h
61875@@ -364,6 +364,7 @@ struct i2c_algorithm {
61876 /* To determine what the adapter supports */
61877 u32 (*functionality) (struct i2c_adapter *);
61878 };
61879+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
61880
61881 /*
61882 * i2c_adapter is the structure used to identify a physical i2c bus along
61883diff --git a/include/linux/i2o.h b/include/linux/i2o.h
61884index a6deef4..c56a7f2 100644
61885--- a/include/linux/i2o.h
61886+++ b/include/linux/i2o.h
61887@@ -564,7 +564,7 @@ struct i2o_controller {
61888 struct i2o_device *exec; /* Executive */
61889 #if BITS_PER_LONG == 64
61890 spinlock_t context_list_lock; /* lock for context_list */
61891- atomic_t context_list_counter; /* needed for unique contexts */
61892+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
61893 struct list_head context_list; /* list of context id's
61894 and pointers */
61895 #endif
61896diff --git a/include/linux/if_team.h b/include/linux/if_team.h
61897index 58404b0..439ed95 100644
61898--- a/include/linux/if_team.h
61899+++ b/include/linux/if_team.h
61900@@ -64,6 +64,7 @@ struct team_mode_ops {
61901 void (*port_leave)(struct team *team, struct team_port *port);
61902 void (*port_change_mac)(struct team *team, struct team_port *port);
61903 };
61904+typedef struct team_mode_ops __no_const team_mode_ops_no_const;
61905
61906 enum team_option_type {
61907 TEAM_OPTION_TYPE_U32,
61908@@ -112,7 +113,7 @@ struct team {
61909 struct list_head option_list;
61910
61911 const struct team_mode *mode;
61912- struct team_mode_ops ops;
61913+ team_mode_ops_no_const ops;
61914 long mode_priv[TEAM_MODE_PRIV_LONGS];
61915 };
61916
61917diff --git a/include/linux/init.h b/include/linux/init.h
61918index 6b95109..4aca62c 100644
61919--- a/include/linux/init.h
61920+++ b/include/linux/init.h
61921@@ -294,13 +294,13 @@ void __init parse_early_options(char *cmdline);
61922
61923 /* Each module must use one module_init(). */
61924 #define module_init(initfn) \
61925- static inline initcall_t __inittest(void) \
61926+ static inline __used initcall_t __inittest(void) \
61927 { return initfn; } \
61928 int init_module(void) __attribute__((alias(#initfn)));
61929
61930 /* This is only required if you want to be unloadable. */
61931 #define module_exit(exitfn) \
61932- static inline exitcall_t __exittest(void) \
61933+ static inline __used exitcall_t __exittest(void) \
61934 { return exitfn; } \
61935 void cleanup_module(void) __attribute__((alias(#exitfn)));
61936
61937diff --git a/include/linux/init_task.h b/include/linux/init_task.h
61938index 9c66b1a..a3fdded 100644
61939--- a/include/linux/init_task.h
61940+++ b/include/linux/init_task.h
61941@@ -127,6 +127,12 @@ extern struct cred init_cred;
61942
61943 #define INIT_TASK_COMM "swapper"
61944
61945+#ifdef CONFIG_X86
61946+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
61947+#else
61948+#define INIT_TASK_THREAD_INFO
61949+#endif
61950+
61951 /*
61952 * INIT_TASK is used to set up the first task table, touch at
61953 * your own risk!. Base=0, limit=0x1fffff (=2MB)
61954@@ -165,6 +171,7 @@ extern struct cred init_cred;
61955 RCU_INIT_POINTER(.cred, &init_cred), \
61956 .comm = INIT_TASK_COMM, \
61957 .thread = INIT_THREAD, \
61958+ INIT_TASK_THREAD_INFO \
61959 .fs = &init_fs, \
61960 .files = &init_files, \
61961 .signal = &init_signals, \
61962diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
61963index e6ca56d..8583707 100644
61964--- a/include/linux/intel-iommu.h
61965+++ b/include/linux/intel-iommu.h
61966@@ -296,7 +296,7 @@ struct iommu_flush {
61967 u8 fm, u64 type);
61968 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
61969 unsigned int size_order, u64 type);
61970-};
61971+} __no_const;
61972
61973 enum {
61974 SR_DMAR_FECTL_REG,
61975diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
61976index a64b00e..464d8bc 100644
61977--- a/include/linux/interrupt.h
61978+++ b/include/linux/interrupt.h
61979@@ -441,7 +441,7 @@ enum
61980 /* map softirq index to softirq name. update 'softirq_to_name' in
61981 * kernel/softirq.c when adding a new softirq.
61982 */
61983-extern char *softirq_to_name[NR_SOFTIRQS];
61984+extern const char * const softirq_to_name[NR_SOFTIRQS];
61985
61986 /* softirq mask and active fields moved to irq_cpustat_t in
61987 * asm/hardirq.h to get better cache usage. KAO
61988@@ -449,12 +449,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
61989
61990 struct softirq_action
61991 {
61992- void (*action)(struct softirq_action *);
61993+ void (*action)(void);
61994 };
61995
61996 asmlinkage void do_softirq(void);
61997 asmlinkage void __do_softirq(void);
61998-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
61999+extern void open_softirq(int nr, void (*action)(void));
62000 extern void softirq_init(void);
62001 static inline void __raise_softirq_irqoff(unsigned int nr)
62002 {
62003diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
62004index 3875719..4cd454c 100644
62005--- a/include/linux/kallsyms.h
62006+++ b/include/linux/kallsyms.h
62007@@ -15,7 +15,8 @@
62008
62009 struct module;
62010
62011-#ifdef CONFIG_KALLSYMS
62012+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
62013+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62014 /* Lookup the address for a symbol. Returns 0 if not found. */
62015 unsigned long kallsyms_lookup_name(const char *name);
62016
62017@@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62018 /* Stupid that this does nothing, but I didn't create this mess. */
62019 #define __print_symbol(fmt, addr)
62020 #endif /*CONFIG_KALLSYMS*/
62021+#else /* when included by kallsyms.c, vsnprintf.c, or
62022+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62023+extern void __print_symbol(const char *fmt, unsigned long address);
62024+extern int sprint_backtrace(char *buffer, unsigned long address);
62025+extern int sprint_symbol(char *buffer, unsigned long address);
62026+const char *kallsyms_lookup(unsigned long addr,
62027+ unsigned long *symbolsize,
62028+ unsigned long *offset,
62029+ char **modname, char *namebuf);
62030+#endif
62031
62032 /* This macro allows us to keep printk typechecking */
62033 static __printf(1, 2)
62034diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62035index c4d2fc1..5df9c19 100644
62036--- a/include/linux/kgdb.h
62037+++ b/include/linux/kgdb.h
62038@@ -53,7 +53,7 @@ extern int kgdb_connected;
62039 extern int kgdb_io_module_registered;
62040
62041 extern atomic_t kgdb_setting_breakpoint;
62042-extern atomic_t kgdb_cpu_doing_single_step;
62043+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62044
62045 extern struct task_struct *kgdb_usethread;
62046 extern struct task_struct *kgdb_contthread;
62047@@ -252,7 +252,7 @@ struct kgdb_arch {
62048 void (*disable_hw_break)(struct pt_regs *regs);
62049 void (*remove_all_hw_break)(void);
62050 void (*correct_hw_break)(void);
62051-};
62052+} __do_const;
62053
62054 /**
62055 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62056@@ -277,7 +277,7 @@ struct kgdb_io {
62057 void (*pre_exception) (void);
62058 void (*post_exception) (void);
62059 int is_console;
62060-};
62061+} __do_const;
62062
62063 extern struct kgdb_arch arch_kgdb_ops;
62064
62065diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62066index 0fb48ef..1b680b2 100644
62067--- a/include/linux/kmod.h
62068+++ b/include/linux/kmod.h
62069@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62070 * usually useless though. */
62071 extern __printf(2, 3)
62072 int __request_module(bool wait, const char *name, ...);
62073+extern __printf(3, 4)
62074+int ___request_module(bool wait, char *param_name, const char *name, ...);
62075 #define request_module(mod...) __request_module(true, mod)
62076 #define request_module_nowait(mod...) __request_module(false, mod)
62077 #define try_then_request_module(x, mod...) \
62078diff --git a/include/linux/kref.h b/include/linux/kref.h
62079index 9c07dce..a92fa71 100644
62080--- a/include/linux/kref.h
62081+++ b/include/linux/kref.h
62082@@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
62083 static inline int kref_sub(struct kref *kref, unsigned int count,
62084 void (*release)(struct kref *kref))
62085 {
62086- WARN_ON(release == NULL);
62087+ BUG_ON(release == NULL);
62088
62089 if (atomic_sub_and_test((int) count, &kref->refcount)) {
62090 release(kref);
62091diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62092index 4c4e83d..695674f 100644
62093--- a/include/linux/kvm_host.h
62094+++ b/include/linux/kvm_host.h
62095@@ -326,7 +326,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62096 void vcpu_load(struct kvm_vcpu *vcpu);
62097 void vcpu_put(struct kvm_vcpu *vcpu);
62098
62099-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62100+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62101 struct module *module);
62102 void kvm_exit(void);
62103
62104@@ -485,7 +485,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62105 struct kvm_guest_debug *dbg);
62106 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62107
62108-int kvm_arch_init(void *opaque);
62109+int kvm_arch_init(const void *opaque);
62110 void kvm_arch_exit(void);
62111
62112 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62113diff --git a/include/linux/libata.h b/include/linux/libata.h
62114index cafc09a..d7e7829 100644
62115--- a/include/linux/libata.h
62116+++ b/include/linux/libata.h
62117@@ -909,7 +909,7 @@ struct ata_port_operations {
62118 * fields must be pointers.
62119 */
62120 const struct ata_port_operations *inherits;
62121-};
62122+} __do_const;
62123
62124 struct ata_port_info {
62125 unsigned long flags;
62126diff --git a/include/linux/mca.h b/include/linux/mca.h
62127index 3797270..7765ede 100644
62128--- a/include/linux/mca.h
62129+++ b/include/linux/mca.h
62130@@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
62131 int region);
62132 void * (*mca_transform_memory)(struct mca_device *,
62133 void *memory);
62134-};
62135+} __no_const;
62136
62137 struct mca_bus {
62138 u64 default_dma_mask;
62139diff --git a/include/linux/memory.h b/include/linux/memory.h
62140index 1ac7f6e..a5794d0 100644
62141--- a/include/linux/memory.h
62142+++ b/include/linux/memory.h
62143@@ -143,7 +143,7 @@ struct memory_accessor {
62144 size_t count);
62145 ssize_t (*write)(struct memory_accessor *, const char *buf,
62146 off_t offset, size_t count);
62147-};
62148+} __no_const;
62149
62150 /*
62151 * Kernel text modification mutex, used for code patching. Users of this lock
62152diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62153index 9970337..9444122 100644
62154--- a/include/linux/mfd/abx500.h
62155+++ b/include/linux/mfd/abx500.h
62156@@ -188,6 +188,7 @@ struct abx500_ops {
62157 int (*event_registers_startup_state_get) (struct device *, u8 *);
62158 int (*startup_irq_enabled) (struct device *, unsigned int);
62159 };
62160+typedef struct abx500_ops __no_const abx500_ops_no_const;
62161
62162 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62163 void abx500_remove_ops(struct device *dev);
62164diff --git a/include/linux/mm.h b/include/linux/mm.h
62165index 17b27cd..baea141 100644
62166--- a/include/linux/mm.h
62167+++ b/include/linux/mm.h
62168@@ -115,7 +115,14 @@ extern unsigned int kobjsize(const void *objp);
62169
62170 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62171 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62172+
62173+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62174+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62175+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62176+#else
62177 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62178+#endif
62179+
62180 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62181 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62182
62183@@ -1012,34 +1019,6 @@ int set_page_dirty(struct page *page);
62184 int set_page_dirty_lock(struct page *page);
62185 int clear_page_dirty_for_io(struct page *page);
62186
62187-/* Is the vma a continuation of the stack vma above it? */
62188-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62189-{
62190- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62191-}
62192-
62193-static inline int stack_guard_page_start(struct vm_area_struct *vma,
62194- unsigned long addr)
62195-{
62196- return (vma->vm_flags & VM_GROWSDOWN) &&
62197- (vma->vm_start == addr) &&
62198- !vma_growsdown(vma->vm_prev, addr);
62199-}
62200-
62201-/* Is the vma a continuation of the stack vma below it? */
62202-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62203-{
62204- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62205-}
62206-
62207-static inline int stack_guard_page_end(struct vm_area_struct *vma,
62208- unsigned long addr)
62209-{
62210- return (vma->vm_flags & VM_GROWSUP) &&
62211- (vma->vm_end == addr) &&
62212- !vma_growsup(vma->vm_next, addr);
62213-}
62214-
62215 extern unsigned long move_page_tables(struct vm_area_struct *vma,
62216 unsigned long old_addr, struct vm_area_struct *new_vma,
62217 unsigned long new_addr, unsigned long len);
62218@@ -1134,6 +1113,15 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
62219 }
62220 #endif
62221
62222+#ifdef CONFIG_MMU
62223+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62224+#else
62225+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62226+{
62227+ return __pgprot(0);
62228+}
62229+#endif
62230+
62231 int vma_wants_writenotify(struct vm_area_struct *vma);
62232
62233 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62234@@ -1152,8 +1140,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
62235 {
62236 return 0;
62237 }
62238+
62239+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
62240+ unsigned long address)
62241+{
62242+ return 0;
62243+}
62244 #else
62245 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62246+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62247 #endif
62248
62249 #ifdef __PAGETABLE_PMD_FOLDED
62250@@ -1162,8 +1157,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
62251 {
62252 return 0;
62253 }
62254+
62255+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
62256+ unsigned long address)
62257+{
62258+ return 0;
62259+}
62260 #else
62261 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
62262+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
62263 #endif
62264
62265 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
62266@@ -1181,11 +1183,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
62267 NULL: pud_offset(pgd, address);
62268 }
62269
62270+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
62271+{
62272+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
62273+ NULL: pud_offset(pgd, address);
62274+}
62275+
62276 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
62277 {
62278 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
62279 NULL: pmd_offset(pud, address);
62280 }
62281+
62282+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
62283+{
62284+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
62285+ NULL: pmd_offset(pud, address);
62286+}
62287 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
62288
62289 #if USE_SPLIT_PTLOCKS
62290@@ -1409,6 +1423,7 @@ out:
62291 }
62292
62293 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62294+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62295
62296 extern unsigned long do_brk(unsigned long, unsigned long);
62297
62298@@ -1466,6 +1481,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62299 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62300 struct vm_area_struct **pprev);
62301
62302+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62303+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62304+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62305+
62306 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62307 NULL if none. Assume start_addr < end_addr. */
62308 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62309@@ -1494,15 +1513,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
62310 return vma;
62311 }
62312
62313-#ifdef CONFIG_MMU
62314-pgprot_t vm_get_page_prot(unsigned long vm_flags);
62315-#else
62316-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
62317-{
62318- return __pgprot(0);
62319-}
62320-#endif
62321-
62322 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
62323 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
62324 unsigned long pfn, unsigned long size, pgprot_t);
62325@@ -1606,7 +1616,7 @@ extern int unpoison_memory(unsigned long pfn);
62326 extern int sysctl_memory_failure_early_kill;
62327 extern int sysctl_memory_failure_recovery;
62328 extern void shake_page(struct page *p, int access);
62329-extern atomic_long_t mce_bad_pages;
62330+extern atomic_long_unchecked_t mce_bad_pages;
62331 extern int soft_offline_page(struct page *page, int flags);
62332
62333 extern void dump_page(struct page *page);
62334@@ -1637,5 +1647,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
62335 static inline bool page_is_guard(struct page *page) { return false; }
62336 #endif /* CONFIG_DEBUG_PAGEALLOC */
62337
62338+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62339+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
62340+#else
62341+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
62342+#endif
62343+
62344 #endif /* __KERNEL__ */
62345 #endif /* _LINUX_MM_H */
62346diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
62347index 3cc3062..efeaeb7 100644
62348--- a/include/linux/mm_types.h
62349+++ b/include/linux/mm_types.h
62350@@ -252,6 +252,8 @@ struct vm_area_struct {
62351 #ifdef CONFIG_NUMA
62352 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
62353 #endif
62354+
62355+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
62356 };
62357
62358 struct core_thread {
62359@@ -326,7 +328,7 @@ struct mm_struct {
62360 unsigned long def_flags;
62361 unsigned long nr_ptes; /* Page table pages */
62362 unsigned long start_code, end_code, start_data, end_data;
62363- unsigned long start_brk, brk, start_stack;
62364+ unsigned long brk_gap, start_brk, brk, start_stack;
62365 unsigned long arg_start, arg_end, env_start, env_end;
62366
62367 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
62368@@ -388,6 +390,24 @@ struct mm_struct {
62369 #ifdef CONFIG_CPUMASK_OFFSTACK
62370 struct cpumask cpumask_allocation;
62371 #endif
62372+
62373+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS) || defined(CONFIG_PAX_HAVE_ACL_FLAGS) || defined(CONFIG_PAX_HOOK_ACL_FLAGS)
62374+ unsigned long pax_flags;
62375+#endif
62376+
62377+#ifdef CONFIG_PAX_DLRESOLVE
62378+ unsigned long call_dl_resolve;
62379+#endif
62380+
62381+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
62382+ unsigned long call_syscall;
62383+#endif
62384+
62385+#ifdef CONFIG_PAX_ASLR
62386+ unsigned long delta_mmap; /* randomized offset */
62387+ unsigned long delta_stack; /* randomized offset */
62388+#endif
62389+
62390 };
62391
62392 static inline void mm_init_cpumask(struct mm_struct *mm)
62393diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
62394index 1d1b1e1..2a13c78 100644
62395--- a/include/linux/mmu_notifier.h
62396+++ b/include/linux/mmu_notifier.h
62397@@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
62398 */
62399 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
62400 ({ \
62401- pte_t __pte; \
62402+ pte_t ___pte; \
62403 struct vm_area_struct *___vma = __vma; \
62404 unsigned long ___address = __address; \
62405- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
62406+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
62407 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
62408- __pte; \
62409+ ___pte; \
62410 })
62411
62412 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
62413diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
62414index 650ba2f..af0a58c 100644
62415--- a/include/linux/mmzone.h
62416+++ b/include/linux/mmzone.h
62417@@ -379,7 +379,7 @@ struct zone {
62418 unsigned long flags; /* zone flags, see below */
62419
62420 /* Zone statistics */
62421- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62422+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62423
62424 /*
62425 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
62426diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
62427index 83ac071..2656e0e 100644
62428--- a/include/linux/mod_devicetable.h
62429+++ b/include/linux/mod_devicetable.h
62430@@ -12,7 +12,7 @@
62431 typedef unsigned long kernel_ulong_t;
62432 #endif
62433
62434-#define PCI_ANY_ID (~0)
62435+#define PCI_ANY_ID ((__u16)~0)
62436
62437 struct pci_device_id {
62438 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
62439@@ -131,7 +131,7 @@ struct usb_device_id {
62440 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
62441 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
62442
62443-#define HID_ANY_ID (~0)
62444+#define HID_ANY_ID (~0U)
62445
62446 struct hid_device_id {
62447 __u16 bus;
62448diff --git a/include/linux/module.h b/include/linux/module.h
62449index 4598bf0..e069d7f 100644
62450--- a/include/linux/module.h
62451+++ b/include/linux/module.h
62452@@ -17,6 +17,7 @@
62453 #include <linux/moduleparam.h>
62454 #include <linux/tracepoint.h>
62455 #include <linux/export.h>
62456+#include <linux/fs.h>
62457
62458 #include <linux/percpu.h>
62459 #include <asm/module.h>
62460@@ -275,19 +276,16 @@ struct module
62461 int (*init)(void);
62462
62463 /* If this is non-NULL, vfree after init() returns */
62464- void *module_init;
62465+ void *module_init_rx, *module_init_rw;
62466
62467 /* Here is the actual code + data, vfree'd on unload. */
62468- void *module_core;
62469+ void *module_core_rx, *module_core_rw;
62470
62471 /* Here are the sizes of the init and core sections */
62472- unsigned int init_size, core_size;
62473+ unsigned int init_size_rw, core_size_rw;
62474
62475 /* The size of the executable code in each section. */
62476- unsigned int init_text_size, core_text_size;
62477-
62478- /* Size of RO sections of the module (text+rodata) */
62479- unsigned int init_ro_size, core_ro_size;
62480+ unsigned int init_size_rx, core_size_rx;
62481
62482 /* Arch-specific module values */
62483 struct mod_arch_specific arch;
62484@@ -343,6 +341,10 @@ struct module
62485 #ifdef CONFIG_EVENT_TRACING
62486 struct ftrace_event_call **trace_events;
62487 unsigned int num_trace_events;
62488+ struct file_operations trace_id;
62489+ struct file_operations trace_enable;
62490+ struct file_operations trace_format;
62491+ struct file_operations trace_filter;
62492 #endif
62493 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
62494 unsigned int num_ftrace_callsites;
62495@@ -390,16 +392,46 @@ bool is_module_address(unsigned long addr);
62496 bool is_module_percpu_address(unsigned long addr);
62497 bool is_module_text_address(unsigned long addr);
62498
62499+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
62500+{
62501+
62502+#ifdef CONFIG_PAX_KERNEXEC
62503+ if (ktla_ktva(addr) >= (unsigned long)start &&
62504+ ktla_ktva(addr) < (unsigned long)start + size)
62505+ return 1;
62506+#endif
62507+
62508+ return ((void *)addr >= start && (void *)addr < start + size);
62509+}
62510+
62511+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
62512+{
62513+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
62514+}
62515+
62516+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
62517+{
62518+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
62519+}
62520+
62521+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
62522+{
62523+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
62524+}
62525+
62526+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
62527+{
62528+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
62529+}
62530+
62531 static inline int within_module_core(unsigned long addr, struct module *mod)
62532 {
62533- return (unsigned long)mod->module_core <= addr &&
62534- addr < (unsigned long)mod->module_core + mod->core_size;
62535+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
62536 }
62537
62538 static inline int within_module_init(unsigned long addr, struct module *mod)
62539 {
62540- return (unsigned long)mod->module_init <= addr &&
62541- addr < (unsigned long)mod->module_init + mod->init_size;
62542+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
62543 }
62544
62545 /* Search for module by name: must hold module_mutex. */
62546diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
62547index b2be02e..0a61daa 100644
62548--- a/include/linux/moduleloader.h
62549+++ b/include/linux/moduleloader.h
62550@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
62551 sections. Returns NULL on failure. */
62552 void *module_alloc(unsigned long size);
62553
62554+#ifdef CONFIG_PAX_KERNEXEC
62555+void *module_alloc_exec(unsigned long size) __size_overflow(1);
62556+#else
62557+#define module_alloc_exec(x) module_alloc(x)
62558+#endif
62559+
62560 /* Free memory returned from module_alloc. */
62561 void module_free(struct module *mod, void *module_region);
62562
62563+#ifdef CONFIG_PAX_KERNEXEC
62564+void module_free_exec(struct module *mod, void *module_region);
62565+#else
62566+#define module_free_exec(x, y) module_free((x), (y))
62567+#endif
62568+
62569 /* Apply the given relocation to the (simplified) ELF. Return -error
62570 or 0. */
62571 int apply_relocate(Elf_Shdr *sechdrs,
62572diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
62573index c47f4d6..23f9bdb 100644
62574--- a/include/linux/moduleparam.h
62575+++ b/include/linux/moduleparam.h
62576@@ -260,7 +260,7 @@ static inline void __kernel_param_unlock(void)
62577 * @len is usually just sizeof(string).
62578 */
62579 #define module_param_string(name, string, len, perm) \
62580- static const struct kparam_string __param_string_##name \
62581+ static const struct kparam_string __param_string_##name __used \
62582 = { len, string }; \
62583 __module_param_call(MODULE_PARAM_PREFIX, name, \
62584 &param_ops_string, \
62585@@ -396,7 +396,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
62586 */
62587 #define module_param_array_named(name, array, type, nump, perm) \
62588 param_check_##type(name, &(array)[0]); \
62589- static const struct kparam_array __param_arr_##name \
62590+ static const struct kparam_array __param_arr_##name __used \
62591 = { .max = ARRAY_SIZE(array), .num = nump, \
62592 .ops = &param_ops_##type, \
62593 .elemsize = sizeof(array[0]), .elem = array }; \
62594diff --git a/include/linux/namei.h b/include/linux/namei.h
62595index ffc0213..2c1f2cb 100644
62596--- a/include/linux/namei.h
62597+++ b/include/linux/namei.h
62598@@ -24,7 +24,7 @@ struct nameidata {
62599 unsigned seq;
62600 int last_type;
62601 unsigned depth;
62602- char *saved_names[MAX_NESTED_LINKS + 1];
62603+ const char *saved_names[MAX_NESTED_LINKS + 1];
62604
62605 /* Intent data */
62606 union {
62607@@ -94,12 +94,12 @@ extern int follow_up(struct path *);
62608 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
62609 extern void unlock_rename(struct dentry *, struct dentry *);
62610
62611-static inline void nd_set_link(struct nameidata *nd, char *path)
62612+static inline void nd_set_link(struct nameidata *nd, const char *path)
62613 {
62614 nd->saved_names[nd->depth] = path;
62615 }
62616
62617-static inline char *nd_get_link(struct nameidata *nd)
62618+static inline const char *nd_get_link(const struct nameidata *nd)
62619 {
62620 return nd->saved_names[nd->depth];
62621 }
62622diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
62623index 7e472b7..212d381 100644
62624--- a/include/linux/netdevice.h
62625+++ b/include/linux/netdevice.h
62626@@ -1002,6 +1002,7 @@ struct net_device_ops {
62627 int (*ndo_neigh_construct)(struct neighbour *n);
62628 void (*ndo_neigh_destroy)(struct neighbour *n);
62629 };
62630+typedef struct net_device_ops __no_const net_device_ops_no_const;
62631
62632 /*
62633 * The DEVICE structure.
62634@@ -1063,7 +1064,7 @@ struct net_device {
62635 int iflink;
62636
62637 struct net_device_stats stats;
62638- atomic_long_t rx_dropped; /* dropped packets by core network
62639+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
62640 * Do not use this in drivers.
62641 */
62642
62643diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
62644new file mode 100644
62645index 0000000..33f4af8
62646--- /dev/null
62647+++ b/include/linux/netfilter/xt_gradm.h
62648@@ -0,0 +1,9 @@
62649+#ifndef _LINUX_NETFILTER_XT_GRADM_H
62650+#define _LINUX_NETFILTER_XT_GRADM_H 1
62651+
62652+struct xt_gradm_mtinfo {
62653+ __u16 flags;
62654+ __u16 invflags;
62655+};
62656+
62657+#endif
62658diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
62659index c65a18a..0c05f3a 100644
62660--- a/include/linux/of_pdt.h
62661+++ b/include/linux/of_pdt.h
62662@@ -32,7 +32,7 @@ struct of_pdt_ops {
62663
62664 /* return 0 on success; fill in 'len' with number of bytes in path */
62665 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
62666-};
62667+} __no_const;
62668
62669 extern void *prom_early_alloc(unsigned long size);
62670
62671diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
62672index a4c5624..79d6d88 100644
62673--- a/include/linux/oprofile.h
62674+++ b/include/linux/oprofile.h
62675@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
62676 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
62677 char const * name, ulong * val);
62678
62679-/** Create a file for read-only access to an atomic_t. */
62680+/** Create a file for read-only access to an atomic_unchecked_t. */
62681 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
62682- char const * name, atomic_t * val);
62683+ char const * name, atomic_unchecked_t * val);
62684
62685 /** create a directory */
62686 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
62687diff --git a/include/linux/padata.h b/include/linux/padata.h
62688index 4633b2f..988bc08 100644
62689--- a/include/linux/padata.h
62690+++ b/include/linux/padata.h
62691@@ -129,7 +129,7 @@ struct parallel_data {
62692 struct padata_instance *pinst;
62693 struct padata_parallel_queue __percpu *pqueue;
62694 struct padata_serial_queue __percpu *squeue;
62695- atomic_t seq_nr;
62696+ atomic_unchecked_t seq_nr;
62697 atomic_t reorder_objects;
62698 atomic_t refcnt;
62699 unsigned int max_seq_nr;
62700diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
62701index abb2776..d8b8e15 100644
62702--- a/include/linux/perf_event.h
62703+++ b/include/linux/perf_event.h
62704@@ -750,8 +750,8 @@ struct perf_event {
62705
62706 enum perf_event_active_state state;
62707 unsigned int attach_state;
62708- local64_t count;
62709- atomic64_t child_count;
62710+ local64_t count; /* PaX: fix it one day */
62711+ atomic64_unchecked_t child_count;
62712
62713 /*
62714 * These are the total time in nanoseconds that the event
62715@@ -802,8 +802,8 @@ struct perf_event {
62716 * These accumulate total time (in nanoseconds) that children
62717 * events have been enabled and running, respectively.
62718 */
62719- atomic64_t child_total_time_enabled;
62720- atomic64_t child_total_time_running;
62721+ atomic64_unchecked_t child_total_time_enabled;
62722+ atomic64_unchecked_t child_total_time_running;
62723
62724 /*
62725 * Protect attach/detach and child_list:
62726diff --git a/include/linux/personality.h b/include/linux/personality.h
62727index 8fc7dd1a..c19d89e 100644
62728--- a/include/linux/personality.h
62729+++ b/include/linux/personality.h
62730@@ -44,6 +44,7 @@ enum {
62731 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
62732 ADDR_NO_RANDOMIZE | \
62733 ADDR_COMPAT_LAYOUT | \
62734+ ADDR_LIMIT_3GB | \
62735 MMAP_PAGE_ZERO)
62736
62737 /*
62738diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
62739index 0072a53..c5dcca5 100644
62740--- a/include/linux/pipe_fs_i.h
62741+++ b/include/linux/pipe_fs_i.h
62742@@ -47,9 +47,9 @@ struct pipe_buffer {
62743 struct pipe_inode_info {
62744 wait_queue_head_t wait;
62745 unsigned int nrbufs, curbuf, buffers;
62746- unsigned int readers;
62747- unsigned int writers;
62748- unsigned int waiting_writers;
62749+ atomic_t readers;
62750+ atomic_t writers;
62751+ atomic_t waiting_writers;
62752 unsigned int r_counter;
62753 unsigned int w_counter;
62754 struct page *tmp_page;
62755diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
62756index 609daae..5392427 100644
62757--- a/include/linux/pm_runtime.h
62758+++ b/include/linux/pm_runtime.h
62759@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
62760
62761 static inline void pm_runtime_mark_last_busy(struct device *dev)
62762 {
62763- ACCESS_ONCE(dev->power.last_busy) = jiffies;
62764+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
62765 }
62766
62767 #else /* !CONFIG_PM_RUNTIME */
62768diff --git a/include/linux/poison.h b/include/linux/poison.h
62769index 2110a81..13a11bb 100644
62770--- a/include/linux/poison.h
62771+++ b/include/linux/poison.h
62772@@ -19,8 +19,8 @@
62773 * under normal circumstances, used to verify that nobody uses
62774 * non-initialized list entries.
62775 */
62776-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
62777-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
62778+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
62779+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
62780
62781 /********** include/linux/timer.h **********/
62782 /*
62783diff --git a/include/linux/preempt.h b/include/linux/preempt.h
62784index 58969b2..ead129b 100644
62785--- a/include/linux/preempt.h
62786+++ b/include/linux/preempt.h
62787@@ -123,7 +123,7 @@ struct preempt_ops {
62788 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
62789 void (*sched_out)(struct preempt_notifier *notifier,
62790 struct task_struct *next);
62791-};
62792+} __no_const;
62793
62794 /**
62795 * preempt_notifier - key for installing preemption notifiers
62796diff --git a/include/linux/printk.h b/include/linux/printk.h
62797index f0e22f7..82dd544 100644
62798--- a/include/linux/printk.h
62799+++ b/include/linux/printk.h
62800@@ -94,6 +94,8 @@ void early_printk(const char *fmt, ...);
62801 extern int printk_needs_cpu(int cpu);
62802 extern void printk_tick(void);
62803
62804+extern int kptr_restrict;
62805+
62806 #ifdef CONFIG_PRINTK
62807 asmlinkage __printf(1, 0)
62808 int vprintk(const char *fmt, va_list args);
62809@@ -112,7 +114,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
62810
62811 extern int printk_delay_msec;
62812 extern int dmesg_restrict;
62813-extern int kptr_restrict;
62814
62815 void log_buf_kexec_setup(void);
62816 void __init setup_log_buf(int early);
62817diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
62818index 85c5073..51fac8b 100644
62819--- a/include/linux/proc_fs.h
62820+++ b/include/linux/proc_fs.h
62821@@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
62822 return proc_create_data(name, mode, parent, proc_fops, NULL);
62823 }
62824
62825+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
62826+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
62827+{
62828+#ifdef CONFIG_GRKERNSEC_PROC_USER
62829+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
62830+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62831+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
62832+#else
62833+ return proc_create_data(name, mode, parent, proc_fops, NULL);
62834+#endif
62835+}
62836+
62837 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
62838 umode_t mode, struct proc_dir_entry *base,
62839 read_proc_t *read_proc, void * data)
62840@@ -258,7 +270,7 @@ union proc_op {
62841 int (*proc_show)(struct seq_file *m,
62842 struct pid_namespace *ns, struct pid *pid,
62843 struct task_struct *task);
62844-};
62845+} __no_const;
62846
62847 struct ctl_table_header;
62848 struct ctl_table;
62849diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
62850index c2f1f6a..6fdb196 100644
62851--- a/include/linux/ptrace.h
62852+++ b/include/linux/ptrace.h
62853@@ -199,9 +199,10 @@ static inline void ptrace_event(int event, unsigned long message)
62854 if (unlikely(ptrace_event_enabled(current, event))) {
62855 current->ptrace_message = message;
62856 ptrace_notify((event << 8) | SIGTRAP);
62857- } else if (event == PTRACE_EVENT_EXEC && unlikely(current->ptrace)) {
62858+ } else if (event == PTRACE_EVENT_EXEC) {
62859 /* legacy EXEC report via SIGTRAP */
62860- send_sig(SIGTRAP, current, 0);
62861+ if ((current->ptrace & (PT_PTRACED|PT_SEIZED)) == PT_PTRACED)
62862+ send_sig(SIGTRAP, current, 0);
62863 }
62864 }
62865
62866diff --git a/include/linux/random.h b/include/linux/random.h
62867index 8f74538..02a1012 100644
62868--- a/include/linux/random.h
62869+++ b/include/linux/random.h
62870@@ -69,12 +69,17 @@ void srandom32(u32 seed);
62871
62872 u32 prandom32(struct rnd_state *);
62873
62874+static inline unsigned long pax_get_random_long(void)
62875+{
62876+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
62877+}
62878+
62879 /*
62880 * Handle minimum values for seeds
62881 */
62882 static inline u32 __seed(u32 x, u32 m)
62883 {
62884- return (x < m) ? x + m : x;
62885+ return (x <= m) ? x + m + 1 : x;
62886 }
62887
62888 /**
62889diff --git a/include/linux/reboot.h b/include/linux/reboot.h
62890index e0879a7..a12f962 100644
62891--- a/include/linux/reboot.h
62892+++ b/include/linux/reboot.h
62893@@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
62894 * Architecture-specific implementations of sys_reboot commands.
62895 */
62896
62897-extern void machine_restart(char *cmd);
62898-extern void machine_halt(void);
62899-extern void machine_power_off(void);
62900+extern void machine_restart(char *cmd) __noreturn;
62901+extern void machine_halt(void) __noreturn;
62902+extern void machine_power_off(void) __noreturn;
62903
62904 extern void machine_shutdown(void);
62905 struct pt_regs;
62906@@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
62907 */
62908
62909 extern void kernel_restart_prepare(char *cmd);
62910-extern void kernel_restart(char *cmd);
62911-extern void kernel_halt(void);
62912-extern void kernel_power_off(void);
62913+extern void kernel_restart(char *cmd) __noreturn;
62914+extern void kernel_halt(void) __noreturn;
62915+extern void kernel_power_off(void) __noreturn;
62916
62917 extern int C_A_D; /* for sysctl */
62918 void ctrl_alt_del(void);
62919@@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
62920 * Emergency restart, callable from an interrupt handler.
62921 */
62922
62923-extern void emergency_restart(void);
62924+extern void emergency_restart(void) __noreturn;
62925 #include <asm/emergency-restart.h>
62926
62927 #endif
62928diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
62929index 2213ddc..650212a 100644
62930--- a/include/linux/reiserfs_fs.h
62931+++ b/include/linux/reiserfs_fs.h
62932@@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
62933 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
62934
62935 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
62936-#define get_generation(s) atomic_read (&fs_generation(s))
62937+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
62938 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
62939 #define __fs_changed(gen,s) (gen != get_generation (s))
62940 #define fs_changed(gen,s) \
62941diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
62942index 8c9e85c..1698e9a 100644
62943--- a/include/linux/reiserfs_fs_sb.h
62944+++ b/include/linux/reiserfs_fs_sb.h
62945@@ -386,7 +386,7 @@ struct reiserfs_sb_info {
62946 /* Comment? -Hans */
62947 wait_queue_head_t s_wait;
62948 /* To be obsoleted soon by per buffer seals.. -Hans */
62949- atomic_t s_generation_counter; // increased by one every time the
62950+ atomic_unchecked_t s_generation_counter; // increased by one every time the
62951 // tree gets re-balanced
62952 unsigned long s_properties; /* File system properties. Currently holds
62953 on-disk FS format */
62954diff --git a/include/linux/relay.h b/include/linux/relay.h
62955index a822fd7..62b70f6 100644
62956--- a/include/linux/relay.h
62957+++ b/include/linux/relay.h
62958@@ -159,7 +159,7 @@ struct rchan_callbacks
62959 * The callback should return 0 if successful, negative if not.
62960 */
62961 int (*remove_buf_file)(struct dentry *dentry);
62962-};
62963+} __no_const;
62964
62965 /*
62966 * CONFIG_RELAY kernel API, kernel/relay.c
62967diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
62968index c6c6084..5bf1212 100644
62969--- a/include/linux/rfkill.h
62970+++ b/include/linux/rfkill.h
62971@@ -147,6 +147,7 @@ struct rfkill_ops {
62972 void (*query)(struct rfkill *rfkill, void *data);
62973 int (*set_block)(void *data, bool blocked);
62974 };
62975+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
62976
62977 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
62978 /**
62979diff --git a/include/linux/rio.h b/include/linux/rio.h
62980index 4d50611..c6858a2 100644
62981--- a/include/linux/rio.h
62982+++ b/include/linux/rio.h
62983@@ -315,7 +315,7 @@ struct rio_ops {
62984 int mbox, void *buffer, size_t len);
62985 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
62986 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
62987-};
62988+} __no_const;
62989
62990 #define RIO_RESOURCE_MEM 0x00000100
62991 #define RIO_RESOURCE_DOORBELL 0x00000200
62992diff --git a/include/linux/rmap.h b/include/linux/rmap.h
62993index 1cdd62a..e399f0d 100644
62994--- a/include/linux/rmap.h
62995+++ b/include/linux/rmap.h
62996@@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
62997 void anon_vma_init(void); /* create anon_vma_cachep */
62998 int anon_vma_prepare(struct vm_area_struct *);
62999 void unlink_anon_vmas(struct vm_area_struct *);
63000-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63001+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63002 void anon_vma_moveto_tail(struct vm_area_struct *);
63003-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63004+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63005 void __anon_vma_link(struct vm_area_struct *);
63006
63007 static inline void anon_vma_merge(struct vm_area_struct *vma,
63008diff --git a/include/linux/sched.h b/include/linux/sched.h
63009index 0657368..765f70f 100644
63010--- a/include/linux/sched.h
63011+++ b/include/linux/sched.h
63012@@ -101,6 +101,7 @@ struct bio_list;
63013 struct fs_struct;
63014 struct perf_event_context;
63015 struct blk_plug;
63016+struct linux_binprm;
63017
63018 /*
63019 * List of flags we want to share for kernel threads,
63020@@ -382,10 +383,13 @@ struct user_namespace;
63021 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63022
63023 extern int sysctl_max_map_count;
63024+extern unsigned long sysctl_heap_stack_gap;
63025
63026 #include <linux/aio.h>
63027
63028 #ifdef CONFIG_MMU
63029+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63030+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63031 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63032 extern unsigned long
63033 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63034@@ -631,6 +635,17 @@ struct signal_struct {
63035 #ifdef CONFIG_TASKSTATS
63036 struct taskstats *stats;
63037 #endif
63038+
63039+#ifdef CONFIG_GRKERNSEC
63040+ u32 curr_ip;
63041+ u32 saved_ip;
63042+ u32 gr_saddr;
63043+ u32 gr_daddr;
63044+ u16 gr_sport;
63045+ u16 gr_dport;
63046+ u8 used_accept:1;
63047+#endif
63048+
63049 #ifdef CONFIG_AUDIT
63050 unsigned audit_tty;
63051 struct tty_audit_buf *tty_audit_buf;
63052@@ -714,6 +729,11 @@ struct user_struct {
63053 struct key *session_keyring; /* UID's default session keyring */
63054 #endif
63055
63056+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63057+ unsigned int banned;
63058+ unsigned long ban_expires;
63059+#endif
63060+
63061 /* Hash table maintenance information */
63062 struct hlist_node uidhash_node;
63063 uid_t uid;
63064@@ -1354,8 +1374,8 @@ struct task_struct {
63065 struct list_head thread_group;
63066
63067 struct completion *vfork_done; /* for vfork() */
63068- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63069- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63070+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63071+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63072
63073 cputime_t utime, stime, utimescaled, stimescaled;
63074 cputime_t gtime;
63075@@ -1371,13 +1391,6 @@ struct task_struct {
63076 struct task_cputime cputime_expires;
63077 struct list_head cpu_timers[3];
63078
63079-/* process credentials */
63080- const struct cred __rcu *real_cred; /* objective and real subjective task
63081- * credentials (COW) */
63082- const struct cred __rcu *cred; /* effective (overridable) subjective task
63083- * credentials (COW) */
63084- struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63085-
63086 char comm[TASK_COMM_LEN]; /* executable name excluding path
63087 - access with [gs]et_task_comm (which lock
63088 it with task_lock())
63089@@ -1394,8 +1407,16 @@ struct task_struct {
63090 #endif
63091 /* CPU-specific state of this task */
63092 struct thread_struct thread;
63093+/* thread_info moved to task_struct */
63094+#ifdef CONFIG_X86
63095+ struct thread_info tinfo;
63096+#endif
63097 /* filesystem information */
63098 struct fs_struct *fs;
63099+
63100+ const struct cred __rcu *cred; /* effective (overridable) subjective task
63101+ * credentials (COW) */
63102+
63103 /* open file information */
63104 struct files_struct *files;
63105 /* namespaces */
63106@@ -1442,6 +1463,11 @@ struct task_struct {
63107 struct rt_mutex_waiter *pi_blocked_on;
63108 #endif
63109
63110+/* process credentials */
63111+ const struct cred __rcu *real_cred; /* objective and real subjective task
63112+ * credentials (COW) */
63113+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63114+
63115 #ifdef CONFIG_DEBUG_MUTEXES
63116 /* mutex deadlock detection */
63117 struct mutex_waiter *blocked_on;
63118@@ -1558,6 +1584,27 @@ struct task_struct {
63119 unsigned long default_timer_slack_ns;
63120
63121 struct list_head *scm_work_list;
63122+
63123+#ifdef CONFIG_GRKERNSEC
63124+ /* grsecurity */
63125+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63126+ u64 exec_id;
63127+#endif
63128+#ifdef CONFIG_GRKERNSEC_SETXID
63129+ const struct cred *delayed_cred;
63130+#endif
63131+ struct dentry *gr_chroot_dentry;
63132+ struct acl_subject_label *acl;
63133+ struct acl_role_label *role;
63134+ struct file *exec_file;
63135+ u16 acl_role_id;
63136+ /* is this the task that authenticated to the special role */
63137+ u8 acl_sp_role;
63138+ u8 is_writable;
63139+ u8 brute;
63140+ u8 gr_is_chrooted;
63141+#endif
63142+
63143 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63144 /* Index of current stored address in ret_stack */
63145 int curr_ret_stack;
63146@@ -1592,6 +1639,51 @@ struct task_struct {
63147 #endif
63148 };
63149
63150+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63151+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63152+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63153+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63154+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63155+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63156+
63157+#ifdef CONFIG_PAX_SOFTMODE
63158+extern int pax_softmode;
63159+#endif
63160+
63161+extern int pax_check_flags(unsigned long *);
63162+
63163+/* if tsk != current then task_lock must be held on it */
63164+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63165+static inline unsigned long pax_get_flags(struct task_struct *tsk)
63166+{
63167+ if (likely(tsk->mm))
63168+ return tsk->mm->pax_flags;
63169+ else
63170+ return 0UL;
63171+}
63172+
63173+/* if tsk != current then task_lock must be held on it */
63174+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63175+{
63176+ if (likely(tsk->mm)) {
63177+ tsk->mm->pax_flags = flags;
63178+ return 0;
63179+ }
63180+ return -EINVAL;
63181+}
63182+#endif
63183+
63184+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63185+extern void pax_set_initial_flags(struct linux_binprm *bprm);
63186+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63187+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63188+#endif
63189+
63190+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63191+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63192+extern void pax_report_refcount_overflow(struct pt_regs *regs);
63193+extern __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
63194+
63195 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63196 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63197
63198@@ -2104,7 +2196,9 @@ void yield(void);
63199 extern struct exec_domain default_exec_domain;
63200
63201 union thread_union {
63202+#ifndef CONFIG_X86
63203 struct thread_info thread_info;
63204+#endif
63205 unsigned long stack[THREAD_SIZE/sizeof(long)];
63206 };
63207
63208@@ -2137,6 +2231,7 @@ extern struct pid_namespace init_pid_ns;
63209 */
63210
63211 extern struct task_struct *find_task_by_vpid(pid_t nr);
63212+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63213 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63214 struct pid_namespace *ns);
63215
63216@@ -2280,7 +2375,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63217 extern void exit_itimers(struct signal_struct *);
63218 extern void flush_itimer_signals(void);
63219
63220-extern void do_group_exit(int);
63221+extern __noreturn void do_group_exit(int);
63222
63223 extern void daemonize(const char *, ...);
63224 extern int allow_signal(int);
63225@@ -2478,13 +2573,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63226
63227 #endif
63228
63229-static inline int object_is_on_stack(void *obj)
63230+static inline int object_starts_on_stack(void *obj)
63231 {
63232- void *stack = task_stack_page(current);
63233+ const void *stack = task_stack_page(current);
63234
63235 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63236 }
63237
63238+#ifdef CONFIG_PAX_USERCOPY
63239+extern int object_is_on_stack(const void *obj, unsigned long len);
63240+#endif
63241+
63242 extern void thread_info_cache_init(void);
63243
63244 #ifdef CONFIG_DEBUG_STACK_USAGE
63245diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63246index 899fbb4..1cb4138 100644
63247--- a/include/linux/screen_info.h
63248+++ b/include/linux/screen_info.h
63249@@ -43,7 +43,8 @@ struct screen_info {
63250 __u16 pages; /* 0x32 */
63251 __u16 vesa_attributes; /* 0x34 */
63252 __u32 capabilities; /* 0x36 */
63253- __u8 _reserved[6]; /* 0x3a */
63254+ __u16 vesapm_size; /* 0x3a */
63255+ __u8 _reserved[4]; /* 0x3c */
63256 } __attribute__((packed));
63257
63258 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63259diff --git a/include/linux/security.h b/include/linux/security.h
63260index 83c18e8..2d98860 100644
63261--- a/include/linux/security.h
63262+++ b/include/linux/security.h
63263@@ -37,6 +37,7 @@
63264 #include <linux/xfrm.h>
63265 #include <linux/slab.h>
63266 #include <linux/xattr.h>
63267+#include <linux/grsecurity.h>
63268 #include <net/flow.h>
63269
63270 /* Maximum number of letters for an LSM name string */
63271diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63272index 44f1514..2bbf6c1 100644
63273--- a/include/linux/seq_file.h
63274+++ b/include/linux/seq_file.h
63275@@ -24,6 +24,9 @@ struct seq_file {
63276 struct mutex lock;
63277 const struct seq_operations *op;
63278 int poll_event;
63279+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63280+ u64 exec_id;
63281+#endif
63282 void *private;
63283 };
63284
63285@@ -33,6 +36,7 @@ struct seq_operations {
63286 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63287 int (*show) (struct seq_file *m, void *v);
63288 };
63289+typedef struct seq_operations __no_const seq_operations_no_const;
63290
63291 #define SEQ_SKIP 1
63292
63293diff --git a/include/linux/shm.h b/include/linux/shm.h
63294index 92808b8..c28cac4 100644
63295--- a/include/linux/shm.h
63296+++ b/include/linux/shm.h
63297@@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63298
63299 /* The task created the shm object. NULL if the task is dead. */
63300 struct task_struct *shm_creator;
63301+#ifdef CONFIG_GRKERNSEC
63302+ time_t shm_createtime;
63303+ pid_t shm_lapid;
63304+#endif
63305 };
63306
63307 /* shm_mode upper byte flags */
63308diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63309index 42854ce..3b7d3c8 100644
63310--- a/include/linux/skbuff.h
63311+++ b/include/linux/skbuff.h
63312@@ -655,7 +655,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63313 */
63314 static inline int skb_queue_empty(const struct sk_buff_head *list)
63315 {
63316- return list->next == (struct sk_buff *)list;
63317+ return list->next == (const struct sk_buff *)list;
63318 }
63319
63320 /**
63321@@ -668,7 +668,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63322 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63323 const struct sk_buff *skb)
63324 {
63325- return skb->next == (struct sk_buff *)list;
63326+ return skb->next == (const struct sk_buff *)list;
63327 }
63328
63329 /**
63330@@ -681,7 +681,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63331 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63332 const struct sk_buff *skb)
63333 {
63334- return skb->prev == (struct sk_buff *)list;
63335+ return skb->prev == (const struct sk_buff *)list;
63336 }
63337
63338 /**
63339@@ -1558,7 +1558,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63340 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63341 */
63342 #ifndef NET_SKB_PAD
63343-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63344+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63345 #endif
63346
63347 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63348diff --git a/include/linux/slab.h b/include/linux/slab.h
63349index 573c809..eaaf6ea 100644
63350--- a/include/linux/slab.h
63351+++ b/include/linux/slab.h
63352@@ -11,12 +11,20 @@
63353
63354 #include <linux/gfp.h>
63355 #include <linux/types.h>
63356+#include <linux/err.h>
63357
63358 /*
63359 * Flags to pass to kmem_cache_create().
63360 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
63361 */
63362 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
63363+
63364+#ifdef CONFIG_PAX_USERCOPY
63365+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
63366+#else
63367+#define SLAB_USERCOPY 0x00000000UL
63368+#endif
63369+
63370 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
63371 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
63372 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
63373@@ -87,10 +95,13 @@
63374 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
63375 * Both make kfree a no-op.
63376 */
63377-#define ZERO_SIZE_PTR ((void *)16)
63378+#define ZERO_SIZE_PTR \
63379+({ \
63380+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
63381+ (void *)(-MAX_ERRNO-1L); \
63382+})
63383
63384-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
63385- (unsigned long)ZERO_SIZE_PTR)
63386+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
63387
63388 /*
63389 * struct kmem_cache related prototypes
63390@@ -161,6 +172,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
63391 void kfree(const void *);
63392 void kzfree(const void *);
63393 size_t ksize(const void *);
63394+void check_object_size(const void *ptr, unsigned long n, bool to);
63395
63396 /*
63397 * Allocator specific definitions. These are mainly used to establish optimized
63398@@ -287,7 +299,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
63399 */
63400 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63401 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63402-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63403+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
63404 #define kmalloc_track_caller(size, flags) \
63405 __kmalloc_track_caller(size, flags, _RET_IP_)
63406 #else
63407@@ -306,7 +318,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63408 */
63409 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63410 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63411-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
63412+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
63413 #define kmalloc_node_track_caller(size, flags, node) \
63414 __kmalloc_node_track_caller(size, flags, node, \
63415 _RET_IP_)
63416diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
63417index fbd1117..d4d8ef8 100644
63418--- a/include/linux/slab_def.h
63419+++ b/include/linux/slab_def.h
63420@@ -66,10 +66,10 @@ struct kmem_cache {
63421 unsigned long node_allocs;
63422 unsigned long node_frees;
63423 unsigned long node_overflow;
63424- atomic_t allochit;
63425- atomic_t allocmiss;
63426- atomic_t freehit;
63427- atomic_t freemiss;
63428+ atomic_unchecked_t allochit;
63429+ atomic_unchecked_t allocmiss;
63430+ atomic_unchecked_t freehit;
63431+ atomic_unchecked_t freemiss;
63432
63433 /*
63434 * If debugging is enabled, then the allocator can add additional
63435@@ -107,7 +107,7 @@ struct cache_sizes {
63436 extern struct cache_sizes malloc_sizes[];
63437
63438 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63439-void *__kmalloc(size_t size, gfp_t flags);
63440+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63441
63442 #ifdef CONFIG_TRACING
63443 extern void *kmem_cache_alloc_trace(size_t size,
63444@@ -160,7 +160,7 @@ found:
63445 }
63446
63447 #ifdef CONFIG_NUMA
63448-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
63449+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63450 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63451
63452 #ifdef CONFIG_TRACING
63453diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
63454index 0ec00b3..39cb7fc 100644
63455--- a/include/linux/slob_def.h
63456+++ b/include/linux/slob_def.h
63457@@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
63458 return kmem_cache_alloc_node(cachep, flags, -1);
63459 }
63460
63461-void *__kmalloc_node(size_t size, gfp_t flags, int node);
63462+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63463
63464 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63465 {
63466@@ -29,6 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63467 return __kmalloc_node(size, flags, -1);
63468 }
63469
63470+static __always_inline void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63471 static __always_inline void *__kmalloc(size_t size, gfp_t flags)
63472 {
63473 return kmalloc(size, flags);
63474diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
63475index a32bcfd..a80ed70 100644
63476--- a/include/linux/slub_def.h
63477+++ b/include/linux/slub_def.h
63478@@ -89,7 +89,7 @@ struct kmem_cache {
63479 struct kmem_cache_order_objects max;
63480 struct kmem_cache_order_objects min;
63481 gfp_t allocflags; /* gfp flags to use on each alloc */
63482- int refcount; /* Refcount for slab cache destroy */
63483+ atomic_t refcount; /* Refcount for slab cache destroy */
63484 void (*ctor)(void *);
63485 int inuse; /* Offset to metadata */
63486 int align; /* Alignment */
63487@@ -150,6 +150,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
63488 * Sorry that the following has to be that ugly but some versions of GCC
63489 * have trouble with constant propagation and loops.
63490 */
63491+static __always_inline int kmalloc_index(size_t size) __size_overflow(1);
63492 static __always_inline int kmalloc_index(size_t size)
63493 {
63494 if (!size)
63495@@ -215,7 +216,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63496 }
63497
63498 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63499-void *__kmalloc(size_t size, gfp_t flags);
63500+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
63501
63502 static __always_inline void *
63503 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
63504@@ -256,6 +257,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
63505 }
63506 #endif
63507
63508+static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __size_overflow(1);
63509 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
63510 {
63511 unsigned int order = get_order(size);
63512@@ -281,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63513 }
63514
63515 #ifdef CONFIG_NUMA
63516-void *__kmalloc_node(size_t size, gfp_t flags, int node);
63517+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63518 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63519
63520 #ifdef CONFIG_TRACING
63521diff --git a/include/linux/sonet.h b/include/linux/sonet.h
63522index de8832d..0147b46 100644
63523--- a/include/linux/sonet.h
63524+++ b/include/linux/sonet.h
63525@@ -61,7 +61,7 @@ struct sonet_stats {
63526 #include <linux/atomic.h>
63527
63528 struct k_sonet_stats {
63529-#define __HANDLE_ITEM(i) atomic_t i
63530+#define __HANDLE_ITEM(i) atomic_unchecked_t i
63531 __SONET_ITEMS
63532 #undef __HANDLE_ITEM
63533 };
63534diff --git a/include/linux/stddef.h b/include/linux/stddef.h
63535index 6a40c76..1747b67 100644
63536--- a/include/linux/stddef.h
63537+++ b/include/linux/stddef.h
63538@@ -3,14 +3,10 @@
63539
63540 #include <linux/compiler.h>
63541
63542+#ifdef __KERNEL__
63543+
63544 #undef NULL
63545-#if defined(__cplusplus)
63546-#define NULL 0
63547-#else
63548 #define NULL ((void *)0)
63549-#endif
63550-
63551-#ifdef __KERNEL__
63552
63553 enum {
63554 false = 0,
63555diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
63556index 2c5993a..b0e79f0 100644
63557--- a/include/linux/sunrpc/clnt.h
63558+++ b/include/linux/sunrpc/clnt.h
63559@@ -172,9 +172,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
63560 {
63561 switch (sap->sa_family) {
63562 case AF_INET:
63563- return ntohs(((struct sockaddr_in *)sap)->sin_port);
63564+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
63565 case AF_INET6:
63566- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
63567+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
63568 }
63569 return 0;
63570 }
63571@@ -207,7 +207,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
63572 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
63573 const struct sockaddr *src)
63574 {
63575- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
63576+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
63577 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
63578
63579 dsin->sin_family = ssin->sin_family;
63580@@ -310,7 +310,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
63581 if (sa->sa_family != AF_INET6)
63582 return 0;
63583
63584- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
63585+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
63586 }
63587
63588 #endif /* __KERNEL__ */
63589diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
63590index e775689..9e206d9 100644
63591--- a/include/linux/sunrpc/sched.h
63592+++ b/include/linux/sunrpc/sched.h
63593@@ -105,6 +105,7 @@ struct rpc_call_ops {
63594 void (*rpc_call_done)(struct rpc_task *, void *);
63595 void (*rpc_release)(void *);
63596 };
63597+typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
63598
63599 struct rpc_task_setup {
63600 struct rpc_task *task;
63601diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
63602index c14fe86..393245e 100644
63603--- a/include/linux/sunrpc/svc_rdma.h
63604+++ b/include/linux/sunrpc/svc_rdma.h
63605@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
63606 extern unsigned int svcrdma_max_requests;
63607 extern unsigned int svcrdma_max_req_size;
63608
63609-extern atomic_t rdma_stat_recv;
63610-extern atomic_t rdma_stat_read;
63611-extern atomic_t rdma_stat_write;
63612-extern atomic_t rdma_stat_sq_starve;
63613-extern atomic_t rdma_stat_rq_starve;
63614-extern atomic_t rdma_stat_rq_poll;
63615-extern atomic_t rdma_stat_rq_prod;
63616-extern atomic_t rdma_stat_sq_poll;
63617-extern atomic_t rdma_stat_sq_prod;
63618+extern atomic_unchecked_t rdma_stat_recv;
63619+extern atomic_unchecked_t rdma_stat_read;
63620+extern atomic_unchecked_t rdma_stat_write;
63621+extern atomic_unchecked_t rdma_stat_sq_starve;
63622+extern atomic_unchecked_t rdma_stat_rq_starve;
63623+extern atomic_unchecked_t rdma_stat_rq_poll;
63624+extern atomic_unchecked_t rdma_stat_rq_prod;
63625+extern atomic_unchecked_t rdma_stat_sq_poll;
63626+extern atomic_unchecked_t rdma_stat_sq_prod;
63627
63628 #define RPCRDMA_VERSION 1
63629
63630diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
63631index bb9127d..34ab358 100644
63632--- a/include/linux/sysctl.h
63633+++ b/include/linux/sysctl.h
63634@@ -155,7 +155,11 @@ enum
63635 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
63636 };
63637
63638-
63639+#ifdef CONFIG_PAX_SOFTMODE
63640+enum {
63641+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
63642+};
63643+#endif
63644
63645 /* CTL_VM names: */
63646 enum
63647@@ -968,6 +972,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
63648
63649 extern int proc_dostring(struct ctl_table *, int,
63650 void __user *, size_t *, loff_t *);
63651+extern int proc_dostring_modpriv(struct ctl_table *, int,
63652+ void __user *, size_t *, loff_t *);
63653 extern int proc_dointvec(struct ctl_table *, int,
63654 void __user *, size_t *, loff_t *);
63655 extern int proc_dointvec_minmax(struct ctl_table *, int,
63656diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
63657index a71a292..51bd91d 100644
63658--- a/include/linux/tracehook.h
63659+++ b/include/linux/tracehook.h
63660@@ -54,12 +54,12 @@ struct linux_binprm;
63661 /*
63662 * ptrace report for syscall entry and exit looks identical.
63663 */
63664-static inline void ptrace_report_syscall(struct pt_regs *regs)
63665+static inline int ptrace_report_syscall(struct pt_regs *regs)
63666 {
63667 int ptrace = current->ptrace;
63668
63669 if (!(ptrace & PT_PTRACED))
63670- return;
63671+ return 0;
63672
63673 ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
63674
63675@@ -72,6 +72,8 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
63676 send_sig(current->exit_code, current, 1);
63677 current->exit_code = 0;
63678 }
63679+
63680+ return fatal_signal_pending(current);
63681 }
63682
63683 /**
63684@@ -96,8 +98,7 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
63685 static inline __must_check int tracehook_report_syscall_entry(
63686 struct pt_regs *regs)
63687 {
63688- ptrace_report_syscall(regs);
63689- return 0;
63690+ return ptrace_report_syscall(regs);
63691 }
63692
63693 /**
63694diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
63695index ff7dc08..893e1bd 100644
63696--- a/include/linux/tty_ldisc.h
63697+++ b/include/linux/tty_ldisc.h
63698@@ -148,7 +148,7 @@ struct tty_ldisc_ops {
63699
63700 struct module *owner;
63701
63702- int refcount;
63703+ atomic_t refcount;
63704 };
63705
63706 struct tty_ldisc {
63707diff --git a/include/linux/types.h b/include/linux/types.h
63708index e5fa503..df6e8a4 100644
63709--- a/include/linux/types.h
63710+++ b/include/linux/types.h
63711@@ -214,10 +214,26 @@ typedef struct {
63712 int counter;
63713 } atomic_t;
63714
63715+#ifdef CONFIG_PAX_REFCOUNT
63716+typedef struct {
63717+ int counter;
63718+} atomic_unchecked_t;
63719+#else
63720+typedef atomic_t atomic_unchecked_t;
63721+#endif
63722+
63723 #ifdef CONFIG_64BIT
63724 typedef struct {
63725 long counter;
63726 } atomic64_t;
63727+
63728+#ifdef CONFIG_PAX_REFCOUNT
63729+typedef struct {
63730+ long counter;
63731+} atomic64_unchecked_t;
63732+#else
63733+typedef atomic64_t atomic64_unchecked_t;
63734+#endif
63735 #endif
63736
63737 struct list_head {
63738diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
63739index 5ca0951..ab496a5 100644
63740--- a/include/linux/uaccess.h
63741+++ b/include/linux/uaccess.h
63742@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
63743 long ret; \
63744 mm_segment_t old_fs = get_fs(); \
63745 \
63746- set_fs(KERNEL_DS); \
63747 pagefault_disable(); \
63748- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
63749- pagefault_enable(); \
63750+ set_fs(KERNEL_DS); \
63751+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
63752 set_fs(old_fs); \
63753+ pagefault_enable(); \
63754 ret; \
63755 })
63756
63757diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
63758index 99c1b4d..bb94261 100644
63759--- a/include/linux/unaligned/access_ok.h
63760+++ b/include/linux/unaligned/access_ok.h
63761@@ -6,32 +6,32 @@
63762
63763 static inline u16 get_unaligned_le16(const void *p)
63764 {
63765- return le16_to_cpup((__le16 *)p);
63766+ return le16_to_cpup((const __le16 *)p);
63767 }
63768
63769 static inline u32 get_unaligned_le32(const void *p)
63770 {
63771- return le32_to_cpup((__le32 *)p);
63772+ return le32_to_cpup((const __le32 *)p);
63773 }
63774
63775 static inline u64 get_unaligned_le64(const void *p)
63776 {
63777- return le64_to_cpup((__le64 *)p);
63778+ return le64_to_cpup((const __le64 *)p);
63779 }
63780
63781 static inline u16 get_unaligned_be16(const void *p)
63782 {
63783- return be16_to_cpup((__be16 *)p);
63784+ return be16_to_cpup((const __be16 *)p);
63785 }
63786
63787 static inline u32 get_unaligned_be32(const void *p)
63788 {
63789- return be32_to_cpup((__be32 *)p);
63790+ return be32_to_cpup((const __be32 *)p);
63791 }
63792
63793 static inline u64 get_unaligned_be64(const void *p)
63794 {
63795- return be64_to_cpup((__be64 *)p);
63796+ return be64_to_cpup((const __be64 *)p);
63797 }
63798
63799 static inline void put_unaligned_le16(u16 val, void *p)
63800diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
63801index 0d3f988..000f101 100644
63802--- a/include/linux/usb/renesas_usbhs.h
63803+++ b/include/linux/usb/renesas_usbhs.h
63804@@ -39,7 +39,7 @@ enum {
63805 */
63806 struct renesas_usbhs_driver_callback {
63807 int (*notify_hotplug)(struct platform_device *pdev);
63808-};
63809+} __no_const;
63810
63811 /*
63812 * callback functions for platform
63813@@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
63814 * VBUS control is needed for Host
63815 */
63816 int (*set_vbus)(struct platform_device *pdev, int enable);
63817-};
63818+} __no_const;
63819
63820 /*
63821 * parameters for renesas usbhs
63822diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
63823index 6f8fbcf..8259001 100644
63824--- a/include/linux/vermagic.h
63825+++ b/include/linux/vermagic.h
63826@@ -25,9 +25,35 @@
63827 #define MODULE_ARCH_VERMAGIC ""
63828 #endif
63829
63830+#ifdef CONFIG_PAX_REFCOUNT
63831+#define MODULE_PAX_REFCOUNT "REFCOUNT "
63832+#else
63833+#define MODULE_PAX_REFCOUNT ""
63834+#endif
63835+
63836+#ifdef CONSTIFY_PLUGIN
63837+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
63838+#else
63839+#define MODULE_CONSTIFY_PLUGIN ""
63840+#endif
63841+
63842+#ifdef STACKLEAK_PLUGIN
63843+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
63844+#else
63845+#define MODULE_STACKLEAK_PLUGIN ""
63846+#endif
63847+
63848+#ifdef CONFIG_GRKERNSEC
63849+#define MODULE_GRSEC "GRSEC "
63850+#else
63851+#define MODULE_GRSEC ""
63852+#endif
63853+
63854 #define VERMAGIC_STRING \
63855 UTS_RELEASE " " \
63856 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
63857 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
63858- MODULE_ARCH_VERMAGIC
63859+ MODULE_ARCH_VERMAGIC \
63860+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
63861+ MODULE_GRSEC
63862
63863diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
63864index dcdfc2b..ec79ab5 100644
63865--- a/include/linux/vmalloc.h
63866+++ b/include/linux/vmalloc.h
63867@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
63868 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
63869 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
63870 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
63871+
63872+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
63873+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
63874+#endif
63875+
63876 /* bits [20..32] reserved for arch specific ioremap internals */
63877
63878 /*
63879@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
63880 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
63881 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
63882 unsigned long start, unsigned long end, gfp_t gfp_mask,
63883- pgprot_t prot, int node, void *caller);
63884+ pgprot_t prot, int node, void *caller) __size_overflow(1);
63885 extern void vfree(const void *addr);
63886
63887 extern void *vmap(struct page **pages, unsigned int count,
63888@@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
63889 extern void free_vm_area(struct vm_struct *area);
63890
63891 /* for /dev/kmem */
63892-extern long vread(char *buf, char *addr, unsigned long count);
63893-extern long vwrite(char *buf, char *addr, unsigned long count);
63894+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
63895+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
63896
63897 /*
63898 * Internals. Dont't use..
63899diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
63900index 65efb92..137adbb 100644
63901--- a/include/linux/vmstat.h
63902+++ b/include/linux/vmstat.h
63903@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
63904 /*
63905 * Zone based page accounting with per cpu differentials.
63906 */
63907-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63908+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63909
63910 static inline void zone_page_state_add(long x, struct zone *zone,
63911 enum zone_stat_item item)
63912 {
63913- atomic_long_add(x, &zone->vm_stat[item]);
63914- atomic_long_add(x, &vm_stat[item]);
63915+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
63916+ atomic_long_add_unchecked(x, &vm_stat[item]);
63917 }
63918
63919 static inline unsigned long global_page_state(enum zone_stat_item item)
63920 {
63921- long x = atomic_long_read(&vm_stat[item]);
63922+ long x = atomic_long_read_unchecked(&vm_stat[item]);
63923 #ifdef CONFIG_SMP
63924 if (x < 0)
63925 x = 0;
63926@@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
63927 static inline unsigned long zone_page_state(struct zone *zone,
63928 enum zone_stat_item item)
63929 {
63930- long x = atomic_long_read(&zone->vm_stat[item]);
63931+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
63932 #ifdef CONFIG_SMP
63933 if (x < 0)
63934 x = 0;
63935@@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
63936 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
63937 enum zone_stat_item item)
63938 {
63939- long x = atomic_long_read(&zone->vm_stat[item]);
63940+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
63941
63942 #ifdef CONFIG_SMP
63943 int cpu;
63944@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
63945
63946 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
63947 {
63948- atomic_long_inc(&zone->vm_stat[item]);
63949- atomic_long_inc(&vm_stat[item]);
63950+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
63951+ atomic_long_inc_unchecked(&vm_stat[item]);
63952 }
63953
63954 static inline void __inc_zone_page_state(struct page *page,
63955@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
63956
63957 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
63958 {
63959- atomic_long_dec(&zone->vm_stat[item]);
63960- atomic_long_dec(&vm_stat[item]);
63961+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
63962+ atomic_long_dec_unchecked(&vm_stat[item]);
63963 }
63964
63965 static inline void __dec_zone_page_state(struct page *page,
63966diff --git a/include/linux/xattr.h b/include/linux/xattr.h
63967index e5d1220..ef6e406 100644
63968--- a/include/linux/xattr.h
63969+++ b/include/linux/xattr.h
63970@@ -57,6 +57,11 @@
63971 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
63972 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
63973
63974+/* User namespace */
63975+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
63976+#define XATTR_PAX_FLAGS_SUFFIX "flags"
63977+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
63978+
63979 #ifdef __KERNEL__
63980
63981 #include <linux/types.h>
63982diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
63983index 4aeff96..b378cdc 100644
63984--- a/include/media/saa7146_vv.h
63985+++ b/include/media/saa7146_vv.h
63986@@ -163,7 +163,7 @@ struct saa7146_ext_vv
63987 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
63988
63989 /* the extension can override this */
63990- struct v4l2_ioctl_ops ops;
63991+ v4l2_ioctl_ops_no_const ops;
63992 /* pointer to the saa7146 core ops */
63993 const struct v4l2_ioctl_ops *core_ops;
63994
63995diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
63996index c7c40f1..4f01585 100644
63997--- a/include/media/v4l2-dev.h
63998+++ b/include/media/v4l2-dev.h
63999@@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
64000
64001
64002 struct v4l2_file_operations {
64003- struct module *owner;
64004+ struct module * const owner;
64005 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
64006 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
64007 unsigned int (*poll) (struct file *, struct poll_table_struct *);
64008@@ -68,6 +68,7 @@ struct v4l2_file_operations {
64009 int (*open) (struct file *);
64010 int (*release) (struct file *);
64011 };
64012+typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64013
64014 /*
64015 * Newer version of video_device, handled by videodev2.c
64016diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64017index 3f5d60f..44210ed 100644
64018--- a/include/media/v4l2-ioctl.h
64019+++ b/include/media/v4l2-ioctl.h
64020@@ -278,7 +278,7 @@ struct v4l2_ioctl_ops {
64021 long (*vidioc_default) (struct file *file, void *fh,
64022 bool valid_prio, int cmd, void *arg);
64023 };
64024-
64025+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64026
64027 /* v4l debugging and diagnostics */
64028
64029diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64030index 8d55251..dfe5b0a 100644
64031--- a/include/net/caif/caif_hsi.h
64032+++ b/include/net/caif/caif_hsi.h
64033@@ -98,7 +98,7 @@ struct cfhsi_drv {
64034 void (*rx_done_cb) (struct cfhsi_drv *drv);
64035 void (*wake_up_cb) (struct cfhsi_drv *drv);
64036 void (*wake_down_cb) (struct cfhsi_drv *drv);
64037-};
64038+} __no_const;
64039
64040 /* Structure implemented by HSI device. */
64041 struct cfhsi_dev {
64042diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
64043index 9e5425b..8136ffc 100644
64044--- a/include/net/caif/cfctrl.h
64045+++ b/include/net/caif/cfctrl.h
64046@@ -52,7 +52,7 @@ struct cfctrl_rsp {
64047 void (*radioset_rsp)(void);
64048 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
64049 struct cflayer *client_layer);
64050-};
64051+} __no_const;
64052
64053 /* Link Setup Parameters for CAIF-Links. */
64054 struct cfctrl_link_param {
64055@@ -101,8 +101,8 @@ struct cfctrl_request_info {
64056 struct cfctrl {
64057 struct cfsrvl serv;
64058 struct cfctrl_rsp res;
64059- atomic_t req_seq_no;
64060- atomic_t rsp_seq_no;
64061+ atomic_unchecked_t req_seq_no;
64062+ atomic_unchecked_t rsp_seq_no;
64063 struct list_head list;
64064 /* Protects from simultaneous access to first_req list */
64065 spinlock_t info_list_lock;
64066diff --git a/include/net/flow.h b/include/net/flow.h
64067index 6c469db..7743b8e 100644
64068--- a/include/net/flow.h
64069+++ b/include/net/flow.h
64070@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64071
64072 extern void flow_cache_flush(void);
64073 extern void flow_cache_flush_deferred(void);
64074-extern atomic_t flow_cache_genid;
64075+extern atomic_unchecked_t flow_cache_genid;
64076
64077 #endif
64078diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64079index b94765e..053f68b 100644
64080--- a/include/net/inetpeer.h
64081+++ b/include/net/inetpeer.h
64082@@ -48,8 +48,8 @@ struct inet_peer {
64083 */
64084 union {
64085 struct {
64086- atomic_t rid; /* Frag reception counter */
64087- atomic_t ip_id_count; /* IP ID for the next packet */
64088+ atomic_unchecked_t rid; /* Frag reception counter */
64089+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64090 __u32 tcp_ts;
64091 __u32 tcp_ts_stamp;
64092 };
64093@@ -115,11 +115,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64094 more++;
64095 inet_peer_refcheck(p);
64096 do {
64097- old = atomic_read(&p->ip_id_count);
64098+ old = atomic_read_unchecked(&p->ip_id_count);
64099 new = old + more;
64100 if (!new)
64101 new = 1;
64102- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64103+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64104 return new;
64105 }
64106
64107diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64108index 10422ef..662570f 100644
64109--- a/include/net/ip_fib.h
64110+++ b/include/net/ip_fib.h
64111@@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64112
64113 #define FIB_RES_SADDR(net, res) \
64114 ((FIB_RES_NH(res).nh_saddr_genid == \
64115- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64116+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64117 FIB_RES_NH(res).nh_saddr : \
64118 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64119 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64120diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64121index ebe517f..1bd286b 100644
64122--- a/include/net/ip_vs.h
64123+++ b/include/net/ip_vs.h
64124@@ -509,7 +509,7 @@ struct ip_vs_conn {
64125 struct ip_vs_conn *control; /* Master control connection */
64126 atomic_t n_control; /* Number of controlled ones */
64127 struct ip_vs_dest *dest; /* real server */
64128- atomic_t in_pkts; /* incoming packet counter */
64129+ atomic_unchecked_t in_pkts; /* incoming packet counter */
64130
64131 /* packet transmitter for different forwarding methods. If it
64132 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64133@@ -647,7 +647,7 @@ struct ip_vs_dest {
64134 __be16 port; /* port number of the server */
64135 union nf_inet_addr addr; /* IP address of the server */
64136 volatile unsigned flags; /* dest status flags */
64137- atomic_t conn_flags; /* flags to copy to conn */
64138+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
64139 atomic_t weight; /* server weight */
64140
64141 atomic_t refcnt; /* reference counter */
64142diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64143index 69b610a..fe3962c 100644
64144--- a/include/net/irda/ircomm_core.h
64145+++ b/include/net/irda/ircomm_core.h
64146@@ -51,7 +51,7 @@ typedef struct {
64147 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64148 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64149 struct ircomm_info *);
64150-} call_t;
64151+} __no_const call_t;
64152
64153 struct ircomm_cb {
64154 irda_queue_t queue;
64155diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64156index 59ba38bc..d515662 100644
64157--- a/include/net/irda/ircomm_tty.h
64158+++ b/include/net/irda/ircomm_tty.h
64159@@ -35,6 +35,7 @@
64160 #include <linux/termios.h>
64161 #include <linux/timer.h>
64162 #include <linux/tty.h> /* struct tty_struct */
64163+#include <asm/local.h>
64164
64165 #include <net/irda/irias_object.h>
64166 #include <net/irda/ircomm_core.h>
64167@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64168 unsigned short close_delay;
64169 unsigned short closing_wait; /* time to wait before closing */
64170
64171- int open_count;
64172- int blocked_open; /* # of blocked opens */
64173+ local_t open_count;
64174+ local_t blocked_open; /* # of blocked opens */
64175
64176 /* Protect concurent access to :
64177 * o self->open_count
64178diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64179index 0954ec9..7413562 100644
64180--- a/include/net/iucv/af_iucv.h
64181+++ b/include/net/iucv/af_iucv.h
64182@@ -138,7 +138,7 @@ struct iucv_sock {
64183 struct iucv_sock_list {
64184 struct hlist_head head;
64185 rwlock_t lock;
64186- atomic_t autobind_name;
64187+ atomic_unchecked_t autobind_name;
64188 };
64189
64190 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64191diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64192index 34c996f..bb3b4d4 100644
64193--- a/include/net/neighbour.h
64194+++ b/include/net/neighbour.h
64195@@ -123,7 +123,7 @@ struct neigh_ops {
64196 void (*error_report)(struct neighbour *, struct sk_buff *);
64197 int (*output)(struct neighbour *, struct sk_buff *);
64198 int (*connected_output)(struct neighbour *, struct sk_buff *);
64199-};
64200+} __do_const;
64201
64202 struct pneigh_entry {
64203 struct pneigh_entry *next;
64204diff --git a/include/net/netlink.h b/include/net/netlink.h
64205index cb1f350..3279d2c 100644
64206--- a/include/net/netlink.h
64207+++ b/include/net/netlink.h
64208@@ -569,7 +569,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64209 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64210 {
64211 if (mark)
64212- skb_trim(skb, (unsigned char *) mark - skb->data);
64213+ skb_trim(skb, (const unsigned char *) mark - skb->data);
64214 }
64215
64216 /**
64217diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64218index bbd023a..97c6d0d 100644
64219--- a/include/net/netns/ipv4.h
64220+++ b/include/net/netns/ipv4.h
64221@@ -57,8 +57,8 @@ struct netns_ipv4 {
64222 unsigned int sysctl_ping_group_range[2];
64223 long sysctl_tcp_mem[3];
64224
64225- atomic_t rt_genid;
64226- atomic_t dev_addr_genid;
64227+ atomic_unchecked_t rt_genid;
64228+ atomic_unchecked_t dev_addr_genid;
64229
64230 #ifdef CONFIG_IP_MROUTE
64231 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64232diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64233index d368561..96aaa17 100644
64234--- a/include/net/sctp/sctp.h
64235+++ b/include/net/sctp/sctp.h
64236@@ -318,9 +318,9 @@ do { \
64237
64238 #else /* SCTP_DEBUG */
64239
64240-#define SCTP_DEBUG_PRINTK(whatever...)
64241-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64242-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64243+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64244+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64245+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64246 #define SCTP_ENABLE_DEBUG
64247 #define SCTP_DISABLE_DEBUG
64248 #define SCTP_ASSERT(expr, str, func)
64249diff --git a/include/net/sock.h b/include/net/sock.h
64250index 91c1c8b..15ae923 100644
64251--- a/include/net/sock.h
64252+++ b/include/net/sock.h
64253@@ -299,7 +299,7 @@ struct sock {
64254 #ifdef CONFIG_RPS
64255 __u32 sk_rxhash;
64256 #endif
64257- atomic_t sk_drops;
64258+ atomic_unchecked_t sk_drops;
64259 int sk_rcvbuf;
64260
64261 struct sk_filter __rcu *sk_filter;
64262@@ -1660,7 +1660,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
64263 }
64264
64265 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64266- char __user *from, char *to,
64267+ char __user *from, unsigned char *to,
64268 int copy, int offset)
64269 {
64270 if (skb->ip_summed == CHECKSUM_NONE) {
64271diff --git a/include/net/tcp.h b/include/net/tcp.h
64272index 2d80c29..aa07caf 100644
64273--- a/include/net/tcp.h
64274+++ b/include/net/tcp.h
64275@@ -1426,7 +1426,7 @@ struct tcp_seq_afinfo {
64276 char *name;
64277 sa_family_t family;
64278 const struct file_operations *seq_fops;
64279- struct seq_operations seq_ops;
64280+ seq_operations_no_const seq_ops;
64281 };
64282
64283 struct tcp_iter_state {
64284diff --git a/include/net/udp.h b/include/net/udp.h
64285index e39592f..fef9680 100644
64286--- a/include/net/udp.h
64287+++ b/include/net/udp.h
64288@@ -243,7 +243,7 @@ struct udp_seq_afinfo {
64289 sa_family_t family;
64290 struct udp_table *udp_table;
64291 const struct file_operations *seq_fops;
64292- struct seq_operations seq_ops;
64293+ seq_operations_no_const seq_ops;
64294 };
64295
64296 struct udp_iter_state {
64297diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64298index 89174e2..1f82598 100644
64299--- a/include/net/xfrm.h
64300+++ b/include/net/xfrm.h
64301@@ -505,7 +505,7 @@ struct xfrm_policy {
64302 struct timer_list timer;
64303
64304 struct flow_cache_object flo;
64305- atomic_t genid;
64306+ atomic_unchecked_t genid;
64307 u32 priority;
64308 u32 index;
64309 struct xfrm_mark mark;
64310diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64311index 1a046b1..ee0bef0 100644
64312--- a/include/rdma/iw_cm.h
64313+++ b/include/rdma/iw_cm.h
64314@@ -122,7 +122,7 @@ struct iw_cm_verbs {
64315 int backlog);
64316
64317 int (*destroy_listen)(struct iw_cm_id *cm_id);
64318-};
64319+} __no_const;
64320
64321 /**
64322 * iw_create_cm_id - Create an IW CM identifier.
64323diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64324index 6a3922f..0b73022 100644
64325--- a/include/scsi/libfc.h
64326+++ b/include/scsi/libfc.h
64327@@ -748,6 +748,7 @@ struct libfc_function_template {
64328 */
64329 void (*disc_stop_final) (struct fc_lport *);
64330 };
64331+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64332
64333 /**
64334 * struct fc_disc - Discovery context
64335@@ -851,7 +852,7 @@ struct fc_lport {
64336 struct fc_vport *vport;
64337
64338 /* Operational Information */
64339- struct libfc_function_template tt;
64340+ libfc_function_template_no_const tt;
64341 u8 link_up;
64342 u8 qfull;
64343 enum fc_lport_state state;
64344diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
64345index 77273f2..dd4031f 100644
64346--- a/include/scsi/scsi_device.h
64347+++ b/include/scsi/scsi_device.h
64348@@ -161,9 +161,9 @@ struct scsi_device {
64349 unsigned int max_device_blocked; /* what device_blocked counts down from */
64350 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
64351
64352- atomic_t iorequest_cnt;
64353- atomic_t iodone_cnt;
64354- atomic_t ioerr_cnt;
64355+ atomic_unchecked_t iorequest_cnt;
64356+ atomic_unchecked_t iodone_cnt;
64357+ atomic_unchecked_t ioerr_cnt;
64358
64359 struct device sdev_gendev,
64360 sdev_dev;
64361diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
64362index 2a65167..91e01f8 100644
64363--- a/include/scsi/scsi_transport_fc.h
64364+++ b/include/scsi/scsi_transport_fc.h
64365@@ -711,7 +711,7 @@ struct fc_function_template {
64366 unsigned long show_host_system_hostname:1;
64367
64368 unsigned long disable_target_scan:1;
64369-};
64370+} __do_const;
64371
64372
64373 /**
64374diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
64375index 030b87c..98a6954 100644
64376--- a/include/sound/ak4xxx-adda.h
64377+++ b/include/sound/ak4xxx-adda.h
64378@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
64379 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
64380 unsigned char val);
64381 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
64382-};
64383+} __no_const;
64384
64385 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
64386
64387diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
64388index 8c05e47..2b5df97 100644
64389--- a/include/sound/hwdep.h
64390+++ b/include/sound/hwdep.h
64391@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
64392 struct snd_hwdep_dsp_status *status);
64393 int (*dsp_load)(struct snd_hwdep *hw,
64394 struct snd_hwdep_dsp_image *image);
64395-};
64396+} __no_const;
64397
64398 struct snd_hwdep {
64399 struct snd_card *card;
64400diff --git a/include/sound/info.h b/include/sound/info.h
64401index 9ca1a49..aba1728 100644
64402--- a/include/sound/info.h
64403+++ b/include/sound/info.h
64404@@ -44,7 +44,7 @@ struct snd_info_entry_text {
64405 struct snd_info_buffer *buffer);
64406 void (*write)(struct snd_info_entry *entry,
64407 struct snd_info_buffer *buffer);
64408-};
64409+} __no_const;
64410
64411 struct snd_info_entry_ops {
64412 int (*open)(struct snd_info_entry *entry,
64413diff --git a/include/sound/pcm.h b/include/sound/pcm.h
64414index 0cf91b2..b70cae4 100644
64415--- a/include/sound/pcm.h
64416+++ b/include/sound/pcm.h
64417@@ -81,6 +81,7 @@ struct snd_pcm_ops {
64418 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
64419 int (*ack)(struct snd_pcm_substream *substream);
64420 };
64421+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
64422
64423 /*
64424 *
64425diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
64426index af1b49e..a5d55a5 100644
64427--- a/include/sound/sb16_csp.h
64428+++ b/include/sound/sb16_csp.h
64429@@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
64430 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
64431 int (*csp_stop) (struct snd_sb_csp * p);
64432 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
64433-};
64434+} __no_const;
64435
64436 /*
64437 * CSP private data
64438diff --git a/include/sound/soc.h b/include/sound/soc.h
64439index 0992dff..bb366fe 100644
64440--- a/include/sound/soc.h
64441+++ b/include/sound/soc.h
64442@@ -682,7 +682,7 @@ struct snd_soc_platform_driver {
64443 /* platform IO - used for platform DAPM */
64444 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
64445 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
64446-};
64447+} __do_const;
64448
64449 struct snd_soc_platform {
64450 const char *name;
64451@@ -852,7 +852,7 @@ struct snd_soc_pcm_runtime {
64452 struct snd_soc_dai_link *dai_link;
64453 struct mutex pcm_mutex;
64454 enum snd_soc_pcm_subclass pcm_subclass;
64455- struct snd_pcm_ops ops;
64456+ snd_pcm_ops_no_const ops;
64457
64458 unsigned int complete:1;
64459 unsigned int dev_registered:1;
64460diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
64461index 444cd6b..3327cc5 100644
64462--- a/include/sound/ymfpci.h
64463+++ b/include/sound/ymfpci.h
64464@@ -358,7 +358,7 @@ struct snd_ymfpci {
64465 spinlock_t reg_lock;
64466 spinlock_t voice_lock;
64467 wait_queue_head_t interrupt_sleep;
64468- atomic_t interrupt_sleep_count;
64469+ atomic_unchecked_t interrupt_sleep_count;
64470 struct snd_info_entry *proc_entry;
64471 const struct firmware *dsp_microcode;
64472 const struct firmware *controller_microcode;
64473diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
64474index fe73eb8..56388b1 100644
64475--- a/include/target/target_core_base.h
64476+++ b/include/target/target_core_base.h
64477@@ -443,7 +443,7 @@ struct t10_reservation_ops {
64478 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
64479 int (*t10_pr_register)(struct se_cmd *);
64480 int (*t10_pr_clear)(struct se_cmd *);
64481-};
64482+} __no_const;
64483
64484 struct t10_reservation {
64485 /* Reservation effects all target ports */
64486@@ -561,8 +561,8 @@ struct se_cmd {
64487 atomic_t t_se_count;
64488 atomic_t t_task_cdbs_left;
64489 atomic_t t_task_cdbs_ex_left;
64490- atomic_t t_task_cdbs_sent;
64491- atomic_t t_transport_aborted;
64492+ atomic_unchecked_t t_task_cdbs_sent;
64493+ atomic_unchecked_t t_transport_aborted;
64494 atomic_t t_transport_active;
64495 atomic_t t_transport_complete;
64496 atomic_t t_transport_queue_active;
64497@@ -799,7 +799,7 @@ struct se_device {
64498 spinlock_t stats_lock;
64499 /* Active commands on this virtual SE device */
64500 atomic_t simple_cmds;
64501- atomic_t dev_ordered_id;
64502+ atomic_unchecked_t dev_ordered_id;
64503 atomic_t execute_tasks;
64504 atomic_t dev_ordered_sync;
64505 atomic_t dev_qf_count;
64506diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
64507index 1c09820..7f5ec79 100644
64508--- a/include/trace/events/irq.h
64509+++ b/include/trace/events/irq.h
64510@@ -36,7 +36,7 @@ struct softirq_action;
64511 */
64512 TRACE_EVENT(irq_handler_entry,
64513
64514- TP_PROTO(int irq, struct irqaction *action),
64515+ TP_PROTO(int irq, const struct irqaction *action),
64516
64517 TP_ARGS(irq, action),
64518
64519@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
64520 */
64521 TRACE_EVENT(irq_handler_exit,
64522
64523- TP_PROTO(int irq, struct irqaction *action, int ret),
64524+ TP_PROTO(int irq, const struct irqaction *action, int ret),
64525
64526 TP_ARGS(irq, action, ret),
64527
64528diff --git a/include/video/udlfb.h b/include/video/udlfb.h
64529index c41f308..6918de3 100644
64530--- a/include/video/udlfb.h
64531+++ b/include/video/udlfb.h
64532@@ -52,10 +52,10 @@ struct dlfb_data {
64533 u32 pseudo_palette[256];
64534 int blank_mode; /*one of FB_BLANK_ */
64535 /* blit-only rendering path metrics, exposed through sysfs */
64536- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64537- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
64538- atomic_t bytes_sent; /* to usb, after compression including overhead */
64539- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
64540+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64541+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
64542+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
64543+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
64544 };
64545
64546 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
64547diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
64548index 0993a22..32ba2fe 100644
64549--- a/include/video/uvesafb.h
64550+++ b/include/video/uvesafb.h
64551@@ -177,6 +177,7 @@ struct uvesafb_par {
64552 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
64553 u8 pmi_setpal; /* PMI for palette changes */
64554 u16 *pmi_base; /* protected mode interface location */
64555+ u8 *pmi_code; /* protected mode code location */
64556 void *pmi_start;
64557 void *pmi_pal;
64558 u8 *vbe_state_orig; /*
64559diff --git a/init/Kconfig b/init/Kconfig
64560index 3f42cd6..613f41d 100644
64561--- a/init/Kconfig
64562+++ b/init/Kconfig
64563@@ -799,6 +799,7 @@ endif # CGROUPS
64564
64565 config CHECKPOINT_RESTORE
64566 bool "Checkpoint/restore support" if EXPERT
64567+ depends on !GRKERNSEC
64568 default n
64569 help
64570 Enables additional kernel features in a sake of checkpoint/restore.
64571@@ -1249,7 +1250,7 @@ config SLUB_DEBUG
64572
64573 config COMPAT_BRK
64574 bool "Disable heap randomization"
64575- default y
64576+ default n
64577 help
64578 Randomizing heap placement makes heap exploits harder, but it
64579 also breaks ancient binaries (including anything libc5 based).
64580diff --git a/init/do_mounts.c b/init/do_mounts.c
64581index bf6edbf..4e5809c 100644
64582--- a/init/do_mounts.c
64583+++ b/init/do_mounts.c
64584@@ -326,11 +326,11 @@ static void __init get_fs_names(char *page)
64585 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
64586 {
64587 struct super_block *s;
64588- int err = sys_mount(name, "/root", fs, flags, data);
64589+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
64590 if (err)
64591 return err;
64592
64593- sys_chdir((const char __user __force *)"/root");
64594+ sys_chdir((const char __force_user *)"/root");
64595 s = current->fs->pwd.dentry->d_sb;
64596 ROOT_DEV = s->s_dev;
64597 printk(KERN_INFO
64598@@ -450,18 +450,18 @@ void __init change_floppy(char *fmt, ...)
64599 va_start(args, fmt);
64600 vsprintf(buf, fmt, args);
64601 va_end(args);
64602- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
64603+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
64604 if (fd >= 0) {
64605 sys_ioctl(fd, FDEJECT, 0);
64606 sys_close(fd);
64607 }
64608 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
64609- fd = sys_open("/dev/console", O_RDWR, 0);
64610+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
64611 if (fd >= 0) {
64612 sys_ioctl(fd, TCGETS, (long)&termios);
64613 termios.c_lflag &= ~ICANON;
64614 sys_ioctl(fd, TCSETSF, (long)&termios);
64615- sys_read(fd, &c, 1);
64616+ sys_read(fd, (char __user *)&c, 1);
64617 termios.c_lflag |= ICANON;
64618 sys_ioctl(fd, TCSETSF, (long)&termios);
64619 sys_close(fd);
64620@@ -555,6 +555,6 @@ void __init prepare_namespace(void)
64621 mount_root();
64622 out:
64623 devtmpfs_mount("dev");
64624- sys_mount(".", "/", NULL, MS_MOVE, NULL);
64625- sys_chroot((const char __user __force *)".");
64626+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64627+ sys_chroot((const char __force_user *)".");
64628 }
64629diff --git a/init/do_mounts.h b/init/do_mounts.h
64630index f5b978a..69dbfe8 100644
64631--- a/init/do_mounts.h
64632+++ b/init/do_mounts.h
64633@@ -15,15 +15,15 @@ extern int root_mountflags;
64634
64635 static inline int create_dev(char *name, dev_t dev)
64636 {
64637- sys_unlink(name);
64638- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
64639+ sys_unlink((char __force_user *)name);
64640+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
64641 }
64642
64643 #if BITS_PER_LONG == 32
64644 static inline u32 bstat(char *name)
64645 {
64646 struct stat64 stat;
64647- if (sys_stat64(name, &stat) != 0)
64648+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
64649 return 0;
64650 if (!S_ISBLK(stat.st_mode))
64651 return 0;
64652@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
64653 static inline u32 bstat(char *name)
64654 {
64655 struct stat stat;
64656- if (sys_newstat(name, &stat) != 0)
64657+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
64658 return 0;
64659 if (!S_ISBLK(stat.st_mode))
64660 return 0;
64661diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
64662index 3098a38..253064e 100644
64663--- a/init/do_mounts_initrd.c
64664+++ b/init/do_mounts_initrd.c
64665@@ -44,13 +44,13 @@ static void __init handle_initrd(void)
64666 create_dev("/dev/root.old", Root_RAM0);
64667 /* mount initrd on rootfs' /root */
64668 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
64669- sys_mkdir("/old", 0700);
64670- root_fd = sys_open("/", 0, 0);
64671- old_fd = sys_open("/old", 0, 0);
64672+ sys_mkdir((const char __force_user *)"/old", 0700);
64673+ root_fd = sys_open((const char __force_user *)"/", 0, 0);
64674+ old_fd = sys_open((const char __force_user *)"/old", 0, 0);
64675 /* move initrd over / and chdir/chroot in initrd root */
64676- sys_chdir("/root");
64677- sys_mount(".", "/", NULL, MS_MOVE, NULL);
64678- sys_chroot(".");
64679+ sys_chdir((const char __force_user *)"/root");
64680+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64681+ sys_chroot((const char __force_user *)".");
64682
64683 /*
64684 * In case that a resume from disk is carried out by linuxrc or one of
64685@@ -67,15 +67,15 @@ static void __init handle_initrd(void)
64686
64687 /* move initrd to rootfs' /old */
64688 sys_fchdir(old_fd);
64689- sys_mount("/", ".", NULL, MS_MOVE, NULL);
64690+ sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
64691 /* switch root and cwd back to / of rootfs */
64692 sys_fchdir(root_fd);
64693- sys_chroot(".");
64694+ sys_chroot((const char __force_user *)".");
64695 sys_close(old_fd);
64696 sys_close(root_fd);
64697
64698 if (new_decode_dev(real_root_dev) == Root_RAM0) {
64699- sys_chdir("/old");
64700+ sys_chdir((const char __force_user *)"/old");
64701 return;
64702 }
64703
64704@@ -83,17 +83,17 @@ static void __init handle_initrd(void)
64705 mount_root();
64706
64707 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
64708- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
64709+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
64710 if (!error)
64711 printk("okay\n");
64712 else {
64713- int fd = sys_open("/dev/root.old", O_RDWR, 0);
64714+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
64715 if (error == -ENOENT)
64716 printk("/initrd does not exist. Ignored.\n");
64717 else
64718 printk("failed\n");
64719 printk(KERN_NOTICE "Unmounting old root\n");
64720- sys_umount("/old", MNT_DETACH);
64721+ sys_umount((char __force_user *)"/old", MNT_DETACH);
64722 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
64723 if (fd < 0) {
64724 error = fd;
64725@@ -116,11 +116,11 @@ int __init initrd_load(void)
64726 * mounted in the normal path.
64727 */
64728 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
64729- sys_unlink("/initrd.image");
64730+ sys_unlink((const char __force_user *)"/initrd.image");
64731 handle_initrd();
64732 return 1;
64733 }
64734 }
64735- sys_unlink("/initrd.image");
64736+ sys_unlink((const char __force_user *)"/initrd.image");
64737 return 0;
64738 }
64739diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
64740index 32c4799..c27ee74 100644
64741--- a/init/do_mounts_md.c
64742+++ b/init/do_mounts_md.c
64743@@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
64744 partitioned ? "_d" : "", minor,
64745 md_setup_args[ent].device_names);
64746
64747- fd = sys_open(name, 0, 0);
64748+ fd = sys_open((char __force_user *)name, 0, 0);
64749 if (fd < 0) {
64750 printk(KERN_ERR "md: open failed - cannot start "
64751 "array %s\n", name);
64752@@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
64753 * array without it
64754 */
64755 sys_close(fd);
64756- fd = sys_open(name, 0, 0);
64757+ fd = sys_open((char __force_user *)name, 0, 0);
64758 sys_ioctl(fd, BLKRRPART, 0);
64759 }
64760 sys_close(fd);
64761@@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
64762
64763 wait_for_device_probe();
64764
64765- fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
64766+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
64767 if (fd >= 0) {
64768 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
64769 sys_close(fd);
64770diff --git a/init/initramfs.c b/init/initramfs.c
64771index 8216c30..25e8e32 100644
64772--- a/init/initramfs.c
64773+++ b/init/initramfs.c
64774@@ -74,7 +74,7 @@ static void __init free_hash(void)
64775 }
64776 }
64777
64778-static long __init do_utime(char __user *filename, time_t mtime)
64779+static long __init do_utime(__force char __user *filename, time_t mtime)
64780 {
64781 struct timespec t[2];
64782
64783@@ -109,7 +109,7 @@ static void __init dir_utime(void)
64784 struct dir_entry *de, *tmp;
64785 list_for_each_entry_safe(de, tmp, &dir_list, list) {
64786 list_del(&de->list);
64787- do_utime(de->name, de->mtime);
64788+ do_utime((char __force_user *)de->name, de->mtime);
64789 kfree(de->name);
64790 kfree(de);
64791 }
64792@@ -271,7 +271,7 @@ static int __init maybe_link(void)
64793 if (nlink >= 2) {
64794 char *old = find_link(major, minor, ino, mode, collected);
64795 if (old)
64796- return (sys_link(old, collected) < 0) ? -1 : 1;
64797+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
64798 }
64799 return 0;
64800 }
64801@@ -280,11 +280,11 @@ static void __init clean_path(char *path, umode_t mode)
64802 {
64803 struct stat st;
64804
64805- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
64806+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
64807 if (S_ISDIR(st.st_mode))
64808- sys_rmdir(path);
64809+ sys_rmdir((char __force_user *)path);
64810 else
64811- sys_unlink(path);
64812+ sys_unlink((char __force_user *)path);
64813 }
64814 }
64815
64816@@ -305,7 +305,7 @@ static int __init do_name(void)
64817 int openflags = O_WRONLY|O_CREAT;
64818 if (ml != 1)
64819 openflags |= O_TRUNC;
64820- wfd = sys_open(collected, openflags, mode);
64821+ wfd = sys_open((char __force_user *)collected, openflags, mode);
64822
64823 if (wfd >= 0) {
64824 sys_fchown(wfd, uid, gid);
64825@@ -317,17 +317,17 @@ static int __init do_name(void)
64826 }
64827 }
64828 } else if (S_ISDIR(mode)) {
64829- sys_mkdir(collected, mode);
64830- sys_chown(collected, uid, gid);
64831- sys_chmod(collected, mode);
64832+ sys_mkdir((char __force_user *)collected, mode);
64833+ sys_chown((char __force_user *)collected, uid, gid);
64834+ sys_chmod((char __force_user *)collected, mode);
64835 dir_add(collected, mtime);
64836 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
64837 S_ISFIFO(mode) || S_ISSOCK(mode)) {
64838 if (maybe_link() == 0) {
64839- sys_mknod(collected, mode, rdev);
64840- sys_chown(collected, uid, gid);
64841- sys_chmod(collected, mode);
64842- do_utime(collected, mtime);
64843+ sys_mknod((char __force_user *)collected, mode, rdev);
64844+ sys_chown((char __force_user *)collected, uid, gid);
64845+ sys_chmod((char __force_user *)collected, mode);
64846+ do_utime((char __force_user *)collected, mtime);
64847 }
64848 }
64849 return 0;
64850@@ -336,15 +336,15 @@ static int __init do_name(void)
64851 static int __init do_copy(void)
64852 {
64853 if (count >= body_len) {
64854- sys_write(wfd, victim, body_len);
64855+ sys_write(wfd, (char __force_user *)victim, body_len);
64856 sys_close(wfd);
64857- do_utime(vcollected, mtime);
64858+ do_utime((char __force_user *)vcollected, mtime);
64859 kfree(vcollected);
64860 eat(body_len);
64861 state = SkipIt;
64862 return 0;
64863 } else {
64864- sys_write(wfd, victim, count);
64865+ sys_write(wfd, (char __force_user *)victim, count);
64866 body_len -= count;
64867 eat(count);
64868 return 1;
64869@@ -355,9 +355,9 @@ static int __init do_symlink(void)
64870 {
64871 collected[N_ALIGN(name_len) + body_len] = '\0';
64872 clean_path(collected, 0);
64873- sys_symlink(collected + N_ALIGN(name_len), collected);
64874- sys_lchown(collected, uid, gid);
64875- do_utime(collected, mtime);
64876+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
64877+ sys_lchown((char __force_user *)collected, uid, gid);
64878+ do_utime((char __force_user *)collected, mtime);
64879 state = SkipIt;
64880 next_state = Reset;
64881 return 0;
64882diff --git a/init/main.c b/init/main.c
64883index ff49a6d..5fa0429 100644
64884--- a/init/main.c
64885+++ b/init/main.c
64886@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
64887 extern void tc_init(void);
64888 #endif
64889
64890+extern void grsecurity_init(void);
64891+
64892 /*
64893 * Debug helper: via this flag we know that we are in 'early bootup code'
64894 * where only the boot processor is running with IRQ disabled. This means
64895@@ -149,6 +151,49 @@ static int __init set_reset_devices(char *str)
64896
64897 __setup("reset_devices", set_reset_devices);
64898
64899+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
64900+extern char pax_enter_kernel_user[];
64901+extern char pax_exit_kernel_user[];
64902+extern pgdval_t clone_pgd_mask;
64903+#endif
64904+
64905+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
64906+static int __init setup_pax_nouderef(char *str)
64907+{
64908+#ifdef CONFIG_X86_32
64909+ unsigned int cpu;
64910+ struct desc_struct *gdt;
64911+
64912+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
64913+ gdt = get_cpu_gdt_table(cpu);
64914+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
64915+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
64916+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
64917+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
64918+ }
64919+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
64920+#else
64921+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
64922+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
64923+ clone_pgd_mask = ~(pgdval_t)0UL;
64924+#endif
64925+
64926+ return 0;
64927+}
64928+early_param("pax_nouderef", setup_pax_nouderef);
64929+#endif
64930+
64931+#ifdef CONFIG_PAX_SOFTMODE
64932+int pax_softmode;
64933+
64934+static int __init setup_pax_softmode(char *str)
64935+{
64936+ get_option(&str, &pax_softmode);
64937+ return 1;
64938+}
64939+__setup("pax_softmode=", setup_pax_softmode);
64940+#endif
64941+
64942 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
64943 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
64944 static const char *panic_later, *panic_param;
64945@@ -675,6 +720,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
64946 {
64947 int count = preempt_count();
64948 int ret;
64949+ const char *msg1 = "", *msg2 = "";
64950
64951 if (initcall_debug)
64952 ret = do_one_initcall_debug(fn);
64953@@ -687,15 +733,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
64954 sprintf(msgbuf, "error code %d ", ret);
64955
64956 if (preempt_count() != count) {
64957- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
64958+ msg1 = " preemption imbalance";
64959 preempt_count() = count;
64960 }
64961 if (irqs_disabled()) {
64962- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
64963+ msg2 = " disabled interrupts";
64964 local_irq_enable();
64965 }
64966- if (msgbuf[0]) {
64967- printk("initcall %pF returned with %s\n", fn, msgbuf);
64968+ if (msgbuf[0] || *msg1 || *msg2) {
64969+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
64970 }
64971
64972 return ret;
64973@@ -814,7 +860,7 @@ static int __init kernel_init(void * unused)
64974 do_basic_setup();
64975
64976 /* Open the /dev/console on the rootfs, this should never fail */
64977- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
64978+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
64979 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
64980
64981 (void) sys_dup(0);
64982@@ -827,11 +873,13 @@ static int __init kernel_init(void * unused)
64983 if (!ramdisk_execute_command)
64984 ramdisk_execute_command = "/init";
64985
64986- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
64987+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
64988 ramdisk_execute_command = NULL;
64989 prepare_namespace();
64990 }
64991
64992+ grsecurity_init();
64993+
64994 /*
64995 * Ok, we have completed the initial bootup, and
64996 * we're essentially up and running. Get rid of the
64997diff --git a/ipc/mqueue.c b/ipc/mqueue.c
64998index 86ee272..773d937 100644
64999--- a/ipc/mqueue.c
65000+++ b/ipc/mqueue.c
65001@@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65002 mq_bytes = (mq_msg_tblsz +
65003 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
65004
65005+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65006 spin_lock(&mq_lock);
65007 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65008 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
65009diff --git a/ipc/msg.c b/ipc/msg.c
65010index 7385de2..a8180e08 100644
65011--- a/ipc/msg.c
65012+++ b/ipc/msg.c
65013@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65014 return security_msg_queue_associate(msq, msgflg);
65015 }
65016
65017+static struct ipc_ops msg_ops = {
65018+ .getnew = newque,
65019+ .associate = msg_security,
65020+ .more_checks = NULL
65021+};
65022+
65023 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65024 {
65025 struct ipc_namespace *ns;
65026- struct ipc_ops msg_ops;
65027 struct ipc_params msg_params;
65028
65029 ns = current->nsproxy->ipc_ns;
65030
65031- msg_ops.getnew = newque;
65032- msg_ops.associate = msg_security;
65033- msg_ops.more_checks = NULL;
65034-
65035 msg_params.key = key;
65036 msg_params.flg = msgflg;
65037
65038diff --git a/ipc/sem.c b/ipc/sem.c
65039index 5215a81..cfc0cac 100644
65040--- a/ipc/sem.c
65041+++ b/ipc/sem.c
65042@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65043 return 0;
65044 }
65045
65046+static struct ipc_ops sem_ops = {
65047+ .getnew = newary,
65048+ .associate = sem_security,
65049+ .more_checks = sem_more_checks
65050+};
65051+
65052 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65053 {
65054 struct ipc_namespace *ns;
65055- struct ipc_ops sem_ops;
65056 struct ipc_params sem_params;
65057
65058 ns = current->nsproxy->ipc_ns;
65059@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65060 if (nsems < 0 || nsems > ns->sc_semmsl)
65061 return -EINVAL;
65062
65063- sem_ops.getnew = newary;
65064- sem_ops.associate = sem_security;
65065- sem_ops.more_checks = sem_more_checks;
65066-
65067 sem_params.key = key;
65068 sem_params.flg = semflg;
65069 sem_params.u.nsems = nsems;
65070diff --git a/ipc/shm.c b/ipc/shm.c
65071index b76be5b..859e750 100644
65072--- a/ipc/shm.c
65073+++ b/ipc/shm.c
65074@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65075 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65076 #endif
65077
65078+#ifdef CONFIG_GRKERNSEC
65079+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65080+ const time_t shm_createtime, const uid_t cuid,
65081+ const int shmid);
65082+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65083+ const time_t shm_createtime);
65084+#endif
65085+
65086 void shm_init_ns(struct ipc_namespace *ns)
65087 {
65088 ns->shm_ctlmax = SHMMAX;
65089@@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65090 shp->shm_lprid = 0;
65091 shp->shm_atim = shp->shm_dtim = 0;
65092 shp->shm_ctim = get_seconds();
65093+#ifdef CONFIG_GRKERNSEC
65094+ {
65095+ struct timespec timeval;
65096+ do_posix_clock_monotonic_gettime(&timeval);
65097+
65098+ shp->shm_createtime = timeval.tv_sec;
65099+ }
65100+#endif
65101 shp->shm_segsz = size;
65102 shp->shm_nattch = 0;
65103 shp->shm_file = file;
65104@@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65105 return 0;
65106 }
65107
65108+static struct ipc_ops shm_ops = {
65109+ .getnew = newseg,
65110+ .associate = shm_security,
65111+ .more_checks = shm_more_checks
65112+};
65113+
65114 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65115 {
65116 struct ipc_namespace *ns;
65117- struct ipc_ops shm_ops;
65118 struct ipc_params shm_params;
65119
65120 ns = current->nsproxy->ipc_ns;
65121
65122- shm_ops.getnew = newseg;
65123- shm_ops.associate = shm_security;
65124- shm_ops.more_checks = shm_more_checks;
65125-
65126 shm_params.key = key;
65127 shm_params.flg = shmflg;
65128 shm_params.u.size = size;
65129@@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65130 f_mode = FMODE_READ | FMODE_WRITE;
65131 }
65132 if (shmflg & SHM_EXEC) {
65133+
65134+#ifdef CONFIG_PAX_MPROTECT
65135+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
65136+ goto out;
65137+#endif
65138+
65139 prot |= PROT_EXEC;
65140 acc_mode |= S_IXUGO;
65141 }
65142@@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65143 if (err)
65144 goto out_unlock;
65145
65146+#ifdef CONFIG_GRKERNSEC
65147+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65148+ shp->shm_perm.cuid, shmid) ||
65149+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65150+ err = -EACCES;
65151+ goto out_unlock;
65152+ }
65153+#endif
65154+
65155 path = shp->shm_file->f_path;
65156 path_get(&path);
65157 shp->shm_nattch++;
65158+#ifdef CONFIG_GRKERNSEC
65159+ shp->shm_lapid = current->pid;
65160+#endif
65161 size = i_size_read(path.dentry->d_inode);
65162 shm_unlock(shp);
65163
65164diff --git a/kernel/acct.c b/kernel/acct.c
65165index 02e6167..54824f7 100644
65166--- a/kernel/acct.c
65167+++ b/kernel/acct.c
65168@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65169 */
65170 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65171 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65172- file->f_op->write(file, (char *)&ac,
65173+ file->f_op->write(file, (char __force_user *)&ac,
65174 sizeof(acct_t), &file->f_pos);
65175 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65176 set_fs(fs);
65177diff --git a/kernel/audit.c b/kernel/audit.c
65178index bb0eb5b..cf2a03a 100644
65179--- a/kernel/audit.c
65180+++ b/kernel/audit.c
65181@@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65182 3) suppressed due to audit_rate_limit
65183 4) suppressed due to audit_backlog_limit
65184 */
65185-static atomic_t audit_lost = ATOMIC_INIT(0);
65186+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65187
65188 /* The netlink socket. */
65189 static struct sock *audit_sock;
65190@@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65191 unsigned long now;
65192 int print;
65193
65194- atomic_inc(&audit_lost);
65195+ atomic_inc_unchecked(&audit_lost);
65196
65197 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
65198
65199@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
65200 printk(KERN_WARNING
65201 "audit: audit_lost=%d audit_rate_limit=%d "
65202 "audit_backlog_limit=%d\n",
65203- atomic_read(&audit_lost),
65204+ atomic_read_unchecked(&audit_lost),
65205 audit_rate_limit,
65206 audit_backlog_limit);
65207 audit_panic(message);
65208@@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
65209 status_set.pid = audit_pid;
65210 status_set.rate_limit = audit_rate_limit;
65211 status_set.backlog_limit = audit_backlog_limit;
65212- status_set.lost = atomic_read(&audit_lost);
65213+ status_set.lost = atomic_read_unchecked(&audit_lost);
65214 status_set.backlog = skb_queue_len(&audit_skb_queue);
65215 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
65216 &status_set, sizeof(status_set));
65217diff --git a/kernel/auditsc.c b/kernel/auditsc.c
65218index af1de0f..06dfe57 100644
65219--- a/kernel/auditsc.c
65220+++ b/kernel/auditsc.c
65221@@ -2288,7 +2288,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
65222 }
65223
65224 /* global counter which is incremented every time something logs in */
65225-static atomic_t session_id = ATOMIC_INIT(0);
65226+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
65227
65228 /**
65229 * audit_set_loginuid - set current task's audit_context loginuid
65230@@ -2312,7 +2312,7 @@ int audit_set_loginuid(uid_t loginuid)
65231 return -EPERM;
65232 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
65233
65234- sessionid = atomic_inc_return(&session_id);
65235+ sessionid = atomic_inc_return_unchecked(&session_id);
65236 if (context && context->in_syscall) {
65237 struct audit_buffer *ab;
65238
65239diff --git a/kernel/capability.c b/kernel/capability.c
65240index 3f1adb6..c564db0 100644
65241--- a/kernel/capability.c
65242+++ b/kernel/capability.c
65243@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
65244 * before modification is attempted and the application
65245 * fails.
65246 */
65247+ if (tocopy > ARRAY_SIZE(kdata))
65248+ return -EFAULT;
65249+
65250 if (copy_to_user(dataptr, kdata, tocopy
65251 * sizeof(struct __user_cap_data_struct))) {
65252 return -EFAULT;
65253@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
65254 int ret;
65255
65256 rcu_read_lock();
65257- ret = security_capable(__task_cred(t), ns, cap);
65258+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
65259+ gr_task_is_capable(t, __task_cred(t), cap);
65260 rcu_read_unlock();
65261
65262- return (ret == 0);
65263+ return ret;
65264 }
65265
65266 /**
65267@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
65268 int ret;
65269
65270 rcu_read_lock();
65271- ret = security_capable_noaudit(__task_cred(t), ns, cap);
65272+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
65273 rcu_read_unlock();
65274
65275- return (ret == 0);
65276+ return ret;
65277 }
65278
65279 /**
65280@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
65281 BUG();
65282 }
65283
65284- if (security_capable(current_cred(), ns, cap) == 0) {
65285+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
65286 current->flags |= PF_SUPERPRIV;
65287 return true;
65288 }
65289@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
65290 }
65291 EXPORT_SYMBOL(ns_capable);
65292
65293+bool ns_capable_nolog(struct user_namespace *ns, int cap)
65294+{
65295+ if (unlikely(!cap_valid(cap))) {
65296+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
65297+ BUG();
65298+ }
65299+
65300+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
65301+ current->flags |= PF_SUPERPRIV;
65302+ return true;
65303+ }
65304+ return false;
65305+}
65306+EXPORT_SYMBOL(ns_capable_nolog);
65307+
65308 /**
65309 * capable - Determine if the current task has a superior capability in effect
65310 * @cap: The capability to be tested for
65311@@ -408,6 +427,12 @@ bool capable(int cap)
65312 }
65313 EXPORT_SYMBOL(capable);
65314
65315+bool capable_nolog(int cap)
65316+{
65317+ return ns_capable_nolog(&init_user_ns, cap);
65318+}
65319+EXPORT_SYMBOL(capable_nolog);
65320+
65321 /**
65322 * nsown_capable - Check superior capability to one's own user_ns
65323 * @cap: The capability in question
65324diff --git a/kernel/compat.c b/kernel/compat.c
65325index a6d0649..f44fb27 100644
65326--- a/kernel/compat.c
65327+++ b/kernel/compat.c
65328@@ -13,6 +13,7 @@
65329
65330 #include <linux/linkage.h>
65331 #include <linux/compat.h>
65332+#include <linux/module.h>
65333 #include <linux/errno.h>
65334 #include <linux/time.h>
65335 #include <linux/signal.h>
65336@@ -168,7 +169,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
65337 mm_segment_t oldfs;
65338 long ret;
65339
65340- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
65341+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
65342 oldfs = get_fs();
65343 set_fs(KERNEL_DS);
65344 ret = hrtimer_nanosleep_restart(restart);
65345@@ -200,7 +201,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
65346 oldfs = get_fs();
65347 set_fs(KERNEL_DS);
65348 ret = hrtimer_nanosleep(&tu,
65349- rmtp ? (struct timespec __user *)&rmt : NULL,
65350+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
65351 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
65352 set_fs(oldfs);
65353
65354@@ -309,7 +310,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
65355 mm_segment_t old_fs = get_fs();
65356
65357 set_fs(KERNEL_DS);
65358- ret = sys_sigpending((old_sigset_t __user *) &s);
65359+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
65360 set_fs(old_fs);
65361 if (ret == 0)
65362 ret = put_user(s, set);
65363@@ -399,7 +400,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
65364 mm_segment_t old_fs = get_fs();
65365
65366 set_fs(KERNEL_DS);
65367- ret = sys_old_getrlimit(resource, &r);
65368+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
65369 set_fs(old_fs);
65370
65371 if (!ret) {
65372@@ -471,7 +472,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
65373 mm_segment_t old_fs = get_fs();
65374
65375 set_fs(KERNEL_DS);
65376- ret = sys_getrusage(who, (struct rusage __user *) &r);
65377+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
65378 set_fs(old_fs);
65379
65380 if (ret)
65381@@ -498,8 +499,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
65382 set_fs (KERNEL_DS);
65383 ret = sys_wait4(pid,
65384 (stat_addr ?
65385- (unsigned int __user *) &status : NULL),
65386- options, (struct rusage __user *) &r);
65387+ (unsigned int __force_user *) &status : NULL),
65388+ options, (struct rusage __force_user *) &r);
65389 set_fs (old_fs);
65390
65391 if (ret > 0) {
65392@@ -524,8 +525,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
65393 memset(&info, 0, sizeof(info));
65394
65395 set_fs(KERNEL_DS);
65396- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
65397- uru ? (struct rusage __user *)&ru : NULL);
65398+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
65399+ uru ? (struct rusage __force_user *)&ru : NULL);
65400 set_fs(old_fs);
65401
65402 if ((ret < 0) || (info.si_signo == 0))
65403@@ -655,8 +656,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
65404 oldfs = get_fs();
65405 set_fs(KERNEL_DS);
65406 err = sys_timer_settime(timer_id, flags,
65407- (struct itimerspec __user *) &newts,
65408- (struct itimerspec __user *) &oldts);
65409+ (struct itimerspec __force_user *) &newts,
65410+ (struct itimerspec __force_user *) &oldts);
65411 set_fs(oldfs);
65412 if (!err && old && put_compat_itimerspec(old, &oldts))
65413 return -EFAULT;
65414@@ -673,7 +674,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
65415 oldfs = get_fs();
65416 set_fs(KERNEL_DS);
65417 err = sys_timer_gettime(timer_id,
65418- (struct itimerspec __user *) &ts);
65419+ (struct itimerspec __force_user *) &ts);
65420 set_fs(oldfs);
65421 if (!err && put_compat_itimerspec(setting, &ts))
65422 return -EFAULT;
65423@@ -692,7 +693,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
65424 oldfs = get_fs();
65425 set_fs(KERNEL_DS);
65426 err = sys_clock_settime(which_clock,
65427- (struct timespec __user *) &ts);
65428+ (struct timespec __force_user *) &ts);
65429 set_fs(oldfs);
65430 return err;
65431 }
65432@@ -707,7 +708,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
65433 oldfs = get_fs();
65434 set_fs(KERNEL_DS);
65435 err = sys_clock_gettime(which_clock,
65436- (struct timespec __user *) &ts);
65437+ (struct timespec __force_user *) &ts);
65438 set_fs(oldfs);
65439 if (!err && put_compat_timespec(&ts, tp))
65440 return -EFAULT;
65441@@ -727,7 +728,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
65442
65443 oldfs = get_fs();
65444 set_fs(KERNEL_DS);
65445- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
65446+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
65447 set_fs(oldfs);
65448
65449 err = compat_put_timex(utp, &txc);
65450@@ -747,7 +748,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
65451 oldfs = get_fs();
65452 set_fs(KERNEL_DS);
65453 err = sys_clock_getres(which_clock,
65454- (struct timespec __user *) &ts);
65455+ (struct timespec __force_user *) &ts);
65456 set_fs(oldfs);
65457 if (!err && tp && put_compat_timespec(&ts, tp))
65458 return -EFAULT;
65459@@ -759,9 +760,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
65460 long err;
65461 mm_segment_t oldfs;
65462 struct timespec tu;
65463- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
65464+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
65465
65466- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
65467+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
65468 oldfs = get_fs();
65469 set_fs(KERNEL_DS);
65470 err = clock_nanosleep_restart(restart);
65471@@ -793,8 +794,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
65472 oldfs = get_fs();
65473 set_fs(KERNEL_DS);
65474 err = sys_clock_nanosleep(which_clock, flags,
65475- (struct timespec __user *) &in,
65476- (struct timespec __user *) &out);
65477+ (struct timespec __force_user *) &in,
65478+ (struct timespec __force_user *) &out);
65479 set_fs(oldfs);
65480
65481 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
65482diff --git a/kernel/configs.c b/kernel/configs.c
65483index 42e8fa0..9e7406b 100644
65484--- a/kernel/configs.c
65485+++ b/kernel/configs.c
65486@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
65487 struct proc_dir_entry *entry;
65488
65489 /* create the current config file */
65490+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
65491+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
65492+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
65493+ &ikconfig_file_ops);
65494+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65495+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
65496+ &ikconfig_file_ops);
65497+#endif
65498+#else
65499 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
65500 &ikconfig_file_ops);
65501+#endif
65502+
65503 if (!entry)
65504 return -ENOMEM;
65505
65506diff --git a/kernel/cred.c b/kernel/cred.c
65507index 48c6fd3..8398912 100644
65508--- a/kernel/cred.c
65509+++ b/kernel/cred.c
65510@@ -204,6 +204,15 @@ void exit_creds(struct task_struct *tsk)
65511 validate_creds(cred);
65512 put_cred(cred);
65513 }
65514+
65515+#ifdef CONFIG_GRKERNSEC_SETXID
65516+ cred = (struct cred *) tsk->delayed_cred;
65517+ if (cred) {
65518+ tsk->delayed_cred = NULL;
65519+ validate_creds(cred);
65520+ put_cred(cred);
65521+ }
65522+#endif
65523 }
65524
65525 /**
65526@@ -472,7 +481,7 @@ error_put:
65527 * Always returns 0 thus allowing this function to be tail-called at the end
65528 * of, say, sys_setgid().
65529 */
65530-int commit_creds(struct cred *new)
65531+static int __commit_creds(struct cred *new)
65532 {
65533 struct task_struct *task = current;
65534 const struct cred *old = task->real_cred;
65535@@ -491,6 +500,8 @@ int commit_creds(struct cred *new)
65536
65537 get_cred(new); /* we will require a ref for the subj creds too */
65538
65539+ gr_set_role_label(task, new->uid, new->gid);
65540+
65541 /* dumpability changes */
65542 if (old->euid != new->euid ||
65543 old->egid != new->egid ||
65544@@ -540,6 +551,101 @@ int commit_creds(struct cred *new)
65545 put_cred(old);
65546 return 0;
65547 }
65548+#ifdef CONFIG_GRKERNSEC_SETXID
65549+extern int set_user(struct cred *new);
65550+
65551+void gr_delayed_cred_worker(void)
65552+{
65553+ const struct cred *new = current->delayed_cred;
65554+ struct cred *ncred;
65555+
65556+ current->delayed_cred = NULL;
65557+
65558+ if (current_uid() && new != NULL) {
65559+ // from doing get_cred on it when queueing this
65560+ put_cred(new);
65561+ return;
65562+ } else if (new == NULL)
65563+ return;
65564+
65565+ ncred = prepare_creds();
65566+ if (!ncred)
65567+ goto die;
65568+ // uids
65569+ ncred->uid = new->uid;
65570+ ncred->euid = new->euid;
65571+ ncred->suid = new->suid;
65572+ ncred->fsuid = new->fsuid;
65573+ // gids
65574+ ncred->gid = new->gid;
65575+ ncred->egid = new->egid;
65576+ ncred->sgid = new->sgid;
65577+ ncred->fsgid = new->fsgid;
65578+ // groups
65579+ if (set_groups(ncred, new->group_info) < 0) {
65580+ abort_creds(ncred);
65581+ goto die;
65582+ }
65583+ // caps
65584+ ncred->securebits = new->securebits;
65585+ ncred->cap_inheritable = new->cap_inheritable;
65586+ ncred->cap_permitted = new->cap_permitted;
65587+ ncred->cap_effective = new->cap_effective;
65588+ ncred->cap_bset = new->cap_bset;
65589+
65590+ if (set_user(ncred)) {
65591+ abort_creds(ncred);
65592+ goto die;
65593+ }
65594+
65595+ // from doing get_cred on it when queueing this
65596+ put_cred(new);
65597+
65598+ __commit_creds(ncred);
65599+ return;
65600+die:
65601+ // from doing get_cred on it when queueing this
65602+ put_cred(new);
65603+ do_group_exit(SIGKILL);
65604+}
65605+#endif
65606+
65607+int commit_creds(struct cred *new)
65608+{
65609+#ifdef CONFIG_GRKERNSEC_SETXID
65610+ int ret;
65611+ int schedule_it = 0;
65612+ struct task_struct *t;
65613+
65614+ /* we won't get called with tasklist_lock held for writing
65615+ and interrupts disabled as the cred struct in that case is
65616+ init_cred
65617+ */
65618+ if (grsec_enable_setxid && !current_is_single_threaded() &&
65619+ !current_uid() && new->uid) {
65620+ schedule_it = 1;
65621+ }
65622+ ret = __commit_creds(new);
65623+ if (schedule_it) {
65624+ rcu_read_lock();
65625+ read_lock(&tasklist_lock);
65626+ for (t = next_thread(current); t != current;
65627+ t = next_thread(t)) {
65628+ if (t->delayed_cred == NULL) {
65629+ t->delayed_cred = get_cred(new);
65630+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
65631+ set_tsk_need_resched(t);
65632+ }
65633+ }
65634+ read_unlock(&tasklist_lock);
65635+ rcu_read_unlock();
65636+ }
65637+ return ret;
65638+#else
65639+ return __commit_creds(new);
65640+#endif
65641+}
65642+
65643 EXPORT_SYMBOL(commit_creds);
65644
65645 /**
65646diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
65647index 7fda904..59f620c 100644
65648--- a/kernel/debug/debug_core.c
65649+++ b/kernel/debug/debug_core.c
65650@@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
65651 */
65652 static atomic_t masters_in_kgdb;
65653 static atomic_t slaves_in_kgdb;
65654-static atomic_t kgdb_break_tasklet_var;
65655+static atomic_unchecked_t kgdb_break_tasklet_var;
65656 atomic_t kgdb_setting_breakpoint;
65657
65658 struct task_struct *kgdb_usethread;
65659@@ -129,7 +129,7 @@ int kgdb_single_step;
65660 static pid_t kgdb_sstep_pid;
65661
65662 /* to keep track of the CPU which is doing the single stepping*/
65663-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65664+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65665
65666 /*
65667 * If you are debugging a problem where roundup (the collection of
65668@@ -537,7 +537,7 @@ return_normal:
65669 * kernel will only try for the value of sstep_tries before
65670 * giving up and continuing on.
65671 */
65672- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
65673+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
65674 (kgdb_info[cpu].task &&
65675 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
65676 atomic_set(&kgdb_active, -1);
65677@@ -631,8 +631,8 @@ cpu_master_loop:
65678 }
65679
65680 kgdb_restore:
65681- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
65682- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
65683+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
65684+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
65685 if (kgdb_info[sstep_cpu].task)
65686 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
65687 else
65688@@ -829,18 +829,18 @@ static void kgdb_unregister_callbacks(void)
65689 static void kgdb_tasklet_bpt(unsigned long ing)
65690 {
65691 kgdb_breakpoint();
65692- atomic_set(&kgdb_break_tasklet_var, 0);
65693+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
65694 }
65695
65696 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
65697
65698 void kgdb_schedule_breakpoint(void)
65699 {
65700- if (atomic_read(&kgdb_break_tasklet_var) ||
65701+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
65702 atomic_read(&kgdb_active) != -1 ||
65703 atomic_read(&kgdb_setting_breakpoint))
65704 return;
65705- atomic_inc(&kgdb_break_tasklet_var);
65706+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
65707 tasklet_schedule(&kgdb_tasklet_breakpoint);
65708 }
65709 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
65710diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
65711index e2ae734..08a4c5c 100644
65712--- a/kernel/debug/kdb/kdb_main.c
65713+++ b/kernel/debug/kdb/kdb_main.c
65714@@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const char **argv)
65715 list_for_each_entry(mod, kdb_modules, list) {
65716
65717 kdb_printf("%-20s%8u 0x%p ", mod->name,
65718- mod->core_size, (void *)mod);
65719+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
65720 #ifdef CONFIG_MODULE_UNLOAD
65721 kdb_printf("%4ld ", module_refcount(mod));
65722 #endif
65723@@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const char **argv)
65724 kdb_printf(" (Loading)");
65725 else
65726 kdb_printf(" (Live)");
65727- kdb_printf(" 0x%p", mod->module_core);
65728+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
65729
65730 #ifdef CONFIG_MODULE_UNLOAD
65731 {
65732diff --git a/kernel/events/core.c b/kernel/events/core.c
65733index 1b5c081..c375f83 100644
65734--- a/kernel/events/core.c
65735+++ b/kernel/events/core.c
65736@@ -173,7 +173,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
65737 return 0;
65738 }
65739
65740-static atomic64_t perf_event_id;
65741+static atomic64_unchecked_t perf_event_id;
65742
65743 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
65744 enum event_type_t event_type);
65745@@ -2581,7 +2581,7 @@ static void __perf_event_read(void *info)
65746
65747 static inline u64 perf_event_count(struct perf_event *event)
65748 {
65749- return local64_read(&event->count) + atomic64_read(&event->child_count);
65750+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
65751 }
65752
65753 static u64 perf_event_read(struct perf_event *event)
65754@@ -2897,9 +2897,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
65755 mutex_lock(&event->child_mutex);
65756 total += perf_event_read(event);
65757 *enabled += event->total_time_enabled +
65758- atomic64_read(&event->child_total_time_enabled);
65759+ atomic64_read_unchecked(&event->child_total_time_enabled);
65760 *running += event->total_time_running +
65761- atomic64_read(&event->child_total_time_running);
65762+ atomic64_read_unchecked(&event->child_total_time_running);
65763
65764 list_for_each_entry(child, &event->child_list, child_list) {
65765 total += perf_event_read(child);
65766@@ -3306,10 +3306,10 @@ void perf_event_update_userpage(struct perf_event *event)
65767 userpg->offset -= local64_read(&event->hw.prev_count);
65768
65769 userpg->time_enabled = enabled +
65770- atomic64_read(&event->child_total_time_enabled);
65771+ atomic64_read_unchecked(&event->child_total_time_enabled);
65772
65773 userpg->time_running = running +
65774- atomic64_read(&event->child_total_time_running);
65775+ atomic64_read_unchecked(&event->child_total_time_running);
65776
65777 barrier();
65778 ++userpg->lock;
65779@@ -3738,11 +3738,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
65780 values[n++] = perf_event_count(event);
65781 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
65782 values[n++] = enabled +
65783- atomic64_read(&event->child_total_time_enabled);
65784+ atomic64_read_unchecked(&event->child_total_time_enabled);
65785 }
65786 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
65787 values[n++] = running +
65788- atomic64_read(&event->child_total_time_running);
65789+ atomic64_read_unchecked(&event->child_total_time_running);
65790 }
65791 if (read_format & PERF_FORMAT_ID)
65792 values[n++] = primary_event_id(event);
65793@@ -4393,12 +4393,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
65794 * need to add enough zero bytes after the string to handle
65795 * the 64bit alignment we do later.
65796 */
65797- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
65798+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
65799 if (!buf) {
65800 name = strncpy(tmp, "//enomem", sizeof(tmp));
65801 goto got_name;
65802 }
65803- name = d_path(&file->f_path, buf, PATH_MAX);
65804+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
65805 if (IS_ERR(name)) {
65806 name = strncpy(tmp, "//toolong", sizeof(tmp));
65807 goto got_name;
65808@@ -5765,7 +5765,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
65809 event->parent = parent_event;
65810
65811 event->ns = get_pid_ns(current->nsproxy->pid_ns);
65812- event->id = atomic64_inc_return(&perf_event_id);
65813+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
65814
65815 event->state = PERF_EVENT_STATE_INACTIVE;
65816
65817@@ -6287,10 +6287,10 @@ static void sync_child_event(struct perf_event *child_event,
65818 /*
65819 * Add back the child's count to the parent's count:
65820 */
65821- atomic64_add(child_val, &parent_event->child_count);
65822- atomic64_add(child_event->total_time_enabled,
65823+ atomic64_add_unchecked(child_val, &parent_event->child_count);
65824+ atomic64_add_unchecked(child_event->total_time_enabled,
65825 &parent_event->child_total_time_enabled);
65826- atomic64_add(child_event->total_time_running,
65827+ atomic64_add_unchecked(child_event->total_time_running,
65828 &parent_event->child_total_time_running);
65829
65830 /*
65831diff --git a/kernel/exit.c b/kernel/exit.c
65832index 46c8b14..d868958 100644
65833--- a/kernel/exit.c
65834+++ b/kernel/exit.c
65835@@ -58,6 +58,10 @@
65836 #include <asm/pgtable.h>
65837 #include <asm/mmu_context.h>
65838
65839+#ifdef CONFIG_GRKERNSEC
65840+extern rwlock_t grsec_exec_file_lock;
65841+#endif
65842+
65843 static void exit_mm(struct task_struct * tsk);
65844
65845 static void __unhash_process(struct task_struct *p, bool group_dead)
65846@@ -169,6 +173,10 @@ void release_task(struct task_struct * p)
65847 struct task_struct *leader;
65848 int zap_leader;
65849 repeat:
65850+#ifdef CONFIG_NET
65851+ gr_del_task_from_ip_table(p);
65852+#endif
65853+
65854 /* don't need to get the RCU readlock here - the process is dead and
65855 * can't be modifying its own credentials. But shut RCU-lockdep up */
65856 rcu_read_lock();
65857@@ -381,7 +389,7 @@ int allow_signal(int sig)
65858 * know it'll be handled, so that they don't get converted to
65859 * SIGKILL or just silently dropped.
65860 */
65861- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
65862+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
65863 recalc_sigpending();
65864 spin_unlock_irq(&current->sighand->siglock);
65865 return 0;
65866@@ -417,6 +425,17 @@ void daemonize(const char *name, ...)
65867 vsnprintf(current->comm, sizeof(current->comm), name, args);
65868 va_end(args);
65869
65870+#ifdef CONFIG_GRKERNSEC
65871+ write_lock(&grsec_exec_file_lock);
65872+ if (current->exec_file) {
65873+ fput(current->exec_file);
65874+ current->exec_file = NULL;
65875+ }
65876+ write_unlock(&grsec_exec_file_lock);
65877+#endif
65878+
65879+ gr_set_kernel_label(current);
65880+
65881 /*
65882 * If we were started as result of loading a module, close all of the
65883 * user space pages. We don't need them, and if we didn't close them
65884@@ -873,6 +892,8 @@ void do_exit(long code)
65885 struct task_struct *tsk = current;
65886 int group_dead;
65887
65888+ set_fs(USER_DS);
65889+
65890 profile_task_exit(tsk);
65891
65892 WARN_ON(blk_needs_flush_plug(tsk));
65893@@ -889,7 +910,6 @@ void do_exit(long code)
65894 * mm_release()->clear_child_tid() from writing to a user-controlled
65895 * kernel address.
65896 */
65897- set_fs(USER_DS);
65898
65899 ptrace_event(PTRACE_EVENT_EXIT, code);
65900
65901@@ -950,6 +970,9 @@ void do_exit(long code)
65902 tsk->exit_code = code;
65903 taskstats_exit(tsk, group_dead);
65904
65905+ gr_acl_handle_psacct(tsk, code);
65906+ gr_acl_handle_exit();
65907+
65908 exit_mm(tsk);
65909
65910 if (group_dead)
65911@@ -1066,7 +1089,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
65912 * Take down every thread in the group. This is called by fatal signals
65913 * as well as by sys_exit_group (below).
65914 */
65915-void
65916+__noreturn void
65917 do_group_exit(int exit_code)
65918 {
65919 struct signal_struct *sig = current->signal;
65920diff --git a/kernel/fork.c b/kernel/fork.c
65921index 423d5a4..881923e 100644
65922--- a/kernel/fork.c
65923+++ b/kernel/fork.c
65924@@ -285,7 +285,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
65925 *stackend = STACK_END_MAGIC; /* for overflow detection */
65926
65927 #ifdef CONFIG_CC_STACKPROTECTOR
65928- tsk->stack_canary = get_random_int();
65929+ tsk->stack_canary = pax_get_random_long();
65930 #endif
65931
65932 /*
65933@@ -309,13 +309,77 @@ out:
65934 }
65935
65936 #ifdef CONFIG_MMU
65937+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
65938+{
65939+ struct vm_area_struct *tmp;
65940+ unsigned long charge;
65941+ struct mempolicy *pol;
65942+ struct file *file;
65943+
65944+ charge = 0;
65945+ if (mpnt->vm_flags & VM_ACCOUNT) {
65946+ unsigned long len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
65947+ if (security_vm_enough_memory(len))
65948+ goto fail_nomem;
65949+ charge = len;
65950+ }
65951+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
65952+ if (!tmp)
65953+ goto fail_nomem;
65954+ *tmp = *mpnt;
65955+ tmp->vm_mm = mm;
65956+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
65957+ pol = mpol_dup(vma_policy(mpnt));
65958+ if (IS_ERR(pol))
65959+ goto fail_nomem_policy;
65960+ vma_set_policy(tmp, pol);
65961+ if (anon_vma_fork(tmp, mpnt))
65962+ goto fail_nomem_anon_vma_fork;
65963+ tmp->vm_flags &= ~VM_LOCKED;
65964+ tmp->vm_next = tmp->vm_prev = NULL;
65965+ tmp->vm_mirror = NULL;
65966+ file = tmp->vm_file;
65967+ if (file) {
65968+ struct inode *inode = file->f_path.dentry->d_inode;
65969+ struct address_space *mapping = file->f_mapping;
65970+
65971+ get_file(file);
65972+ if (tmp->vm_flags & VM_DENYWRITE)
65973+ atomic_dec(&inode->i_writecount);
65974+ mutex_lock(&mapping->i_mmap_mutex);
65975+ if (tmp->vm_flags & VM_SHARED)
65976+ mapping->i_mmap_writable++;
65977+ flush_dcache_mmap_lock(mapping);
65978+ /* insert tmp into the share list, just after mpnt */
65979+ vma_prio_tree_add(tmp, mpnt);
65980+ flush_dcache_mmap_unlock(mapping);
65981+ mutex_unlock(&mapping->i_mmap_mutex);
65982+ }
65983+
65984+ /*
65985+ * Clear hugetlb-related page reserves for children. This only
65986+ * affects MAP_PRIVATE mappings. Faults generated by the child
65987+ * are not guaranteed to succeed, even if read-only
65988+ */
65989+ if (is_vm_hugetlb_page(tmp))
65990+ reset_vma_resv_huge_pages(tmp);
65991+
65992+ return tmp;
65993+
65994+fail_nomem_anon_vma_fork:
65995+ mpol_put(pol);
65996+fail_nomem_policy:
65997+ kmem_cache_free(vm_area_cachep, tmp);
65998+fail_nomem:
65999+ vm_unacct_memory(charge);
66000+ return NULL;
66001+}
66002+
66003 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66004 {
66005 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66006 struct rb_node **rb_link, *rb_parent;
66007 int retval;
66008- unsigned long charge;
66009- struct mempolicy *pol;
66010
66011 down_write(&oldmm->mmap_sem);
66012 flush_cache_dup_mm(oldmm);
66013@@ -327,8 +391,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66014 mm->locked_vm = 0;
66015 mm->mmap = NULL;
66016 mm->mmap_cache = NULL;
66017- mm->free_area_cache = oldmm->mmap_base;
66018- mm->cached_hole_size = ~0UL;
66019+ mm->free_area_cache = oldmm->free_area_cache;
66020+ mm->cached_hole_size = oldmm->cached_hole_size;
66021 mm->map_count = 0;
66022 cpumask_clear(mm_cpumask(mm));
66023 mm->mm_rb = RB_ROOT;
66024@@ -344,8 +408,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66025
66026 prev = NULL;
66027 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66028- struct file *file;
66029-
66030 if (mpnt->vm_flags & VM_DONTCOPY) {
66031 long pages = vma_pages(mpnt);
66032 mm->total_vm -= pages;
66033@@ -353,53 +415,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66034 -pages);
66035 continue;
66036 }
66037- charge = 0;
66038- if (mpnt->vm_flags & VM_ACCOUNT) {
66039- unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66040- if (security_vm_enough_memory(len))
66041- goto fail_nomem;
66042- charge = len;
66043+ tmp = dup_vma(mm, mpnt);
66044+ if (!tmp) {
66045+ retval = -ENOMEM;
66046+ goto out;
66047 }
66048- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66049- if (!tmp)
66050- goto fail_nomem;
66051- *tmp = *mpnt;
66052- INIT_LIST_HEAD(&tmp->anon_vma_chain);
66053- pol = mpol_dup(vma_policy(mpnt));
66054- retval = PTR_ERR(pol);
66055- if (IS_ERR(pol))
66056- goto fail_nomem_policy;
66057- vma_set_policy(tmp, pol);
66058- tmp->vm_mm = mm;
66059- if (anon_vma_fork(tmp, mpnt))
66060- goto fail_nomem_anon_vma_fork;
66061- tmp->vm_flags &= ~VM_LOCKED;
66062- tmp->vm_next = tmp->vm_prev = NULL;
66063- file = tmp->vm_file;
66064- if (file) {
66065- struct inode *inode = file->f_path.dentry->d_inode;
66066- struct address_space *mapping = file->f_mapping;
66067-
66068- get_file(file);
66069- if (tmp->vm_flags & VM_DENYWRITE)
66070- atomic_dec(&inode->i_writecount);
66071- mutex_lock(&mapping->i_mmap_mutex);
66072- if (tmp->vm_flags & VM_SHARED)
66073- mapping->i_mmap_writable++;
66074- flush_dcache_mmap_lock(mapping);
66075- /* insert tmp into the share list, just after mpnt */
66076- vma_prio_tree_add(tmp, mpnt);
66077- flush_dcache_mmap_unlock(mapping);
66078- mutex_unlock(&mapping->i_mmap_mutex);
66079- }
66080-
66081- /*
66082- * Clear hugetlb-related page reserves for children. This only
66083- * affects MAP_PRIVATE mappings. Faults generated by the child
66084- * are not guaranteed to succeed, even if read-only
66085- */
66086- if (is_vm_hugetlb_page(tmp))
66087- reset_vma_resv_huge_pages(tmp);
66088
66089 /*
66090 * Link in the new vma and copy the page table entries.
66091@@ -422,6 +442,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66092 if (retval)
66093 goto out;
66094 }
66095+
66096+#ifdef CONFIG_PAX_SEGMEXEC
66097+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66098+ struct vm_area_struct *mpnt_m;
66099+
66100+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66101+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66102+
66103+ if (!mpnt->vm_mirror)
66104+ continue;
66105+
66106+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66107+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66108+ mpnt->vm_mirror = mpnt_m;
66109+ } else {
66110+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66111+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66112+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66113+ mpnt->vm_mirror->vm_mirror = mpnt;
66114+ }
66115+ }
66116+ BUG_ON(mpnt_m);
66117+ }
66118+#endif
66119+
66120 /* a new mm has just been created */
66121 arch_dup_mmap(oldmm, mm);
66122 retval = 0;
66123@@ -430,14 +475,6 @@ out:
66124 flush_tlb_mm(oldmm);
66125 up_write(&oldmm->mmap_sem);
66126 return retval;
66127-fail_nomem_anon_vma_fork:
66128- mpol_put(pol);
66129-fail_nomem_policy:
66130- kmem_cache_free(vm_area_cachep, tmp);
66131-fail_nomem:
66132- retval = -ENOMEM;
66133- vm_unacct_memory(charge);
66134- goto out;
66135 }
66136
66137 static inline int mm_alloc_pgd(struct mm_struct *mm)
66138@@ -659,8 +696,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
66139 return ERR_PTR(err);
66140
66141 mm = get_task_mm(task);
66142- if (mm && mm != current->mm &&
66143- !ptrace_may_access(task, mode)) {
66144+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
66145+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
66146 mmput(mm);
66147 mm = ERR_PTR(-EACCES);
66148 }
66149@@ -882,13 +919,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66150 spin_unlock(&fs->lock);
66151 return -EAGAIN;
66152 }
66153- fs->users++;
66154+ atomic_inc(&fs->users);
66155 spin_unlock(&fs->lock);
66156 return 0;
66157 }
66158 tsk->fs = copy_fs_struct(fs);
66159 if (!tsk->fs)
66160 return -ENOMEM;
66161+ gr_set_chroot_entries(tsk, &tsk->fs->root);
66162 return 0;
66163 }
66164
66165@@ -1152,6 +1190,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66166 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66167 #endif
66168 retval = -EAGAIN;
66169+
66170+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66171+
66172 if (atomic_read(&p->real_cred->user->processes) >=
66173 task_rlimit(p, RLIMIT_NPROC)) {
66174 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66175@@ -1307,6 +1348,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66176 if (clone_flags & CLONE_THREAD)
66177 p->tgid = current->tgid;
66178
66179+ gr_copy_label(p);
66180+
66181 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
66182 /*
66183 * Clear TID on mm_release()?
66184@@ -1475,6 +1518,8 @@ bad_fork_cleanup_count:
66185 bad_fork_free:
66186 free_task(p);
66187 fork_out:
66188+ gr_log_forkfail(retval);
66189+
66190 return ERR_PTR(retval);
66191 }
66192
66193@@ -1575,6 +1620,8 @@ long do_fork(unsigned long clone_flags,
66194 if (clone_flags & CLONE_PARENT_SETTID)
66195 put_user(nr, parent_tidptr);
66196
66197+ gr_handle_brute_check();
66198+
66199 if (clone_flags & CLONE_VFORK) {
66200 p->vfork_done = &vfork;
66201 init_completion(&vfork);
66202@@ -1673,7 +1720,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
66203 return 0;
66204
66205 /* don't need lock here; in the worst case we'll do useless copy */
66206- if (fs->users == 1)
66207+ if (atomic_read(&fs->users) == 1)
66208 return 0;
66209
66210 *new_fsp = copy_fs_struct(fs);
66211@@ -1762,7 +1809,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
66212 fs = current->fs;
66213 spin_lock(&fs->lock);
66214 current->fs = new_fs;
66215- if (--fs->users)
66216+ gr_set_chroot_entries(current, &current->fs->root);
66217+ if (atomic_dec_return(&fs->users))
66218 new_fs = NULL;
66219 else
66220 new_fs = fs;
66221diff --git a/kernel/futex.c b/kernel/futex.c
66222index 866c9d5..5c5f828 100644
66223--- a/kernel/futex.c
66224+++ b/kernel/futex.c
66225@@ -54,6 +54,7 @@
66226 #include <linux/mount.h>
66227 #include <linux/pagemap.h>
66228 #include <linux/syscalls.h>
66229+#include <linux/ptrace.h>
66230 #include <linux/signal.h>
66231 #include <linux/export.h>
66232 #include <linux/magic.h>
66233@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
66234 struct page *page, *page_head;
66235 int err, ro = 0;
66236
66237+#ifdef CONFIG_PAX_SEGMEXEC
66238+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
66239+ return -EFAULT;
66240+#endif
66241+
66242 /*
66243 * The futex address must be "naturally" aligned.
66244 */
66245@@ -2721,6 +2727,7 @@ static int __init futex_init(void)
66246 {
66247 u32 curval;
66248 int i;
66249+ mm_segment_t oldfs;
66250
66251 /*
66252 * This will fail and we want it. Some arch implementations do
66253@@ -2732,8 +2739,11 @@ static int __init futex_init(void)
66254 * implementation, the non-functional ones will return
66255 * -ENOSYS.
66256 */
66257+ oldfs = get_fs();
66258+ set_fs(USER_DS);
66259 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
66260 futex_cmpxchg_enabled = 1;
66261+ set_fs(oldfs);
66262
66263 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
66264 plist_head_init(&futex_queues[i].chain);
66265diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
66266index 9b22d03..6295b62 100644
66267--- a/kernel/gcov/base.c
66268+++ b/kernel/gcov/base.c
66269@@ -102,11 +102,6 @@ void gcov_enable_events(void)
66270 }
66271
66272 #ifdef CONFIG_MODULES
66273-static inline int within(void *addr, void *start, unsigned long size)
66274-{
66275- return ((addr >= start) && (addr < start + size));
66276-}
66277-
66278 /* Update list and generate events when modules are unloaded. */
66279 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66280 void *data)
66281@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66282 prev = NULL;
66283 /* Remove entries located in module from linked list. */
66284 for (info = gcov_info_head; info; info = info->next) {
66285- if (within(info, mod->module_core, mod->core_size)) {
66286+ if (within_module_core_rw((unsigned long)info, mod)) {
66287 if (prev)
66288 prev->next = info->next;
66289 else
66290diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
66291index ae34bf5..4e2f3d0 100644
66292--- a/kernel/hrtimer.c
66293+++ b/kernel/hrtimer.c
66294@@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
66295 local_irq_restore(flags);
66296 }
66297
66298-static void run_hrtimer_softirq(struct softirq_action *h)
66299+static void run_hrtimer_softirq(void)
66300 {
66301 hrtimer_peek_ahead_timers();
66302 }
66303diff --git a/kernel/jump_label.c b/kernel/jump_label.c
66304index 01d3b70..9e4d098 100644
66305--- a/kernel/jump_label.c
66306+++ b/kernel/jump_label.c
66307@@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
66308
66309 size = (((unsigned long)stop - (unsigned long)start)
66310 / sizeof(struct jump_entry));
66311+ pax_open_kernel();
66312 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
66313+ pax_close_kernel();
66314 }
66315
66316 static void jump_label_update(struct jump_label_key *key, int enable);
66317@@ -340,10 +342,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
66318 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
66319 struct jump_entry *iter;
66320
66321+ pax_open_kernel();
66322 for (iter = iter_start; iter < iter_stop; iter++) {
66323 if (within_module_init(iter->code, mod))
66324 iter->code = 0;
66325 }
66326+ pax_close_kernel();
66327 }
66328
66329 static int
66330diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
66331index 079f1d3..a407562 100644
66332--- a/kernel/kallsyms.c
66333+++ b/kernel/kallsyms.c
66334@@ -11,6 +11,9 @@
66335 * Changed the compression method from stem compression to "table lookup"
66336 * compression (see scripts/kallsyms.c for a more complete description)
66337 */
66338+#ifdef CONFIG_GRKERNSEC_HIDESYM
66339+#define __INCLUDED_BY_HIDESYM 1
66340+#endif
66341 #include <linux/kallsyms.h>
66342 #include <linux/module.h>
66343 #include <linux/init.h>
66344@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
66345
66346 static inline int is_kernel_inittext(unsigned long addr)
66347 {
66348+ if (system_state != SYSTEM_BOOTING)
66349+ return 0;
66350+
66351 if (addr >= (unsigned long)_sinittext
66352 && addr <= (unsigned long)_einittext)
66353 return 1;
66354 return 0;
66355 }
66356
66357+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66358+#ifdef CONFIG_MODULES
66359+static inline int is_module_text(unsigned long addr)
66360+{
66361+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
66362+ return 1;
66363+
66364+ addr = ktla_ktva(addr);
66365+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
66366+}
66367+#else
66368+static inline int is_module_text(unsigned long addr)
66369+{
66370+ return 0;
66371+}
66372+#endif
66373+#endif
66374+
66375 static inline int is_kernel_text(unsigned long addr)
66376 {
66377 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
66378@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
66379
66380 static inline int is_kernel(unsigned long addr)
66381 {
66382+
66383+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66384+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
66385+ return 1;
66386+
66387+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
66388+#else
66389 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
66390+#endif
66391+
66392 return 1;
66393 return in_gate_area_no_mm(addr);
66394 }
66395
66396 static int is_ksym_addr(unsigned long addr)
66397 {
66398+
66399+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66400+ if (is_module_text(addr))
66401+ return 0;
66402+#endif
66403+
66404 if (all_var)
66405 return is_kernel(addr);
66406
66407@@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
66408
66409 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
66410 {
66411- iter->name[0] = '\0';
66412 iter->nameoff = get_symbol_offset(new_pos);
66413 iter->pos = new_pos;
66414 }
66415@@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
66416 {
66417 struct kallsym_iter *iter = m->private;
66418
66419+#ifdef CONFIG_GRKERNSEC_HIDESYM
66420+ if (current_uid())
66421+ return 0;
66422+#endif
66423+
66424 /* Some debugging symbols have no name. Ignore them. */
66425 if (!iter->name[0])
66426 return 0;
66427@@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
66428 struct kallsym_iter *iter;
66429 int ret;
66430
66431- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
66432+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
66433 if (!iter)
66434 return -ENOMEM;
66435 reset_iter(iter, 0);
66436diff --git a/kernel/kexec.c b/kernel/kexec.c
66437index 7b08867..3bac516 100644
66438--- a/kernel/kexec.c
66439+++ b/kernel/kexec.c
66440@@ -1047,7 +1047,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
66441 unsigned long flags)
66442 {
66443 struct compat_kexec_segment in;
66444- struct kexec_segment out, __user *ksegments;
66445+ struct kexec_segment out;
66446+ struct kexec_segment __user *ksegments;
66447 unsigned long i, result;
66448
66449 /* Don't allow clients that don't understand the native
66450diff --git a/kernel/kmod.c b/kernel/kmod.c
66451index a3a46cb..f2e42f8 100644
66452--- a/kernel/kmod.c
66453+++ b/kernel/kmod.c
66454@@ -75,13 +75,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
66455 * If module auto-loading support is disabled then this function
66456 * becomes a no-operation.
66457 */
66458-int __request_module(bool wait, const char *fmt, ...)
66459+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
66460 {
66461- va_list args;
66462 char module_name[MODULE_NAME_LEN];
66463 unsigned int max_modprobes;
66464 int ret;
66465- char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
66466+ char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
66467 static char *envp[] = { "HOME=/",
66468 "TERM=linux",
66469 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
66470@@ -90,9 +89,7 @@ int __request_module(bool wait, const char *fmt, ...)
66471 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
66472 static int kmod_loop_msg;
66473
66474- va_start(args, fmt);
66475- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
66476- va_end(args);
66477+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
66478 if (ret >= MODULE_NAME_LEN)
66479 return -ENAMETOOLONG;
66480
66481@@ -100,6 +97,20 @@ int __request_module(bool wait, const char *fmt, ...)
66482 if (ret)
66483 return ret;
66484
66485+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66486+ if (!current_uid()) {
66487+ /* hack to workaround consolekit/udisks stupidity */
66488+ read_lock(&tasklist_lock);
66489+ if (!strcmp(current->comm, "mount") &&
66490+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
66491+ read_unlock(&tasklist_lock);
66492+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
66493+ return -EPERM;
66494+ }
66495+ read_unlock(&tasklist_lock);
66496+ }
66497+#endif
66498+
66499 /* If modprobe needs a service that is in a module, we get a recursive
66500 * loop. Limit the number of running kmod threads to max_threads/2 or
66501 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
66502@@ -135,6 +146,47 @@ int __request_module(bool wait, const char *fmt, ...)
66503 atomic_dec(&kmod_concurrent);
66504 return ret;
66505 }
66506+
66507+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
66508+{
66509+ va_list args;
66510+ int ret;
66511+
66512+ va_start(args, fmt);
66513+ ret = ____request_module(wait, module_param, fmt, args);
66514+ va_end(args);
66515+
66516+ return ret;
66517+}
66518+
66519+int __request_module(bool wait, const char *fmt, ...)
66520+{
66521+ va_list args;
66522+ int ret;
66523+
66524+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66525+ if (current_uid()) {
66526+ char module_param[MODULE_NAME_LEN];
66527+
66528+ memset(module_param, 0, sizeof(module_param));
66529+
66530+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
66531+
66532+ va_start(args, fmt);
66533+ ret = ____request_module(wait, module_param, fmt, args);
66534+ va_end(args);
66535+
66536+ return ret;
66537+ }
66538+#endif
66539+
66540+ va_start(args, fmt);
66541+ ret = ____request_module(wait, NULL, fmt, args);
66542+ va_end(args);
66543+
66544+ return ret;
66545+}
66546+
66547 EXPORT_SYMBOL(__request_module);
66548 #endif /* CONFIG_MODULES */
66549
66550@@ -224,7 +276,7 @@ static int wait_for_helper(void *data)
66551 *
66552 * Thus the __user pointer cast is valid here.
66553 */
66554- sys_wait4(pid, (int __user *)&ret, 0, NULL);
66555+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
66556
66557 /*
66558 * If ret is 0, either ____call_usermodehelper failed and the
66559diff --git a/kernel/kprobes.c b/kernel/kprobes.c
66560index c62b854..cb67968 100644
66561--- a/kernel/kprobes.c
66562+++ b/kernel/kprobes.c
66563@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
66564 * kernel image and loaded module images reside. This is required
66565 * so x86_64 can correctly handle the %rip-relative fixups.
66566 */
66567- kip->insns = module_alloc(PAGE_SIZE);
66568+ kip->insns = module_alloc_exec(PAGE_SIZE);
66569 if (!kip->insns) {
66570 kfree(kip);
66571 return NULL;
66572@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
66573 */
66574 if (!list_is_singular(&kip->list)) {
66575 list_del(&kip->list);
66576- module_free(NULL, kip->insns);
66577+ module_free_exec(NULL, kip->insns);
66578 kfree(kip);
66579 }
66580 return 1;
66581@@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
66582 {
66583 int i, err = 0;
66584 unsigned long offset = 0, size = 0;
66585- char *modname, namebuf[128];
66586+ char *modname, namebuf[KSYM_NAME_LEN];
66587 const char *symbol_name;
66588 void *addr;
66589 struct kprobe_blackpoint *kb;
66590@@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
66591 const char *sym = NULL;
66592 unsigned int i = *(loff_t *) v;
66593 unsigned long offset = 0;
66594- char *modname, namebuf[128];
66595+ char *modname, namebuf[KSYM_NAME_LEN];
66596
66597 head = &kprobe_table[i];
66598 preempt_disable();
66599diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
66600index 4e316e1..5501eef 100644
66601--- a/kernel/ksysfs.c
66602+++ b/kernel/ksysfs.c
66603@@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
66604 {
66605 if (count+1 > UEVENT_HELPER_PATH_LEN)
66606 return -ENOENT;
66607+ if (!capable(CAP_SYS_ADMIN))
66608+ return -EPERM;
66609 memcpy(uevent_helper, buf, count);
66610 uevent_helper[count] = '\0';
66611 if (count && uevent_helper[count-1] == '\n')
66612diff --git a/kernel/lockdep.c b/kernel/lockdep.c
66613index 8889f7d..95319b7 100644
66614--- a/kernel/lockdep.c
66615+++ b/kernel/lockdep.c
66616@@ -590,6 +590,10 @@ static int static_obj(void *obj)
66617 end = (unsigned long) &_end,
66618 addr = (unsigned long) obj;
66619
66620+#ifdef CONFIG_PAX_KERNEXEC
66621+ start = ktla_ktva(start);
66622+#endif
66623+
66624 /*
66625 * static variable?
66626 */
66627@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
66628 if (!static_obj(lock->key)) {
66629 debug_locks_off();
66630 printk("INFO: trying to register non-static key.\n");
66631+ printk("lock:%pS key:%pS.\n", lock, lock->key);
66632 printk("the code is fine but needs lockdep annotation.\n");
66633 printk("turning off the locking correctness validator.\n");
66634 dump_stack();
66635@@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
66636 if (!class)
66637 return 0;
66638 }
66639- atomic_inc((atomic_t *)&class->ops);
66640+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
66641 if (very_verbose(class)) {
66642 printk("\nacquire class [%p] %s", class->key, class->name);
66643 if (class->name_version > 1)
66644diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
66645index 91c32a0..b2c71c5 100644
66646--- a/kernel/lockdep_proc.c
66647+++ b/kernel/lockdep_proc.c
66648@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
66649
66650 static void print_name(struct seq_file *m, struct lock_class *class)
66651 {
66652- char str[128];
66653+ char str[KSYM_NAME_LEN];
66654 const char *name = class->name;
66655
66656 if (!name) {
66657diff --git a/kernel/module.c b/kernel/module.c
66658index 3d56b6f..2a22bd0 100644
66659--- a/kernel/module.c
66660+++ b/kernel/module.c
66661@@ -58,6 +58,7 @@
66662 #include <linux/jump_label.h>
66663 #include <linux/pfn.h>
66664 #include <linux/bsearch.h>
66665+#include <linux/grsecurity.h>
66666
66667 #define CREATE_TRACE_POINTS
66668 #include <trace/events/module.h>
66669@@ -113,7 +114,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
66670
66671 /* Bounds of module allocation, for speeding __module_address.
66672 * Protected by module_mutex. */
66673-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
66674+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
66675+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
66676
66677 int register_module_notifier(struct notifier_block * nb)
66678 {
66679@@ -277,7 +279,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66680 return true;
66681
66682 list_for_each_entry_rcu(mod, &modules, list) {
66683- struct symsearch arr[] = {
66684+ struct symsearch modarr[] = {
66685 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
66686 NOT_GPL_ONLY, false },
66687 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
66688@@ -299,7 +301,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66689 #endif
66690 };
66691
66692- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
66693+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
66694 return true;
66695 }
66696 return false;
66697@@ -431,7 +433,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
66698 static int percpu_modalloc(struct module *mod,
66699 unsigned long size, unsigned long align)
66700 {
66701- if (align > PAGE_SIZE) {
66702+ if (align-1 >= PAGE_SIZE) {
66703 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
66704 mod->name, align, PAGE_SIZE);
66705 align = PAGE_SIZE;
66706@@ -1001,7 +1003,7 @@ struct module_attribute module_uevent =
66707 static ssize_t show_coresize(struct module_attribute *mattr,
66708 struct module_kobject *mk, char *buffer)
66709 {
66710- return sprintf(buffer, "%u\n", mk->mod->core_size);
66711+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
66712 }
66713
66714 static struct module_attribute modinfo_coresize =
66715@@ -1010,7 +1012,7 @@ static struct module_attribute modinfo_coresize =
66716 static ssize_t show_initsize(struct module_attribute *mattr,
66717 struct module_kobject *mk, char *buffer)
66718 {
66719- return sprintf(buffer, "%u\n", mk->mod->init_size);
66720+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
66721 }
66722
66723 static struct module_attribute modinfo_initsize =
66724@@ -1224,7 +1226,7 @@ resolve_symbol_wait(struct module *mod,
66725 */
66726 #ifdef CONFIG_SYSFS
66727
66728-#ifdef CONFIG_KALLSYMS
66729+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66730 static inline bool sect_empty(const Elf_Shdr *sect)
66731 {
66732 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
66733@@ -1690,21 +1692,21 @@ static void set_section_ro_nx(void *base,
66734
66735 static void unset_module_core_ro_nx(struct module *mod)
66736 {
66737- set_page_attributes(mod->module_core + mod->core_text_size,
66738- mod->module_core + mod->core_size,
66739+ set_page_attributes(mod->module_core_rw,
66740+ mod->module_core_rw + mod->core_size_rw,
66741 set_memory_x);
66742- set_page_attributes(mod->module_core,
66743- mod->module_core + mod->core_ro_size,
66744+ set_page_attributes(mod->module_core_rx,
66745+ mod->module_core_rx + mod->core_size_rx,
66746 set_memory_rw);
66747 }
66748
66749 static void unset_module_init_ro_nx(struct module *mod)
66750 {
66751- set_page_attributes(mod->module_init + mod->init_text_size,
66752- mod->module_init + mod->init_size,
66753+ set_page_attributes(mod->module_init_rw,
66754+ mod->module_init_rw + mod->init_size_rw,
66755 set_memory_x);
66756- set_page_attributes(mod->module_init,
66757- mod->module_init + mod->init_ro_size,
66758+ set_page_attributes(mod->module_init_rx,
66759+ mod->module_init_rx + mod->init_size_rx,
66760 set_memory_rw);
66761 }
66762
66763@@ -1715,14 +1717,14 @@ void set_all_modules_text_rw(void)
66764
66765 mutex_lock(&module_mutex);
66766 list_for_each_entry_rcu(mod, &modules, list) {
66767- if ((mod->module_core) && (mod->core_text_size)) {
66768- set_page_attributes(mod->module_core,
66769- mod->module_core + mod->core_text_size,
66770+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
66771+ set_page_attributes(mod->module_core_rx,
66772+ mod->module_core_rx + mod->core_size_rx,
66773 set_memory_rw);
66774 }
66775- if ((mod->module_init) && (mod->init_text_size)) {
66776- set_page_attributes(mod->module_init,
66777- mod->module_init + mod->init_text_size,
66778+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
66779+ set_page_attributes(mod->module_init_rx,
66780+ mod->module_init_rx + mod->init_size_rx,
66781 set_memory_rw);
66782 }
66783 }
66784@@ -1736,14 +1738,14 @@ void set_all_modules_text_ro(void)
66785
66786 mutex_lock(&module_mutex);
66787 list_for_each_entry_rcu(mod, &modules, list) {
66788- if ((mod->module_core) && (mod->core_text_size)) {
66789- set_page_attributes(mod->module_core,
66790- mod->module_core + mod->core_text_size,
66791+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
66792+ set_page_attributes(mod->module_core_rx,
66793+ mod->module_core_rx + mod->core_size_rx,
66794 set_memory_ro);
66795 }
66796- if ((mod->module_init) && (mod->init_text_size)) {
66797- set_page_attributes(mod->module_init,
66798- mod->module_init + mod->init_text_size,
66799+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
66800+ set_page_attributes(mod->module_init_rx,
66801+ mod->module_init_rx + mod->init_size_rx,
66802 set_memory_ro);
66803 }
66804 }
66805@@ -1789,16 +1791,19 @@ static void free_module(struct module *mod)
66806
66807 /* This may be NULL, but that's OK */
66808 unset_module_init_ro_nx(mod);
66809- module_free(mod, mod->module_init);
66810+ module_free(mod, mod->module_init_rw);
66811+ module_free_exec(mod, mod->module_init_rx);
66812 kfree(mod->args);
66813 percpu_modfree(mod);
66814
66815 /* Free lock-classes: */
66816- lockdep_free_key_range(mod->module_core, mod->core_size);
66817+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
66818+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
66819
66820 /* Finally, free the core (containing the module structure) */
66821 unset_module_core_ro_nx(mod);
66822- module_free(mod, mod->module_core);
66823+ module_free_exec(mod, mod->module_core_rx);
66824+ module_free(mod, mod->module_core_rw);
66825
66826 #ifdef CONFIG_MPU
66827 update_protections(current->mm);
66828@@ -1867,10 +1872,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66829 unsigned int i;
66830 int ret = 0;
66831 const struct kernel_symbol *ksym;
66832+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66833+ int is_fs_load = 0;
66834+ int register_filesystem_found = 0;
66835+ char *p;
66836+
66837+ p = strstr(mod->args, "grsec_modharden_fs");
66838+ if (p) {
66839+ char *endptr = p + strlen("grsec_modharden_fs");
66840+ /* copy \0 as well */
66841+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
66842+ is_fs_load = 1;
66843+ }
66844+#endif
66845
66846 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
66847 const char *name = info->strtab + sym[i].st_name;
66848
66849+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66850+ /* it's a real shame this will never get ripped and copied
66851+ upstream! ;(
66852+ */
66853+ if (is_fs_load && !strcmp(name, "register_filesystem"))
66854+ register_filesystem_found = 1;
66855+#endif
66856+
66857 switch (sym[i].st_shndx) {
66858 case SHN_COMMON:
66859 /* We compiled with -fno-common. These are not
66860@@ -1891,7 +1917,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66861 ksym = resolve_symbol_wait(mod, info, name);
66862 /* Ok if resolved. */
66863 if (ksym && !IS_ERR(ksym)) {
66864+ pax_open_kernel();
66865 sym[i].st_value = ksym->value;
66866+ pax_close_kernel();
66867 break;
66868 }
66869
66870@@ -1910,11 +1938,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66871 secbase = (unsigned long)mod_percpu(mod);
66872 else
66873 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
66874+ pax_open_kernel();
66875 sym[i].st_value += secbase;
66876+ pax_close_kernel();
66877 break;
66878 }
66879 }
66880
66881+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66882+ if (is_fs_load && !register_filesystem_found) {
66883+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
66884+ ret = -EPERM;
66885+ }
66886+#endif
66887+
66888 return ret;
66889 }
66890
66891@@ -2018,22 +2055,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
66892 || s->sh_entsize != ~0UL
66893 || strstarts(sname, ".init"))
66894 continue;
66895- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
66896+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
66897+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
66898+ else
66899+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
66900 pr_debug("\t%s\n", sname);
66901 }
66902- switch (m) {
66903- case 0: /* executable */
66904- mod->core_size = debug_align(mod->core_size);
66905- mod->core_text_size = mod->core_size;
66906- break;
66907- case 1: /* RO: text and ro-data */
66908- mod->core_size = debug_align(mod->core_size);
66909- mod->core_ro_size = mod->core_size;
66910- break;
66911- case 3: /* whole core */
66912- mod->core_size = debug_align(mod->core_size);
66913- break;
66914- }
66915 }
66916
66917 pr_debug("Init section allocation order:\n");
66918@@ -2047,23 +2074,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
66919 || s->sh_entsize != ~0UL
66920 || !strstarts(sname, ".init"))
66921 continue;
66922- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
66923- | INIT_OFFSET_MASK);
66924+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
66925+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
66926+ else
66927+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
66928+ s->sh_entsize |= INIT_OFFSET_MASK;
66929 pr_debug("\t%s\n", sname);
66930 }
66931- switch (m) {
66932- case 0: /* executable */
66933- mod->init_size = debug_align(mod->init_size);
66934- mod->init_text_size = mod->init_size;
66935- break;
66936- case 1: /* RO: text and ro-data */
66937- mod->init_size = debug_align(mod->init_size);
66938- mod->init_ro_size = mod->init_size;
66939- break;
66940- case 3: /* whole init */
66941- mod->init_size = debug_align(mod->init_size);
66942- break;
66943- }
66944 }
66945 }
66946
66947@@ -2235,7 +2252,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
66948
66949 /* Put symbol section at end of init part of module. */
66950 symsect->sh_flags |= SHF_ALLOC;
66951- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
66952+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
66953 info->index.sym) | INIT_OFFSET_MASK;
66954 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
66955
66956@@ -2250,13 +2267,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
66957 }
66958
66959 /* Append room for core symbols at end of core part. */
66960- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
66961- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
66962- mod->core_size += strtab_size;
66963+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
66964+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
66965+ mod->core_size_rx += strtab_size;
66966
66967 /* Put string table section at end of init part of module. */
66968 strsect->sh_flags |= SHF_ALLOC;
66969- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
66970+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
66971 info->index.str) | INIT_OFFSET_MASK;
66972 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
66973 }
66974@@ -2274,12 +2291,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
66975 /* Make sure we get permanent strtab: don't use info->strtab. */
66976 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
66977
66978+ pax_open_kernel();
66979+
66980 /* Set types up while we still have access to sections. */
66981 for (i = 0; i < mod->num_symtab; i++)
66982 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
66983
66984- mod->core_symtab = dst = mod->module_core + info->symoffs;
66985- mod->core_strtab = s = mod->module_core + info->stroffs;
66986+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
66987+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
66988 src = mod->symtab;
66989 *dst = *src;
66990 *s++ = 0;
66991@@ -2292,6 +2311,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
66992 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
66993 }
66994 mod->core_num_syms = ndst;
66995+
66996+ pax_close_kernel();
66997 }
66998 #else
66999 static inline void layout_symtab(struct module *mod, struct load_info *info)
67000@@ -2325,17 +2346,33 @@ void * __weak module_alloc(unsigned long size)
67001 return size == 0 ? NULL : vmalloc_exec(size);
67002 }
67003
67004-static void *module_alloc_update_bounds(unsigned long size)
67005+static void *module_alloc_update_bounds_rw(unsigned long size)
67006 {
67007 void *ret = module_alloc(size);
67008
67009 if (ret) {
67010 mutex_lock(&module_mutex);
67011 /* Update module bounds. */
67012- if ((unsigned long)ret < module_addr_min)
67013- module_addr_min = (unsigned long)ret;
67014- if ((unsigned long)ret + size > module_addr_max)
67015- module_addr_max = (unsigned long)ret + size;
67016+ if ((unsigned long)ret < module_addr_min_rw)
67017+ module_addr_min_rw = (unsigned long)ret;
67018+ if ((unsigned long)ret + size > module_addr_max_rw)
67019+ module_addr_max_rw = (unsigned long)ret + size;
67020+ mutex_unlock(&module_mutex);
67021+ }
67022+ return ret;
67023+}
67024+
67025+static void *module_alloc_update_bounds_rx(unsigned long size)
67026+{
67027+ void *ret = module_alloc_exec(size);
67028+
67029+ if (ret) {
67030+ mutex_lock(&module_mutex);
67031+ /* Update module bounds. */
67032+ if ((unsigned long)ret < module_addr_min_rx)
67033+ module_addr_min_rx = (unsigned long)ret;
67034+ if ((unsigned long)ret + size > module_addr_max_rx)
67035+ module_addr_max_rx = (unsigned long)ret + size;
67036 mutex_unlock(&module_mutex);
67037 }
67038 return ret;
67039@@ -2512,8 +2549,14 @@ static struct module *setup_load_info(struct load_info *info)
67040 static int check_modinfo(struct module *mod, struct load_info *info)
67041 {
67042 const char *modmagic = get_modinfo(info, "vermagic");
67043+ const char *license = get_modinfo(info, "license");
67044 int err;
67045
67046+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67047+ if (!license || !license_is_gpl_compatible(license))
67048+ return -ENOEXEC;
67049+#endif
67050+
67051 /* This is allowed: modprobe --force will invalidate it. */
67052 if (!modmagic) {
67053 err = try_to_force_load(mod, "bad vermagic");
67054@@ -2536,7 +2579,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67055 }
67056
67057 /* Set up license info based on the info section */
67058- set_license(mod, get_modinfo(info, "license"));
67059+ set_license(mod, license);
67060
67061 return 0;
67062 }
67063@@ -2630,7 +2673,7 @@ static int move_module(struct module *mod, struct load_info *info)
67064 void *ptr;
67065
67066 /* Do the allocs. */
67067- ptr = module_alloc_update_bounds(mod->core_size);
67068+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67069 /*
67070 * The pointer to this block is stored in the module structure
67071 * which is inside the block. Just mark it as not being a
67072@@ -2640,23 +2683,50 @@ static int move_module(struct module *mod, struct load_info *info)
67073 if (!ptr)
67074 return -ENOMEM;
67075
67076- memset(ptr, 0, mod->core_size);
67077- mod->module_core = ptr;
67078+ memset(ptr, 0, mod->core_size_rw);
67079+ mod->module_core_rw = ptr;
67080
67081- ptr = module_alloc_update_bounds(mod->init_size);
67082+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67083 /*
67084 * The pointer to this block is stored in the module structure
67085 * which is inside the block. This block doesn't need to be
67086 * scanned as it contains data and code that will be freed
67087 * after the module is initialized.
67088 */
67089- kmemleak_ignore(ptr);
67090- if (!ptr && mod->init_size) {
67091- module_free(mod, mod->module_core);
67092+ kmemleak_not_leak(ptr);
67093+ if (!ptr && mod->init_size_rw) {
67094+ module_free(mod, mod->module_core_rw);
67095 return -ENOMEM;
67096 }
67097- memset(ptr, 0, mod->init_size);
67098- mod->module_init = ptr;
67099+ memset(ptr, 0, mod->init_size_rw);
67100+ mod->module_init_rw = ptr;
67101+
67102+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67103+ kmemleak_not_leak(ptr);
67104+ if (!ptr) {
67105+ module_free(mod, mod->module_init_rw);
67106+ module_free(mod, mod->module_core_rw);
67107+ return -ENOMEM;
67108+ }
67109+
67110+ pax_open_kernel();
67111+ memset(ptr, 0, mod->core_size_rx);
67112+ pax_close_kernel();
67113+ mod->module_core_rx = ptr;
67114+
67115+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67116+ kmemleak_not_leak(ptr);
67117+ if (!ptr && mod->init_size_rx) {
67118+ module_free_exec(mod, mod->module_core_rx);
67119+ module_free(mod, mod->module_init_rw);
67120+ module_free(mod, mod->module_core_rw);
67121+ return -ENOMEM;
67122+ }
67123+
67124+ pax_open_kernel();
67125+ memset(ptr, 0, mod->init_size_rx);
67126+ pax_close_kernel();
67127+ mod->module_init_rx = ptr;
67128
67129 /* Transfer each section which specifies SHF_ALLOC */
67130 pr_debug("final section addresses:\n");
67131@@ -2667,16 +2737,45 @@ static int move_module(struct module *mod, struct load_info *info)
67132 if (!(shdr->sh_flags & SHF_ALLOC))
67133 continue;
67134
67135- if (shdr->sh_entsize & INIT_OFFSET_MASK)
67136- dest = mod->module_init
67137- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67138- else
67139- dest = mod->module_core + shdr->sh_entsize;
67140+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
67141+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67142+ dest = mod->module_init_rw
67143+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67144+ else
67145+ dest = mod->module_init_rx
67146+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67147+ } else {
67148+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67149+ dest = mod->module_core_rw + shdr->sh_entsize;
67150+ else
67151+ dest = mod->module_core_rx + shdr->sh_entsize;
67152+ }
67153+
67154+ if (shdr->sh_type != SHT_NOBITS) {
67155+
67156+#ifdef CONFIG_PAX_KERNEXEC
67157+#ifdef CONFIG_X86_64
67158+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
67159+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
67160+#endif
67161+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
67162+ pax_open_kernel();
67163+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67164+ pax_close_kernel();
67165+ } else
67166+#endif
67167
67168- if (shdr->sh_type != SHT_NOBITS)
67169 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67170+ }
67171 /* Update sh_addr to point to copy in image. */
67172- shdr->sh_addr = (unsigned long)dest;
67173+
67174+#ifdef CONFIG_PAX_KERNEXEC
67175+ if (shdr->sh_flags & SHF_EXECINSTR)
67176+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
67177+ else
67178+#endif
67179+
67180+ shdr->sh_addr = (unsigned long)dest;
67181 pr_debug("\t0x%lx %s\n",
67182 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
67183 }
67184@@ -2727,12 +2826,12 @@ static void flush_module_icache(const struct module *mod)
67185 * Do it before processing of module parameters, so the module
67186 * can provide parameter accessor functions of its own.
67187 */
67188- if (mod->module_init)
67189- flush_icache_range((unsigned long)mod->module_init,
67190- (unsigned long)mod->module_init
67191- + mod->init_size);
67192- flush_icache_range((unsigned long)mod->module_core,
67193- (unsigned long)mod->module_core + mod->core_size);
67194+ if (mod->module_init_rx)
67195+ flush_icache_range((unsigned long)mod->module_init_rx,
67196+ (unsigned long)mod->module_init_rx
67197+ + mod->init_size_rx);
67198+ flush_icache_range((unsigned long)mod->module_core_rx,
67199+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
67200
67201 set_fs(old_fs);
67202 }
67203@@ -2802,8 +2901,10 @@ out:
67204 static void module_deallocate(struct module *mod, struct load_info *info)
67205 {
67206 percpu_modfree(mod);
67207- module_free(mod, mod->module_init);
67208- module_free(mod, mod->module_core);
67209+ module_free_exec(mod, mod->module_init_rx);
67210+ module_free_exec(mod, mod->module_core_rx);
67211+ module_free(mod, mod->module_init_rw);
67212+ module_free(mod, mod->module_core_rw);
67213 }
67214
67215 int __weak module_finalize(const Elf_Ehdr *hdr,
67216@@ -2867,9 +2968,38 @@ static struct module *load_module(void __user *umod,
67217 if (err)
67218 goto free_unload;
67219
67220+ /* Now copy in args */
67221+ mod->args = strndup_user(uargs, ~0UL >> 1);
67222+ if (IS_ERR(mod->args)) {
67223+ err = PTR_ERR(mod->args);
67224+ goto free_unload;
67225+ }
67226+
67227 /* Set up MODINFO_ATTR fields */
67228 setup_modinfo(mod, &info);
67229
67230+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67231+ {
67232+ char *p, *p2;
67233+
67234+ if (strstr(mod->args, "grsec_modharden_netdev")) {
67235+ 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);
67236+ err = -EPERM;
67237+ goto free_modinfo;
67238+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
67239+ p += strlen("grsec_modharden_normal");
67240+ p2 = strstr(p, "_");
67241+ if (p2) {
67242+ *p2 = '\0';
67243+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
67244+ *p2 = '_';
67245+ }
67246+ err = -EPERM;
67247+ goto free_modinfo;
67248+ }
67249+ }
67250+#endif
67251+
67252 /* Fix up syms, so that st_value is a pointer to location. */
67253 err = simplify_symbols(mod, &info);
67254 if (err < 0)
67255@@ -2885,13 +3015,6 @@ static struct module *load_module(void __user *umod,
67256
67257 flush_module_icache(mod);
67258
67259- /* Now copy in args */
67260- mod->args = strndup_user(uargs, ~0UL >> 1);
67261- if (IS_ERR(mod->args)) {
67262- err = PTR_ERR(mod->args);
67263- goto free_arch_cleanup;
67264- }
67265-
67266 /* Mark state as coming so strong_try_module_get() ignores us. */
67267 mod->state = MODULE_STATE_COMING;
67268
67269@@ -2948,11 +3071,10 @@ static struct module *load_module(void __user *umod,
67270 unlock:
67271 mutex_unlock(&module_mutex);
67272 synchronize_sched();
67273- kfree(mod->args);
67274- free_arch_cleanup:
67275 module_arch_cleanup(mod);
67276 free_modinfo:
67277 free_modinfo(mod);
67278+ kfree(mod->args);
67279 free_unload:
67280 module_unload_free(mod);
67281 free_module:
67282@@ -2993,16 +3115,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67283 MODULE_STATE_COMING, mod);
67284
67285 /* Set RO and NX regions for core */
67286- set_section_ro_nx(mod->module_core,
67287- mod->core_text_size,
67288- mod->core_ro_size,
67289- mod->core_size);
67290+ set_section_ro_nx(mod->module_core_rx,
67291+ mod->core_size_rx,
67292+ mod->core_size_rx,
67293+ mod->core_size_rx);
67294
67295 /* Set RO and NX regions for init */
67296- set_section_ro_nx(mod->module_init,
67297- mod->init_text_size,
67298- mod->init_ro_size,
67299- mod->init_size);
67300+ set_section_ro_nx(mod->module_init_rx,
67301+ mod->init_size_rx,
67302+ mod->init_size_rx,
67303+ mod->init_size_rx);
67304
67305 do_mod_ctors(mod);
67306 /* Start the module */
67307@@ -3048,11 +3170,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67308 mod->strtab = mod->core_strtab;
67309 #endif
67310 unset_module_init_ro_nx(mod);
67311- module_free(mod, mod->module_init);
67312- mod->module_init = NULL;
67313- mod->init_size = 0;
67314- mod->init_ro_size = 0;
67315- mod->init_text_size = 0;
67316+ module_free(mod, mod->module_init_rw);
67317+ module_free_exec(mod, mod->module_init_rx);
67318+ mod->module_init_rw = NULL;
67319+ mod->module_init_rx = NULL;
67320+ mod->init_size_rw = 0;
67321+ mod->init_size_rx = 0;
67322 mutex_unlock(&module_mutex);
67323
67324 return 0;
67325@@ -3083,10 +3206,16 @@ static const char *get_ksymbol(struct module *mod,
67326 unsigned long nextval;
67327
67328 /* At worse, next value is at end of module */
67329- if (within_module_init(addr, mod))
67330- nextval = (unsigned long)mod->module_init+mod->init_text_size;
67331+ if (within_module_init_rx(addr, mod))
67332+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
67333+ else if (within_module_init_rw(addr, mod))
67334+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
67335+ else if (within_module_core_rx(addr, mod))
67336+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
67337+ else if (within_module_core_rw(addr, mod))
67338+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
67339 else
67340- nextval = (unsigned long)mod->module_core+mod->core_text_size;
67341+ return NULL;
67342
67343 /* Scan for closest preceding symbol, and next symbol. (ELF
67344 starts real symbols at 1). */
67345@@ -3321,7 +3450,7 @@ static int m_show(struct seq_file *m, void *p)
67346 char buf[8];
67347
67348 seq_printf(m, "%s %u",
67349- mod->name, mod->init_size + mod->core_size);
67350+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
67351 print_unload_info(m, mod);
67352
67353 /* Informative for users. */
67354@@ -3330,7 +3459,7 @@ static int m_show(struct seq_file *m, void *p)
67355 mod->state == MODULE_STATE_COMING ? "Loading":
67356 "Live");
67357 /* Used by oprofile and other similar tools. */
67358- seq_printf(m, " 0x%pK", mod->module_core);
67359+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
67360
67361 /* Taints info */
67362 if (mod->taints)
67363@@ -3366,7 +3495,17 @@ static const struct file_operations proc_modules_operations = {
67364
67365 static int __init proc_modules_init(void)
67366 {
67367+#ifndef CONFIG_GRKERNSEC_HIDESYM
67368+#ifdef CONFIG_GRKERNSEC_PROC_USER
67369+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67370+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67371+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
67372+#else
67373 proc_create("modules", 0, NULL, &proc_modules_operations);
67374+#endif
67375+#else
67376+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67377+#endif
67378 return 0;
67379 }
67380 module_init(proc_modules_init);
67381@@ -3425,12 +3564,12 @@ struct module *__module_address(unsigned long addr)
67382 {
67383 struct module *mod;
67384
67385- if (addr < module_addr_min || addr > module_addr_max)
67386+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
67387+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
67388 return NULL;
67389
67390 list_for_each_entry_rcu(mod, &modules, list)
67391- if (within_module_core(addr, mod)
67392- || within_module_init(addr, mod))
67393+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
67394 return mod;
67395 return NULL;
67396 }
67397@@ -3464,11 +3603,20 @@ bool is_module_text_address(unsigned long addr)
67398 */
67399 struct module *__module_text_address(unsigned long addr)
67400 {
67401- struct module *mod = __module_address(addr);
67402+ struct module *mod;
67403+
67404+#ifdef CONFIG_X86_32
67405+ addr = ktla_ktva(addr);
67406+#endif
67407+
67408+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
67409+ return NULL;
67410+
67411+ mod = __module_address(addr);
67412+
67413 if (mod) {
67414 /* Make sure it's within the text section. */
67415- if (!within(addr, mod->module_init, mod->init_text_size)
67416- && !within(addr, mod->module_core, mod->core_text_size))
67417+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
67418 mod = NULL;
67419 }
67420 return mod;
67421diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
67422index 7e3443f..b2a1e6b 100644
67423--- a/kernel/mutex-debug.c
67424+++ b/kernel/mutex-debug.c
67425@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
67426 }
67427
67428 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67429- struct thread_info *ti)
67430+ struct task_struct *task)
67431 {
67432 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
67433
67434 /* Mark the current thread as blocked on the lock: */
67435- ti->task->blocked_on = waiter;
67436+ task->blocked_on = waiter;
67437 }
67438
67439 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67440- struct thread_info *ti)
67441+ struct task_struct *task)
67442 {
67443 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
67444- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
67445- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
67446- ti->task->blocked_on = NULL;
67447+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
67448+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
67449+ task->blocked_on = NULL;
67450
67451 list_del_init(&waiter->list);
67452 waiter->task = NULL;
67453diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
67454index 0799fd3..d06ae3b 100644
67455--- a/kernel/mutex-debug.h
67456+++ b/kernel/mutex-debug.h
67457@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
67458 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
67459 extern void debug_mutex_add_waiter(struct mutex *lock,
67460 struct mutex_waiter *waiter,
67461- struct thread_info *ti);
67462+ struct task_struct *task);
67463 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67464- struct thread_info *ti);
67465+ struct task_struct *task);
67466 extern void debug_mutex_unlock(struct mutex *lock);
67467 extern void debug_mutex_init(struct mutex *lock, const char *name,
67468 struct lock_class_key *key);
67469diff --git a/kernel/mutex.c b/kernel/mutex.c
67470index 89096dd..f91ebc5 100644
67471--- a/kernel/mutex.c
67472+++ b/kernel/mutex.c
67473@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67474 spin_lock_mutex(&lock->wait_lock, flags);
67475
67476 debug_mutex_lock_common(lock, &waiter);
67477- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
67478+ debug_mutex_add_waiter(lock, &waiter, task);
67479
67480 /* add waiting tasks to the end of the waitqueue (FIFO): */
67481 list_add_tail(&waiter.list, &lock->wait_list);
67482@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67483 * TASK_UNINTERRUPTIBLE case.)
67484 */
67485 if (unlikely(signal_pending_state(state, task))) {
67486- mutex_remove_waiter(lock, &waiter,
67487- task_thread_info(task));
67488+ mutex_remove_waiter(lock, &waiter, task);
67489 mutex_release(&lock->dep_map, 1, ip);
67490 spin_unlock_mutex(&lock->wait_lock, flags);
67491
67492@@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67493 done:
67494 lock_acquired(&lock->dep_map, ip);
67495 /* got the lock - rejoice! */
67496- mutex_remove_waiter(lock, &waiter, current_thread_info());
67497+ mutex_remove_waiter(lock, &waiter, task);
67498 mutex_set_owner(lock);
67499
67500 /* set it to 0 if there are no waiters left: */
67501diff --git a/kernel/padata.c b/kernel/padata.c
67502index b452599..5d68f4e 100644
67503--- a/kernel/padata.c
67504+++ b/kernel/padata.c
67505@@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_instance *pinst,
67506 padata->pd = pd;
67507 padata->cb_cpu = cb_cpu;
67508
67509- if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
67510- atomic_set(&pd->seq_nr, -1);
67511+ if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
67512+ atomic_set_unchecked(&pd->seq_nr, -1);
67513
67514- padata->seq_nr = atomic_inc_return(&pd->seq_nr);
67515+ padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
67516
67517 target_cpu = padata_cpu_hash(padata);
67518 queue = per_cpu_ptr(pd->pqueue, target_cpu);
67519@@ -444,7 +444,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
67520 padata_init_pqueues(pd);
67521 padata_init_squeues(pd);
67522 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
67523- atomic_set(&pd->seq_nr, -1);
67524+ atomic_set_unchecked(&pd->seq_nr, -1);
67525 atomic_set(&pd->reorder_objects, 0);
67526 atomic_set(&pd->refcnt, 0);
67527 pd->pinst = pinst;
67528diff --git a/kernel/panic.c b/kernel/panic.c
67529index 8ed89a1..e83856a 100644
67530--- a/kernel/panic.c
67531+++ b/kernel/panic.c
67532@@ -402,7 +402,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
67533 const char *board;
67534
67535 printk(KERN_WARNING "------------[ cut here ]------------\n");
67536- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
67537+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
67538 board = dmi_get_system_info(DMI_PRODUCT_NAME);
67539 if (board)
67540 printk(KERN_WARNING "Hardware name: %s\n", board);
67541@@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
67542 */
67543 void __stack_chk_fail(void)
67544 {
67545- panic("stack-protector: Kernel stack is corrupted in: %p\n",
67546+ dump_stack();
67547+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
67548 __builtin_return_address(0));
67549 }
67550 EXPORT_SYMBOL(__stack_chk_fail);
67551diff --git a/kernel/pid.c b/kernel/pid.c
67552index 9f08dfa..6765c40 100644
67553--- a/kernel/pid.c
67554+++ b/kernel/pid.c
67555@@ -33,6 +33,7 @@
67556 #include <linux/rculist.h>
67557 #include <linux/bootmem.h>
67558 #include <linux/hash.h>
67559+#include <linux/security.h>
67560 #include <linux/pid_namespace.h>
67561 #include <linux/init_task.h>
67562 #include <linux/syscalls.h>
67563@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
67564
67565 int pid_max = PID_MAX_DEFAULT;
67566
67567-#define RESERVED_PIDS 300
67568+#define RESERVED_PIDS 500
67569
67570 int pid_max_min = RESERVED_PIDS + 1;
67571 int pid_max_max = PID_MAX_LIMIT;
67572@@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
67573 */
67574 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
67575 {
67576+ struct task_struct *task;
67577+
67578 rcu_lockdep_assert(rcu_read_lock_held(),
67579 "find_task_by_pid_ns() needs rcu_read_lock()"
67580 " protection");
67581- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67582+
67583+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67584+
67585+ if (gr_pid_is_chrooted(task))
67586+ return NULL;
67587+
67588+ return task;
67589 }
67590
67591 struct task_struct *find_task_by_vpid(pid_t vnr)
67592@@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
67593 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
67594 }
67595
67596+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
67597+{
67598+ rcu_lockdep_assert(rcu_read_lock_held(),
67599+ "find_task_by_pid_ns() needs rcu_read_lock()"
67600+ " protection");
67601+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
67602+}
67603+
67604 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
67605 {
67606 struct pid *pid;
67607diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
67608index 125cb67..a4d1c30 100644
67609--- a/kernel/posix-cpu-timers.c
67610+++ b/kernel/posix-cpu-timers.c
67611@@ -6,6 +6,7 @@
67612 #include <linux/posix-timers.h>
67613 #include <linux/errno.h>
67614 #include <linux/math64.h>
67615+#include <linux/security.h>
67616 #include <asm/uaccess.h>
67617 #include <linux/kernel_stat.h>
67618 #include <trace/events/timer.h>
67619@@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
67620
67621 static __init int init_posix_cpu_timers(void)
67622 {
67623- struct k_clock process = {
67624+ static struct k_clock process = {
67625 .clock_getres = process_cpu_clock_getres,
67626 .clock_get = process_cpu_clock_get,
67627 .timer_create = process_cpu_timer_create,
67628 .nsleep = process_cpu_nsleep,
67629 .nsleep_restart = process_cpu_nsleep_restart,
67630 };
67631- struct k_clock thread = {
67632+ static struct k_clock thread = {
67633 .clock_getres = thread_cpu_clock_getres,
67634 .clock_get = thread_cpu_clock_get,
67635 .timer_create = thread_cpu_timer_create,
67636diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
67637index 69185ae..cc2847a 100644
67638--- a/kernel/posix-timers.c
67639+++ b/kernel/posix-timers.c
67640@@ -43,6 +43,7 @@
67641 #include <linux/idr.h>
67642 #include <linux/posix-clock.h>
67643 #include <linux/posix-timers.h>
67644+#include <linux/grsecurity.h>
67645 #include <linux/syscalls.h>
67646 #include <linux/wait.h>
67647 #include <linux/workqueue.h>
67648@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
67649 * which we beg off on and pass to do_sys_settimeofday().
67650 */
67651
67652-static struct k_clock posix_clocks[MAX_CLOCKS];
67653+static struct k_clock *posix_clocks[MAX_CLOCKS];
67654
67655 /*
67656 * These ones are defined below.
67657@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
67658 */
67659 static __init int init_posix_timers(void)
67660 {
67661- struct k_clock clock_realtime = {
67662+ static struct k_clock clock_realtime = {
67663 .clock_getres = hrtimer_get_res,
67664 .clock_get = posix_clock_realtime_get,
67665 .clock_set = posix_clock_realtime_set,
67666@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
67667 .timer_get = common_timer_get,
67668 .timer_del = common_timer_del,
67669 };
67670- struct k_clock clock_monotonic = {
67671+ static struct k_clock clock_monotonic = {
67672 .clock_getres = hrtimer_get_res,
67673 .clock_get = posix_ktime_get_ts,
67674 .nsleep = common_nsleep,
67675@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
67676 .timer_get = common_timer_get,
67677 .timer_del = common_timer_del,
67678 };
67679- struct k_clock clock_monotonic_raw = {
67680+ static struct k_clock clock_monotonic_raw = {
67681 .clock_getres = hrtimer_get_res,
67682 .clock_get = posix_get_monotonic_raw,
67683 };
67684- struct k_clock clock_realtime_coarse = {
67685+ static struct k_clock clock_realtime_coarse = {
67686 .clock_getres = posix_get_coarse_res,
67687 .clock_get = posix_get_realtime_coarse,
67688 };
67689- struct k_clock clock_monotonic_coarse = {
67690+ static struct k_clock clock_monotonic_coarse = {
67691 .clock_getres = posix_get_coarse_res,
67692 .clock_get = posix_get_monotonic_coarse,
67693 };
67694- struct k_clock clock_boottime = {
67695+ static struct k_clock clock_boottime = {
67696 .clock_getres = hrtimer_get_res,
67697 .clock_get = posix_get_boottime,
67698 .nsleep = common_nsleep,
67699@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
67700 return;
67701 }
67702
67703- posix_clocks[clock_id] = *new_clock;
67704+ posix_clocks[clock_id] = new_clock;
67705 }
67706 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
67707
67708@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
67709 return (id & CLOCKFD_MASK) == CLOCKFD ?
67710 &clock_posix_dynamic : &clock_posix_cpu;
67711
67712- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
67713+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
67714 return NULL;
67715- return &posix_clocks[id];
67716+ return posix_clocks[id];
67717 }
67718
67719 static int common_timer_create(struct k_itimer *new_timer)
67720@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
67721 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
67722 return -EFAULT;
67723
67724+ /* only the CLOCK_REALTIME clock can be set, all other clocks
67725+ have their clock_set fptr set to a nosettime dummy function
67726+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
67727+ call common_clock_set, which calls do_sys_settimeofday, which
67728+ we hook
67729+ */
67730+
67731 return kc->clock_set(which_clock, &new_tp);
67732 }
67733
67734diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
67735index d523593..68197a4 100644
67736--- a/kernel/power/poweroff.c
67737+++ b/kernel/power/poweroff.c
67738@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
67739 .enable_mask = SYSRQ_ENABLE_BOOT,
67740 };
67741
67742-static int pm_sysrq_init(void)
67743+static int __init pm_sysrq_init(void)
67744 {
67745 register_sysrq_key('o', &sysrq_poweroff_op);
67746 return 0;
67747diff --git a/kernel/power/process.c b/kernel/power/process.c
67748index 7aac07a..2d3c6dc 100644
67749--- a/kernel/power/process.c
67750+++ b/kernel/power/process.c
67751@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
67752 u64 elapsed_csecs64;
67753 unsigned int elapsed_csecs;
67754 bool wakeup = false;
67755+ bool timedout = false;
67756
67757 do_gettimeofday(&start);
67758
67759@@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
67760
67761 while (true) {
67762 todo = 0;
67763+ if (time_after(jiffies, end_time))
67764+ timedout = true;
67765 read_lock(&tasklist_lock);
67766 do_each_thread(g, p) {
67767 if (p == current || !freeze_task(p))
67768@@ -60,9 +63,13 @@ static int try_to_freeze_tasks(bool user_only)
67769 * try_to_stop() after schedule() in ptrace/signal
67770 * stop sees TIF_FREEZE.
67771 */
67772- if (!task_is_stopped_or_traced(p) &&
67773- !freezer_should_skip(p))
67774+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
67775 todo++;
67776+ if (timedout) {
67777+ printk(KERN_ERR "Task refusing to freeze:\n");
67778+ sched_show_task(p);
67779+ }
67780+ }
67781 } while_each_thread(g, p);
67782 read_unlock(&tasklist_lock);
67783
67784@@ -71,7 +78,7 @@ static int try_to_freeze_tasks(bool user_only)
67785 todo += wq_busy;
67786 }
67787
67788- if (!todo || time_after(jiffies, end_time))
67789+ if (!todo || timedout)
67790 break;
67791
67792 if (pm_wakeup_pending()) {
67793diff --git a/kernel/printk.c b/kernel/printk.c
67794index 32690a0..cd7c798 100644
67795--- a/kernel/printk.c
67796+++ b/kernel/printk.c
67797@@ -313,6 +313,11 @@ static int check_syslog_permissions(int type, bool from_file)
67798 if (from_file && type != SYSLOG_ACTION_OPEN)
67799 return 0;
67800
67801+#ifdef CONFIG_GRKERNSEC_DMESG
67802+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
67803+ return -EPERM;
67804+#endif
67805+
67806 if (syslog_action_restricted(type)) {
67807 if (capable(CAP_SYSLOG))
67808 return 0;
67809diff --git a/kernel/profile.c b/kernel/profile.c
67810index 76b8e77..a2930e8 100644
67811--- a/kernel/profile.c
67812+++ b/kernel/profile.c
67813@@ -39,7 +39,7 @@ struct profile_hit {
67814 /* Oprofile timer tick hook */
67815 static int (*timer_hook)(struct pt_regs *) __read_mostly;
67816
67817-static atomic_t *prof_buffer;
67818+static atomic_unchecked_t *prof_buffer;
67819 static unsigned long prof_len, prof_shift;
67820
67821 int prof_on __read_mostly;
67822@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
67823 hits[i].pc = 0;
67824 continue;
67825 }
67826- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67827+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67828 hits[i].hits = hits[i].pc = 0;
67829 }
67830 }
67831@@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67832 * Add the current hit(s) and flush the write-queue out
67833 * to the global buffer:
67834 */
67835- atomic_add(nr_hits, &prof_buffer[pc]);
67836+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
67837 for (i = 0; i < NR_PROFILE_HIT; ++i) {
67838- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67839+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67840 hits[i].pc = hits[i].hits = 0;
67841 }
67842 out:
67843@@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67844 {
67845 unsigned long pc;
67846 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
67847- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67848+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67849 }
67850 #endif /* !CONFIG_SMP */
67851
67852@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
67853 return -EFAULT;
67854 buf++; p++; count--; read++;
67855 }
67856- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
67857+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
67858 if (copy_to_user(buf, (void *)pnt, count))
67859 return -EFAULT;
67860 read += count;
67861@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
67862 }
67863 #endif
67864 profile_discard_flip_buffers();
67865- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
67866+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
67867 return count;
67868 }
67869
67870diff --git a/kernel/ptrace.c b/kernel/ptrace.c
67871index 00ab2ca..d237f61 100644
67872--- a/kernel/ptrace.c
67873+++ b/kernel/ptrace.c
67874@@ -285,7 +285,7 @@ static int ptrace_attach(struct task_struct *task, long request,
67875 task->ptrace = PT_PTRACED;
67876 if (seize)
67877 task->ptrace |= PT_SEIZED;
67878- if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
67879+ if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
67880 task->ptrace |= PT_PTRACE_CAP;
67881
67882 __ptrace_link(task, current);
67883@@ -491,7 +491,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
67884 break;
67885 return -EIO;
67886 }
67887- if (copy_to_user(dst, buf, retval))
67888+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
67889 return -EFAULT;
67890 copied += retval;
67891 src += retval;
67892@@ -688,7 +688,7 @@ int ptrace_request(struct task_struct *child, long request,
67893 bool seized = child->ptrace & PT_SEIZED;
67894 int ret = -EIO;
67895 siginfo_t siginfo, *si;
67896- void __user *datavp = (void __user *) data;
67897+ void __user *datavp = (__force void __user *) data;
67898 unsigned long __user *datalp = datavp;
67899 unsigned long flags;
67900
67901@@ -890,14 +890,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
67902 goto out;
67903 }
67904
67905+ if (gr_handle_ptrace(child, request)) {
67906+ ret = -EPERM;
67907+ goto out_put_task_struct;
67908+ }
67909+
67910 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67911 ret = ptrace_attach(child, request, data);
67912 /*
67913 * Some architectures need to do book-keeping after
67914 * a ptrace attach.
67915 */
67916- if (!ret)
67917+ if (!ret) {
67918 arch_ptrace_attach(child);
67919+ gr_audit_ptrace(child);
67920+ }
67921 goto out_put_task_struct;
67922 }
67923
67924@@ -923,7 +930,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
67925 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
67926 if (copied != sizeof(tmp))
67927 return -EIO;
67928- return put_user(tmp, (unsigned long __user *)data);
67929+ return put_user(tmp, (__force unsigned long __user *)data);
67930 }
67931
67932 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
67933@@ -1033,14 +1040,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
67934 goto out;
67935 }
67936
67937+ if (gr_handle_ptrace(child, request)) {
67938+ ret = -EPERM;
67939+ goto out_put_task_struct;
67940+ }
67941+
67942 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67943 ret = ptrace_attach(child, request, data);
67944 /*
67945 * Some architectures need to do book-keeping after
67946 * a ptrace attach.
67947 */
67948- if (!ret)
67949+ if (!ret) {
67950 arch_ptrace_attach(child);
67951+ gr_audit_ptrace(child);
67952+ }
67953 goto out_put_task_struct;
67954 }
67955
67956diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
67957index 977296d..c4744dc 100644
67958--- a/kernel/rcutiny.c
67959+++ b/kernel/rcutiny.c
67960@@ -46,7 +46,7 @@
67961 struct rcu_ctrlblk;
67962 static void invoke_rcu_callbacks(void);
67963 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
67964-static void rcu_process_callbacks(struct softirq_action *unused);
67965+static void rcu_process_callbacks(void);
67966 static void __call_rcu(struct rcu_head *head,
67967 void (*func)(struct rcu_head *rcu),
67968 struct rcu_ctrlblk *rcp);
67969@@ -297,7 +297,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
67970 rcu_is_callbacks_kthread()));
67971 }
67972
67973-static void rcu_process_callbacks(struct softirq_action *unused)
67974+static void rcu_process_callbacks(void)
67975 {
67976 __rcu_process_callbacks(&rcu_sched_ctrlblk);
67977 __rcu_process_callbacks(&rcu_bh_ctrlblk);
67978diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
67979index 9cb1ae4..aac7d3e 100644
67980--- a/kernel/rcutiny_plugin.h
67981+++ b/kernel/rcutiny_plugin.h
67982@@ -920,7 +920,7 @@ static int rcu_kthread(void *arg)
67983 have_rcu_kthread_work = morework;
67984 local_irq_restore(flags);
67985 if (work)
67986- rcu_process_callbacks(NULL);
67987+ rcu_process_callbacks();
67988 schedule_timeout_interruptible(1); /* Leave CPU for others. */
67989 }
67990
67991diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
67992index a58ac28..196a3d8 100644
67993--- a/kernel/rcutorture.c
67994+++ b/kernel/rcutorture.c
67995@@ -148,12 +148,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
67996 { 0 };
67997 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
67998 { 0 };
67999-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68000-static atomic_t n_rcu_torture_alloc;
68001-static atomic_t n_rcu_torture_alloc_fail;
68002-static atomic_t n_rcu_torture_free;
68003-static atomic_t n_rcu_torture_mberror;
68004-static atomic_t n_rcu_torture_error;
68005+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68006+static atomic_unchecked_t n_rcu_torture_alloc;
68007+static atomic_unchecked_t n_rcu_torture_alloc_fail;
68008+static atomic_unchecked_t n_rcu_torture_free;
68009+static atomic_unchecked_t n_rcu_torture_mberror;
68010+static atomic_unchecked_t n_rcu_torture_error;
68011 static long n_rcu_torture_boost_ktrerror;
68012 static long n_rcu_torture_boost_rterror;
68013 static long n_rcu_torture_boost_failure;
68014@@ -243,11 +243,11 @@ rcu_torture_alloc(void)
68015
68016 spin_lock_bh(&rcu_torture_lock);
68017 if (list_empty(&rcu_torture_freelist)) {
68018- atomic_inc(&n_rcu_torture_alloc_fail);
68019+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68020 spin_unlock_bh(&rcu_torture_lock);
68021 return NULL;
68022 }
68023- atomic_inc(&n_rcu_torture_alloc);
68024+ atomic_inc_unchecked(&n_rcu_torture_alloc);
68025 p = rcu_torture_freelist.next;
68026 list_del_init(p);
68027 spin_unlock_bh(&rcu_torture_lock);
68028@@ -260,7 +260,7 @@ rcu_torture_alloc(void)
68029 static void
68030 rcu_torture_free(struct rcu_torture *p)
68031 {
68032- atomic_inc(&n_rcu_torture_free);
68033+ atomic_inc_unchecked(&n_rcu_torture_free);
68034 spin_lock_bh(&rcu_torture_lock);
68035 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68036 spin_unlock_bh(&rcu_torture_lock);
68037@@ -380,7 +380,7 @@ rcu_torture_cb(struct rcu_head *p)
68038 i = rp->rtort_pipe_count;
68039 if (i > RCU_TORTURE_PIPE_LEN)
68040 i = RCU_TORTURE_PIPE_LEN;
68041- atomic_inc(&rcu_torture_wcount[i]);
68042+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68043 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68044 rp->rtort_mbtest = 0;
68045 rcu_torture_free(rp);
68046@@ -427,7 +427,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68047 i = rp->rtort_pipe_count;
68048 if (i > RCU_TORTURE_PIPE_LEN)
68049 i = RCU_TORTURE_PIPE_LEN;
68050- atomic_inc(&rcu_torture_wcount[i]);
68051+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68052 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68053 rp->rtort_mbtest = 0;
68054 list_del(&rp->rtort_free);
68055@@ -916,7 +916,7 @@ rcu_torture_writer(void *arg)
68056 i = old_rp->rtort_pipe_count;
68057 if (i > RCU_TORTURE_PIPE_LEN)
68058 i = RCU_TORTURE_PIPE_LEN;
68059- atomic_inc(&rcu_torture_wcount[i]);
68060+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68061 old_rp->rtort_pipe_count++;
68062 cur_ops->deferred_free(old_rp);
68063 }
68064@@ -997,7 +997,7 @@ static void rcu_torture_timer(unsigned long unused)
68065 return;
68066 }
68067 if (p->rtort_mbtest == 0)
68068- atomic_inc(&n_rcu_torture_mberror);
68069+ atomic_inc_unchecked(&n_rcu_torture_mberror);
68070 spin_lock(&rand_lock);
68071 cur_ops->read_delay(&rand);
68072 n_rcu_torture_timers++;
68073@@ -1061,7 +1061,7 @@ rcu_torture_reader(void *arg)
68074 continue;
68075 }
68076 if (p->rtort_mbtest == 0)
68077- atomic_inc(&n_rcu_torture_mberror);
68078+ atomic_inc_unchecked(&n_rcu_torture_mberror);
68079 cur_ops->read_delay(&rand);
68080 preempt_disable();
68081 pipe_count = p->rtort_pipe_count;
68082@@ -1123,10 +1123,10 @@ rcu_torture_printk(char *page)
68083 rcu_torture_current,
68084 rcu_torture_current_version,
68085 list_empty(&rcu_torture_freelist),
68086- atomic_read(&n_rcu_torture_alloc),
68087- atomic_read(&n_rcu_torture_alloc_fail),
68088- atomic_read(&n_rcu_torture_free),
68089- atomic_read(&n_rcu_torture_mberror),
68090+ atomic_read_unchecked(&n_rcu_torture_alloc),
68091+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68092+ atomic_read_unchecked(&n_rcu_torture_free),
68093+ atomic_read_unchecked(&n_rcu_torture_mberror),
68094 n_rcu_torture_boost_ktrerror,
68095 n_rcu_torture_boost_rterror,
68096 n_rcu_torture_boost_failure,
68097@@ -1136,7 +1136,7 @@ rcu_torture_printk(char *page)
68098 n_online_attempts,
68099 n_offline_successes,
68100 n_offline_attempts);
68101- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68102+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68103 n_rcu_torture_boost_ktrerror != 0 ||
68104 n_rcu_torture_boost_rterror != 0 ||
68105 n_rcu_torture_boost_failure != 0)
68106@@ -1144,7 +1144,7 @@ rcu_torture_printk(char *page)
68107 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68108 if (i > 1) {
68109 cnt += sprintf(&page[cnt], "!!! ");
68110- atomic_inc(&n_rcu_torture_error);
68111+ atomic_inc_unchecked(&n_rcu_torture_error);
68112 WARN_ON_ONCE(1);
68113 }
68114 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68115@@ -1158,7 +1158,7 @@ rcu_torture_printk(char *page)
68116 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68117 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68118 cnt += sprintf(&page[cnt], " %d",
68119- atomic_read(&rcu_torture_wcount[i]));
68120+ atomic_read_unchecked(&rcu_torture_wcount[i]));
68121 }
68122 cnt += sprintf(&page[cnt], "\n");
68123 if (cur_ops->stats)
68124@@ -1600,7 +1600,7 @@ rcu_torture_cleanup(void)
68125
68126 if (cur_ops->cleanup)
68127 cur_ops->cleanup();
68128- if (atomic_read(&n_rcu_torture_error))
68129+ if (atomic_read_unchecked(&n_rcu_torture_error))
68130 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68131 else
68132 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
68133@@ -1664,17 +1664,17 @@ rcu_torture_init(void)
68134
68135 rcu_torture_current = NULL;
68136 rcu_torture_current_version = 0;
68137- atomic_set(&n_rcu_torture_alloc, 0);
68138- atomic_set(&n_rcu_torture_alloc_fail, 0);
68139- atomic_set(&n_rcu_torture_free, 0);
68140- atomic_set(&n_rcu_torture_mberror, 0);
68141- atomic_set(&n_rcu_torture_error, 0);
68142+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
68143+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
68144+ atomic_set_unchecked(&n_rcu_torture_free, 0);
68145+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
68146+ atomic_set_unchecked(&n_rcu_torture_error, 0);
68147 n_rcu_torture_boost_ktrerror = 0;
68148 n_rcu_torture_boost_rterror = 0;
68149 n_rcu_torture_boost_failure = 0;
68150 n_rcu_torture_boosts = 0;
68151 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
68152- atomic_set(&rcu_torture_wcount[i], 0);
68153+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
68154 for_each_possible_cpu(cpu) {
68155 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68156 per_cpu(rcu_torture_count, cpu)[i] = 0;
68157diff --git a/kernel/rcutree.c b/kernel/rcutree.c
68158index 6c4a672..70f3202 100644
68159--- a/kernel/rcutree.c
68160+++ b/kernel/rcutree.c
68161@@ -363,9 +363,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
68162 rcu_prepare_for_idle(smp_processor_id());
68163 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68164 smp_mb__before_atomic_inc(); /* See above. */
68165- atomic_inc(&rdtp->dynticks);
68166+ atomic_inc_unchecked(&rdtp->dynticks);
68167 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
68168- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68169+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68170 }
68171
68172 /**
68173@@ -438,10 +438,10 @@ void rcu_irq_exit(void)
68174 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
68175 {
68176 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
68177- atomic_inc(&rdtp->dynticks);
68178+ atomic_inc_unchecked(&rdtp->dynticks);
68179 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68180 smp_mb__after_atomic_inc(); /* See above. */
68181- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68182+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68183 rcu_cleanup_after_idle(smp_processor_id());
68184 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
68185 if (!is_idle_task(current)) {
68186@@ -531,14 +531,14 @@ void rcu_nmi_enter(void)
68187 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
68188
68189 if (rdtp->dynticks_nmi_nesting == 0 &&
68190- (atomic_read(&rdtp->dynticks) & 0x1))
68191+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
68192 return;
68193 rdtp->dynticks_nmi_nesting++;
68194 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
68195- atomic_inc(&rdtp->dynticks);
68196+ atomic_inc_unchecked(&rdtp->dynticks);
68197 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68198 smp_mb__after_atomic_inc(); /* See above. */
68199- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68200+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68201 }
68202
68203 /**
68204@@ -557,9 +557,9 @@ void rcu_nmi_exit(void)
68205 return;
68206 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68207 smp_mb__before_atomic_inc(); /* See above. */
68208- atomic_inc(&rdtp->dynticks);
68209+ atomic_inc_unchecked(&rdtp->dynticks);
68210 smp_mb__after_atomic_inc(); /* Force delay to next write. */
68211- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68212+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68213 }
68214
68215 #ifdef CONFIG_PROVE_RCU
68216@@ -575,7 +575,7 @@ int rcu_is_cpu_idle(void)
68217 int ret;
68218
68219 preempt_disable();
68220- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68221+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68222 preempt_enable();
68223 return ret;
68224 }
68225@@ -604,7 +604,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
68226 */
68227 static int dyntick_save_progress_counter(struct rcu_data *rdp)
68228 {
68229- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
68230+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68231 return (rdp->dynticks_snap & 0x1) == 0;
68232 }
68233
68234@@ -619,7 +619,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
68235 unsigned int curr;
68236 unsigned int snap;
68237
68238- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
68239+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68240 snap = (unsigned int)rdp->dynticks_snap;
68241
68242 /*
68243@@ -1667,7 +1667,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
68244 /*
68245 * Do RCU core processing for the current CPU.
68246 */
68247-static void rcu_process_callbacks(struct softirq_action *unused)
68248+static void rcu_process_callbacks(void)
68249 {
68250 trace_rcu_utilization("Start RCU core");
68251 __rcu_process_callbacks(&rcu_sched_state,
68252@@ -2030,7 +2030,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
68253 rdp->qlen = 0;
68254 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
68255 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_NESTING);
68256- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
68257+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
68258 rdp->cpu = cpu;
68259 rdp->rsp = rsp;
68260 raw_spin_unlock_irqrestore(&rnp->lock, flags);
68261@@ -2058,8 +2058,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
68262 rdp->n_force_qs_snap = rsp->n_force_qs;
68263 rdp->blimit = blimit;
68264 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_NESTING;
68265- atomic_set(&rdp->dynticks->dynticks,
68266- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
68267+ atomic_set_unchecked(&rdp->dynticks->dynticks,
68268+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
68269 rcu_prepare_for_idle_init(cpu);
68270 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
68271
68272diff --git a/kernel/rcutree.h b/kernel/rcutree.h
68273index fddff92..2c08359 100644
68274--- a/kernel/rcutree.h
68275+++ b/kernel/rcutree.h
68276@@ -87,7 +87,7 @@ struct rcu_dynticks {
68277 long long dynticks_nesting; /* Track irq/process nesting level. */
68278 /* Process level is worth LLONG_MAX/2. */
68279 int dynticks_nmi_nesting; /* Track NMI nesting level. */
68280- atomic_t dynticks; /* Even value for idle, else odd. */
68281+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
68282 };
68283
68284 /* RCU's kthread states for tracing. */
68285diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
68286index 8bb35d7..6ea0a463 100644
68287--- a/kernel/rcutree_plugin.h
68288+++ b/kernel/rcutree_plugin.h
68289@@ -850,7 +850,7 @@ void synchronize_rcu_expedited(void)
68290
68291 /* Clean up and exit. */
68292 smp_mb(); /* ensure expedited GP seen before counter increment. */
68293- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
68294+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
68295 unlock_mb_ret:
68296 mutex_unlock(&sync_rcu_preempt_exp_mutex);
68297 mb_ret:
68298@@ -1833,8 +1833,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
68299
68300 #else /* #ifndef CONFIG_SMP */
68301
68302-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
68303-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
68304+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
68305+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
68306
68307 static int synchronize_sched_expedited_cpu_stop(void *data)
68308 {
68309@@ -1889,7 +1889,7 @@ void synchronize_sched_expedited(void)
68310 int firstsnap, s, snap, trycount = 0;
68311
68312 /* Note that atomic_inc_return() implies full memory barrier. */
68313- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
68314+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
68315 get_online_cpus();
68316
68317 /*
68318@@ -1910,7 +1910,7 @@ void synchronize_sched_expedited(void)
68319 }
68320
68321 /* Check to see if someone else did our work for us. */
68322- s = atomic_read(&sync_sched_expedited_done);
68323+ s = atomic_read_unchecked(&sync_sched_expedited_done);
68324 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
68325 smp_mb(); /* ensure test happens before caller kfree */
68326 return;
68327@@ -1925,7 +1925,7 @@ void synchronize_sched_expedited(void)
68328 * grace period works for us.
68329 */
68330 get_online_cpus();
68331- snap = atomic_read(&sync_sched_expedited_started);
68332+ snap = atomic_read_unchecked(&sync_sched_expedited_started);
68333 smp_mb(); /* ensure read is before try_stop_cpus(). */
68334 }
68335
68336@@ -1936,12 +1936,12 @@ void synchronize_sched_expedited(void)
68337 * than we did beat us to the punch.
68338 */
68339 do {
68340- s = atomic_read(&sync_sched_expedited_done);
68341+ s = atomic_read_unchecked(&sync_sched_expedited_done);
68342 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
68343 smp_mb(); /* ensure test happens before caller kfree */
68344 break;
68345 }
68346- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
68347+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
68348
68349 put_online_cpus();
68350 }
68351diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
68352index 654cfe6..c0b28e2 100644
68353--- a/kernel/rcutree_trace.c
68354+++ b/kernel/rcutree_trace.c
68355@@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
68356 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68357 rdp->qs_pending);
68358 seq_printf(m, " dt=%d/%llx/%d df=%lu",
68359- atomic_read(&rdp->dynticks->dynticks),
68360+ atomic_read_unchecked(&rdp->dynticks->dynticks),
68361 rdp->dynticks->dynticks_nesting,
68362 rdp->dynticks->dynticks_nmi_nesting,
68363 rdp->dynticks_fqs);
68364@@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
68365 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68366 rdp->qs_pending);
68367 seq_printf(m, ",%d,%llx,%d,%lu",
68368- atomic_read(&rdp->dynticks->dynticks),
68369+ atomic_read_unchecked(&rdp->dynticks->dynticks),
68370 rdp->dynticks->dynticks_nesting,
68371 rdp->dynticks->dynticks_nmi_nesting,
68372 rdp->dynticks_fqs);
68373diff --git a/kernel/resource.c b/kernel/resource.c
68374index 7640b3a..5879283 100644
68375--- a/kernel/resource.c
68376+++ b/kernel/resource.c
68377@@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
68378
68379 static int __init ioresources_init(void)
68380 {
68381+#ifdef CONFIG_GRKERNSEC_PROC_ADD
68382+#ifdef CONFIG_GRKERNSEC_PROC_USER
68383+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
68384+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
68385+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68386+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
68387+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
68388+#endif
68389+#else
68390 proc_create("ioports", 0, NULL, &proc_ioports_operations);
68391 proc_create("iomem", 0, NULL, &proc_iomem_operations);
68392+#endif
68393 return 0;
68394 }
68395 __initcall(ioresources_init);
68396diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
68397index 98ec494..4241d6d 100644
68398--- a/kernel/rtmutex-tester.c
68399+++ b/kernel/rtmutex-tester.c
68400@@ -20,7 +20,7 @@
68401 #define MAX_RT_TEST_MUTEXES 8
68402
68403 static spinlock_t rttest_lock;
68404-static atomic_t rttest_event;
68405+static atomic_unchecked_t rttest_event;
68406
68407 struct test_thread_data {
68408 int opcode;
68409@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68410
68411 case RTTEST_LOCKCONT:
68412 td->mutexes[td->opdata] = 1;
68413- td->event = atomic_add_return(1, &rttest_event);
68414+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68415 return 0;
68416
68417 case RTTEST_RESET:
68418@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68419 return 0;
68420
68421 case RTTEST_RESETEVENT:
68422- atomic_set(&rttest_event, 0);
68423+ atomic_set_unchecked(&rttest_event, 0);
68424 return 0;
68425
68426 default:
68427@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68428 return ret;
68429
68430 td->mutexes[id] = 1;
68431- td->event = atomic_add_return(1, &rttest_event);
68432+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68433 rt_mutex_lock(&mutexes[id]);
68434- td->event = atomic_add_return(1, &rttest_event);
68435+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68436 td->mutexes[id] = 4;
68437 return 0;
68438
68439@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68440 return ret;
68441
68442 td->mutexes[id] = 1;
68443- td->event = atomic_add_return(1, &rttest_event);
68444+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68445 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
68446- td->event = atomic_add_return(1, &rttest_event);
68447+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68448 td->mutexes[id] = ret ? 0 : 4;
68449 return ret ? -EINTR : 0;
68450
68451@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68452 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
68453 return ret;
68454
68455- td->event = atomic_add_return(1, &rttest_event);
68456+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68457 rt_mutex_unlock(&mutexes[id]);
68458- td->event = atomic_add_return(1, &rttest_event);
68459+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68460 td->mutexes[id] = 0;
68461 return 0;
68462
68463@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68464 break;
68465
68466 td->mutexes[dat] = 2;
68467- td->event = atomic_add_return(1, &rttest_event);
68468+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68469 break;
68470
68471 default:
68472@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68473 return;
68474
68475 td->mutexes[dat] = 3;
68476- td->event = atomic_add_return(1, &rttest_event);
68477+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68478 break;
68479
68480 case RTTEST_LOCKNOWAIT:
68481@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68482 return;
68483
68484 td->mutexes[dat] = 1;
68485- td->event = atomic_add_return(1, &rttest_event);
68486+ td->event = atomic_add_return_unchecked(1, &rttest_event);
68487 return;
68488
68489 default:
68490diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
68491index e8a1f83..363d17d 100644
68492--- a/kernel/sched/auto_group.c
68493+++ b/kernel/sched/auto_group.c
68494@@ -11,7 +11,7 @@
68495
68496 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
68497 static struct autogroup autogroup_default;
68498-static atomic_t autogroup_seq_nr;
68499+static atomic_unchecked_t autogroup_seq_nr;
68500
68501 void __init autogroup_init(struct task_struct *init_task)
68502 {
68503@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
68504
68505 kref_init(&ag->kref);
68506 init_rwsem(&ag->lock);
68507- ag->id = atomic_inc_return(&autogroup_seq_nr);
68508+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
68509 ag->tg = tg;
68510 #ifdef CONFIG_RT_GROUP_SCHED
68511 /*
68512diff --git a/kernel/sched/core.c b/kernel/sched/core.c
68513index 478a04c..e16339a 100644
68514--- a/kernel/sched/core.c
68515+++ b/kernel/sched/core.c
68516@@ -3851,6 +3851,8 @@ int can_nice(const struct task_struct *p, const int nice)
68517 /* convert nice value [19,-20] to rlimit style value [1,40] */
68518 int nice_rlim = 20 - nice;
68519
68520+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
68521+
68522 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
68523 capable(CAP_SYS_NICE));
68524 }
68525@@ -3884,7 +3886,8 @@ SYSCALL_DEFINE1(nice, int, increment)
68526 if (nice > 19)
68527 nice = 19;
68528
68529- if (increment < 0 && !can_nice(current, nice))
68530+ if (increment < 0 && (!can_nice(current, nice) ||
68531+ gr_handle_chroot_nice()))
68532 return -EPERM;
68533
68534 retval = security_task_setnice(current, nice);
68535@@ -4041,6 +4044,7 @@ recheck:
68536 unsigned long rlim_rtprio =
68537 task_rlimit(p, RLIMIT_RTPRIO);
68538
68539+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
68540 /* can't set/change the rt policy */
68541 if (policy != p->policy && !rlim_rtprio)
68542 return -EPERM;
68543diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
68544index aca16b8..8e3acc4 100644
68545--- a/kernel/sched/fair.c
68546+++ b/kernel/sched/fair.c
68547@@ -5147,7 +5147,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
68548 * run_rebalance_domains is triggered when needed from the scheduler tick.
68549 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
68550 */
68551-static void run_rebalance_domains(struct softirq_action *h)
68552+static void run_rebalance_domains(void)
68553 {
68554 int this_cpu = smp_processor_id();
68555 struct rq *this_rq = cpu_rq(this_cpu);
68556diff --git a/kernel/signal.c b/kernel/signal.c
68557index b09cf3b..b291c66 100644
68558--- a/kernel/signal.c
68559+++ b/kernel/signal.c
68560@@ -46,12 +46,12 @@ static struct kmem_cache *sigqueue_cachep;
68561
68562 int print_fatal_signals __read_mostly;
68563
68564-static void __user *sig_handler(struct task_struct *t, int sig)
68565+static __sighandler_t sig_handler(struct task_struct *t, int sig)
68566 {
68567 return t->sighand->action[sig - 1].sa.sa_handler;
68568 }
68569
68570-static int sig_handler_ignored(void __user *handler, int sig)
68571+static int sig_handler_ignored(__sighandler_t handler, int sig)
68572 {
68573 /* Is it explicitly or implicitly ignored? */
68574 return handler == SIG_IGN ||
68575@@ -61,7 +61,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
68576 static int sig_task_ignored(struct task_struct *t, int sig,
68577 int from_ancestor_ns)
68578 {
68579- void __user *handler;
68580+ __sighandler_t handler;
68581
68582 handler = sig_handler(t, sig);
68583
68584@@ -365,6 +365,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
68585 atomic_inc(&user->sigpending);
68586 rcu_read_unlock();
68587
68588+ if (!override_rlimit)
68589+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
68590+
68591 if (override_rlimit ||
68592 atomic_read(&user->sigpending) <=
68593 task_rlimit(t, RLIMIT_SIGPENDING)) {
68594@@ -489,7 +492,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
68595
68596 int unhandled_signal(struct task_struct *tsk, int sig)
68597 {
68598- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
68599+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
68600 if (is_global_init(tsk))
68601 return 1;
68602 if (handler != SIG_IGN && handler != SIG_DFL)
68603@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
68604 }
68605 }
68606
68607+ /* allow glibc communication via tgkill to other threads in our
68608+ thread group */
68609+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
68610+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
68611+ && gr_handle_signal(t, sig))
68612+ return -EPERM;
68613+
68614 return security_task_kill(t, info, sig, 0);
68615 }
68616
68617@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68618 return send_signal(sig, info, p, 1);
68619 }
68620
68621-static int
68622+int
68623 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68624 {
68625 return send_signal(sig, info, t, 0);
68626@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68627 unsigned long int flags;
68628 int ret, blocked, ignored;
68629 struct k_sigaction *action;
68630+ int is_unhandled = 0;
68631
68632 spin_lock_irqsave(&t->sighand->siglock, flags);
68633 action = &t->sighand->action[sig-1];
68634@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68635 }
68636 if (action->sa.sa_handler == SIG_DFL)
68637 t->signal->flags &= ~SIGNAL_UNKILLABLE;
68638+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
68639+ is_unhandled = 1;
68640 ret = specific_send_sig_info(sig, info, t);
68641 spin_unlock_irqrestore(&t->sighand->siglock, flags);
68642
68643+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
68644+ normal operation */
68645+ if (is_unhandled) {
68646+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
68647+ gr_handle_crash(t, sig);
68648+ }
68649+
68650 return ret;
68651 }
68652
68653@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68654 ret = check_kill_permission(sig, info, p);
68655 rcu_read_unlock();
68656
68657- if (!ret && sig)
68658+ if (!ret && sig) {
68659 ret = do_send_sig_info(sig, info, p, true);
68660+ if (!ret)
68661+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
68662+ }
68663
68664 return ret;
68665 }
68666@@ -2829,7 +2852,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
68667 int error = -ESRCH;
68668
68669 rcu_read_lock();
68670- p = find_task_by_vpid(pid);
68671+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68672+ /* allow glibc communication via tgkill to other threads in our
68673+ thread group */
68674+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
68675+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
68676+ p = find_task_by_vpid_unrestricted(pid);
68677+ else
68678+#endif
68679+ p = find_task_by_vpid(pid);
68680 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
68681 error = check_kill_permission(sig, info, p);
68682 /*
68683diff --git a/kernel/smp.c b/kernel/smp.c
68684index db197d6..17aef0b 100644
68685--- a/kernel/smp.c
68686+++ b/kernel/smp.c
68687@@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
68688 }
68689 EXPORT_SYMBOL(smp_call_function);
68690
68691-void ipi_call_lock(void)
68692+void ipi_call_lock(void) __acquires(call_function.lock)
68693 {
68694 raw_spin_lock(&call_function.lock);
68695 }
68696
68697-void ipi_call_unlock(void)
68698+void ipi_call_unlock(void) __releases(call_function.lock)
68699 {
68700 raw_spin_unlock(&call_function.lock);
68701 }
68702
68703-void ipi_call_lock_irq(void)
68704+void ipi_call_lock_irq(void) __acquires(call_function.lock)
68705 {
68706 raw_spin_lock_irq(&call_function.lock);
68707 }
68708
68709-void ipi_call_unlock_irq(void)
68710+void ipi_call_unlock_irq(void) __releases(call_function.lock)
68711 {
68712 raw_spin_unlock_irq(&call_function.lock);
68713 }
68714diff --git a/kernel/softirq.c b/kernel/softirq.c
68715index 4eb3a0f..6f1fa81 100644
68716--- a/kernel/softirq.c
68717+++ b/kernel/softirq.c
68718@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
68719
68720 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
68721
68722-char *softirq_to_name[NR_SOFTIRQS] = {
68723+const char * const softirq_to_name[NR_SOFTIRQS] = {
68724 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
68725 "TASKLET", "SCHED", "HRTIMER", "RCU"
68726 };
68727@@ -235,7 +235,7 @@ restart:
68728 kstat_incr_softirqs_this_cpu(vec_nr);
68729
68730 trace_softirq_entry(vec_nr);
68731- h->action(h);
68732+ h->action();
68733 trace_softirq_exit(vec_nr);
68734 if (unlikely(prev_count != preempt_count())) {
68735 printk(KERN_ERR "huh, entered softirq %u %s %p"
68736@@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
68737 local_irq_restore(flags);
68738 }
68739
68740-void open_softirq(int nr, void (*action)(struct softirq_action *))
68741+void open_softirq(int nr, void (*action)(void))
68742 {
68743- softirq_vec[nr].action = action;
68744+ pax_open_kernel();
68745+ *(void **)&softirq_vec[nr].action = action;
68746+ pax_close_kernel();
68747 }
68748
68749 /*
68750@@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
68751
68752 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
68753
68754-static void tasklet_action(struct softirq_action *a)
68755+static void tasklet_action(void)
68756 {
68757 struct tasklet_struct *list;
68758
68759@@ -476,7 +478,7 @@ static void tasklet_action(struct softirq_action *a)
68760 }
68761 }
68762
68763-static void tasklet_hi_action(struct softirq_action *a)
68764+static void tasklet_hi_action(void)
68765 {
68766 struct tasklet_struct *list;
68767
68768diff --git a/kernel/sys.c b/kernel/sys.c
68769index 888d227..f04b318 100644
68770--- a/kernel/sys.c
68771+++ b/kernel/sys.c
68772@@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
68773 error = -EACCES;
68774 goto out;
68775 }
68776+
68777+ if (gr_handle_chroot_setpriority(p, niceval)) {
68778+ error = -EACCES;
68779+ goto out;
68780+ }
68781+
68782 no_nice = security_task_setnice(p, niceval);
68783 if (no_nice) {
68784 error = no_nice;
68785@@ -572,6 +578,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
68786 goto error;
68787 }
68788
68789+ if (gr_check_group_change(new->gid, new->egid, -1))
68790+ goto error;
68791+
68792 if (rgid != (gid_t) -1 ||
68793 (egid != (gid_t) -1 && egid != old->gid))
68794 new->sgid = new->egid;
68795@@ -601,6 +610,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
68796 old = current_cred();
68797
68798 retval = -EPERM;
68799+
68800+ if (gr_check_group_change(gid, gid, gid))
68801+ goto error;
68802+
68803 if (nsown_capable(CAP_SETGID))
68804 new->gid = new->egid = new->sgid = new->fsgid = gid;
68805 else if (gid == old->gid || gid == old->sgid)
68806@@ -618,7 +631,7 @@ error:
68807 /*
68808 * change the user struct in a credentials set to match the new UID
68809 */
68810-static int set_user(struct cred *new)
68811+int set_user(struct cred *new)
68812 {
68813 struct user_struct *new_user;
68814
68815@@ -688,6 +701,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
68816 goto error;
68817 }
68818
68819+ if (gr_check_user_change(new->uid, new->euid, -1))
68820+ goto error;
68821+
68822 if (new->uid != old->uid) {
68823 retval = set_user(new);
68824 if (retval < 0)
68825@@ -732,6 +748,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
68826 old = current_cred();
68827
68828 retval = -EPERM;
68829+
68830+ if (gr_check_crash_uid(uid))
68831+ goto error;
68832+ if (gr_check_user_change(uid, uid, uid))
68833+ goto error;
68834+
68835 if (nsown_capable(CAP_SETUID)) {
68836 new->suid = new->uid = uid;
68837 if (uid != old->uid) {
68838@@ -786,6 +808,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
68839 goto error;
68840 }
68841
68842+ if (gr_check_user_change(ruid, euid, -1))
68843+ goto error;
68844+
68845 if (ruid != (uid_t) -1) {
68846 new->uid = ruid;
68847 if (ruid != old->uid) {
68848@@ -850,6 +875,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
68849 goto error;
68850 }
68851
68852+ if (gr_check_group_change(rgid, egid, -1))
68853+ goto error;
68854+
68855 if (rgid != (gid_t) -1)
68856 new->gid = rgid;
68857 if (egid != (gid_t) -1)
68858@@ -896,6 +924,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
68859 old = current_cred();
68860 old_fsuid = old->fsuid;
68861
68862+ if (gr_check_user_change(-1, -1, uid))
68863+ goto error;
68864+
68865 if (uid == old->uid || uid == old->euid ||
68866 uid == old->suid || uid == old->fsuid ||
68867 nsown_capable(CAP_SETUID)) {
68868@@ -906,6 +937,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
68869 }
68870 }
68871
68872+error:
68873 abort_creds(new);
68874 return old_fsuid;
68875
68876@@ -932,12 +964,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
68877 if (gid == old->gid || gid == old->egid ||
68878 gid == old->sgid || gid == old->fsgid ||
68879 nsown_capable(CAP_SETGID)) {
68880+ if (gr_check_group_change(-1, -1, gid))
68881+ goto error;
68882+
68883 if (gid != old_fsgid) {
68884 new->fsgid = gid;
68885 goto change_okay;
68886 }
68887 }
68888
68889+error:
68890 abort_creds(new);
68891 return old_fsgid;
68892
68893@@ -1189,7 +1225,10 @@ static int override_release(char __user *release, int len)
68894 }
68895 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
68896 snprintf(buf, len, "2.6.%u%s", v, rest);
68897- ret = copy_to_user(release, buf, len);
68898+ if (len > sizeof(buf))
68899+ ret = -EFAULT;
68900+ else
68901+ ret = copy_to_user(release, buf, len);
68902 }
68903 return ret;
68904 }
68905@@ -1243,19 +1282,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
68906 return -EFAULT;
68907
68908 down_read(&uts_sem);
68909- error = __copy_to_user(&name->sysname, &utsname()->sysname,
68910+ error = __copy_to_user(name->sysname, &utsname()->sysname,
68911 __OLD_UTS_LEN);
68912 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
68913- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
68914+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
68915 __OLD_UTS_LEN);
68916 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
68917- error |= __copy_to_user(&name->release, &utsname()->release,
68918+ error |= __copy_to_user(name->release, &utsname()->release,
68919 __OLD_UTS_LEN);
68920 error |= __put_user(0, name->release + __OLD_UTS_LEN);
68921- error |= __copy_to_user(&name->version, &utsname()->version,
68922+ error |= __copy_to_user(name->version, &utsname()->version,
68923 __OLD_UTS_LEN);
68924 error |= __put_user(0, name->version + __OLD_UTS_LEN);
68925- error |= __copy_to_user(&name->machine, &utsname()->machine,
68926+ error |= __copy_to_user(name->machine, &utsname()->machine,
68927 __OLD_UTS_LEN);
68928 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
68929 up_read(&uts_sem);
68930@@ -1838,7 +1877,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
68931 error = get_dumpable(me->mm);
68932 break;
68933 case PR_SET_DUMPABLE:
68934- if (arg2 < 0 || arg2 > 1) {
68935+ if (arg2 > 1) {
68936 error = -EINVAL;
68937 break;
68938 }
68939diff --git a/kernel/sysctl.c b/kernel/sysctl.c
68940index f03a6ef..735d95c 100644
68941--- a/kernel/sysctl.c
68942+++ b/kernel/sysctl.c
68943@@ -86,6 +86,13 @@
68944
68945
68946 #if defined(CONFIG_SYSCTL)
68947+#include <linux/grsecurity.h>
68948+#include <linux/grinternal.h>
68949+
68950+extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
68951+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
68952+ const int op);
68953+extern int gr_handle_chroot_sysctl(const int op);
68954
68955 /* External variables not in a header file. */
68956 extern int sysctl_overcommit_memory;
68957@@ -165,10 +172,8 @@ static int proc_taint(struct ctl_table *table, int write,
68958 void __user *buffer, size_t *lenp, loff_t *ppos);
68959 #endif
68960
68961-#ifdef CONFIG_PRINTK
68962 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
68963 void __user *buffer, size_t *lenp, loff_t *ppos);
68964-#endif
68965
68966 #ifdef CONFIG_MAGIC_SYSRQ
68967 /* Note: sysrq code uses it's own private copy */
68968@@ -191,6 +196,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
68969 }
68970
68971 #endif
68972+extern struct ctl_table grsecurity_table[];
68973
68974 static struct ctl_table root_table[];
68975 static struct ctl_table_root sysctl_table_root;
68976@@ -220,6 +226,20 @@ extern struct ctl_table epoll_table[];
68977 int sysctl_legacy_va_layout;
68978 #endif
68979
68980+#ifdef CONFIG_PAX_SOFTMODE
68981+static ctl_table pax_table[] = {
68982+ {
68983+ .procname = "softmode",
68984+ .data = &pax_softmode,
68985+ .maxlen = sizeof(unsigned int),
68986+ .mode = 0600,
68987+ .proc_handler = &proc_dointvec,
68988+ },
68989+
68990+ { }
68991+};
68992+#endif
68993+
68994 /* The default sysctl tables: */
68995
68996 static struct ctl_table root_table[] = {
68997@@ -266,6 +286,22 @@ static int max_extfrag_threshold = 1000;
68998 #endif
68999
69000 static struct ctl_table kern_table[] = {
69001+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69002+ {
69003+ .procname = "grsecurity",
69004+ .mode = 0500,
69005+ .child = grsecurity_table,
69006+ },
69007+#endif
69008+
69009+#ifdef CONFIG_PAX_SOFTMODE
69010+ {
69011+ .procname = "pax",
69012+ .mode = 0500,
69013+ .child = pax_table,
69014+ },
69015+#endif
69016+
69017 {
69018 .procname = "sched_child_runs_first",
69019 .data = &sysctl_sched_child_runs_first,
69020@@ -550,7 +586,7 @@ static struct ctl_table kern_table[] = {
69021 .data = &modprobe_path,
69022 .maxlen = KMOD_PATH_LEN,
69023 .mode = 0644,
69024- .proc_handler = proc_dostring,
69025+ .proc_handler = proc_dostring_modpriv,
69026 },
69027 {
69028 .procname = "modules_disabled",
69029@@ -717,16 +753,20 @@ static struct ctl_table kern_table[] = {
69030 .extra1 = &zero,
69031 .extra2 = &one,
69032 },
69033+#endif
69034 {
69035 .procname = "kptr_restrict",
69036 .data = &kptr_restrict,
69037 .maxlen = sizeof(int),
69038 .mode = 0644,
69039 .proc_handler = proc_dointvec_minmax_sysadmin,
69040+#ifdef CONFIG_GRKERNSEC_HIDESYM
69041+ .extra1 = &two,
69042+#else
69043 .extra1 = &zero,
69044+#endif
69045 .extra2 = &two,
69046 },
69047-#endif
69048 {
69049 .procname = "ngroups_max",
69050 .data = &ngroups_max,
69051@@ -1225,6 +1265,13 @@ static struct ctl_table vm_table[] = {
69052 .proc_handler = proc_dointvec_minmax,
69053 .extra1 = &zero,
69054 },
69055+ {
69056+ .procname = "heap_stack_gap",
69057+ .data = &sysctl_heap_stack_gap,
69058+ .maxlen = sizeof(sysctl_heap_stack_gap),
69059+ .mode = 0644,
69060+ .proc_handler = proc_doulongvec_minmax,
69061+ },
69062 #else
69063 {
69064 .procname = "nr_trim_pages",
69065@@ -1729,6 +1776,17 @@ static int test_perm(int mode, int op)
69066 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
69067 {
69068 int mode;
69069+ int error;
69070+
69071+ if (table->parent != NULL && table->parent->procname != NULL &&
69072+ table->procname != NULL &&
69073+ gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
69074+ return -EACCES;
69075+ if (gr_handle_chroot_sysctl(op))
69076+ return -EACCES;
69077+ error = gr_handle_sysctl(table, op);
69078+ if (error)
69079+ return error;
69080
69081 if (root->permissions)
69082 mode = root->permissions(root, current->nsproxy, table);
69083@@ -2133,6 +2191,16 @@ int proc_dostring(struct ctl_table *table, int write,
69084 buffer, lenp, ppos);
69085 }
69086
69087+int proc_dostring_modpriv(struct ctl_table *table, int write,
69088+ void __user *buffer, size_t *lenp, loff_t *ppos)
69089+{
69090+ if (write && !capable(CAP_SYS_MODULE))
69091+ return -EPERM;
69092+
69093+ return _proc_do_string(table->data, table->maxlen, write,
69094+ buffer, lenp, ppos);
69095+}
69096+
69097 static size_t proc_skip_spaces(char **buf)
69098 {
69099 size_t ret;
69100@@ -2238,6 +2306,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
69101 len = strlen(tmp);
69102 if (len > *size)
69103 len = *size;
69104+ if (len > sizeof(tmp))
69105+ len = sizeof(tmp);
69106 if (copy_to_user(*buf, tmp, len))
69107 return -EFAULT;
69108 *size -= len;
69109@@ -2430,7 +2500,6 @@ static int proc_taint(struct ctl_table *table, int write,
69110 return err;
69111 }
69112
69113-#ifdef CONFIG_PRINTK
69114 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69115 void __user *buffer, size_t *lenp, loff_t *ppos)
69116 {
69117@@ -2439,7 +2508,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69118
69119 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
69120 }
69121-#endif
69122
69123 struct do_proc_dointvec_minmax_conv_param {
69124 int *min;
69125@@ -2554,8 +2622,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
69126 *i = val;
69127 } else {
69128 val = convdiv * (*i) / convmul;
69129- if (!first)
69130+ if (!first) {
69131 err = proc_put_char(&buffer, &left, '\t');
69132+ if (err)
69133+ break;
69134+ }
69135 err = proc_put_long(&buffer, &left, val, false);
69136 if (err)
69137 break;
69138@@ -2950,6 +3021,12 @@ int proc_dostring(struct ctl_table *table, int write,
69139 return -ENOSYS;
69140 }
69141
69142+int proc_dostring_modpriv(struct ctl_table *table, int write,
69143+ void __user *buffer, size_t *lenp, loff_t *ppos)
69144+{
69145+ return -ENOSYS;
69146+}
69147+
69148 int proc_dointvec(struct ctl_table *table, int write,
69149 void __user *buffer, size_t *lenp, loff_t *ppos)
69150 {
69151@@ -3006,6 +3083,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
69152 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
69153 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
69154 EXPORT_SYMBOL(proc_dostring);
69155+EXPORT_SYMBOL(proc_dostring_modpriv);
69156 EXPORT_SYMBOL(proc_doulongvec_minmax);
69157 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
69158 EXPORT_SYMBOL(register_sysctl_table);
69159diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
69160index a650694..aaeeb20 100644
69161--- a/kernel/sysctl_binary.c
69162+++ b/kernel/sysctl_binary.c
69163@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
69164 int i;
69165
69166 set_fs(KERNEL_DS);
69167- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69168+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69169 set_fs(old_fs);
69170 if (result < 0)
69171 goto out_kfree;
69172@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
69173 }
69174
69175 set_fs(KERNEL_DS);
69176- result = vfs_write(file, buffer, str - buffer, &pos);
69177+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69178 set_fs(old_fs);
69179 if (result < 0)
69180 goto out_kfree;
69181@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
69182 int i;
69183
69184 set_fs(KERNEL_DS);
69185- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69186+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69187 set_fs(old_fs);
69188 if (result < 0)
69189 goto out_kfree;
69190@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
69191 }
69192
69193 set_fs(KERNEL_DS);
69194- result = vfs_write(file, buffer, str - buffer, &pos);
69195+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69196 set_fs(old_fs);
69197 if (result < 0)
69198 goto out_kfree;
69199@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
69200 int i;
69201
69202 set_fs(KERNEL_DS);
69203- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69204+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69205 set_fs(old_fs);
69206 if (result < 0)
69207 goto out;
69208@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69209 __le16 dnaddr;
69210
69211 set_fs(KERNEL_DS);
69212- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69213+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69214 set_fs(old_fs);
69215 if (result < 0)
69216 goto out;
69217@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69218 le16_to_cpu(dnaddr) & 0x3ff);
69219
69220 set_fs(KERNEL_DS);
69221- result = vfs_write(file, buf, len, &pos);
69222+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
69223 set_fs(old_fs);
69224 if (result < 0)
69225 goto out;
69226diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
69227index 362da65..ab8ef8c 100644
69228--- a/kernel/sysctl_check.c
69229+++ b/kernel/sysctl_check.c
69230@@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
69231 set_fail(&fail, table, "Directory with extra2");
69232 } else {
69233 if ((table->proc_handler == proc_dostring) ||
69234+ (table->proc_handler == proc_dostring_modpriv) ||
69235 (table->proc_handler == proc_dointvec) ||
69236 (table->proc_handler == proc_dointvec_minmax) ||
69237 (table->proc_handler == proc_dointvec_jiffies) ||
69238diff --git a/kernel/taskstats.c b/kernel/taskstats.c
69239index e660464..c8b9e67 100644
69240--- a/kernel/taskstats.c
69241+++ b/kernel/taskstats.c
69242@@ -27,9 +27,12 @@
69243 #include <linux/cgroup.h>
69244 #include <linux/fs.h>
69245 #include <linux/file.h>
69246+#include <linux/grsecurity.h>
69247 #include <net/genetlink.h>
69248 #include <linux/atomic.h>
69249
69250+extern int gr_is_taskstats_denied(int pid);
69251+
69252 /*
69253 * Maximum length of a cpumask that can be specified in
69254 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
69255@@ -556,6 +559,9 @@ err:
69256
69257 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
69258 {
69259+ if (gr_is_taskstats_denied(current->pid))
69260+ return -EACCES;
69261+
69262 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
69263 return cmd_attr_register_cpumask(info);
69264 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
69265diff --git a/kernel/time.c b/kernel/time.c
69266index 73e416d..cfc6f69 100644
69267--- a/kernel/time.c
69268+++ b/kernel/time.c
69269@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
69270 return error;
69271
69272 if (tz) {
69273+ /* we log in do_settimeofday called below, so don't log twice
69274+ */
69275+ if (!tv)
69276+ gr_log_timechange();
69277+
69278 /* SMP safe, global irq locking makes it work. */
69279 sys_tz = *tz;
69280 update_vsyscall_tz();
69281diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
69282index 8a46f5d..bbe6f9c 100644
69283--- a/kernel/time/alarmtimer.c
69284+++ b/kernel/time/alarmtimer.c
69285@@ -773,7 +773,7 @@ static int __init alarmtimer_init(void)
69286 struct platform_device *pdev;
69287 int error = 0;
69288 int i;
69289- struct k_clock alarm_clock = {
69290+ static struct k_clock alarm_clock = {
69291 .clock_getres = alarm_clock_getres,
69292 .clock_get = alarm_clock_get,
69293 .timer_create = alarm_timer_create,
69294diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
69295index fd4a7b1..fae5c2a 100644
69296--- a/kernel/time/tick-broadcast.c
69297+++ b/kernel/time/tick-broadcast.c
69298@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
69299 * then clear the broadcast bit.
69300 */
69301 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
69302- int cpu = smp_processor_id();
69303+ cpu = smp_processor_id();
69304
69305 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
69306 tick_broadcast_clear_oneshot(cpu);
69307diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
69308index 0c63581..e25dcb6 100644
69309--- a/kernel/time/timekeeping.c
69310+++ b/kernel/time/timekeeping.c
69311@@ -14,6 +14,7 @@
69312 #include <linux/init.h>
69313 #include <linux/mm.h>
69314 #include <linux/sched.h>
69315+#include <linux/grsecurity.h>
69316 #include <linux/syscore_ops.h>
69317 #include <linux/clocksource.h>
69318 #include <linux/jiffies.h>
69319@@ -365,6 +366,8 @@ int do_settimeofday(const struct timespec *tv)
69320 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
69321 return -EINVAL;
69322
69323+ gr_log_timechange();
69324+
69325 write_seqlock_irqsave(&xtime_lock, flags);
69326
69327 timekeeping_forward_now();
69328diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
69329index 3258455..f35227d 100644
69330--- a/kernel/time/timer_list.c
69331+++ b/kernel/time/timer_list.c
69332@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
69333
69334 static void print_name_offset(struct seq_file *m, void *sym)
69335 {
69336+#ifdef CONFIG_GRKERNSEC_HIDESYM
69337+ SEQ_printf(m, "<%p>", NULL);
69338+#else
69339 char symname[KSYM_NAME_LEN];
69340
69341 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
69342 SEQ_printf(m, "<%pK>", sym);
69343 else
69344 SEQ_printf(m, "%s", symname);
69345+#endif
69346 }
69347
69348 static void
69349@@ -112,7 +116,11 @@ next_one:
69350 static void
69351 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
69352 {
69353+#ifdef CONFIG_GRKERNSEC_HIDESYM
69354+ SEQ_printf(m, " .base: %p\n", NULL);
69355+#else
69356 SEQ_printf(m, " .base: %pK\n", base);
69357+#endif
69358 SEQ_printf(m, " .index: %d\n",
69359 base->index);
69360 SEQ_printf(m, " .resolution: %Lu nsecs\n",
69361@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
69362 {
69363 struct proc_dir_entry *pe;
69364
69365+#ifdef CONFIG_GRKERNSEC_PROC_ADD
69366+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
69367+#else
69368 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
69369+#endif
69370 if (!pe)
69371 return -ENOMEM;
69372 return 0;
69373diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
69374index 0b537f2..9e71eca 100644
69375--- a/kernel/time/timer_stats.c
69376+++ b/kernel/time/timer_stats.c
69377@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
69378 static unsigned long nr_entries;
69379 static struct entry entries[MAX_ENTRIES];
69380
69381-static atomic_t overflow_count;
69382+static atomic_unchecked_t overflow_count;
69383
69384 /*
69385 * The entries are in a hash-table, for fast lookup:
69386@@ -140,7 +140,7 @@ static void reset_entries(void)
69387 nr_entries = 0;
69388 memset(entries, 0, sizeof(entries));
69389 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
69390- atomic_set(&overflow_count, 0);
69391+ atomic_set_unchecked(&overflow_count, 0);
69392 }
69393
69394 static struct entry *alloc_entry(void)
69395@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69396 if (likely(entry))
69397 entry->count++;
69398 else
69399- atomic_inc(&overflow_count);
69400+ atomic_inc_unchecked(&overflow_count);
69401
69402 out_unlock:
69403 raw_spin_unlock_irqrestore(lock, flags);
69404@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69405
69406 static void print_name_offset(struct seq_file *m, unsigned long addr)
69407 {
69408+#ifdef CONFIG_GRKERNSEC_HIDESYM
69409+ seq_printf(m, "<%p>", NULL);
69410+#else
69411 char symname[KSYM_NAME_LEN];
69412
69413 if (lookup_symbol_name(addr, symname) < 0)
69414 seq_printf(m, "<%p>", (void *)addr);
69415 else
69416 seq_printf(m, "%s", symname);
69417+#endif
69418 }
69419
69420 static int tstats_show(struct seq_file *m, void *v)
69421@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
69422
69423 seq_puts(m, "Timer Stats Version: v0.2\n");
69424 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
69425- if (atomic_read(&overflow_count))
69426+ if (atomic_read_unchecked(&overflow_count))
69427 seq_printf(m, "Overflow: %d entries\n",
69428- atomic_read(&overflow_count));
69429+ atomic_read_unchecked(&overflow_count));
69430
69431 for (i = 0; i < nr_entries; i++) {
69432 entry = entries + i;
69433@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
69434 {
69435 struct proc_dir_entry *pe;
69436
69437+#ifdef CONFIG_GRKERNSEC_PROC_ADD
69438+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
69439+#else
69440 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
69441+#endif
69442 if (!pe)
69443 return -ENOMEM;
69444 return 0;
69445diff --git a/kernel/timer.c b/kernel/timer.c
69446index a297ffc..5e16b0b 100644
69447--- a/kernel/timer.c
69448+++ b/kernel/timer.c
69449@@ -1354,7 +1354,7 @@ void update_process_times(int user_tick)
69450 /*
69451 * This function runs timers and the timer-tq in bottom half context.
69452 */
69453-static void run_timer_softirq(struct softirq_action *h)
69454+static void run_timer_softirq(void)
69455 {
69456 struct tvec_base *base = __this_cpu_read(tvec_bases);
69457
69458diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
69459index cdea7b5..9b820d4 100644
69460--- a/kernel/trace/blktrace.c
69461+++ b/kernel/trace/blktrace.c
69462@@ -324,7 +324,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
69463 struct blk_trace *bt = filp->private_data;
69464 char buf[16];
69465
69466- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
69467+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
69468
69469 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
69470 }
69471@@ -389,7 +389,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
69472 return 1;
69473
69474 bt = buf->chan->private_data;
69475- atomic_inc(&bt->dropped);
69476+ atomic_inc_unchecked(&bt->dropped);
69477 return 0;
69478 }
69479
69480@@ -490,7 +490,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
69481
69482 bt->dir = dir;
69483 bt->dev = dev;
69484- atomic_set(&bt->dropped, 0);
69485+ atomic_set_unchecked(&bt->dropped, 0);
69486
69487 ret = -EIO;
69488 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
69489diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
69490index 683d559..d70d914 100644
69491--- a/kernel/trace/ftrace.c
69492+++ b/kernel/trace/ftrace.c
69493@@ -1726,12 +1726,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
69494 if (unlikely(ftrace_disabled))
69495 return 0;
69496
69497+ ret = ftrace_arch_code_modify_prepare();
69498+ FTRACE_WARN_ON(ret);
69499+ if (ret)
69500+ return 0;
69501+
69502 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
69503+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
69504 if (ret) {
69505 ftrace_bug(ret, ip);
69506- return 0;
69507 }
69508- return 1;
69509+ return ret ? 0 : 1;
69510 }
69511
69512 /*
69513@@ -2843,7 +2848,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
69514
69515 int
69516 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
69517- void *data)
69518+ void *data)
69519 {
69520 struct ftrace_func_probe *entry;
69521 struct ftrace_page *pg;
69522diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
69523index c4579f1..6a439da 100644
69524--- a/kernel/trace/trace.c
69525+++ b/kernel/trace/trace.c
69526@@ -4258,10 +4258,9 @@ static const struct file_operations tracing_dyn_info_fops = {
69527 };
69528 #endif
69529
69530-static struct dentry *d_tracer;
69531-
69532 struct dentry *tracing_init_dentry(void)
69533 {
69534+ static struct dentry *d_tracer;
69535 static int once;
69536
69537 if (d_tracer)
69538@@ -4281,10 +4280,9 @@ struct dentry *tracing_init_dentry(void)
69539 return d_tracer;
69540 }
69541
69542-static struct dentry *d_percpu;
69543-
69544 struct dentry *tracing_dentry_percpu(void)
69545 {
69546+ static struct dentry *d_percpu;
69547 static int once;
69548 struct dentry *d_tracer;
69549
69550diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
69551index c212a7f..7b02394 100644
69552--- a/kernel/trace/trace_events.c
69553+++ b/kernel/trace/trace_events.c
69554@@ -1299,10 +1299,6 @@ static LIST_HEAD(ftrace_module_file_list);
69555 struct ftrace_module_file_ops {
69556 struct list_head list;
69557 struct module *mod;
69558- struct file_operations id;
69559- struct file_operations enable;
69560- struct file_operations format;
69561- struct file_operations filter;
69562 };
69563
69564 static struct ftrace_module_file_ops *
69565@@ -1323,17 +1319,12 @@ trace_create_file_ops(struct module *mod)
69566
69567 file_ops->mod = mod;
69568
69569- file_ops->id = ftrace_event_id_fops;
69570- file_ops->id.owner = mod;
69571-
69572- file_ops->enable = ftrace_enable_fops;
69573- file_ops->enable.owner = mod;
69574-
69575- file_ops->filter = ftrace_event_filter_fops;
69576- file_ops->filter.owner = mod;
69577-
69578- file_ops->format = ftrace_event_format_fops;
69579- file_ops->format.owner = mod;
69580+ pax_open_kernel();
69581+ *(void **)&mod->trace_id.owner = mod;
69582+ *(void **)&mod->trace_enable.owner = mod;
69583+ *(void **)&mod->trace_filter.owner = mod;
69584+ *(void **)&mod->trace_format.owner = mod;
69585+ pax_close_kernel();
69586
69587 list_add(&file_ops->list, &ftrace_module_file_list);
69588
69589@@ -1357,8 +1348,8 @@ static void trace_module_add_events(struct module *mod)
69590
69591 for_each_event(call, start, end) {
69592 __trace_add_event_call(*call, mod,
69593- &file_ops->id, &file_ops->enable,
69594- &file_ops->filter, &file_ops->format);
69595+ &mod->trace_id, &mod->trace_enable,
69596+ &mod->trace_filter, &mod->trace_format);
69597 }
69598 }
69599
69600diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
69601index 00d527c..7c5b1a3 100644
69602--- a/kernel/trace/trace_kprobe.c
69603+++ b/kernel/trace/trace_kprobe.c
69604@@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69605 long ret;
69606 int maxlen = get_rloc_len(*(u32 *)dest);
69607 u8 *dst = get_rloc_data(dest);
69608- u8 *src = addr;
69609+ const u8 __user *src = (const u8 __force_user *)addr;
69610 mm_segment_t old_fs = get_fs();
69611 if (!maxlen)
69612 return;
69613@@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69614 pagefault_disable();
69615 do
69616 ret = __copy_from_user_inatomic(dst++, src++, 1);
69617- while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
69618+ while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
69619 dst[-1] = '\0';
69620 pagefault_enable();
69621 set_fs(old_fs);
69622@@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69623 ((u8 *)get_rloc_data(dest))[0] = '\0';
69624 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
69625 } else
69626- *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
69627+ *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
69628 get_rloc_offs(*(u32 *)dest));
69629 }
69630 /* Return the length of string -- including null terminal byte */
69631@@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
69632 set_fs(KERNEL_DS);
69633 pagefault_disable();
69634 do {
69635- ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
69636+ ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
69637 len++;
69638 } while (c && ret == 0 && len < MAX_STRING_SIZE);
69639 pagefault_enable();
69640diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
69641index fd3c8aa..5f324a6 100644
69642--- a/kernel/trace/trace_mmiotrace.c
69643+++ b/kernel/trace/trace_mmiotrace.c
69644@@ -24,7 +24,7 @@ struct header_iter {
69645 static struct trace_array *mmio_trace_array;
69646 static bool overrun_detected;
69647 static unsigned long prev_overruns;
69648-static atomic_t dropped_count;
69649+static atomic_unchecked_t dropped_count;
69650
69651 static void mmio_reset_data(struct trace_array *tr)
69652 {
69653@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
69654
69655 static unsigned long count_overruns(struct trace_iterator *iter)
69656 {
69657- unsigned long cnt = atomic_xchg(&dropped_count, 0);
69658+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
69659 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
69660
69661 if (over > prev_overruns)
69662@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
69663 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
69664 sizeof(*entry), 0, pc);
69665 if (!event) {
69666- atomic_inc(&dropped_count);
69667+ atomic_inc_unchecked(&dropped_count);
69668 return;
69669 }
69670 entry = ring_buffer_event_data(event);
69671@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
69672 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
69673 sizeof(*entry), 0, pc);
69674 if (!event) {
69675- atomic_inc(&dropped_count);
69676+ atomic_inc_unchecked(&dropped_count);
69677 return;
69678 }
69679 entry = ring_buffer_event_data(event);
69680diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
69681index d9c07f0..c1eeceb 100644
69682--- a/kernel/trace/trace_output.c
69683+++ b/kernel/trace/trace_output.c
69684@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
69685
69686 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
69687 if (!IS_ERR(p)) {
69688- p = mangle_path(s->buffer + s->len, p, "\n");
69689+ p = mangle_path(s->buffer + s->len, p, "\n\\");
69690 if (p) {
69691 s->len = p - s->buffer;
69692 return 1;
69693diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
69694index d4545f4..a9010a1 100644
69695--- a/kernel/trace/trace_stack.c
69696+++ b/kernel/trace/trace_stack.c
69697@@ -53,7 +53,7 @@ static inline void check_stack(void)
69698 return;
69699
69700 /* we do not handle interrupt stacks yet */
69701- if (!object_is_on_stack(&this_size))
69702+ if (!object_starts_on_stack(&this_size))
69703 return;
69704
69705 local_irq_save(flags);
69706diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
69707index 209b379..7f76423 100644
69708--- a/kernel/trace/trace_workqueue.c
69709+++ b/kernel/trace/trace_workqueue.c
69710@@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
69711 int cpu;
69712 pid_t pid;
69713 /* Can be inserted from interrupt or user context, need to be atomic */
69714- atomic_t inserted;
69715+ atomic_unchecked_t inserted;
69716 /*
69717 * Don't need to be atomic, works are serialized in a single workqueue thread
69718 * on a single CPU.
69719@@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
69720 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
69721 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
69722 if (node->pid == wq_thread->pid) {
69723- atomic_inc(&node->inserted);
69724+ atomic_inc_unchecked(&node->inserted);
69725 goto found;
69726 }
69727 }
69728@@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
69729 tsk = get_pid_task(pid, PIDTYPE_PID);
69730 if (tsk) {
69731 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
69732- atomic_read(&cws->inserted), cws->executed,
69733+ atomic_read_unchecked(&cws->inserted), cws->executed,
69734 tsk->comm);
69735 put_task_struct(tsk);
69736 }
69737diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
69738index 8745ac7..d144e37 100644
69739--- a/lib/Kconfig.debug
69740+++ b/lib/Kconfig.debug
69741@@ -1103,6 +1103,7 @@ config LATENCYTOP
69742 depends on DEBUG_KERNEL
69743 depends on STACKTRACE_SUPPORT
69744 depends on PROC_FS
69745+ depends on !GRKERNSEC_HIDESYM
69746 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
69747 select KALLSYMS
69748 select KALLSYMS_ALL
69749diff --git a/lib/bitmap.c b/lib/bitmap.c
69750index 0d4a127..33a06c7 100644
69751--- a/lib/bitmap.c
69752+++ b/lib/bitmap.c
69753@@ -419,7 +419,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
69754 {
69755 int c, old_c, totaldigits, ndigits, nchunks, nbits;
69756 u32 chunk;
69757- const char __user __force *ubuf = (const char __user __force *)buf;
69758+ const char __user *ubuf = (const char __force_user *)buf;
69759
69760 bitmap_zero(maskp, nmaskbits);
69761
69762@@ -504,7 +504,7 @@ int bitmap_parse_user(const char __user *ubuf,
69763 {
69764 if (!access_ok(VERIFY_READ, ubuf, ulen))
69765 return -EFAULT;
69766- return __bitmap_parse((const char __force *)ubuf,
69767+ return __bitmap_parse((const char __force_kernel *)ubuf,
69768 ulen, 1, maskp, nmaskbits);
69769
69770 }
69771@@ -596,7 +596,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
69772 {
69773 unsigned a, b;
69774 int c, old_c, totaldigits;
69775- const char __user __force *ubuf = (const char __user __force *)buf;
69776+ const char __user *ubuf = (const char __force_user *)buf;
69777 int exp_digit, in_range;
69778
69779 totaldigits = c = 0;
69780@@ -696,7 +696,7 @@ int bitmap_parselist_user(const char __user *ubuf,
69781 {
69782 if (!access_ok(VERIFY_READ, ubuf, ulen))
69783 return -EFAULT;
69784- return __bitmap_parselist((const char __force *)ubuf,
69785+ return __bitmap_parselist((const char __force_kernel *)ubuf,
69786 ulen, 1, maskp, nmaskbits);
69787 }
69788 EXPORT_SYMBOL(bitmap_parselist_user);
69789diff --git a/lib/bug.c b/lib/bug.c
69790index a28c141..2bd3d95 100644
69791--- a/lib/bug.c
69792+++ b/lib/bug.c
69793@@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
69794 return BUG_TRAP_TYPE_NONE;
69795
69796 bug = find_bug(bugaddr);
69797+ if (!bug)
69798+ return BUG_TRAP_TYPE_NONE;
69799
69800 file = NULL;
69801 line = 0;
69802diff --git a/lib/debugobjects.c b/lib/debugobjects.c
69803index 0ab9ae8..f01ceca 100644
69804--- a/lib/debugobjects.c
69805+++ b/lib/debugobjects.c
69806@@ -288,7 +288,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
69807 if (limit > 4)
69808 return;
69809
69810- is_on_stack = object_is_on_stack(addr);
69811+ is_on_stack = object_starts_on_stack(addr);
69812 if (is_on_stack == onstack)
69813 return;
69814
69815diff --git a/lib/devres.c b/lib/devres.c
69816index 9676617..5149e15 100644
69817--- a/lib/devres.c
69818+++ b/lib/devres.c
69819@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
69820 void devm_iounmap(struct device *dev, void __iomem *addr)
69821 {
69822 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
69823- (void *)addr));
69824+ (void __force *)addr));
69825 iounmap(addr);
69826 }
69827 EXPORT_SYMBOL(devm_iounmap);
69828@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
69829 {
69830 ioport_unmap(addr);
69831 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
69832- devm_ioport_map_match, (void *)addr));
69833+ devm_ioport_map_match, (void __force *)addr));
69834 }
69835 EXPORT_SYMBOL(devm_ioport_unmap);
69836
69837diff --git a/lib/dma-debug.c b/lib/dma-debug.c
69838index fea790a..ebb0e82 100644
69839--- a/lib/dma-debug.c
69840+++ b/lib/dma-debug.c
69841@@ -925,7 +925,7 @@ out:
69842
69843 static void check_for_stack(struct device *dev, void *addr)
69844 {
69845- if (object_is_on_stack(addr))
69846+ if (object_starts_on_stack(addr))
69847 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
69848 "stack [addr=%p]\n", addr);
69849 }
69850diff --git a/lib/extable.c b/lib/extable.c
69851index 4cac81e..63e9b8f 100644
69852--- a/lib/extable.c
69853+++ b/lib/extable.c
69854@@ -13,6 +13,7 @@
69855 #include <linux/init.h>
69856 #include <linux/sort.h>
69857 #include <asm/uaccess.h>
69858+#include <asm/pgtable.h>
69859
69860 #ifndef ARCH_HAS_SORT_EXTABLE
69861 /*
69862@@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
69863 void sort_extable(struct exception_table_entry *start,
69864 struct exception_table_entry *finish)
69865 {
69866+ pax_open_kernel();
69867 sort(start, finish - start, sizeof(struct exception_table_entry),
69868 cmp_ex, NULL);
69869+ pax_close_kernel();
69870 }
69871
69872 #ifdef CONFIG_MODULES
69873diff --git a/lib/inflate.c b/lib/inflate.c
69874index 013a761..c28f3fc 100644
69875--- a/lib/inflate.c
69876+++ b/lib/inflate.c
69877@@ -269,7 +269,7 @@ static void free(void *where)
69878 malloc_ptr = free_mem_ptr;
69879 }
69880 #else
69881-#define malloc(a) kmalloc(a, GFP_KERNEL)
69882+#define malloc(a) kmalloc((a), GFP_KERNEL)
69883 #define free(a) kfree(a)
69884 #endif
69885
69886diff --git a/lib/ioremap.c b/lib/ioremap.c
69887index da4e2ad..6373b5f 100644
69888--- a/lib/ioremap.c
69889+++ b/lib/ioremap.c
69890@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
69891 unsigned long next;
69892
69893 phys_addr -= addr;
69894- pmd = pmd_alloc(&init_mm, pud, addr);
69895+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
69896 if (!pmd)
69897 return -ENOMEM;
69898 do {
69899@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
69900 unsigned long next;
69901
69902 phys_addr -= addr;
69903- pud = pud_alloc(&init_mm, pgd, addr);
69904+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
69905 if (!pud)
69906 return -ENOMEM;
69907 do {
69908diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
69909index bd2bea9..6b3c95e 100644
69910--- a/lib/is_single_threaded.c
69911+++ b/lib/is_single_threaded.c
69912@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
69913 struct task_struct *p, *t;
69914 bool ret;
69915
69916+ if (!mm)
69917+ return true;
69918+
69919 if (atomic_read(&task->signal->live) != 1)
69920 return false;
69921
69922diff --git a/lib/radix-tree.c b/lib/radix-tree.c
69923index dc63d08..95ae14a 100644
69924--- a/lib/radix-tree.c
69925+++ b/lib/radix-tree.c
69926@@ -78,7 +78,7 @@ struct radix_tree_preload {
69927 int nr;
69928 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
69929 };
69930-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
69931+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
69932
69933 static inline void *ptr_to_indirect(void *ptr)
69934 {
69935diff --git a/lib/vsprintf.c b/lib/vsprintf.c
69936index 38e612e..4fb99a8 100644
69937--- a/lib/vsprintf.c
69938+++ b/lib/vsprintf.c
69939@@ -16,6 +16,9 @@
69940 * - scnprintf and vscnprintf
69941 */
69942
69943+#ifdef CONFIG_GRKERNSEC_HIDESYM
69944+#define __INCLUDED_BY_HIDESYM 1
69945+#endif
69946 #include <stdarg.h>
69947 #include <linux/module.h>
69948 #include <linux/types.h>
69949@@ -413,7 +416,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
69950 char sym[KSYM_SYMBOL_LEN];
69951 if (ext == 'B')
69952 sprint_backtrace(sym, value);
69953- else if (ext != 'f' && ext != 's')
69954+ else if (ext != 'f' && ext != 's' && ext != 'a')
69955 sprint_symbol(sym, value);
69956 else
69957 kallsyms_lookup(value, NULL, NULL, NULL, sym);
69958@@ -789,7 +792,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
69959 return number(buf, end, *(const netdev_features_t *)addr, spec);
69960 }
69961
69962+#ifdef CONFIG_GRKERNSEC_HIDESYM
69963+int kptr_restrict __read_mostly = 2;
69964+#else
69965 int kptr_restrict __read_mostly;
69966+#endif
69967
69968 /*
69969 * Show a '%p' thing. A kernel extension is that the '%p' is followed
69970@@ -803,6 +810,8 @@ int kptr_restrict __read_mostly;
69971 * - 'S' For symbolic direct pointers with offset
69972 * - 's' For symbolic direct pointers without offset
69973 * - 'B' For backtraced symbolic direct pointers with offset
69974+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
69975+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
69976 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
69977 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
69978 * - 'M' For a 6-byte MAC address, it prints the address in the
69979@@ -848,12 +857,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
69980 {
69981 if (!ptr && *fmt != 'K') {
69982 /*
69983- * Print (null) with the same width as a pointer so it makes
69984+ * Print (nil) with the same width as a pointer so it makes
69985 * tabular output look nice.
69986 */
69987 if (spec.field_width == -1)
69988 spec.field_width = 2 * sizeof(void *);
69989- return string(buf, end, "(null)", spec);
69990+ return string(buf, end, "(nil)", spec);
69991 }
69992
69993 switch (*fmt) {
69994@@ -863,6 +872,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
69995 /* Fallthrough */
69996 case 'S':
69997 case 's':
69998+#ifdef CONFIG_GRKERNSEC_HIDESYM
69999+ break;
70000+#else
70001+ return symbol_string(buf, end, ptr, spec, *fmt);
70002+#endif
70003+ case 'A':
70004+ case 'a':
70005 case 'B':
70006 return symbol_string(buf, end, ptr, spec, *fmt);
70007 case 'R':
70008@@ -1633,11 +1649,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70009 typeof(type) value; \
70010 if (sizeof(type) == 8) { \
70011 args = PTR_ALIGN(args, sizeof(u32)); \
70012- *(u32 *)&value = *(u32 *)args; \
70013- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70014+ *(u32 *)&value = *(const u32 *)args; \
70015+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70016 } else { \
70017 args = PTR_ALIGN(args, sizeof(type)); \
70018- value = *(typeof(type) *)args; \
70019+ value = *(const typeof(type) *)args; \
70020 } \
70021 args += sizeof(type); \
70022 value; \
70023@@ -1700,7 +1716,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70024 case FORMAT_TYPE_STR: {
70025 const char *str_arg = args;
70026 args += strlen(str_arg) + 1;
70027- str = string(str, end, (char *)str_arg, spec);
70028+ str = string(str, end, str_arg, spec);
70029 break;
70030 }
70031
70032diff --git a/localversion-grsec b/localversion-grsec
70033new file mode 100644
70034index 0000000..7cd6065
70035--- /dev/null
70036+++ b/localversion-grsec
70037@@ -0,0 +1 @@
70038+-grsec
70039diff --git a/mm/Kconfig b/mm/Kconfig
70040index e338407..4210331 100644
70041--- a/mm/Kconfig
70042+++ b/mm/Kconfig
70043@@ -247,10 +247,10 @@ config KSM
70044 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70045
70046 config DEFAULT_MMAP_MIN_ADDR
70047- int "Low address space to protect from user allocation"
70048+ int "Low address space to protect from user allocation"
70049 depends on MMU
70050- default 4096
70051- help
70052+ default 65536
70053+ help
70054 This is the portion of low virtual memory which should be protected
70055 from userspace allocation. Keeping a user from writing to low pages
70056 can help reduce the impact of kernel NULL pointer bugs.
70057@@ -280,7 +280,7 @@ config MEMORY_FAILURE
70058
70059 config HWPOISON_INJECT
70060 tristate "HWPoison pages injector"
70061- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
70062+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
70063 select PROC_PAGE_MONITOR
70064
70065 config NOMMU_INITIAL_TRIM_EXCESS
70066diff --git a/mm/filemap.c b/mm/filemap.c
70067index b662757..3081ddd 100644
70068--- a/mm/filemap.c
70069+++ b/mm/filemap.c
70070@@ -1770,7 +1770,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70071 struct address_space *mapping = file->f_mapping;
70072
70073 if (!mapping->a_ops->readpage)
70074- return -ENOEXEC;
70075+ return -ENODEV;
70076 file_accessed(file);
70077 vma->vm_ops = &generic_file_vm_ops;
70078 vma->vm_flags |= VM_CAN_NONLINEAR;
70079@@ -2176,6 +2176,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70080 *pos = i_size_read(inode);
70081
70082 if (limit != RLIM_INFINITY) {
70083+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70084 if (*pos >= limit) {
70085 send_sig(SIGXFSZ, current, 0);
70086 return -EFBIG;
70087diff --git a/mm/fremap.c b/mm/fremap.c
70088index 9ed4fd4..c42648d 100644
70089--- a/mm/fremap.c
70090+++ b/mm/fremap.c
70091@@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70092 retry:
70093 vma = find_vma(mm, start);
70094
70095+#ifdef CONFIG_PAX_SEGMEXEC
70096+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70097+ goto out;
70098+#endif
70099+
70100 /*
70101 * Make sure the vma is shared, that it supports prefaulting,
70102 * and that the remapped range is valid and fully within
70103diff --git a/mm/highmem.c b/mm/highmem.c
70104index 57d82c6..e9e0552 100644
70105--- a/mm/highmem.c
70106+++ b/mm/highmem.c
70107@@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70108 * So no dangers, even with speculative execution.
70109 */
70110 page = pte_page(pkmap_page_table[i]);
70111+ pax_open_kernel();
70112 pte_clear(&init_mm, (unsigned long)page_address(page),
70113 &pkmap_page_table[i]);
70114-
70115+ pax_close_kernel();
70116 set_page_address(page, NULL);
70117 need_flush = 1;
70118 }
70119@@ -186,9 +187,11 @@ start:
70120 }
70121 }
70122 vaddr = PKMAP_ADDR(last_pkmap_nr);
70123+
70124+ pax_open_kernel();
70125 set_pte_at(&init_mm, vaddr,
70126 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
70127-
70128+ pax_close_kernel();
70129 pkmap_count[last_pkmap_nr] = 1;
70130 set_page_address(page, (void *)vaddr);
70131
70132diff --git a/mm/huge_memory.c b/mm/huge_memory.c
70133index 8f7fc39..69bf1e9 100644
70134--- a/mm/huge_memory.c
70135+++ b/mm/huge_memory.c
70136@@ -733,7 +733,7 @@ out:
70137 * run pte_offset_map on the pmd, if an huge pmd could
70138 * materialize from under us from a different thread.
70139 */
70140- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
70141+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70142 return VM_FAULT_OOM;
70143 /* if an huge pmd materialized from under us just retry later */
70144 if (unlikely(pmd_trans_huge(*pmd)))
70145diff --git a/mm/hugetlb.c b/mm/hugetlb.c
70146index fece520..e10da7f 100644
70147--- a/mm/hugetlb.c
70148+++ b/mm/hugetlb.c
70149@@ -2146,6 +2146,15 @@ static void hugetlb_vm_op_open(struct vm_area_struct *vma)
70150 kref_get(&reservations->refs);
70151 }
70152
70153+static void resv_map_put(struct vm_area_struct *vma)
70154+{
70155+ struct resv_map *reservations = vma_resv_map(vma);
70156+
70157+ if (!reservations)
70158+ return;
70159+ kref_put(&reservations->refs, resv_map_release);
70160+}
70161+
70162 static void hugetlb_vm_op_close(struct vm_area_struct *vma)
70163 {
70164 struct hstate *h = hstate_vma(vma);
70165@@ -2162,7 +2171,7 @@ static void hugetlb_vm_op_close(struct vm_area_struct *vma)
70166 reserve = (end - start) -
70167 region_count(&reservations->regions, start, end);
70168
70169- kref_put(&reservations->refs, resv_map_release);
70170+ resv_map_put(vma);
70171
70172 if (reserve) {
70173 hugetlb_acct_memory(h, -reserve);
70174@@ -2425,6 +2434,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
70175 return 1;
70176 }
70177
70178+#ifdef CONFIG_PAX_SEGMEXEC
70179+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
70180+{
70181+ struct mm_struct *mm = vma->vm_mm;
70182+ struct vm_area_struct *vma_m;
70183+ unsigned long address_m;
70184+ pte_t *ptep_m;
70185+
70186+ vma_m = pax_find_mirror_vma(vma);
70187+ if (!vma_m)
70188+ return;
70189+
70190+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70191+ address_m = address + SEGMEXEC_TASK_SIZE;
70192+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
70193+ get_page(page_m);
70194+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
70195+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
70196+}
70197+#endif
70198+
70199 /*
70200 * Hugetlb_cow() should be called with page lock of the original hugepage held.
70201 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
70202@@ -2537,6 +2567,11 @@ retry_avoidcopy:
70203 make_huge_pte(vma, new_page, 1));
70204 page_remove_rmap(old_page);
70205 hugepage_add_new_anon_rmap(new_page, vma, address);
70206+
70207+#ifdef CONFIG_PAX_SEGMEXEC
70208+ pax_mirror_huge_pte(vma, address, new_page);
70209+#endif
70210+
70211 /* Make the old page be freed below */
70212 new_page = old_page;
70213 mmu_notifier_invalidate_range_end(mm,
70214@@ -2691,6 +2726,10 @@ retry:
70215 && (vma->vm_flags & VM_SHARED)));
70216 set_huge_pte_at(mm, address, ptep, new_pte);
70217
70218+#ifdef CONFIG_PAX_SEGMEXEC
70219+ pax_mirror_huge_pte(vma, address, page);
70220+#endif
70221+
70222 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
70223 /* Optimization, do the COW without a second fault */
70224 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
70225@@ -2720,6 +2759,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70226 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
70227 struct hstate *h = hstate_vma(vma);
70228
70229+#ifdef CONFIG_PAX_SEGMEXEC
70230+ struct vm_area_struct *vma_m;
70231+#endif
70232+
70233 address &= huge_page_mask(h);
70234
70235 ptep = huge_pte_offset(mm, address);
70236@@ -2733,6 +2776,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70237 VM_FAULT_SET_HINDEX(h - hstates);
70238 }
70239
70240+#ifdef CONFIG_PAX_SEGMEXEC
70241+ vma_m = pax_find_mirror_vma(vma);
70242+ if (vma_m) {
70243+ unsigned long address_m;
70244+
70245+ if (vma->vm_start > vma_m->vm_start) {
70246+ address_m = address;
70247+ address -= SEGMEXEC_TASK_SIZE;
70248+ vma = vma_m;
70249+ h = hstate_vma(vma);
70250+ } else
70251+ address_m = address + SEGMEXEC_TASK_SIZE;
70252+
70253+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
70254+ return VM_FAULT_OOM;
70255+ address_m &= HPAGE_MASK;
70256+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
70257+ }
70258+#endif
70259+
70260 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
70261 if (!ptep)
70262 return VM_FAULT_OOM;
70263@@ -2978,12 +3041,16 @@ int hugetlb_reserve_pages(struct inode *inode,
70264 set_vma_resv_flags(vma, HPAGE_RESV_OWNER);
70265 }
70266
70267- if (chg < 0)
70268- return chg;
70269+ if (chg < 0) {
70270+ ret = chg;
70271+ goto out_err;
70272+ }
70273
70274 /* There must be enough pages in the subpool for the mapping */
70275- if (hugepage_subpool_get_pages(spool, chg))
70276- return -ENOSPC;
70277+ if (hugepage_subpool_get_pages(spool, chg)) {
70278+ ret = -ENOSPC;
70279+ goto out_err;
70280+ }
70281
70282 /*
70283 * Check enough hugepages are available for the reservation.
70284@@ -2992,7 +3059,7 @@ int hugetlb_reserve_pages(struct inode *inode,
70285 ret = hugetlb_acct_memory(h, chg);
70286 if (ret < 0) {
70287 hugepage_subpool_put_pages(spool, chg);
70288- return ret;
70289+ goto out_err;
70290 }
70291
70292 /*
70293@@ -3009,6 +3076,10 @@ int hugetlb_reserve_pages(struct inode *inode,
70294 if (!vma || vma->vm_flags & VM_MAYSHARE)
70295 region_add(&inode->i_mapping->private_list, from, to);
70296 return 0;
70297+out_err:
70298+ if (vma)
70299+ resv_map_put(vma);
70300+ return ret;
70301 }
70302
70303 void hugetlb_unreserve_pages(struct inode *inode, long offset, long freed)
70304diff --git a/mm/internal.h b/mm/internal.h
70305index 2189af4..f2ca332 100644
70306--- a/mm/internal.h
70307+++ b/mm/internal.h
70308@@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
70309 * in mm/page_alloc.c
70310 */
70311 extern void __free_pages_bootmem(struct page *page, unsigned int order);
70312+extern void free_compound_page(struct page *page);
70313 extern void prep_compound_page(struct page *page, unsigned long order);
70314 #ifdef CONFIG_MEMORY_FAILURE
70315 extern bool is_free_buddy_page(struct page *page);
70316diff --git a/mm/kmemleak.c b/mm/kmemleak.c
70317index 45eb621..6ccd8ea 100644
70318--- a/mm/kmemleak.c
70319+++ b/mm/kmemleak.c
70320@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
70321
70322 for (i = 0; i < object->trace_len; i++) {
70323 void *ptr = (void *)object->trace[i];
70324- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
70325+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
70326 }
70327 }
70328
70329diff --git a/mm/maccess.c b/mm/maccess.c
70330index d53adf9..03a24bf 100644
70331--- a/mm/maccess.c
70332+++ b/mm/maccess.c
70333@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
70334 set_fs(KERNEL_DS);
70335 pagefault_disable();
70336 ret = __copy_from_user_inatomic(dst,
70337- (__force const void __user *)src, size);
70338+ (const void __force_user *)src, size);
70339 pagefault_enable();
70340 set_fs(old_fs);
70341
70342@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
70343
70344 set_fs(KERNEL_DS);
70345 pagefault_disable();
70346- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
70347+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
70348 pagefault_enable();
70349 set_fs(old_fs);
70350
70351diff --git a/mm/madvise.c b/mm/madvise.c
70352index 74bf193..feb6fd3 100644
70353--- a/mm/madvise.c
70354+++ b/mm/madvise.c
70355@@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
70356 pgoff_t pgoff;
70357 unsigned long new_flags = vma->vm_flags;
70358
70359+#ifdef CONFIG_PAX_SEGMEXEC
70360+ struct vm_area_struct *vma_m;
70361+#endif
70362+
70363 switch (behavior) {
70364 case MADV_NORMAL:
70365 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
70366@@ -110,6 +114,13 @@ success:
70367 /*
70368 * vm_flags is protected by the mmap_sem held in write mode.
70369 */
70370+
70371+#ifdef CONFIG_PAX_SEGMEXEC
70372+ vma_m = pax_find_mirror_vma(vma);
70373+ if (vma_m)
70374+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
70375+#endif
70376+
70377 vma->vm_flags = new_flags;
70378
70379 out:
70380@@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70381 struct vm_area_struct ** prev,
70382 unsigned long start, unsigned long end)
70383 {
70384+
70385+#ifdef CONFIG_PAX_SEGMEXEC
70386+ struct vm_area_struct *vma_m;
70387+#endif
70388+
70389 *prev = vma;
70390 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
70391 return -EINVAL;
70392@@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70393 zap_page_range(vma, start, end - start, &details);
70394 } else
70395 zap_page_range(vma, start, end - start, NULL);
70396+
70397+#ifdef CONFIG_PAX_SEGMEXEC
70398+ vma_m = pax_find_mirror_vma(vma);
70399+ if (vma_m) {
70400+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
70401+ struct zap_details details = {
70402+ .nonlinear_vma = vma_m,
70403+ .last_index = ULONG_MAX,
70404+ };
70405+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
70406+ } else
70407+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
70408+ }
70409+#endif
70410+
70411 return 0;
70412 }
70413
70414@@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
70415 if (end < start)
70416 goto out;
70417
70418+#ifdef CONFIG_PAX_SEGMEXEC
70419+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70420+ if (end > SEGMEXEC_TASK_SIZE)
70421+ goto out;
70422+ } else
70423+#endif
70424+
70425+ if (end > TASK_SIZE)
70426+ goto out;
70427+
70428 error = 0;
70429 if (end == start)
70430 goto out;
70431diff --git a/mm/memory-failure.c b/mm/memory-failure.c
70432index 56080ea..115071e 100644
70433--- a/mm/memory-failure.c
70434+++ b/mm/memory-failure.c
70435@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
70436
70437 int sysctl_memory_failure_recovery __read_mostly = 1;
70438
70439-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70440+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70441
70442 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
70443
70444@@ -202,7 +202,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
70445 si.si_signo = SIGBUS;
70446 si.si_errno = 0;
70447 si.si_code = BUS_MCEERR_AO;
70448- si.si_addr = (void *)addr;
70449+ si.si_addr = (void __user *)addr;
70450 #ifdef __ARCH_SI_TRAPNO
70451 si.si_trapno = trapno;
70452 #endif
70453@@ -1010,7 +1010,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70454 }
70455
70456 nr_pages = 1 << compound_trans_order(hpage);
70457- atomic_long_add(nr_pages, &mce_bad_pages);
70458+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
70459
70460 /*
70461 * We need/can do nothing about count=0 pages.
70462@@ -1040,7 +1040,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70463 if (!PageHWPoison(hpage)
70464 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
70465 || (p != hpage && TestSetPageHWPoison(hpage))) {
70466- atomic_long_sub(nr_pages, &mce_bad_pages);
70467+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70468 return 0;
70469 }
70470 set_page_hwpoison_huge_page(hpage);
70471@@ -1098,7 +1098,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70472 }
70473 if (hwpoison_filter(p)) {
70474 if (TestClearPageHWPoison(p))
70475- atomic_long_sub(nr_pages, &mce_bad_pages);
70476+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70477 unlock_page(hpage);
70478 put_page(hpage);
70479 return 0;
70480@@ -1315,7 +1315,7 @@ int unpoison_memory(unsigned long pfn)
70481 return 0;
70482 }
70483 if (TestClearPageHWPoison(p))
70484- atomic_long_sub(nr_pages, &mce_bad_pages);
70485+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70486 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
70487 return 0;
70488 }
70489@@ -1329,7 +1329,7 @@ int unpoison_memory(unsigned long pfn)
70490 */
70491 if (TestClearPageHWPoison(page)) {
70492 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
70493- atomic_long_sub(nr_pages, &mce_bad_pages);
70494+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70495 freeit = 1;
70496 if (PageHuge(page))
70497 clear_page_hwpoison_huge_page(page);
70498@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
70499 }
70500 done:
70501 if (!PageHWPoison(hpage))
70502- atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
70503+ atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
70504 set_page_hwpoison_huge_page(hpage);
70505 dequeue_hwpoisoned_huge_page(hpage);
70506 /* keep elevated page count for bad page */
70507@@ -1573,7 +1573,7 @@ int soft_offline_page(struct page *page, int flags)
70508 return ret;
70509
70510 done:
70511- atomic_long_add(1, &mce_bad_pages);
70512+ atomic_long_add_unchecked(1, &mce_bad_pages);
70513 SetPageHWPoison(page);
70514 /* keep elevated page count for bad page */
70515 return ret;
70516diff --git a/mm/memory.c b/mm/memory.c
70517index 10b4dda..06857f3 100644
70518--- a/mm/memory.c
70519+++ b/mm/memory.c
70520@@ -457,8 +457,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
70521 return;
70522
70523 pmd = pmd_offset(pud, start);
70524+
70525+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
70526 pud_clear(pud);
70527 pmd_free_tlb(tlb, pmd, start);
70528+#endif
70529+
70530 }
70531
70532 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70533@@ -489,9 +493,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70534 if (end - 1 > ceiling - 1)
70535 return;
70536
70537+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
70538 pud = pud_offset(pgd, start);
70539 pgd_clear(pgd);
70540 pud_free_tlb(tlb, pud, start);
70541+#endif
70542+
70543 }
70544
70545 /*
70546@@ -1593,12 +1600,6 @@ no_page_table:
70547 return page;
70548 }
70549
70550-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
70551-{
70552- return stack_guard_page_start(vma, addr) ||
70553- stack_guard_page_end(vma, addr+PAGE_SIZE);
70554-}
70555-
70556 /**
70557 * __get_user_pages() - pin user pages in memory
70558 * @tsk: task_struct of target task
70559@@ -1671,10 +1672,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70560 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
70561 i = 0;
70562
70563- do {
70564+ while (nr_pages) {
70565 struct vm_area_struct *vma;
70566
70567- vma = find_extend_vma(mm, start);
70568+ vma = find_vma(mm, start);
70569 if (!vma && in_gate_area(mm, start)) {
70570 unsigned long pg = start & PAGE_MASK;
70571 pgd_t *pgd;
70572@@ -1722,7 +1723,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70573 goto next_page;
70574 }
70575
70576- if (!vma ||
70577+ if (!vma || start < vma->vm_start ||
70578 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
70579 !(vm_flags & vma->vm_flags))
70580 return i ? : -EFAULT;
70581@@ -1749,11 +1750,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70582 int ret;
70583 unsigned int fault_flags = 0;
70584
70585- /* For mlock, just skip the stack guard page. */
70586- if (foll_flags & FOLL_MLOCK) {
70587- if (stack_guard_page(vma, start))
70588- goto next_page;
70589- }
70590 if (foll_flags & FOLL_WRITE)
70591 fault_flags |= FAULT_FLAG_WRITE;
70592 if (nonblocking)
70593@@ -1827,7 +1823,7 @@ next_page:
70594 start += PAGE_SIZE;
70595 nr_pages--;
70596 } while (nr_pages && start < vma->vm_end);
70597- } while (nr_pages);
70598+ }
70599 return i;
70600 }
70601 EXPORT_SYMBOL(__get_user_pages);
70602@@ -2034,6 +2030,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
70603 page_add_file_rmap(page);
70604 set_pte_at(mm, addr, pte, mk_pte(page, prot));
70605
70606+#ifdef CONFIG_PAX_SEGMEXEC
70607+ pax_mirror_file_pte(vma, addr, page, ptl);
70608+#endif
70609+
70610 retval = 0;
70611 pte_unmap_unlock(pte, ptl);
70612 return retval;
70613@@ -2068,10 +2068,22 @@ out:
70614 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
70615 struct page *page)
70616 {
70617+
70618+#ifdef CONFIG_PAX_SEGMEXEC
70619+ struct vm_area_struct *vma_m;
70620+#endif
70621+
70622 if (addr < vma->vm_start || addr >= vma->vm_end)
70623 return -EFAULT;
70624 if (!page_count(page))
70625 return -EINVAL;
70626+
70627+#ifdef CONFIG_PAX_SEGMEXEC
70628+ vma_m = pax_find_mirror_vma(vma);
70629+ if (vma_m)
70630+ vma_m->vm_flags |= VM_INSERTPAGE;
70631+#endif
70632+
70633 vma->vm_flags |= VM_INSERTPAGE;
70634 return insert_page(vma, addr, page, vma->vm_page_prot);
70635 }
70636@@ -2157,6 +2169,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
70637 unsigned long pfn)
70638 {
70639 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
70640+ BUG_ON(vma->vm_mirror);
70641
70642 if (addr < vma->vm_start || addr >= vma->vm_end)
70643 return -EFAULT;
70644@@ -2364,7 +2377,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
70645
70646 BUG_ON(pud_huge(*pud));
70647
70648- pmd = pmd_alloc(mm, pud, addr);
70649+ pmd = (mm == &init_mm) ?
70650+ pmd_alloc_kernel(mm, pud, addr) :
70651+ pmd_alloc(mm, pud, addr);
70652 if (!pmd)
70653 return -ENOMEM;
70654 do {
70655@@ -2384,7 +2399,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
70656 unsigned long next;
70657 int err;
70658
70659- pud = pud_alloc(mm, pgd, addr);
70660+ pud = (mm == &init_mm) ?
70661+ pud_alloc_kernel(mm, pgd, addr) :
70662+ pud_alloc(mm, pgd, addr);
70663 if (!pud)
70664 return -ENOMEM;
70665 do {
70666@@ -2472,6 +2489,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
70667 copy_user_highpage(dst, src, va, vma);
70668 }
70669
70670+#ifdef CONFIG_PAX_SEGMEXEC
70671+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
70672+{
70673+ struct mm_struct *mm = vma->vm_mm;
70674+ spinlock_t *ptl;
70675+ pte_t *pte, entry;
70676+
70677+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
70678+ entry = *pte;
70679+ if (!pte_present(entry)) {
70680+ if (!pte_none(entry)) {
70681+ BUG_ON(pte_file(entry));
70682+ free_swap_and_cache(pte_to_swp_entry(entry));
70683+ pte_clear_not_present_full(mm, address, pte, 0);
70684+ }
70685+ } else {
70686+ struct page *page;
70687+
70688+ flush_cache_page(vma, address, pte_pfn(entry));
70689+ entry = ptep_clear_flush(vma, address, pte);
70690+ BUG_ON(pte_dirty(entry));
70691+ page = vm_normal_page(vma, address, entry);
70692+ if (page) {
70693+ update_hiwater_rss(mm);
70694+ if (PageAnon(page))
70695+ dec_mm_counter_fast(mm, MM_ANONPAGES);
70696+ else
70697+ dec_mm_counter_fast(mm, MM_FILEPAGES);
70698+ page_remove_rmap(page);
70699+ page_cache_release(page);
70700+ }
70701+ }
70702+ pte_unmap_unlock(pte, ptl);
70703+}
70704+
70705+/* PaX: if vma is mirrored, synchronize the mirror's PTE
70706+ *
70707+ * the ptl of the lower mapped page is held on entry and is not released on exit
70708+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
70709+ */
70710+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70711+{
70712+ struct mm_struct *mm = vma->vm_mm;
70713+ unsigned long address_m;
70714+ spinlock_t *ptl_m;
70715+ struct vm_area_struct *vma_m;
70716+ pmd_t *pmd_m;
70717+ pte_t *pte_m, entry_m;
70718+
70719+ BUG_ON(!page_m || !PageAnon(page_m));
70720+
70721+ vma_m = pax_find_mirror_vma(vma);
70722+ if (!vma_m)
70723+ return;
70724+
70725+ BUG_ON(!PageLocked(page_m));
70726+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70727+ address_m = address + SEGMEXEC_TASK_SIZE;
70728+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70729+ pte_m = pte_offset_map(pmd_m, address_m);
70730+ ptl_m = pte_lockptr(mm, pmd_m);
70731+ if (ptl != ptl_m) {
70732+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70733+ if (!pte_none(*pte_m))
70734+ goto out;
70735+ }
70736+
70737+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70738+ page_cache_get(page_m);
70739+ page_add_anon_rmap(page_m, vma_m, address_m);
70740+ inc_mm_counter_fast(mm, MM_ANONPAGES);
70741+ set_pte_at(mm, address_m, pte_m, entry_m);
70742+ update_mmu_cache(vma_m, address_m, entry_m);
70743+out:
70744+ if (ptl != ptl_m)
70745+ spin_unlock(ptl_m);
70746+ pte_unmap(pte_m);
70747+ unlock_page(page_m);
70748+}
70749+
70750+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70751+{
70752+ struct mm_struct *mm = vma->vm_mm;
70753+ unsigned long address_m;
70754+ spinlock_t *ptl_m;
70755+ struct vm_area_struct *vma_m;
70756+ pmd_t *pmd_m;
70757+ pte_t *pte_m, entry_m;
70758+
70759+ BUG_ON(!page_m || PageAnon(page_m));
70760+
70761+ vma_m = pax_find_mirror_vma(vma);
70762+ if (!vma_m)
70763+ return;
70764+
70765+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70766+ address_m = address + SEGMEXEC_TASK_SIZE;
70767+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70768+ pte_m = pte_offset_map(pmd_m, address_m);
70769+ ptl_m = pte_lockptr(mm, pmd_m);
70770+ if (ptl != ptl_m) {
70771+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70772+ if (!pte_none(*pte_m))
70773+ goto out;
70774+ }
70775+
70776+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70777+ page_cache_get(page_m);
70778+ page_add_file_rmap(page_m);
70779+ inc_mm_counter_fast(mm, MM_FILEPAGES);
70780+ set_pte_at(mm, address_m, pte_m, entry_m);
70781+ update_mmu_cache(vma_m, address_m, entry_m);
70782+out:
70783+ if (ptl != ptl_m)
70784+ spin_unlock(ptl_m);
70785+ pte_unmap(pte_m);
70786+}
70787+
70788+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
70789+{
70790+ struct mm_struct *mm = vma->vm_mm;
70791+ unsigned long address_m;
70792+ spinlock_t *ptl_m;
70793+ struct vm_area_struct *vma_m;
70794+ pmd_t *pmd_m;
70795+ pte_t *pte_m, entry_m;
70796+
70797+ vma_m = pax_find_mirror_vma(vma);
70798+ if (!vma_m)
70799+ return;
70800+
70801+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70802+ address_m = address + SEGMEXEC_TASK_SIZE;
70803+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70804+ pte_m = pte_offset_map(pmd_m, address_m);
70805+ ptl_m = pte_lockptr(mm, pmd_m);
70806+ if (ptl != ptl_m) {
70807+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70808+ if (!pte_none(*pte_m))
70809+ goto out;
70810+ }
70811+
70812+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
70813+ set_pte_at(mm, address_m, pte_m, entry_m);
70814+out:
70815+ if (ptl != ptl_m)
70816+ spin_unlock(ptl_m);
70817+ pte_unmap(pte_m);
70818+}
70819+
70820+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
70821+{
70822+ struct page *page_m;
70823+ pte_t entry;
70824+
70825+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
70826+ goto out;
70827+
70828+ entry = *pte;
70829+ page_m = vm_normal_page(vma, address, entry);
70830+ if (!page_m)
70831+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
70832+ else if (PageAnon(page_m)) {
70833+ if (pax_find_mirror_vma(vma)) {
70834+ pte_unmap_unlock(pte, ptl);
70835+ lock_page(page_m);
70836+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
70837+ if (pte_same(entry, *pte))
70838+ pax_mirror_anon_pte(vma, address, page_m, ptl);
70839+ else
70840+ unlock_page(page_m);
70841+ }
70842+ } else
70843+ pax_mirror_file_pte(vma, address, page_m, ptl);
70844+
70845+out:
70846+ pte_unmap_unlock(pte, ptl);
70847+}
70848+#endif
70849+
70850 /*
70851 * This routine handles present pages, when users try to write
70852 * to a shared page. It is done by copying the page to a new address
70853@@ -2683,6 +2880,12 @@ gotten:
70854 */
70855 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70856 if (likely(pte_same(*page_table, orig_pte))) {
70857+
70858+#ifdef CONFIG_PAX_SEGMEXEC
70859+ if (pax_find_mirror_vma(vma))
70860+ BUG_ON(!trylock_page(new_page));
70861+#endif
70862+
70863 if (old_page) {
70864 if (!PageAnon(old_page)) {
70865 dec_mm_counter_fast(mm, MM_FILEPAGES);
70866@@ -2734,6 +2937,10 @@ gotten:
70867 page_remove_rmap(old_page);
70868 }
70869
70870+#ifdef CONFIG_PAX_SEGMEXEC
70871+ pax_mirror_anon_pte(vma, address, new_page, ptl);
70872+#endif
70873+
70874 /* Free the old page.. */
70875 new_page = old_page;
70876 ret |= VM_FAULT_WRITE;
70877@@ -3013,6 +3220,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70878 swap_free(entry);
70879 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
70880 try_to_free_swap(page);
70881+
70882+#ifdef CONFIG_PAX_SEGMEXEC
70883+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
70884+#endif
70885+
70886 unlock_page(page);
70887 if (swapcache) {
70888 /*
70889@@ -3036,6 +3248,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70890
70891 /* No need to invalidate - it was non-present before */
70892 update_mmu_cache(vma, address, page_table);
70893+
70894+#ifdef CONFIG_PAX_SEGMEXEC
70895+ pax_mirror_anon_pte(vma, address, page, ptl);
70896+#endif
70897+
70898 unlock:
70899 pte_unmap_unlock(page_table, ptl);
70900 out:
70901@@ -3055,40 +3272,6 @@ out_release:
70902 }
70903
70904 /*
70905- * This is like a special single-page "expand_{down|up}wards()",
70906- * except we must first make sure that 'address{-|+}PAGE_SIZE'
70907- * doesn't hit another vma.
70908- */
70909-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
70910-{
70911- address &= PAGE_MASK;
70912- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
70913- struct vm_area_struct *prev = vma->vm_prev;
70914-
70915- /*
70916- * Is there a mapping abutting this one below?
70917- *
70918- * That's only ok if it's the same stack mapping
70919- * that has gotten split..
70920- */
70921- if (prev && prev->vm_end == address)
70922- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
70923-
70924- expand_downwards(vma, address - PAGE_SIZE);
70925- }
70926- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
70927- struct vm_area_struct *next = vma->vm_next;
70928-
70929- /* As VM_GROWSDOWN but s/below/above/ */
70930- if (next && next->vm_start == address + PAGE_SIZE)
70931- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
70932-
70933- expand_upwards(vma, address + PAGE_SIZE);
70934- }
70935- return 0;
70936-}
70937-
70938-/*
70939 * We enter with non-exclusive mmap_sem (to exclude vma changes,
70940 * but allow concurrent faults), and pte mapped but not yet locked.
70941 * We return with mmap_sem still held, but pte unmapped and unlocked.
70942@@ -3097,27 +3280,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
70943 unsigned long address, pte_t *page_table, pmd_t *pmd,
70944 unsigned int flags)
70945 {
70946- struct page *page;
70947+ struct page *page = NULL;
70948 spinlock_t *ptl;
70949 pte_t entry;
70950
70951- pte_unmap(page_table);
70952-
70953- /* Check if we need to add a guard page to the stack */
70954- if (check_stack_guard_page(vma, address) < 0)
70955- return VM_FAULT_SIGBUS;
70956-
70957- /* Use the zero-page for reads */
70958 if (!(flags & FAULT_FLAG_WRITE)) {
70959 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
70960 vma->vm_page_prot));
70961- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70962+ ptl = pte_lockptr(mm, pmd);
70963+ spin_lock(ptl);
70964 if (!pte_none(*page_table))
70965 goto unlock;
70966 goto setpte;
70967 }
70968
70969 /* Allocate our own private page. */
70970+ pte_unmap(page_table);
70971+
70972 if (unlikely(anon_vma_prepare(vma)))
70973 goto oom;
70974 page = alloc_zeroed_user_highpage_movable(vma, address);
70975@@ -3136,6 +3315,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
70976 if (!pte_none(*page_table))
70977 goto release;
70978
70979+#ifdef CONFIG_PAX_SEGMEXEC
70980+ if (pax_find_mirror_vma(vma))
70981+ BUG_ON(!trylock_page(page));
70982+#endif
70983+
70984 inc_mm_counter_fast(mm, MM_ANONPAGES);
70985 page_add_new_anon_rmap(page, vma, address);
70986 setpte:
70987@@ -3143,6 +3327,12 @@ setpte:
70988
70989 /* No need to invalidate - it was non-present before */
70990 update_mmu_cache(vma, address, page_table);
70991+
70992+#ifdef CONFIG_PAX_SEGMEXEC
70993+ if (page)
70994+ pax_mirror_anon_pte(vma, address, page, ptl);
70995+#endif
70996+
70997 unlock:
70998 pte_unmap_unlock(page_table, ptl);
70999 return 0;
71000@@ -3286,6 +3476,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71001 */
71002 /* Only go through if we didn't race with anybody else... */
71003 if (likely(pte_same(*page_table, orig_pte))) {
71004+
71005+#ifdef CONFIG_PAX_SEGMEXEC
71006+ if (anon && pax_find_mirror_vma(vma))
71007+ BUG_ON(!trylock_page(page));
71008+#endif
71009+
71010 flush_icache_page(vma, page);
71011 entry = mk_pte(page, vma->vm_page_prot);
71012 if (flags & FAULT_FLAG_WRITE)
71013@@ -3305,6 +3501,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71014
71015 /* no need to invalidate: a not-present page won't be cached */
71016 update_mmu_cache(vma, address, page_table);
71017+
71018+#ifdef CONFIG_PAX_SEGMEXEC
71019+ if (anon)
71020+ pax_mirror_anon_pte(vma, address, page, ptl);
71021+ else
71022+ pax_mirror_file_pte(vma, address, page, ptl);
71023+#endif
71024+
71025 } else {
71026 if (cow_page)
71027 mem_cgroup_uncharge_page(cow_page);
71028@@ -3458,6 +3662,12 @@ int handle_pte_fault(struct mm_struct *mm,
71029 if (flags & FAULT_FLAG_WRITE)
71030 flush_tlb_fix_spurious_fault(vma, address);
71031 }
71032+
71033+#ifdef CONFIG_PAX_SEGMEXEC
71034+ pax_mirror_pte(vma, address, pte, pmd, ptl);
71035+ return 0;
71036+#endif
71037+
71038 unlock:
71039 pte_unmap_unlock(pte, ptl);
71040 return 0;
71041@@ -3474,6 +3684,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71042 pmd_t *pmd;
71043 pte_t *pte;
71044
71045+#ifdef CONFIG_PAX_SEGMEXEC
71046+ struct vm_area_struct *vma_m;
71047+#endif
71048+
71049 __set_current_state(TASK_RUNNING);
71050
71051 count_vm_event(PGFAULT);
71052@@ -3485,6 +3699,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71053 if (unlikely(is_vm_hugetlb_page(vma)))
71054 return hugetlb_fault(mm, vma, address, flags);
71055
71056+#ifdef CONFIG_PAX_SEGMEXEC
71057+ vma_m = pax_find_mirror_vma(vma);
71058+ if (vma_m) {
71059+ unsigned long address_m;
71060+ pgd_t *pgd_m;
71061+ pud_t *pud_m;
71062+ pmd_t *pmd_m;
71063+
71064+ if (vma->vm_start > vma_m->vm_start) {
71065+ address_m = address;
71066+ address -= SEGMEXEC_TASK_SIZE;
71067+ vma = vma_m;
71068+ } else
71069+ address_m = address + SEGMEXEC_TASK_SIZE;
71070+
71071+ pgd_m = pgd_offset(mm, address_m);
71072+ pud_m = pud_alloc(mm, pgd_m, address_m);
71073+ if (!pud_m)
71074+ return VM_FAULT_OOM;
71075+ pmd_m = pmd_alloc(mm, pud_m, address_m);
71076+ if (!pmd_m)
71077+ return VM_FAULT_OOM;
71078+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71079+ return VM_FAULT_OOM;
71080+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71081+ }
71082+#endif
71083+
71084 pgd = pgd_offset(mm, address);
71085 pud = pud_alloc(mm, pgd, address);
71086 if (!pud)
71087@@ -3514,7 +3756,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71088 * run pte_offset_map on the pmd, if an huge pmd could
71089 * materialize from under us from a different thread.
71090 */
71091- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71092+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71093 return VM_FAULT_OOM;
71094 /* if an huge pmd materialized from under us just retry later */
71095 if (unlikely(pmd_trans_huge(*pmd)))
71096@@ -3551,6 +3793,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71097 spin_unlock(&mm->page_table_lock);
71098 return 0;
71099 }
71100+
71101+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71102+{
71103+ pud_t *new = pud_alloc_one(mm, address);
71104+ if (!new)
71105+ return -ENOMEM;
71106+
71107+ smp_wmb(); /* See comment in __pte_alloc */
71108+
71109+ spin_lock(&mm->page_table_lock);
71110+ if (pgd_present(*pgd)) /* Another has populated it */
71111+ pud_free(mm, new);
71112+ else
71113+ pgd_populate_kernel(mm, pgd, new);
71114+ spin_unlock(&mm->page_table_lock);
71115+ return 0;
71116+}
71117 #endif /* __PAGETABLE_PUD_FOLDED */
71118
71119 #ifndef __PAGETABLE_PMD_FOLDED
71120@@ -3581,6 +3840,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
71121 spin_unlock(&mm->page_table_lock);
71122 return 0;
71123 }
71124+
71125+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
71126+{
71127+ pmd_t *new = pmd_alloc_one(mm, address);
71128+ if (!new)
71129+ return -ENOMEM;
71130+
71131+ smp_wmb(); /* See comment in __pte_alloc */
71132+
71133+ spin_lock(&mm->page_table_lock);
71134+#ifndef __ARCH_HAS_4LEVEL_HACK
71135+ if (pud_present(*pud)) /* Another has populated it */
71136+ pmd_free(mm, new);
71137+ else
71138+ pud_populate_kernel(mm, pud, new);
71139+#else
71140+ if (pgd_present(*pud)) /* Another has populated it */
71141+ pmd_free(mm, new);
71142+ else
71143+ pgd_populate_kernel(mm, pud, new);
71144+#endif /* __ARCH_HAS_4LEVEL_HACK */
71145+ spin_unlock(&mm->page_table_lock);
71146+ return 0;
71147+}
71148 #endif /* __PAGETABLE_PMD_FOLDED */
71149
71150 int make_pages_present(unsigned long addr, unsigned long end)
71151@@ -3618,7 +3901,7 @@ static int __init gate_vma_init(void)
71152 gate_vma.vm_start = FIXADDR_USER_START;
71153 gate_vma.vm_end = FIXADDR_USER_END;
71154 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71155- gate_vma.vm_page_prot = __P101;
71156+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71157 /*
71158 * Make sure the vDSO gets into every core dump.
71159 * Dumping its contents makes post-mortem fully interpretable later
71160diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71161index 0a37570..2048346 100644
71162--- a/mm/mempolicy.c
71163+++ b/mm/mempolicy.c
71164@@ -640,6 +640,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71165 unsigned long vmstart;
71166 unsigned long vmend;
71167
71168+#ifdef CONFIG_PAX_SEGMEXEC
71169+ struct vm_area_struct *vma_m;
71170+#endif
71171+
71172 vma = find_vma(mm, start);
71173 if (!vma || vma->vm_start > start)
71174 return -EFAULT;
71175@@ -679,6 +683,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71176 err = policy_vma(vma, new_pol);
71177 if (err)
71178 goto out;
71179+
71180+#ifdef CONFIG_PAX_SEGMEXEC
71181+ vma_m = pax_find_mirror_vma(vma);
71182+ if (vma_m) {
71183+ err = policy_vma(vma_m, new_pol);
71184+ if (err)
71185+ goto out;
71186+ }
71187+#endif
71188+
71189 }
71190
71191 out:
71192@@ -1112,6 +1126,17 @@ static long do_mbind(unsigned long start, unsigned long len,
71193
71194 if (end < start)
71195 return -EINVAL;
71196+
71197+#ifdef CONFIG_PAX_SEGMEXEC
71198+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71199+ if (end > SEGMEXEC_TASK_SIZE)
71200+ return -EINVAL;
71201+ } else
71202+#endif
71203+
71204+ if (end > TASK_SIZE)
71205+ return -EINVAL;
71206+
71207 if (end == start)
71208 return 0;
71209
71210@@ -1330,6 +1355,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71211 if (!mm)
71212 goto out;
71213
71214+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71215+ if (mm != current->mm &&
71216+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71217+ err = -EPERM;
71218+ goto out;
71219+ }
71220+#endif
71221+
71222 /*
71223 * Check if this process has the right to modify the specified
71224 * process. The right exists if the process has administrative
71225@@ -1339,8 +1372,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71226 rcu_read_lock();
71227 tcred = __task_cred(task);
71228 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71229- cred->uid != tcred->suid && cred->uid != tcred->uid &&
71230- !capable(CAP_SYS_NICE)) {
71231+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71232 rcu_read_unlock();
71233 err = -EPERM;
71234 goto out;
71235diff --git a/mm/migrate.c b/mm/migrate.c
71236index 1503b6b..156c672 100644
71237--- a/mm/migrate.c
71238+++ b/mm/migrate.c
71239@@ -1370,6 +1370,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71240 if (!mm)
71241 return -EINVAL;
71242
71243+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71244+ if (mm != current->mm &&
71245+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71246+ err = -EPERM;
71247+ goto out;
71248+ }
71249+#endif
71250+
71251 /*
71252 * Check if this process has the right to modify the specified
71253 * process. The right exists if the process has administrative
71254@@ -1379,8 +1387,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71255 rcu_read_lock();
71256 tcred = __task_cred(task);
71257 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71258- cred->uid != tcred->suid && cred->uid != tcred->uid &&
71259- !capable(CAP_SYS_NICE)) {
71260+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71261 rcu_read_unlock();
71262 err = -EPERM;
71263 goto out;
71264diff --git a/mm/mlock.c b/mm/mlock.c
71265index ef726e8..13e0901 100644
71266--- a/mm/mlock.c
71267+++ b/mm/mlock.c
71268@@ -13,6 +13,7 @@
71269 #include <linux/pagemap.h>
71270 #include <linux/mempolicy.h>
71271 #include <linux/syscalls.h>
71272+#include <linux/security.h>
71273 #include <linux/sched.h>
71274 #include <linux/export.h>
71275 #include <linux/rmap.h>
71276@@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
71277 return -EINVAL;
71278 if (end == start)
71279 return 0;
71280+ if (end > TASK_SIZE)
71281+ return -EINVAL;
71282+
71283 vma = find_vma(current->mm, start);
71284 if (!vma || vma->vm_start > start)
71285 return -ENOMEM;
71286@@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
71287 for (nstart = start ; ; ) {
71288 vm_flags_t newflags;
71289
71290+#ifdef CONFIG_PAX_SEGMEXEC
71291+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71292+ break;
71293+#endif
71294+
71295 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
71296
71297 newflags = vma->vm_flags | VM_LOCKED;
71298@@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
71299 lock_limit >>= PAGE_SHIFT;
71300
71301 /* check against resource limits */
71302+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
71303 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
71304 error = do_mlock(start, len, 1);
71305 up_write(&current->mm->mmap_sem);
71306@@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
71307 static int do_mlockall(int flags)
71308 {
71309 struct vm_area_struct * vma, * prev = NULL;
71310- unsigned int def_flags = 0;
71311
71312 if (flags & MCL_FUTURE)
71313- def_flags = VM_LOCKED;
71314- current->mm->def_flags = def_flags;
71315+ current->mm->def_flags |= VM_LOCKED;
71316+ else
71317+ current->mm->def_flags &= ~VM_LOCKED;
71318 if (flags == MCL_FUTURE)
71319 goto out;
71320
71321 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
71322 vm_flags_t newflags;
71323
71324+#ifdef CONFIG_PAX_SEGMEXEC
71325+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71326+ break;
71327+#endif
71328+
71329+ BUG_ON(vma->vm_end > TASK_SIZE);
71330 newflags = vma->vm_flags | VM_LOCKED;
71331 if (!(flags & MCL_CURRENT))
71332 newflags &= ~VM_LOCKED;
71333@@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
71334 lock_limit >>= PAGE_SHIFT;
71335
71336 ret = -ENOMEM;
71337+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
71338 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
71339 capable(CAP_IPC_LOCK))
71340 ret = do_mlockall(flags);
71341diff --git a/mm/mmap.c b/mm/mmap.c
71342index da15a79..314aef3 100644
71343--- a/mm/mmap.c
71344+++ b/mm/mmap.c
71345@@ -46,6 +46,16 @@
71346 #define arch_rebalance_pgtables(addr, len) (addr)
71347 #endif
71348
71349+static inline void verify_mm_writelocked(struct mm_struct *mm)
71350+{
71351+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
71352+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71353+ up_read(&mm->mmap_sem);
71354+ BUG();
71355+ }
71356+#endif
71357+}
71358+
71359 static void unmap_region(struct mm_struct *mm,
71360 struct vm_area_struct *vma, struct vm_area_struct *prev,
71361 unsigned long start, unsigned long end);
71362@@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
71363 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
71364 *
71365 */
71366-pgprot_t protection_map[16] = {
71367+pgprot_t protection_map[16] __read_only = {
71368 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
71369 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
71370 };
71371
71372-pgprot_t vm_get_page_prot(unsigned long vm_flags)
71373+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
71374 {
71375- return __pgprot(pgprot_val(protection_map[vm_flags &
71376+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
71377 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
71378 pgprot_val(arch_vm_get_page_prot(vm_flags)));
71379+
71380+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71381+ if (!(__supported_pte_mask & _PAGE_NX) &&
71382+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
71383+ (vm_flags & (VM_READ | VM_WRITE)))
71384+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
71385+#endif
71386+
71387+ return prot;
71388 }
71389 EXPORT_SYMBOL(vm_get_page_prot);
71390
71391 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
71392 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
71393 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
71394+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
71395 /*
71396 * Make sure vm_committed_as in one cacheline and not cacheline shared with
71397 * other variables. It can be updated by several CPUs frequently.
71398@@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
71399 struct vm_area_struct *next = vma->vm_next;
71400
71401 might_sleep();
71402+ BUG_ON(vma->vm_mirror);
71403 if (vma->vm_ops && vma->vm_ops->close)
71404 vma->vm_ops->close(vma);
71405 if (vma->vm_file) {
71406@@ -272,6 +293,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
71407 * not page aligned -Ram Gupta
71408 */
71409 rlim = rlimit(RLIMIT_DATA);
71410+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
71411 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
71412 (mm->end_data - mm->start_data) > rlim)
71413 goto out;
71414@@ -689,6 +711,12 @@ static int
71415 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
71416 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71417 {
71418+
71419+#ifdef CONFIG_PAX_SEGMEXEC
71420+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
71421+ return 0;
71422+#endif
71423+
71424 if (is_mergeable_vma(vma, file, vm_flags) &&
71425 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71426 if (vma->vm_pgoff == vm_pgoff)
71427@@ -708,6 +736,12 @@ static int
71428 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71429 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71430 {
71431+
71432+#ifdef CONFIG_PAX_SEGMEXEC
71433+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
71434+ return 0;
71435+#endif
71436+
71437 if (is_mergeable_vma(vma, file, vm_flags) &&
71438 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71439 pgoff_t vm_pglen;
71440@@ -750,13 +784,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71441 struct vm_area_struct *vma_merge(struct mm_struct *mm,
71442 struct vm_area_struct *prev, unsigned long addr,
71443 unsigned long end, unsigned long vm_flags,
71444- struct anon_vma *anon_vma, struct file *file,
71445+ struct anon_vma *anon_vma, struct file *file,
71446 pgoff_t pgoff, struct mempolicy *policy)
71447 {
71448 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
71449 struct vm_area_struct *area, *next;
71450 int err;
71451
71452+#ifdef CONFIG_PAX_SEGMEXEC
71453+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
71454+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
71455+
71456+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
71457+#endif
71458+
71459 /*
71460 * We later require that vma->vm_flags == vm_flags,
71461 * so this tests vma->vm_flags & VM_SPECIAL, too.
71462@@ -772,6 +813,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71463 if (next && next->vm_end == end) /* cases 6, 7, 8 */
71464 next = next->vm_next;
71465
71466+#ifdef CONFIG_PAX_SEGMEXEC
71467+ if (prev)
71468+ prev_m = pax_find_mirror_vma(prev);
71469+ if (area)
71470+ area_m = pax_find_mirror_vma(area);
71471+ if (next)
71472+ next_m = pax_find_mirror_vma(next);
71473+#endif
71474+
71475 /*
71476 * Can it merge with the predecessor?
71477 */
71478@@ -791,9 +841,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71479 /* cases 1, 6 */
71480 err = vma_adjust(prev, prev->vm_start,
71481 next->vm_end, prev->vm_pgoff, NULL);
71482- } else /* cases 2, 5, 7 */
71483+
71484+#ifdef CONFIG_PAX_SEGMEXEC
71485+ if (!err && prev_m)
71486+ err = vma_adjust(prev_m, prev_m->vm_start,
71487+ next_m->vm_end, prev_m->vm_pgoff, NULL);
71488+#endif
71489+
71490+ } else { /* cases 2, 5, 7 */
71491 err = vma_adjust(prev, prev->vm_start,
71492 end, prev->vm_pgoff, NULL);
71493+
71494+#ifdef CONFIG_PAX_SEGMEXEC
71495+ if (!err && prev_m)
71496+ err = vma_adjust(prev_m, prev_m->vm_start,
71497+ end_m, prev_m->vm_pgoff, NULL);
71498+#endif
71499+
71500+ }
71501 if (err)
71502 return NULL;
71503 khugepaged_enter_vma_merge(prev);
71504@@ -807,12 +872,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71505 mpol_equal(policy, vma_policy(next)) &&
71506 can_vma_merge_before(next, vm_flags,
71507 anon_vma, file, pgoff+pglen)) {
71508- if (prev && addr < prev->vm_end) /* case 4 */
71509+ if (prev && addr < prev->vm_end) { /* case 4 */
71510 err = vma_adjust(prev, prev->vm_start,
71511 addr, prev->vm_pgoff, NULL);
71512- else /* cases 3, 8 */
71513+
71514+#ifdef CONFIG_PAX_SEGMEXEC
71515+ if (!err && prev_m)
71516+ err = vma_adjust(prev_m, prev_m->vm_start,
71517+ addr_m, prev_m->vm_pgoff, NULL);
71518+#endif
71519+
71520+ } else { /* cases 3, 8 */
71521 err = vma_adjust(area, addr, next->vm_end,
71522 next->vm_pgoff - pglen, NULL);
71523+
71524+#ifdef CONFIG_PAX_SEGMEXEC
71525+ if (!err && area_m)
71526+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
71527+ next_m->vm_pgoff - pglen, NULL);
71528+#endif
71529+
71530+ }
71531 if (err)
71532 return NULL;
71533 khugepaged_enter_vma_merge(area);
71534@@ -921,14 +1001,11 @@ none:
71535 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
71536 struct file *file, long pages)
71537 {
71538- const unsigned long stack_flags
71539- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
71540-
71541 if (file) {
71542 mm->shared_vm += pages;
71543 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
71544 mm->exec_vm += pages;
71545- } else if (flags & stack_flags)
71546+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
71547 mm->stack_vm += pages;
71548 if (flags & (VM_RESERVED|VM_IO))
71549 mm->reserved_vm += pages;
71550@@ -955,7 +1032,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71551 * (the exception is when the underlying filesystem is noexec
71552 * mounted, in which case we dont add PROT_EXEC.)
71553 */
71554- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
71555+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
71556 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
71557 prot |= PROT_EXEC;
71558
71559@@ -981,7 +1058,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71560 /* Obtain the address to map to. we verify (or select) it and ensure
71561 * that it represents a valid section of the address space.
71562 */
71563- addr = get_unmapped_area(file, addr, len, pgoff, flags);
71564+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
71565 if (addr & ~PAGE_MASK)
71566 return addr;
71567
71568@@ -992,6 +1069,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71569 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
71570 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
71571
71572+#ifdef CONFIG_PAX_MPROTECT
71573+ if (mm->pax_flags & MF_PAX_MPROTECT) {
71574+#ifndef CONFIG_PAX_MPROTECT_COMPAT
71575+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
71576+ gr_log_rwxmmap(file);
71577+
71578+#ifdef CONFIG_PAX_EMUPLT
71579+ vm_flags &= ~VM_EXEC;
71580+#else
71581+ return -EPERM;
71582+#endif
71583+
71584+ }
71585+
71586+ if (!(vm_flags & VM_EXEC))
71587+ vm_flags &= ~VM_MAYEXEC;
71588+#else
71589+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
71590+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
71591+#endif
71592+ else
71593+ vm_flags &= ~VM_MAYWRITE;
71594+ }
71595+#endif
71596+
71597+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71598+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
71599+ vm_flags &= ~VM_PAGEEXEC;
71600+#endif
71601+
71602 if (flags & MAP_LOCKED)
71603 if (!can_do_mlock())
71604 return -EPERM;
71605@@ -1003,6 +1110,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71606 locked += mm->locked_vm;
71607 lock_limit = rlimit(RLIMIT_MEMLOCK);
71608 lock_limit >>= PAGE_SHIFT;
71609+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
71610 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
71611 return -EAGAIN;
71612 }
71613@@ -1073,6 +1181,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71614 if (error)
71615 return error;
71616
71617+ if (!gr_acl_handle_mmap(file, prot))
71618+ return -EACCES;
71619+
71620 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
71621 }
71622 EXPORT_SYMBOL(do_mmap_pgoff);
71623@@ -1153,7 +1264,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
71624 vm_flags_t vm_flags = vma->vm_flags;
71625
71626 /* If it was private or non-writable, the write bit is already clear */
71627- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
71628+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
71629 return 0;
71630
71631 /* The backer wishes to know when pages are first written to? */
71632@@ -1202,14 +1313,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
71633 unsigned long charged = 0;
71634 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
71635
71636+#ifdef CONFIG_PAX_SEGMEXEC
71637+ struct vm_area_struct *vma_m = NULL;
71638+#endif
71639+
71640+ /*
71641+ * mm->mmap_sem is required to protect against another thread
71642+ * changing the mappings in case we sleep.
71643+ */
71644+ verify_mm_writelocked(mm);
71645+
71646 /* Clear old maps */
71647 error = -ENOMEM;
71648-munmap_back:
71649 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71650 if (vma && vma->vm_start < addr + len) {
71651 if (do_munmap(mm, addr, len))
71652 return -ENOMEM;
71653- goto munmap_back;
71654+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71655+ BUG_ON(vma && vma->vm_start < addr + len);
71656 }
71657
71658 /* Check against address space limit. */
71659@@ -1258,6 +1379,16 @@ munmap_back:
71660 goto unacct_error;
71661 }
71662
71663+#ifdef CONFIG_PAX_SEGMEXEC
71664+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
71665+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71666+ if (!vma_m) {
71667+ error = -ENOMEM;
71668+ goto free_vma;
71669+ }
71670+ }
71671+#endif
71672+
71673 vma->vm_mm = mm;
71674 vma->vm_start = addr;
71675 vma->vm_end = addr + len;
71676@@ -1282,6 +1413,19 @@ munmap_back:
71677 error = file->f_op->mmap(file, vma);
71678 if (error)
71679 goto unmap_and_free_vma;
71680+
71681+#ifdef CONFIG_PAX_SEGMEXEC
71682+ if (vma_m && (vm_flags & VM_EXECUTABLE))
71683+ added_exe_file_vma(mm);
71684+#endif
71685+
71686+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71687+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
71688+ vma->vm_flags |= VM_PAGEEXEC;
71689+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71690+ }
71691+#endif
71692+
71693 if (vm_flags & VM_EXECUTABLE)
71694 added_exe_file_vma(mm);
71695
71696@@ -1319,6 +1463,11 @@ munmap_back:
71697 vma_link(mm, vma, prev, rb_link, rb_parent);
71698 file = vma->vm_file;
71699
71700+#ifdef CONFIG_PAX_SEGMEXEC
71701+ if (vma_m)
71702+ BUG_ON(pax_mirror_vma(vma_m, vma));
71703+#endif
71704+
71705 /* Once vma denies write, undo our temporary denial count */
71706 if (correct_wcount)
71707 atomic_inc(&inode->i_writecount);
71708@@ -1327,6 +1476,7 @@ out:
71709
71710 mm->total_vm += len >> PAGE_SHIFT;
71711 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
71712+ track_exec_limit(mm, addr, addr + len, vm_flags);
71713 if (vm_flags & VM_LOCKED) {
71714 if (!mlock_vma_pages_range(vma, addr, addr + len))
71715 mm->locked_vm += (len >> PAGE_SHIFT);
71716@@ -1344,6 +1494,12 @@ unmap_and_free_vma:
71717 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
71718 charged = 0;
71719 free_vma:
71720+
71721+#ifdef CONFIG_PAX_SEGMEXEC
71722+ if (vma_m)
71723+ kmem_cache_free(vm_area_cachep, vma_m);
71724+#endif
71725+
71726 kmem_cache_free(vm_area_cachep, vma);
71727 unacct_error:
71728 if (charged)
71729@@ -1351,6 +1507,44 @@ unacct_error:
71730 return error;
71731 }
71732
71733+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
71734+{
71735+ if (!vma) {
71736+#ifdef CONFIG_STACK_GROWSUP
71737+ if (addr > sysctl_heap_stack_gap)
71738+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
71739+ else
71740+ vma = find_vma(current->mm, 0);
71741+ if (vma && (vma->vm_flags & VM_GROWSUP))
71742+ return false;
71743+#endif
71744+ return true;
71745+ }
71746+
71747+ if (addr + len > vma->vm_start)
71748+ return false;
71749+
71750+ if (vma->vm_flags & VM_GROWSDOWN)
71751+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
71752+#ifdef CONFIG_STACK_GROWSUP
71753+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
71754+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
71755+#endif
71756+
71757+ return true;
71758+}
71759+
71760+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
71761+{
71762+ if (vma->vm_start < len)
71763+ return -ENOMEM;
71764+ if (!(vma->vm_flags & VM_GROWSDOWN))
71765+ return vma->vm_start - len;
71766+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
71767+ return vma->vm_start - len - sysctl_heap_stack_gap;
71768+ return -ENOMEM;
71769+}
71770+
71771 /* Get an address range which is currently unmapped.
71772 * For shmat() with addr=0.
71773 *
71774@@ -1377,18 +1571,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
71775 if (flags & MAP_FIXED)
71776 return addr;
71777
71778+#ifdef CONFIG_PAX_RANDMMAP
71779+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71780+#endif
71781+
71782 if (addr) {
71783 addr = PAGE_ALIGN(addr);
71784- vma = find_vma(mm, addr);
71785- if (TASK_SIZE - len >= addr &&
71786- (!vma || addr + len <= vma->vm_start))
71787- return addr;
71788+ if (TASK_SIZE - len >= addr) {
71789+ vma = find_vma(mm, addr);
71790+ if (check_heap_stack_gap(vma, addr, len))
71791+ return addr;
71792+ }
71793 }
71794 if (len > mm->cached_hole_size) {
71795- start_addr = addr = mm->free_area_cache;
71796+ start_addr = addr = mm->free_area_cache;
71797 } else {
71798- start_addr = addr = TASK_UNMAPPED_BASE;
71799- mm->cached_hole_size = 0;
71800+ start_addr = addr = mm->mmap_base;
71801+ mm->cached_hole_size = 0;
71802 }
71803
71804 full_search:
71805@@ -1399,34 +1598,40 @@ full_search:
71806 * Start a new search - just in case we missed
71807 * some holes.
71808 */
71809- if (start_addr != TASK_UNMAPPED_BASE) {
71810- addr = TASK_UNMAPPED_BASE;
71811- start_addr = addr;
71812+ if (start_addr != mm->mmap_base) {
71813+ start_addr = addr = mm->mmap_base;
71814 mm->cached_hole_size = 0;
71815 goto full_search;
71816 }
71817 return -ENOMEM;
71818 }
71819- if (!vma || addr + len <= vma->vm_start) {
71820- /*
71821- * Remember the place where we stopped the search:
71822- */
71823- mm->free_area_cache = addr + len;
71824- return addr;
71825- }
71826+ if (check_heap_stack_gap(vma, addr, len))
71827+ break;
71828 if (addr + mm->cached_hole_size < vma->vm_start)
71829 mm->cached_hole_size = vma->vm_start - addr;
71830 addr = vma->vm_end;
71831 }
71832+
71833+ /*
71834+ * Remember the place where we stopped the search:
71835+ */
71836+ mm->free_area_cache = addr + len;
71837+ return addr;
71838 }
71839 #endif
71840
71841 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
71842 {
71843+
71844+#ifdef CONFIG_PAX_SEGMEXEC
71845+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71846+ return;
71847+#endif
71848+
71849 /*
71850 * Is this a new hole at the lowest possible address?
71851 */
71852- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
71853+ if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
71854 mm->free_area_cache = addr;
71855 mm->cached_hole_size = ~0UL;
71856 }
71857@@ -1444,7 +1649,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71858 {
71859 struct vm_area_struct *vma;
71860 struct mm_struct *mm = current->mm;
71861- unsigned long addr = addr0;
71862+ unsigned long base = mm->mmap_base, addr = addr0;
71863
71864 /* requested length too big for entire address space */
71865 if (len > TASK_SIZE)
71866@@ -1453,13 +1658,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71867 if (flags & MAP_FIXED)
71868 return addr;
71869
71870+#ifdef CONFIG_PAX_RANDMMAP
71871+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71872+#endif
71873+
71874 /* requesting a specific address */
71875 if (addr) {
71876 addr = PAGE_ALIGN(addr);
71877- vma = find_vma(mm, addr);
71878- if (TASK_SIZE - len >= addr &&
71879- (!vma || addr + len <= vma->vm_start))
71880- return addr;
71881+ if (TASK_SIZE - len >= addr) {
71882+ vma = find_vma(mm, addr);
71883+ if (check_heap_stack_gap(vma, addr, len))
71884+ return addr;
71885+ }
71886 }
71887
71888 /* check if free_area_cache is useful for us */
71889@@ -1474,7 +1684,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71890 /* make sure it can fit in the remaining address space */
71891 if (addr > len) {
71892 vma = find_vma(mm, addr-len);
71893- if (!vma || addr <= vma->vm_start)
71894+ if (check_heap_stack_gap(vma, addr - len, len))
71895 /* remember the address as a hint for next time */
71896 return (mm->free_area_cache = addr-len);
71897 }
71898@@ -1491,7 +1701,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71899 * return with success:
71900 */
71901 vma = find_vma(mm, addr);
71902- if (!vma || addr+len <= vma->vm_start)
71903+ if (check_heap_stack_gap(vma, addr, len))
71904 /* remember the address as a hint for next time */
71905 return (mm->free_area_cache = addr);
71906
71907@@ -1500,8 +1710,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71908 mm->cached_hole_size = vma->vm_start - addr;
71909
71910 /* try just below the current vma->vm_start */
71911- addr = vma->vm_start-len;
71912- } while (len < vma->vm_start);
71913+ addr = skip_heap_stack_gap(vma, len);
71914+ } while (!IS_ERR_VALUE(addr));
71915
71916 bottomup:
71917 /*
71918@@ -1510,13 +1720,21 @@ bottomup:
71919 * can happen with large stack limits and large mmap()
71920 * allocations.
71921 */
71922+ mm->mmap_base = TASK_UNMAPPED_BASE;
71923+
71924+#ifdef CONFIG_PAX_RANDMMAP
71925+ if (mm->pax_flags & MF_PAX_RANDMMAP)
71926+ mm->mmap_base += mm->delta_mmap;
71927+#endif
71928+
71929+ mm->free_area_cache = mm->mmap_base;
71930 mm->cached_hole_size = ~0UL;
71931- mm->free_area_cache = TASK_UNMAPPED_BASE;
71932 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
71933 /*
71934 * Restore the topdown base:
71935 */
71936- mm->free_area_cache = mm->mmap_base;
71937+ mm->mmap_base = base;
71938+ mm->free_area_cache = base;
71939 mm->cached_hole_size = ~0UL;
71940
71941 return addr;
71942@@ -1525,6 +1743,12 @@ bottomup:
71943
71944 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
71945 {
71946+
71947+#ifdef CONFIG_PAX_SEGMEXEC
71948+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71949+ return;
71950+#endif
71951+
71952 /*
71953 * Is this a new hole at the highest possible address?
71954 */
71955@@ -1532,8 +1756,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
71956 mm->free_area_cache = addr;
71957
71958 /* dont allow allocations above current base */
71959- if (mm->free_area_cache > mm->mmap_base)
71960+ if (mm->free_area_cache > mm->mmap_base) {
71961 mm->free_area_cache = mm->mmap_base;
71962+ mm->cached_hole_size = ~0UL;
71963+ }
71964 }
71965
71966 unsigned long
71967@@ -1629,6 +1855,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
71968 return vma;
71969 }
71970
71971+#ifdef CONFIG_PAX_SEGMEXEC
71972+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
71973+{
71974+ struct vm_area_struct *vma_m;
71975+
71976+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
71977+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
71978+ BUG_ON(vma->vm_mirror);
71979+ return NULL;
71980+ }
71981+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
71982+ vma_m = vma->vm_mirror;
71983+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
71984+ BUG_ON(vma->vm_file != vma_m->vm_file);
71985+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
71986+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
71987+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
71988+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
71989+ return vma_m;
71990+}
71991+#endif
71992+
71993 /*
71994 * Verify that the stack growth is acceptable and
71995 * update accounting. This is shared with both the
71996@@ -1645,6 +1893,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71997 return -ENOMEM;
71998
71999 /* Stack limit test */
72000+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
72001 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
72002 return -ENOMEM;
72003
72004@@ -1655,6 +1904,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72005 locked = mm->locked_vm + grow;
72006 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
72007 limit >>= PAGE_SHIFT;
72008+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72009 if (locked > limit && !capable(CAP_IPC_LOCK))
72010 return -ENOMEM;
72011 }
72012@@ -1685,37 +1935,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72013 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
72014 * vma is the last one with address > vma->vm_end. Have to extend vma.
72015 */
72016+#ifndef CONFIG_IA64
72017+static
72018+#endif
72019 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72020 {
72021 int error;
72022+ bool locknext;
72023
72024 if (!(vma->vm_flags & VM_GROWSUP))
72025 return -EFAULT;
72026
72027+ /* Also guard against wrapping around to address 0. */
72028+ if (address < PAGE_ALIGN(address+1))
72029+ address = PAGE_ALIGN(address+1);
72030+ else
72031+ return -ENOMEM;
72032+
72033 /*
72034 * We must make sure the anon_vma is allocated
72035 * so that the anon_vma locking is not a noop.
72036 */
72037 if (unlikely(anon_vma_prepare(vma)))
72038 return -ENOMEM;
72039+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72040+ if (locknext && anon_vma_prepare(vma->vm_next))
72041+ return -ENOMEM;
72042 vma_lock_anon_vma(vma);
72043+ if (locknext)
72044+ vma_lock_anon_vma(vma->vm_next);
72045
72046 /*
72047 * vma->vm_start/vm_end cannot change under us because the caller
72048 * is required to hold the mmap_sem in read mode. We need the
72049- * anon_vma lock to serialize against concurrent expand_stacks.
72050- * Also guard against wrapping around to address 0.
72051+ * anon_vma locks to serialize against concurrent expand_stacks
72052+ * and expand_upwards.
72053 */
72054- if (address < PAGE_ALIGN(address+4))
72055- address = PAGE_ALIGN(address+4);
72056- else {
72057- vma_unlock_anon_vma(vma);
72058- return -ENOMEM;
72059- }
72060 error = 0;
72061
72062 /* Somebody else might have raced and expanded it already */
72063- if (address > vma->vm_end) {
72064+ 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)
72065+ error = -ENOMEM;
72066+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72067 unsigned long size, grow;
72068
72069 size = address - vma->vm_start;
72070@@ -1730,6 +1991,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72071 }
72072 }
72073 }
72074+ if (locknext)
72075+ vma_unlock_anon_vma(vma->vm_next);
72076 vma_unlock_anon_vma(vma);
72077 khugepaged_enter_vma_merge(vma);
72078 return error;
72079@@ -1743,6 +2006,8 @@ int expand_downwards(struct vm_area_struct *vma,
72080 unsigned long address)
72081 {
72082 int error;
72083+ bool lockprev = false;
72084+ struct vm_area_struct *prev;
72085
72086 /*
72087 * We must make sure the anon_vma is allocated
72088@@ -1756,6 +2021,15 @@ int expand_downwards(struct vm_area_struct *vma,
72089 if (error)
72090 return error;
72091
72092+ prev = vma->vm_prev;
72093+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72094+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72095+#endif
72096+ if (lockprev && anon_vma_prepare(prev))
72097+ return -ENOMEM;
72098+ if (lockprev)
72099+ vma_lock_anon_vma(prev);
72100+
72101 vma_lock_anon_vma(vma);
72102
72103 /*
72104@@ -1765,9 +2039,17 @@ int expand_downwards(struct vm_area_struct *vma,
72105 */
72106
72107 /* Somebody else might have raced and expanded it already */
72108- if (address < vma->vm_start) {
72109+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72110+ error = -ENOMEM;
72111+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72112 unsigned long size, grow;
72113
72114+#ifdef CONFIG_PAX_SEGMEXEC
72115+ struct vm_area_struct *vma_m;
72116+
72117+ vma_m = pax_find_mirror_vma(vma);
72118+#endif
72119+
72120 size = vma->vm_end - address;
72121 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72122
72123@@ -1777,11 +2059,22 @@ int expand_downwards(struct vm_area_struct *vma,
72124 if (!error) {
72125 vma->vm_start = address;
72126 vma->vm_pgoff -= grow;
72127+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72128+
72129+#ifdef CONFIG_PAX_SEGMEXEC
72130+ if (vma_m) {
72131+ vma_m->vm_start -= grow << PAGE_SHIFT;
72132+ vma_m->vm_pgoff -= grow;
72133+ }
72134+#endif
72135+
72136 perf_event_mmap(vma);
72137 }
72138 }
72139 }
72140 vma_unlock_anon_vma(vma);
72141+ if (lockprev)
72142+ vma_unlock_anon_vma(prev);
72143 khugepaged_enter_vma_merge(vma);
72144 return error;
72145 }
72146@@ -1851,6 +2144,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72147 do {
72148 long nrpages = vma_pages(vma);
72149
72150+#ifdef CONFIG_PAX_SEGMEXEC
72151+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72152+ vma = remove_vma(vma);
72153+ continue;
72154+ }
72155+#endif
72156+
72157 mm->total_vm -= nrpages;
72158 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
72159 vma = remove_vma(vma);
72160@@ -1896,6 +2196,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72161 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72162 vma->vm_prev = NULL;
72163 do {
72164+
72165+#ifdef CONFIG_PAX_SEGMEXEC
72166+ if (vma->vm_mirror) {
72167+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72168+ vma->vm_mirror->vm_mirror = NULL;
72169+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
72170+ vma->vm_mirror = NULL;
72171+ }
72172+#endif
72173+
72174 rb_erase(&vma->vm_rb, &mm->mm_rb);
72175 mm->map_count--;
72176 tail_vma = vma;
72177@@ -1924,14 +2234,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72178 struct vm_area_struct *new;
72179 int err = -ENOMEM;
72180
72181+#ifdef CONFIG_PAX_SEGMEXEC
72182+ struct vm_area_struct *vma_m, *new_m = NULL;
72183+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72184+#endif
72185+
72186 if (is_vm_hugetlb_page(vma) && (addr &
72187 ~(huge_page_mask(hstate_vma(vma)))))
72188 return -EINVAL;
72189
72190+#ifdef CONFIG_PAX_SEGMEXEC
72191+ vma_m = pax_find_mirror_vma(vma);
72192+#endif
72193+
72194 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72195 if (!new)
72196 goto out_err;
72197
72198+#ifdef CONFIG_PAX_SEGMEXEC
72199+ if (vma_m) {
72200+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72201+ if (!new_m) {
72202+ kmem_cache_free(vm_area_cachep, new);
72203+ goto out_err;
72204+ }
72205+ }
72206+#endif
72207+
72208 /* most fields are the same, copy all, and then fixup */
72209 *new = *vma;
72210
72211@@ -1944,6 +2273,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72212 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
72213 }
72214
72215+#ifdef CONFIG_PAX_SEGMEXEC
72216+ if (vma_m) {
72217+ *new_m = *vma_m;
72218+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
72219+ new_m->vm_mirror = new;
72220+ new->vm_mirror = new_m;
72221+
72222+ if (new_below)
72223+ new_m->vm_end = addr_m;
72224+ else {
72225+ new_m->vm_start = addr_m;
72226+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
72227+ }
72228+ }
72229+#endif
72230+
72231 pol = mpol_dup(vma_policy(vma));
72232 if (IS_ERR(pol)) {
72233 err = PTR_ERR(pol);
72234@@ -1969,6 +2314,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72235 else
72236 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
72237
72238+#ifdef CONFIG_PAX_SEGMEXEC
72239+ if (!err && vma_m) {
72240+ if (anon_vma_clone(new_m, vma_m))
72241+ goto out_free_mpol;
72242+
72243+ mpol_get(pol);
72244+ vma_set_policy(new_m, pol);
72245+
72246+ if (new_m->vm_file) {
72247+ get_file(new_m->vm_file);
72248+ if (vma_m->vm_flags & VM_EXECUTABLE)
72249+ added_exe_file_vma(mm);
72250+ }
72251+
72252+ if (new_m->vm_ops && new_m->vm_ops->open)
72253+ new_m->vm_ops->open(new_m);
72254+
72255+ if (new_below)
72256+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
72257+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
72258+ else
72259+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
72260+
72261+ if (err) {
72262+ if (new_m->vm_ops && new_m->vm_ops->close)
72263+ new_m->vm_ops->close(new_m);
72264+ if (new_m->vm_file) {
72265+ if (vma_m->vm_flags & VM_EXECUTABLE)
72266+ removed_exe_file_vma(mm);
72267+ fput(new_m->vm_file);
72268+ }
72269+ mpol_put(pol);
72270+ }
72271+ }
72272+#endif
72273+
72274 /* Success. */
72275 if (!err)
72276 return 0;
72277@@ -1981,10 +2362,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72278 removed_exe_file_vma(mm);
72279 fput(new->vm_file);
72280 }
72281- unlink_anon_vmas(new);
72282 out_free_mpol:
72283 mpol_put(pol);
72284 out_free_vma:
72285+
72286+#ifdef CONFIG_PAX_SEGMEXEC
72287+ if (new_m) {
72288+ unlink_anon_vmas(new_m);
72289+ kmem_cache_free(vm_area_cachep, new_m);
72290+ }
72291+#endif
72292+
72293+ unlink_anon_vmas(new);
72294 kmem_cache_free(vm_area_cachep, new);
72295 out_err:
72296 return err;
72297@@ -1997,6 +2386,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72298 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72299 unsigned long addr, int new_below)
72300 {
72301+
72302+#ifdef CONFIG_PAX_SEGMEXEC
72303+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72304+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
72305+ if (mm->map_count >= sysctl_max_map_count-1)
72306+ return -ENOMEM;
72307+ } else
72308+#endif
72309+
72310 if (mm->map_count >= sysctl_max_map_count)
72311 return -ENOMEM;
72312
72313@@ -2008,11 +2406,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72314 * work. This now handles partial unmappings.
72315 * Jeremy Fitzhardinge <jeremy@goop.org>
72316 */
72317+#ifdef CONFIG_PAX_SEGMEXEC
72318 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72319 {
72320+ int ret = __do_munmap(mm, start, len);
72321+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
72322+ return ret;
72323+
72324+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
72325+}
72326+
72327+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72328+#else
72329+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72330+#endif
72331+{
72332 unsigned long end;
72333 struct vm_area_struct *vma, *prev, *last;
72334
72335+ /*
72336+ * mm->mmap_sem is required to protect against another thread
72337+ * changing the mappings in case we sleep.
72338+ */
72339+ verify_mm_writelocked(mm);
72340+
72341 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
72342 return -EINVAL;
72343
72344@@ -2087,6 +2504,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72345 /* Fix up all other VM information */
72346 remove_vma_list(mm, vma);
72347
72348+ track_exec_limit(mm, start, end, 0UL);
72349+
72350 return 0;
72351 }
72352
72353@@ -2099,22 +2518,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
72354
72355 profile_munmap(addr);
72356
72357+#ifdef CONFIG_PAX_SEGMEXEC
72358+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
72359+ (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
72360+ return -EINVAL;
72361+#endif
72362+
72363 down_write(&mm->mmap_sem);
72364 ret = do_munmap(mm, addr, len);
72365 up_write(&mm->mmap_sem);
72366 return ret;
72367 }
72368
72369-static inline void verify_mm_writelocked(struct mm_struct *mm)
72370-{
72371-#ifdef CONFIG_DEBUG_VM
72372- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72373- WARN_ON(1);
72374- up_read(&mm->mmap_sem);
72375- }
72376-#endif
72377-}
72378-
72379 /*
72380 * this is really a simplified "do_mmap". it only handles
72381 * anonymous maps. eventually we may be able to do some
72382@@ -2128,6 +2543,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72383 struct rb_node ** rb_link, * rb_parent;
72384 pgoff_t pgoff = addr >> PAGE_SHIFT;
72385 int error;
72386+ unsigned long charged;
72387
72388 len = PAGE_ALIGN(len);
72389 if (!len)
72390@@ -2139,16 +2555,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72391
72392 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
72393
72394+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
72395+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
72396+ flags &= ~VM_EXEC;
72397+
72398+#ifdef CONFIG_PAX_MPROTECT
72399+ if (mm->pax_flags & MF_PAX_MPROTECT)
72400+ flags &= ~VM_MAYEXEC;
72401+#endif
72402+
72403+ }
72404+#endif
72405+
72406 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
72407 if (error & ~PAGE_MASK)
72408 return error;
72409
72410+ charged = len >> PAGE_SHIFT;
72411+
72412 /*
72413 * mlock MCL_FUTURE?
72414 */
72415 if (mm->def_flags & VM_LOCKED) {
72416 unsigned long locked, lock_limit;
72417- locked = len >> PAGE_SHIFT;
72418+ locked = charged;
72419 locked += mm->locked_vm;
72420 lock_limit = rlimit(RLIMIT_MEMLOCK);
72421 lock_limit >>= PAGE_SHIFT;
72422@@ -2165,22 +2595,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72423 /*
72424 * Clear old maps. this also does some error checking for us
72425 */
72426- munmap_back:
72427 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72428 if (vma && vma->vm_start < addr + len) {
72429 if (do_munmap(mm, addr, len))
72430 return -ENOMEM;
72431- goto munmap_back;
72432+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72433+ BUG_ON(vma && vma->vm_start < addr + len);
72434 }
72435
72436 /* Check against address space limits *after* clearing old maps... */
72437- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
72438+ if (!may_expand_vm(mm, charged))
72439 return -ENOMEM;
72440
72441 if (mm->map_count > sysctl_max_map_count)
72442 return -ENOMEM;
72443
72444- if (security_vm_enough_memory(len >> PAGE_SHIFT))
72445+ if (security_vm_enough_memory(charged))
72446 return -ENOMEM;
72447
72448 /* Can we just expand an old private anonymous mapping? */
72449@@ -2194,7 +2624,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72450 */
72451 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72452 if (!vma) {
72453- vm_unacct_memory(len >> PAGE_SHIFT);
72454+ vm_unacct_memory(charged);
72455 return -ENOMEM;
72456 }
72457
72458@@ -2208,11 +2638,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72459 vma_link(mm, vma, prev, rb_link, rb_parent);
72460 out:
72461 perf_event_mmap(vma);
72462- mm->total_vm += len >> PAGE_SHIFT;
72463+ mm->total_vm += charged;
72464 if (flags & VM_LOCKED) {
72465 if (!mlock_vma_pages_range(vma, addr, addr + len))
72466- mm->locked_vm += (len >> PAGE_SHIFT);
72467+ mm->locked_vm += charged;
72468 }
72469+ track_exec_limit(mm, addr, addr + len, flags);
72470 return addr;
72471 }
72472
72473@@ -2259,8 +2690,10 @@ void exit_mmap(struct mm_struct *mm)
72474 * Walk the list again, actually closing and freeing it,
72475 * with preemption enabled, without holding any MM locks.
72476 */
72477- while (vma)
72478+ while (vma) {
72479+ vma->vm_mirror = NULL;
72480 vma = remove_vma(vma);
72481+ }
72482
72483 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
72484 }
72485@@ -2274,6 +2707,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72486 struct vm_area_struct * __vma, * prev;
72487 struct rb_node ** rb_link, * rb_parent;
72488
72489+#ifdef CONFIG_PAX_SEGMEXEC
72490+ struct vm_area_struct *vma_m = NULL;
72491+#endif
72492+
72493+ if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
72494+ return -EPERM;
72495+
72496 /*
72497 * The vm_pgoff of a purely anonymous vma should be irrelevant
72498 * until its first write fault, when page's anon_vma and index
72499@@ -2296,7 +2736,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72500 if ((vma->vm_flags & VM_ACCOUNT) &&
72501 security_vm_enough_memory_mm(mm, vma_pages(vma)))
72502 return -ENOMEM;
72503+
72504+#ifdef CONFIG_PAX_SEGMEXEC
72505+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
72506+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72507+ if (!vma_m)
72508+ return -ENOMEM;
72509+ }
72510+#endif
72511+
72512 vma_link(mm, vma, prev, rb_link, rb_parent);
72513+
72514+#ifdef CONFIG_PAX_SEGMEXEC
72515+ if (vma_m)
72516+ BUG_ON(pax_mirror_vma(vma_m, vma));
72517+#endif
72518+
72519 return 0;
72520 }
72521
72522@@ -2315,6 +2770,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72523 struct mempolicy *pol;
72524 bool faulted_in_anon_vma = true;
72525
72526+ BUG_ON(vma->vm_mirror);
72527+
72528 /*
72529 * If anonymous vma has not yet been faulted, update new pgoff
72530 * to match new location, to increase its chance of merging.
72531@@ -2382,6 +2839,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72532 return NULL;
72533 }
72534
72535+#ifdef CONFIG_PAX_SEGMEXEC
72536+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
72537+{
72538+ struct vm_area_struct *prev_m;
72539+ struct rb_node **rb_link_m, *rb_parent_m;
72540+ struct mempolicy *pol_m;
72541+
72542+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
72543+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
72544+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
72545+ *vma_m = *vma;
72546+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
72547+ if (anon_vma_clone(vma_m, vma))
72548+ return -ENOMEM;
72549+ pol_m = vma_policy(vma_m);
72550+ mpol_get(pol_m);
72551+ vma_set_policy(vma_m, pol_m);
72552+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
72553+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
72554+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
72555+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
72556+ if (vma_m->vm_file)
72557+ get_file(vma_m->vm_file);
72558+ if (vma_m->vm_ops && vma_m->vm_ops->open)
72559+ vma_m->vm_ops->open(vma_m);
72560+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
72561+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
72562+ vma_m->vm_mirror = vma;
72563+ vma->vm_mirror = vma_m;
72564+ return 0;
72565+}
72566+#endif
72567+
72568 /*
72569 * Return true if the calling process may expand its vm space by the passed
72570 * number of pages
72571@@ -2393,6 +2883,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
72572
72573 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
72574
72575+#ifdef CONFIG_PAX_RANDMMAP
72576+ if (mm->pax_flags & MF_PAX_RANDMMAP)
72577+ cur -= mm->brk_gap;
72578+#endif
72579+
72580+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
72581 if (cur + npages > lim)
72582 return 0;
72583 return 1;
72584@@ -2463,6 +2959,22 @@ int install_special_mapping(struct mm_struct *mm,
72585 vma->vm_start = addr;
72586 vma->vm_end = addr + len;
72587
72588+#ifdef CONFIG_PAX_MPROTECT
72589+ if (mm->pax_flags & MF_PAX_MPROTECT) {
72590+#ifndef CONFIG_PAX_MPROTECT_COMPAT
72591+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
72592+ return -EPERM;
72593+ if (!(vm_flags & VM_EXEC))
72594+ vm_flags &= ~VM_MAYEXEC;
72595+#else
72596+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72597+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72598+#endif
72599+ else
72600+ vm_flags &= ~VM_MAYWRITE;
72601+ }
72602+#endif
72603+
72604 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
72605 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72606
72607diff --git a/mm/mprotect.c b/mm/mprotect.c
72608index f437d05..e3763f6 100644
72609--- a/mm/mprotect.c
72610+++ b/mm/mprotect.c
72611@@ -23,10 +23,16 @@
72612 #include <linux/mmu_notifier.h>
72613 #include <linux/migrate.h>
72614 #include <linux/perf_event.h>
72615+
72616+#ifdef CONFIG_PAX_MPROTECT
72617+#include <linux/elf.h>
72618+#endif
72619+
72620 #include <asm/uaccess.h>
72621 #include <asm/pgtable.h>
72622 #include <asm/cacheflush.h>
72623 #include <asm/tlbflush.h>
72624+#include <asm/mmu_context.h>
72625
72626 #ifndef pgprot_modify
72627 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
72628@@ -141,6 +147,48 @@ static void change_protection(struct vm_area_struct *vma,
72629 flush_tlb_range(vma, start, end);
72630 }
72631
72632+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72633+/* called while holding the mmap semaphor for writing except stack expansion */
72634+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
72635+{
72636+ unsigned long oldlimit, newlimit = 0UL;
72637+
72638+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
72639+ return;
72640+
72641+ spin_lock(&mm->page_table_lock);
72642+ oldlimit = mm->context.user_cs_limit;
72643+ if ((prot & VM_EXEC) && oldlimit < end)
72644+ /* USER_CS limit moved up */
72645+ newlimit = end;
72646+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
72647+ /* USER_CS limit moved down */
72648+ newlimit = start;
72649+
72650+ if (newlimit) {
72651+ mm->context.user_cs_limit = newlimit;
72652+
72653+#ifdef CONFIG_SMP
72654+ wmb();
72655+ cpus_clear(mm->context.cpu_user_cs_mask);
72656+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
72657+#endif
72658+
72659+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
72660+ }
72661+ spin_unlock(&mm->page_table_lock);
72662+ if (newlimit == end) {
72663+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
72664+
72665+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
72666+ if (is_vm_hugetlb_page(vma))
72667+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
72668+ else
72669+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
72670+ }
72671+}
72672+#endif
72673+
72674 int
72675 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72676 unsigned long start, unsigned long end, unsigned long newflags)
72677@@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72678 int error;
72679 int dirty_accountable = 0;
72680
72681+#ifdef CONFIG_PAX_SEGMEXEC
72682+ struct vm_area_struct *vma_m = NULL;
72683+ unsigned long start_m, end_m;
72684+
72685+ start_m = start + SEGMEXEC_TASK_SIZE;
72686+ end_m = end + SEGMEXEC_TASK_SIZE;
72687+#endif
72688+
72689 if (newflags == oldflags) {
72690 *pprev = vma;
72691 return 0;
72692 }
72693
72694+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
72695+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
72696+
72697+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
72698+ return -ENOMEM;
72699+
72700+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
72701+ return -ENOMEM;
72702+ }
72703+
72704 /*
72705 * If we make a private mapping writable we increase our commit;
72706 * but (without finer accounting) cannot reduce our commit if we
72707@@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72708 }
72709 }
72710
72711+#ifdef CONFIG_PAX_SEGMEXEC
72712+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
72713+ if (start != vma->vm_start) {
72714+ error = split_vma(mm, vma, start, 1);
72715+ if (error)
72716+ goto fail;
72717+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
72718+ *pprev = (*pprev)->vm_next;
72719+ }
72720+
72721+ if (end != vma->vm_end) {
72722+ error = split_vma(mm, vma, end, 0);
72723+ if (error)
72724+ goto fail;
72725+ }
72726+
72727+ if (pax_find_mirror_vma(vma)) {
72728+ error = __do_munmap(mm, start_m, end_m - start_m);
72729+ if (error)
72730+ goto fail;
72731+ } else {
72732+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72733+ if (!vma_m) {
72734+ error = -ENOMEM;
72735+ goto fail;
72736+ }
72737+ vma->vm_flags = newflags;
72738+ error = pax_mirror_vma(vma_m, vma);
72739+ if (error) {
72740+ vma->vm_flags = oldflags;
72741+ goto fail;
72742+ }
72743+ }
72744+ }
72745+#endif
72746+
72747 /*
72748 * First try to merge with previous and/or next vma.
72749 */
72750@@ -204,9 +306,21 @@ success:
72751 * vm_flags and vm_page_prot are protected by the mmap_sem
72752 * held in write mode.
72753 */
72754+
72755+#ifdef CONFIG_PAX_SEGMEXEC
72756+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
72757+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
72758+#endif
72759+
72760 vma->vm_flags = newflags;
72761+
72762+#ifdef CONFIG_PAX_MPROTECT
72763+ if (mm->binfmt && mm->binfmt->handle_mprotect)
72764+ mm->binfmt->handle_mprotect(vma, newflags);
72765+#endif
72766+
72767 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
72768- vm_get_page_prot(newflags));
72769+ vm_get_page_prot(vma->vm_flags));
72770
72771 if (vma_wants_writenotify(vma)) {
72772 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
72773@@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72774 end = start + len;
72775 if (end <= start)
72776 return -ENOMEM;
72777+
72778+#ifdef CONFIG_PAX_SEGMEXEC
72779+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72780+ if (end > SEGMEXEC_TASK_SIZE)
72781+ return -EINVAL;
72782+ } else
72783+#endif
72784+
72785+ if (end > TASK_SIZE)
72786+ return -EINVAL;
72787+
72788 if (!arch_validate_prot(prot))
72789 return -EINVAL;
72790
72791@@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72792 /*
72793 * Does the application expect PROT_READ to imply PROT_EXEC:
72794 */
72795- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72796+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72797 prot |= PROT_EXEC;
72798
72799 vm_flags = calc_vm_prot_bits(prot);
72800@@ -288,6 +413,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72801 if (start > vma->vm_start)
72802 prev = vma;
72803
72804+#ifdef CONFIG_PAX_MPROTECT
72805+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
72806+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
72807+#endif
72808+
72809 for (nstart = start ; ; ) {
72810 unsigned long newflags;
72811
72812@@ -297,6 +427,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72813
72814 /* newflags >> 4 shift VM_MAY% in place of VM_% */
72815 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
72816+ if (prot & (PROT_WRITE | PROT_EXEC))
72817+ gr_log_rwxmprotect(vma->vm_file);
72818+
72819+ error = -EACCES;
72820+ goto out;
72821+ }
72822+
72823+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
72824 error = -EACCES;
72825 goto out;
72826 }
72827@@ -311,6 +449,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72828 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
72829 if (error)
72830 goto out;
72831+
72832+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
72833+
72834 nstart = tmp;
72835
72836 if (nstart < prev->vm_end)
72837diff --git a/mm/mremap.c b/mm/mremap.c
72838index 87bb839..c3bfadb 100644
72839--- a/mm/mremap.c
72840+++ b/mm/mremap.c
72841@@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
72842 continue;
72843 pte = ptep_get_and_clear(mm, old_addr, old_pte);
72844 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
72845+
72846+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72847+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
72848+ pte = pte_exprotect(pte);
72849+#endif
72850+
72851 set_pte_at(mm, new_addr, new_pte, pte);
72852 }
72853
72854@@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
72855 if (is_vm_hugetlb_page(vma))
72856 goto Einval;
72857
72858+#ifdef CONFIG_PAX_SEGMEXEC
72859+ if (pax_find_mirror_vma(vma))
72860+ goto Einval;
72861+#endif
72862+
72863 /* We can't remap across vm area boundaries */
72864 if (old_len > vma->vm_end - addr)
72865 goto Efault;
72866@@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
72867 unsigned long ret = -EINVAL;
72868 unsigned long charged = 0;
72869 unsigned long map_flags;
72870+ unsigned long pax_task_size = TASK_SIZE;
72871
72872 if (new_addr & ~PAGE_MASK)
72873 goto out;
72874
72875- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
72876+#ifdef CONFIG_PAX_SEGMEXEC
72877+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
72878+ pax_task_size = SEGMEXEC_TASK_SIZE;
72879+#endif
72880+
72881+ pax_task_size -= PAGE_SIZE;
72882+
72883+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
72884 goto out;
72885
72886 /* Check if the location we're moving into overlaps the
72887 * old location at all, and fail if it does.
72888 */
72889- if ((new_addr <= addr) && (new_addr+new_len) > addr)
72890- goto out;
72891-
72892- if ((addr <= new_addr) && (addr+old_len) > new_addr)
72893+ if (addr + old_len > new_addr && new_addr + new_len > addr)
72894 goto out;
72895
72896 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72897@@ -440,6 +456,7 @@ unsigned long do_mremap(unsigned long addr,
72898 struct vm_area_struct *vma;
72899 unsigned long ret = -EINVAL;
72900 unsigned long charged = 0;
72901+ unsigned long pax_task_size = TASK_SIZE;
72902
72903 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
72904 goto out;
72905@@ -458,6 +475,17 @@ unsigned long do_mremap(unsigned long addr,
72906 if (!new_len)
72907 goto out;
72908
72909+#ifdef CONFIG_PAX_SEGMEXEC
72910+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
72911+ pax_task_size = SEGMEXEC_TASK_SIZE;
72912+#endif
72913+
72914+ pax_task_size -= PAGE_SIZE;
72915+
72916+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
72917+ old_len > pax_task_size || addr > pax_task_size-old_len)
72918+ goto out;
72919+
72920 if (flags & MREMAP_FIXED) {
72921 if (flags & MREMAP_MAYMOVE)
72922 ret = mremap_to(addr, old_len, new_addr, new_len);
72923@@ -507,6 +535,7 @@ unsigned long do_mremap(unsigned long addr,
72924 addr + new_len);
72925 }
72926 ret = addr;
72927+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
72928 goto out;
72929 }
72930 }
72931@@ -533,7 +562,13 @@ unsigned long do_mremap(unsigned long addr,
72932 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72933 if (ret)
72934 goto out;
72935+
72936+ map_flags = vma->vm_flags;
72937 ret = move_vma(vma, addr, old_len, new_len, new_addr);
72938+ if (!(ret & ~PAGE_MASK)) {
72939+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
72940+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
72941+ }
72942 }
72943 out:
72944 if (ret & ~PAGE_MASK)
72945diff --git a/mm/nommu.c b/mm/nommu.c
72946index f59e170..34e2a2b 100644
72947--- a/mm/nommu.c
72948+++ b/mm/nommu.c
72949@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
72950 int sysctl_overcommit_ratio = 50; /* default is 50% */
72951 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
72952 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
72953-int heap_stack_gap = 0;
72954
72955 atomic_long_t mmap_pages_allocated;
72956
72957@@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
72958 EXPORT_SYMBOL(find_vma);
72959
72960 /*
72961- * find a VMA
72962- * - we don't extend stack VMAs under NOMMU conditions
72963- */
72964-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
72965-{
72966- return find_vma(mm, addr);
72967-}
72968-
72969-/*
72970 * expand a stack to a given address
72971 * - not supported under NOMMU conditions
72972 */
72973@@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72974
72975 /* most fields are the same, copy all, and then fixup */
72976 *new = *vma;
72977+ INIT_LIST_HEAD(&new->anon_vma_chain);
72978 *region = *vma->vm_region;
72979 new->vm_region = region;
72980
72981diff --git a/mm/page_alloc.c b/mm/page_alloc.c
72982index a13ded1..b949d15 100644
72983--- a/mm/page_alloc.c
72984+++ b/mm/page_alloc.c
72985@@ -335,7 +335,7 @@ out:
72986 * This usage means that zero-order pages may not be compound.
72987 */
72988
72989-static void free_compound_page(struct page *page)
72990+void free_compound_page(struct page *page)
72991 {
72992 __free_pages_ok(page, compound_order(page));
72993 }
72994@@ -692,6 +692,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
72995 int i;
72996 int bad = 0;
72997
72998+#ifdef CONFIG_PAX_MEMORY_SANITIZE
72999+ unsigned long index = 1UL << order;
73000+#endif
73001+
73002 trace_mm_page_free(page, order);
73003 kmemcheck_free_shadow(page, order);
73004
73005@@ -707,6 +711,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73006 debug_check_no_obj_freed(page_address(page),
73007 PAGE_SIZE << order);
73008 }
73009+
73010+#ifdef CONFIG_PAX_MEMORY_SANITIZE
73011+ for (; index; --index)
73012+ sanitize_highpage(page + index - 1);
73013+#endif
73014+
73015 arch_free_page(page, order);
73016 kernel_map_pages(page, 1 << order, 0);
73017
73018@@ -830,8 +840,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
73019 arch_alloc_page(page, order);
73020 kernel_map_pages(page, 1 << order, 1);
73021
73022+#ifndef CONFIG_PAX_MEMORY_SANITIZE
73023 if (gfp_flags & __GFP_ZERO)
73024 prep_zero_page(page, order, gfp_flags);
73025+#endif
73026
73027 if (order && (gfp_flags & __GFP_COMP))
73028 prep_compound_page(page, order);
73029@@ -3468,7 +3480,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73030 unsigned long pfn;
73031
73032 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73033+#ifdef CONFIG_X86_32
73034+ /* boot failures in VMware 8 on 32bit vanilla since
73035+ this change */
73036+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73037+#else
73038 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73039+#endif
73040 return 1;
73041 }
73042 return 0;
73043diff --git a/mm/percpu.c b/mm/percpu.c
73044index 317de23..1ba7776 100644
73045--- a/mm/percpu.c
73046+++ b/mm/percpu.c
73047@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73048 static unsigned int pcpu_high_unit_cpu __read_mostly;
73049
73050 /* the address of the first chunk which starts with the kernel static area */
73051-void *pcpu_base_addr __read_mostly;
73052+void *pcpu_base_addr __read_only;
73053 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73054
73055 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73056diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
73057index c20ff48..137702a 100644
73058--- a/mm/process_vm_access.c
73059+++ b/mm/process_vm_access.c
73060@@ -13,6 +13,7 @@
73061 #include <linux/uio.h>
73062 #include <linux/sched.h>
73063 #include <linux/highmem.h>
73064+#include <linux/security.h>
73065 #include <linux/ptrace.h>
73066 #include <linux/slab.h>
73067 #include <linux/syscalls.h>
73068@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73069 size_t iov_l_curr_offset = 0;
73070 ssize_t iov_len;
73071
73072+ return -ENOSYS; // PaX: until properly audited
73073+
73074 /*
73075 * Work out how many pages of struct pages we're going to need
73076 * when eventually calling get_user_pages
73077 */
73078 for (i = 0; i < riovcnt; i++) {
73079 iov_len = rvec[i].iov_len;
73080- if (iov_len > 0) {
73081- nr_pages_iov = ((unsigned long)rvec[i].iov_base
73082- + iov_len)
73083- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
73084- / PAGE_SIZE + 1;
73085- nr_pages = max(nr_pages, nr_pages_iov);
73086- }
73087+ if (iov_len <= 0)
73088+ continue;
73089+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
73090+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
73091+ nr_pages = max(nr_pages, nr_pages_iov);
73092 }
73093
73094 if (nr_pages == 0)
73095@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73096 goto free_proc_pages;
73097 }
73098
73099+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
73100+ rc = -EPERM;
73101+ goto put_task_struct;
73102+ }
73103+
73104 mm = mm_access(task, PTRACE_MODE_ATTACH);
73105 if (!mm || IS_ERR(mm)) {
73106 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
73107diff --git a/mm/rmap.c b/mm/rmap.c
73108index c8454e0..b04f3a2 100644
73109--- a/mm/rmap.c
73110+++ b/mm/rmap.c
73111@@ -152,6 +152,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73112 struct anon_vma *anon_vma = vma->anon_vma;
73113 struct anon_vma_chain *avc;
73114
73115+#ifdef CONFIG_PAX_SEGMEXEC
73116+ struct anon_vma_chain *avc_m = NULL;
73117+#endif
73118+
73119 might_sleep();
73120 if (unlikely(!anon_vma)) {
73121 struct mm_struct *mm = vma->vm_mm;
73122@@ -161,6 +165,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73123 if (!avc)
73124 goto out_enomem;
73125
73126+#ifdef CONFIG_PAX_SEGMEXEC
73127+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73128+ if (!avc_m)
73129+ goto out_enomem_free_avc;
73130+#endif
73131+
73132 anon_vma = find_mergeable_anon_vma(vma);
73133 allocated = NULL;
73134 if (!anon_vma) {
73135@@ -174,6 +184,21 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73136 /* page_table_lock to protect against threads */
73137 spin_lock(&mm->page_table_lock);
73138 if (likely(!vma->anon_vma)) {
73139+
73140+#ifdef CONFIG_PAX_SEGMEXEC
73141+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73142+
73143+ if (vma_m) {
73144+ BUG_ON(vma_m->anon_vma);
73145+ vma_m->anon_vma = anon_vma;
73146+ avc_m->anon_vma = anon_vma;
73147+ avc_m->vma = vma;
73148+ list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
73149+ list_add(&avc_m->same_anon_vma, &anon_vma->head);
73150+ avc_m = NULL;
73151+ }
73152+#endif
73153+
73154 vma->anon_vma = anon_vma;
73155 avc->anon_vma = anon_vma;
73156 avc->vma = vma;
73157@@ -187,12 +212,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73158
73159 if (unlikely(allocated))
73160 put_anon_vma(allocated);
73161+
73162+#ifdef CONFIG_PAX_SEGMEXEC
73163+ if (unlikely(avc_m))
73164+ anon_vma_chain_free(avc_m);
73165+#endif
73166+
73167 if (unlikely(avc))
73168 anon_vma_chain_free(avc);
73169 }
73170 return 0;
73171
73172 out_enomem_free_avc:
73173+
73174+#ifdef CONFIG_PAX_SEGMEXEC
73175+ if (avc_m)
73176+ anon_vma_chain_free(avc_m);
73177+#endif
73178+
73179 anon_vma_chain_free(avc);
73180 out_enomem:
73181 return -ENOMEM;
73182@@ -243,7 +280,7 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
73183 * Attach the anon_vmas from src to dst.
73184 * Returns 0 on success, -ENOMEM on failure.
73185 */
73186-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73187+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73188 {
73189 struct anon_vma_chain *avc, *pavc;
73190 struct anon_vma *root = NULL;
73191@@ -321,7 +358,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
73192 * the corresponding VMA in the parent process is attached to.
73193 * Returns 0 on success, non-zero on failure.
73194 */
73195-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73196+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73197 {
73198 struct anon_vma_chain *avc;
73199 struct anon_vma *anon_vma;
73200diff --git a/mm/shmem.c b/mm/shmem.c
73201index 269d049..a9d2b50 100644
73202--- a/mm/shmem.c
73203+++ b/mm/shmem.c
73204@@ -31,7 +31,7 @@
73205 #include <linux/export.h>
73206 #include <linux/swap.h>
73207
73208-static struct vfsmount *shm_mnt;
73209+struct vfsmount *shm_mnt;
73210
73211 #ifdef CONFIG_SHMEM
73212 /*
73213@@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
73214 #define BOGO_DIRENT_SIZE 20
73215
73216 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
73217-#define SHORT_SYMLINK_LEN 128
73218+#define SHORT_SYMLINK_LEN 64
73219
73220 struct shmem_xattr {
73221 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
73222@@ -2180,8 +2180,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
73223 int err = -ENOMEM;
73224
73225 /* Round up to L1_CACHE_BYTES to resist false sharing */
73226- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
73227- L1_CACHE_BYTES), GFP_KERNEL);
73228+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
73229 if (!sbinfo)
73230 return -ENOMEM;
73231
73232diff --git a/mm/slab.c b/mm/slab.c
73233index f0bd785..348b96a 100644
73234--- a/mm/slab.c
73235+++ b/mm/slab.c
73236@@ -153,7 +153,7 @@
73237
73238 /* Legal flag mask for kmem_cache_create(). */
73239 #if DEBUG
73240-# define CREATE_MASK (SLAB_RED_ZONE | \
73241+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
73242 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
73243 SLAB_CACHE_DMA | \
73244 SLAB_STORE_USER | \
73245@@ -161,7 +161,7 @@
73246 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73247 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
73248 #else
73249-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
73250+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
73251 SLAB_CACHE_DMA | \
73252 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
73253 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73254@@ -290,7 +290,7 @@ struct kmem_list3 {
73255 * Need this for bootstrapping a per node allocator.
73256 */
73257 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
73258-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
73259+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
73260 #define CACHE_CACHE 0
73261 #define SIZE_AC MAX_NUMNODES
73262 #define SIZE_L3 (2 * MAX_NUMNODES)
73263@@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
73264 if ((x)->max_freeable < i) \
73265 (x)->max_freeable = i; \
73266 } while (0)
73267-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
73268-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
73269-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
73270-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
73271+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
73272+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
73273+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
73274+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
73275 #else
73276 #define STATS_INC_ACTIVE(x) do { } while (0)
73277 #define STATS_DEC_ACTIVE(x) do { } while (0)
73278@@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
73279 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
73280 */
73281 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
73282- const struct slab *slab, void *obj)
73283+ const struct slab *slab, const void *obj)
73284 {
73285 u32 offset = (obj - slab->s_mem);
73286 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
73287@@ -568,7 +568,7 @@ struct cache_names {
73288 static struct cache_names __initdata cache_names[] = {
73289 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
73290 #include <linux/kmalloc_sizes.h>
73291- {NULL,}
73292+ {NULL}
73293 #undef CACHE
73294 };
73295
73296@@ -1588,7 +1588,7 @@ void __init kmem_cache_init(void)
73297 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
73298 sizes[INDEX_AC].cs_size,
73299 ARCH_KMALLOC_MINALIGN,
73300- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73301+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73302 NULL);
73303
73304 if (INDEX_AC != INDEX_L3) {
73305@@ -1596,7 +1596,7 @@ void __init kmem_cache_init(void)
73306 kmem_cache_create(names[INDEX_L3].name,
73307 sizes[INDEX_L3].cs_size,
73308 ARCH_KMALLOC_MINALIGN,
73309- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73310+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73311 NULL);
73312 }
73313
73314@@ -1614,7 +1614,7 @@ void __init kmem_cache_init(void)
73315 sizes->cs_cachep = kmem_cache_create(names->name,
73316 sizes->cs_size,
73317 ARCH_KMALLOC_MINALIGN,
73318- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73319+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73320 NULL);
73321 }
73322 #ifdef CONFIG_ZONE_DMA
73323@@ -4339,10 +4339,10 @@ static int s_show(struct seq_file *m, void *p)
73324 }
73325 /* cpu stats */
73326 {
73327- unsigned long allochit = atomic_read(&cachep->allochit);
73328- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
73329- unsigned long freehit = atomic_read(&cachep->freehit);
73330- unsigned long freemiss = atomic_read(&cachep->freemiss);
73331+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
73332+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
73333+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
73334+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
73335
73336 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
73337 allochit, allocmiss, freehit, freemiss);
73338@@ -4601,13 +4601,62 @@ static int __init slab_proc_init(void)
73339 {
73340 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
73341 #ifdef CONFIG_DEBUG_SLAB_LEAK
73342- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
73343+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
73344 #endif
73345 return 0;
73346 }
73347 module_init(slab_proc_init);
73348 #endif
73349
73350+void check_object_size(const void *ptr, unsigned long n, bool to)
73351+{
73352+
73353+#ifdef CONFIG_PAX_USERCOPY
73354+ struct page *page;
73355+ struct kmem_cache *cachep = NULL;
73356+ struct slab *slabp;
73357+ unsigned int objnr;
73358+ unsigned long offset;
73359+ const char *type;
73360+
73361+ if (!n)
73362+ return;
73363+
73364+ type = "<null>";
73365+ if (ZERO_OR_NULL_PTR(ptr))
73366+ goto report;
73367+
73368+ if (!virt_addr_valid(ptr))
73369+ return;
73370+
73371+ page = virt_to_head_page(ptr);
73372+
73373+ type = "<process stack>";
73374+ if (!PageSlab(page)) {
73375+ if (object_is_on_stack(ptr, n) == -1)
73376+ goto report;
73377+ return;
73378+ }
73379+
73380+ cachep = page_get_cache(page);
73381+ type = cachep->name;
73382+ if (!(cachep->flags & SLAB_USERCOPY))
73383+ goto report;
73384+
73385+ slabp = page_get_slab(page);
73386+ objnr = obj_to_index(cachep, slabp, ptr);
73387+ BUG_ON(objnr >= cachep->num);
73388+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
73389+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
73390+ return;
73391+
73392+report:
73393+ pax_report_usercopy(ptr, n, to, type);
73394+#endif
73395+
73396+}
73397+EXPORT_SYMBOL(check_object_size);
73398+
73399 /**
73400 * ksize - get the actual amount of memory allocated for a given object
73401 * @objp: Pointer to the object
73402diff --git a/mm/slob.c b/mm/slob.c
73403index 8105be4..e045f96 100644
73404--- a/mm/slob.c
73405+++ b/mm/slob.c
73406@@ -29,7 +29,7 @@
73407 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
73408 * alloc_pages() directly, allocating compound pages so the page order
73409 * does not have to be separately tracked, and also stores the exact
73410- * allocation size in page->private so that it can be used to accurately
73411+ * allocation size in slob_page->size so that it can be used to accurately
73412 * provide ksize(). These objects are detected in kfree() because slob_page()
73413 * is false for them.
73414 *
73415@@ -58,6 +58,7 @@
73416 */
73417
73418 #include <linux/kernel.h>
73419+#include <linux/sched.h>
73420 #include <linux/slab.h>
73421 #include <linux/mm.h>
73422 #include <linux/swap.h> /* struct reclaim_state */
73423@@ -102,7 +103,8 @@ struct slob_page {
73424 unsigned long flags; /* mandatory */
73425 atomic_t _count; /* mandatory */
73426 slobidx_t units; /* free units left in page */
73427- unsigned long pad[2];
73428+ unsigned long pad[1];
73429+ unsigned long size; /* size when >=PAGE_SIZE */
73430 slob_t *free; /* first free slob_t in page */
73431 struct list_head list; /* linked list of free pages */
73432 };
73433@@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
73434 */
73435 static inline int is_slob_page(struct slob_page *sp)
73436 {
73437- return PageSlab((struct page *)sp);
73438+ return PageSlab((struct page *)sp) && !sp->size;
73439 }
73440
73441 static inline void set_slob_page(struct slob_page *sp)
73442@@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
73443
73444 static inline struct slob_page *slob_page(const void *addr)
73445 {
73446- return (struct slob_page *)virt_to_page(addr);
73447+ return (struct slob_page *)virt_to_head_page(addr);
73448 }
73449
73450 /*
73451@@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
73452 /*
73453 * Return the size of a slob block.
73454 */
73455-static slobidx_t slob_units(slob_t *s)
73456+static slobidx_t slob_units(const slob_t *s)
73457 {
73458 if (s->units > 0)
73459 return s->units;
73460@@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
73461 /*
73462 * Return the next free slob block pointer after this one.
73463 */
73464-static slob_t *slob_next(slob_t *s)
73465+static slob_t *slob_next(const slob_t *s)
73466 {
73467 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
73468 slobidx_t next;
73469@@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
73470 /*
73471 * Returns true if s is the last free block in its page.
73472 */
73473-static int slob_last(slob_t *s)
73474+static int slob_last(const slob_t *s)
73475 {
73476 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
73477 }
73478@@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
73479 if (!page)
73480 return NULL;
73481
73482+ set_slob_page(page);
73483 return page_address(page);
73484 }
73485
73486@@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
73487 if (!b)
73488 return NULL;
73489 sp = slob_page(b);
73490- set_slob_page(sp);
73491
73492 spin_lock_irqsave(&slob_lock, flags);
73493 sp->units = SLOB_UNITS(PAGE_SIZE);
73494 sp->free = b;
73495+ sp->size = 0;
73496 INIT_LIST_HEAD(&sp->list);
73497 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
73498 set_slob_page_free(sp, slob_list);
73499@@ -476,10 +479,9 @@ out:
73500 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
73501 */
73502
73503-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73504+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
73505 {
73506- unsigned int *m;
73507- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73508+ slob_t *m;
73509 void *ret;
73510
73511 gfp &= gfp_allowed_mask;
73512@@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73513
73514 if (!m)
73515 return NULL;
73516- *m = size;
73517+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
73518+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
73519+ m[0].units = size;
73520+ m[1].units = align;
73521 ret = (void *)m + align;
73522
73523 trace_kmalloc_node(_RET_IP_, ret,
73524@@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73525 gfp |= __GFP_COMP;
73526 ret = slob_new_pages(gfp, order, node);
73527 if (ret) {
73528- struct page *page;
73529- page = virt_to_page(ret);
73530- page->private = size;
73531+ struct slob_page *sp;
73532+ sp = slob_page(ret);
73533+ sp->size = size;
73534 }
73535
73536 trace_kmalloc_node(_RET_IP_, ret,
73537 size, PAGE_SIZE << order, gfp, node);
73538 }
73539
73540- kmemleak_alloc(ret, size, 1, gfp);
73541+ return ret;
73542+}
73543+
73544+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73545+{
73546+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73547+ void *ret = __kmalloc_node_align(size, gfp, node, align);
73548+
73549+ if (!ZERO_OR_NULL_PTR(ret))
73550+ kmemleak_alloc(ret, size, 1, gfp);
73551 return ret;
73552 }
73553 EXPORT_SYMBOL(__kmalloc_node);
73554@@ -533,13 +547,92 @@ void kfree(const void *block)
73555 sp = slob_page(block);
73556 if (is_slob_page(sp)) {
73557 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73558- unsigned int *m = (unsigned int *)(block - align);
73559- slob_free(m, *m + align);
73560- } else
73561+ slob_t *m = (slob_t *)(block - align);
73562+ slob_free(m, m[0].units + align);
73563+ } else {
73564+ clear_slob_page(sp);
73565+ free_slob_page(sp);
73566+ sp->size = 0;
73567 put_page(&sp->page);
73568+ }
73569 }
73570 EXPORT_SYMBOL(kfree);
73571
73572+void check_object_size(const void *ptr, unsigned long n, bool to)
73573+{
73574+
73575+#ifdef CONFIG_PAX_USERCOPY
73576+ struct slob_page *sp;
73577+ const slob_t *free;
73578+ const void *base;
73579+ unsigned long flags;
73580+ const char *type;
73581+
73582+ if (!n)
73583+ return;
73584+
73585+ type = "<null>";
73586+ if (ZERO_OR_NULL_PTR(ptr))
73587+ goto report;
73588+
73589+ if (!virt_addr_valid(ptr))
73590+ return;
73591+
73592+ type = "<process stack>";
73593+ sp = slob_page(ptr);
73594+ if (!PageSlab((struct page *)sp)) {
73595+ if (object_is_on_stack(ptr, n) == -1)
73596+ goto report;
73597+ return;
73598+ }
73599+
73600+ type = "<slob>";
73601+ if (sp->size) {
73602+ base = page_address(&sp->page);
73603+ if (base <= ptr && n <= sp->size - (ptr - base))
73604+ return;
73605+ goto report;
73606+ }
73607+
73608+ /* some tricky double walking to find the chunk */
73609+ spin_lock_irqsave(&slob_lock, flags);
73610+ base = (void *)((unsigned long)ptr & PAGE_MASK);
73611+ free = sp->free;
73612+
73613+ while (!slob_last(free) && (void *)free <= ptr) {
73614+ base = free + slob_units(free);
73615+ free = slob_next(free);
73616+ }
73617+
73618+ while (base < (void *)free) {
73619+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
73620+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
73621+ int offset;
73622+
73623+ if (ptr < base + align)
73624+ break;
73625+
73626+ offset = ptr - base - align;
73627+ if (offset >= m) {
73628+ base += size;
73629+ continue;
73630+ }
73631+
73632+ if (n > m - offset)
73633+ break;
73634+
73635+ spin_unlock_irqrestore(&slob_lock, flags);
73636+ return;
73637+ }
73638+
73639+ spin_unlock_irqrestore(&slob_lock, flags);
73640+report:
73641+ pax_report_usercopy(ptr, n, to, type);
73642+#endif
73643+
73644+}
73645+EXPORT_SYMBOL(check_object_size);
73646+
73647 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
73648 size_t ksize(const void *block)
73649 {
73650@@ -552,10 +645,10 @@ size_t ksize(const void *block)
73651 sp = slob_page(block);
73652 if (is_slob_page(sp)) {
73653 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73654- unsigned int *m = (unsigned int *)(block - align);
73655- return SLOB_UNITS(*m) * SLOB_UNIT;
73656+ slob_t *m = (slob_t *)(block - align);
73657+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
73658 } else
73659- return sp->page.private;
73660+ return sp->size;
73661 }
73662 EXPORT_SYMBOL(ksize);
73663
73664@@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73665 {
73666 struct kmem_cache *c;
73667
73668+#ifdef CONFIG_PAX_USERCOPY
73669+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
73670+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
73671+#else
73672 c = slob_alloc(sizeof(struct kmem_cache),
73673 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
73674+#endif
73675
73676 if (c) {
73677 c->name = name;
73678@@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
73679
73680 lockdep_trace_alloc(flags);
73681
73682+#ifdef CONFIG_PAX_USERCOPY
73683+ b = __kmalloc_node_align(c->size, flags, node, c->align);
73684+#else
73685 if (c->size < PAGE_SIZE) {
73686 b = slob_alloc(c->size, flags, c->align, node);
73687 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73688 SLOB_UNITS(c->size) * SLOB_UNIT,
73689 flags, node);
73690 } else {
73691+ struct slob_page *sp;
73692+
73693 b = slob_new_pages(flags, get_order(c->size), node);
73694+ sp = slob_page(b);
73695+ sp->size = c->size;
73696 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73697 PAGE_SIZE << get_order(c->size),
73698 flags, node);
73699 }
73700+#endif
73701
73702 if (c->ctor)
73703 c->ctor(b);
73704@@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
73705
73706 static void __kmem_cache_free(void *b, int size)
73707 {
73708- if (size < PAGE_SIZE)
73709+ struct slob_page *sp = slob_page(b);
73710+
73711+ if (is_slob_page(sp))
73712 slob_free(b, size);
73713- else
73714+ else {
73715+ clear_slob_page(sp);
73716+ free_slob_page(sp);
73717+ sp->size = 0;
73718 slob_free_pages(b, get_order(size));
73719+ }
73720 }
73721
73722 static void kmem_rcu_free(struct rcu_head *head)
73723@@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
73724
73725 void kmem_cache_free(struct kmem_cache *c, void *b)
73726 {
73727+ int size = c->size;
73728+
73729+#ifdef CONFIG_PAX_USERCOPY
73730+ if (size + c->align < PAGE_SIZE) {
73731+ size += c->align;
73732+ b -= c->align;
73733+ }
73734+#endif
73735+
73736 kmemleak_free_recursive(b, c->flags);
73737 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
73738 struct slob_rcu *slob_rcu;
73739- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
73740- slob_rcu->size = c->size;
73741+ slob_rcu = b + (size - sizeof(struct slob_rcu));
73742+ slob_rcu->size = size;
73743 call_rcu(&slob_rcu->head, kmem_rcu_free);
73744 } else {
73745- __kmem_cache_free(b, c->size);
73746+ __kmem_cache_free(b, size);
73747 }
73748
73749+#ifdef CONFIG_PAX_USERCOPY
73750+ trace_kfree(_RET_IP_, b);
73751+#else
73752 trace_kmem_cache_free(_RET_IP_, b);
73753+#endif
73754+
73755 }
73756 EXPORT_SYMBOL(kmem_cache_free);
73757
73758diff --git a/mm/slub.c b/mm/slub.c
73759index 0342a5d..8180ae9 100644
73760--- a/mm/slub.c
73761+++ b/mm/slub.c
73762@@ -208,7 +208,7 @@ struct track {
73763
73764 enum track_item { TRACK_ALLOC, TRACK_FREE };
73765
73766-#ifdef CONFIG_SYSFS
73767+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73768 static int sysfs_slab_add(struct kmem_cache *);
73769 static int sysfs_slab_alias(struct kmem_cache *, const char *);
73770 static void sysfs_slab_remove(struct kmem_cache *);
73771@@ -532,7 +532,7 @@ static void print_track(const char *s, struct track *t)
73772 if (!t->addr)
73773 return;
73774
73775- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
73776+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
73777 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
73778 #ifdef CONFIG_STACKTRACE
73779 {
73780@@ -2571,6 +2571,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
73781
73782 page = virt_to_head_page(x);
73783
73784+ BUG_ON(!PageSlab(page));
73785+
73786 slab_free(s, page, x, _RET_IP_);
73787
73788 trace_kmem_cache_free(_RET_IP_, x);
73789@@ -2604,7 +2606,7 @@ static int slub_min_objects;
73790 * Merge control. If this is set then no merging of slab caches will occur.
73791 * (Could be removed. This was introduced to pacify the merge skeptics.)
73792 */
73793-static int slub_nomerge;
73794+static int slub_nomerge = 1;
73795
73796 /*
73797 * Calculate the order of allocation given an slab object size.
73798@@ -3057,7 +3059,7 @@ static int kmem_cache_open(struct kmem_cache *s,
73799 else
73800 s->cpu_partial = 30;
73801
73802- s->refcount = 1;
73803+ atomic_set(&s->refcount, 1);
73804 #ifdef CONFIG_NUMA
73805 s->remote_node_defrag_ratio = 1000;
73806 #endif
73807@@ -3161,8 +3163,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
73808 void kmem_cache_destroy(struct kmem_cache *s)
73809 {
73810 down_write(&slub_lock);
73811- s->refcount--;
73812- if (!s->refcount) {
73813+ if (atomic_dec_and_test(&s->refcount)) {
73814 list_del(&s->list);
73815 up_write(&slub_lock);
73816 if (kmem_cache_close(s)) {
73817@@ -3373,6 +3374,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
73818 EXPORT_SYMBOL(__kmalloc_node);
73819 #endif
73820
73821+void check_object_size(const void *ptr, unsigned long n, bool to)
73822+{
73823+
73824+#ifdef CONFIG_PAX_USERCOPY
73825+ struct page *page;
73826+ struct kmem_cache *s = NULL;
73827+ unsigned long offset;
73828+ const char *type;
73829+
73830+ if (!n)
73831+ return;
73832+
73833+ type = "<null>";
73834+ if (ZERO_OR_NULL_PTR(ptr))
73835+ goto report;
73836+
73837+ if (!virt_addr_valid(ptr))
73838+ return;
73839+
73840+ page = virt_to_head_page(ptr);
73841+
73842+ type = "<process stack>";
73843+ if (!PageSlab(page)) {
73844+ if (object_is_on_stack(ptr, n) == -1)
73845+ goto report;
73846+ return;
73847+ }
73848+
73849+ s = page->slab;
73850+ type = s->name;
73851+ if (!(s->flags & SLAB_USERCOPY))
73852+ goto report;
73853+
73854+ offset = (ptr - page_address(page)) % s->size;
73855+ if (offset <= s->objsize && n <= s->objsize - offset)
73856+ return;
73857+
73858+report:
73859+ pax_report_usercopy(ptr, n, to, type);
73860+#endif
73861+
73862+}
73863+EXPORT_SYMBOL(check_object_size);
73864+
73865 size_t ksize(const void *object)
73866 {
73867 struct page *page;
73868@@ -3647,7 +3692,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
73869 int node;
73870
73871 list_add(&s->list, &slab_caches);
73872- s->refcount = -1;
73873+ atomic_set(&s->refcount, -1);
73874
73875 for_each_node_state(node, N_NORMAL_MEMORY) {
73876 struct kmem_cache_node *n = get_node(s, node);
73877@@ -3767,17 +3812,17 @@ void __init kmem_cache_init(void)
73878
73879 /* Caches that are not of the two-to-the-power-of size */
73880 if (KMALLOC_MIN_SIZE <= 32) {
73881- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
73882+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
73883 caches++;
73884 }
73885
73886 if (KMALLOC_MIN_SIZE <= 64) {
73887- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
73888+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
73889 caches++;
73890 }
73891
73892 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
73893- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
73894+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
73895 caches++;
73896 }
73897
73898@@ -3845,7 +3890,7 @@ static int slab_unmergeable(struct kmem_cache *s)
73899 /*
73900 * We may have set a slab to be unmergeable during bootstrap.
73901 */
73902- if (s->refcount < 0)
73903+ if (atomic_read(&s->refcount) < 0)
73904 return 1;
73905
73906 return 0;
73907@@ -3904,7 +3949,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73908 down_write(&slub_lock);
73909 s = find_mergeable(size, align, flags, name, ctor);
73910 if (s) {
73911- s->refcount++;
73912+ atomic_inc(&s->refcount);
73913 /*
73914 * Adjust the object sizes so that we clear
73915 * the complete object on kzalloc.
73916@@ -3913,7 +3958,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73917 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
73918
73919 if (sysfs_slab_alias(s, name)) {
73920- s->refcount--;
73921+ atomic_dec(&s->refcount);
73922 goto err;
73923 }
73924 up_write(&slub_lock);
73925@@ -4042,7 +4087,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
73926 }
73927 #endif
73928
73929-#ifdef CONFIG_SYSFS
73930+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73931 static int count_inuse(struct page *page)
73932 {
73933 return page->inuse;
73934@@ -4429,12 +4474,12 @@ static void resiliency_test(void)
73935 validate_slab_cache(kmalloc_caches[9]);
73936 }
73937 #else
73938-#ifdef CONFIG_SYSFS
73939+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73940 static void resiliency_test(void) {};
73941 #endif
73942 #endif
73943
73944-#ifdef CONFIG_SYSFS
73945+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73946 enum slab_stat_type {
73947 SL_ALL, /* All slabs */
73948 SL_PARTIAL, /* Only partially allocated slabs */
73949@@ -4677,7 +4722,7 @@ SLAB_ATTR_RO(ctor);
73950
73951 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
73952 {
73953- return sprintf(buf, "%d\n", s->refcount - 1);
73954+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
73955 }
73956 SLAB_ATTR_RO(aliases);
73957
73958@@ -5244,6 +5289,7 @@ static char *create_unique_id(struct kmem_cache *s)
73959 return name;
73960 }
73961
73962+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73963 static int sysfs_slab_add(struct kmem_cache *s)
73964 {
73965 int err;
73966@@ -5306,6 +5352,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
73967 kobject_del(&s->kobj);
73968 kobject_put(&s->kobj);
73969 }
73970+#endif
73971
73972 /*
73973 * Need to buffer aliases during bootup until sysfs becomes
73974@@ -5319,6 +5366,7 @@ struct saved_alias {
73975
73976 static struct saved_alias *alias_list;
73977
73978+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73979 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
73980 {
73981 struct saved_alias *al;
73982@@ -5341,6 +5389,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
73983 alias_list = al;
73984 return 0;
73985 }
73986+#endif
73987
73988 static int __init slab_sysfs_init(void)
73989 {
73990diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
73991index 1b7e22a..3fcd4f3 100644
73992--- a/mm/sparse-vmemmap.c
73993+++ b/mm/sparse-vmemmap.c
73994@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
73995 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
73996 if (!p)
73997 return NULL;
73998- pud_populate(&init_mm, pud, p);
73999+ pud_populate_kernel(&init_mm, pud, p);
74000 }
74001 return pud;
74002 }
74003@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
74004 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74005 if (!p)
74006 return NULL;
74007- pgd_populate(&init_mm, pgd, p);
74008+ pgd_populate_kernel(&init_mm, pgd, p);
74009 }
74010 return pgd;
74011 }
74012diff --git a/mm/swap.c b/mm/swap.c
74013index 14380e9..e244704 100644
74014--- a/mm/swap.c
74015+++ b/mm/swap.c
74016@@ -30,6 +30,7 @@
74017 #include <linux/backing-dev.h>
74018 #include <linux/memcontrol.h>
74019 #include <linux/gfp.h>
74020+#include <linux/hugetlb.h>
74021
74022 #include "internal.h"
74023
74024@@ -70,6 +71,8 @@ static void __put_compound_page(struct page *page)
74025
74026 __page_cache_release(page);
74027 dtor = get_compound_page_dtor(page);
74028+ if (!PageHuge(page))
74029+ BUG_ON(dtor != free_compound_page);
74030 (*dtor)(page);
74031 }
74032
74033diff --git a/mm/swapfile.c b/mm/swapfile.c
74034index f31b29d..8bdcae2 100644
74035--- a/mm/swapfile.c
74036+++ b/mm/swapfile.c
74037@@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
74038
74039 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74040 /* Activity counter to indicate that a swapon or swapoff has occurred */
74041-static atomic_t proc_poll_event = ATOMIC_INIT(0);
74042+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74043
74044 static inline unsigned char swap_count(unsigned char ent)
74045 {
74046@@ -1669,7 +1669,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
74047 }
74048 filp_close(swap_file, NULL);
74049 err = 0;
74050- atomic_inc(&proc_poll_event);
74051+ atomic_inc_unchecked(&proc_poll_event);
74052 wake_up_interruptible(&proc_poll_wait);
74053
74054 out_dput:
74055@@ -1685,8 +1685,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74056
74057 poll_wait(file, &proc_poll_wait, wait);
74058
74059- if (seq->poll_event != atomic_read(&proc_poll_event)) {
74060- seq->poll_event = atomic_read(&proc_poll_event);
74061+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74062+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74063 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74064 }
74065
74066@@ -1784,7 +1784,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74067 return ret;
74068
74069 seq = file->private_data;
74070- seq->poll_event = atomic_read(&proc_poll_event);
74071+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74072 return 0;
74073 }
74074
74075@@ -2122,7 +2122,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74076 (p->flags & SWP_DISCARDABLE) ? "D" : "");
74077
74078 mutex_unlock(&swapon_mutex);
74079- atomic_inc(&proc_poll_event);
74080+ atomic_inc_unchecked(&proc_poll_event);
74081 wake_up_interruptible(&proc_poll_wait);
74082
74083 if (S_ISREG(inode->i_mode))
74084diff --git a/mm/util.c b/mm/util.c
74085index 136ac4f..f917fa9 100644
74086--- a/mm/util.c
74087+++ b/mm/util.c
74088@@ -243,6 +243,12 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
74089 void arch_pick_mmap_layout(struct mm_struct *mm)
74090 {
74091 mm->mmap_base = TASK_UNMAPPED_BASE;
74092+
74093+#ifdef CONFIG_PAX_RANDMMAP
74094+ if (mm->pax_flags & MF_PAX_RANDMMAP)
74095+ mm->mmap_base += mm->delta_mmap;
74096+#endif
74097+
74098 mm->get_unmapped_area = arch_get_unmapped_area;
74099 mm->unmap_area = arch_unmap_area;
74100 }
74101diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74102index 86ce9a5..550d03c 100644
74103--- a/mm/vmalloc.c
74104+++ b/mm/vmalloc.c
74105@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74106
74107 pte = pte_offset_kernel(pmd, addr);
74108 do {
74109- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74110- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74111+
74112+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74113+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74114+ BUG_ON(!pte_exec(*pte));
74115+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74116+ continue;
74117+ }
74118+#endif
74119+
74120+ {
74121+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74122+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74123+ }
74124 } while (pte++, addr += PAGE_SIZE, addr != end);
74125 }
74126
74127@@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74128 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
74129 {
74130 pte_t *pte;
74131+ int ret = -ENOMEM;
74132
74133 /*
74134 * nr is a running index into the array which helps higher level
74135@@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74136 pte = pte_alloc_kernel(pmd, addr);
74137 if (!pte)
74138 return -ENOMEM;
74139+
74140+ pax_open_kernel();
74141 do {
74142 struct page *page = pages[*nr];
74143
74144- if (WARN_ON(!pte_none(*pte)))
74145- return -EBUSY;
74146- if (WARN_ON(!page))
74147- return -ENOMEM;
74148+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74149+ if (pgprot_val(prot) & _PAGE_NX)
74150+#endif
74151+
74152+ if (WARN_ON(!pte_none(*pte))) {
74153+ ret = -EBUSY;
74154+ goto out;
74155+ }
74156+ if (WARN_ON(!page)) {
74157+ ret = -ENOMEM;
74158+ goto out;
74159+ }
74160 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
74161 (*nr)++;
74162 } while (pte++, addr += PAGE_SIZE, addr != end);
74163- return 0;
74164+ ret = 0;
74165+out:
74166+ pax_close_kernel();
74167+ return ret;
74168 }
74169
74170 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74171@@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74172 pmd_t *pmd;
74173 unsigned long next;
74174
74175- pmd = pmd_alloc(&init_mm, pud, addr);
74176+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
74177 if (!pmd)
74178 return -ENOMEM;
74179 do {
74180@@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
74181 pud_t *pud;
74182 unsigned long next;
74183
74184- pud = pud_alloc(&init_mm, pgd, addr);
74185+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
74186 if (!pud)
74187 return -ENOMEM;
74188 do {
74189@@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
74190 * and fall back on vmalloc() if that fails. Others
74191 * just put it in the vmalloc space.
74192 */
74193-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
74194+#ifdef CONFIG_MODULES
74195+#ifdef MODULES_VADDR
74196 unsigned long addr = (unsigned long)x;
74197 if (addr >= MODULES_VADDR && addr < MODULES_END)
74198 return 1;
74199 #endif
74200+
74201+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74202+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
74203+ return 1;
74204+#endif
74205+
74206+#endif
74207+
74208 return is_vmalloc_addr(x);
74209 }
74210
74211@@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
74212
74213 if (!pgd_none(*pgd)) {
74214 pud_t *pud = pud_offset(pgd, addr);
74215+#ifdef CONFIG_X86
74216+ if (!pud_large(*pud))
74217+#endif
74218 if (!pud_none(*pud)) {
74219 pmd_t *pmd = pmd_offset(pud, addr);
74220+#ifdef CONFIG_X86
74221+ if (!pmd_large(*pmd))
74222+#endif
74223 if (!pmd_none(*pmd)) {
74224 pte_t *ptep, pte;
74225
74226@@ -332,6 +372,10 @@ static void purge_vmap_area_lazy(void);
74227 static struct vmap_area *alloc_vmap_area(unsigned long size,
74228 unsigned long align,
74229 unsigned long vstart, unsigned long vend,
74230+ int node, gfp_t gfp_mask) __size_overflow(1);
74231+static struct vmap_area *alloc_vmap_area(unsigned long size,
74232+ unsigned long align,
74233+ unsigned long vstart, unsigned long vend,
74234 int node, gfp_t gfp_mask)
74235 {
74236 struct vmap_area *va;
74237@@ -1319,6 +1363,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
74238 struct vm_struct *area;
74239
74240 BUG_ON(in_interrupt());
74241+
74242+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74243+ if (flags & VM_KERNEXEC) {
74244+ if (start != VMALLOC_START || end != VMALLOC_END)
74245+ return NULL;
74246+ start = (unsigned long)MODULES_EXEC_VADDR;
74247+ end = (unsigned long)MODULES_EXEC_END;
74248+ }
74249+#endif
74250+
74251 if (flags & VM_IOREMAP) {
74252 int bit = fls(size);
74253
74254@@ -1551,6 +1605,11 @@ void *vmap(struct page **pages, unsigned int count,
74255 if (count > totalram_pages)
74256 return NULL;
74257
74258+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74259+ if (!(pgprot_val(prot) & _PAGE_NX))
74260+ flags |= VM_KERNEXEC;
74261+#endif
74262+
74263 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
74264 __builtin_return_address(0));
74265 if (!area)
74266@@ -1652,6 +1711,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
74267 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
74268 goto fail;
74269
74270+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74271+ if (!(pgprot_val(prot) & _PAGE_NX))
74272+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
74273+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
74274+ else
74275+#endif
74276+
74277 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
74278 start, end, node, gfp_mask, caller);
74279 if (!area)
74280@@ -1825,10 +1891,9 @@ EXPORT_SYMBOL(vzalloc_node);
74281 * For tight control over page level allocator and protection flags
74282 * use __vmalloc() instead.
74283 */
74284-
74285 void *vmalloc_exec(unsigned long size)
74286 {
74287- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
74288+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
74289 -1, __builtin_return_address(0));
74290 }
74291
74292@@ -2123,6 +2188,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
74293 unsigned long uaddr = vma->vm_start;
74294 unsigned long usize = vma->vm_end - vma->vm_start;
74295
74296+ BUG_ON(vma->vm_mirror);
74297+
74298 if ((PAGE_SIZE-1) & (unsigned long)addr)
74299 return -EINVAL;
74300
74301@@ -2375,8 +2442,8 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
74302 return NULL;
74303 }
74304
74305- vms = kzalloc(sizeof(vms[0]) * nr_vms, GFP_KERNEL);
74306- vas = kzalloc(sizeof(vas[0]) * nr_vms, GFP_KERNEL);
74307+ vms = kcalloc(nr_vms, sizeof(vms[0]), GFP_KERNEL);
74308+ vas = kcalloc(nr_vms, sizeof(vas[0]), GFP_KERNEL);
74309 if (!vas || !vms)
74310 goto err_free2;
74311
74312diff --git a/mm/vmstat.c b/mm/vmstat.c
74313index f600557..1459fc8 100644
74314--- a/mm/vmstat.c
74315+++ b/mm/vmstat.c
74316@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
74317 *
74318 * vm_stat contains the global counters
74319 */
74320-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74321+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74322 EXPORT_SYMBOL(vm_stat);
74323
74324 #ifdef CONFIG_SMP
74325@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
74326 v = p->vm_stat_diff[i];
74327 p->vm_stat_diff[i] = 0;
74328 local_irq_restore(flags);
74329- atomic_long_add(v, &zone->vm_stat[i]);
74330+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
74331 global_diff[i] += v;
74332 #ifdef CONFIG_NUMA
74333 /* 3 seconds idle till flush */
74334@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
74335
74336 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
74337 if (global_diff[i])
74338- atomic_long_add(global_diff[i], &vm_stat[i]);
74339+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
74340 }
74341
74342 #endif
74343@@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
74344 start_cpu_timer(cpu);
74345 #endif
74346 #ifdef CONFIG_PROC_FS
74347- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
74348- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
74349- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
74350- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
74351+ {
74352+ mode_t gr_mode = S_IRUGO;
74353+#ifdef CONFIG_GRKERNSEC_PROC_ADD
74354+ gr_mode = S_IRUSR;
74355+#endif
74356+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
74357+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
74358+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74359+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
74360+#else
74361+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
74362+#endif
74363+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
74364+ }
74365 #endif
74366 return 0;
74367 }
74368diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
74369index efea35b..9c8dd0b 100644
74370--- a/net/8021q/vlan.c
74371+++ b/net/8021q/vlan.c
74372@@ -554,8 +554,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
74373 err = -EPERM;
74374 if (!capable(CAP_NET_ADMIN))
74375 break;
74376- if ((args.u.name_type >= 0) &&
74377- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
74378+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
74379 struct vlan_net *vn;
74380
74381 vn = net_generic(net, vlan_net_id);
74382diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
74383index fccae26..e7ece2f 100644
74384--- a/net/9p/trans_fd.c
74385+++ b/net/9p/trans_fd.c
74386@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
74387 oldfs = get_fs();
74388 set_fs(get_ds());
74389 /* The cast to a user pointer is valid due to the set_fs() */
74390- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
74391+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
74392 set_fs(oldfs);
74393
74394 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
74395diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
74396index 876fbe8..8bbea9f 100644
74397--- a/net/atm/atm_misc.c
74398+++ b/net/atm/atm_misc.c
74399@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
74400 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
74401 return 1;
74402 atm_return(vcc, truesize);
74403- atomic_inc(&vcc->stats->rx_drop);
74404+ atomic_inc_unchecked(&vcc->stats->rx_drop);
74405 return 0;
74406 }
74407 EXPORT_SYMBOL(atm_charge);
74408@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
74409 }
74410 }
74411 atm_return(vcc, guess);
74412- atomic_inc(&vcc->stats->rx_drop);
74413+ atomic_inc_unchecked(&vcc->stats->rx_drop);
74414 return NULL;
74415 }
74416 EXPORT_SYMBOL(atm_alloc_charge);
74417@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
74418
74419 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74420 {
74421-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74422+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74423 __SONET_ITEMS
74424 #undef __HANDLE_ITEM
74425 }
74426@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
74427
74428 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74429 {
74430-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74431+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
74432 __SONET_ITEMS
74433 #undef __HANDLE_ITEM
74434 }
74435diff --git a/net/atm/lec.h b/net/atm/lec.h
74436index dfc0719..47c5322 100644
74437--- a/net/atm/lec.h
74438+++ b/net/atm/lec.h
74439@@ -48,7 +48,7 @@ struct lane2_ops {
74440 const u8 *tlvs, u32 sizeoftlvs);
74441 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
74442 const u8 *tlvs, u32 sizeoftlvs);
74443-};
74444+} __no_const;
74445
74446 /*
74447 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
74448diff --git a/net/atm/mpc.h b/net/atm/mpc.h
74449index 0919a88..a23d54e 100644
74450--- a/net/atm/mpc.h
74451+++ b/net/atm/mpc.h
74452@@ -33,7 +33,7 @@ struct mpoa_client {
74453 struct mpc_parameters parameters; /* parameters for this client */
74454
74455 const struct net_device_ops *old_ops;
74456- struct net_device_ops new_ops;
74457+ net_device_ops_no_const new_ops;
74458 };
74459
74460
74461diff --git a/net/atm/proc.c b/net/atm/proc.c
74462index 0d020de..011c7bb 100644
74463--- a/net/atm/proc.c
74464+++ b/net/atm/proc.c
74465@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
74466 const struct k_atm_aal_stats *stats)
74467 {
74468 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
74469- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
74470- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
74471- atomic_read(&stats->rx_drop));
74472+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
74473+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
74474+ atomic_read_unchecked(&stats->rx_drop));
74475 }
74476
74477 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
74478diff --git a/net/atm/resources.c b/net/atm/resources.c
74479index 23f45ce..c748f1a 100644
74480--- a/net/atm/resources.c
74481+++ b/net/atm/resources.c
74482@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
74483 static void copy_aal_stats(struct k_atm_aal_stats *from,
74484 struct atm_aal_stats *to)
74485 {
74486-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74487+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74488 __AAL_STAT_ITEMS
74489 #undef __HANDLE_ITEM
74490 }
74491@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
74492 static void subtract_aal_stats(struct k_atm_aal_stats *from,
74493 struct atm_aal_stats *to)
74494 {
74495-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74496+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
74497 __AAL_STAT_ITEMS
74498 #undef __HANDLE_ITEM
74499 }
74500diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
74501index 3512e25..2b33401 100644
74502--- a/net/batman-adv/bat_iv_ogm.c
74503+++ b/net/batman-adv/bat_iv_ogm.c
74504@@ -541,7 +541,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
74505
74506 /* change sequence number to network order */
74507 batman_ogm_packet->seqno =
74508- htonl((uint32_t)atomic_read(&hard_iface->seqno));
74509+ htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
74510
74511 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
74512 batman_ogm_packet->tt_crc = htons((uint16_t)
74513@@ -561,7 +561,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
74514 else
74515 batman_ogm_packet->gw_flags = NO_FLAGS;
74516
74517- atomic_inc(&hard_iface->seqno);
74518+ atomic_inc_unchecked(&hard_iface->seqno);
74519
74520 slide_own_bcast_window(hard_iface);
74521 bat_ogm_queue_add(bat_priv, hard_iface->packet_buff,
74522@@ -922,7 +922,7 @@ static void bat_ogm_process(const struct ethhdr *ethhdr,
74523 return;
74524
74525 /* could be changed by schedule_own_packet() */
74526- if_incoming_seqno = atomic_read(&if_incoming->seqno);
74527+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
74528
74529 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
74530
74531diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
74532index 7704df4..beb4e16 100644
74533--- a/net/batman-adv/hard-interface.c
74534+++ b/net/batman-adv/hard-interface.c
74535@@ -326,8 +326,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
74536 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
74537 dev_add_pack(&hard_iface->batman_adv_ptype);
74538
74539- atomic_set(&hard_iface->seqno, 1);
74540- atomic_set(&hard_iface->frag_seqno, 1);
74541+ atomic_set_unchecked(&hard_iface->seqno, 1);
74542+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
74543 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
74544 hard_iface->net_dev->name);
74545
74546diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
74547index 987c75a..20d6f36 100644
74548--- a/net/batman-adv/soft-interface.c
74549+++ b/net/batman-adv/soft-interface.c
74550@@ -645,7 +645,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
74551
74552 /* set broadcast sequence number */
74553 bcast_packet->seqno =
74554- htonl(atomic_inc_return(&bat_priv->bcast_seqno));
74555+ htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
74556
74557 add_bcast_packet_to_list(bat_priv, skb, 1);
74558
74559@@ -843,7 +843,7 @@ struct net_device *softif_create(const char *name)
74560 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
74561
74562 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
74563- atomic_set(&bat_priv->bcast_seqno, 1);
74564+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
74565 atomic_set(&bat_priv->ttvn, 0);
74566 atomic_set(&bat_priv->tt_local_changes, 0);
74567 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
74568diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
74569index e9eb043..d174eeb 100644
74570--- a/net/batman-adv/types.h
74571+++ b/net/batman-adv/types.h
74572@@ -38,8 +38,8 @@ struct hard_iface {
74573 int16_t if_num;
74574 char if_status;
74575 struct net_device *net_dev;
74576- atomic_t seqno;
74577- atomic_t frag_seqno;
74578+ atomic_unchecked_t seqno;
74579+ atomic_unchecked_t frag_seqno;
74580 unsigned char *packet_buff;
74581 int packet_len;
74582 struct kobject *hardif_obj;
74583@@ -154,7 +154,7 @@ struct bat_priv {
74584 atomic_t orig_interval; /* uint */
74585 atomic_t hop_penalty; /* uint */
74586 atomic_t log_level; /* uint */
74587- atomic_t bcast_seqno;
74588+ atomic_unchecked_t bcast_seqno;
74589 atomic_t bcast_queue_left;
74590 atomic_t batman_queue_left;
74591 atomic_t ttvn; /* translation table version number */
74592diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
74593index 07d1c1d..7e9bea9 100644
74594--- a/net/batman-adv/unicast.c
74595+++ b/net/batman-adv/unicast.c
74596@@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
74597 frag1->flags = UNI_FRAG_HEAD | large_tail;
74598 frag2->flags = large_tail;
74599
74600- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
74601+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
74602 frag1->seqno = htons(seqno - 1);
74603 frag2->seqno = htons(seqno);
74604
74605diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
74606index 280953b..cd219bb 100644
74607--- a/net/bluetooth/hci_conn.c
74608+++ b/net/bluetooth/hci_conn.c
74609@@ -234,7 +234,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
74610 memset(&cp, 0, sizeof(cp));
74611
74612 cp.handle = cpu_to_le16(conn->handle);
74613- memcpy(cp.ltk, ltk, sizeof(ltk));
74614+ memcpy(cp.ltk, ltk, sizeof(cp.ltk));
74615
74616 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
74617 }
74618diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
74619index 32d338c..d24bcdb 100644
74620--- a/net/bluetooth/l2cap_core.c
74621+++ b/net/bluetooth/l2cap_core.c
74622@@ -2418,8 +2418,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
74623 break;
74624
74625 case L2CAP_CONF_RFC:
74626- if (olen == sizeof(rfc))
74627- memcpy(&rfc, (void *)val, olen);
74628+ if (olen != sizeof(rfc))
74629+ break;
74630+
74631+ memcpy(&rfc, (void *)val, olen);
74632
74633 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
74634 rfc.mode != chan->mode)
74635@@ -2537,8 +2539,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
74636
74637 switch (type) {
74638 case L2CAP_CONF_RFC:
74639- if (olen == sizeof(rfc))
74640- memcpy(&rfc, (void *)val, olen);
74641+ if (olen != sizeof(rfc))
74642+ break;
74643+
74644+ memcpy(&rfc, (void *)val, olen);
74645 goto done;
74646 }
74647 }
74648diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
74649index 5fe2ff3..10968b5 100644
74650--- a/net/bridge/netfilter/ebtables.c
74651+++ b/net/bridge/netfilter/ebtables.c
74652@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
74653 tmp.valid_hooks = t->table->valid_hooks;
74654 }
74655 mutex_unlock(&ebt_mutex);
74656- if (copy_to_user(user, &tmp, *len) != 0){
74657+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
74658 BUGPRINT("c2u Didn't work\n");
74659 ret = -EFAULT;
74660 break;
74661diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
74662index a97d97a..6f679ed 100644
74663--- a/net/caif/caif_socket.c
74664+++ b/net/caif/caif_socket.c
74665@@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
74666 #ifdef CONFIG_DEBUG_FS
74667 struct debug_fs_counter {
74668 atomic_t caif_nr_socks;
74669- atomic_t caif_sock_create;
74670- atomic_t num_connect_req;
74671- atomic_t num_connect_resp;
74672- atomic_t num_connect_fail_resp;
74673- atomic_t num_disconnect;
74674- atomic_t num_remote_shutdown_ind;
74675- atomic_t num_tx_flow_off_ind;
74676- atomic_t num_tx_flow_on_ind;
74677- atomic_t num_rx_flow_off;
74678- atomic_t num_rx_flow_on;
74679+ atomic_unchecked_t caif_sock_create;
74680+ atomic_unchecked_t num_connect_req;
74681+ atomic_unchecked_t num_connect_resp;
74682+ atomic_unchecked_t num_connect_fail_resp;
74683+ atomic_unchecked_t num_disconnect;
74684+ atomic_unchecked_t num_remote_shutdown_ind;
74685+ atomic_unchecked_t num_tx_flow_off_ind;
74686+ atomic_unchecked_t num_tx_flow_on_ind;
74687+ atomic_unchecked_t num_rx_flow_off;
74688+ atomic_unchecked_t num_rx_flow_on;
74689 };
74690 static struct debug_fs_counter cnt;
74691 #define dbfs_atomic_inc(v) atomic_inc_return(v)
74692+#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
74693 #define dbfs_atomic_dec(v) atomic_dec_return(v)
74694 #else
74695 #define dbfs_atomic_inc(v) 0
74696@@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74697 atomic_read(&cf_sk->sk.sk_rmem_alloc),
74698 sk_rcvbuf_lowwater(cf_sk));
74699 set_rx_flow_off(cf_sk);
74700- dbfs_atomic_inc(&cnt.num_rx_flow_off);
74701+ dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
74702 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
74703 }
74704
74705@@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74706 set_rx_flow_off(cf_sk);
74707 if (net_ratelimit())
74708 pr_debug("sending flow OFF due to rmem_schedule\n");
74709- dbfs_atomic_inc(&cnt.num_rx_flow_off);
74710+ dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
74711 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
74712 }
74713 skb->dev = NULL;
74714@@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer *layr,
74715 switch (flow) {
74716 case CAIF_CTRLCMD_FLOW_ON_IND:
74717 /* OK from modem to start sending again */
74718- dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
74719+ dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
74720 set_tx_flow_on(cf_sk);
74721 cf_sk->sk.sk_state_change(&cf_sk->sk);
74722 break;
74723
74724 case CAIF_CTRLCMD_FLOW_OFF_IND:
74725 /* Modem asks us to shut up */
74726- dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
74727+ dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
74728 set_tx_flow_off(cf_sk);
74729 cf_sk->sk.sk_state_change(&cf_sk->sk);
74730 break;
74731@@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74732 /* We're now connected */
74733 caif_client_register_refcnt(&cf_sk->layer,
74734 cfsk_hold, cfsk_put);
74735- dbfs_atomic_inc(&cnt.num_connect_resp);
74736+ dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
74737 cf_sk->sk.sk_state = CAIF_CONNECTED;
74738 set_tx_flow_on(cf_sk);
74739 cf_sk->sk.sk_state_change(&cf_sk->sk);
74740@@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74741
74742 case CAIF_CTRLCMD_INIT_FAIL_RSP:
74743 /* Connect request failed */
74744- dbfs_atomic_inc(&cnt.num_connect_fail_resp);
74745+ dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
74746 cf_sk->sk.sk_err = ECONNREFUSED;
74747 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
74748 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
74749@@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74750
74751 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
74752 /* Modem has closed this connection, or device is down. */
74753- dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
74754+ dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
74755 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
74756 cf_sk->sk.sk_err = ECONNRESET;
74757 set_rx_flow_on(cf_sk);
74758@@ -297,7 +298,7 @@ static void caif_check_flow_release(struct sock *sk)
74759 return;
74760
74761 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
74762- dbfs_atomic_inc(&cnt.num_rx_flow_on);
74763+ dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
74764 set_rx_flow_on(cf_sk);
74765 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
74766 }
74767@@ -856,7 +857,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
74768 /*ifindex = id of the interface.*/
74769 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
74770
74771- dbfs_atomic_inc(&cnt.num_connect_req);
74772+ dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
74773 cf_sk->layer.receive = caif_sktrecv_cb;
74774
74775 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
74776@@ -945,7 +946,7 @@ static int caif_release(struct socket *sock)
74777 spin_unlock_bh(&sk->sk_receive_queue.lock);
74778 sock->sk = NULL;
74779
74780- dbfs_atomic_inc(&cnt.num_disconnect);
74781+ dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
74782
74783 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
74784 if (cf_sk->debugfs_socket_dir != NULL)
74785@@ -1124,7 +1125,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
74786 cf_sk->conn_req.protocol = protocol;
74787 /* Increase the number of sockets created. */
74788 dbfs_atomic_inc(&cnt.caif_nr_socks);
74789- num = dbfs_atomic_inc(&cnt.caif_sock_create);
74790+ num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
74791 #ifdef CONFIG_DEBUG_FS
74792 if (!IS_ERR(debugfsdir)) {
74793
74794diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
74795index 5cf5222..6f704ad 100644
74796--- a/net/caif/cfctrl.c
74797+++ b/net/caif/cfctrl.c
74798@@ -9,6 +9,7 @@
74799 #include <linux/stddef.h>
74800 #include <linux/spinlock.h>
74801 #include <linux/slab.h>
74802+#include <linux/sched.h>
74803 #include <net/caif/caif_layer.h>
74804 #include <net/caif/cfpkt.h>
74805 #include <net/caif/cfctrl.h>
74806@@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
74807 memset(&dev_info, 0, sizeof(dev_info));
74808 dev_info.id = 0xff;
74809 cfsrvl_init(&this->serv, 0, &dev_info, false);
74810- atomic_set(&this->req_seq_no, 1);
74811- atomic_set(&this->rsp_seq_no, 1);
74812+ atomic_set_unchecked(&this->req_seq_no, 1);
74813+ atomic_set_unchecked(&this->rsp_seq_no, 1);
74814 this->serv.layer.receive = cfctrl_recv;
74815 sprintf(this->serv.layer.name, "ctrl");
74816 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
74817@@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
74818 struct cfctrl_request_info *req)
74819 {
74820 spin_lock_bh(&ctrl->info_list_lock);
74821- atomic_inc(&ctrl->req_seq_no);
74822- req->sequence_no = atomic_read(&ctrl->req_seq_no);
74823+ atomic_inc_unchecked(&ctrl->req_seq_no);
74824+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
74825 list_add_tail(&req->list, &ctrl->list);
74826 spin_unlock_bh(&ctrl->info_list_lock);
74827 }
74828@@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
74829 if (p != first)
74830 pr_warn("Requests are not received in order\n");
74831
74832- atomic_set(&ctrl->rsp_seq_no,
74833+ atomic_set_unchecked(&ctrl->rsp_seq_no,
74834 p->sequence_no);
74835 list_del(&p->list);
74836 goto out;
74837diff --git a/net/can/gw.c b/net/can/gw.c
74838index 3d79b12..8de85fa 100644
74839--- a/net/can/gw.c
74840+++ b/net/can/gw.c
74841@@ -96,7 +96,7 @@ struct cf_mod {
74842 struct {
74843 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
74844 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
74845- } csumfunc;
74846+ } __no_const csumfunc;
74847 };
74848
74849
74850diff --git a/net/compat.c b/net/compat.c
74851index 6def90e..c6992fa 100644
74852--- a/net/compat.c
74853+++ b/net/compat.c
74854@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
74855 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
74856 __get_user(kmsg->msg_flags, &umsg->msg_flags))
74857 return -EFAULT;
74858- kmsg->msg_name = compat_ptr(tmp1);
74859- kmsg->msg_iov = compat_ptr(tmp2);
74860- kmsg->msg_control = compat_ptr(tmp3);
74861+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
74862+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
74863+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
74864 return 0;
74865 }
74866
74867@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74868
74869 if (kern_msg->msg_namelen) {
74870 if (mode == VERIFY_READ) {
74871- int err = move_addr_to_kernel(kern_msg->msg_name,
74872+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
74873 kern_msg->msg_namelen,
74874 kern_address);
74875 if (err < 0)
74876@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74877 kern_msg->msg_name = NULL;
74878
74879 tot_len = iov_from_user_compat_to_kern(kern_iov,
74880- (struct compat_iovec __user *)kern_msg->msg_iov,
74881+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
74882 kern_msg->msg_iovlen);
74883 if (tot_len >= 0)
74884 kern_msg->msg_iov = kern_iov;
74885@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74886
74887 #define CMSG_COMPAT_FIRSTHDR(msg) \
74888 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
74889- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
74890+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
74891 (struct compat_cmsghdr __user *)NULL)
74892
74893 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
74894 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
74895 (ucmlen) <= (unsigned long) \
74896 ((mhdr)->msg_controllen - \
74897- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
74898+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
74899
74900 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
74901 struct compat_cmsghdr __user *cmsg, int cmsg_len)
74902 {
74903 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
74904- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
74905+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
74906 msg->msg_controllen)
74907 return NULL;
74908 return (struct compat_cmsghdr __user *)ptr;
74909@@ -221,7 +221,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
74910 {
74911 struct compat_timeval ctv;
74912 struct compat_timespec cts[3];
74913- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74914+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74915 struct compat_cmsghdr cmhdr;
74916 int cmlen;
74917
74918@@ -273,7 +273,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
74919
74920 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
74921 {
74922- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74923+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74924 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
74925 int fdnum = scm->fp->count;
74926 struct file **fp = scm->fp->fp;
74927@@ -370,7 +370,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
74928 return -EFAULT;
74929 old_fs = get_fs();
74930 set_fs(KERNEL_DS);
74931- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
74932+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
74933 set_fs(old_fs);
74934
74935 return err;
74936@@ -431,7 +431,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
74937 len = sizeof(ktime);
74938 old_fs = get_fs();
74939 set_fs(KERNEL_DS);
74940- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
74941+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
74942 set_fs(old_fs);
74943
74944 if (!err) {
74945@@ -566,7 +566,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74946 case MCAST_JOIN_GROUP:
74947 case MCAST_LEAVE_GROUP:
74948 {
74949- struct compat_group_req __user *gr32 = (void *)optval;
74950+ struct compat_group_req __user *gr32 = (void __user *)optval;
74951 struct group_req __user *kgr =
74952 compat_alloc_user_space(sizeof(struct group_req));
74953 u32 interface;
74954@@ -587,7 +587,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74955 case MCAST_BLOCK_SOURCE:
74956 case MCAST_UNBLOCK_SOURCE:
74957 {
74958- struct compat_group_source_req __user *gsr32 = (void *)optval;
74959+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
74960 struct group_source_req __user *kgsr = compat_alloc_user_space(
74961 sizeof(struct group_source_req));
74962 u32 interface;
74963@@ -608,7 +608,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74964 }
74965 case MCAST_MSFILTER:
74966 {
74967- struct compat_group_filter __user *gf32 = (void *)optval;
74968+ struct compat_group_filter __user *gf32 = (void __user *)optval;
74969 struct group_filter __user *kgf;
74970 u32 interface, fmode, numsrc;
74971
74972@@ -646,7 +646,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
74973 char __user *optval, int __user *optlen,
74974 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
74975 {
74976- struct compat_group_filter __user *gf32 = (void *)optval;
74977+ struct compat_group_filter __user *gf32 = (void __user *)optval;
74978 struct group_filter __user *kgf;
74979 int __user *koptlen;
74980 u32 interface, fmode, numsrc;
74981diff --git a/net/core/datagram.c b/net/core/datagram.c
74982index 68bbf9f..5ef0d12 100644
74983--- a/net/core/datagram.c
74984+++ b/net/core/datagram.c
74985@@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
74986 }
74987
74988 kfree_skb(skb);
74989- atomic_inc(&sk->sk_drops);
74990+ atomic_inc_unchecked(&sk->sk_drops);
74991 sk_mem_reclaim_partial(sk);
74992
74993 return err;
74994diff --git a/net/core/dev.c b/net/core/dev.c
74995index 0336374..659088a 100644
74996--- a/net/core/dev.c
74997+++ b/net/core/dev.c
74998@@ -1138,10 +1138,14 @@ void dev_load(struct net *net, const char *name)
74999 if (no_module && capable(CAP_NET_ADMIN))
75000 no_module = request_module("netdev-%s", name);
75001 if (no_module && capable(CAP_SYS_MODULE)) {
75002+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75003+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
75004+#else
75005 if (!request_module("%s", name))
75006 pr_err("Loading kernel module for a network device "
75007 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
75008 "instead\n", name);
75009+#endif
75010 }
75011 }
75012 EXPORT_SYMBOL(dev_load);
75013@@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75014 {
75015 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
75016 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
75017- atomic_long_inc(&dev->rx_dropped);
75018+ atomic_long_inc_unchecked(&dev->rx_dropped);
75019 kfree_skb(skb);
75020 return NET_RX_DROP;
75021 }
75022@@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75023 nf_reset(skb);
75024
75025 if (unlikely(!is_skb_forwardable(dev, skb))) {
75026- atomic_long_inc(&dev->rx_dropped);
75027+ atomic_long_inc_unchecked(&dev->rx_dropped);
75028 kfree_skb(skb);
75029 return NET_RX_DROP;
75030 }
75031@@ -2077,7 +2081,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
75032
75033 struct dev_gso_cb {
75034 void (*destructor)(struct sk_buff *skb);
75035-};
75036+} __no_const;
75037
75038 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
75039
75040@@ -2933,7 +2937,7 @@ enqueue:
75041
75042 local_irq_restore(flags);
75043
75044- atomic_long_inc(&skb->dev->rx_dropped);
75045+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75046 kfree_skb(skb);
75047 return NET_RX_DROP;
75048 }
75049@@ -3005,7 +3009,7 @@ int netif_rx_ni(struct sk_buff *skb)
75050 }
75051 EXPORT_SYMBOL(netif_rx_ni);
75052
75053-static void net_tx_action(struct softirq_action *h)
75054+static void net_tx_action(void)
75055 {
75056 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75057
75058@@ -3293,7 +3297,7 @@ ncls:
75059 if (pt_prev) {
75060 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
75061 } else {
75062- atomic_long_inc(&skb->dev->rx_dropped);
75063+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75064 kfree_skb(skb);
75065 /* Jamal, now you will not able to escape explaining
75066 * me how you were going to use this. :-)
75067@@ -3853,7 +3857,7 @@ void netif_napi_del(struct napi_struct *napi)
75068 }
75069 EXPORT_SYMBOL(netif_napi_del);
75070
75071-static void net_rx_action(struct softirq_action *h)
75072+static void net_rx_action(void)
75073 {
75074 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75075 unsigned long time_limit = jiffies + 2;
75076@@ -5878,7 +5882,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
75077 } else {
75078 netdev_stats_to_stats64(storage, &dev->stats);
75079 }
75080- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
75081+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
75082 return storage;
75083 }
75084 EXPORT_SYMBOL(dev_get_stats);
75085diff --git a/net/core/flow.c b/net/core/flow.c
75086index e318c7e..168b1d0 100644
75087--- a/net/core/flow.c
75088+++ b/net/core/flow.c
75089@@ -61,7 +61,7 @@ struct flow_cache {
75090 struct timer_list rnd_timer;
75091 };
75092
75093-atomic_t flow_cache_genid = ATOMIC_INIT(0);
75094+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75095 EXPORT_SYMBOL(flow_cache_genid);
75096 static struct flow_cache flow_cache_global;
75097 static struct kmem_cache *flow_cachep __read_mostly;
75098@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75099
75100 static int flow_entry_valid(struct flow_cache_entry *fle)
75101 {
75102- if (atomic_read(&flow_cache_genid) != fle->genid)
75103+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75104 return 0;
75105 if (fle->object && !fle->object->ops->check(fle->object))
75106 return 0;
75107@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75108 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75109 fcp->hash_count++;
75110 }
75111- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75112+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75113 flo = fle->object;
75114 if (!flo)
75115 goto ret_object;
75116@@ -280,7 +280,7 @@ nocache:
75117 }
75118 flo = resolver(net, key, family, dir, flo, ctx);
75119 if (fle) {
75120- fle->genid = atomic_read(&flow_cache_genid);
75121+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
75122 if (!IS_ERR(flo))
75123 fle->object = flo;
75124 else
75125diff --git a/net/core/iovec.c b/net/core/iovec.c
75126index c40f27e..7f49254 100644
75127--- a/net/core/iovec.c
75128+++ b/net/core/iovec.c
75129@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75130 if (m->msg_namelen) {
75131 if (mode == VERIFY_READ) {
75132 void __user *namep;
75133- namep = (void __user __force *) m->msg_name;
75134+ namep = (void __force_user *) m->msg_name;
75135 err = move_addr_to_kernel(namep, m->msg_namelen,
75136 address);
75137 if (err < 0)
75138@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75139 }
75140
75141 size = m->msg_iovlen * sizeof(struct iovec);
75142- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
75143+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
75144 return -EFAULT;
75145
75146 m->msg_iov = iov;
75147diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
75148index 5c30296..ebe7b61 100644
75149--- a/net/core/rtnetlink.c
75150+++ b/net/core/rtnetlink.c
75151@@ -57,7 +57,7 @@ struct rtnl_link {
75152 rtnl_doit_func doit;
75153 rtnl_dumpit_func dumpit;
75154 rtnl_calcit_func calcit;
75155-};
75156+} __no_const;
75157
75158 static DEFINE_MUTEX(rtnl_mutex);
75159
75160diff --git a/net/core/scm.c b/net/core/scm.c
75161index ff52ad0..aff1c0f 100644
75162--- a/net/core/scm.c
75163+++ b/net/core/scm.c
75164@@ -220,7 +220,7 @@ EXPORT_SYMBOL(__scm_send);
75165 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75166 {
75167 struct cmsghdr __user *cm
75168- = (__force struct cmsghdr __user *)msg->msg_control;
75169+ = (struct cmsghdr __force_user *)msg->msg_control;
75170 struct cmsghdr cmhdr;
75171 int cmlen = CMSG_LEN(len);
75172 int err;
75173@@ -243,7 +243,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75174 err = -EFAULT;
75175 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
75176 goto out;
75177- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
75178+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
75179 goto out;
75180 cmlen = CMSG_SPACE(len);
75181 if (msg->msg_controllen < cmlen)
75182@@ -259,7 +259,7 @@ EXPORT_SYMBOL(put_cmsg);
75183 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75184 {
75185 struct cmsghdr __user *cm
75186- = (__force struct cmsghdr __user*)msg->msg_control;
75187+ = (struct cmsghdr __force_user *)msg->msg_control;
75188
75189 int fdmax = 0;
75190 int fdnum = scm->fp->count;
75191@@ -279,7 +279,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75192 if (fdnum < fdmax)
75193 fdmax = fdnum;
75194
75195- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
75196+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
75197 i++, cmfptr++)
75198 {
75199 int new_fd;
75200diff --git a/net/core/sock.c b/net/core/sock.c
75201index 02f8dfe..86dfd4a 100644
75202--- a/net/core/sock.c
75203+++ b/net/core/sock.c
75204@@ -341,7 +341,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75205 struct sk_buff_head *list = &sk->sk_receive_queue;
75206
75207 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
75208- atomic_inc(&sk->sk_drops);
75209+ atomic_inc_unchecked(&sk->sk_drops);
75210 trace_sock_rcvqueue_full(sk, skb);
75211 return -ENOMEM;
75212 }
75213@@ -351,7 +351,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75214 return err;
75215
75216 if (!sk_rmem_schedule(sk, skb->truesize)) {
75217- atomic_inc(&sk->sk_drops);
75218+ atomic_inc_unchecked(&sk->sk_drops);
75219 return -ENOBUFS;
75220 }
75221
75222@@ -371,7 +371,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75223 skb_dst_force(skb);
75224
75225 spin_lock_irqsave(&list->lock, flags);
75226- skb->dropcount = atomic_read(&sk->sk_drops);
75227+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75228 __skb_queue_tail(list, skb);
75229 spin_unlock_irqrestore(&list->lock, flags);
75230
75231@@ -391,7 +391,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75232 skb->dev = NULL;
75233
75234 if (sk_rcvqueues_full(sk, skb)) {
75235- atomic_inc(&sk->sk_drops);
75236+ atomic_inc_unchecked(&sk->sk_drops);
75237 goto discard_and_relse;
75238 }
75239 if (nested)
75240@@ -409,7 +409,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75241 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
75242 } else if (sk_add_backlog(sk, skb)) {
75243 bh_unlock_sock(sk);
75244- atomic_inc(&sk->sk_drops);
75245+ atomic_inc_unchecked(&sk->sk_drops);
75246 goto discard_and_relse;
75247 }
75248
75249@@ -974,7 +974,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75250 if (len > sizeof(peercred))
75251 len = sizeof(peercred);
75252 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
75253- if (copy_to_user(optval, &peercred, len))
75254+ if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
75255 return -EFAULT;
75256 goto lenout;
75257 }
75258@@ -987,7 +987,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75259 return -ENOTCONN;
75260 if (lv < len)
75261 return -EINVAL;
75262- if (copy_to_user(optval, address, len))
75263+ if (len > sizeof(address) || copy_to_user(optval, address, len))
75264 return -EFAULT;
75265 goto lenout;
75266 }
75267@@ -1024,7 +1024,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75268
75269 if (len > lv)
75270 len = lv;
75271- if (copy_to_user(optval, &v, len))
75272+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
75273 return -EFAULT;
75274 lenout:
75275 if (put_user(len, optlen))
75276@@ -2108,7 +2108,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
75277 */
75278 smp_wmb();
75279 atomic_set(&sk->sk_refcnt, 1);
75280- atomic_set(&sk->sk_drops, 0);
75281+ atomic_set_unchecked(&sk->sk_drops, 0);
75282 }
75283 EXPORT_SYMBOL(sock_init_data);
75284
75285diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
75286index b9868e1..849f809 100644
75287--- a/net/core/sock_diag.c
75288+++ b/net/core/sock_diag.c
75289@@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
75290
75291 int sock_diag_check_cookie(void *sk, __u32 *cookie)
75292 {
75293+#ifndef CONFIG_GRKERNSEC_HIDESYM
75294 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
75295 cookie[1] != INET_DIAG_NOCOOKIE) &&
75296 ((u32)(unsigned long)sk != cookie[0] ||
75297 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
75298 return -ESTALE;
75299 else
75300+#endif
75301 return 0;
75302 }
75303 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
75304
75305 void sock_diag_save_cookie(void *sk, __u32 *cookie)
75306 {
75307+#ifdef CONFIG_GRKERNSEC_HIDESYM
75308+ cookie[0] = 0;
75309+ cookie[1] = 0;
75310+#else
75311 cookie[0] = (u32)(unsigned long)sk;
75312 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
75313+#endif
75314 }
75315 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
75316
75317diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
75318index 02e75d1..9a57a7c 100644
75319--- a/net/decnet/sysctl_net_decnet.c
75320+++ b/net/decnet/sysctl_net_decnet.c
75321@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
75322
75323 if (len > *lenp) len = *lenp;
75324
75325- if (copy_to_user(buffer, addr, len))
75326+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
75327 return -EFAULT;
75328
75329 *lenp = len;
75330@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
75331
75332 if (len > *lenp) len = *lenp;
75333
75334- if (copy_to_user(buffer, devname, len))
75335+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
75336 return -EFAULT;
75337
75338 *lenp = len;
75339diff --git a/net/econet/Kconfig b/net/econet/Kconfig
75340index 39a2d29..f39c0fe 100644
75341--- a/net/econet/Kconfig
75342+++ b/net/econet/Kconfig
75343@@ -4,7 +4,7 @@
75344
75345 config ECONET
75346 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
75347- depends on EXPERIMENTAL && INET
75348+ depends on EXPERIMENTAL && INET && BROKEN
75349 ---help---
75350 Econet is a fairly old and slow networking protocol mainly used by
75351 Acorn computers to access file and print servers. It uses native
75352diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
75353index 92fc5f6..b790d91 100644
75354--- a/net/ipv4/fib_frontend.c
75355+++ b/net/ipv4/fib_frontend.c
75356@@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
75357 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75358 fib_sync_up(dev);
75359 #endif
75360- atomic_inc(&net->ipv4.dev_addr_genid);
75361+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75362 rt_cache_flush(dev_net(dev), -1);
75363 break;
75364 case NETDEV_DOWN:
75365 fib_del_ifaddr(ifa, NULL);
75366- atomic_inc(&net->ipv4.dev_addr_genid);
75367+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75368 if (ifa->ifa_dev->ifa_list == NULL) {
75369 /* Last address was deleted from this interface.
75370 * Disable IP.
75371@@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
75372 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75373 fib_sync_up(dev);
75374 #endif
75375- atomic_inc(&net->ipv4.dev_addr_genid);
75376+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75377 rt_cache_flush(dev_net(dev), -1);
75378 break;
75379 case NETDEV_DOWN:
75380diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
75381index 80106d8..232e898 100644
75382--- a/net/ipv4/fib_semantics.c
75383+++ b/net/ipv4/fib_semantics.c
75384@@ -699,7 +699,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
75385 nh->nh_saddr = inet_select_addr(nh->nh_dev,
75386 nh->nh_gw,
75387 nh->nh_parent->fib_scope);
75388- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
75389+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
75390
75391 return nh->nh_saddr;
75392 }
75393diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
75394index 984ec65..97ac518 100644
75395--- a/net/ipv4/inet_hashtables.c
75396+++ b/net/ipv4/inet_hashtables.c
75397@@ -18,12 +18,15 @@
75398 #include <linux/sched.h>
75399 #include <linux/slab.h>
75400 #include <linux/wait.h>
75401+#include <linux/security.h>
75402
75403 #include <net/inet_connection_sock.h>
75404 #include <net/inet_hashtables.h>
75405 #include <net/secure_seq.h>
75406 #include <net/ip.h>
75407
75408+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
75409+
75410 /*
75411 * Allocate and initialize a new local port bind bucket.
75412 * The bindhash mutex for snum's hash chain must be held here.
75413@@ -530,6 +533,8 @@ ok:
75414 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
75415 spin_unlock(&head->lock);
75416
75417+ gr_update_task_in_ip_table(current, inet_sk(sk));
75418+
75419 if (tw) {
75420 inet_twsk_deschedule(tw, death_row);
75421 while (twrefcnt) {
75422diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
75423index d4d61b6..b81aec8 100644
75424--- a/net/ipv4/inetpeer.c
75425+++ b/net/ipv4/inetpeer.c
75426@@ -487,8 +487,8 @@ relookup:
75427 if (p) {
75428 p->daddr = *daddr;
75429 atomic_set(&p->refcnt, 1);
75430- atomic_set(&p->rid, 0);
75431- atomic_set(&p->ip_id_count,
75432+ atomic_set_unchecked(&p->rid, 0);
75433+ atomic_set_unchecked(&p->ip_id_count,
75434 (daddr->family == AF_INET) ?
75435 secure_ip_id(daddr->addr.a4) :
75436 secure_ipv6_id(daddr->addr.a6));
75437diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
75438index 1f23a57..7180dfe 100644
75439--- a/net/ipv4/ip_fragment.c
75440+++ b/net/ipv4/ip_fragment.c
75441@@ -316,7 +316,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
75442 return 0;
75443
75444 start = qp->rid;
75445- end = atomic_inc_return(&peer->rid);
75446+ end = atomic_inc_return_unchecked(&peer->rid);
75447 qp->rid = end;
75448
75449 rc = qp->q.fragments && (end - start) > max;
75450diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
75451index 8aa87c1..35c3248 100644
75452--- a/net/ipv4/ip_sockglue.c
75453+++ b/net/ipv4/ip_sockglue.c
75454@@ -1112,7 +1112,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75455 len = min_t(unsigned int, len, opt->optlen);
75456 if (put_user(len, optlen))
75457 return -EFAULT;
75458- if (copy_to_user(optval, opt->__data, len))
75459+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
75460+ copy_to_user(optval, opt->__data, len))
75461 return -EFAULT;
75462 return 0;
75463 }
75464@@ -1240,7 +1241,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75465 if (sk->sk_type != SOCK_STREAM)
75466 return -ENOPROTOOPT;
75467
75468- msg.msg_control = optval;
75469+ msg.msg_control = (void __force_kernel *)optval;
75470 msg.msg_controllen = len;
75471 msg.msg_flags = flags;
75472
75473diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
75474index 6e412a6..6640538 100644
75475--- a/net/ipv4/ipconfig.c
75476+++ b/net/ipv4/ipconfig.c
75477@@ -318,7 +318,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
75478
75479 mm_segment_t oldfs = get_fs();
75480 set_fs(get_ds());
75481- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75482+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75483 set_fs(oldfs);
75484 return res;
75485 }
75486@@ -329,7 +329,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
75487
75488 mm_segment_t oldfs = get_fs();
75489 set_fs(get_ds());
75490- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75491+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75492 set_fs(oldfs);
75493 return res;
75494 }
75495@@ -340,7 +340,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
75496
75497 mm_segment_t oldfs = get_fs();
75498 set_fs(get_ds());
75499- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
75500+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
75501 set_fs(oldfs);
75502 return res;
75503 }
75504diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
75505index b072386..abdebcf 100644
75506--- a/net/ipv4/ping.c
75507+++ b/net/ipv4/ping.c
75508@@ -838,7 +838,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
75509 sk_rmem_alloc_get(sp),
75510 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75511 atomic_read(&sp->sk_refcnt), sp,
75512- atomic_read(&sp->sk_drops), len);
75513+ atomic_read_unchecked(&sp->sk_drops), len);
75514 }
75515
75516 static int ping_seq_show(struct seq_file *seq, void *v)
75517diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
75518index 3ccda5a..3c1e61d 100644
75519--- a/net/ipv4/raw.c
75520+++ b/net/ipv4/raw.c
75521@@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
75522 int raw_rcv(struct sock *sk, struct sk_buff *skb)
75523 {
75524 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
75525- atomic_inc(&sk->sk_drops);
75526+ atomic_inc_unchecked(&sk->sk_drops);
75527 kfree_skb(skb);
75528 return NET_RX_DROP;
75529 }
75530@@ -742,16 +742,20 @@ static int raw_init(struct sock *sk)
75531
75532 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
75533 {
75534+ struct icmp_filter filter;
75535+
75536 if (optlen > sizeof(struct icmp_filter))
75537 optlen = sizeof(struct icmp_filter);
75538- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
75539+ if (copy_from_user(&filter, optval, optlen))
75540 return -EFAULT;
75541+ raw_sk(sk)->filter = filter;
75542 return 0;
75543 }
75544
75545 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
75546 {
75547 int len, ret = -EFAULT;
75548+ struct icmp_filter filter;
75549
75550 if (get_user(len, optlen))
75551 goto out;
75552@@ -761,8 +765,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
75553 if (len > sizeof(struct icmp_filter))
75554 len = sizeof(struct icmp_filter);
75555 ret = -EFAULT;
75556- if (put_user(len, optlen) ||
75557- copy_to_user(optval, &raw_sk(sk)->filter, len))
75558+ filter = raw_sk(sk)->filter;
75559+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
75560 goto out;
75561 ret = 0;
75562 out: return ret;
75563@@ -990,7 +994,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
75564 sk_wmem_alloc_get(sp),
75565 sk_rmem_alloc_get(sp),
75566 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75567- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
75568+ atomic_read(&sp->sk_refcnt),
75569+#ifdef CONFIG_GRKERNSEC_HIDESYM
75570+ NULL,
75571+#else
75572+ sp,
75573+#endif
75574+ atomic_read_unchecked(&sp->sk_drops));
75575 }
75576
75577 static int raw_seq_show(struct seq_file *seq, void *v)
75578diff --git a/net/ipv4/route.c b/net/ipv4/route.c
75579index 0197747..7adb0dc 100644
75580--- a/net/ipv4/route.c
75581+++ b/net/ipv4/route.c
75582@@ -311,7 +311,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
75583
75584 static inline int rt_genid(struct net *net)
75585 {
75586- return atomic_read(&net->ipv4.rt_genid);
75587+ return atomic_read_unchecked(&net->ipv4.rt_genid);
75588 }
75589
75590 #ifdef CONFIG_PROC_FS
75591@@ -935,7 +935,7 @@ static void rt_cache_invalidate(struct net *net)
75592 unsigned char shuffle;
75593
75594 get_random_bytes(&shuffle, sizeof(shuffle));
75595- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
75596+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
75597 inetpeer_invalidate_tree(AF_INET);
75598 }
75599
75600@@ -3010,7 +3010,7 @@ static int rt_fill_info(struct net *net,
75601 error = rt->dst.error;
75602 if (peer) {
75603 inet_peer_refcheck(rt->peer);
75604- id = atomic_read(&peer->ip_id_count) & 0xffff;
75605+ id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
75606 if (peer->tcp_ts_stamp) {
75607 ts = peer->tcp_ts;
75608 tsage = get_seconds() - peer->tcp_ts_stamp;
75609diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
75610index fd54c5f..96d6407 100644
75611--- a/net/ipv4/tcp_ipv4.c
75612+++ b/net/ipv4/tcp_ipv4.c
75613@@ -88,6 +88,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
75614 int sysctl_tcp_low_latency __read_mostly;
75615 EXPORT_SYMBOL(sysctl_tcp_low_latency);
75616
75617+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75618+extern int grsec_enable_blackhole;
75619+#endif
75620
75621 #ifdef CONFIG_TCP_MD5SIG
75622 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
75623@@ -1638,6 +1641,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
75624 return 0;
75625
75626 reset:
75627+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75628+ if (!grsec_enable_blackhole)
75629+#endif
75630 tcp_v4_send_reset(rsk, skb);
75631 discard:
75632 kfree_skb(skb);
75633@@ -1700,12 +1706,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
75634 TCP_SKB_CB(skb)->sacked = 0;
75635
75636 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
75637- if (!sk)
75638+ if (!sk) {
75639+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75640+ ret = 1;
75641+#endif
75642 goto no_tcp_socket;
75643-
75644+ }
75645 process:
75646- if (sk->sk_state == TCP_TIME_WAIT)
75647+ if (sk->sk_state == TCP_TIME_WAIT) {
75648+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75649+ ret = 2;
75650+#endif
75651 goto do_time_wait;
75652+ }
75653
75654 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
75655 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
75656@@ -1755,6 +1768,10 @@ no_tcp_socket:
75657 bad_packet:
75658 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
75659 } else {
75660+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75661+ if (!grsec_enable_blackhole || (ret == 1 &&
75662+ (skb->dev->flags & IFF_LOOPBACK)))
75663+#endif
75664 tcp_v4_send_reset(NULL, skb);
75665 }
75666
75667@@ -2417,7 +2434,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
75668 0, /* non standard timer */
75669 0, /* open_requests have no inode */
75670 atomic_read(&sk->sk_refcnt),
75671+#ifdef CONFIG_GRKERNSEC_HIDESYM
75672+ NULL,
75673+#else
75674 req,
75675+#endif
75676 len);
75677 }
75678
75679@@ -2467,7 +2488,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
75680 sock_i_uid(sk),
75681 icsk->icsk_probes_out,
75682 sock_i_ino(sk),
75683- atomic_read(&sk->sk_refcnt), sk,
75684+ atomic_read(&sk->sk_refcnt),
75685+#ifdef CONFIG_GRKERNSEC_HIDESYM
75686+ NULL,
75687+#else
75688+ sk,
75689+#endif
75690 jiffies_to_clock_t(icsk->icsk_rto),
75691 jiffies_to_clock_t(icsk->icsk_ack.ato),
75692 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
75693@@ -2495,7 +2521,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
75694 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
75695 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
75696 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
75697- atomic_read(&tw->tw_refcnt), tw, len);
75698+ atomic_read(&tw->tw_refcnt),
75699+#ifdef CONFIG_GRKERNSEC_HIDESYM
75700+ NULL,
75701+#else
75702+ tw,
75703+#endif
75704+ len);
75705 }
75706
75707 #define TMPSZ 150
75708diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
75709index 550e755..25721b3 100644
75710--- a/net/ipv4/tcp_minisocks.c
75711+++ b/net/ipv4/tcp_minisocks.c
75712@@ -27,6 +27,10 @@
75713 #include <net/inet_common.h>
75714 #include <net/xfrm.h>
75715
75716+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75717+extern int grsec_enable_blackhole;
75718+#endif
75719+
75720 int sysctl_tcp_syncookies __read_mostly = 1;
75721 EXPORT_SYMBOL(sysctl_tcp_syncookies);
75722
75723@@ -753,6 +757,10 @@ listen_overflow:
75724
75725 embryonic_reset:
75726 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
75727+
75728+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75729+ if (!grsec_enable_blackhole)
75730+#endif
75731 if (!(flg & TCP_FLAG_RST))
75732 req->rsk_ops->send_reset(sk, skb);
75733
75734diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
75735index 85ee7eb..53277ab 100644
75736--- a/net/ipv4/tcp_probe.c
75737+++ b/net/ipv4/tcp_probe.c
75738@@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
75739 if (cnt + width >= len)
75740 break;
75741
75742- if (copy_to_user(buf + cnt, tbuf, width))
75743+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
75744 return -EFAULT;
75745 cnt += width;
75746 }
75747diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
75748index cd2e072..1fffee2 100644
75749--- a/net/ipv4/tcp_timer.c
75750+++ b/net/ipv4/tcp_timer.c
75751@@ -22,6 +22,10 @@
75752 #include <linux/gfp.h>
75753 #include <net/tcp.h>
75754
75755+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75756+extern int grsec_lastack_retries;
75757+#endif
75758+
75759 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
75760 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
75761 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
75762@@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
75763 }
75764 }
75765
75766+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75767+ if ((sk->sk_state == TCP_LAST_ACK) &&
75768+ (grsec_lastack_retries > 0) &&
75769+ (grsec_lastack_retries < retry_until))
75770+ retry_until = grsec_lastack_retries;
75771+#endif
75772+
75773 if (retransmits_timed_out(sk, retry_until,
75774 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
75775 /* Has it gone just too far? */
75776diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
75777index 5d075b5..d907d5f 100644
75778--- a/net/ipv4/udp.c
75779+++ b/net/ipv4/udp.c
75780@@ -86,6 +86,7 @@
75781 #include <linux/types.h>
75782 #include <linux/fcntl.h>
75783 #include <linux/module.h>
75784+#include <linux/security.h>
75785 #include <linux/socket.h>
75786 #include <linux/sockios.h>
75787 #include <linux/igmp.h>
75788@@ -108,6 +109,10 @@
75789 #include <trace/events/udp.h>
75790 #include "udp_impl.h"
75791
75792+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75793+extern int grsec_enable_blackhole;
75794+#endif
75795+
75796 struct udp_table udp_table __read_mostly;
75797 EXPORT_SYMBOL(udp_table);
75798
75799@@ -566,6 +571,9 @@ found:
75800 return s;
75801 }
75802
75803+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
75804+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
75805+
75806 /*
75807 * This routine is called by the ICMP module when it gets some
75808 * sort of error condition. If err < 0 then the socket should
75809@@ -857,9 +865,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
75810 dport = usin->sin_port;
75811 if (dport == 0)
75812 return -EINVAL;
75813+
75814+ err = gr_search_udp_sendmsg(sk, usin);
75815+ if (err)
75816+ return err;
75817 } else {
75818 if (sk->sk_state != TCP_ESTABLISHED)
75819 return -EDESTADDRREQ;
75820+
75821+ err = gr_search_udp_sendmsg(sk, NULL);
75822+ if (err)
75823+ return err;
75824+
75825 daddr = inet->inet_daddr;
75826 dport = inet->inet_dport;
75827 /* Open fast path for connected socket.
75828@@ -1100,7 +1117,7 @@ static unsigned int first_packet_length(struct sock *sk)
75829 udp_lib_checksum_complete(skb)) {
75830 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75831 IS_UDPLITE(sk));
75832- atomic_inc(&sk->sk_drops);
75833+ atomic_inc_unchecked(&sk->sk_drops);
75834 __skb_unlink(skb, rcvq);
75835 __skb_queue_tail(&list_kill, skb);
75836 }
75837@@ -1186,6 +1203,10 @@ try_again:
75838 if (!skb)
75839 goto out;
75840
75841+ err = gr_search_udp_recvmsg(sk, skb);
75842+ if (err)
75843+ goto out_free;
75844+
75845 ulen = skb->len - sizeof(struct udphdr);
75846 copied = len;
75847 if (copied > ulen)
75848@@ -1489,7 +1510,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75849
75850 drop:
75851 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
75852- atomic_inc(&sk->sk_drops);
75853+ atomic_inc_unchecked(&sk->sk_drops);
75854 kfree_skb(skb);
75855 return -1;
75856 }
75857@@ -1508,7 +1529,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
75858 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
75859
75860 if (!skb1) {
75861- atomic_inc(&sk->sk_drops);
75862+ atomic_inc_unchecked(&sk->sk_drops);
75863 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
75864 IS_UDPLITE(sk));
75865 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75866@@ -1677,6 +1698,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75867 goto csum_error;
75868
75869 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
75870+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75871+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
75872+#endif
75873 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
75874
75875 /*
75876@@ -2100,8 +2124,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
75877 sk_wmem_alloc_get(sp),
75878 sk_rmem_alloc_get(sp),
75879 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75880- atomic_read(&sp->sk_refcnt), sp,
75881- atomic_read(&sp->sk_drops), len);
75882+ atomic_read(&sp->sk_refcnt),
75883+#ifdef CONFIG_GRKERNSEC_HIDESYM
75884+ NULL,
75885+#else
75886+ sp,
75887+#endif
75888+ atomic_read_unchecked(&sp->sk_drops), len);
75889 }
75890
75891 int udp4_seq_show(struct seq_file *seq, void *v)
75892diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
75893index 6b8ebc5..1d624f4 100644
75894--- a/net/ipv6/addrconf.c
75895+++ b/net/ipv6/addrconf.c
75896@@ -2145,7 +2145,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
75897 p.iph.ihl = 5;
75898 p.iph.protocol = IPPROTO_IPV6;
75899 p.iph.ttl = 64;
75900- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
75901+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
75902
75903 if (ops->ndo_do_ioctl) {
75904 mm_segment_t oldfs = get_fs();
75905diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
75906index 02dd203..e03fcc9 100644
75907--- a/net/ipv6/inet6_connection_sock.c
75908+++ b/net/ipv6/inet6_connection_sock.c
75909@@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
75910 #ifdef CONFIG_XFRM
75911 {
75912 struct rt6_info *rt = (struct rt6_info *)dst;
75913- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
75914+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
75915 }
75916 #endif
75917 }
75918@@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
75919 #ifdef CONFIG_XFRM
75920 if (dst) {
75921 struct rt6_info *rt = (struct rt6_info *)dst;
75922- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
75923+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
75924 __sk_dst_reset(sk);
75925 dst = NULL;
75926 }
75927diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
75928index 18a2719..779f36a 100644
75929--- a/net/ipv6/ipv6_sockglue.c
75930+++ b/net/ipv6/ipv6_sockglue.c
75931@@ -960,7 +960,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
75932 if (sk->sk_type != SOCK_STREAM)
75933 return -ENOPROTOOPT;
75934
75935- msg.msg_control = optval;
75936+ msg.msg_control = (void __force_kernel *)optval;
75937 msg.msg_controllen = len;
75938 msg.msg_flags = flags;
75939
75940diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
75941index d02f7e4..2d2a0f1 100644
75942--- a/net/ipv6/raw.c
75943+++ b/net/ipv6/raw.c
75944@@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
75945 {
75946 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
75947 skb_checksum_complete(skb)) {
75948- atomic_inc(&sk->sk_drops);
75949+ atomic_inc_unchecked(&sk->sk_drops);
75950 kfree_skb(skb);
75951 return NET_RX_DROP;
75952 }
75953@@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
75954 struct raw6_sock *rp = raw6_sk(sk);
75955
75956 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
75957- atomic_inc(&sk->sk_drops);
75958+ atomic_inc_unchecked(&sk->sk_drops);
75959 kfree_skb(skb);
75960 return NET_RX_DROP;
75961 }
75962@@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
75963
75964 if (inet->hdrincl) {
75965 if (skb_checksum_complete(skb)) {
75966- atomic_inc(&sk->sk_drops);
75967+ atomic_inc_unchecked(&sk->sk_drops);
75968 kfree_skb(skb);
75969 return NET_RX_DROP;
75970 }
75971@@ -602,7 +602,7 @@ out:
75972 return err;
75973 }
75974
75975-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
75976+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
75977 struct flowi6 *fl6, struct dst_entry **dstp,
75978 unsigned int flags)
75979 {
75980@@ -912,12 +912,15 @@ do_confirm:
75981 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
75982 char __user *optval, int optlen)
75983 {
75984+ struct icmp6_filter filter;
75985+
75986 switch (optname) {
75987 case ICMPV6_FILTER:
75988 if (optlen > sizeof(struct icmp6_filter))
75989 optlen = sizeof(struct icmp6_filter);
75990- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
75991+ if (copy_from_user(&filter, optval, optlen))
75992 return -EFAULT;
75993+ raw6_sk(sk)->filter = filter;
75994 return 0;
75995 default:
75996 return -ENOPROTOOPT;
75997@@ -930,6 +933,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
75998 char __user *optval, int __user *optlen)
75999 {
76000 int len;
76001+ struct icmp6_filter filter;
76002
76003 switch (optname) {
76004 case ICMPV6_FILTER:
76005@@ -941,7 +945,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76006 len = sizeof(struct icmp6_filter);
76007 if (put_user(len, optlen))
76008 return -EFAULT;
76009- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76010+ filter = raw6_sk(sk)->filter;
76011+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
76012 return -EFAULT;
76013 return 0;
76014 default:
76015@@ -1248,7 +1253,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76016 0, 0L, 0,
76017 sock_i_uid(sp), 0,
76018 sock_i_ino(sp),
76019- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76020+ atomic_read(&sp->sk_refcnt),
76021+#ifdef CONFIG_GRKERNSEC_HIDESYM
76022+ NULL,
76023+#else
76024+ sp,
76025+#endif
76026+ atomic_read_unchecked(&sp->sk_drops));
76027 }
76028
76029 static int raw6_seq_show(struct seq_file *seq, void *v)
76030diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76031index a89ca8d..12e66b0 100644
76032--- a/net/ipv6/tcp_ipv6.c
76033+++ b/net/ipv6/tcp_ipv6.c
76034@@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76035 }
76036 #endif
76037
76038+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76039+extern int grsec_enable_blackhole;
76040+#endif
76041+
76042 static void tcp_v6_hash(struct sock *sk)
76043 {
76044 if (sk->sk_state != TCP_CLOSE) {
76045@@ -1654,6 +1658,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76046 return 0;
76047
76048 reset:
76049+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76050+ if (!grsec_enable_blackhole)
76051+#endif
76052 tcp_v6_send_reset(sk, skb);
76053 discard:
76054 if (opt_skb)
76055@@ -1733,12 +1740,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76056 TCP_SKB_CB(skb)->sacked = 0;
76057
76058 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76059- if (!sk)
76060+ if (!sk) {
76061+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76062+ ret = 1;
76063+#endif
76064 goto no_tcp_socket;
76065+ }
76066
76067 process:
76068- if (sk->sk_state == TCP_TIME_WAIT)
76069+ if (sk->sk_state == TCP_TIME_WAIT) {
76070+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76071+ ret = 2;
76072+#endif
76073 goto do_time_wait;
76074+ }
76075
76076 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76077 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76078@@ -1786,6 +1801,10 @@ no_tcp_socket:
76079 bad_packet:
76080 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76081 } else {
76082+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76083+ if (!grsec_enable_blackhole || (ret == 1 &&
76084+ (skb->dev->flags & IFF_LOOPBACK)))
76085+#endif
76086 tcp_v6_send_reset(NULL, skb);
76087 }
76088
76089@@ -2047,7 +2066,13 @@ static void get_openreq6(struct seq_file *seq,
76090 uid,
76091 0, /* non standard timer */
76092 0, /* open_requests have no inode */
76093- 0, req);
76094+ 0,
76095+#ifdef CONFIG_GRKERNSEC_HIDESYM
76096+ NULL
76097+#else
76098+ req
76099+#endif
76100+ );
76101 }
76102
76103 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76104@@ -2097,7 +2122,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76105 sock_i_uid(sp),
76106 icsk->icsk_probes_out,
76107 sock_i_ino(sp),
76108- atomic_read(&sp->sk_refcnt), sp,
76109+ atomic_read(&sp->sk_refcnt),
76110+#ifdef CONFIG_GRKERNSEC_HIDESYM
76111+ NULL,
76112+#else
76113+ sp,
76114+#endif
76115 jiffies_to_clock_t(icsk->icsk_rto),
76116 jiffies_to_clock_t(icsk->icsk_ack.ato),
76117 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76118@@ -2132,7 +2162,13 @@ static void get_timewait6_sock(struct seq_file *seq,
76119 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76120 tw->tw_substate, 0, 0,
76121 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76122- atomic_read(&tw->tw_refcnt), tw);
76123+ atomic_read(&tw->tw_refcnt),
76124+#ifdef CONFIG_GRKERNSEC_HIDESYM
76125+ NULL
76126+#else
76127+ tw
76128+#endif
76129+ );
76130 }
76131
76132 static int tcp6_seq_show(struct seq_file *seq, void *v)
76133diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
76134index 4f96b5c..75543d7 100644
76135--- a/net/ipv6/udp.c
76136+++ b/net/ipv6/udp.c
76137@@ -50,6 +50,10 @@
76138 #include <linux/seq_file.h>
76139 #include "udp_impl.h"
76140
76141+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76142+extern int grsec_enable_blackhole;
76143+#endif
76144+
76145 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76146 {
76147 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76148@@ -551,7 +555,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
76149
76150 return 0;
76151 drop:
76152- atomic_inc(&sk->sk_drops);
76153+ atomic_inc_unchecked(&sk->sk_drops);
76154 drop_no_sk_drops_inc:
76155 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76156 kfree_skb(skb);
76157@@ -627,7 +631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76158 continue;
76159 }
76160 drop:
76161- atomic_inc(&sk->sk_drops);
76162+ atomic_inc_unchecked(&sk->sk_drops);
76163 UDP6_INC_STATS_BH(sock_net(sk),
76164 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
76165 UDP6_INC_STATS_BH(sock_net(sk),
76166@@ -782,6 +786,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76167 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
76168 proto == IPPROTO_UDPLITE);
76169
76170+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76171+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76172+#endif
76173 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76174
76175 kfree_skb(skb);
76176@@ -798,7 +805,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76177 if (!sock_owned_by_user(sk))
76178 udpv6_queue_rcv_skb(sk, skb);
76179 else if (sk_add_backlog(sk, skb)) {
76180- atomic_inc(&sk->sk_drops);
76181+ atomic_inc_unchecked(&sk->sk_drops);
76182 bh_unlock_sock(sk);
76183 sock_put(sk);
76184 goto discard;
76185@@ -1410,8 +1417,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
76186 0, 0L, 0,
76187 sock_i_uid(sp), 0,
76188 sock_i_ino(sp),
76189- atomic_read(&sp->sk_refcnt), sp,
76190- atomic_read(&sp->sk_drops));
76191+ atomic_read(&sp->sk_refcnt),
76192+#ifdef CONFIG_GRKERNSEC_HIDESYM
76193+ NULL,
76194+#else
76195+ sp,
76196+#endif
76197+ atomic_read_unchecked(&sp->sk_drops));
76198 }
76199
76200 int udp6_seq_show(struct seq_file *seq, void *v)
76201diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
76202index 253695d..9481ce8 100644
76203--- a/net/irda/ircomm/ircomm_tty.c
76204+++ b/net/irda/ircomm/ircomm_tty.c
76205@@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76206 add_wait_queue(&self->open_wait, &wait);
76207
76208 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76209- __FILE__,__LINE__, tty->driver->name, self->open_count );
76210+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76211
76212 /* As far as I can see, we protect open_count - Jean II */
76213 spin_lock_irqsave(&self->spinlock, flags);
76214 if (!tty_hung_up_p(filp)) {
76215 extra_count = 1;
76216- self->open_count--;
76217+ local_dec(&self->open_count);
76218 }
76219 spin_unlock_irqrestore(&self->spinlock, flags);
76220- self->blocked_open++;
76221+ local_inc(&self->blocked_open);
76222
76223 while (1) {
76224 if (tty->termios->c_cflag & CBAUD) {
76225@@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76226 }
76227
76228 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
76229- __FILE__,__LINE__, tty->driver->name, self->open_count );
76230+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76231
76232 schedule();
76233 }
76234@@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76235 if (extra_count) {
76236 /* ++ is not atomic, so this should be protected - Jean II */
76237 spin_lock_irqsave(&self->spinlock, flags);
76238- self->open_count++;
76239+ local_inc(&self->open_count);
76240 spin_unlock_irqrestore(&self->spinlock, flags);
76241 }
76242- self->blocked_open--;
76243+ local_dec(&self->blocked_open);
76244
76245 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
76246- __FILE__,__LINE__, tty->driver->name, self->open_count);
76247+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
76248
76249 if (!retval)
76250 self->flags |= ASYNC_NORMAL_ACTIVE;
76251@@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
76252 }
76253 /* ++ is not atomic, so this should be protected - Jean II */
76254 spin_lock_irqsave(&self->spinlock, flags);
76255- self->open_count++;
76256+ local_inc(&self->open_count);
76257
76258 tty->driver_data = self;
76259 self->tty = tty;
76260 spin_unlock_irqrestore(&self->spinlock, flags);
76261
76262 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
76263- self->line, self->open_count);
76264+ self->line, local_read(&self->open_count));
76265
76266 /* Not really used by us, but lets do it anyway */
76267 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
76268@@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76269 return;
76270 }
76271
76272- if ((tty->count == 1) && (self->open_count != 1)) {
76273+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
76274 /*
76275 * Uh, oh. tty->count is 1, which means that the tty
76276 * structure will be freed. state->count should always
76277@@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76278 */
76279 IRDA_DEBUG(0, "%s(), bad serial port count; "
76280 "tty->count is 1, state->count is %d\n", __func__ ,
76281- self->open_count);
76282- self->open_count = 1;
76283+ local_read(&self->open_count));
76284+ local_set(&self->open_count, 1);
76285 }
76286
76287- if (--self->open_count < 0) {
76288+ if (local_dec_return(&self->open_count) < 0) {
76289 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
76290- __func__, self->line, self->open_count);
76291- self->open_count = 0;
76292+ __func__, self->line, local_read(&self->open_count));
76293+ local_set(&self->open_count, 0);
76294 }
76295- if (self->open_count) {
76296+ if (local_read(&self->open_count)) {
76297 spin_unlock_irqrestore(&self->spinlock, flags);
76298
76299 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
76300@@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76301 tty->closing = 0;
76302 self->tty = NULL;
76303
76304- if (self->blocked_open) {
76305+ if (local_read(&self->blocked_open)) {
76306 if (self->close_delay)
76307 schedule_timeout_interruptible(self->close_delay);
76308 wake_up_interruptible(&self->open_wait);
76309@@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
76310 spin_lock_irqsave(&self->spinlock, flags);
76311 self->flags &= ~ASYNC_NORMAL_ACTIVE;
76312 self->tty = NULL;
76313- self->open_count = 0;
76314+ local_set(&self->open_count, 0);
76315 spin_unlock_irqrestore(&self->spinlock, flags);
76316
76317 wake_up_interruptible(&self->open_wait);
76318@@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
76319 seq_putc(m, '\n');
76320
76321 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
76322- seq_printf(m, "Open count: %d\n", self->open_count);
76323+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
76324 seq_printf(m, "Max data size: %d\n", self->max_data_size);
76325 seq_printf(m, "Max header size: %d\n", self->max_header_size);
76326
76327diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
76328index d5c5b8f..33beff0 100644
76329--- a/net/iucv/af_iucv.c
76330+++ b/net/iucv/af_iucv.c
76331@@ -764,10 +764,10 @@ static int iucv_sock_autobind(struct sock *sk)
76332
76333 write_lock_bh(&iucv_sk_list.lock);
76334
76335- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
76336+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76337 while (__iucv_get_sock_by_name(name)) {
76338 sprintf(name, "%08x",
76339- atomic_inc_return(&iucv_sk_list.autobind_name));
76340+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76341 }
76342
76343 write_unlock_bh(&iucv_sk_list.lock);
76344diff --git a/net/key/af_key.c b/net/key/af_key.c
76345index 11dbb22..c20f667 100644
76346--- a/net/key/af_key.c
76347+++ b/net/key/af_key.c
76348@@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
76349 static u32 get_acqseq(void)
76350 {
76351 u32 res;
76352- static atomic_t acqseq;
76353+ static atomic_unchecked_t acqseq;
76354
76355 do {
76356- res = atomic_inc_return(&acqseq);
76357+ res = atomic_inc_return_unchecked(&acqseq);
76358 } while (!res);
76359 return res;
76360 }
76361diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
76362index 2f0642d..e5c6fba 100644
76363--- a/net/mac80211/ieee80211_i.h
76364+++ b/net/mac80211/ieee80211_i.h
76365@@ -28,6 +28,7 @@
76366 #include <net/ieee80211_radiotap.h>
76367 #include <net/cfg80211.h>
76368 #include <net/mac80211.h>
76369+#include <asm/local.h>
76370 #include "key.h"
76371 #include "sta_info.h"
76372
76373@@ -781,7 +782,7 @@ struct ieee80211_local {
76374 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
76375 spinlock_t queue_stop_reason_lock;
76376
76377- int open_count;
76378+ local_t open_count;
76379 int monitors, cooked_mntrs;
76380 /* number of interfaces with corresponding FIF_ flags */
76381 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
76382diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
76383index 8e2137b..2974283 100644
76384--- a/net/mac80211/iface.c
76385+++ b/net/mac80211/iface.c
76386@@ -222,7 +222,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76387 break;
76388 }
76389
76390- if (local->open_count == 0) {
76391+ if (local_read(&local->open_count) == 0) {
76392 res = drv_start(local);
76393 if (res)
76394 goto err_del_bss;
76395@@ -246,7 +246,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76396 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
76397
76398 if (!is_valid_ether_addr(dev->dev_addr)) {
76399- if (!local->open_count)
76400+ if (!local_read(&local->open_count))
76401 drv_stop(local);
76402 return -EADDRNOTAVAIL;
76403 }
76404@@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76405 mutex_unlock(&local->mtx);
76406
76407 if (coming_up)
76408- local->open_count++;
76409+ local_inc(&local->open_count);
76410
76411 if (hw_reconf_flags)
76412 ieee80211_hw_config(local, hw_reconf_flags);
76413@@ -360,7 +360,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76414 err_del_interface:
76415 drv_remove_interface(local, sdata);
76416 err_stop:
76417- if (!local->open_count)
76418+ if (!local_read(&local->open_count))
76419 drv_stop(local);
76420 err_del_bss:
76421 sdata->bss = NULL;
76422@@ -489,7 +489,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76423 }
76424
76425 if (going_down)
76426- local->open_count--;
76427+ local_dec(&local->open_count);
76428
76429 switch (sdata->vif.type) {
76430 case NL80211_IFTYPE_AP_VLAN:
76431@@ -548,7 +548,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76432
76433 ieee80211_recalc_ps(local, -1);
76434
76435- if (local->open_count == 0) {
76436+ if (local_read(&local->open_count) == 0) {
76437 if (local->ops->napi_poll)
76438 napi_disable(&local->napi);
76439 ieee80211_clear_tx_pending(local);
76440diff --git a/net/mac80211/main.c b/net/mac80211/main.c
76441index b142bd4..a651749 100644
76442--- a/net/mac80211/main.c
76443+++ b/net/mac80211/main.c
76444@@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
76445 local->hw.conf.power_level = power;
76446 }
76447
76448- if (changed && local->open_count) {
76449+ if (changed && local_read(&local->open_count)) {
76450 ret = drv_config(local, changed);
76451 /*
76452 * Goal:
76453diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
76454index 596efaf..8f1911f 100644
76455--- a/net/mac80211/pm.c
76456+++ b/net/mac80211/pm.c
76457@@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76458 struct ieee80211_sub_if_data *sdata;
76459 struct sta_info *sta;
76460
76461- if (!local->open_count)
76462+ if (!local_read(&local->open_count))
76463 goto suspend;
76464
76465 ieee80211_scan_cancel(local);
76466@@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76467 cancel_work_sync(&local->dynamic_ps_enable_work);
76468 del_timer_sync(&local->dynamic_ps_timer);
76469
76470- local->wowlan = wowlan && local->open_count;
76471+ local->wowlan = wowlan && local_read(&local->open_count);
76472 if (local->wowlan) {
76473 int err = drv_suspend(local, wowlan);
76474 if (err < 0) {
76475@@ -129,7 +129,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76476 }
76477
76478 /* stop hardware - this must stop RX */
76479- if (local->open_count)
76480+ if (local_read(&local->open_count))
76481 ieee80211_stop_device(local);
76482
76483 suspend:
76484diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
76485index f9b8e81..bb89b46 100644
76486--- a/net/mac80211/rate.c
76487+++ b/net/mac80211/rate.c
76488@@ -401,7 +401,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
76489
76490 ASSERT_RTNL();
76491
76492- if (local->open_count)
76493+ if (local_read(&local->open_count))
76494 return -EBUSY;
76495
76496 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
76497diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
76498index c97a065..ff61928 100644
76499--- a/net/mac80211/rc80211_pid_debugfs.c
76500+++ b/net/mac80211/rc80211_pid_debugfs.c
76501@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
76502
76503 spin_unlock_irqrestore(&events->lock, status);
76504
76505- if (copy_to_user(buf, pb, p))
76506+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
76507 return -EFAULT;
76508
76509 return p;
76510diff --git a/net/mac80211/util.c b/net/mac80211/util.c
76511index 9919892..8c49803 100644
76512--- a/net/mac80211/util.c
76513+++ b/net/mac80211/util.c
76514@@ -1143,7 +1143,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
76515 }
76516 #endif
76517 /* everything else happens only if HW was up & running */
76518- if (!local->open_count)
76519+ if (!local_read(&local->open_count))
76520 goto wake_up;
76521
76522 /*
76523diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
76524index f8ac4ef..b02560b 100644
76525--- a/net/netfilter/Kconfig
76526+++ b/net/netfilter/Kconfig
76527@@ -806,6 +806,16 @@ config NETFILTER_XT_MATCH_ESP
76528
76529 To compile it as a module, choose M here. If unsure, say N.
76530
76531+config NETFILTER_XT_MATCH_GRADM
76532+ tristate '"gradm" match support'
76533+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
76534+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
76535+ ---help---
76536+ The gradm match allows to match on grsecurity RBAC being enabled.
76537+ It is useful when iptables rules are applied early on bootup to
76538+ prevent connections to the machine (except from a trusted host)
76539+ while the RBAC system is disabled.
76540+
76541 config NETFILTER_XT_MATCH_HASHLIMIT
76542 tristate '"hashlimit" match support'
76543 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
76544diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
76545index 40f4c3d..0d5dd6b 100644
76546--- a/net/netfilter/Makefile
76547+++ b/net/netfilter/Makefile
76548@@ -83,6 +83,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
76549 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
76550 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
76551 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
76552+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
76553 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
76554 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
76555 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
76556diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
76557index 29fa5ba..8debc79 100644
76558--- a/net/netfilter/ipvs/ip_vs_conn.c
76559+++ b/net/netfilter/ipvs/ip_vs_conn.c
76560@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
76561 /* Increase the refcnt counter of the dest */
76562 atomic_inc(&dest->refcnt);
76563
76564- conn_flags = atomic_read(&dest->conn_flags);
76565+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
76566 if (cp->protocol != IPPROTO_UDP)
76567 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
76568 /* Bind with the destination and its corresponding transmitter */
76569@@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
76570 atomic_set(&cp->refcnt, 1);
76571
76572 atomic_set(&cp->n_control, 0);
76573- atomic_set(&cp->in_pkts, 0);
76574+ atomic_set_unchecked(&cp->in_pkts, 0);
76575
76576 atomic_inc(&ipvs->conn_count);
76577 if (flags & IP_VS_CONN_F_NO_CPORT)
76578@@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
76579
76580 /* Don't drop the entry if its number of incoming packets is not
76581 located in [0, 8] */
76582- i = atomic_read(&cp->in_pkts);
76583+ i = atomic_read_unchecked(&cp->in_pkts);
76584 if (i > 8 || i < 0) return 0;
76585
76586 if (!todrop_rate[i]) return 0;
76587diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
76588index 2555816..31492d9 100644
76589--- a/net/netfilter/ipvs/ip_vs_core.c
76590+++ b/net/netfilter/ipvs/ip_vs_core.c
76591@@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
76592 ret = cp->packet_xmit(skb, cp, pd->pp);
76593 /* do not touch skb anymore */
76594
76595- atomic_inc(&cp->in_pkts);
76596+ atomic_inc_unchecked(&cp->in_pkts);
76597 ip_vs_conn_put(cp);
76598 return ret;
76599 }
76600@@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
76601 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
76602 pkts = sysctl_sync_threshold(ipvs);
76603 else
76604- pkts = atomic_add_return(1, &cp->in_pkts);
76605+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
76606
76607 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
76608 cp->protocol == IPPROTO_SCTP) {
76609diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
76610index b3afe18..08ec940 100644
76611--- a/net/netfilter/ipvs/ip_vs_ctl.c
76612+++ b/net/netfilter/ipvs/ip_vs_ctl.c
76613@@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
76614 ip_vs_rs_hash(ipvs, dest);
76615 write_unlock_bh(&ipvs->rs_lock);
76616 }
76617- atomic_set(&dest->conn_flags, conn_flags);
76618+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
76619
76620 /* bind the service */
76621 if (!dest->svc) {
76622@@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
76623 " %-7s %-6d %-10d %-10d\n",
76624 &dest->addr.in6,
76625 ntohs(dest->port),
76626- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
76627+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
76628 atomic_read(&dest->weight),
76629 atomic_read(&dest->activeconns),
76630 atomic_read(&dest->inactconns));
76631@@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
76632 "%-7s %-6d %-10d %-10d\n",
76633 ntohl(dest->addr.ip),
76634 ntohs(dest->port),
76635- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
76636+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
76637 atomic_read(&dest->weight),
76638 atomic_read(&dest->activeconns),
76639 atomic_read(&dest->inactconns));
76640@@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
76641
76642 entry.addr = dest->addr.ip;
76643 entry.port = dest->port;
76644- entry.conn_flags = atomic_read(&dest->conn_flags);
76645+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
76646 entry.weight = atomic_read(&dest->weight);
76647 entry.u_threshold = dest->u_threshold;
76648 entry.l_threshold = dest->l_threshold;
76649@@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
76650 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
76651
76652 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
76653- atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
76654+ atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
76655 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
76656 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
76657 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
76658diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
76659index 8a0d6d6..90ec197 100644
76660--- a/net/netfilter/ipvs/ip_vs_sync.c
76661+++ b/net/netfilter/ipvs/ip_vs_sync.c
76662@@ -649,7 +649,7 @@ control:
76663 * i.e only increment in_pkts for Templates.
76664 */
76665 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
76666- int pkts = atomic_add_return(1, &cp->in_pkts);
76667+ int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
76668
76669 if (pkts % sysctl_sync_period(ipvs) != 1)
76670 return;
76671@@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
76672
76673 if (opt)
76674 memcpy(&cp->in_seq, opt, sizeof(*opt));
76675- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
76676+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
76677 cp->state = state;
76678 cp->old_state = cp->state;
76679 /*
76680diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
76681index 7fd66de..e6fb361 100644
76682--- a/net/netfilter/ipvs/ip_vs_xmit.c
76683+++ b/net/netfilter/ipvs/ip_vs_xmit.c
76684@@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
76685 else
76686 rc = NF_ACCEPT;
76687 /* do not touch skb anymore */
76688- atomic_inc(&cp->in_pkts);
76689+ atomic_inc_unchecked(&cp->in_pkts);
76690 goto out;
76691 }
76692
76693@@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
76694 else
76695 rc = NF_ACCEPT;
76696 /* do not touch skb anymore */
76697- atomic_inc(&cp->in_pkts);
76698+ atomic_inc_unchecked(&cp->in_pkts);
76699 goto out;
76700 }
76701
76702diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
76703index 66b2c54..c7884e3 100644
76704--- a/net/netfilter/nfnetlink_log.c
76705+++ b/net/netfilter/nfnetlink_log.c
76706@@ -70,7 +70,7 @@ struct nfulnl_instance {
76707 };
76708
76709 static DEFINE_SPINLOCK(instances_lock);
76710-static atomic_t global_seq;
76711+static atomic_unchecked_t global_seq;
76712
76713 #define INSTANCE_BUCKETS 16
76714 static struct hlist_head instance_table[INSTANCE_BUCKETS];
76715@@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
76716 /* global sequence number */
76717 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
76718 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
76719- htonl(atomic_inc_return(&global_seq)));
76720+ htonl(atomic_inc_return_unchecked(&global_seq)));
76721
76722 if (data_len) {
76723 struct nlattr *nla;
76724diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
76725new file mode 100644
76726index 0000000..6905327
76727--- /dev/null
76728+++ b/net/netfilter/xt_gradm.c
76729@@ -0,0 +1,51 @@
76730+/*
76731+ * gradm match for netfilter
76732